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

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

Issue 414603002: Add support for partial append window end trimming. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typos. Created 6 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 | 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 <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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 if (track_number == kTextTrackNum || 452 if (track_number == kTextTrackNum ||
453 track_number == kAlternateTextTrackNum) { 453 track_number == kAlternateTextTrackNum) {
454 block_info.duration = kTextBlockDuration; 454 block_info.duration = kTextBlockDuration;
455 ASSERT_EQ(kWebMFlagKeyframe, block_info.flags) 455 ASSERT_EQ(kWebMFlagKeyframe, block_info.flags)
456 << "Text block with timestamp " << block_info.timestamp_in_ms 456 << "Text block with timestamp " << block_info.timestamp_in_ms
457 << " was not marked as a keyframe." 457 << " was not marked as a keyframe."
458 << " All text blocks must be keyframes"; 458 << " All text blocks must be keyframes";
459 } 459 }
460 460
461 if (track_number == kAudioTrackNum)
462 block_info.flags = kWebMFlagKeyframe;
463
461 blocks->push_back(block_info); 464 blocks->push_back(block_info);
462 } 465 }
463 } 466 }
464 467
465 scoped_ptr<Cluster> GenerateCluster(const std::vector<BlockInfo>& blocks, 468 scoped_ptr<Cluster> GenerateCluster(const std::vector<BlockInfo>& blocks,
466 bool unknown_size) { 469 bool unknown_size) {
467 DCHECK_GT(blocks.size(), 0u); 470 DCHECK_GT(blocks.size(), 0u);
468 ClusterBuilder cb; 471 ClusterBuilder cb;
469 472
470 std::vector<uint8> data(10); 473 std::vector<uint8> data(10);
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 DemuxerStream* text_stream = NULL; 1366 DemuxerStream* text_stream = NULL;
1364 EXPECT_CALL(host_, AddTextStream(_, _)) 1367 EXPECT_CALL(host_, AddTextStream(_, _))
1365 .WillOnce(SaveArg<0>(&text_stream)); 1368 .WillOnce(SaveArg<0>(&text_stream));
1366 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( 1369 ASSERT_TRUE(InitDemuxerWithEncryptionInfo(
1367 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); 1370 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false));
1368 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1371 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1369 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1372 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1370 ASSERT_TRUE(audio_stream && video_stream && text_stream); 1373 ASSERT_TRUE(audio_stream && video_stream && text_stream);
1371 1374
1372 AppendMuxedCluster( 1375 AppendMuxedCluster(
1373 MuxedStreamInfo(kAudioTrackNum, "0 23K"), 1376 MuxedStreamInfo(kAudioTrackNum, "0 23K"),
acolwell GONE FROM CHROMIUM 2014/07/23 00:15:42 nit: Remove 0 and s/23K/23D23K/ . The intent of th
DaleCurtis 2014/07/23 01:50:41 Doesn't look like "D" is an understood code here.
1374 MuxedStreamInfo(kVideoTrackNum, "0 30K"), 1377 MuxedStreamInfo(kVideoTrackNum, "0 30K"),
1375 MuxedStreamInfo(kTextTrackNum, "25K 40K")); 1378 MuxedStreamInfo(kTextTrackNum, "25K 40K"));
1376 CheckExpectedRanges(kSourceId, "{ [23,46) }"); 1379 CheckExpectedRanges(kSourceId, "{ [0,46) }");
acolwell GONE FROM CHROMIUM 2014/07/23 00:15:42 This shouldn't be needed after the change above.
DaleCurtis 2014/07/23 01:50:41 Acknowledged.
1377 1380
1378 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); 1381 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO);
1379 AppendMuxedCluster( 1382 AppendMuxedCluster(
1380 MuxedStreamInfo(kAudioTrackNum, "46 69K"), 1383 MuxedStreamInfo(kAudioTrackNum, "46 69K"),
acolwell GONE FROM CHROMIUM 2014/07/23 00:15:42 nit: s/46/46K/ just so it is explicit please.
DaleCurtis 2014/07/23 01:50:41 Done.
1381 MuxedStreamInfo(kVideoTrackNum, "60 90K"), 1384 MuxedStreamInfo(kVideoTrackNum, "60 90K"),
1382 MuxedStreamInfo(kTextTrackNum, "80K 90K")); 1385 MuxedStreamInfo(kTextTrackNum, "80K 90K"));
1383 CheckExpectedRanges(kSourceId, "{ [23,92) }"); 1386 CheckExpectedRanges(kSourceId, "{ [0,92) }");
acolwell GONE FROM CHROMIUM 2014/07/23 00:15:42 ditto
DaleCurtis 2014/07/23 01:50:41 Acknowledged.
1384 1387
1385 CheckExpectedBuffers(audio_stream, "23 69"); 1388 CheckExpectedBuffers(audio_stream, "0 23");
acolwell GONE FROM CHROMIUM 2014/07/23 00:15:42 I think this should be "23 46 69" since everything
DaleCurtis 2014/07/23 01:50:41 23 43 with my change above.
1386 CheckExpectedBuffers(video_stream, "30 90"); 1389 CheckExpectedBuffers(video_stream, "30 90");
1387 CheckExpectedBuffers(text_stream, "25 40 80 90"); 1390 CheckExpectedBuffers(text_stream, "25 40 80 90");
1388 } 1391 }
1389 1392
1390 // Make sure that the demuxer reports an error if Shutdown() 1393 // Make sure that the demuxer reports an error if Shutdown()
1391 // is called before all the initialization segments are appended. 1394 // is called before all the initialization segments are appended.
1392 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1395 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1393 EXPECT_CALL(*this, DemuxerOpened()); 1396 EXPECT_CALL(*this, DemuxerOpened());
1394 demuxer_->Initialize( 1397 demuxer_->Initialize(
1395 &host_, CreateInitDoneCB( 1398 &host_, CreateInitDoneCB(
(...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 AppendSingleStreamCluster( 3352 AppendSingleStreamCluster(
3350 kSourceId, kAudioTrackNum, 3353 kSourceId, kAudioTrackNum,
3351 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); 3354 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K");
3352 3355
3353 // Verify that frames that end outside the window are not included 3356 // Verify that frames that end outside the window are not included
3354 // in the buffer. Also verify that buffers that start inside the 3357 // in the buffer. Also verify that buffers that start inside the
3355 // window and extend beyond the end of the window are not included. 3358 // window and extend beyond the end of the window are not included.
3356 // 3359 //
3357 // The first 50ms of the range should be truncated since it overlaps 3360 // The first 50ms of the range should be truncated since it overlaps
3358 // the start of the append window. 3361 // the start of the append window.
3359 CheckExpectedRanges(kSourceId, "{ [50,270) }"); 3362 CheckExpectedRanges(kSourceId, "{ [50,280) }");
acolwell GONE FROM CHROMIUM 2014/07/23 00:15:42 why did this and the range below change?
DaleCurtis 2014/07/23 01:50:41 Previously 270K was being entirely discarded since
3360 3363
3361 // The "50P" buffer is the "0" buffer marked for complete discard. The next 3364 // The "50P" buffer is the "0" buffer marked for complete discard. The next
3362 // "50" buffer is the "30" buffer marked with 20ms of start discard. 3365 // "50" buffer is the "30" buffer marked with 20ms of start discard.
3363 CheckExpectedBuffers(stream, "50P 50 60 90 120 150 180 210 240"); 3366 CheckExpectedBuffers(stream, "50P 50 60 90 120 150 180 210 240");
3364 3367
3365 // Extend the append window to [50,650). 3368 // Extend the append window to [50,650).
3366 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3369 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3367 3370
3368 // Append more data and verify that a new range is created. 3371 // Append more data and verify that a new range is created.
3369 AppendSingleStreamCluster( 3372 AppendSingleStreamCluster(
3370 kSourceId, kAudioTrackNum, 3373 kSourceId, kAudioTrackNum,
3371 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 3374 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3372 CheckExpectedRanges(kSourceId, "{ [50,270) [360,630) }"); 3375 CheckExpectedRanges(kSourceId, "{ [50,280) [360,650) }");
3373 } 3376 }
3374 3377
3375 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { 3378 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) {
3376 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3379 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3377 3380
3378 // Set the append window to [10,20). 3381 // Set the append window to [10,20).
3379 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); 3382 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10);
3380 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3383 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3381 3384
3382 // Append a cluster that starts before and ends after the append window. 3385 // Append a cluster that starts before and ends after the append window.
3383 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K"); 3386 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K");
3384 3387
3385 // Verify that everything is dropped in this case. No partial append should 3388 // Verify the append is clipped to the append window.
3386 // be generated. 3389 CheckExpectedRanges(kSourceId, "{ [10,20) }");
3387 CheckExpectedRanges(kSourceId, "{ }");
3388 } 3390 }
3389 3391
3390 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) { 3392 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) {
3391 EXPECT_CALL(*this, DemuxerOpened()); 3393 EXPECT_CALL(*this, DemuxerOpened());
3392 demuxer_->Initialize( 3394 demuxer_->Initialize(
3393 &host_, 3395 &host_,
3394 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 3396 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3395 true); 3397 true);
3396 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 3398 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3397 3399
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
3653 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { 3655 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) {
3654 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3656 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3655 3657
3656 AppendCluster(GenerateCluster(0, 0, 4)); 3658 AppendCluster(GenerateCluster(0, 0, 4));
3657 AppendData(kCuesHeader, sizeof(kCuesHeader)); 3659 AppendData(kCuesHeader, sizeof(kCuesHeader));
3658 AppendCluster(GenerateCluster(46, 66, 5)); 3660 AppendCluster(GenerateCluster(46, 66, 5));
3659 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 3661 CheckExpectedRanges(kSourceId, "{ [0,115) }");
3660 } 3662 }
3661 3663
3662 } // namespace media 3664 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698