diff options
author | Niels Möller <nisse@webrtc.org> | 2019-06-27 12:15:06 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-28 07:29:10 +0000 |
commit | 767efaba10970f2168d42d4632d545fa13341343 (patch) | |
tree | 66980ebaa381fe9fb0878de38f069e95df662920 /common_audio | |
parent | 71809c67ce0a5cdfe368e5d7f13c3d0a14812e17 (diff) | |
download | webrtc-767efaba10970f2168d42d4632d545fa13341343.tar.gz |
Delete method ReadableWav::Eof, which was used incorrectly.
Bug: webrtc:6463
Change-Id: I160ff01c16045eba438f928b429eacdb5342e5a9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144026
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28409}
Diffstat (limited to 'common_audio')
-rw-r--r-- | common_audio/wav_file.cc | 1 | ||||
-rw-r--r-- | common_audio/wav_header.cc | 21 | ||||
-rw-r--r-- | common_audio/wav_header.h | 2 | ||||
-rw-r--r-- | common_audio/wav_header_unittest.cc | 5 |
4 files changed, 7 insertions, 22 deletions
diff --git a/common_audio/wav_file.cc b/common_audio/wav_file.cc index b404d9392f..da1a899b3b 100644 --- a/common_audio/wav_file.cc +++ b/common_audio/wav_file.cc @@ -39,7 +39,6 @@ class ReadableWavFile : public ReadableWav { size_t Read(void* buf, size_t num_bytes) override { return fread(buf, 1, num_bytes, file_); } - bool Eof() const override { return feof(file_) != 0; } bool SeekForward(uint32_t num_bytes) override { return fseek(file_, num_bytes, SEEK_CUR) == 0; } diff --git a/common_audio/wav_header.cc b/common_audio/wav_header.cc index 9d602e9a01..15eb1f844e 100644 --- a/common_audio/wav_header.cc +++ b/common_audio/wav_header.cc @@ -108,21 +108,20 @@ static inline uint16_t BlockAlign(size_t num_channels, // Finds a chunk having the sought ID. If found, then |readable| points to the // first byte of the sought chunk data. If not found, the end of the file is // reached. -void FindWaveChunk(ChunkHeader* chunk_header, +bool FindWaveChunk(ChunkHeader* chunk_header, ReadableWav* readable, const std::string sought_chunk_id) { RTC_DCHECK_EQ(sought_chunk_id.size(), 4); - while (!readable->Eof()) { + while (true) { if (readable->Read(chunk_header, sizeof(*chunk_header)) != sizeof(*chunk_header)) - return; // EOF. + return false; // EOF. if (ReadFourCC(chunk_header->ID) == sought_chunk_id) - return; // Sought chunk found. + return true; // Sought chunk found. // Ignore current chunk by skipping its payload. if (!readable->SeekForward(chunk_header->Size)) - return; // EOF or error. + return false; // EOF or error. } - // EOF. } bool ReadFmtChunkData(FmtSubchunk* fmt_subchunk, ReadableWav* readable) { @@ -254,8 +253,7 @@ bool ReadWavHeader(ReadableWav* readable, // does not put requirements on the chunks order, it is uncommon to find the // "data" chunk before the "fmt " one. The code below fails if this is not the // case. - FindWaveChunk(&header.fmt.header, readable, "fmt "); - if (ReadFourCC(header.fmt.header.ID) != "fmt ") { + if (!FindWaveChunk(&header.fmt.header, readable, "fmt ")) { RTC_LOG(LS_ERROR) << "Cannot find 'fmt ' chunk."; return false; } @@ -263,12 +261,7 @@ bool ReadWavHeader(ReadableWav* readable, RTC_LOG(LS_ERROR) << "Cannot read 'fmt ' chunk."; return false; } - if (readable->Eof()) { - RTC_LOG(LS_ERROR) << "'fmt ' chunk placed after 'data' chunk."; - return false; - } - FindWaveChunk(&header.data.header, readable, "data"); - if (ReadFourCC(header.data.header.ID) != "data") { + if (!FindWaveChunk(&header.data.header, readable, "data")) { RTC_LOG(LS_ERROR) << "Cannot find 'data' chunk."; return false; } diff --git a/common_audio/wav_header.h b/common_audio/wav_header.h index a519ba556f..0c83d8d84d 100644 --- a/common_audio/wav_header.h +++ b/common_audio/wav_header.h @@ -22,8 +22,6 @@ class ReadableWav { public: // Returns the number of bytes read. virtual size_t Read(void* buf, size_t num_bytes) = 0; - // Returns true if the end-of-file has been reached. - virtual bool Eof() const = 0; virtual bool SeekForward(uint32_t num_bytes) = 0; virtual ~ReadableWav() = default; }; diff --git a/common_audio/wav_header_unittest.cc b/common_audio/wav_header_unittest.cc index 2e2eda5a6f..8276e5906a 100644 --- a/common_audio/wav_header_unittest.cc +++ b/common_audio/wav_header_unittest.cc @@ -33,9 +33,6 @@ class ReadableWavBuffer : public ReadableWav { } size_t Read(void* buf, size_t num_bytes) override { - // Verify we don't try to read outside of a properly sized header. - if (size_ >= kWavHeaderSize) - EXPECT_GE(size_, pos_ + num_bytes); EXPECT_FALSE(buf_exhausted_); const size_t bytes_remaining = size_ - pos_; @@ -51,8 +48,6 @@ class ReadableWavBuffer : public ReadableWav { return num_bytes; } - bool Eof() const override { return pos_ == size_; } - bool SeekForward(uint32_t num_bytes) override { // Verify we don't try to read outside of a properly sized header. if (size_ >= kWavHeaderSize) |