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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 class ChunkDemuxerTest : public ::testing::Test { | 246 class ChunkDemuxerTest : public ::testing::Test { |
| 247 public: | |
| 248 // Public method becuase test cases use it directly. | |
|
wolenetz
2016/09/27 21:01:14
nit: spelling
alokp
2016/09/28 17:22:45
Done.
| |
| 249 MOCK_METHOD1(DemuxerInitialized, void(PipelineStatus)); | |
| 250 | |
| 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() { |
| 256 return GenerateCluster(0, 4); | 260 return GenerateCluster(0, 4); |
| (...skipping 522 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, | |
| 790 PipelineStatus status) { | |
| 791 EXPECT_EQ(status, expected_status); | |
| 792 } | |
| 793 | |
| 794 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, | 793 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, |
| 795 PipelineStatus expected_status) { | 794 PipelineStatus expected_status) { |
| 796 if (expected_duration != kNoTimestamp) | 795 if (expected_duration != kNoTimestamp) |
| 797 EXPECT_CALL(host_, SetDuration(expected_duration)); | 796 EXPECT_CALL(host_, SetDuration(expected_duration)); |
| 798 return CreateInitDoneCB(expected_status); | 797 return CreateInitDoneCB(expected_status); |
| 799 } | 798 } |
| 800 | 799 |
| 801 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { | 800 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { |
| 802 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, | 801 EXPECT_CALL(*this, DemuxerInitialized(expected_status)); |
|
wolenetz
2016/10/05 23:41:24
Good :)
| |
| 803 base::Unretained(this), | 802 return base::Bind(&ChunkDemuxerTest::DemuxerInitialized, |
| 804 expected_status); | 803 base::Unretained(this)); |
| 805 } | 804 } |
| 806 | 805 |
| 807 enum StreamFlags { | 806 enum StreamFlags { |
| 808 HAS_AUDIO = 1 << 0, | 807 HAS_AUDIO = 1 << 0, |
| 809 HAS_VIDEO = 1 << 1, | 808 HAS_VIDEO = 1 << 1, |
| 810 HAS_TEXT = 1 << 2, | 809 HAS_TEXT = 1 << 2, |
| 811 USE_ALTERNATE_AUDIO_TRACK_ID = 1 << 3, | 810 USE_ALTERNATE_AUDIO_TRACK_ID = 1 << 3, |
| 812 USE_ALTERNATE_VIDEO_TRACK_ID = 1 << 4, | 811 USE_ALTERNATE_VIDEO_TRACK_ID = 1 << 4, |
| 813 USE_ALTERNATE_TEXT_TRACK_ID = 1 << 5, | 812 USE_ALTERNATE_TEXT_TRACK_ID = 1 << 5, |
| 814 }; | 813 }; |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1665 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23), | 1664 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23), |
| 1666 MuxedStreamInfo(kVideoTrackNum, "60 90K", 30), | 1665 MuxedStreamInfo(kVideoTrackNum, "60 90K", 30), |
| 1667 MuxedStreamInfo(kTextTrackNum, "80K 90K")); | 1666 MuxedStreamInfo(kTextTrackNum, "80K 90K")); |
| 1668 CheckExpectedRanges("{ [23,92) }"); | 1667 CheckExpectedRanges("{ [23,92) }"); |
| 1669 | 1668 |
| 1670 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); | 1669 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); |
| 1671 CheckExpectedBuffers(video_stream, "30K 90K"); | 1670 CheckExpectedBuffers(video_stream, "30K 90K"); |
| 1672 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); | 1671 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); |
| 1673 } | 1672 } |
| 1674 | 1673 |
| 1675 // Make sure that the demuxer reports an error if Shutdown() | 1674 // Make sure that the demuxer reports an error if Shutdown() |
|
wolenetz
2016/09/27 21:01:14
Where is the error verified now?
(The err is becau
alokp
2016/09/28 17:22:45
The error was never being verified (silently) beca
wolenetz
2016/10/03 21:16:23
Hmm. If there is a demuxer error that isn't report
alokp
2016/10/04 20:48:40
Is shutting down before appending initialization s
wolenetz
2016/10/05 23:41:23
Ok. Thanks for clarifying.
This test's comment is
alokp
2016/10/06 05:49:17
Done.
| |
| 1676 // is called before all the initialization segments are appended. | 1675 // is called before all the initialization segments are appended. |
| 1677 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { | 1676 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { |
| 1678 EXPECT_CALL(*this, DemuxerOpened()); | 1677 EXPECT_CALL(*this, DemuxerOpened()); |
| 1679 demuxer_->Initialize( | 1678 demuxer_->Initialize(&host_, base::Bind(&ChunkDemuxerTest::DemuxerInitialized, |
| 1680 &host_, CreateInitDoneCB( | 1679 base::Unretained(this)), |
| 1681 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1680 true); |
| 1682 | 1681 |
| 1683 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1682 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 1684 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); | 1683 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); |
| 1685 | 1684 |
| 1686 ExpectInitMediaLogs(HAS_AUDIO); | 1685 ExpectInitMediaLogs(HAS_AUDIO); |
| 1687 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1686 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
| 1688 ASSERT_TRUE(AppendInitSegmentWithSourceId("audio", HAS_AUDIO)); | 1687 ASSERT_TRUE(AppendInitSegmentWithSourceId("audio", HAS_AUDIO)); |
| 1689 | 1688 |
| 1690 ShutdownDemuxer(); | 1689 ShutdownDemuxer(); |
| 1691 } | 1690 } |
| 1692 | 1691 |
| 1693 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { | 1692 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { |
| 1694 EXPECT_CALL(*this, DemuxerOpened()); | 1693 EXPECT_CALL(*this, DemuxerOpened()); |
| 1695 demuxer_->Initialize( | 1694 demuxer_->Initialize(&host_, base::Bind(&ChunkDemuxerTest::DemuxerInitialized, |
|
wolenetz
2016/09/27 21:01:14
Ditto.
alokp
2016/09/28 17:22:45
ditto.
wolenetz
2016/10/03 21:16:23
ditto :)
wolenetz
2016/10/05 23:41:23
ignore
alokp
2016/10/06 05:49:17
Acknowledged.
| |
| 1696 &host_, CreateInitDoneCB( | 1695 base::Unretained(this)), |
| 1697 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1696 true); |
| 1698 | 1697 |
| 1699 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1698 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 1700 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); | 1699 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); |
| 1701 | 1700 |
| 1702 EXPECT_CALL(host_, AddTextStream(_, _)) | 1701 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1703 .Times(Exactly(1)); | 1702 .Times(Exactly(1)); |
| 1704 | 1703 |
| 1705 ExpectInitMediaLogs(HAS_VIDEO); | 1704 ExpectInitMediaLogs(HAS_VIDEO); |
| 1706 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1705 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
| 1707 ASSERT_TRUE( | 1706 ASSERT_TRUE( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1758 | 1757 |
| 1759 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); | 1758 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); |
| 1760 | 1759 |
| 1761 base::RunLoop().RunUntilIdle(); | 1760 base::RunLoop().RunUntilIdle(); |
| 1762 | 1761 |
| 1763 Checkpoint(2); | 1762 Checkpoint(2); |
| 1764 } | 1763 } |
| 1765 | 1764 |
| 1766 // Test that parsing errors are handled for clusters appended after init. | 1765 // Test that parsing errors are handled for clusters appended after init. |
| 1767 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { | 1766 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { |
| 1767 InSequence s; | |
| 1768 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1768 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1769 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster())); | |
| 1770 | 1769 |
| 1771 EXPECT_MEDIA_LOG(StreamParsingFailed()); | 1770 EXPECT_MEDIA_LOG(StreamParsingFailed()); |
| 1772 EXPECT_CALL(host_, OnDemuxerError(CHUNK_DEMUXER_ERROR_APPEND_FAILED)); | 1771 EXPECT_CALL(host_, OnDemuxerError(CHUNK_DEMUXER_ERROR_APPEND_FAILED)); |
| 1773 AppendGarbage(); | 1772 AppendGarbage(); |
| 1774 } | 1773 } |
| 1775 | 1774 |
| 1776 // Test the case where a Seek() is requested while the parser | 1775 // 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 | 1776 // is in the middle of cluster. This is to verify that the parser |
| 1778 // does not reset itself on a seek. | 1777 // does not reset itself on a seek. |
| 1779 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) { | 1778 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) { |
| (...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3214 EXPECT_EQ(DemuxerStream::kOk, status); | 3213 EXPECT_EQ(DemuxerStream::kOk, status); |
| 3215 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); | 3214 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); |
| 3216 | 3215 |
| 3217 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); | 3216 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); |
| 3218 EXPECT_EQ(DemuxerStream::kOk, status); | 3217 EXPECT_EQ(DemuxerStream::kOk, status); |
| 3219 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); | 3218 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); |
| 3220 } | 3219 } |
| 3221 | 3220 |
| 3222 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { | 3221 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { |
| 3223 EXPECT_CALL(*this, DemuxerOpened()); | 3222 EXPECT_CALL(*this, DemuxerOpened()); |
| 3224 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true); | 3223 demuxer_->Initialize(&host_, base::Bind(&ChunkDemuxerTest::DemuxerInitialized, |
|
wolenetz
2016/09/27 21:01:14
Where is *lack* of error on CDT::DemuxerInitialize
alokp
2016/09/28 17:22:45
This again was silently not getting verified becau
wolenetz
2016/10/03 21:16:23
I wonder if this could be fixed with a test class
alokp
2016/10/04 20:48:40
RunUntilIdle does not help here because init_cb is
wolenetz
2016/10/05 23:41:24
I see. My comment was that RunUntilIdle() might le
alokp
2016/10/06 05:49:17
Acknowledged.
| |
| 3224 base::Unretained(this)), | |
| 3225 true); | |
| 3225 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 3226 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 3226 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); | 3227 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); |
| 3227 | 3228 |
| 3228 CheckExpectedRanges("audio", "{ }"); | 3229 CheckExpectedRanges("audio", "{ }"); |
| 3229 CheckExpectedRanges("video", "{ }"); | 3230 CheckExpectedRanges("video", "{ }"); |
| 3230 } | 3231 } |
| 3231 | 3232 |
| 3232 // Test that Seek() completes successfully when the first cluster | 3233 // Test that Seek() completes successfully when the first cluster |
| 3233 // arrives. | 3234 // arrives. |
| 3234 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) { | 3235 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)); | 4739 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 4739 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4740 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 4740 EXPECT_NE(nullptr, audio_stream); | 4741 EXPECT_NE(nullptr, audio_stream); |
| 4741 CheckStreamStatusNotifications(audio_stream); | 4742 CheckStreamStatusNotifications(audio_stream); |
| 4742 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4743 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 4743 EXPECT_NE(nullptr, video_stream); | 4744 EXPECT_NE(nullptr, video_stream); |
| 4744 CheckStreamStatusNotifications(video_stream); | 4745 CheckStreamStatusNotifications(video_stream); |
| 4745 } | 4746 } |
| 4746 | 4747 |
| 4747 } // namespace media | 4748 } // namespace media |
| OLD | NEW |