Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: media/filters/ffmpeg_demuxer_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <deque> 6 #include <deque>
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 24 matching lines...) Expand all
35 using ::testing::WithArgs; 35 using ::testing::WithArgs;
36 using ::testing::_; 36 using ::testing::_;
37 37
38 namespace media { 38 namespace media {
39 39
40 MATCHER(IsEndOfStreamBuffer, 40 MATCHER(IsEndOfStreamBuffer,
41 std::string(negation ? "isn't" : "is") + " end of stream") { 41 std::string(negation ? "isn't" : "is") + " end of stream") {
42 return arg->end_of_stream(); 42 return arg->end_of_stream();
43 } 43 }
44 44
45 const uint8 kEncryptedMediaInitData[] = { 45 const uint8_t kEncryptedMediaInitData[] = {
46 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 46 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
47 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 47 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
48 }; 48 };
49 49
50 static void EosOnReadDone(bool* got_eos_buffer, 50 static void EosOnReadDone(bool* got_eos_buffer,
51 DemuxerStream::Status status, 51 DemuxerStream::Status status,
52 const scoped_refptr<DecoderBuffer>& buffer) { 52 const scoped_refptr<DecoderBuffer>& buffer) {
53 base::MessageLoop::current()->PostTask( 53 base::MessageLoop::current()->PostTask(
54 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 54 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
55 55
56 EXPECT_EQ(status, DemuxerStream::kOk); 56 EXPECT_EQ(status, DemuxerStream::kOk);
57 if (buffer->end_of_stream()) { 57 if (buffer->end_of_stream()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 void InitializeDemuxerText(bool enable_text) { 105 void InitializeDemuxerText(bool enable_text) {
106 InitializeDemuxerWithTimelineOffset(enable_text, base::Time()); 106 InitializeDemuxerWithTimelineOffset(enable_text, base::Time());
107 } 107 }
108 108
109 void InitializeDemuxer() { 109 void InitializeDemuxer() {
110 InitializeDemuxerText(false); 110 InitializeDemuxerText(false);
111 } 111 }
112 112
113 MOCK_METHOD2(OnReadDoneCalled, void(int, int64)); 113 MOCK_METHOD2(OnReadDoneCalled, void(int, int64_t));
114 114
115 struct ReadExpectation { 115 struct ReadExpectation {
116 ReadExpectation(int size, 116 ReadExpectation(int size,
117 int64 timestamp_us, 117 int64_t timestamp_us,
118 const base::TimeDelta& discard_front_padding, 118 const base::TimeDelta& discard_front_padding,
119 bool is_key_frame) 119 bool is_key_frame)
120 : size(size), 120 : size(size),
121 timestamp_us(timestamp_us), 121 timestamp_us(timestamp_us),
122 discard_front_padding(discard_front_padding), 122 discard_front_padding(discard_front_padding),
123 is_key_frame(is_key_frame) { 123 is_key_frame(is_key_frame) {}
124 }
125 124
126 int size; 125 int size;
127 int64 timestamp_us; 126 int64_t timestamp_us;
128 base::TimeDelta discard_front_padding; 127 base::TimeDelta discard_front_padding;
129 bool is_key_frame; 128 bool is_key_frame;
130 }; 129 };
131 130
132 // Verifies that |buffer| has a specific |size| and |timestamp|. 131 // Verifies that |buffer| has a specific |size| and |timestamp|.
133 // |location| simply indicates where the call to this function was made. 132 // |location| simply indicates where the call to this function was made.
134 // This makes it easier to track down where test failures occur. 133 // This makes it easier to track down where test failures occur.
135 void OnReadDone(const tracked_objects::Location& location, 134 void OnReadDone(const tracked_objects::Location& location,
136 const ReadExpectation& read_expectation, 135 const ReadExpectation& read_expectation,
137 DemuxerStream::Status status, 136 DemuxerStream::Status status,
(...skipping 10 matching lines...) Expand all
148 EXPECT_EQ(read_expectation.discard_front_padding, 147 EXPECT_EQ(read_expectation.discard_front_padding,
149 buffer->discard_padding().first); 148 buffer->discard_padding().first);
150 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame()); 149 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame());
151 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 150 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
152 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us); 151 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us);
153 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 152 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
154 } 153 }
155 154
156 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, 155 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location,
157 int size, 156 int size,
158 int64 timestamp_us, 157 int64_t timestamp_us,
159 bool is_key_frame) { 158 bool is_key_frame) {
160 return NewReadCBWithCheckedDiscard(location, 159 return NewReadCBWithCheckedDiscard(location,
161 size, 160 size,
162 timestamp_us, 161 timestamp_us,
163 base::TimeDelta(), 162 base::TimeDelta(),
164 is_key_frame); 163 is_key_frame);
165 } 164 }
166 165
167 DemuxerStream::ReadCB NewReadCBWithCheckedDiscard( 166 DemuxerStream::ReadCB NewReadCBWithCheckedDiscard(
168 const tracked_objects::Location& location, 167 const tracked_objects::Location& location,
169 int size, 168 int size,
170 int64 timestamp_us, 169 int64_t timestamp_us,
171 base::TimeDelta discard_front_padding, 170 base::TimeDelta discard_front_padding,
172 bool is_key_frame) { 171 bool is_key_frame) {
173 EXPECT_CALL(*this, OnReadDoneCalled(size, timestamp_us)); 172 EXPECT_CALL(*this, OnReadDoneCalled(size, timestamp_us));
174 173
175 struct ReadExpectation read_expectation(size, 174 struct ReadExpectation read_expectation(size,
176 timestamp_us, 175 timestamp_us,
177 discard_front_padding, 176 discard_front_padding,
178 is_key_frame); 177 is_key_frame);
179 178
180 return base::Bind(&FFmpegDemuxerTest::OnReadDone, 179 return base::Bind(&FFmpegDemuxerTest::OnReadDone,
181 base::Unretained(this), 180 base::Unretained(this),
182 location, 181 location,
183 read_expectation); 182 read_expectation);
184 } 183 }
185 184
186 MOCK_METHOD2(OnEncryptedMediaInitData, 185 MOCK_METHOD2(OnEncryptedMediaInitData,
187 void(EmeInitDataType init_data_type, 186 void(EmeInitDataType init_data_type,
188 const std::vector<uint8>& init_data)); 187 const std::vector<uint8_t>& init_data));
189 188
190 // Accessor to demuxer internals. 189 // Accessor to demuxer internals.
191 void set_duration_known(bool duration_known) { 190 void set_duration_known(bool duration_known) {
192 demuxer_->duration_known_ = duration_known; 191 demuxer_->duration_known_ = duration_known;
193 } 192 }
194 193
195 bool IsStreamStopped(DemuxerStream::Type type) { 194 bool IsStreamStopped(DemuxerStream::Type type) {
196 DemuxerStream* stream = demuxer_->GetStream(type); 195 DemuxerStream* stream = demuxer_->GetStream(type);
197 CHECK(stream); 196 CHECK(stream);
198 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_; 197 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); 369 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec());
371 370
372 // Unknown stream should never be present. 371 // Unknown stream should never be present.
373 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); 372 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN));
374 } 373 }
375 374
376 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) { 375 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) {
377 EXPECT_CALL(*this, 376 EXPECT_CALL(*this,
378 OnEncryptedMediaInitData( 377 OnEncryptedMediaInitData(
379 EmeInitDataType::WEBM, 378 EmeInitDataType::WEBM,
380 std::vector<uint8>(kEncryptedMediaInitData, 379 std::vector<uint8_t>(kEncryptedMediaInitData,
381 kEncryptedMediaInitData + 380 kEncryptedMediaInitData +
382 arraysize(kEncryptedMediaInitData)))) 381 arraysize(kEncryptedMediaInitData))))
383 .Times(Exactly(2)); 382 .Times(Exactly(2));
384 383
385 CreateDemuxer("bear-320x240-av_enc-av.webm"); 384 CreateDemuxer("bear-320x240-av_enc-av.webm");
386 InitializeDemuxer(); 385 InitializeDemuxer();
387 } 386 }
388 387
389 TEST_F(FFmpegDemuxerTest, Read_Audio) { 388 TEST_F(FFmpegDemuxerTest, Read_Audio) {
390 // We test that on a successful audio packet read. 389 // We test that on a successful audio packet read.
391 CreateDemuxer("bear-320x240.webm"); 390 CreateDemuxer("bear-320x240.webm");
392 InitializeDemuxer(); 391 InitializeDemuxer();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 message_loop_.Run(); 436 message_loop_.Run();
438 } 437 }
439 438
440 TEST_F(FFmpegDemuxerTest, SeekInitialized_NoVideoStartTime) { 439 TEST_F(FFmpegDemuxerTest, SeekInitialized_NoVideoStartTime) {
441 CreateDemuxer("audio-start-time-only.webm"); 440 CreateDemuxer("audio-start-time-only.webm");
442 InitializeDemuxer(); 441 InitializeDemuxer();
443 EXPECT_EQ(0, preferred_seeking_stream_index()); 442 EXPECT_EQ(0, preferred_seeking_stream_index());
444 } 443 }
445 444
446 TEST_F(FFmpegDemuxerTest, Read_VideoPositiveStartTime) { 445 TEST_F(FFmpegDemuxerTest, Read_VideoPositiveStartTime) {
447 const int64 kTimelineOffsetMs = 1352550896000LL; 446 const int64_t kTimelineOffsetMs = 1352550896000LL;
448 447
449 // Test the start time is the first timestamp of the video and audio stream. 448 // Test the start time is the first timestamp of the video and audio stream.
450 CreateDemuxer("nonzero-start-time.webm"); 449 CreateDemuxer("nonzero-start-time.webm");
451 InitializeDemuxerWithTimelineOffset( 450 InitializeDemuxerWithTimelineOffset(
452 false, base::Time::FromJsTime(kTimelineOffsetMs)); 451 false, base::Time::FromJsTime(kTimelineOffsetMs));
453 452
454 // Attempt a read from the video stream and run the message loop until done. 453 // Attempt a read from the video stream and run the message loop until done.
455 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 454 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
456 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 455 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
457 456
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 ASSERT_TRUE(audio); 975 ASSERT_TRUE(audio);
977 976
978 // Seek to near the end of the file 977 // Seek to near the end of the file
979 WaitableMessageLoopEvent event; 978 WaitableMessageLoopEvent event;
980 demuxer_->Seek(.9 * audio->duration(), event.GetPipelineStatusCB()); 979 demuxer_->Seek(.9 * audio->duration(), event.GetPipelineStatusCB());
981 event.RunAndWaitForStatus(PIPELINE_OK); 980 event.RunAndWaitForStatus(PIPELINE_OK);
982 981
983 // Verify that seeking to the end read only a small portion of the file. 982 // Verify that seeking to the end read only a small portion of the file.
984 // Slow seeks that read sequentially up to the seek point will read too many 983 // Slow seeks that read sequentially up to the seek point will read too many
985 // bytes and fail this check. 984 // bytes and fail this check.
986 int64 file_size = 0; 985 int64_t file_size = 0;
987 ASSERT_TRUE(data_source_->GetSize(&file_size)); 986 ASSERT_TRUE(data_source_->GetSize(&file_size));
988 EXPECT_LT(data_source_->bytes_read_for_testing(), (file_size * .25)); 987 EXPECT_LT(data_source_->bytes_read_for_testing(), (file_size * .25));
989 } 988 }
990 989
991 // MP3s should seek quickly without sequentially reading up to the seek point. 990 // MP3s should seek quickly without sequentially reading up to the seek point.
992 // VBR vs CBR and the presence/absence of TOC influence the seeking algorithm. 991 // VBR vs CBR and the presence/absence of TOC influence the seeking algorithm.
993 // See http://crbug.com/530043 and FFmpeg flag AVFMT_FLAG_FAST_SEEK. 992 // See http://crbug.com/530043 and FFmpeg flag AVFMT_FLAG_FAST_SEEK.
994 INSTANTIATE_TEST_CASE_P(, Mp3SeekFFmpegDemuxerTest, 993 INSTANTIATE_TEST_CASE_P(, Mp3SeekFFmpegDemuxerTest,
995 ::testing::Values("bear-audio-10s-CBR-has-TOC.mp3", 994 ::testing::Values("bear-audio-10s-CBR-has-TOC.mp3",
996 "bear-audio-10s-CBR-no-TOC.mp3", 995 "bear-audio-10s-CBR-no-TOC.mp3",
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1122
1124 video->Read(NewReadCB(FROM_HERE, 3569, 66733, true)); 1123 video->Read(NewReadCB(FROM_HERE, 3569, 66733, true));
1125 message_loop_.Run(); 1124 message_loop_.Run();
1126 1125
1127 video->Read(NewReadCB(FROM_HERE, 1042, 200200, false)); 1126 video->Read(NewReadCB(FROM_HERE, 1042, 200200, false));
1128 message_loop_.Run(); 1127 message_loop_.Run();
1129 } 1128 }
1130 #endif 1129 #endif
1131 1130
1132 } // namespace media 1131 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698