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

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

Issue 2273273002: Directly call ChunkDemuxer::Initialize completion callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 3 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
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | third_party/WebKit/LayoutTests/TestExpectations » ('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 "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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 void AppendGarbage() { 779 void AppendGarbage() {
780 // Fill up an array with gibberish. 780 // Fill up an array with gibberish.
781 int garbage_cluster_size = 10; 781 int garbage_cluster_size = 10;
782 std::unique_ptr<uint8_t[]> garbage_cluster( 782 std::unique_ptr<uint8_t[]> garbage_cluster(
783 new uint8_t[garbage_cluster_size]); 783 new uint8_t[garbage_cluster_size]);
784 for (int i = 0; i < garbage_cluster_size; ++i) 784 for (int i = 0; i < garbage_cluster_size; ++i)
785 garbage_cluster[i] = i; 785 garbage_cluster[i] = i;
786 ASSERT_FALSE(AppendData(garbage_cluster.get(), garbage_cluster_size)); 786 ASSERT_FALSE(AppendData(garbage_cluster.get(), garbage_cluster_size));
787 } 787 }
788 788
789 void InitDoneCalled(PipelineStatus expected_status, 789 MOCK_METHOD1(DemuxerInitialized, void(PipelineStatus));
790 PipelineStatus status) {
791 EXPECT_EQ(status, expected_status);
792 }
793 790
794 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, 791 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration,
795 PipelineStatus expected_status) { 792 PipelineStatus expected_status) {
796 if (expected_duration != kNoTimestamp) 793 if (expected_duration != kNoTimestamp)
797 EXPECT_CALL(host_, SetDuration(expected_duration)); 794 EXPECT_CALL(host_, SetDuration(expected_duration));
798 return CreateInitDoneCB(expected_status); 795 return CreateInitDoneCB(expected_status);
799 } 796 }
800 797
801 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { 798 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) {
802 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, 799 EXPECT_CALL(*this, DemuxerInitialized(expected_status));
803 base::Unretained(this), 800 return base::Bind(&ChunkDemuxerTest::DemuxerInitialized,
804 expected_status); 801 base::Unretained(this));
805 } 802 }
806 803
807 enum StreamFlags { 804 enum StreamFlags {
808 HAS_AUDIO = 1 << 0, 805 HAS_AUDIO = 1 << 0,
809 HAS_VIDEO = 1 << 1, 806 HAS_VIDEO = 1 << 1,
810 HAS_TEXT = 1 << 2, 807 HAS_TEXT = 1 << 2,
811 USE_ALTERNATE_AUDIO_TRACK_ID = 1 << 3, 808 USE_ALTERNATE_AUDIO_TRACK_ID = 1 << 3,
812 USE_ALTERNATE_VIDEO_TRACK_ID = 1 << 4, 809 USE_ALTERNATE_VIDEO_TRACK_ID = 1 << 4,
813 USE_ALTERNATE_TEXT_TRACK_ID = 1 << 5, 810 USE_ALTERNATE_TEXT_TRACK_ID = 1 << 5,
814 }; 811 };
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); 1667 CheckExpectedBuffers(audio_stream, "23K 46K 69K");
1671 CheckExpectedBuffers(video_stream, "30K 90K"); 1668 CheckExpectedBuffers(video_stream, "30K 90K");
1672 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); 1669 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K");
1673 } 1670 }
1674 1671
1675 // Make sure that the demuxer reports an error if Shutdown() 1672 // Make sure that the demuxer reports an error if Shutdown()
1676 // is called before all the initialization segments are appended. 1673 // is called before all the initialization segments are appended.
1677 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1674 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1678 EXPECT_CALL(*this, DemuxerOpened()); 1675 EXPECT_CALL(*this, DemuxerOpened());
1679 demuxer_->Initialize( 1676 demuxer_->Initialize(
1680 &host_, CreateInitDoneCB( 1677 &host_,
1681 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1678 base::Bind(&ChunkDemuxerTest_Shutdown_BeforeAllInitSegmentsAppended_Test::
xhwang 2016/09/19 17:35:12 Will &ChunkDemuxerTest:: work?
alokp 2016/09/19 17:43:20 I wish. Sorry for the ugliness. The only other wa
alokp 2016/09/19 18:50:17 Made the mock method public as discussed offline.
1679 DemuxerInitialized,
1680 base::Unretained(this)),
1681 true);
1682 1682
1683 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1683 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1684 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); 1684 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk);
1685 1685
1686 ExpectInitMediaLogs(HAS_AUDIO); 1686 ExpectInitMediaLogs(HAS_AUDIO);
1687 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); 1687 EXPECT_CALL(*this, InitSegmentReceivedMock(_));
1688 ASSERT_TRUE(AppendInitSegmentWithSourceId("audio", HAS_AUDIO)); 1688 ASSERT_TRUE(AppendInitSegmentWithSourceId("audio", HAS_AUDIO));
1689 1689
1690 ShutdownDemuxer(); 1690 ShutdownDemuxer();
1691 } 1691 }
1692 1692
1693 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { 1693 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) {
1694 EXPECT_CALL(*this, DemuxerOpened()); 1694 EXPECT_CALL(*this, DemuxerOpened());
1695 demuxer_->Initialize( 1695 demuxer_->Initialize(
1696 &host_, CreateInitDoneCB( 1696 &host_,
1697 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1697 base::Bind(
1698 &ChunkDemuxerTest_Shutdown_BeforeAllInitSegmentsAppendedText_Test::
1699 DemuxerInitialized,
1700 base::Unretained(this)),
1701 true);
1698 1702
1699 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1703 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1700 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); 1704 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk);
1701 1705
1702 EXPECT_CALL(host_, AddTextStream(_, _)) 1706 EXPECT_CALL(host_, AddTextStream(_, _))
1703 .Times(Exactly(1)); 1707 .Times(Exactly(1));
1704 1708
1705 ExpectInitMediaLogs(HAS_VIDEO); 1709 ExpectInitMediaLogs(HAS_VIDEO);
1706 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); 1710 EXPECT_CALL(*this, InitSegmentReceivedMock(_));
1707 ASSERT_TRUE( 1711 ASSERT_TRUE(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1758 1762
1759 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); 1763 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster()));
1760 1764
1761 base::RunLoop().RunUntilIdle(); 1765 base::RunLoop().RunUntilIdle();
1762 1766
1763 Checkpoint(2); 1767 Checkpoint(2);
1764 } 1768 }
1765 1769
1766 // Test that parsing errors are handled for clusters appended after init. 1770 // Test that parsing errors are handled for clusters appended after init.
1767 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { 1771 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) {
1772 InSequence s;
1768 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1773 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1769 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster()));
1770 1774
1771 EXPECT_MEDIA_LOG(StreamParsingFailed()); 1775 EXPECT_MEDIA_LOG(StreamParsingFailed());
1772 EXPECT_CALL(host_, OnDemuxerError(CHUNK_DEMUXER_ERROR_APPEND_FAILED)); 1776 EXPECT_CALL(host_, OnDemuxerError(CHUNK_DEMUXER_ERROR_APPEND_FAILED));
1773 AppendGarbage(); 1777 AppendGarbage();
1774 } 1778 }
1775 1779
1776 // Test the case where a Seek() is requested while the parser 1780 // Test the case where a Seek() is requested while the parser
1777 // is in the middle of cluster. This is to verify that the parser 1781 // is in the middle of cluster. This is to verify that the parser
1778 // does not reset itself on a seek. 1782 // does not reset itself on a seek.
1779 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) { 1783 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) {
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 EXPECT_EQ(DemuxerStream::kOk, status); 3218 EXPECT_EQ(DemuxerStream::kOk, status);
3215 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); 3219 EXPECT_EQ(kLastAudioTimestamp, last_timestamp);
3216 3220
3217 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); 3221 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp);
3218 EXPECT_EQ(DemuxerStream::kOk, status); 3222 EXPECT_EQ(DemuxerStream::kOk, status);
3219 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); 3223 EXPECT_EQ(kLastVideoTimestamp, last_timestamp);
3220 } 3224 }
3221 3225
3222 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { 3226 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) {
3223 EXPECT_CALL(*this, DemuxerOpened()); 3227 EXPECT_CALL(*this, DemuxerOpened());
3224 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true); 3228 demuxer_->Initialize(
3229 &host_,
3230 base::Bind(&ChunkDemuxerTest_GetBufferedRangesBeforeInitSegment_Test::
3231 DemuxerInitialized,
3232 base::Unretained(this)),
3233 true);
3225 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 3234 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
3226 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); 3235 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk);
3227 3236
3228 CheckExpectedRanges("audio", "{ }"); 3237 CheckExpectedRanges("audio", "{ }");
3229 CheckExpectedRanges("video", "{ }"); 3238 CheckExpectedRanges("video", "{ }");
3230 } 3239 }
3231 3240
3232 // Test that Seek() completes successfully when the first cluster 3241 // Test that Seek() completes successfully when the first cluster
3233 // arrives. 3242 // arrives.
3234 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) { 3243 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) {
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after
4738 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4747 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4739 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4748 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
4740 EXPECT_NE(nullptr, audio_stream); 4749 EXPECT_NE(nullptr, audio_stream);
4741 CheckStreamStatusNotifications(audio_stream); 4750 CheckStreamStatusNotifications(audio_stream);
4742 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 4751 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
4743 EXPECT_NE(nullptr, video_stream); 4752 EXPECT_NE(nullptr, video_stream);
4744 CheckStreamStatusNotifications(video_stream); 4753 CheckStreamStatusNotifications(video_stream);
4745 } 4754 }
4746 4755
4747 } // namespace media 4756 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | third_party/WebKit/LayoutTests/TestExpectations » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698