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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "media/base/mock_filters.h" | 7 #include "media/base/mock_filters.h" |
8 #include "media/base/test_data_util.h" | 8 #include "media/base/test_data_util.h" |
9 #include "media/ffmpeg/ffmpeg_common.h" | 9 #include "media/ffmpeg/ffmpeg_common.h" |
10 #include "media/filters/ffmpeg_glue.h" | 10 #include "media/filters/ffmpeg_glue.h" |
11 #include "media/filters/in_memory_url_protocol.h" | 11 #include "media/filters/in_memory_url_protocol.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 using ::testing::_; | 14 using ::testing::_; |
15 using ::testing::DoAll; | 15 using ::testing::DoAll; |
16 using ::testing::InSequence; | 16 using ::testing::InSequence; |
17 using ::testing::Return; | 17 using ::testing::Return; |
18 using ::testing::SetArgumentPointee; | 18 using ::testing::SetArgumentPointee; |
19 using ::testing::StrictMock; | 19 using ::testing::StrictMock; |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class MockProtocol : public FFmpegURLProtocol { | 23 class MockProtocol : public FFmpegURLProtocol { |
24 public: | 24 public: |
25 MockProtocol() {} | 25 MockProtocol() {} |
26 | 26 |
27 MOCK_METHOD2(Read, int(int size, uint8* data)); | 27 MOCK_METHOD2(Read, int(int size, uint8_t* data)); |
28 MOCK_METHOD1(GetPosition, bool(int64* position_out)); | 28 MOCK_METHOD1(GetPosition, bool(int64_t* position_out)); |
29 MOCK_METHOD1(SetPosition, bool(int64 position)); | 29 MOCK_METHOD1(SetPosition, bool(int64_t position)); |
30 MOCK_METHOD1(GetSize, bool(int64* size_out)); | 30 MOCK_METHOD1(GetSize, bool(int64_t* size_out)); |
31 MOCK_METHOD0(IsStreaming, bool()); | 31 MOCK_METHOD0(IsStreaming, bool()); |
32 | 32 |
33 private: | 33 private: |
34 DISALLOW_COPY_AND_ASSIGN(MockProtocol); | 34 DISALLOW_COPY_AND_ASSIGN(MockProtocol); |
35 }; | 35 }; |
36 | 36 |
37 class FFmpegGlueTest : public ::testing::Test { | 37 class FFmpegGlueTest : public ::testing::Test { |
38 public: | 38 public: |
39 FFmpegGlueTest() | 39 FFmpegGlueTest() |
40 : protocol_(new StrictMock<MockProtocol>()) { | 40 : protocol_(new StrictMock<MockProtocol>()) { |
41 // IsStreaming() is called when opening. | 41 // IsStreaming() is called when opening. |
42 EXPECT_CALL(*protocol_.get(), IsStreaming()).WillOnce(Return(true)); | 42 EXPECT_CALL(*protocol_.get(), IsStreaming()).WillOnce(Return(true)); |
43 glue_.reset(new FFmpegGlue(protocol_.get())); | 43 glue_.reset(new FFmpegGlue(protocol_.get())); |
44 CHECK(glue_->format_context()); | 44 CHECK(glue_->format_context()); |
45 CHECK(glue_->format_context()->pb); | 45 CHECK(glue_->format_context()->pb); |
46 } | 46 } |
47 | 47 |
48 ~FFmpegGlueTest() override { | 48 ~FFmpegGlueTest() override { |
49 // Ensure |glue_| and |protocol_| are still alive. | 49 // Ensure |glue_| and |protocol_| are still alive. |
50 CHECK(glue_.get()); | 50 CHECK(glue_.get()); |
51 CHECK(protocol_.get()); | 51 CHECK(protocol_.get()); |
52 | 52 |
53 // |protocol_| should outlive |glue_|, so ensure it's destructed first. | 53 // |protocol_| should outlive |glue_|, so ensure it's destructed first. |
54 glue_.reset(); | 54 glue_.reset(); |
55 } | 55 } |
56 | 56 |
57 int ReadPacket(int size, uint8* data) { | 57 int ReadPacket(int size, uint8_t* data) { |
58 return glue_->format_context()->pb->read_packet( | 58 return glue_->format_context()->pb->read_packet( |
59 protocol_.get(), data, size); | 59 protocol_.get(), data, size); |
60 } | 60 } |
61 | 61 |
62 int64 Seek(int64 offset, int whence) { | 62 int64_t Seek(int64_t offset, int whence) { |
63 return glue_->format_context()->pb->seek(protocol_.get(), offset, whence); | 63 return glue_->format_context()->pb->seek(protocol_.get(), offset, whence); |
64 } | 64 } |
65 | 65 |
66 protected: | 66 protected: |
67 scoped_ptr<FFmpegGlue> glue_; | 67 scoped_ptr<FFmpegGlue> glue_; |
68 scoped_ptr< StrictMock<MockProtocol> > protocol_; | 68 scoped_ptr< StrictMock<MockProtocol> > protocol_; |
69 | 69 |
70 private: | 70 private: |
71 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueTest); | 71 DISALLOW_COPY_AND_ASSIGN(FFmpegGlueTest); |
72 }; | 72 }; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // Ensure writing has been disabled. | 110 // Ensure writing has been disabled. |
111 TEST_F(FFmpegGlueTest, Write) { | 111 TEST_F(FFmpegGlueTest, Write) { |
112 ASSERT_FALSE(glue_->format_context()->pb->write_packet); | 112 ASSERT_FALSE(glue_->format_context()->pb->write_packet); |
113 ASSERT_FALSE(glue_->format_context()->pb->write_flag); | 113 ASSERT_FALSE(glue_->format_context()->pb->write_flag); |
114 } | 114 } |
115 | 115 |
116 // Test both successful and unsuccessful reads pass through correctly. | 116 // Test both successful and unsuccessful reads pass through correctly. |
117 TEST_F(FFmpegGlueTest, Read) { | 117 TEST_F(FFmpegGlueTest, Read) { |
118 const int kBufferSize = 16; | 118 const int kBufferSize = 16; |
119 uint8 buffer[kBufferSize]; | 119 uint8_t buffer[kBufferSize]; |
120 | 120 |
121 // Reads are for the most part straight-through calls to Read(). | 121 // Reads are for the most part straight-through calls to Read(). |
122 InSequence s; | 122 InSequence s; |
123 EXPECT_CALL(*protocol_, Read(0, buffer)) | 123 EXPECT_CALL(*protocol_, Read(0, buffer)) |
124 .WillOnce(Return(0)); | 124 .WillOnce(Return(0)); |
125 EXPECT_CALL(*protocol_, Read(kBufferSize, buffer)) | 125 EXPECT_CALL(*protocol_, Read(kBufferSize, buffer)) |
126 .WillOnce(Return(kBufferSize)); | 126 .WillOnce(Return(kBufferSize)); |
127 EXPECT_CALL(*protocol_, Read(kBufferSize, buffer)) | 127 EXPECT_CALL(*protocol_, Read(kBufferSize, buffer)) |
128 .WillOnce(Return(DataSource::kReadError)); | 128 .WillOnce(Return(DataSource::kReadError)); |
129 | 129 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 ASSERT_GT(glue_->format_context()->nb_streams, 0u); | 236 ASSERT_GT(glue_->format_context()->nb_streams, 0u); |
237 | 237 |
238 // Pick the audio stream (1) so this works when the ffmpeg video decoders are | 238 // Pick the audio stream (1) so this works when the ffmpeg video decoders are |
239 // disabled. | 239 // disabled. |
240 AVCodecContext* context = glue_->format_context()->streams[1]->codec; | 240 AVCodecContext* context = glue_->format_context()->streams[1]->codec; |
241 ASSERT_EQ(0, avcodec_open2( | 241 ASSERT_EQ(0, avcodec_open2( |
242 context, avcodec_find_decoder(context->codec_id), NULL)); | 242 context, avcodec_find_decoder(context->codec_id), NULL)); |
243 } | 243 } |
244 | 244 |
245 } // namespace media | 245 } // namespace media |
OLD | NEW |