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

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

Issue 11410052: Refactor FFmpegURLProtocol code from FFmpegDemuxer into BlockingUrlProtocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
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/file_path.h" 10 #include "base/file_path.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 demuxer_->Stop(NewExpectedClosure()); 65 demuxer_->Stop(NewExpectedClosure());
66 } 66 }
67 67
68 // Finish up any remaining tasks. 68 // Finish up any remaining tasks.
69 message_loop_.RunAllPending(); 69 message_loop_.RunAllPending();
70 // Release the reference to the demuxer. 70 // Release the reference to the demuxer.
71 demuxer_ = NULL; 71 demuxer_ = NULL;
72 } 72 }
73 73
74 void CreateDemuxer(const std::string& name) { 74 void CreateDemuxer(const std::string& name) {
75 CreateDemuxer(name, false);
76 }
77
78 void CreateDemuxer(const std::string& name, bool disable_file_size) {
79 CHECK(!demuxer_); 75 CHECK(!demuxer_);
80 76
81 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); 77 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber());
82 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); 78 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber());
83 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 79 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
84 80
85 CreateDataSource(name, disable_file_size); 81 CreateDataSource(name);
86 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), 82 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(),
87 data_source_); 83 data_source_);
88 } 84 }
89 85
90 MOCK_METHOD1(CheckPoint, void(int v)); 86 MOCK_METHOD1(CheckPoint, void(int v));
91 87
92 void InitializeDemuxer() { 88 void InitializeDemuxer() {
93 EXPECT_CALL(host_, SetDuration(_)); 89 EXPECT_CALL(host_, SetDuration(_));
94 demuxer_->Initialize(&host_, NewExpectedStatusCB(PIPELINE_OK)); 90 demuxer_->Initialize(&host_, NewExpectedStatusCB(PIPELINE_OK));
95 message_loop_.RunAllPending(); 91 message_loop_.RunAllPending();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const int kMaxBuffers = 170; 149 const int kMaxBuffers = 170;
154 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { 150 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) {
155 audio->Read(base::Bind(&EosOnReadDone, &got_eos_buffer)); 151 audio->Read(base::Bind(&EosOnReadDone, &got_eos_buffer));
156 message_loop_.RunAllPending(); 152 message_loop_.RunAllPending();
157 } 153 }
158 154
159 EXPECT_TRUE(got_eos_buffer); 155 EXPECT_TRUE(got_eos_buffer);
160 } 156 }
161 157
162 private: 158 private:
163 void CreateDataSource(const std::string& name, bool disable_file_size) { 159 void CreateDataSource(const std::string& name) {
164 CHECK(!data_source_); 160 CHECK(!data_source_);
165 161
166 FilePath file_path; 162 FilePath file_path;
167 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); 163 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path));
168 164
169 file_path = file_path.Append(FILE_PATH_LITERAL("media")) 165 file_path = file_path.Append(FILE_PATH_LITERAL("media"))
170 .Append(FILE_PATH_LITERAL("test")) 166 .Append(FILE_PATH_LITERAL("test"))
171 .Append(FILE_PATH_LITERAL("data")) 167 .Append(FILE_PATH_LITERAL("data"))
172 .AppendASCII(name); 168 .AppendASCII(name);
173 169
174 data_source_ = new FileDataSource(disable_file_size); 170 data_source_ = new FileDataSource();
175 EXPECT_TRUE(data_source_->Initialize(file_path.MaybeAsASCII())); 171 EXPECT_TRUE(data_source_->Initialize(file_path.MaybeAsASCII()));
176 } 172 }
177 173
178 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); 174 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest);
179 }; 175 };
180 176
181 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { 177 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
182 // Simulate avformat_open_input() failing. 178 // Simulate avformat_open_input() failing.
183 CreateDemuxer("ten_byte_file"), 179 CreateDemuxer("ten_byte_file"),
184 demuxer_->Initialize( 180 demuxer_->Initialize(
185 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 181 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN));
186 182
187 message_loop_.RunAllPending(); 183 message_loop_.RunAllPending();
188 } 184 }
189 185
190 // TODO(acolwell): Uncomment this test when we discover a file that passes 186 // TODO(acolwell): Uncomment this test when we discover a file that passes
191 // avformat_open_input(), but has avformat_find_stream_info() fail. 187 // avformat_open_input(), but has avformat_find_stream_info() fail.
192 // 188 //
193 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { 189 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
194 // CreateDemuxer("find_stream_info_fail.webm"); 190 // ("find_stream_info_fail.webm");
195 // demuxer_->Initialize( 191 // demuxer_->Initialize(
196 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE)); 192 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE));
197 // message_loop_.RunAllPending(); 193 // message_loop_.RunAllPending();
198 //} 194 //}
199 195
200 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { 196 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
201 // Open a file with no streams whatsoever. 197 // Open a file with no streams whatsoever.
202 CreateDemuxer("no_streams.webm"); 198 CreateDemuxer("no_streams.webm");
203 demuxer_->Initialize( 199 demuxer_->Initialize(
204 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); 200 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 336
341 TEST_F(FFmpegDemuxerTest, Read_EndOfStream) { 337 TEST_F(FFmpegDemuxerTest, Read_EndOfStream) {
342 // Verify that end of stream buffers are created. 338 // Verify that end of stream buffers are created.
343 CreateDemuxer("bear-320x240.webm"); 339 CreateDemuxer("bear-320x240.webm");
344 InitializeDemuxer(); 340 InitializeDemuxer();
345 ReadUntilEndOfStream(); 341 ReadUntilEndOfStream();
346 } 342 }
347 343
348 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration) { 344 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration) {
349 // Verify that end of stream buffers are created. 345 // Verify that end of stream buffers are created.
350 CreateDemuxer("bear-320x240.webm", false); 346 CreateDemuxer("bear-320x240.webm");
351 InitializeDemuxer(); 347 InitializeDemuxer();
352 set_duration_known(false); 348 set_duration_known(false);
353 EXPECT_CALL(host_, SetDuration(_)); 349 EXPECT_CALL(host_, SetDuration(_));
354 ReadUntilEndOfStream(); 350 ReadUntilEndOfStream();
355 } 351 }
356 352
357 TEST_F(FFmpegDemuxerTest, Seek) { 353 TEST_F(FFmpegDemuxerTest, Seek) {
358 // We're testing that the demuxer frees all queued packets when it receives 354 // We're testing that the demuxer frees all queued packets when it receives
359 // a Seek(). 355 // a Seek().
360 CreateDemuxer("bear-320x240.webm"); 356 CreateDemuxer("bear-320x240.webm");
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 video->Read(NewReadCB(FROM_HERE, 22084, 0)); 518 video->Read(NewReadCB(FROM_HERE, 22084, 0));
523 message_loop_.RunAllPending(); 519 message_loop_.RunAllPending();
524 520
525 // Attempt a read from the audio stream: it should immediately return end of 521 // Attempt a read from the audio stream: it should immediately return end of
526 // stream without requiring the message loop to read data. 522 // stream without requiring the message loop to read data.
527 bool got_eos_buffer = false; 523 bool got_eos_buffer = false;
528 audio->Read(base::Bind(&EosOnReadDone, &got_eos_buffer)); 524 audio->Read(base::Bind(&EosOnReadDone, &got_eos_buffer));
529 EXPECT_TRUE(got_eos_buffer); 525 EXPECT_TRUE(got_eos_buffer);
530 } 526 }
531 527
532 TEST_F(FFmpegDemuxerTest, ProtocolRead) {
533 CreateDemuxer("bear-320x240.webm");
534 InitializeDemuxer();
535
536 // Set read head to zero as Initialize() will have parsed a bit of the file.
537 int64 position = 0;
538 EXPECT_TRUE(demuxer_->SetPosition(0));
539 EXPECT_TRUE(demuxer_->GetPosition(&position));
540 EXPECT_EQ(0, position);
541
542 // Read 32 bytes from offset zero and verify position.
543 uint8 buffer[32];
544 EXPECT_EQ(32, demuxer_->Read(32, buffer));
545 EXPECT_TRUE(demuxer_->GetPosition(&position));
546 EXPECT_EQ(32, position);
547
548 // Read an additional 32 bytes and verify position.
549 EXPECT_EQ(32, demuxer_->Read(32, buffer));
550 EXPECT_TRUE(demuxer_->GetPosition(&position));
551 EXPECT_EQ(64, position);
552
553 // Seek to end and read until EOF.
554 int64 size = 0;
555 EXPECT_TRUE(demuxer_->GetSize(&size));
556 EXPECT_TRUE(demuxer_->SetPosition(size - 48));
557 EXPECT_EQ(32, demuxer_->Read(32, buffer));
558 EXPECT_TRUE(demuxer_->GetPosition(&position));
559 EXPECT_EQ(size - 16, position);
560
561 EXPECT_EQ(16, demuxer_->Read(32, buffer));
562 EXPECT_TRUE(demuxer_->GetPosition(&position));
563 EXPECT_EQ(size, position);
564
565 EXPECT_EQ(0, demuxer_->Read(32, buffer));
566 EXPECT_TRUE(demuxer_->GetPosition(&position));
567 EXPECT_EQ(size, position);
568
569 demuxer_->Stop(NewExpectedClosure());
570 message_loop_.RunAllPending();
571 }
572
573 TEST_F(FFmpegDemuxerTest, ProtocolGetSetPosition) {
574 CreateDemuxer("bear-320x240.webm");
575 InitializeDemuxer();
576
577 InSequence s;
578
579 int64 size;
580 int64 position;
581 EXPECT_TRUE(demuxer_->GetSize(&size));
582 EXPECT_TRUE(demuxer_->GetPosition(&position));
583
584 EXPECT_TRUE(demuxer_->SetPosition(512));
585 EXPECT_FALSE(demuxer_->SetPosition(size));
586 EXPECT_FALSE(demuxer_->SetPosition(size + 1));
587 EXPECT_FALSE(demuxer_->SetPosition(-1));
588 EXPECT_TRUE(demuxer_->GetPosition(&position));
589 EXPECT_EQ(512, position);
590 }
591
592 TEST_F(FFmpegDemuxerTest, ProtocolGetSize) {
593 CreateDemuxer("bear-320x240.webm");
594 InitializeDemuxer();
595
596 int64 data_source_size = 0;
597 int64 demuxer_size = 0;
598 EXPECT_TRUE(data_source_->GetSize(&data_source_size));
599 EXPECT_TRUE(demuxer_->GetSize(&demuxer_size));
600 EXPECT_NE(0, data_source_size);
601 EXPECT_EQ(data_source_size, demuxer_size);
602 }
603
604 TEST_F(FFmpegDemuxerTest, ProtocolIsStreaming) {
605 CreateDemuxer("bear-320x240.webm");
606 InitializeDemuxer();
607
608 EXPECT_FALSE(data_source_->IsStreaming());
609 EXPECT_FALSE(demuxer_->IsStreaming());
610 }
611
612 // Verify that seek works properly when the WebM cues data is at the start of 528 // Verify that seek works properly when the WebM cues data is at the start of
613 // the file instead of at the end. 529 // the file instead of at the end.
614 TEST_F(FFmpegDemuxerTest, SeekWithCuesBeforeFirstCluster) { 530 TEST_F(FFmpegDemuxerTest, SeekWithCuesBeforeFirstCluster) {
615 CreateDemuxer("bear-320x240-cues-in-front.webm"); 531 CreateDemuxer("bear-320x240-cues-in-front.webm");
616 InitializeDemuxer(); 532 InitializeDemuxer();
617 533
618 // Get our streams. 534 // Get our streams.
619 scoped_refptr<DemuxerStream> video = 535 scoped_refptr<DemuxerStream> video =
620 demuxer_->GetStream(DemuxerStream::VIDEO); 536 demuxer_->GetStream(DemuxerStream::VIDEO);
621 scoped_refptr<DemuxerStream> audio = 537 scoped_refptr<DemuxerStream> audio =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { 607 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) {
692 CreateDemuxer("vorbis_audio_wmv_video.mkv"); 608 CreateDemuxer("vorbis_audio_wmv_video.mkv");
693 InitializeDemuxer(); 609 InitializeDemuxer();
694 610
695 // Ensure the expected streams are present. 611 // Ensure the expected streams are present.
696 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); 612 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO));
697 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); 613 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO));
698 } 614 }
699 615
700 } // namespace media 616 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698