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

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

Issue 178153004: Enable round-tripping and updating of WebSourceBufferImpl timestamp offset (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initializes |user_specified_timestamp_offset_| to 0.0. Created 6 years, 10 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 if (expected_status == PIPELINE_OK) 484 if (expected_status == PIPELINE_OK)
485 expected_duration = kDefaultDuration(); 485 expected_duration = kDefaultDuration();
486 486
487 EXPECT_CALL(*this, DemuxerOpened()); 487 EXPECT_CALL(*this, DemuxerOpened());
488 demuxer_->Initialize( 488 demuxer_->Initialize(
489 &host_, CreateInitDoneCB(expected_duration, expected_status), true); 489 &host_, CreateInitDoneCB(expected_duration, expected_status), true);
490 490
491 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) 491 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk)
492 return false; 492 return false;
493 493
494 EXPECT_EQ(0.0, demuxer_->GetTimestampOffset(kSourceId));
495
494 AppendInitSegmentWithEncryptedInfo( 496 AppendInitSegmentWithEncryptedInfo(
495 kSourceId, stream_flags, 497 kSourceId, stream_flags,
496 is_audio_encrypted, is_video_encrypted); 498 is_audio_encrypted, is_video_encrypted);
497 return true; 499 return true;
498 } 500 }
499 501
500 bool InitDemuxerAudioAndVideoSourcesText(const std::string& audio_id, 502 bool InitDemuxerAudioAndVideoSourcesText(const std::string& audio_id,
501 const std::string& video_id, 503 const std::string& video_id,
502 bool has_text) { 504 bool has_text) {
503 EXPECT_CALL(*this, DemuxerOpened()); 505 EXPECT_CALL(*this, DemuxerOpened());
(...skipping 2068 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 // seek to a new location that has the same configuration as 2574 // seek to a new location that has the same configuration as
2573 // the start of the file without a Read() in the middle. 2575 // the start of the file without a Read() in the middle.
2574 Seek(base::TimeDelta::FromMilliseconds(527)); 2576 Seek(base::TimeDelta::FromMilliseconds(527));
2575 Seek(base::TimeDelta::FromMilliseconds(801)); 2577 Seek(base::TimeDelta::FromMilliseconds(801));
2576 2578
2577 // Verify that no config change is signalled. 2579 // Verify that no config change is signalled.
2578 ExpectRead(DemuxerStream::VIDEO, 801); 2580 ExpectRead(DemuxerStream::VIDEO, 801);
2579 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); 2581 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config()));
2580 } 2582 }
2581 2583
2584 TEST_F(ChunkDemuxerTest, TimestampOffsetUserRoundTrips) {
2585 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
2586
2587 // Set an offset value that has greater precision than base::TimeDelta
2588 // microsecond granularity, and confirm that the exact value is returned
2589 // when getting the offset.
2590 double super_precise_offset = 99.123456789;
2591 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, super_precise_offset));
2592 EXPECT_EQ(super_precise_offset, demuxer_->GetTimestampOffset(kSourceId));
2593 }
2594
2582 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) { 2595 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) {
2583 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2596 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2584 2597
2585 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2598 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, 30));
2586 kSourceId, base::TimeDelta::FromSeconds(30)));
2587 AppendCluster(GenerateCluster(0, 2)); 2599 AppendCluster(GenerateCluster(0, 2));
2588 2600
2589 Seek(base::TimeDelta::FromMilliseconds(30000)); 2601 Seek(base::TimeDelta::FromMilliseconds(30000));
2590 2602
2591 GenerateExpectedReads(30000, 2); 2603 GenerateExpectedReads(30000, 2);
2592 } 2604 }
2593 2605
2594 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) { 2606 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) {
2595 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2607 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2596 2608
2597 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2609 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, -1));
2598 kSourceId, base::TimeDelta::FromSeconds(-1)));
2599 AppendCluster(GenerateCluster(1000, 2)); 2610 AppendCluster(GenerateCluster(1000, 2));
2600 2611
2601 GenerateExpectedReads(0, 2); 2612 GenerateExpectedReads(0, 2);
2602 } 2613 }
2603 2614
2604 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) { 2615 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) {
2605 std::string audio_id = "audio1"; 2616 std::string audio_id = "audio1";
2606 std::string video_id = "video1"; 2617 std::string video_id = "video1";
2607 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2618 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2608 2619
2609 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2620 ASSERT_TRUE(demuxer_->SetTimestampOffset(audio_id, -2.5));
2610 audio_id, base::TimeDelta::FromMilliseconds(-2500))); 2621 ASSERT_TRUE(demuxer_->SetTimestampOffset(video_id, -2.5));
2611 ASSERT_TRUE(demuxer_->SetTimestampOffset(
2612 video_id, base::TimeDelta::FromMilliseconds(-2500)));
2613 AppendCluster(audio_id, GenerateSingleStreamCluster(2500, 2622 AppendCluster(audio_id, GenerateSingleStreamCluster(2500,
2614 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2623 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2615 AppendCluster(video_id, GenerateSingleStreamCluster(2500, 2624 AppendCluster(video_id, GenerateSingleStreamCluster(2500,
2616 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2625 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2617 GenerateAudioStreamExpectedReads(0, 4); 2626 GenerateAudioStreamExpectedReads(0, 4);
2618 GenerateVideoStreamExpectedReads(0, 4); 2627 GenerateVideoStreamExpectedReads(0, 4);
2619 2628
2620 Seek(base::TimeDelta::FromMilliseconds(27300)); 2629 Seek(base::TimeDelta::FromMilliseconds(27300));
2621 2630
2622 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2631 ASSERT_TRUE(demuxer_->SetTimestampOffset(audio_id, 27.3));
2623 audio_id, base::TimeDelta::FromMilliseconds(27300))); 2632 ASSERT_TRUE(demuxer_->SetTimestampOffset(video_id, 27.3));
2624 ASSERT_TRUE(demuxer_->SetTimestampOffset(
2625 video_id, base::TimeDelta::FromMilliseconds(27300)));
2626 AppendCluster(audio_id, GenerateSingleStreamCluster( 2633 AppendCluster(audio_id, GenerateSingleStreamCluster(
2627 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2634 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2628 AppendCluster(video_id, GenerateSingleStreamCluster( 2635 AppendCluster(video_id, GenerateSingleStreamCluster(
2629 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2636 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2630 GenerateVideoStreamExpectedReads(27300, 4); 2637 GenerateVideoStreamExpectedReads(27300, 4);
2631 GenerateAudioStreamExpectedReads(27300, 4); 2638 GenerateAudioStreamExpectedReads(27300, 4);
2632 } 2639 }
2633 2640
2634 TEST_F(ChunkDemuxerTest, TimestampOffsetMidMediaSegment) { 2641 TEST_F(ChunkDemuxerTest, TimestampOffsetMidMediaSegment) {
2635 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2642 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2636 2643
2637 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); 2644 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2638 // Append only part of the cluster data. 2645 // Append only part of the cluster data.
2639 AppendData(cluster->data(), cluster->size() - 13); 2646 AppendData(cluster->data(), cluster->size() - 13);
2640 2647
2641 // Setting a timestamp should fail because we're in the middle of a cluster. 2648 // Setting a timestamp should fail because we're in the middle of a cluster.
2642 ASSERT_FALSE(demuxer_->SetTimestampOffset( 2649 ASSERT_FALSE(demuxer_->SetTimestampOffset(kSourceId, 25));
2643 kSourceId, base::TimeDelta::FromSeconds(25)));
2644 2650
2645 demuxer_->Abort(kSourceId); 2651 demuxer_->Abort(kSourceId);
2646 // After Abort(), setting a timestamp should succeed since we're no longer 2652 // After Abort(), setting a timestamp should succeed since we're no longer
2647 // in the middle of a cluster 2653 // in the middle of a cluster
2648 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2654 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, 25));
2649 kSourceId, base::TimeDelta::FromSeconds(25)));
2650 } 2655 }
2651 2656
2652 TEST_F(ChunkDemuxerTest, WebMParsingMediaSegmentDetection) { 2657 TEST_F(ChunkDemuxerTest, WebMParsingMediaSegmentDetection) {
2653 // TODO(wolenetz): Also test 'unknown' sized clusters. 2658 // TODO(wolenetz): Also test 'unknown' sized clusters.
2654 // See http://crbug.com/335676. 2659 // See http://crbug.com/335676.
2655 const uint8 kBuffer[] = { 2660 const uint8 kBuffer[] = {
2656 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 2661 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3)
2657 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 2662 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1)
2658 }; 2663 };
2659 2664
(...skipping 10 matching lines...) Expand all
2670 test_arrays_out_of_sync); 2675 test_arrays_out_of_sync);
2671 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); 2676 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index);
2672 2677
2673 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2678 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2674 2679
2675 for (size_t i = 0; i < sizeof(kBuffer); i++) { 2680 for (size_t i = 0; i < sizeof(kBuffer); i++) {
2676 DVLOG(3) << "Appending and testing index " << i; 2681 DVLOG(3) << "Appending and testing index " << i;
2677 AppendData(kBuffer + i, 1); 2682 AppendData(kBuffer + i, 1);
2678 bool expected_return_value = kExpectedReturnValues[i]; 2683 bool expected_return_value = kExpectedReturnValues[i];
2679 EXPECT_EQ(expected_return_value, demuxer_->SetTimestampOffset( 2684 EXPECT_EQ(expected_return_value, demuxer_->SetTimestampOffset(
2680 kSourceId, base::TimeDelta::FromSeconds(25))); 2685 kSourceId, 25));
2681 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode( 2686 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode(
2682 kSourceId, true)); 2687 kSourceId, true));
2683 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode( 2688 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode(
2684 kSourceId, false)); 2689 kSourceId, false));
2685 } 2690 }
2686 } 2691 }
2687 2692
2688 TEST_F(ChunkDemuxerTest, SetSequenceModeMidMediaSegment) { 2693 TEST_F(ChunkDemuxerTest, SetSequenceModeMidMediaSegment) {
2689 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2694 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2690 2695
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 kStreamDuration + kVideoBlockDuration, 2733 kStreamDuration + kVideoBlockDuration,
2729 2)); 2734 2));
2730 2735
2731 // See that the range has increased appropriately. 2736 // See that the range has increased appropriately.
2732 CheckExpectedRanges(kSourceId, "{ [201191,201270) }"); 2737 CheckExpectedRanges(kSourceId, "{ [201191,201270) }");
2733 } 2738 }
2734 2739
2735 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { 2740 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
2736 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2741 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2737 2742
2738 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, kDefaultDuration())); 2743 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId,
2744 kDefaultDuration().InSecondsF()));
2739 2745
2740 EXPECT_CALL(host_, SetDuration( 2746 EXPECT_CALL(host_, SetDuration(
2741 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2747 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2742 kAudioBlockDuration * 2))); 2748 kAudioBlockDuration * 2)));
2743 AppendCluster(GenerateCluster(0, 4)); 2749 AppendCluster(GenerateCluster(0, 4));
2744 } 2750 }
2745 2751
2746 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) { 2752 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) {
2747 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2753 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2748 2754
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 // NOTE: we start at 175 here because the buffer at 125 was returned 3148 // NOTE: we start at 175 here because the buffer at 125 was returned
3143 // to the pending read initiated above. 3149 // to the pending read initiated above.
3144 CheckExpectedBuffers(text_stream, "175 225"); 3150 CheckExpectedBuffers(text_stream, "175 225");
3145 3151
3146 // Verify that audio & video streams contiue to return expected values. 3152 // Verify that audio & video streams contiue to return expected values.
3147 CheckExpectedBuffers(audio_stream, "160 180"); 3153 CheckExpectedBuffers(audio_stream, "160 180");
3148 CheckExpectedBuffers(video_stream, "180 210"); 3154 CheckExpectedBuffers(video_stream, "180 210");
3149 } 3155 }
3150 3156
3151 } // namespace media 3157 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698