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

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

Issue 712593003: Move key frame flag from StreamParserBuffer to DecoderBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 char str[] = "\xAE\x9E\xD7\x81\x03\x73\xC5\x81\x03" 258 char str[] = "\xAE\x9E\xD7\x81\x03\x73\xC5\x81\x03"
259 "\x83\x81\x11\x86\x92" 259 "\x83\x81\x11\x86\x92"
260 "D_WEBVTT/SUBTITLES"; 260 "D_WEBVTT/SUBTITLES";
261 DCHECK_EQ(str[4], kTextTrackNum); 261 DCHECK_EQ(str[4], kTextTrackNum);
262 if (use_alternate_text_track_id) 262 if (use_alternate_text_track_id)
263 str[4] = kAlternateTextTrackNum; 263 str[4] = kAlternateTextTrackNum;
264 264
265 const int len = strlen(str); 265 const int len = strlen(str);
266 DCHECK_EQ(len, 32); 266 DCHECK_EQ(len, 32);
267 const uint8* const buf = reinterpret_cast<const uint8*>(str); 267 const uint8* const buf = reinterpret_cast<const uint8*>(str);
268 text_track_entry = DecoderBuffer::CopyFrom(buf, len); 268 text_track_entry = DecoderBuffer::CopyFrom(buf, len, false);
269 tracks_element_size += text_track_entry->data_size(); 269 tracks_element_size += text_track_entry->data_size();
270 } 270 }
271 271
272 *size = ebml_header->data_size() + info->data_size() + 272 *size = ebml_header->data_size() + info->data_size() +
273 kTracksHeaderSize + tracks_element_size; 273 kTracksHeaderSize + tracks_element_size;
274 274
275 buffer->reset(new uint8[*size]); 275 buffer->reset(new uint8[*size]);
276 276
277 uint8* buf = buffer->get(); 277 uint8* buf = buffer->get();
278 memcpy(buf, ebml_header->data(), ebml_header->data_size()); 278 memcpy(buf, ebml_header->data(), ebml_header->data_size());
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, 1067 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer,
1068 base::Unretained(this), &status, &buffer)); 1068 base::Unretained(this), &status, &buffer));
1069 base::MessageLoop::current()->RunUntilIdle(); 1069 base::MessageLoop::current()->RunUntilIdle();
1070 if (status != DemuxerStream::kOk || buffer->end_of_stream()) 1070 if (status != DemuxerStream::kOk || buffer->end_of_stream())
1071 break; 1071 break;
1072 1072
1073 if (i > 0) 1073 if (i > 0)
1074 ss << " "; 1074 ss << " ";
1075 ss << buffer->timestamp().InMilliseconds(); 1075 ss << buffer->timestamp().InMilliseconds();
1076 1076
1077 if (buffer->is_keyframe())
1078 ss << "K";
1079
1077 // Handle preroll buffers. 1080 // Handle preroll buffers.
1078 if (EndsWith(timestamps[i], "P", true)) { 1081 if (EndsWith(timestamps[i], "P", true)) {
1079 ASSERT_EQ(kInfiniteDuration(), buffer->discard_padding().first); 1082 ASSERT_EQ(kInfiniteDuration(), buffer->discard_padding().first);
1080 ASSERT_EQ(base::TimeDelta(), buffer->discard_padding().second); 1083 ASSERT_EQ(base::TimeDelta(), buffer->discard_padding().second);
1081 ss << "P"; 1084 ss << "P";
1082 } 1085 }
1083 } 1086 }
1084 EXPECT_EQ(expected, ss.str()); 1087 EXPECT_EQ(expected, ss.str());
1085 } 1088 }
1086 1089
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 append_window_end_for_next_append_, 1380 append_window_end_for_next_append_,
1378 &timestamp_offset_map_[kSourceId], 1381 &timestamp_offset_map_[kSourceId],
1379 init_segment_received_cb_); 1382 init_segment_received_cb_);
1380 1383
1381 AppendMuxedCluster( 1384 AppendMuxedCluster(
1382 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), 1385 MuxedStreamInfo(kAudioTrackNum, "46K 69K"),
1383 MuxedStreamInfo(kVideoTrackNum, "60K"), 1386 MuxedStreamInfo(kVideoTrackNum, "60K"),
1384 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); 1387 MuxedStreamInfo(kAlternateTextTrackNum, "45K"));
1385 1388
1386 CheckExpectedRanges(kSourceId, "{ [0,92) }"); 1389 CheckExpectedRanges(kSourceId, "{ [0,92) }");
1387 CheckExpectedBuffers(audio_stream, "0 23 46 69"); 1390 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K");
1388 CheckExpectedBuffers(video_stream, "0 30 60"); 1391 CheckExpectedBuffers(video_stream, "0K 30 60K");
1389 CheckExpectedBuffers(text_stream, "10 45"); 1392 CheckExpectedBuffers(text_stream, "10K 45K");
1390 1393
1391 ShutdownDemuxer(); 1394 ShutdownDemuxer();
1392 } 1395 }
1393 1396
1394 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { 1397 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) {
1395 // Tests that non-keyframes following an init segment are allowed 1398 // Tests that non-keyframes following an init segment are allowed
1396 // and dropped, as expected if the initialization segment received 1399 // and dropped, as expected if the initialization segment received
1397 // algorithm correctly sets the needs random access point flag to true for all 1400 // algorithm correctly sets the needs random access point flag to true for all
1398 // track buffers. Note that the first initialization segment is insufficient 1401 // track buffers. Note that the first initialization segment is insufficient
1399 // to fully test this since needs random access point flag initializes to 1402 // to fully test this since needs random access point flag initializes to
(...skipping 15 matching lines...) Expand all
1415 CheckExpectedRanges(kSourceId, "{ [23,46) }"); 1418 CheckExpectedRanges(kSourceId, "{ [23,46) }");
1416 1419
1417 EXPECT_CALL(*this, InitSegmentReceived()); 1420 EXPECT_CALL(*this, InitSegmentReceived());
1418 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); 1421 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO);
1419 AppendMuxedCluster( 1422 AppendMuxedCluster(
1420 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), 1423 MuxedStreamInfo(kAudioTrackNum, "46K 69K"),
1421 MuxedStreamInfo(kVideoTrackNum, "60 90K"), 1424 MuxedStreamInfo(kVideoTrackNum, "60 90K"),
1422 MuxedStreamInfo(kTextTrackNum, "80K 90K")); 1425 MuxedStreamInfo(kTextTrackNum, "80K 90K"));
1423 CheckExpectedRanges(kSourceId, "{ [23,92) }"); 1426 CheckExpectedRanges(kSourceId, "{ [23,92) }");
1424 1427
1425 CheckExpectedBuffers(audio_stream, "23 46 69"); 1428 CheckExpectedBuffers(audio_stream, "23K 46K 69K");
1426 CheckExpectedBuffers(video_stream, "30 90"); 1429 CheckExpectedBuffers(video_stream, "30K 90K");
1427 CheckExpectedBuffers(text_stream, "25 40 80 90"); 1430 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K");
1428 } 1431 }
1429 1432
1430 // Make sure that the demuxer reports an error if Shutdown() 1433 // Make sure that the demuxer reports an error if Shutdown()
1431 // is called before all the initialization segments are appended. 1434 // is called before all the initialization segments are appended.
1432 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1435 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1433 EXPECT_CALL(*this, DemuxerOpened()); 1436 EXPECT_CALL(*this, DemuxerOpened());
1434 demuxer_->Initialize( 1437 demuxer_->Initialize(
1435 &host_, CreateInitDoneCB( 1438 &host_, CreateInitDoneCB(
1436 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1439 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1437 1440
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after
3402 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3405 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3403 3406
3404 // Append a cluster that starts before and ends after the append window. 3407 // Append a cluster that starts before and ends after the append window.
3405 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3408 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3406 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3409 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3407 3410
3408 // Verify that GOPs that start outside the window are not included 3411 // Verify that GOPs that start outside the window are not included
3409 // in the buffer. Also verify that buffers that start inside the 3412 // in the buffer. Also verify that buffers that start inside the
3410 // window and extend beyond the end of the window are not included. 3413 // window and extend beyond the end of the window are not included.
3411 CheckExpectedRanges(kSourceId, "{ [120,270) }"); 3414 CheckExpectedRanges(kSourceId, "{ [120,270) }");
3412 CheckExpectedBuffers(stream, "120 150 180 210 240"); 3415 CheckExpectedBuffers(stream, "120K 150 180 210 240K");
3413 3416
3414 // Extend the append window to [50,650). 3417 // Extend the append window to [50,650).
3415 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3418 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3416 3419
3417 // Append more data and verify that adding buffers start at the next 3420 // Append more data and verify that adding buffers start at the next
3418 // keyframe. 3421 // keyframe.
3419 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3422 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3420 "360 390 420K 450 480 510 540K 570 600 630K"); 3423 "360 390 420K 450 480 510 540K 570 600 630K");
3421 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); 3424 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }");
3422 } 3425 }
(...skipping 14 matching lines...) Expand all
3437 // Verify that frames that end outside the window are not included 3440 // Verify that frames that end outside the window are not included
3438 // in the buffer. Also verify that buffers that start inside the 3441 // in the buffer. Also verify that buffers that start inside the
3439 // window and extend beyond the end of the window are not included. 3442 // window and extend beyond the end of the window are not included.
3440 // 3443 //
3441 // The first 50ms of the range should be truncated since it overlaps 3444 // The first 50ms of the range should be truncated since it overlaps
3442 // the start of the append window. 3445 // the start of the append window.
3443 CheckExpectedRanges(kSourceId, "{ [50,280) }"); 3446 CheckExpectedRanges(kSourceId, "{ [50,280) }");
3444 3447
3445 // The "50P" buffer is the "0" buffer marked for complete discard. The next 3448 // The "50P" buffer is the "0" buffer marked for complete discard. The next
3446 // "50" buffer is the "30" buffer marked with 20ms of start discard. 3449 // "50" buffer is the "30" buffer marked with 20ms of start discard.
3447 CheckExpectedBuffers(stream, "50P 50 60 90 120 150 180 210 240"); 3450 CheckExpectedBuffers(stream, "50KP 50K 60K 90K 120K 150K 180K 210K 240K");
3448 3451
3449 // Extend the append window to [50,650). 3452 // Extend the append window to [50,650).
3450 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3453 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3451 3454
3452 // Append more data and verify that a new range is created. 3455 // Append more data and verify that a new range is created.
3453 AppendSingleStreamCluster( 3456 AppendSingleStreamCluster(
3454 kSourceId, kAudioTrackNum, 3457 kSourceId, kAudioTrackNum,
3455 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 3458 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3456 CheckExpectedRanges(kSourceId, "{ [50,280) [360,650) }"); 3459 CheckExpectedRanges(kSourceId, "{ [50,280) [360,650) }");
3457 } 3460 }
(...skipping 26 matching lines...) Expand all
3484 3487
3485 // Read a WebM file into memory and send the data to the demuxer. The chunk 3488 // Read a WebM file into memory and send the data to the demuxer. The chunk
3486 // size has been chosen carefully to ensure the preroll buffer used by the 3489 // size has been chosen carefully to ensure the preroll buffer used by the
3487 // partial append window trim must come from a previous Append() call. 3490 // partial append window trim must come from a previous Append() call.
3488 scoped_refptr<DecoderBuffer> buffer = 3491 scoped_refptr<DecoderBuffer> buffer =
3489 ReadTestDataFile("bear-320x240-audio-only.webm"); 3492 ReadTestDataFile("bear-320x240-audio-only.webm");
3490 EXPECT_CALL(*this, InitSegmentReceived()); 3493 EXPECT_CALL(*this, InitSegmentReceived());
3491 AppendDataInPieces(buffer->data(), buffer->data_size(), 128); 3494 AppendDataInPieces(buffer->data(), buffer->data_size(), 128);
3492 3495
3493 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3496 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3494 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128"); 3497 CheckExpectedBuffers(stream, "50KP 50K 62K 86K 109K 122K 125K 128K");
3495 } 3498 }
3496 3499
3497 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { 3500 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) {
3498 EXPECT_CALL(*this, DemuxerOpened()); 3501 EXPECT_CALL(*this, DemuxerOpened());
3499 demuxer_->Initialize( 3502 demuxer_->Initialize(
3500 &host_, 3503 &host_,
3501 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 3504 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3502 true); 3505 true);
3503 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 3506 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3504 3507
(...skipping 21 matching lines...) Expand all
3526 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); 3529 ReadTestDataFile("bear-320x240-audio-only-48khz.webm");
3527 EXPECT_CALL(*this, InitSegmentReceived()); 3530 EXPECT_CALL(*this, InitSegmentReceived());
3528 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); 3531 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber());
3529 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); 3532 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1));
3530 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); 3533 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512);
3531 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); 3534 CheckExpectedRanges(kSourceId, "{ [2746,5519) }");
3532 3535
3533 Seek(duration_1); 3536 Seek(duration_1);
3534 ExpectConfigChanged(DemuxerStream::AUDIO); 3537 ExpectConfigChanged(DemuxerStream::AUDIO);
3535 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); 3538 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config()));
3536 CheckExpectedBuffers(stream, "2746 2767 2789 2810"); 3539 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K");
3537 } 3540 }
3538 3541
3539 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { 3542 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3540 DemuxerStream* text_stream = NULL; 3543 DemuxerStream* text_stream = NULL;
3541 EXPECT_CALL(host_, AddTextStream(_, _)) 3544 EXPECT_CALL(host_, AddTextStream(_, _))
3542 .WillOnce(SaveArg<0>(&text_stream)); 3545 .WillOnce(SaveArg<0>(&text_stream));
3543 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 3546 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3544 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3547 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3545 3548
3546 // Set the append window to [20,280). 3549 // Set the append window to [20,280).
3547 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3550 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3548 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3551 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3549 3552
3550 // Append a cluster that starts before and ends after the append 3553 // Append a cluster that starts before and ends after the append
3551 // window. 3554 // window.
3552 AppendMuxedCluster( 3555 AppendMuxedCluster(
3553 MuxedStreamInfo(kVideoTrackNum, 3556 MuxedStreamInfo(kVideoTrackNum,
3554 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"), 3557 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"),
3555 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K 300K" )); 3558 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K 300K" ));
3556 3559
3557 // Verify that text cues that start outside the window are not included 3560 // Verify that text cues that start outside the window are not included
3558 // in the buffer. Also verify that cues that extend beyond the 3561 // in the buffer. Also verify that cues that extend beyond the
3559 // window are not included. 3562 // window are not included.
3560 CheckExpectedRanges(kSourceId, "{ [100,270) }"); 3563 CheckExpectedRanges(kSourceId, "{ [100,270) }");
3561 CheckExpectedBuffers(video_stream, "120 150 180 210 240"); 3564 CheckExpectedBuffers(video_stream, "120K 150 180 210 240K");
3562 CheckExpectedBuffers(text_stream, "100"); 3565 CheckExpectedBuffers(text_stream, "100K");
3563 3566
3564 // Extend the append window to [20,650). 3567 // Extend the append window to [20,650).
3565 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3568 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3566 3569
3567 // Append more data and verify that a new range is created. 3570 // Append more data and verify that a new range is created.
3568 AppendMuxedCluster( 3571 AppendMuxedCluster(
3569 MuxedStreamInfo(kVideoTrackNum, 3572 MuxedStreamInfo(kVideoTrackNum,
3570 "360 390 420K 450 480 510 540K 570 600 630K"), 3573 "360 390 420K 450 480 510 540K 570 600 630K"),
3571 MuxedStreamInfo(kTextTrackNum, "400K 500K 600K 700K" )); 3574 MuxedStreamInfo(kTextTrackNum, "400K 500K 600K 700K" ));
3572 CheckExpectedRanges(kSourceId, "{ [100,270) [400,630) }"); 3575 CheckExpectedRanges(kSourceId, "{ [100,270) [400,630) }");
3573 3576
3574 // Seek to the new range and verify that the expected buffers are returned. 3577 // Seek to the new range and verify that the expected buffers are returned.
3575 Seek(base::TimeDelta::FromMilliseconds(420)); 3578 Seek(base::TimeDelta::FromMilliseconds(420));
3576 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600"); 3579 CheckExpectedBuffers(video_stream, "420K 450 480 510 540K 570 600");
3577 CheckExpectedBuffers(text_stream, "400 500"); 3580 CheckExpectedBuffers(text_stream, "400K 500K");
3578 } 3581 }
3579 3582
3580 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { 3583 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) {
3581 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3584 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3582 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 3585 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
3583 AppendGarbage(); 3586 AppendGarbage();
3584 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); 3587 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50);
3585 demuxer_->StartWaitingForSeek(seek_time); 3588 demuxer_->StartWaitingForSeek(seek_time);
3586 } 3589 }
3587 3590
3588 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) { 3591 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) {
3589 DemuxerStream* text_stream = NULL; 3592 DemuxerStream* text_stream = NULL;
3590 EXPECT_CALL(host_, AddTextStream(_, _)) 3593 EXPECT_CALL(host_, AddTextStream(_, _))
3591 .WillOnce(SaveArg<0>(&text_stream)); 3594 .WillOnce(SaveArg<0>(&text_stream));
3592 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 3595 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
3593 3596
3594 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3597 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3595 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3598 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3596 3599
3597 AppendMuxedCluster( 3600 AppendMuxedCluster(
3598 MuxedStreamInfo(kAudioTrackNum, "0K 20K 40K 60K 80K 100K 120K 140K"), 3601 MuxedStreamInfo(kAudioTrackNum, "0K 20K 40K 60K 80K 100K 120K 140K"),
3599 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180"), 3602 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180"),
3600 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K")); 3603 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K"));
3601 3604
3602 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); 3605 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
3603 CheckExpectedBuffers(video_stream, "0 30 60 90 120 150 180"); 3606 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180");
3604 CheckExpectedBuffers(text_stream, "0 100 200"); 3607 CheckExpectedBuffers(text_stream, "0K 100K 200K");
3605 3608
3606 // Remove the buffers that were added. 3609 // Remove the buffers that were added.
3607 demuxer_->Remove(kSourceId, base::TimeDelta(), 3610 demuxer_->Remove(kSourceId, base::TimeDelta(),
3608 base::TimeDelta::FromMilliseconds(300)); 3611 base::TimeDelta::FromMilliseconds(300));
3609 3612
3610 // Verify that all the appended data has been removed. 3613 // Verify that all the appended data has been removed.
3611 CheckExpectedRanges(kSourceId, "{ }"); 3614 CheckExpectedRanges(kSourceId, "{ }");
3612 3615
3613 // Append new buffers that are clearly different than the original 3616 // Append new buffers that are clearly different than the original
3614 // ones and verify that only the new buffers are returned. 3617 // ones and verify that only the new buffers are returned.
3615 AppendMuxedCluster( 3618 AppendMuxedCluster(
3616 MuxedStreamInfo(kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K"), 3619 MuxedStreamInfo(kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K"),
3617 MuxedStreamInfo(kVideoTrackNum, "1K 31 61 91 121K 151 181"), 3620 MuxedStreamInfo(kVideoTrackNum, "1K 31 61 91 121K 151 181"),
3618 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K")); 3621 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K"));
3619 3622
3620 Seek(base::TimeDelta()); 3623 Seek(base::TimeDelta());
3621 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141"); 3624 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K");
3622 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181"); 3625 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181");
3623 CheckExpectedBuffers(text_stream, "1 101 201"); 3626 CheckExpectedBuffers(text_stream, "1K 101K 201K");
3624 } 3627 }
3625 3628
3626 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { 3629 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) {
3627 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3630 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3628 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3631 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3629 3632
3630 // Set the duration to something small so that the append that 3633 // Set the duration to something small so that the append that
3631 // follows updates the duration to reflect the end of the appended data. 3634 // follows updates the duration to reflect the end of the appended data.
3632 EXPECT_CALL(host_, SetDuration( 3635 EXPECT_CALL(host_, SetDuration(
3633 base::TimeDelta::FromMilliseconds(1))); 3636 base::TimeDelta::FromMilliseconds(1)));
3634 demuxer_->SetDuration(0.001); 3637 demuxer_->SetDuration(0.001);
3635 3638
3636 EXPECT_CALL(host_, SetDuration( 3639 EXPECT_CALL(host_, SetDuration(
3637 base::TimeDelta::FromMilliseconds(160))); 3640 base::TimeDelta::FromMilliseconds(160)));
3638 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3641 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3639 "0K 20K 40K 60K 80K 100K 120K 140K"); 3642 "0K 20K 40K 60K 80K 100K 120K 140K");
3640 3643
3641 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 3644 CheckExpectedRanges(kSourceId, "{ [0,160) }");
3642 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); 3645 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
3643 3646
3644 demuxer_->Remove(kSourceId, 3647 demuxer_->Remove(kSourceId,
3645 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()), 3648 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()),
3646 kInfiniteDuration()); 3649 kInfiniteDuration());
3647 3650
3648 Seek(base::TimeDelta()); 3651 Seek(base::TimeDelta());
3649 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 3652 CheckExpectedRanges(kSourceId, "{ [0,160) }");
3650 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); 3653 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
3651 } 3654 }
3652 3655
3653 // Verifies that a Seek() will complete without text cues for 3656 // Verifies that a Seek() will complete without text cues for
3654 // the seek point and will return cues after the seek position 3657 // the seek point and will return cues after the seek position
3655 // when they are eventually appended. 3658 // when they are eventually appended.
3656 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { 3659 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) {
3657 DemuxerStream* text_stream = NULL; 3660 DemuxerStream* text_stream = NULL;
3658 EXPECT_CALL(host_, AddTextStream(_, _)) 3661 EXPECT_CALL(host_, AddTextStream(_, _))
3659 .WillOnce(SaveArg<0>(&text_stream)); 3662 .WillOnce(SaveArg<0>(&text_stream));
3660 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 3663 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
(...skipping 19 matching lines...) Expand all
3680 AppendMuxedCluster( 3683 AppendMuxedCluster(
3681 MuxedStreamInfo(kAudioTrackNum, 3684 MuxedStreamInfo(kAudioTrackNum,
3682 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K 200K"), 3685 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K 200K"),
3683 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180 210")); 3686 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180 210"));
3684 3687
3685 message_loop_.RunUntilIdle(); 3688 message_loop_.RunUntilIdle();
3686 EXPECT_TRUE(seek_cb_was_called); 3689 EXPECT_TRUE(seek_cb_was_called);
3687 EXPECT_FALSE(text_read_done); 3690 EXPECT_FALSE(text_read_done);
3688 3691
3689 // Read some audio & video buffers to further verify seek completion. 3692 // Read some audio & video buffers to further verify seek completion.
3690 CheckExpectedBuffers(audio_stream, "120 140"); 3693 CheckExpectedBuffers(audio_stream, "120K 140K");
3691 CheckExpectedBuffers(video_stream, "120 150"); 3694 CheckExpectedBuffers(video_stream, "120K 150");
3692 3695
3693 EXPECT_FALSE(text_read_done); 3696 EXPECT_FALSE(text_read_done);
3694 3697
3695 // Append text cues that start after the seek point and verify that 3698 // Append text cues that start after the seek point and verify that
3696 // they are returned by Read() calls. 3699 // they are returned by Read() calls.
3697 AppendMuxedCluster( 3700 AppendMuxedCluster(
3698 MuxedStreamInfo(kAudioTrackNum, "220K 240K 260K 280K"), 3701 MuxedStreamInfo(kAudioTrackNum, "220K 240K 260K 280K"),
3699 MuxedStreamInfo(kVideoTrackNum, "240K 270 300 330"), 3702 MuxedStreamInfo(kVideoTrackNum, "240K 270 300 330"),
3700 MuxedStreamInfo(kTextTrackNum, "225K 275K 325K")); 3703 MuxedStreamInfo(kTextTrackNum, "225K 275K 325K"));
3701 3704
3702 message_loop_.RunUntilIdle(); 3705 message_loop_.RunUntilIdle();
3703 EXPECT_TRUE(text_read_done); 3706 EXPECT_TRUE(text_read_done);
3704 3707
3705 // NOTE: we start at 275 here because the buffer at 225 was returned 3708 // NOTE: we start at 275 here because the buffer at 225 was returned
3706 // to the pending read initiated above. 3709 // to the pending read initiated above.
3707 CheckExpectedBuffers(text_stream, "275 325"); 3710 CheckExpectedBuffers(text_stream, "275K 325K");
3708 3711
3709 // Verify that audio & video streams continue to return expected values. 3712 // Verify that audio & video streams continue to return expected values.
3710 CheckExpectedBuffers(audio_stream, "160 180"); 3713 CheckExpectedBuffers(audio_stream, "160K 180K");
3711 CheckExpectedBuffers(video_stream, "180 210"); 3714 CheckExpectedBuffers(video_stream, "180 210");
3712 } 3715 }
3713 3716
3714 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) { 3717 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) {
3715 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3718 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3716 3719
3717 AppendCluster(GenerateCluster(0, 0, 4, true)); 3720 AppendCluster(GenerateCluster(0, 0, 4, true));
3718 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 3721 CheckExpectedRanges(kSourceId, "{ [0,46) }");
3719 3722
3720 // A new cluster indicates end of the previous cluster with unknown size. 3723 // A new cluster indicates end of the previous cluster with unknown size.
(...skipping 18 matching lines...) Expand all
3739 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { 3742 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) {
3740 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3743 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3741 3744
3742 AppendCluster(GenerateCluster(0, 0, 4)); 3745 AppendCluster(GenerateCluster(0, 0, 4));
3743 AppendData(kCuesHeader, sizeof(kCuesHeader)); 3746 AppendData(kCuesHeader, sizeof(kCuesHeader));
3744 AppendCluster(GenerateCluster(46, 66, 5)); 3747 AppendCluster(GenerateCluster(46, 66, 5));
3745 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 3748 CheckExpectedRanges(kSourceId, "{ [0,115) }");
3746 } 3749 }
3747 3750
3748 } // namespace media 3751 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698