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

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

Issue 9860027: Remove DemuxerFactory and URL parameter from Pipeline. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: again 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
« no previous file with comments | « media/filters/chunk_demuxer_factory.cc ('k') | media/filters/dummy_demuxer.h » ('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 "base/bind.h" 5 #include "base/bind.h"
6 #include "media/base/audio_decoder_config.h" 6 #include "media/base/audio_decoder_config.h"
7 #include "media/base/mock_callback.h" 7 #include "media/base/mock_callback.h"
8 #include "media/base/mock_demuxer_host.h" 8 #include "media/base/mock_demuxer_host.h"
9 #include "media/base/test_data_util.h" 9 #include "media/base/test_data_util.h"
10 #include "media/filters/chunk_demuxer.h" 10 #include "media/filters/chunk_demuxer.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 protected: 83 protected:
84 enum CodecsIndex { 84 enum CodecsIndex {
85 AUDIO, 85 AUDIO,
86 VIDEO, 86 VIDEO,
87 MAX_CODECS_INDEX 87 MAX_CODECS_INDEX
88 }; 88 };
89 89
90 ChunkDemuxerTest() 90 ChunkDemuxerTest()
91 : client_(new MockChunkDemuxerClient()), 91 : client_(new MockChunkDemuxerClient()),
92 demuxer_(new ChunkDemuxer(client_.get())) { 92 demuxer_(new ChunkDemuxer(client_.get())) {
93 demuxer_->set_host(&mock_demuxer_host_);
93 } 94 }
94 95
95 virtual ~ChunkDemuxerTest() { 96 virtual ~ChunkDemuxerTest() {
96 ShutdownDemuxer(); 97 ShutdownDemuxer();
97 } 98 }
98 99
99 void CreateInfoTracks(bool has_audio, bool has_video, 100 void CreateInfoTracks(bool has_audio, bool has_video,
100 bool video_content_encoded, scoped_array<uint8>* buffer, 101 bool video_content_encoded, scoped_array<uint8>* buffer,
101 int* size) { 102 int* size) {
102 scoped_array<uint8> info; 103 scoped_array<uint8> info;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 187
187 bool AppendInfoTracks(bool has_audio, bool has_video, 188 bool AppendInfoTracks(bool has_audio, bool has_video,
188 bool video_content_encoded) { 189 bool video_content_encoded) {
189 scoped_array<uint8> info_tracks; 190 scoped_array<uint8> info_tracks;
190 int info_tracks_size = 0; 191 int info_tracks_size = 0;
191 CreateInfoTracks(has_audio, has_video, video_content_encoded, 192 CreateInfoTracks(has_audio, has_video, video_content_encoded,
192 &info_tracks, &info_tracks_size); 193 &info_tracks, &info_tracks_size);
193 return AppendData(info_tracks.get(), info_tracks_size); 194 return AppendData(info_tracks.get(), info_tracks_size);
194 } 195 }
195 196
196 void InitDoneCalled(const base::TimeDelta& expected_duration, 197 void InitDoneCalled(PipelineStatus expected_status,
197 PipelineStatus expected_status,
198 bool call_set_host,
199 PipelineStatus status) { 198 PipelineStatus status) {
200 EXPECT_EQ(status, expected_status); 199 EXPECT_EQ(status, expected_status);
200 }
201 201
202 if (status == PIPELINE_OK) { 202 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration,
203 PipelineStatus expected_status) {
204 if (expected_status == PIPELINE_OK) {
203 EXPECT_CALL(mock_demuxer_host_, SetDuration(expected_duration)); 205 EXPECT_CALL(mock_demuxer_host_, SetDuration(expected_duration));
204 EXPECT_CALL(mock_demuxer_host_, SetCurrentReadPosition(_)); 206 EXPECT_CALL(mock_demuxer_host_, SetCurrentReadPosition(_));
207 }
205 208
206 if (call_set_host)
207 demuxer_->set_host(&mock_demuxer_host_);
208 }
209 }
210
211 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& duration,
212 PipelineStatus expected_status,
213 bool call_set_host) {
214 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, 209 return base::Bind(&ChunkDemuxerTest::InitDoneCalled,
215 base::Unretained(this), 210 base::Unretained(this),
216 duration, 211 expected_status);
217 expected_status,
218 call_set_host);
219 } 212 }
220 213
221 bool InitDemuxer(bool has_audio, bool has_video, 214 bool InitDemuxer(bool has_audio, bool has_video,
222 bool video_content_encoded) { 215 bool video_content_encoded) {
223 PipelineStatus expected_status = 216 PipelineStatus expected_status =
224 (has_audio || has_video) ? PIPELINE_OK : DEMUXER_ERROR_COULD_NOT_OPEN; 217 (has_audio || has_video) ? PIPELINE_OK : DEMUXER_ERROR_COULD_NOT_OPEN;
225 218
226 EXPECT_CALL(*client_, DemuxerOpened(_)); 219 EXPECT_CALL(*client_, DemuxerOpened(_));
227 demuxer_->Init(CreateInitDoneCB(kDefaultDuration(), expected_status, true)); 220 demuxer_->Initialize(CreateInitDoneCB(
221 kDefaultDuration(), expected_status));
228 222
229 return AppendInfoTracks(has_audio, has_video, video_content_encoded); 223 return AppendInfoTracks(has_audio, has_video, video_content_encoded);
230 } 224 }
231 225
232 void ShutdownDemuxer() { 226 void ShutdownDemuxer() {
233 if (demuxer_) { 227 if (demuxer_) {
234 EXPECT_CALL(*client_, DemuxerClosed()); 228 EXPECT_CALL(*client_, DemuxerClosed());
235 demuxer_->Shutdown(); 229 demuxer_->Shutdown();
236 } 230 }
237 } 231 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // a timestamp of kSkip indicates that a Read() call for that stream 263 // a timestamp of kSkip indicates that a Read() call for that stream
270 // shouldn't be made on that iteration of the loop. If both streams have 264 // shouldn't be made on that iteration of the loop. If both streams have
271 // a kSkip then the loop will terminate. 265 // a kSkip then the loop will terminate.
272 bool ParseWebMFile(const std::string& filename, 266 bool ParseWebMFile(const std::string& filename,
273 const BufferTimestamps* timestamps, 267 const BufferTimestamps* timestamps,
274 const base::TimeDelta& duration) { 268 const base::TimeDelta& duration) {
275 scoped_array<uint8> buffer; 269 scoped_array<uint8> buffer;
276 int buffer_size = 0; 270 int buffer_size = 0;
277 271
278 EXPECT_CALL(*client_, DemuxerOpened(_)); 272 EXPECT_CALL(*client_, DemuxerOpened(_));
279 demuxer_->Init(CreateInitDoneCB(duration, PIPELINE_OK, true)); 273 demuxer_->Initialize(CreateInitDoneCB(duration, PIPELINE_OK));
280 274
281 // Read a WebM file into memory and send the data to the demuxer. 275 // Read a WebM file into memory and send the data to the demuxer.
282 ReadTestDataFile(filename, &buffer, &buffer_size); 276 ReadTestDataFile(filename, &buffer, &buffer_size);
283 if (!AppendDataInPieces(buffer.get(), buffer_size, 512)) 277 if (!AppendDataInPieces(buffer.get(), buffer_size, 512))
284 return false; 278 return false;
285 279
286 scoped_refptr<DemuxerStream> audio = 280 scoped_refptr<DemuxerStream> audio =
287 demuxer_->GetStream(DemuxerStream::AUDIO); 281 demuxer_->GetStream(DemuxerStream::AUDIO);
288 scoped_refptr<DemuxerStream> video = 282 scoped_refptr<DemuxerStream> video =
289 demuxer_->GetStream(DemuxerStream::VIDEO); 283 demuxer_->GetStream(DemuxerStream::VIDEO);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 bool has_audio = (i & 0x1) != 0; 330 bool has_audio = (i & 0x1) != 0;
337 bool has_video = (i & 0x2) != 0; 331 bool has_video = (i & 0x2) != 0;
338 bool video_content_encoded = (i & 0x4) != 0; 332 bool video_content_encoded = (i & 0x4) != 0;
339 333
340 // No test on invalid combination. 334 // No test on invalid combination.
341 if (!has_video && video_content_encoded) 335 if (!has_video && video_content_encoded)
342 continue; 336 continue;
343 337
344 client_.reset(new MockChunkDemuxerClient()); 338 client_.reset(new MockChunkDemuxerClient());
345 demuxer_ = new ChunkDemuxer(client_.get()); 339 demuxer_ = new ChunkDemuxer(client_.get());
340 demuxer_->set_host(&mock_demuxer_host_);
346 ASSERT_TRUE(InitDemuxer(has_audio, has_video, video_content_encoded)); 341 ASSERT_TRUE(InitDemuxer(has_audio, has_video, video_content_encoded));
347 342
348 scoped_refptr<DemuxerStream> audio_stream = 343 scoped_refptr<DemuxerStream> audio_stream =
349 demuxer_->GetStream(DemuxerStream::AUDIO); 344 demuxer_->GetStream(DemuxerStream::AUDIO);
350 if (has_audio) { 345 if (has_audio) {
351 ASSERT_TRUE(audio_stream); 346 ASSERT_TRUE(audio_stream);
352 347
353 const AudioDecoderConfig& config = audio_stream->audio_decoder_config(); 348 const AudioDecoderConfig& config = audio_stream->audio_decoder_config();
354 EXPECT_EQ(kCodecVorbis, config.codec()); 349 EXPECT_EQ(kCodecVorbis, config.codec());
355 EXPECT_EQ(16, config.bits_per_channel()); 350 EXPECT_EQ(16, config.bits_per_channel());
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 AddSimpleBlock(&cb, kAudioTrackNum, 10); 627 AddSimpleBlock(&cb, kAudioTrackNum, 10);
633 AddSimpleBlock(&cb, kVideoTrackNum, 10); 628 AddSimpleBlock(&cb, kVideoTrackNum, 10);
634 scoped_ptr<Cluster> cluster_c(cb.Finish()); 629 scoped_ptr<Cluster> cluster_c(cb.Finish());
635 EXPECT_FALSE(demuxer_->AppendData(cluster_c->data(), cluster_c->size())); 630 EXPECT_FALSE(demuxer_->AppendData(cluster_c->data(), cluster_c->size()));
636 } 631 }
637 632
638 // Test the case where a cluster is passed to AppendData() before 633 // Test the case where a cluster is passed to AppendData() before
639 // INFO & TRACKS data. 634 // INFO & TRACKS data.
640 TEST_F(ChunkDemuxerTest, TestClusterBeforeInfoTracks) { 635 TEST_F(ChunkDemuxerTest, TestClusterBeforeInfoTracks) {
641 EXPECT_CALL(*client_, DemuxerOpened(_)); 636 EXPECT_CALL(*client_, DemuxerOpened(_));
642 demuxer_->Init(NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 637 demuxer_->Initialize(NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN));
643 638
644 ClusterBuilder cb; 639 ClusterBuilder cb;
645 cb.SetClusterTimecode(0); 640 cb.SetClusterTimecode(0);
646 AddSimpleBlock(&cb, kVideoTrackNum, 0); 641 AddSimpleBlock(&cb, kVideoTrackNum, 0);
647 scoped_ptr<Cluster> cluster(cb.Finish()); 642 scoped_ptr<Cluster> cluster(cb.Finish());
648 643
649 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); 644 ASSERT_TRUE(AppendData(cluster->data(), cluster->size()));
650 } 645 }
651 646
652 // Test cases where we get an EndOfStream() call during initialization. 647 // Test cases where we get an EndOfStream() call during initialization.
653 TEST_F(ChunkDemuxerTest, TestEOSDuringInit) { 648 TEST_F(ChunkDemuxerTest, TestEOSDuringInit) {
654 EXPECT_CALL(*client_, DemuxerOpened(_)); 649 EXPECT_CALL(*client_, DemuxerOpened(_));
655 demuxer_->Init(NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 650 demuxer_->Initialize(NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN));
656 demuxer_->EndOfStream(PIPELINE_OK); 651 demuxer_->EndOfStream(PIPELINE_OK);
657 } 652 }
658 653
659 TEST_F(ChunkDemuxerTest, TestDecodeErrorEndOfStream) { 654 TEST_F(ChunkDemuxerTest, TestDecodeErrorEndOfStream) {
660 ASSERT_TRUE(InitDemuxer(true, true, false)); 655 ASSERT_TRUE(InitDemuxer(true, true, false));
661 656
662 ClusterBuilder cb; 657 ClusterBuilder cb;
663 cb.SetClusterTimecode(0); 658 cb.SetClusterTimecode(0);
664 AddSimpleBlock(&cb, kAudioTrackNum, 0); 659 AddSimpleBlock(&cb, kAudioTrackNum, 0);
665 AddSimpleBlock(&cb, kVideoTrackNum, 0); 660 AddSimpleBlock(&cb, kVideoTrackNum, 0);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); 824 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true);
830 825
831 end_of_stream_helper_3.RequestReads(); 826 end_of_stream_helper_3.RequestReads();
832 end_of_stream_helper_3.CheckIfReadDonesWereCalled(true); 827 end_of_stream_helper_3.CheckIfReadDonesWereCalled(true);
833 } 828 }
834 829
835 // Make sure AppendData() will accept elements that span multiple calls. 830 // Make sure AppendData() will accept elements that span multiple calls.
836 TEST_F(ChunkDemuxerTest, TestAppendingInPieces) { 831 TEST_F(ChunkDemuxerTest, TestAppendingInPieces) {
837 832
838 EXPECT_CALL(*client_, DemuxerOpened(_)); 833 EXPECT_CALL(*client_, DemuxerOpened(_));
839 demuxer_->Init(CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK, true)); 834 demuxer_->Initialize(CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK));
840 835
841 scoped_array<uint8> info_tracks; 836 scoped_array<uint8> info_tracks;
842 int info_tracks_size = 0; 837 int info_tracks_size = 0;
843 CreateInfoTracks(true, true, false, &info_tracks, &info_tracks_size); 838 CreateInfoTracks(true, true, false, &info_tracks, &info_tracks_size);
844 839
845 ClusterBuilder cb; 840 ClusterBuilder cb;
846 cb.SetClusterTimecode(0); 841 cb.SetClusterTimecode(0);
847 AddSimpleBlock(&cb, kAudioTrackNum, 32, 512); 842 AddSimpleBlock(&cb, kAudioTrackNum, 32, 512);
848 AddSimpleBlock(&cb, kVideoTrackNum, 123, 1024); 843 AddSimpleBlock(&cb, kVideoTrackNum, 123, 1024);
849 scoped_ptr<Cluster> cluster_a(cb.Finish()); 844 scoped_ptr<Cluster> cluster_a(cb.Finish());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 1019
1025 // Append the remaining data. 1020 // Append the remaining data.
1026 ASSERT_TRUE(AppendData(cluster->data() + i, cluster->size() - i)); 1021 ASSERT_TRUE(AppendData(cluster->data() + i, cluster->size() - i));
1027 1022
1028 EXPECT_TRUE(audio_read_done); 1023 EXPECT_TRUE(audio_read_done);
1029 EXPECT_TRUE(video_read_done); 1024 EXPECT_TRUE(video_read_done);
1030 } 1025 }
1031 1026
1032 1027
1033 TEST_F(ChunkDemuxerTest, TestParseErrorDuringInit) { 1028 TEST_F(ChunkDemuxerTest, TestParseErrorDuringInit) {
1029 EXPECT_CALL(mock_demuxer_host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1030
1034 EXPECT_CALL(*client_, DemuxerOpened(_)); 1031 EXPECT_CALL(*client_, DemuxerOpened(_));
1035 demuxer_->Init(CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK, false)); 1032 demuxer_->Initialize(CreateInitDoneCB(
1033 kDefaultDuration(), PIPELINE_OK));
1036 ASSERT_TRUE(AppendInfoTracks(true, true, false)); 1034 ASSERT_TRUE(AppendInfoTracks(true, true, false));
1037 1035
1038 uint8 tmp = 0; 1036 uint8 tmp = 0;
1039 ASSERT_TRUE(demuxer_->AppendData(&tmp, 1)); 1037 ASSERT_TRUE(demuxer_->AppendData(&tmp, 1));
1040
1041 EXPECT_CALL(mock_demuxer_host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1042 demuxer_->set_host(&mock_demuxer_host_);
1043 } 1038 }
1044 1039
1045 } // namespace media 1040 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer_factory.cc ('k') | media/filters/dummy_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698