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

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

Issue 10451049: Track buffered byte ranges correctly in media::Pipeline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months 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
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/filters/file_data_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 void CreateDemuxer(const std::string& name) { 60 void CreateDemuxer(const std::string& name) {
61 CreateDemuxer(name, false); 61 CreateDemuxer(name, false);
62 } 62 }
63 63
64 void CreateDemuxer(const std::string& name, bool disable_file_size) { 64 void CreateDemuxer(const std::string& name, bool disable_file_size) {
65 CHECK(!demuxer_); 65 CHECK(!demuxer_);
66 66
67 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); 67 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber());
68 EXPECT_CALL(host_, SetBufferedBytes(_)).Times(AnyNumber()); 68 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber());
69 EXPECT_CALL(host_, SetCurrentReadPosition(_))
70 .WillRepeatedly(SaveArg<0>(&current_read_position_));
71 69
72 CreateDataSource(name, disable_file_size); 70 CreateDataSource(name, disable_file_size);
73 demuxer_ = new FFmpegDemuxer(&message_loop_, data_source_); 71 demuxer_ = new FFmpegDemuxer(&message_loop_, data_source_);
74 } 72 }
75 73
76 MOCK_METHOD1(CheckPoint, void(int v)); 74 MOCK_METHOD1(CheckPoint, void(int v));
77 75
78 void InitializeDemuxer() { 76 void InitializeDemuxer() {
79 EXPECT_CALL(host_, SetDuration(_)); 77 EXPECT_CALL(host_, SetDuration(_));
80 demuxer_->Initialize(&host_, NewExpectedStatusCB(PIPELINE_OK)); 78 demuxer_->Initialize(&host_, NewExpectedStatusCB(PIPELINE_OK));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 CHECK(stream); 116 CHECK(stream);
119 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; 117 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_;
120 } 118 }
121 119
122 // Fixture members. 120 // Fixture members.
123 scoped_refptr<FileDataSource> data_source_; 121 scoped_refptr<FileDataSource> data_source_;
124 scoped_refptr<FFmpegDemuxer> demuxer_; 122 scoped_refptr<FFmpegDemuxer> demuxer_;
125 StrictMock<MockDemuxerHost> host_; 123 StrictMock<MockDemuxerHost> host_;
126 MessageLoop message_loop_; 124 MessageLoop message_loop_;
127 125
128 int64 current_read_position_;
129
130 AVFormatContext* format_context() { 126 AVFormatContext* format_context() {
131 return demuxer_->format_context_; 127 return demuxer_->format_context_;
132 } 128 }
133 129
134 void ReadUntilEndOfStream() { 130 void ReadUntilEndOfStream() {
135 // We should expect an end of stream buffer. 131 // We should expect an end of stream buffer.
136 scoped_refptr<DemuxerStream> audio = 132 scoped_refptr<DemuxerStream> audio =
137 demuxer_->GetStream(DemuxerStream::AUDIO); 133 demuxer_->GetStream(DemuxerStream::AUDIO);
138 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); 134 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader());
139 135
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 data_source_ = new FileDataSource(disable_file_size); 171 data_source_ = new FileDataSource(disable_file_size);
176 EXPECT_EQ(PIPELINE_OK, data_source_->Initialize(file_path.MaybeAsASCII())); 172 EXPECT_EQ(PIPELINE_OK, data_source_->Initialize(file_path.MaybeAsASCII()));
177 } 173 }
178 174
179 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); 175 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest);
180 }; 176 };
181 177
182 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { 178 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
183 // Simulate avformat_open_input() failing. 179 // Simulate avformat_open_input() failing.
184 CreateDemuxer("ten_byte_file"), 180 CreateDemuxer("ten_byte_file"),
185 EXPECT_CALL(host_, SetCurrentReadPosition(_));
186 demuxer_->Initialize( 181 demuxer_->Initialize(
187 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 182 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN));
188 183
189 message_loop_.RunAllPending(); 184 message_loop_.RunAllPending();
190 } 185 }
191 186
192 // TODO(acolwell): Uncomment this test when we discover a file that passes 187 // TODO(acolwell): Uncomment this test when we discover a file that passes
193 // avformat_open_input(), but has avformat_find_stream_info() fail. 188 // avformat_open_input(), but has avformat_find_stream_info() fail.
194 // 189 //
195 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { 190 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
196 // CreateDemuxer("find_stream_info_fail.webm"); 191 // CreateDemuxer("find_stream_info_fail.webm");
197 // demuxer_->Initialize( 192 // demuxer_->Initialize(
198 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE)); 193 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE));
199 // message_loop_.RunAllPending(); 194 // message_loop_.RunAllPending();
200 //} 195 //}
201 196
202 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { 197 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
203 // Open a file with no streams whatsoever. 198 // Open a file with no streams whatsoever.
204 CreateDemuxer("no_streams.webm"); 199 CreateDemuxer("no_streams.webm");
205 EXPECT_CALL(host_, SetCurrentReadPosition(_));
206 demuxer_->Initialize( 200 demuxer_->Initialize(
207 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); 201 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
208 message_loop_.RunAllPending(); 202 message_loop_.RunAllPending();
209 } 203 }
210 204
211 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) { 205 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) {
212 // Open a file containing streams but none of which are audio/video streams. 206 // Open a file containing streams but none of which are audio/video streams.
213 CreateDemuxer("no_audio_video.webm"); 207 CreateDemuxer("no_audio_video.webm");
214 demuxer_->Initialize( 208 demuxer_->Initialize(
215 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); 209 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 579
586 // Set read head to zero as Initialize() will have parsed a bit of the file. 580 // Set read head to zero as Initialize() will have parsed a bit of the file.
587 int64 position = 0; 581 int64 position = 0;
588 EXPECT_TRUE(demuxer_->SetPosition(0)); 582 EXPECT_TRUE(demuxer_->SetPosition(0));
589 EXPECT_TRUE(demuxer_->GetPosition(&position)); 583 EXPECT_TRUE(demuxer_->GetPosition(&position));
590 EXPECT_EQ(0, position); 584 EXPECT_EQ(0, position);
591 585
592 // Read 32 bytes from offset zero and verify position. 586 // Read 32 bytes from offset zero and verify position.
593 uint8 buffer[32]; 587 uint8 buffer[32];
594 EXPECT_EQ(32u, demuxer_->Read(32, buffer)); 588 EXPECT_EQ(32u, demuxer_->Read(32, buffer));
595 EXPECT_EQ(32, current_read_position_);
596 EXPECT_TRUE(demuxer_->GetPosition(&position)); 589 EXPECT_TRUE(demuxer_->GetPosition(&position));
597 EXPECT_EQ(32, position); 590 EXPECT_EQ(32, position);
598 591
599 // Read an additional 32 bytes and verify position. 592 // Read an additional 32 bytes and verify position.
600 EXPECT_EQ(32u, demuxer_->Read(32, buffer)); 593 EXPECT_EQ(32u, demuxer_->Read(32, buffer));
601 EXPECT_EQ(64, current_read_position_);
602 EXPECT_TRUE(demuxer_->GetPosition(&position)); 594 EXPECT_TRUE(demuxer_->GetPosition(&position));
603 EXPECT_EQ(64, position); 595 EXPECT_EQ(64, position);
604 596
605 // Seek to end and read until EOF. 597 // Seek to end and read until EOF.
606 int64 size = 0; 598 int64 size = 0;
607 EXPECT_TRUE(demuxer_->GetSize(&size)); 599 EXPECT_TRUE(demuxer_->GetSize(&size));
608 EXPECT_TRUE(demuxer_->SetPosition(size - 48)); 600 EXPECT_TRUE(demuxer_->SetPosition(size - 48));
609 EXPECT_EQ(32u, demuxer_->Read(32, buffer)); 601 EXPECT_EQ(32u, demuxer_->Read(32, buffer));
610 EXPECT_EQ(size - 16, current_read_position_);
611 EXPECT_TRUE(demuxer_->GetPosition(&position)); 602 EXPECT_TRUE(demuxer_->GetPosition(&position));
612 EXPECT_EQ(size - 16, position); 603 EXPECT_EQ(size - 16, position);
613 604
614 EXPECT_EQ(16u, demuxer_->Read(32, buffer)); 605 EXPECT_EQ(16u, demuxer_->Read(32, buffer));
615 EXPECT_EQ(size, current_read_position_);
616 EXPECT_TRUE(demuxer_->GetPosition(&position)); 606 EXPECT_TRUE(demuxer_->GetPosition(&position));
617 EXPECT_EQ(size, position); 607 EXPECT_EQ(size, position);
618 608
619 EXPECT_EQ(0u, demuxer_->Read(32, buffer)); 609 EXPECT_EQ(0u, demuxer_->Read(32, buffer));
620 EXPECT_EQ(size, current_read_position_);
621 EXPECT_TRUE(demuxer_->GetPosition(&position)); 610 EXPECT_TRUE(demuxer_->GetPosition(&position));
622 EXPECT_EQ(size, position); 611 EXPECT_EQ(size, position);
623 612
624 demuxer_->Stop(NewExpectedClosure()); 613 demuxer_->Stop(NewExpectedClosure());
625 message_loop_.RunAllPending(); 614 message_loop_.RunAllPending();
626 } 615 }
627 616
628 TEST_F(FFmpegDemuxerTest, GetBitrate_SetInContainer) { 617 TEST_F(FFmpegDemuxerTest, GetBitrate_SetInContainer) {
629 EXPECT_TRUE(VideoHasValidBitrate("bear.ogv", false)); 618 EXPECT_TRUE(VideoHasValidBitrate("bear.ogv", false));
630 } 619 }
(...skipping 13 matching lines...) Expand all
644 TEST_F(FFmpegDemuxerTest, ProtocolGetSetPosition) { 633 TEST_F(FFmpegDemuxerTest, ProtocolGetSetPosition) {
645 CreateDemuxer("bear-320x240.webm"); 634 CreateDemuxer("bear-320x240.webm");
646 InitializeDemuxer(); 635 InitializeDemuxer();
647 636
648 InSequence s; 637 InSequence s;
649 638
650 int64 size; 639 int64 size;
651 int64 position; 640 int64 position;
652 EXPECT_TRUE(demuxer_->GetSize(&size)); 641 EXPECT_TRUE(demuxer_->GetSize(&size));
653 EXPECT_TRUE(demuxer_->GetPosition(&position)); 642 EXPECT_TRUE(demuxer_->GetPosition(&position));
654 EXPECT_EQ(current_read_position_, position);
655 643
656 EXPECT_TRUE(demuxer_->SetPosition(512)); 644 EXPECT_TRUE(demuxer_->SetPosition(512));
657 EXPECT_FALSE(demuxer_->SetPosition(size)); 645 EXPECT_FALSE(demuxer_->SetPosition(size));
658 EXPECT_FALSE(demuxer_->SetPosition(size + 1)); 646 EXPECT_FALSE(demuxer_->SetPosition(size + 1));
659 EXPECT_FALSE(demuxer_->SetPosition(-1)); 647 EXPECT_FALSE(demuxer_->SetPosition(-1));
660 EXPECT_TRUE(demuxer_->GetPosition(&position)); 648 EXPECT_TRUE(demuxer_->GetPosition(&position));
661 EXPECT_EQ(512, position); 649 EXPECT_EQ(512, position);
662 } 650 }
663 651
664 TEST_F(FFmpegDemuxerTest, ProtocolGetSize) { 652 TEST_F(FFmpegDemuxerTest, ProtocolGetSize) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { 773 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) {
786 CreateDemuxer("vorbis_audio_wmv_video.mkv"); 774 CreateDemuxer("vorbis_audio_wmv_video.mkv");
787 InitializeDemuxer(); 775 InitializeDemuxer();
788 776
789 // Ensure the expected streams are present. 777 // Ensure the expected streams are present.
790 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); 778 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO));
791 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); 779 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO));
792 } 780 }
793 781
794 } // namespace media 782 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/filters/file_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698