Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/audio_file_reader.h" | 5 #include "media/filters/audio_file_reader.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 void Initialize(const char* filename) { | 29 void Initialize(const char* filename) { |
| 30 data_ = ReadTestDataFile(filename); | 30 data_ = ReadTestDataFile(filename); |
| 31 protocol_.reset( | 31 protocol_.reset( |
| 32 new InMemoryUrlProtocol(data_->data(), data_->data_size(), false)); | 32 new InMemoryUrlProtocol(data_->data(), data_->data_size(), false)); |
| 33 reader_.reset(new AudioFileReader(protocol_.get())); | 33 reader_.reset(new AudioFileReader(protocol_.get())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Reads and the entire file provided to Initialize(). | 36 // Reads and the entire file provided to Initialize(). |
| 37 void ReadAndVerify(const char* expected_audio_hash, int expected_frames) { | 37 void ReadAndVerify(const char* expected_audio_hash, int expected_frames) { |
| 38 std::vector<std::unique_ptr<AudioBus>> decodedAudioPackets; | |
| 39 int actual_frames = reader_->Read(decodedAudioPackets); | |
| 38 std::unique_ptr<AudioBus> decoded_audio_data = | 40 std::unique_ptr<AudioBus> decoded_audio_data = |
| 39 AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames()); | 41 AudioBus::Create(reader_->channels(), actual_frames); |
| 40 int actual_frames = reader_->Read(decoded_audio_data.get()); | 42 int dest_start_frame = 0; |
| 43 for (auto&& packet : decodedAudioPackets) { | |
|
DaleCurtis
2017/02/09 18:47:36
no &&
Raymond Toy
2017/02/09 21:45:06
Done.
| |
| 44 int frame_count = packet->frames(); | |
| 45 packet->CopyPartialFramesTo(0, frame_count, dest_start_frame, | |
| 46 decoded_audio_data.get()); | |
| 47 dest_start_frame += frame_count; | |
| 48 } | |
| 41 ASSERT_LE(actual_frames, decoded_audio_data->frames()); | 49 ASSERT_LE(actual_frames, decoded_audio_data->frames()); |
| 42 ASSERT_EQ(expected_frames, actual_frames); | 50 ASSERT_EQ(expected_frames, actual_frames); |
| 43 | 51 |
| 44 AudioHash audio_hash; | 52 AudioHash audio_hash; |
| 45 audio_hash.Update(decoded_audio_data.get(), actual_frames); | 53 audio_hash.Update(decoded_audio_data.get(), actual_frames); |
| 46 EXPECT_EQ(expected_audio_hash, audio_hash.ToString()); | 54 EXPECT_EQ(expected_audio_hash, audio_hash.ToString()); |
| 47 } | 55 } |
| 48 | 56 |
| 49 // Verify packets are consistent across demuxer runs. Reads the first few | 57 // Verify packets are consistent across demuxer runs. Reads the first few |
| 50 // packets and then seeks back to the start timestamp and verifies that the | 58 // packets and then seeks back to the start timestamp and verifies that the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 ASSERT_TRUE(reader_->SeekForTesting(start_timestamp)); | 90 ASSERT_TRUE(reader_->SeekForTesting(start_timestamp)); |
| 83 } | 91 } |
| 84 } | 92 } |
| 85 | 93 |
| 86 void RunTest(const char* fn, | 94 void RunTest(const char* fn, |
| 87 const char* hash, | 95 const char* hash, |
| 88 int channels, | 96 int channels, |
| 89 int sample_rate, | 97 int sample_rate, |
| 90 base::TimeDelta duration, | 98 base::TimeDelta duration, |
| 91 int frames, | 99 int frames, |
| 92 int trimmed_frames) { | 100 int expected_frames) { |
| 93 Initialize(fn); | 101 Initialize(fn); |
| 94 ASSERT_TRUE(reader_->Open()); | 102 ASSERT_TRUE(reader_->Open()); |
| 95 EXPECT_EQ(channels, reader_->channels()); | 103 EXPECT_EQ(channels, reader_->channels()); |
| 96 EXPECT_EQ(sample_rate, reader_->sample_rate()); | 104 EXPECT_EQ(sample_rate, reader_->sample_rate()); |
| 97 EXPECT_EQ(duration.InMicroseconds(), | 105 if (frames >= 0) { |
| 98 reader_->GetDuration().InMicroseconds()); | 106 EXPECT_EQ(duration.InMicroseconds(), |
| 99 EXPECT_EQ(frames, reader_->GetNumberOfFrames()); | 107 reader_->GetDuration().InMicroseconds()); |
| 108 EXPECT_EQ(frames, reader_->GetNumberOfFrames()); | |
| 109 } else { | |
| 110 EXPECT_EQ(reader_->HasKnownDuration(), false); | |
|
DaleCurtis
2017/02/09 18:47:36
If this is only used for testing now rename it as
Raymond Toy
2017/02/09 19:56:05
It's used in audio_decoder.cc in a DVLOG. I'm deba
Raymond Toy
2017/02/09 21:45:06
Renamed to HasKnownDurationForTesting. Still used
DaleCurtis
2017/02/09 22:42:20
Yeah either drop from DVLOG or rename back to what
Raymond Toy
2017/02/09 23:09:28
Renamed.
| |
| 111 } | |
| 100 if (!packet_verification_disabled_) | 112 if (!packet_verification_disabled_) |
| 101 ASSERT_NO_FATAL_FAILURE(VerifyPackets()); | 113 ASSERT_NO_FATAL_FAILURE(VerifyPackets()); |
| 102 ReadAndVerify(hash, trimmed_frames); | 114 ReadAndVerify(hash, expected_frames); |
| 103 } | 115 } |
| 104 | 116 |
| 105 void RunTestFailingDemux(const char* fn) { | 117 void RunTestFailingDemux(const char* fn) { |
| 106 Initialize(fn); | 118 Initialize(fn); |
| 107 EXPECT_FALSE(reader_->Open()); | 119 EXPECT_FALSE(reader_->Open()); |
| 108 } | 120 } |
| 109 | 121 |
| 110 void RunTestFailingDecode(const char* fn) { | 122 void RunTestFailingDecode(const char* fn) { |
| 111 Initialize(fn); | 123 Initialize(fn); |
| 112 EXPECT_TRUE(reader_->Open()); | 124 EXPECT_TRUE(reader_->Open()); |
| 113 std::unique_ptr<AudioBus> decoded_audio_data = | 125 std::vector<std::unique_ptr<AudioBus>> decodedAudioPackets; |
| 114 AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames()); | 126 EXPECT_EQ(reader_->Read(decodedAudioPackets), 0); |
| 115 EXPECT_EQ(reader_->Read(decoded_audio_data.get()), 0); | |
| 116 } | 127 } |
| 117 | 128 |
| 118 void disable_packet_verification() { | 129 void disable_packet_verification() { |
| 119 packet_verification_disabled_ = true; | 130 packet_verification_disabled_ = true; |
| 120 } | 131 } |
| 121 | 132 |
| 122 protected: | 133 protected: |
| 123 scoped_refptr<DecoderBuffer> data_; | 134 scoped_refptr<DecoderBuffer> data_; |
| 124 std::unique_ptr<InMemoryUrlProtocol> protocol_; | 135 std::unique_ptr<InMemoryUrlProtocol> protocol_; |
| 125 std::unique_ptr<AudioFileReader> reader_; | 136 std::unique_ptr<AudioFileReader> reader_; |
| 126 bool packet_verification_disabled_; | 137 bool packet_verification_disabled_; |
| 127 | 138 |
| 128 DISALLOW_COPY_AND_ASSIGN(AudioFileReaderTest); | 139 DISALLOW_COPY_AND_ASSIGN(AudioFileReaderTest); |
| 129 }; | 140 }; |
| 130 | 141 |
| 131 TEST_F(AudioFileReaderTest, WithoutOpen) { | 142 TEST_F(AudioFileReaderTest, WithoutOpen) { |
| 132 Initialize("bear.ogv"); | 143 Initialize("bear.ogv"); |
| 133 } | 144 } |
| 134 | 145 |
| 135 TEST_F(AudioFileReaderTest, InvalidFile) { | 146 TEST_F(AudioFileReaderTest, InvalidFile) { |
| 136 RunTestFailingDemux("ten_byte_file"); | 147 RunTestFailingDemux("ten_byte_file"); |
| 137 } | 148 } |
| 138 | 149 |
| 139 TEST_F(AudioFileReaderTest, InfiniteDuration) { | 150 TEST_F(AudioFileReaderTest, UnknownDuration) { |
| 140 RunTestFailingDemux("bear-320x240-live.webm"); | 151 RunTest("bear-320x240-live.webm", |
|
Raymond Toy
2017/02/09 21:45:07
Presubmit keeps telling me I need to reformat this
DaleCurtis
2017/02/09 22:42:20
Just run git cl format.
Raymond Toy
2017/02/09 23:09:28
Done.
| |
| 152 "-3.59,-2.06,-0.43,2.15,0.77,-0.95,", | |
| 153 2, | |
| 154 44100, | |
| 155 base::TimeDelta::FromMicroseconds(-1), | |
| 156 -1, | |
| 157 121024); | |
| 141 } | 158 } |
| 142 | 159 |
| 143 TEST_F(AudioFileReaderTest, WithVideo) { | 160 TEST_F(AudioFileReaderTest, WithVideo) { |
| 144 RunTest("bear.ogv", | 161 RunTest("bear.ogv", |
| 145 "-2.49,-0.75,0.38,1.60,0.70,-1.22,", | 162 "-0.73,0.92,0.48,-0.07,-0.92,-0.88,", |
| 146 2, | 163 2, |
| 147 44100, | 164 44100, |
| 148 base::TimeDelta::FromMicroseconds(1011520), | 165 base::TimeDelta::FromMicroseconds(1011520), |
| 149 44609, | 166 44609, |
| 150 44609); | 167 45632); |
| 151 } | 168 } |
| 152 | 169 |
| 153 TEST_F(AudioFileReaderTest, Vorbis) { | 170 TEST_F(AudioFileReaderTest, Vorbis) { |
| 154 RunTest("sfx.ogg", | 171 RunTest("sfx.ogg", |
| 155 "4.36,4.81,4.84,4.45,4.61,4.63,", | 172 "2.17,3.31,5.15,6.33,5.97,4.35,", |
| 156 1, | 173 1, |
| 157 44100, | 174 44100, |
| 158 base::TimeDelta::FromMicroseconds(350001), | 175 base::TimeDelta::FromMicroseconds(350001), |
| 159 15436, | 176 15436, |
| 160 15436); | 177 15936); |
| 161 } | 178 } |
| 162 | 179 |
| 163 TEST_F(AudioFileReaderTest, WaveU8) { | 180 TEST_F(AudioFileReaderTest, WaveU8) { |
| 164 RunTest("sfx_u8.wav", | 181 RunTest("sfx_u8.wav", |
| 165 "-1.23,-1.57,-1.14,-0.91,-0.87,-0.07,", | 182 "-1.23,-1.57,-1.14,-0.91,-0.87,-0.07,", |
| 166 1, | 183 1, |
| 167 44100, | 184 44100, |
| 168 base::TimeDelta::FromMicroseconds(288414), | 185 base::TimeDelta::FromMicroseconds(288414), |
| 169 12720, | 186 12720, |
| 170 12719); | 187 12719); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 RunTest("4ch.wav", | 259 RunTest("4ch.wav", |
| 243 "131.71,38.02,130.31,44.89,135.98,42.52,", | 260 "131.71,38.02,130.31,44.89,135.98,42.52,", |
| 244 4, | 261 4, |
| 245 44100, | 262 44100, |
| 246 base::TimeDelta::FromMicroseconds(100001), | 263 base::TimeDelta::FromMicroseconds(100001), |
| 247 4411, | 264 4411, |
| 248 4410); | 265 4410); |
| 249 } | 266 } |
| 250 | 267 |
| 251 } // namespace media | 268 } // namespace media |
| OLD | NEW |