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" |
| 6 |
| 7 #include <memory> |
| 8 |
5 #include "base/logging.h" | 9 #include "base/logging.h" |
6 #include "base/macros.h" | 10 #include "base/macros.h" |
7 #include "base/md5.h" | 11 #include "base/md5.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "build/build_config.h" | 12 #include "build/build_config.h" |
10 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
11 #include "media/base/audio_hash.h" | 14 #include "media/base/audio_hash.h" |
12 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
13 #include "media/base/test_data_util.h" | 16 #include "media/base/test_data_util.h" |
14 #include "media/ffmpeg/ffmpeg_common.h" | 17 #include "media/ffmpeg/ffmpeg_common.h" |
15 #include "media/filters/audio_file_reader.h" | |
16 #include "media/filters/in_memory_url_protocol.h" | 18 #include "media/filters/in_memory_url_protocol.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 | 20 |
19 namespace media { | 21 namespace media { |
20 | 22 |
21 class AudioFileReaderTest : public testing::Test { | 23 class AudioFileReaderTest : public testing::Test { |
22 public: | 24 public: |
23 AudioFileReaderTest() : packet_verification_disabled_(false) {} | 25 AudioFileReaderTest() : packet_verification_disabled_(false) {} |
24 ~AudioFileReaderTest() override {} | 26 ~AudioFileReaderTest() override {} |
25 | 27 |
26 void Initialize(const char* filename) { | 28 void Initialize(const char* filename) { |
27 data_ = ReadTestDataFile(filename); | 29 data_ = ReadTestDataFile(filename); |
28 protocol_.reset( | 30 protocol_.reset( |
29 new InMemoryUrlProtocol(data_->data(), data_->data_size(), false)); | 31 new InMemoryUrlProtocol(data_->data(), data_->data_size(), false)); |
30 reader_.reset(new AudioFileReader(protocol_.get())); | 32 reader_.reset(new AudioFileReader(protocol_.get())); |
31 } | 33 } |
32 | 34 |
33 // Reads and the entire file provided to Initialize(). | 35 // Reads and the entire file provided to Initialize(). |
34 void ReadAndVerify(const char* expected_audio_hash, int expected_frames) { | 36 void ReadAndVerify(const char* expected_audio_hash, int expected_frames) { |
35 scoped_ptr<AudioBus> decoded_audio_data = | 37 std::unique_ptr<AudioBus> decoded_audio_data = |
36 AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames()); | 38 AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames()); |
37 int actual_frames = reader_->Read(decoded_audio_data.get()); | 39 int actual_frames = reader_->Read(decoded_audio_data.get()); |
38 ASSERT_LE(actual_frames, decoded_audio_data->frames()); | 40 ASSERT_LE(actual_frames, decoded_audio_data->frames()); |
39 ASSERT_EQ(expected_frames, actual_frames); | 41 ASSERT_EQ(expected_frames, actual_frames); |
40 | 42 |
41 AudioHash audio_hash; | 43 AudioHash audio_hash; |
42 audio_hash.Update(decoded_audio_data.get(), actual_frames); | 44 audio_hash.Update(decoded_audio_data.get(), actual_frames); |
43 EXPECT_EQ(expected_audio_hash, audio_hash.ToString()); | 45 EXPECT_EQ(expected_audio_hash, audio_hash.ToString()); |
44 } | 46 } |
45 | 47 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 102 } |
101 | 103 |
102 void RunTestFailingDemux(const char* fn) { | 104 void RunTestFailingDemux(const char* fn) { |
103 Initialize(fn); | 105 Initialize(fn); |
104 EXPECT_FALSE(reader_->Open()); | 106 EXPECT_FALSE(reader_->Open()); |
105 } | 107 } |
106 | 108 |
107 void RunTestFailingDecode(const char* fn) { | 109 void RunTestFailingDecode(const char* fn) { |
108 Initialize(fn); | 110 Initialize(fn); |
109 EXPECT_TRUE(reader_->Open()); | 111 EXPECT_TRUE(reader_->Open()); |
110 scoped_ptr<AudioBus> decoded_audio_data = | 112 std::unique_ptr<AudioBus> decoded_audio_data = |
111 AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames()); | 113 AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames()); |
112 EXPECT_EQ(reader_->Read(decoded_audio_data.get()), 0); | 114 EXPECT_EQ(reader_->Read(decoded_audio_data.get()), 0); |
113 } | 115 } |
114 | 116 |
115 void disable_packet_verification() { | 117 void disable_packet_verification() { |
116 packet_verification_disabled_ = true; | 118 packet_verification_disabled_ = true; |
117 } | 119 } |
118 | 120 |
119 protected: | 121 protected: |
120 scoped_refptr<DecoderBuffer> data_; | 122 scoped_refptr<DecoderBuffer> data_; |
121 scoped_ptr<InMemoryUrlProtocol> protocol_; | 123 std::unique_ptr<InMemoryUrlProtocol> protocol_; |
122 scoped_ptr<AudioFileReader> reader_; | 124 std::unique_ptr<AudioFileReader> reader_; |
123 bool packet_verification_disabled_; | 125 bool packet_verification_disabled_; |
124 | 126 |
125 DISALLOW_COPY_AND_ASSIGN(AudioFileReaderTest); | 127 DISALLOW_COPY_AND_ASSIGN(AudioFileReaderTest); |
126 }; | 128 }; |
127 | 129 |
128 TEST_F(AudioFileReaderTest, WithoutOpen) { | 130 TEST_F(AudioFileReaderTest, WithoutOpen) { |
129 Initialize("bear.ogv"); | 131 Initialize("bear.ogv"); |
130 } | 132 } |
131 | 133 |
132 TEST_F(AudioFileReaderTest, InvalidFile) { | 134 TEST_F(AudioFileReaderTest, InvalidFile) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 RunTest("4ch.wav", | 237 RunTest("4ch.wav", |
236 "131.71,38.02,130.31,44.89,135.98,42.52,", | 238 "131.71,38.02,130.31,44.89,135.98,42.52,", |
237 4, | 239 4, |
238 44100, | 240 44100, |
239 base::TimeDelta::FromMicroseconds(100001), | 241 base::TimeDelta::FromMicroseconds(100001), |
240 4411, | 242 4411, |
241 4410); | 243 4410); |
242 } | 244 } |
243 | 245 |
244 } // namespace media | 246 } // namespace media |
OLD | NEW |