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

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

Issue 2086353002: Remove calls to deprecated MessageLoop methods in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
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 "media/filters/chunk_demuxer.h" 5 #include "media/filters/chunk_demuxer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 EXPECT_TRUE(AppendData(bear1->data() + 72737, 28183)); 984 EXPECT_TRUE(AppendData(bear1->data() + 72737, 28183));
985 CheckExpectedRanges("{ [0,2736) }"); 985 CheckExpectedRanges("{ [0,2736) }");
986 986
987 MarkEndOfStream(PIPELINE_OK); 987 MarkEndOfStream(PIPELINE_OK);
988 return true; 988 return true;
989 } 989 }
990 990
991 void ShutdownDemuxer() { 991 void ShutdownDemuxer() {
992 if (demuxer_) { 992 if (demuxer_) {
993 demuxer_->Shutdown(); 993 demuxer_->Shutdown();
994 message_loop_.RunUntilIdle(); 994 base::RunLoop().RunUntilIdle();
995 } 995 }
996 } 996 }
997 997
998 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64_t timecode) { 998 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64_t timecode) {
999 uint8_t data[] = {0x00}; 999 uint8_t data[] = {0x00};
1000 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data)); 1000 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data));
1001 } 1001 }
1002 1002
1003 std::unique_ptr<Cluster> GenerateCluster(int timecode, int block_count) { 1003 std::unique_ptr<Cluster> GenerateCluster(int timecode, int block_count) {
1004 return GenerateCluster(timecode, timecode, block_count); 1004 return GenerateCluster(timecode, timecode, block_count);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 cb.AddBlockGroup(track_number, timecode, block_duration, 1102 cb.AddBlockGroup(track_number, timecode, block_duration,
1103 kWebMFlagKeyframe, static_cast<bool>(kWebMFlagKeyframe), 1103 kWebMFlagKeyframe, static_cast<bool>(kWebMFlagKeyframe),
1104 &data[0], data.size()); 1104 &data[0], data.size());
1105 } 1105 }
1106 1106
1107 return cb.Finish(); 1107 return cb.Finish();
1108 } 1108 }
1109 1109
1110 void Read(DemuxerStream::Type type, const DemuxerStream::ReadCB& read_cb) { 1110 void Read(DemuxerStream::Type type, const DemuxerStream::ReadCB& read_cb) {
1111 demuxer_->GetStream(type)->Read(read_cb); 1111 demuxer_->GetStream(type)->Read(read_cb);
1112 message_loop_.RunUntilIdle(); 1112 base::RunLoop().RunUntilIdle();
1113 } 1113 }
1114 1114
1115 void ReadAudio(const DemuxerStream::ReadCB& read_cb) { 1115 void ReadAudio(const DemuxerStream::ReadCB& read_cb) {
1116 Read(DemuxerStream::AUDIO, read_cb); 1116 Read(DemuxerStream::AUDIO, read_cb);
1117 } 1117 }
1118 1118
1119 void ReadVideo(const DemuxerStream::ReadCB& read_cb) { 1119 void ReadVideo(const DemuxerStream::ReadCB& read_cb) {
1120 Read(DemuxerStream::VIDEO, read_cb); 1120 Read(DemuxerStream::VIDEO, read_cb);
1121 } 1121 }
1122 1122
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 base::RunLoop().RunUntilIdle(); 1235 base::RunLoop().RunUntilIdle();
1236 if (*status == DemuxerStream::kOk && !buffer->end_of_stream()) 1236 if (*status == DemuxerStream::kOk && !buffer->end_of_stream())
1237 *last_timestamp = buffer->timestamp(); 1237 *last_timestamp = buffer->timestamp();
1238 } while (*status == DemuxerStream::kOk && !buffer->end_of_stream()); 1238 } while (*status == DemuxerStream::kOk && !buffer->end_of_stream());
1239 } 1239 }
1240 1240
1241 void ExpectEndOfStream(DemuxerStream::Type type) { 1241 void ExpectEndOfStream(DemuxerStream::Type type) {
1242 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, IsEndOfStream())); 1242 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, IsEndOfStream()));
1243 demuxer_->GetStream(type)->Read(base::Bind( 1243 demuxer_->GetStream(type)->Read(base::Bind(
1244 &ChunkDemuxerTest::ReadDone, base::Unretained(this))); 1244 &ChunkDemuxerTest::ReadDone, base::Unretained(this)));
1245 message_loop_.RunUntilIdle(); 1245 base::RunLoop().RunUntilIdle();
1246 } 1246 }
1247 1247
1248 void ExpectRead(DemuxerStream::Type type, int64_t timestamp_in_ms) { 1248 void ExpectRead(DemuxerStream::Type type, int64_t timestamp_in_ms) {
1249 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, 1249 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk,
1250 HasTimestamp(timestamp_in_ms))); 1250 HasTimestamp(timestamp_in_ms)));
1251 demuxer_->GetStream(type)->Read(base::Bind( 1251 demuxer_->GetStream(type)->Read(base::Bind(
1252 &ChunkDemuxerTest::ReadDone, base::Unretained(this))); 1252 &ChunkDemuxerTest::ReadDone, base::Unretained(this)));
1253 message_loop_.RunUntilIdle(); 1253 base::RunLoop().RunUntilIdle();
1254 } 1254 }
1255 1255
1256 void ExpectConfigChanged(DemuxerStream::Type type) { 1256 void ExpectConfigChanged(DemuxerStream::Type type) {
1257 EXPECT_CALL(*this, ReadDone(DemuxerStream::kConfigChanged, _)); 1257 EXPECT_CALL(*this, ReadDone(DemuxerStream::kConfigChanged, _));
1258 demuxer_->GetStream(type)->Read(base::Bind( 1258 demuxer_->GetStream(type)->Read(base::Bind(
1259 &ChunkDemuxerTest::ReadDone, base::Unretained(this))); 1259 &ChunkDemuxerTest::ReadDone, base::Unretained(this)));
1260 message_loop_.RunUntilIdle(); 1260 base::RunLoop().RunUntilIdle();
1261 } 1261 }
1262 1262
1263 void CheckExpectedBuffers(DemuxerStream* stream, 1263 void CheckExpectedBuffers(DemuxerStream* stream,
1264 const std::string& expected) { 1264 const std::string& expected) {
1265 std::vector<std::string> timestamps = base::SplitString( 1265 std::vector<std::string> timestamps = base::SplitString(
1266 expected, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1266 expected, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1267 std::stringstream ss; 1267 std::stringstream ss;
1268 for (size_t i = 0; i < timestamps.size(); ++i) { 1268 for (size_t i = 0; i < timestamps.size(); ++i) {
1269 // Initialize status to kAborted since it's possible for Read() to return 1269 // Initialize status to kAborted since it's possible for Read() to return
1270 // without calling StoreStatusAndBuffer() if it doesn't have any buffers 1270 // without calling StoreStatusAndBuffer() if it doesn't have any buffers
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 MOCK_METHOD0(DemuxerOpened, void()); 1362 MOCK_METHOD0(DemuxerOpened, void());
1363 MOCK_METHOD2(OnEncryptedMediaInitData, 1363 MOCK_METHOD2(OnEncryptedMediaInitData,
1364 void(EmeInitDataType init_data_type, 1364 void(EmeInitDataType init_data_type,
1365 const std::vector<uint8_t>& init_data)); 1365 const std::vector<uint8_t>& init_data));
1366 1366
1367 MOCK_METHOD1(InitSegmentReceivedMock, void(std::unique_ptr<MediaTracks>&)); 1367 MOCK_METHOD1(InitSegmentReceivedMock, void(std::unique_ptr<MediaTracks>&));
1368 1368
1369 void Seek(base::TimeDelta seek_time) { 1369 void Seek(base::TimeDelta seek_time) {
1370 demuxer_->StartWaitingForSeek(seek_time); 1370 demuxer_->StartWaitingForSeek(seek_time);
1371 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); 1371 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK));
1372 message_loop_.RunUntilIdle(); 1372 base::RunLoop().RunUntilIdle();
1373 } 1373 }
1374 1374
1375 void MarkEndOfStream(PipelineStatus status) { 1375 void MarkEndOfStream(PipelineStatus status) {
1376 demuxer_->MarkEndOfStream(status); 1376 demuxer_->MarkEndOfStream(status);
1377 message_loop_.RunUntilIdle(); 1377 base::RunLoop().RunUntilIdle();
1378 } 1378 }
1379 1379
1380 bool SetTimestampOffset(const std::string& id, 1380 bool SetTimestampOffset(const std::string& id,
1381 base::TimeDelta timestamp_offset) { 1381 base::TimeDelta timestamp_offset) {
1382 if (demuxer_->IsParsingMediaSegment(id)) 1382 if (demuxer_->IsParsingMediaSegment(id))
1383 return false; 1383 return false;
1384 1384
1385 timestamp_offset_map_[id] = timestamp_offset; 1385 timestamp_offset_map_[id] = timestamp_offset;
1386 return true; 1386 return true;
1387 } 1387 }
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 1719
1720 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1720 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1721 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1721 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1722 1722
1723 bool audio_read_done = false; 1723 bool audio_read_done = false;
1724 bool video_read_done = false; 1724 bool video_read_done = false;
1725 bool text_read_done = false; 1725 bool text_read_done = false;
1726 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); 1726 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
1727 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done)); 1727 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done));
1728 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done)); 1728 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done));
1729 message_loop_.RunUntilIdle(); 1729 base::RunLoop().RunUntilIdle();
1730 1730
1731 EXPECT_FALSE(audio_read_done); 1731 EXPECT_FALSE(audio_read_done);
1732 EXPECT_FALSE(video_read_done); 1732 EXPECT_FALSE(video_read_done);
1733 EXPECT_FALSE(text_read_done); 1733 EXPECT_FALSE(text_read_done);
1734 1734
1735 ShutdownDemuxer(); 1735 ShutdownDemuxer();
1736 1736
1737 EXPECT_TRUE(audio_read_done); 1737 EXPECT_TRUE(audio_read_done);
1738 EXPECT_TRUE(video_read_done); 1738 EXPECT_TRUE(video_read_done);
1739 EXPECT_TRUE(text_read_done); 1739 EXPECT_TRUE(text_read_done);
(...skipping 10 matching lines...) Expand all
1750 EXPECT_CALL(*this, Checkpoint(1)); 1750 EXPECT_CALL(*this, Checkpoint(1));
1751 1751
1752 Seek(base::TimeDelta::FromMilliseconds(46)); 1752 Seek(base::TimeDelta::FromMilliseconds(46));
1753 1753
1754 EXPECT_CALL(*this, Checkpoint(2)); 1754 EXPECT_CALL(*this, Checkpoint(2));
1755 1755
1756 Checkpoint(1); 1756 Checkpoint(1);
1757 1757
1758 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); 1758 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster()));
1759 1759
1760 message_loop_.RunUntilIdle(); 1760 base::RunLoop().RunUntilIdle();
1761 1761
1762 Checkpoint(2); 1762 Checkpoint(2);
1763 } 1763 }
1764 1764
1765 // Test that parsing errors are handled for clusters appended after init. 1765 // Test that parsing errors are handled for clusters appended after init.
1766 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { 1766 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) {
1767 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1767 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1768 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster())); 1768 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster()));
1769 1769
1770 EXPECT_MEDIA_LOG(StreamParsingFailed()); 1770 EXPECT_MEDIA_LOG(StreamParsingFailed());
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 bool video_read_done_1 = false; 2058 bool video_read_done_1 = false;
2059 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); 2059 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get());
2060 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); 2060 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get());
2061 2061
2062 ReadAudio(base::Bind(&OnReadDone, 2062 ReadAudio(base::Bind(&OnReadDone,
2063 base::TimeDelta::FromMilliseconds(0), 2063 base::TimeDelta::FromMilliseconds(0),
2064 &audio_read_done_1)); 2064 &audio_read_done_1));
2065 ReadVideo(base::Bind(&OnReadDone, 2065 ReadVideo(base::Bind(&OnReadDone,
2066 base::TimeDelta::FromMilliseconds(0), 2066 base::TimeDelta::FromMilliseconds(0),
2067 &video_read_done_1)); 2067 &video_read_done_1));
2068 message_loop_.RunUntilIdle(); 2068 base::RunLoop().RunUntilIdle();
2069 2069
2070 EXPECT_TRUE(audio_read_done_1); 2070 EXPECT_TRUE(audio_read_done_1);
2071 EXPECT_TRUE(video_read_done_1); 2071 EXPECT_TRUE(video_read_done_1);
2072 2072
2073 end_of_stream_helper_1.RequestReads(); 2073 end_of_stream_helper_1.RequestReads();
2074 2074
2075 EXPECT_CALL(host_, SetDuration( 2075 EXPECT_CALL(host_, SetDuration(
2076 base::TimeDelta::FromMilliseconds(kVideoBlockDuration))); 2076 base::TimeDelta::FromMilliseconds(kVideoBlockDuration)));
2077 MarkEndOfStream(PIPELINE_OK); 2077 MarkEndOfStream(PIPELINE_OK);
2078 2078
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2351 &video_read_done)); 2351 &video_read_done));
2352 2352
2353 // Make sure the reads haven't completed yet. 2353 // Make sure the reads haven't completed yet.
2354 EXPECT_FALSE(audio_read_done); 2354 EXPECT_FALSE(audio_read_done);
2355 EXPECT_FALSE(video_read_done); 2355 EXPECT_FALSE(video_read_done);
2356 2356
2357 // Append data one byte at a time until one or both reads complete. 2357 // Append data one byte at a time until one or both reads complete.
2358 int i = 0; 2358 int i = 0;
2359 for (; i < cluster->size() && !(audio_read_done || video_read_done); ++i) { 2359 for (; i < cluster->size() && !(audio_read_done || video_read_done); ++i) {
2360 ASSERT_TRUE(AppendData(cluster->data() + i, 1)); 2360 ASSERT_TRUE(AppendData(cluster->data() + i, 1));
2361 message_loop_.RunUntilIdle(); 2361 base::RunLoop().RunUntilIdle();
2362 } 2362 }
2363 2363
2364 EXPECT_TRUE(audio_read_done || video_read_done); 2364 EXPECT_TRUE(audio_read_done || video_read_done);
2365 EXPECT_GT(i, 0); 2365 EXPECT_GT(i, 0);
2366 EXPECT_LT(i, cluster->size()); 2366 EXPECT_LT(i, cluster->size());
2367 2367
2368 audio_read_done = false; 2368 audio_read_done = false;
2369 video_read_done = false; 2369 video_read_done = false;
2370 ReadAudio(base::Bind(&OnReadDone, 2370 ReadAudio(base::Bind(&OnReadDone,
2371 base::TimeDelta::FromMilliseconds(23), 2371 base::TimeDelta::FromMilliseconds(23),
2372 &audio_read_done)); 2372 &audio_read_done));
2373 ReadVideo(base::Bind(&OnReadDone, 2373 ReadVideo(base::Bind(&OnReadDone,
2374 base::TimeDelta::FromMilliseconds(33), 2374 base::TimeDelta::FromMilliseconds(33),
2375 &video_read_done)); 2375 &video_read_done));
2376 2376
2377 // Make sure the reads haven't completed yet. 2377 // Make sure the reads haven't completed yet.
2378 EXPECT_FALSE(audio_read_done); 2378 EXPECT_FALSE(audio_read_done);
2379 EXPECT_FALSE(video_read_done); 2379 EXPECT_FALSE(video_read_done);
2380 2380
2381 // Append the remaining data. 2381 // Append the remaining data.
2382 ASSERT_LT(i, cluster->size()); 2382 ASSERT_LT(i, cluster->size());
2383 ASSERT_TRUE(AppendData(cluster->data() + i, cluster->size() - i)); 2383 ASSERT_TRUE(AppendData(cluster->data() + i, cluster->size() - i));
2384 2384
2385 message_loop_.RunUntilIdle(); 2385 base::RunLoop().RunUntilIdle();
2386 2386
2387 EXPECT_TRUE(audio_read_done); 2387 EXPECT_TRUE(audio_read_done);
2388 EXPECT_TRUE(video_read_done); 2388 EXPECT_TRUE(video_read_done);
2389 } 2389 }
2390 2390
2391 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { 2391 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) {
2392 EXPECT_CALL(*this, DemuxerOpened()); 2392 EXPECT_CALL(*this, DemuxerOpened());
2393 demuxer_->Initialize( 2393 demuxer_->Initialize(
2394 &host_, 2394 &host_,
2395 CreateInitDoneCB(kNoTimestamp(), CHUNK_DEMUXER_ERROR_APPEND_FAILED), 2395 CreateInitDoneCB(kNoTimestamp(), CHUNK_DEMUXER_ERROR_APPEND_FAILED),
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2579 2579
2580 // Read() from audio should return normal buffers. 2580 // Read() from audio should return normal buffers.
2581 GenerateAudioStreamExpectedReads(0, 4); 2581 GenerateAudioStreamExpectedReads(0, 4);
2582 2582
2583 // Remove the audio id. 2583 // Remove the audio id.
2584 demuxer_->RemoveId(audio_id); 2584 demuxer_->RemoveId(audio_id);
2585 2585
2586 // Read() from audio should return "end of stream" buffers. 2586 // Read() from audio should return "end of stream" buffers.
2587 bool audio_read_done = false; 2587 bool audio_read_done = false;
2588 ReadAudio(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); 2588 ReadAudio(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
2589 message_loop_.RunUntilIdle(); 2589 base::RunLoop().RunUntilIdle();
2590 EXPECT_TRUE(audio_read_done); 2590 EXPECT_TRUE(audio_read_done);
2591 2591
2592 // Read() from video should still return normal buffers. 2592 // Read() from video should still return normal buffers.
2593 GenerateVideoStreamExpectedReads(0, 4); 2593 GenerateVideoStreamExpectedReads(0, 4);
2594 } 2594 }
2595 2595
2596 // Test that removing an ID immediately after adding it does not interfere with 2596 // Test that removing an ID immediately after adding it does not interfere with
2597 // quota for new IDs in the future. 2597 // quota for new IDs in the future.
2598 TEST_F(ChunkDemuxerTest, RemoveAndAddId) { 2598 TEST_F(ChunkDemuxerTest, RemoveAndAddId) {
2599 std::string audio_id_1 = "audio1"; 2599 std::string audio_id_1 = "audio1";
(...skipping 18 matching lines...) Expand all
2618 bool video_read_done = false; 2618 bool video_read_done = false;
2619 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); 2619 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done));
2620 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); 2620 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done));
2621 EXPECT_FALSE(audio_read_done); 2621 EXPECT_FALSE(audio_read_done);
2622 EXPECT_FALSE(video_read_done); 2622 EXPECT_FALSE(video_read_done);
2623 2623
2624 // Now cancel the pending seek, which should flush the reads with empty 2624 // Now cancel the pending seek, which should flush the reads with empty
2625 // buffers. 2625 // buffers.
2626 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); 2626 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0);
2627 demuxer_->CancelPendingSeek(seek_time); 2627 demuxer_->CancelPendingSeek(seek_time);
2628 message_loop_.RunUntilIdle(); 2628 base::RunLoop().RunUntilIdle();
2629 EXPECT_TRUE(audio_read_done); 2629 EXPECT_TRUE(audio_read_done);
2630 EXPECT_TRUE(video_read_done); 2630 EXPECT_TRUE(video_read_done);
2631 2631
2632 // A seek back to the buffered region should succeed. 2632 // A seek back to the buffered region should succeed.
2633 Seek(seek_time); 2633 Seek(seek_time);
2634 GenerateExpectedReads(0, 4); 2634 GenerateExpectedReads(0, 4);
2635 } 2635 }
2636 2636
2637 TEST_F(ChunkDemuxerTest, SeekCanceledWhileWaitingForSeek) { 2637 TEST_F(ChunkDemuxerTest, SeekCanceledWhileWaitingForSeek) {
2638 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2638 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 EXPECT_FALSE(audio_read_done); 2702 EXPECT_FALSE(audio_read_done);
2703 EXPECT_FALSE(video_read_done); 2703 EXPECT_FALSE(video_read_done);
2704 2704
2705 ASSERT_TRUE(AppendCluster( 2705 ASSERT_TRUE(AppendCluster(
2706 audio_id, GenerateSingleStreamCluster(3000, 3092, kAudioTrackNum, 2706 audio_id, GenerateSingleStreamCluster(3000, 3092, kAudioTrackNum,
2707 kAudioBlockDuration))); 2707 kAudioBlockDuration)));
2708 ASSERT_TRUE(AppendCluster( 2708 ASSERT_TRUE(AppendCluster(
2709 video_id, GenerateSingleStreamCluster(3000, 3132, kVideoTrackNum, 2709 video_id, GenerateSingleStreamCluster(3000, 3132, kVideoTrackNum,
2710 kVideoBlockDuration))); 2710 kVideoBlockDuration)));
2711 2711
2712 message_loop_.RunUntilIdle(); 2712 base::RunLoop().RunUntilIdle();
2713 2713
2714 // Read() should return buffers at 3. 2714 // Read() should return buffers at 3.
2715 EXPECT_TRUE(audio_read_done); 2715 EXPECT_TRUE(audio_read_done);
2716 EXPECT_TRUE(video_read_done); 2716 EXPECT_TRUE(video_read_done);
2717 } 2717 }
2718 2718
2719 // Test that Seek() completes successfully when EndOfStream 2719 // Test that Seek() completes successfully when EndOfStream
2720 // is called before data is available for that seek point. 2720 // is called before data is available for that seek point.
2721 // This scenario might be useful if seeking past the end of stream 2721 // This scenario might be useful if seeking past the end of stream
2722 // of either audio or video (or both). 2722 // of either audio or video (or both).
2723 TEST_F(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) { 2723 TEST_F(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) {
2724 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2724 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2725 2725
2726 AppendMuxedCluster( 2726 AppendMuxedCluster(
2727 MuxedStreamInfo(kAudioTrackNum, 2727 MuxedStreamInfo(kAudioTrackNum,
2728 "0K 10K 20K 30K 40K 50K 60K 70K 80K 90K 100K 110K", 10), 2728 "0K 10K 20K 30K 40K 50K 60K 70K 80K 90K 100K 110K", 10),
2729 MuxedStreamInfo(kVideoTrackNum, "0K 20K 40K 60K 80K", 20)); 2729 MuxedStreamInfo(kVideoTrackNum, "0K 20K 40K 60K 80K", 20));
2730 CheckExpectedRanges("{ [0,100) }"); 2730 CheckExpectedRanges("{ [0,100) }");
2731 2731
2732 // Seeking past the end of video. 2732 // Seeking past the end of video.
2733 // Note: audio data is available for that seek point. 2733 // Note: audio data is available for that seek point.
2734 bool seek_cb_was_called = false; 2734 bool seek_cb_was_called = false;
2735 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110); 2735 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110);
2736 demuxer_->StartWaitingForSeek(seek_time); 2736 demuxer_->StartWaitingForSeek(seek_time);
2737 demuxer_->Seek(seek_time, 2737 demuxer_->Seek(seek_time,
2738 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 2738 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
2739 message_loop_.RunUntilIdle(); 2739 base::RunLoop().RunUntilIdle();
2740 2740
2741 EXPECT_FALSE(seek_cb_was_called); 2741 EXPECT_FALSE(seek_cb_was_called);
2742 2742
2743 EXPECT_CALL(host_, SetDuration( 2743 EXPECT_CALL(host_, SetDuration(
2744 base::TimeDelta::FromMilliseconds(120))); 2744 base::TimeDelta::FromMilliseconds(120)));
2745 MarkEndOfStream(PIPELINE_OK); 2745 MarkEndOfStream(PIPELINE_OK);
2746 CheckExpectedRanges("{ [0,120) }"); 2746 CheckExpectedRanges("{ [0,120) }");
2747 message_loop_.RunUntilIdle(); 2747 base::RunLoop().RunUntilIdle();
2748 2748
2749 EXPECT_TRUE(seek_cb_was_called); 2749 EXPECT_TRUE(seek_cb_was_called);
2750 2750
2751 ShutdownDemuxer(); 2751 ShutdownDemuxer();
2752 } 2752 }
2753 2753
2754 // Test that EndOfStream is ignored if coming during a pending seek 2754 // Test that EndOfStream is ignored if coming during a pending seek
2755 // whose seek time is before some existing ranges. 2755 // whose seek time is before some existing ranges.
2756 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) { 2756 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) {
2757 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2757 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2758 2758
2759 AppendMuxedCluster( 2759 AppendMuxedCluster(
2760 MuxedStreamInfo(kAudioTrackNum, 2760 MuxedStreamInfo(kAudioTrackNum,
2761 "0K 10K 20K 30K 40K 50K 60K 70K 80K 90K 100K 110K", 10), 2761 "0K 10K 20K 30K 40K 50K 60K 70K 80K 90K 100K 110K", 10),
2762 MuxedStreamInfo(kVideoTrackNum, "0K 20K 40K 60K 80K", 20)); 2762 MuxedStreamInfo(kVideoTrackNum, "0K 20K 40K 60K 80K", 20));
2763 AppendMuxedCluster( 2763 AppendMuxedCluster(
2764 MuxedStreamInfo(kAudioTrackNum, 2764 MuxedStreamInfo(kAudioTrackNum,
2765 "200K 210K 220K 230K 240K 250K 260K 270K 280K 290K", 10), 2765 "200K 210K 220K 230K 240K 250K 260K 270K 280K 290K", 10),
2766 MuxedStreamInfo(kVideoTrackNum, "200K 220K 240K 260K 280K", 20)); 2766 MuxedStreamInfo(kVideoTrackNum, "200K 220K 240K 260K 280K", 20));
2767 2767
2768 bool seek_cb_was_called = false; 2768 bool seek_cb_was_called = false;
2769 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160); 2769 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160);
2770 demuxer_->StartWaitingForSeek(seek_time); 2770 demuxer_->StartWaitingForSeek(seek_time);
2771 demuxer_->Seek(seek_time, 2771 demuxer_->Seek(seek_time,
2772 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 2772 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
2773 message_loop_.RunUntilIdle(); 2773 base::RunLoop().RunUntilIdle();
2774 2774
2775 EXPECT_FALSE(seek_cb_was_called); 2775 EXPECT_FALSE(seek_cb_was_called);
2776 2776
2777 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(300))); 2777 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(300)));
2778 MarkEndOfStream(PIPELINE_OK); 2778 MarkEndOfStream(PIPELINE_OK);
2779 message_loop_.RunUntilIdle(); 2779 base::RunLoop().RunUntilIdle();
2780 2780
2781 EXPECT_FALSE(seek_cb_was_called); 2781 EXPECT_FALSE(seek_cb_was_called);
2782 2782
2783 demuxer_->UnmarkEndOfStream(); 2783 demuxer_->UnmarkEndOfStream();
2784 2784
2785 AppendMuxedCluster( 2785 AppendMuxedCluster(
2786 MuxedStreamInfo(kAudioTrackNum, "140K 150K 160K 170K", 10), 2786 MuxedStreamInfo(kAudioTrackNum, "140K 150K 160K 170K", 10),
2787 MuxedStreamInfo(kVideoTrackNum, "140K 145K 150K 155K 160K 165K 170K 175K", 2787 MuxedStreamInfo(kVideoTrackNum, "140K 145K 150K 155K 160K 165K 170K 175K",
2788 20)); 2788 20));
2789 2789
2790 message_loop_.RunUntilIdle(); 2790 base::RunLoop().RunUntilIdle();
2791 2791
2792 EXPECT_TRUE(seek_cb_was_called); 2792 EXPECT_TRUE(seek_cb_was_called);
2793 2793
2794 ShutdownDemuxer(); 2794 ShutdownDemuxer();
2795 } 2795 }
2796 2796
2797 // Test ranges in an audio-only stream. 2797 // Test ranges in an audio-only stream.
2798 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { 2798 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) {
2799 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 2799 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
2800 2800
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
3728 MarkEndOfStream(PIPELINE_OK); 3728 MarkEndOfStream(PIPELINE_OK);
3729 } 3729 }
3730 3730
3731 // Test receiving a Shutdown() call before we get an Initialize() 3731 // Test receiving a Shutdown() call before we get an Initialize()
3732 // call. This can happen if video element gets destroyed before 3732 // call. This can happen if video element gets destroyed before
3733 // the pipeline has a chance to initialize the demuxer. 3733 // the pipeline has a chance to initialize the demuxer.
3734 TEST_F(ChunkDemuxerTest, Shutdown_BeforeInitialize) { 3734 TEST_F(ChunkDemuxerTest, Shutdown_BeforeInitialize) {
3735 demuxer_->Shutdown(); 3735 demuxer_->Shutdown();
3736 demuxer_->Initialize( 3736 demuxer_->Initialize(
3737 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); 3737 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true);
3738 message_loop_.RunUntilIdle(); 3738 base::RunLoop().RunUntilIdle();
3739 } 3739 }
3740 3740
3741 // Verifies that signaling end of stream while stalled at a gap 3741 // Verifies that signaling end of stream while stalled at a gap
3742 // boundary does not trigger end of stream buffers to be returned. 3742 // boundary does not trigger end of stream buffers to be returned.
3743 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { 3743 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) {
3744 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3744 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3745 3745
3746 ASSERT_TRUE(AppendCluster(0, 10)); 3746 ASSERT_TRUE(AppendCluster(0, 10));
3747 ASSERT_TRUE(AppendCluster(300, 10)); 3747 ASSERT_TRUE(AppendCluster(300, 10));
3748 CheckExpectedRanges("{ [0,132) [300,432) }"); 3748 CheckExpectedRanges("{ [0,132) [300,432) }");
(...skipping 17 matching lines...) Expand all
3766 MarkEndOfStream(PIPELINE_OK); 3766 MarkEndOfStream(PIPELINE_OK);
3767 3767
3768 // Verify that the reads still haven't completed. 3768 // Verify that the reads still haven't completed.
3769 EXPECT_FALSE(audio_read_done); 3769 EXPECT_FALSE(audio_read_done);
3770 EXPECT_FALSE(video_read_done); 3770 EXPECT_FALSE(video_read_done);
3771 3771
3772 demuxer_->UnmarkEndOfStream(); 3772 demuxer_->UnmarkEndOfStream();
3773 3773
3774 ASSERT_TRUE(AppendCluster(138, 22)); 3774 ASSERT_TRUE(AppendCluster(138, 22));
3775 3775
3776 message_loop_.RunUntilIdle(); 3776 base::RunLoop().RunUntilIdle();
3777 3777
3778 CheckExpectedRanges("{ [0,435) }"); 3778 CheckExpectedRanges("{ [0,435) }");
3779 3779
3780 // Verify that the reads have completed. 3780 // Verify that the reads have completed.
3781 EXPECT_TRUE(audio_read_done); 3781 EXPECT_TRUE(audio_read_done);
3782 EXPECT_TRUE(video_read_done); 3782 EXPECT_TRUE(video_read_done);
3783 3783
3784 // Read the rest of the buffers. 3784 // Read the rest of the buffers.
3785 GenerateExpectedReads(161, 171, 20); 3785 GenerateExpectedReads(161, 171, 20);
3786 3786
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
4339 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 4339 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
4340 4340
4341 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4341 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
4342 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 4342 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
4343 4343
4344 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120); 4344 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120);
4345 bool seek_cb_was_called = false; 4345 bool seek_cb_was_called = false;
4346 demuxer_->StartWaitingForSeek(seek_time); 4346 demuxer_->StartWaitingForSeek(seek_time);
4347 demuxer_->Seek(seek_time, 4347 demuxer_->Seek(seek_time,
4348 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 4348 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
4349 message_loop_.RunUntilIdle(); 4349 base::RunLoop().RunUntilIdle();
4350 4350
4351 EXPECT_FALSE(seek_cb_was_called); 4351 EXPECT_FALSE(seek_cb_was_called);
4352 4352
4353 bool text_read_done = false; 4353 bool text_read_done = false;
4354 text_stream->Read(base::Bind(&OnReadDone, 4354 text_stream->Read(base::Bind(&OnReadDone,
4355 base::TimeDelta::FromMilliseconds(225), 4355 base::TimeDelta::FromMilliseconds(225),
4356 &text_read_done)); 4356 &text_read_done));
4357 4357
4358 // Append audio & video data so the seek completes. 4358 // Append audio & video data so the seek completes.
4359 AppendMuxedCluster( 4359 AppendMuxedCluster(
4360 MuxedStreamInfo(kAudioTrackNum, 4360 MuxedStreamInfo(kAudioTrackNum,
4361 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K 200K", 20), 4361 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K 200K", 20),
4362 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180 210", 30)); 4362 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180 210", 30));
4363 4363
4364 message_loop_.RunUntilIdle(); 4364 base::RunLoop().RunUntilIdle();
4365 EXPECT_TRUE(seek_cb_was_called); 4365 EXPECT_TRUE(seek_cb_was_called);
4366 EXPECT_FALSE(text_read_done); 4366 EXPECT_FALSE(text_read_done);
4367 4367
4368 // Read some audio & video buffers to further verify seek completion. 4368 // Read some audio & video buffers to further verify seek completion.
4369 CheckExpectedBuffers(audio_stream, "120K 140K"); 4369 CheckExpectedBuffers(audio_stream, "120K 140K");
4370 CheckExpectedBuffers(video_stream, "120K 150"); 4370 CheckExpectedBuffers(video_stream, "120K 150");
4371 4371
4372 EXPECT_FALSE(text_read_done); 4372 EXPECT_FALSE(text_read_done);
4373 4373
4374 // Append text cues that start after the seek point and verify that 4374 // Append text cues that start after the seek point and verify that
4375 // they are returned by Read() calls. 4375 // they are returned by Read() calls.
4376 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "220K 240K 260K 280K", 20), 4376 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "220K 240K 260K 280K", 20),
4377 MuxedStreamInfo(kVideoTrackNum, "240K 270 300 330", 30), 4377 MuxedStreamInfo(kVideoTrackNum, "240K 270 300 330", 30),
4378 MuxedStreamInfo(kTextTrackNum, "225K 275K 325K")); 4378 MuxedStreamInfo(kTextTrackNum, "225K 275K 325K"));
4379 4379
4380 message_loop_.RunUntilIdle(); 4380 base::RunLoop().RunUntilIdle();
4381 EXPECT_TRUE(text_read_done); 4381 EXPECT_TRUE(text_read_done);
4382 4382
4383 // NOTE: we start at 275 here because the buffer at 225 was returned 4383 // NOTE: we start at 275 here because the buffer at 225 was returned
4384 // to the pending read initiated above. 4384 // to the pending read initiated above.
4385 CheckExpectedBuffers(text_stream, "275K 325K"); 4385 CheckExpectedBuffers(text_stream, "275K 325K");
4386 4386
4387 // Verify that audio & video streams continue to return expected values. 4387 // Verify that audio & video streams continue to return expected values.
4388 CheckExpectedBuffers(audio_stream, "160K 180K"); 4388 CheckExpectedBuffers(audio_stream, "160K 180K");
4389 CheckExpectedBuffers(video_stream, "180 210"); 4389 CheckExpectedBuffers(video_stream, "180 210");
4390 } 4390 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
4705 cluster->size() - video_start)); 4705 cluster->size() - video_start));
4706 4706
4707 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); 4707 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }");
4708 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); 4708 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }");
4709 CheckExpectedRanges("{ [30,90) }"); 4709 CheckExpectedRanges("{ [30,90) }");
4710 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); 4710 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K");
4711 CheckExpectedBuffers(video_stream, "71K 81"); 4711 CheckExpectedBuffers(video_stream, "71K 81");
4712 } 4712 }
4713 4713
4714 } // namespace media 4714 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/audio_decoder_selector_unittest.cc ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698