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/ffmpeg_glue.h" | 5 #include "media/filters/ffmpeg_glue.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/test/histogram_tester.h" |
| 14 #include "media/base/container_names.h" |
13 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
14 #include "media/base/test_data_util.h" | 16 #include "media/base/test_data_util.h" |
15 #include "media/ffmpeg/ffmpeg_common.h" | 17 #include "media/ffmpeg/ffmpeg_common.h" |
16 #include "media/ffmpeg/ffmpeg_deleters.h" | 18 #include "media/ffmpeg/ffmpeg_deleters.h" |
17 #include "media/filters/in_memory_url_protocol.h" | 19 #include "media/filters/in_memory_url_protocol.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 using ::testing::_; | 22 using ::testing::_; |
21 using ::testing::DoAll; | 23 using ::testing::DoAll; |
22 using ::testing::InSequence; | 24 using ::testing::InSequence; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ~FFmpegGlueTest() override { | 56 ~FFmpegGlueTest() override { |
55 // Ensure |glue_| and |protocol_| are still alive. | 57 // Ensure |glue_| and |protocol_| are still alive. |
56 CHECK(glue_.get()); | 58 CHECK(glue_.get()); |
57 CHECK(protocol_.get()); | 59 CHECK(protocol_.get()); |
58 | 60 |
59 // |protocol_| should outlive |glue_|, so ensure it's destructed first. | 61 // |protocol_| should outlive |glue_|, so ensure it's destructed first. |
60 glue_.reset(); | 62 glue_.reset(); |
61 } | 63 } |
62 | 64 |
63 int ReadPacket(int size, uint8_t* data) { | 65 int ReadPacket(int size, uint8_t* data) { |
64 return glue_->format_context()->pb->read_packet( | 66 return glue_->format_context()->pb->read_packet(protocol_.get(), data, |
65 protocol_.get(), data, size); | 67 size); |
66 } | 68 } |
67 | 69 |
68 int64_t Seek(int64_t offset, int whence) { | 70 int64_t Seek(int64_t offset, int whence) { |
69 return glue_->format_context()->pb->seek(protocol_.get(), offset, whence); | 71 return glue_->format_context()->pb->seek(protocol_.get(), offset, whence); |
70 } | 72 } |
71 | 73 |
72 protected: | 74 protected: |
73 std::unique_ptr<FFmpegGlue> glue_; | 75 std::unique_ptr<FFmpegGlue> glue_; |
74 std::unique_ptr<StrictMock<MockProtocol>> protocol_; | 76 std::unique_ptr<StrictMock<MockProtocol>> protocol_; |
75 | 77 |
(...skipping 30 matching lines...) Expand all Loading... |
106 protected: | 108 protected: |
107 std::unique_ptr<FFmpegGlue> glue_; | 109 std::unique_ptr<FFmpegGlue> glue_; |
108 | 110 |
109 private: | 111 private: |
110 std::unique_ptr<InMemoryUrlProtocol> protocol_; | 112 std::unique_ptr<InMemoryUrlProtocol> protocol_; |
111 scoped_refptr<DecoderBuffer> data_; | 113 scoped_refptr<DecoderBuffer> data_; |
112 | 114 |
113 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueDestructionTest); | 115 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueDestructionTest); |
114 }; | 116 }; |
115 | 117 |
| 118 // Tests that ensure we are using the correct AVInputFormat name given by ffmpeg |
| 119 // for supported containers. |
| 120 class FFmpegGlueContainerTest : public FFmpegGlueDestructionTest { |
| 121 public: |
| 122 FFmpegGlueContainerTest() {} |
| 123 ~FFmpegGlueContainerTest() override {} |
| 124 |
| 125 protected: |
| 126 void InitializeAndOpen(const char* filename) { |
| 127 Initialize(filename); |
| 128 ASSERT_TRUE(glue_->OpenContext()); |
| 129 } |
| 130 |
| 131 void ExpectContainer(container_names::MediaContainerName container) { |
| 132 histogram_tester_.ExpectUniqueSample("Media.DetectedContainer", container, |
| 133 1); |
| 134 } |
| 135 |
| 136 private: |
| 137 base::HistogramTester histogram_tester_; |
| 138 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueContainerTest); |
| 139 }; |
| 140 |
116 // Ensure writing has been disabled. | 141 // Ensure writing has been disabled. |
117 TEST_F(FFmpegGlueTest, Write) { | 142 TEST_F(FFmpegGlueTest, Write) { |
118 ASSERT_FALSE(glue_->format_context()->pb->write_packet); | 143 ASSERT_FALSE(glue_->format_context()->pb->write_packet); |
119 ASSERT_FALSE(glue_->format_context()->pb->write_flag); | 144 ASSERT_FALSE(glue_->format_context()->pb->write_flag); |
120 } | 145 } |
121 | 146 |
122 // Test both successful and unsuccessful reads pass through correctly. | 147 // Test both successful and unsuccessful reads pass through correctly. |
123 TEST_F(FFmpegGlueTest, Read) { | 148 TEST_F(FFmpegGlueTest, Read) { |
124 const int kBufferSize = 16; | 149 const int kBufferSize = 16; |
125 uint8_t buffer[kBufferSize]; | 150 uint8_t buffer[kBufferSize]; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // and ordering to ensure |context| is destructed before |glue_|. | 271 // and ordering to ensure |context| is destructed before |glue_|. |
247 // Pick the audio stream (1) so this works when the ffmpeg video decoders are | 272 // Pick the audio stream (1) so this works when the ffmpeg video decoders are |
248 // disabled. | 273 // disabled. |
249 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> context( | 274 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> context( |
250 AVStreamToAVCodecContext(glue_->format_context()->streams[1])); | 275 AVStreamToAVCodecContext(glue_->format_context()->streams[1])); |
251 ASSERT_NE(nullptr, context.get()); | 276 ASSERT_NE(nullptr, context.get()); |
252 ASSERT_EQ(0, avcodec_open2(context.get(), | 277 ASSERT_EQ(0, avcodec_open2(context.get(), |
253 avcodec_find_decoder(context->codec_id), nullptr)); | 278 avcodec_find_decoder(context->codec_id), nullptr)); |
254 } | 279 } |
255 | 280 |
| 281 TEST_F(FFmpegGlueContainerTest, OGG) { |
| 282 InitializeAndOpen("sfx.ogg"); |
| 283 ExpectContainer(container_names::CONTAINER_OGG); |
| 284 } |
| 285 |
| 286 TEST_F(FFmpegGlueContainerTest, WEBM) { |
| 287 InitializeAndOpen("sfx-opus-441.webm"); |
| 288 ExpectContainer(container_names::CONTAINER_WEBM); |
| 289 } |
| 290 |
| 291 TEST_F(FFmpegGlueContainerTest, FLAC) { |
| 292 InitializeAndOpen("sfx.flac"); |
| 293 ExpectContainer(container_names::CONTAINER_FLAC); |
| 294 } |
| 295 |
| 296 TEST_F(FFmpegGlueContainerTest, WAV) { |
| 297 InitializeAndOpen("sfx_s16le.wav"); |
| 298 ExpectContainer(container_names::CONTAINER_WAV); |
| 299 } |
| 300 |
| 301 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 302 TEST_F(FFmpegGlueContainerTest, MOV) { |
| 303 InitializeAndOpen("sfx.m4a"); |
| 304 ExpectContainer(container_names::CONTAINER_MOV); |
| 305 } |
| 306 |
| 307 TEST_F(FFmpegGlueContainerTest, MP3) { |
| 308 InitializeAndOpen("sfx.mp3"); |
| 309 ExpectContainer(container_names::CONTAINER_MP3); |
| 310 } |
| 311 |
| 312 TEST_F(FFmpegGlueContainerTest, AAC) { |
| 313 InitializeAndOpen("sfx.adts"); |
| 314 ExpectContainer(container_names::CONTAINER_AAC); |
| 315 } |
| 316 |
| 317 #if defined(OS_CHROMEOS) |
| 318 TEST_F(FFmpegGlueContainerTest, AVI) { |
| 319 InitializeAndOpen("bear.avi"); |
| 320 ExpectContainer(container_names::CONTAINER_AVI); |
| 321 } |
| 322 |
| 323 TEST_F(FFmpegGlueContainerTest, AMR) { |
| 324 InitializeAndOpen("bear.amr"); |
| 325 ExpectContainer(container_names::CONTAINER_AMR); |
| 326 } |
| 327 #endif // defined(OS_CHROMEOS) |
| 328 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 329 |
| 330 // Probe something unsupported to ensure we fall back to the our internal guess. |
| 331 TEST_F(FFmpegGlueContainerTest, FLV) { |
| 332 Initialize("bear.flv"); |
| 333 ASSERT_FALSE(glue_->OpenContext()); |
| 334 ExpectContainer(container_names::CONTAINER_FLV); |
| 335 } |
| 336 |
256 } // namespace media | 337 } // namespace media |
OLD | NEW |