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" | 13 #include "base/test/histogram_tester.h" |
14 #include "media/base/container_names.h" | 14 #include "media/base/container_names.h" |
15 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
16 #include "media/base/test_data_util.h" | 16 #include "media/base/test_data_util.h" |
17 #include "media/ffmpeg/ffmpeg_common.h" | 17 #include "media/ffmpeg/ffmpeg_common.h" |
18 #include "media/ffmpeg/ffmpeg_deleters.h" | 18 #include "media/ffmpeg/ffmpeg_deleters.h" |
19 #include "media/filters/in_memory_url_protocol.h" | 19 #include "media/filters/in_memory_url_protocol.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 using ::testing::_; | 22 using ::testing::_; |
23 using ::testing::DoAll; | 23 using ::testing::DoAll; |
24 using ::testing::InSequence; | 24 using ::testing::InSequence; |
25 using ::testing::Return; | 25 using ::testing::Return; |
26 using ::testing::SetArgumentPointee; | 26 using ::testing::SetArgPointee; |
27 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
28 | 28 |
29 namespace media { | 29 namespace media { |
30 | 30 |
31 class MockProtocol : public FFmpegURLProtocol { | 31 class MockProtocol : public FFmpegURLProtocol { |
32 public: | 32 public: |
33 MockProtocol() {} | 33 MockProtocol() {} |
34 | 34 |
35 MOCK_METHOD2(Read, int(int size, uint8_t* data)); | 35 MOCK_METHOD2(Read, int(int size, uint8_t* data)); |
36 MOCK_METHOD1(GetPosition, bool(int64_t* position_out)); | 36 MOCK_METHOD1(GetPosition, bool(int64_t* position_out)); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 TEST_F(FFmpegGlueTest, Seek) { | 167 TEST_F(FFmpegGlueTest, Seek) { |
168 // SEEK_SET should be a straight-through call to SetPosition(), which when | 168 // SEEK_SET should be a straight-through call to SetPosition(), which when |
169 // successful will return the result from GetPosition(). | 169 // successful will return the result from GetPosition(). |
170 InSequence s; | 170 InSequence s; |
171 EXPECT_CALL(*protocol_, SetPosition(-16)) | 171 EXPECT_CALL(*protocol_, SetPosition(-16)) |
172 .WillOnce(Return(false)); | 172 .WillOnce(Return(false)); |
173 | 173 |
174 EXPECT_CALL(*protocol_, SetPosition(16)) | 174 EXPECT_CALL(*protocol_, SetPosition(16)) |
175 .WillOnce(Return(true)); | 175 .WillOnce(Return(true)); |
176 EXPECT_CALL(*protocol_, GetPosition(_)) | 176 EXPECT_CALL(*protocol_, GetPosition(_)) |
177 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 177 .WillOnce(DoAll(SetArgPointee<0>(8), Return(true))); |
178 | 178 |
179 EXPECT_EQ(AVERROR(EIO), Seek(-16, SEEK_SET)); | 179 EXPECT_EQ(AVERROR(EIO), Seek(-16, SEEK_SET)); |
180 EXPECT_EQ(8, Seek(16, SEEK_SET)); | 180 EXPECT_EQ(8, Seek(16, SEEK_SET)); |
181 | 181 |
182 // SEEK_CUR should call GetPosition() first, and if it succeeds add the offset | 182 // SEEK_CUR should call GetPosition() first, and if it succeeds add the offset |
183 // to the result then call SetPosition()+GetPosition(). | 183 // to the result then call SetPosition()+GetPosition(). |
184 EXPECT_CALL(*protocol_, GetPosition(_)) | 184 EXPECT_CALL(*protocol_, GetPosition(_)) |
185 .WillOnce(Return(false)); | 185 .WillOnce(Return(false)); |
186 | 186 |
187 EXPECT_CALL(*protocol_, GetPosition(_)) | 187 EXPECT_CALL(*protocol_, GetPosition(_)) |
188 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 188 .WillOnce(DoAll(SetArgPointee<0>(8), Return(true))); |
189 EXPECT_CALL(*protocol_, SetPosition(16)) | 189 EXPECT_CALL(*protocol_, SetPosition(16)) |
190 .WillOnce(Return(false)); | 190 .WillOnce(Return(false)); |
191 | 191 |
192 EXPECT_CALL(*protocol_, GetPosition(_)) | 192 EXPECT_CALL(*protocol_, GetPosition(_)) |
193 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 193 .WillOnce(DoAll(SetArgPointee<0>(8), Return(true))); |
194 EXPECT_CALL(*protocol_, SetPosition(16)) | 194 EXPECT_CALL(*protocol_, SetPosition(16)) |
195 .WillOnce(Return(true)); | 195 .WillOnce(Return(true)); |
196 EXPECT_CALL(*protocol_, GetPosition(_)) | 196 EXPECT_CALL(*protocol_, GetPosition(_)) |
197 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 197 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))); |
198 | 198 |
199 EXPECT_EQ(AVERROR(EIO), Seek(8, SEEK_CUR)); | 199 EXPECT_EQ(AVERROR(EIO), Seek(8, SEEK_CUR)); |
200 EXPECT_EQ(AVERROR(EIO), Seek(8, SEEK_CUR)); | 200 EXPECT_EQ(AVERROR(EIO), Seek(8, SEEK_CUR)); |
201 EXPECT_EQ(16, Seek(8, SEEK_CUR)); | 201 EXPECT_EQ(16, Seek(8, SEEK_CUR)); |
202 | 202 |
203 // SEEK_END should call GetSize() first, and if it succeeds add the offset | 203 // SEEK_END should call GetSize() first, and if it succeeds add the offset |
204 // to the result then call SetPosition()+GetPosition(). | 204 // to the result then call SetPosition()+GetPosition(). |
205 EXPECT_CALL(*protocol_, GetSize(_)) | 205 EXPECT_CALL(*protocol_, GetSize(_)) |
206 .WillOnce(Return(false)); | 206 .WillOnce(Return(false)); |
207 | 207 |
208 EXPECT_CALL(*protocol_, GetSize(_)) | 208 EXPECT_CALL(*protocol_, GetSize(_)) |
209 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 209 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))); |
210 EXPECT_CALL(*protocol_, SetPosition(8)) | 210 EXPECT_CALL(*protocol_, SetPosition(8)) |
211 .WillOnce(Return(false)); | 211 .WillOnce(Return(false)); |
212 | 212 |
213 EXPECT_CALL(*protocol_, GetSize(_)) | 213 EXPECT_CALL(*protocol_, GetSize(_)) |
214 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 214 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))); |
215 EXPECT_CALL(*protocol_, SetPosition(8)) | 215 EXPECT_CALL(*protocol_, SetPosition(8)) |
216 .WillOnce(Return(true)); | 216 .WillOnce(Return(true)); |
217 EXPECT_CALL(*protocol_, GetPosition(_)) | 217 EXPECT_CALL(*protocol_, GetPosition(_)) |
218 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 218 .WillOnce(DoAll(SetArgPointee<0>(8), Return(true))); |
219 | 219 |
220 EXPECT_EQ(AVERROR(EIO), Seek(-8, SEEK_END)); | 220 EXPECT_EQ(AVERROR(EIO), Seek(-8, SEEK_END)); |
221 EXPECT_EQ(AVERROR(EIO), Seek(-8, SEEK_END)); | 221 EXPECT_EQ(AVERROR(EIO), Seek(-8, SEEK_END)); |
222 EXPECT_EQ(8, Seek(-8, SEEK_END)); | 222 EXPECT_EQ(8, Seek(-8, SEEK_END)); |
223 | 223 |
224 // AVSEEK_SIZE should be a straight-through call to GetSize(). | 224 // AVSEEK_SIZE should be a straight-through call to GetSize(). |
225 EXPECT_CALL(*protocol_, GetSize(_)) | 225 EXPECT_CALL(*protocol_, GetSize(_)) |
226 .WillOnce(Return(false)); | 226 .WillOnce(Return(false)); |
227 | 227 |
228 EXPECT_CALL(*protocol_, GetSize(_)) | 228 EXPECT_CALL(*protocol_, GetSize(_)) |
229 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 229 .WillOnce(DoAll(SetArgPointee<0>(16), Return(true))); |
230 | 230 |
231 EXPECT_EQ(AVERROR(EIO), Seek(0, AVSEEK_SIZE)); | 231 EXPECT_EQ(AVERROR(EIO), Seek(0, AVSEEK_SIZE)); |
232 EXPECT_EQ(16, Seek(0, AVSEEK_SIZE)); | 232 EXPECT_EQ(16, Seek(0, AVSEEK_SIZE)); |
233 } | 233 } |
234 | 234 |
235 // Ensure destruction release the appropriate resources when OpenContext() is | 235 // Ensure destruction release the appropriate resources when OpenContext() is |
236 // never called. | 236 // never called. |
237 TEST_F(FFmpegGlueDestructionTest, WithoutOpen) { | 237 TEST_F(FFmpegGlueDestructionTest, WithoutOpen) { |
238 Initialize("ten_byte_file"); | 238 Initialize("ten_byte_file"); |
239 } | 239 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) | 328 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
329 | 329 |
330 // Probe something unsupported to ensure we fall back to the our internal guess. | 330 // Probe something unsupported to ensure we fall back to the our internal guess. |
331 TEST_F(FFmpegGlueContainerTest, FLV) { | 331 TEST_F(FFmpegGlueContainerTest, FLV) { |
332 Initialize("bear.flv"); | 332 Initialize("bear.flv"); |
333 ASSERT_FALSE(glue_->OpenContext()); | 333 ASSERT_FALSE(glue_->OpenContext()); |
334 ExpectContainer(container_names::CONTAINER_FLV); | 334 ExpectContainer(container_names::CONTAINER_FLV); |
335 } | 335 } |
336 | 336 |
337 } // namespace media | 337 } // namespace media |
OLD | NEW |