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

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

Issue 9968117: Move Demuxer::set_host() to Initialize(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 8 years, 8 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
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 <deque> 5 #include <deque>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "media/base/filters.h" 10 #include "media/base/filters.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); 65 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber());
66 EXPECT_CALL(host_, SetBufferedBytes(_)).Times(AnyNumber()); 66 EXPECT_CALL(host_, SetBufferedBytes(_)).Times(AnyNumber());
67 EXPECT_CALL(host_, SetCurrentReadPosition(_)) 67 EXPECT_CALL(host_, SetCurrentReadPosition(_))
68 .WillRepeatedly(SaveArg<0>(&current_read_position_)); 68 .WillRepeatedly(SaveArg<0>(&current_read_position_));
69 69
70 CreateDataSource(name, disable_file_size); 70 CreateDataSource(name, disable_file_size);
71 71
72 // Create an FFmpegDemuxer with local data source. 72 // Create an FFmpegDemuxer with local data source.
73 demuxer_ = new FFmpegDemuxer(&message_loop_, data_source_, true); 73 demuxer_ = new FFmpegDemuxer(&message_loop_, data_source_, true);
74 demuxer_->disable_first_seek_hack_for_testing(); 74 demuxer_->disable_first_seek_hack_for_testing();
75
76 // Inject a filter host and message loop and prepare a data source.
77 demuxer_->set_host(&host_);
78 } 75 }
79 76
80 MOCK_METHOD1(CheckPoint, void(int v)); 77 MOCK_METHOD1(CheckPoint, void(int v));
81 78
82 void InitializeDemuxer() { 79 void InitializeDemuxer() {
83 EXPECT_CALL(host_, SetDuration(_)); 80 EXPECT_CALL(host_, SetDuration(_));
84 demuxer_->Initialize(NewExpectedStatusCB(PIPELINE_OK)); 81 demuxer_->Initialize(&host_, NewExpectedStatusCB(PIPELINE_OK));
85 message_loop_.RunAllPending(); 82 message_loop_.RunAllPending();
86 } 83 }
87 84
88 // Verifies that |buffer| has a specific |size| and |timestamp|. 85 // Verifies that |buffer| has a specific |size| and |timestamp|.
89 // |location| simply indicates where the call to this function was made. 86 // |location| simply indicates where the call to this function was made.
90 // This makes it easier to track down where test failures occur. 87 // This makes it easier to track down where test failures occur.
91 void ValidateBuffer(const tracked_objects::Location& location, 88 void ValidateBuffer(const tracked_objects::Location& location,
92 const scoped_refptr<Buffer>& buffer, 89 const scoped_refptr<Buffer>& buffer,
93 int size, int64 timestampInMicroseconds) { 90 int size, int64 timestampInMicroseconds) {
94 std::string location_str; 91 std::string location_str;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_EQ(PIPELINE_OK, data_source_->Initialize(file_path.MaybeAsASCII())); 139 EXPECT_EQ(PIPELINE_OK, data_source_->Initialize(file_path.MaybeAsASCII()));
143 } 140 }
144 141
145 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); 142 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest);
146 }; 143 };
147 144
148 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { 145 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
149 // Simulate avformat_open_input() failing. 146 // Simulate avformat_open_input() failing.
150 CreateDemuxer("ten_byte_file"), 147 CreateDemuxer("ten_byte_file"),
151 EXPECT_CALL(host_, SetCurrentReadPosition(_)); 148 EXPECT_CALL(host_, SetCurrentReadPosition(_));
152 demuxer_->Initialize(NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 149 demuxer_->Initialize(
150 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN));
153 151
154 message_loop_.RunAllPending(); 152 message_loop_.RunAllPending();
155 } 153 }
156 154
157 // TODO(acolwell): Uncomment this test when we discover a file that passes 155 // TODO(acolwell): Uncomment this test when we discover a file that passes
158 // avformat_open_input(), but has avformat_find_stream_info() fail. 156 // avformat_open_input(), but has avformat_find_stream_info() fail.
159 // 157 //
160 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { 158 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
161 // CreateDemuxer("find_stream_info_fail.webm"); 159 // CreateDemuxer("find_stream_info_fail.webm");
162 // demuxer_->Initialize( 160 // demuxer_->Initialize(
163 // NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE)); 161 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE));
164 // message_loop_.RunAllPending(); 162 // message_loop_.RunAllPending();
165 //} 163 //}
166 164
167 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { 165 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
168 // Open a file with no streams whatsoever. 166 // Open a file with no streams whatsoever.
169 CreateDemuxer("no_streams.webm"); 167 CreateDemuxer("no_streams.webm");
170 EXPECT_CALL(host_, SetCurrentReadPosition(_)); 168 EXPECT_CALL(host_, SetCurrentReadPosition(_));
171 demuxer_->Initialize( 169 demuxer_->Initialize(
172 NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); 170 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
173 message_loop_.RunAllPending(); 171 message_loop_.RunAllPending();
174 } 172 }
175 173
176 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) { 174 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) {
177 // Open a file containing streams but none of which are audio/video streams. 175 // Open a file containing streams but none of which are audio/video streams.
178 CreateDemuxer("no_audio_video.webm"); 176 CreateDemuxer("no_audio_video.webm");
179 demuxer_->Initialize( 177 demuxer_->Initialize(
180 NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); 178 &host_, NewExpectedStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
181 message_loop_.RunAllPending(); 179 message_loop_.RunAllPending();
182 } 180 }
183 181
184 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { 182 TEST_F(FFmpegDemuxerTest, Initialize_Successful) {
185 CreateDemuxer("bear-320x240.webm"); 183 CreateDemuxer("bear-320x240.webm");
186 InitializeDemuxer(); 184 InitializeDemuxer();
187 185
188 // Video stream should be present. 186 // Video stream should be present.
189 scoped_refptr<DemuxerStream> stream = 187 scoped_refptr<DemuxerStream> stream =
190 demuxer_->GetStream(DemuxerStream::VIDEO); 188 demuxer_->GetStream(DemuxerStream::VIDEO);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 callback.Run(size); 577 callback.Run(size);
580 } 578 }
581 579
582 TEST_F(FFmpegDemuxerTest, ProtocolRead) { 580 TEST_F(FFmpegDemuxerTest, ProtocolRead) {
583 scoped_refptr<StrictMock<MockDataSource> > data_source = 581 scoped_refptr<StrictMock<MockDataSource> > data_source =
584 new StrictMock<MockDataSource>(); 582 new StrictMock<MockDataSource>();
585 583
586 EXPECT_CALL(*data_source, Stop(_)) 584 EXPECT_CALL(*data_source, Stop(_))
587 .WillRepeatedly(Invoke(&RunStopFilterCallback)); 585 .WillRepeatedly(Invoke(&RunStopFilterCallback));
588 586
589 // Creates a demuxer. 587 // Create a demuxer.
590 scoped_refptr<MockFFmpegDemuxer> demuxer( 588 scoped_refptr<MockFFmpegDemuxer> demuxer(
591 new MockFFmpegDemuxer(&message_loop_, data_source)); 589 new MockFFmpegDemuxer(&message_loop_, data_source));
592 demuxer->set_host(&host_); 590 demuxer->Initialize(&host_, NewExpectedStatusCB(PIPELINE_OK));
acolwell GONE FROM CHROMIUM 2012/04/04 16:01:00 what?! Initialize() wasn't necessary before? Seems
scherkus (not reviewing) 2012/04/05 01:54:53 DCHECK(host_) added and rewrote these tests
591 message_loop_.RunAllPending();
593 592
594 uint8 kBuffer[1]; 593 uint8 kBuffer[1];
595 InSequence s; 594 InSequence s;
596 // Actions taken in the first read. 595 // Actions taken in the first read.
597 EXPECT_CALL(*data_source, GetSize(_)) 596 EXPECT_CALL(*data_source, GetSize(_))
598 .WillOnce(DoAll(SetArgPointee<0>(1024), Return(true))); 597 .WillOnce(DoAll(SetArgPointee<0>(1024), Return(true)));
599 EXPECT_CALL(*data_source, Read(0, 512, kBuffer, _)) 598 EXPECT_CALL(*data_source, Read(0, 512, kBuffer, _))
600 .WillOnce(WithArgs<1, 3>(Invoke(&RunCallback))); 599 .WillOnce(WithArgs<1, 3>(Invoke(&RunCallback)));
601 EXPECT_CALL(*demuxer, SignalReadCompleted(512)); 600 EXPECT_CALL(*demuxer, SignalReadCompleted(512));
602 EXPECT_CALL(*demuxer, WaitForRead()) 601 EXPECT_CALL(*demuxer, WaitForRead())
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 message_loop_.RunAllPending(); 748 message_loop_.RunAllPending();
750 EXPECT_TRUE(reader->called()); 749 EXPECT_TRUE(reader->called());
751 ValidateBuffer(FROM_HERE, reader->buffer(), 1740, 2436000); 750 ValidateBuffer(FROM_HERE, reader->buffer(), 1740, 2436000);
752 751
753 // Manually release the last reference to the buffer and verify it was freed. 752 // Manually release the last reference to the buffer and verify it was freed.
754 reader->Reset(); 753 reader->Reset();
755 message_loop_.RunAllPending(); 754 message_loop_.RunAllPending();
756 } 755 }
757 756
758 } // namespace media 757 } // namespace media
OLDNEW
« media/filters/ffmpeg_demuxer.cc ('K') | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698