Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 EXPECT_EQ(status, DemuxerStream::kOk); | 236 EXPECT_EQ(status, DemuxerStream::kOk); |
| 237 EXPECT_TRUE(buffer->end_of_stream()); | 237 EXPECT_TRUE(buffer->end_of_stream()); |
| 238 *called = true; | 238 *called = true; |
| 239 } | 239 } |
| 240 | 240 |
| 241 static void OnSeekDone_OKExpected(bool* called, PipelineStatus status) { | 241 static void OnSeekDone_OKExpected(bool* called, PipelineStatus status) { |
| 242 EXPECT_EQ(status, PIPELINE_OK); | 242 EXPECT_EQ(status, PIPELINE_OK); |
| 243 *called = true; | 243 *called = true; |
| 244 } | 244 } |
| 245 | 245 |
| 246 static void OnPipelineStatus_NOTREACHED(PipelineStatus status) { | |
| 247 NOTREACHED(); | |
| 248 } | |
| 249 | |
| 246 class ChunkDemuxerTest : public ::testing::Test { | 250 class ChunkDemuxerTest : public ::testing::Test { |
| 247 protected: | 251 protected: |
| 248 enum CodecsIndex { | 252 enum CodecsIndex { |
| 249 AUDIO, | 253 AUDIO, |
| 250 VIDEO, | 254 VIDEO, |
| 251 MAX_CODECS_INDEX | 255 MAX_CODECS_INDEX |
| 252 }; | 256 }; |
| 253 | 257 |
| 254 // Default cluster to append first for simple tests. | 258 // Default cluster to append first for simple tests. |
| 255 std::unique_ptr<Cluster> kDefaultFirstCluster() { | 259 std::unique_ptr<Cluster> kDefaultFirstCluster() { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 void AppendGarbage() { | 783 void AppendGarbage() { |
| 780 // Fill up an array with gibberish. | 784 // Fill up an array with gibberish. |
| 781 int garbage_cluster_size = 10; | 785 int garbage_cluster_size = 10; |
| 782 std::unique_ptr<uint8_t[]> garbage_cluster( | 786 std::unique_ptr<uint8_t[]> garbage_cluster( |
| 783 new uint8_t[garbage_cluster_size]); | 787 new uint8_t[garbage_cluster_size]); |
| 784 for (int i = 0; i < garbage_cluster_size; ++i) | 788 for (int i = 0; i < garbage_cluster_size; ++i) |
| 785 garbage_cluster[i] = i; | 789 garbage_cluster[i] = i; |
| 786 ASSERT_FALSE(AppendData(garbage_cluster.get(), garbage_cluster_size)); | 790 ASSERT_FALSE(AppendData(garbage_cluster.get(), garbage_cluster_size)); |
| 787 } | 791 } |
| 788 | 792 |
| 789 void InitDoneCalled(PipelineStatus expected_status, | 793 MOCK_METHOD1(DemuxerInitialized, void(PipelineStatus)); |
|
alokp
2016/09/16 22:10:16
Converted InitDoneCalled into a mock method so tha
| |
| 790 PipelineStatus status) { | 794 |
| 791 EXPECT_EQ(status, expected_status); | 795 void InitDoneCB(PipelineStatus status) { DemuxerInitialized(status); } |
| 792 } | |
| 793 | 796 |
| 794 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, | 797 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, |
| 795 PipelineStatus expected_status) { | 798 PipelineStatus expected_status) { |
| 796 if (expected_duration != kNoTimestamp) | 799 if (expected_duration != kNoTimestamp) |
| 797 EXPECT_CALL(host_, SetDuration(expected_duration)); | 800 EXPECT_CALL(host_, SetDuration(expected_duration)); |
| 798 return CreateInitDoneCB(expected_status); | 801 return CreateInitDoneCB(expected_status); |
| 799 } | 802 } |
| 800 | 803 |
| 801 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { | 804 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { |
| 802 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, | 805 EXPECT_CALL(*this, DemuxerInitialized(expected_status)); |
| 803 base::Unretained(this), | 806 return base::Bind(&ChunkDemuxerTest::InitDoneCB, base::Unretained(this)); |
| 804 expected_status); | |
| 805 } | 807 } |
| 806 | 808 |
| 807 enum StreamFlags { | 809 enum StreamFlags { |
| 808 HAS_AUDIO = 1 << 0, | 810 HAS_AUDIO = 1 << 0, |
| 809 HAS_VIDEO = 1 << 1, | 811 HAS_VIDEO = 1 << 1, |
| 810 HAS_TEXT = 1 << 2, | 812 HAS_TEXT = 1 << 2, |
| 811 USE_ALTERNATE_AUDIO_TRACK_ID = 1 << 3, | 813 USE_ALTERNATE_AUDIO_TRACK_ID = 1 << 3, |
| 812 USE_ALTERNATE_VIDEO_TRACK_ID = 1 << 4, | 814 USE_ALTERNATE_VIDEO_TRACK_ID = 1 << 4, |
| 813 USE_ALTERNATE_TEXT_TRACK_ID = 1 << 5, | 815 USE_ALTERNATE_TEXT_TRACK_ID = 1 << 5, |
| 814 }; | 816 }; |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1669 | 1671 |
| 1670 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); | 1672 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); |
| 1671 CheckExpectedBuffers(video_stream, "30K 90K"); | 1673 CheckExpectedBuffers(video_stream, "30K 90K"); |
| 1672 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); | 1674 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); |
| 1673 } | 1675 } |
| 1674 | 1676 |
| 1675 // Make sure that the demuxer reports an error if Shutdown() | 1677 // Make sure that the demuxer reports an error if Shutdown() |
| 1676 // is called before all the initialization segments are appended. | 1678 // is called before all the initialization segments are appended. |
| 1677 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { | 1679 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { |
| 1678 EXPECT_CALL(*this, DemuxerOpened()); | 1680 EXPECT_CALL(*this, DemuxerOpened()); |
| 1679 demuxer_->Initialize( | 1681 demuxer_->Initialize(&host_, base::Bind(&OnPipelineStatus_NOTREACHED), true); |
|
alokp
2016/09/16 22:10:16
init_cb should not be called here since the demuxe
xhwang
2016/09/16 23:41:47
hmm, we typically don't like outstanding callbacks
alokp
2016/09/17 00:06:05
This patch does not change this behavior. ChunkDem
xhwang
2016/09/17 03:58:24
The demuxer API is a bit old and it's not very cle
alokp
2016/09/17 05:43:14
I see. I misunderstood your previous comment. I ag
| |
| 1680 &host_, CreateInitDoneCB( | |
| 1681 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), 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(&host_, base::Bind(&OnPipelineStatus_NOTREACHED), true); |
|
alokp
2016/09/16 22:10:16
ditto
| |
| 1696 &host_, CreateInitDoneCB( | |
| 1697 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | |
| 1698 | 1696 |
| 1699 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1697 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 1700 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); | 1698 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); |
| 1701 | 1699 |
| 1702 EXPECT_CALL(host_, AddTextStream(_, _)) | 1700 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1703 .Times(Exactly(1)); | 1701 .Times(Exactly(1)); |
| 1704 | 1702 |
| 1705 ExpectInitMediaLogs(HAS_VIDEO); | 1703 ExpectInitMediaLogs(HAS_VIDEO); |
| 1706 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1704 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
| 1707 ASSERT_TRUE( | 1705 ASSERT_TRUE( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1758 | 1756 |
| 1759 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); | 1757 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); |
| 1760 | 1758 |
| 1761 base::RunLoop().RunUntilIdle(); | 1759 base::RunLoop().RunUntilIdle(); |
| 1762 | 1760 |
| 1763 Checkpoint(2); | 1761 Checkpoint(2); |
| 1764 } | 1762 } |
| 1765 | 1763 |
| 1766 // Test that parsing errors are handled for clusters appended after init. | 1764 // Test that parsing errors are handled for clusters appended after init. |
| 1767 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { | 1765 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { |
| 1766 InSequence s; | |
|
alokp
2016/09/16 22:10:16
Added to verify that init_cb is called before OnDe
| |
| 1768 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1767 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1769 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster())); | |
| 1770 | 1768 |
| 1771 EXPECT_MEDIA_LOG(StreamParsingFailed()); | 1769 EXPECT_MEDIA_LOG(StreamParsingFailed()); |
| 1772 EXPECT_CALL(host_, OnDemuxerError(CHUNK_DEMUXER_ERROR_APPEND_FAILED)); | 1770 EXPECT_CALL(host_, OnDemuxerError(CHUNK_DEMUXER_ERROR_APPEND_FAILED)); |
| 1773 AppendGarbage(); | 1771 AppendGarbage(); |
| 1774 } | 1772 } |
| 1775 | 1773 |
| 1776 // Test the case where a Seek() is requested while the parser | 1774 // 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 | 1775 // is in the middle of cluster. This is to verify that the parser |
| 1778 // does not reset itself on a seek. | 1776 // does not reset itself on a seek. |
| 1779 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) { | 1777 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) { |
| (...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3214 EXPECT_EQ(DemuxerStream::kOk, status); | 3212 EXPECT_EQ(DemuxerStream::kOk, status); |
| 3215 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); | 3213 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); |
| 3216 | 3214 |
| 3217 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); | 3215 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); |
| 3218 EXPECT_EQ(DemuxerStream::kOk, status); | 3216 EXPECT_EQ(DemuxerStream::kOk, status); |
| 3219 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); | 3217 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); |
| 3220 } | 3218 } |
| 3221 | 3219 |
| 3222 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { | 3220 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { |
| 3223 EXPECT_CALL(*this, DemuxerOpened()); | 3221 EXPECT_CALL(*this, DemuxerOpened()); |
| 3224 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true); | 3222 demuxer_->Initialize(&host_, base::Bind(&OnPipelineStatus_NOTREACHED), true); |
| 3225 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 3223 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 3226 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); | 3224 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); |
| 3227 | 3225 |
| 3228 CheckExpectedRanges("audio", "{ }"); | 3226 CheckExpectedRanges("audio", "{ }"); |
| 3229 CheckExpectedRanges("video", "{ }"); | 3227 CheckExpectedRanges("video", "{ }"); |
| 3230 } | 3228 } |
| 3231 | 3229 |
| 3232 // Test that Seek() completes successfully when the first cluster | 3230 // Test that Seek() completes successfully when the first cluster |
| 3233 // arrives. | 3231 // arrives. |
| 3234 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) { | 3232 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) { |
| (...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4738 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4736 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 4739 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4737 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 4740 EXPECT_NE(nullptr, audio_stream); | 4738 EXPECT_NE(nullptr, audio_stream); |
| 4741 CheckStreamStatusNotifications(audio_stream); | 4739 CheckStreamStatusNotifications(audio_stream); |
| 4742 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4740 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 4743 EXPECT_NE(nullptr, video_stream); | 4741 EXPECT_NE(nullptr, video_stream); |
| 4744 CheckStreamStatusNotifications(video_stream); | 4742 CheckStreamStatusNotifications(video_stream); |
| 4745 } | 4743 } |
| 4746 | 4744 |
| 4747 } // namespace media | 4745 } // namespace media |
| OLD | NEW |