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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const int kAudioTrackEntryHeaderSize = | 75 const int kAudioTrackEntryHeaderSize = |
76 kAudioTrackSizeOffset + kAudioTrackSizeWidth; | 76 kAudioTrackSizeOffset + kAudioTrackSizeWidth; |
77 | 77 |
78 // The size of TrackEntry element in test file "webm_vp8_track_entry" starts at | 78 // The size of TrackEntry element in test file "webm_vp8_track_entry" starts at |
79 // index 1 and spans 8 bytes. | 79 // index 1 and spans 8 bytes. |
80 const int kVideoTrackSizeOffset = 1; | 80 const int kVideoTrackSizeOffset = 1; |
81 const int kVideoTrackSizeWidth = 8; | 81 const int kVideoTrackSizeWidth = 8; |
82 const int kVideoTrackEntryHeaderSize = | 82 const int kVideoTrackEntryHeaderSize = |
83 kVideoTrackSizeOffset + kVideoTrackSizeWidth; | 83 kVideoTrackSizeOffset + kVideoTrackSizeWidth; |
84 | 84 |
| 85 // Track numbers AKA bytestream track ids. Bytestream track ids might change |
| 86 // within a single playback session if there is only one track of a given type. |
85 const int kVideoTrackNum = 1; | 87 const int kVideoTrackNum = 1; |
86 const int kAudioTrackNum = 2; | 88 const int kAudioTrackNum = 2; |
87 const int kTextTrackNum = 3; | 89 const int kTextTrackNum = 3; |
88 const int kAlternateVideoTrackNum = 4; | 90 const int kAlternateVideoTrackNum = 4; |
89 const int kAlternateAudioTrackNum = 5; | 91 const int kAlternateAudioTrackNum = 5; |
90 const int kAlternateTextTrackNum = 6; | 92 const int kAlternateTextTrackNum = 6; |
91 | 93 |
| 94 // These value represent externally assigned track ids (for example track ids |
| 95 // assigned by blink). Not to be confused with bytestream track ids above. The |
| 96 // main difference is that these track ids must stay the same for the duration |
| 97 // of the playback session, whereas track numbers / bytestream track ids might |
| 98 // change in subsequent init segments. |
| 99 const int kExternalVideoTrackId = 10; |
| 100 const int kExternalAudioTrackId = 11; |
| 101 |
92 const int kAudioBlockDuration = 23; | 102 const int kAudioBlockDuration = 23; |
93 const int kVideoBlockDuration = 33; | 103 const int kVideoBlockDuration = 33; |
94 const int kTextBlockDuration = 100; | 104 const int kTextBlockDuration = 100; |
95 const int kBlockSize = 10; | 105 const int kBlockSize = 10; |
96 | 106 |
97 const char kSourceId[] = "SourceId"; | 107 const char kSourceId[] = "SourceId"; |
98 const char kDefaultFirstClusterRange[] = "{ [0,46) }"; | 108 const char kDefaultFirstClusterRange[] = "{ [0,46) }"; |
99 const int kDefaultFirstClusterEndTimestamp = 66; | 109 const int kDefaultFirstClusterEndTimestamp = 66; |
100 const int kDefaultSecondClusterEndTimestamp = 132; | 110 const int kDefaultSecondClusterEndTimestamp = 132; |
101 | 111 |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 | 1407 |
1398 // Map of source id to timestamp offset to use for the next AppendData() | 1408 // Map of source id to timestamp offset to use for the next AppendData() |
1399 // operation for that source id. | 1409 // operation for that source id. |
1400 std::map<std::string, base::TimeDelta> timestamp_offset_map_; | 1410 std::map<std::string, base::TimeDelta> timestamp_offset_map_; |
1401 | 1411 |
1402 public: | 1412 public: |
1403 void InitSegmentReceived(std::unique_ptr<MediaTracks> tracks) { | 1413 void InitSegmentReceived(std::unique_ptr<MediaTracks> tracks) { |
1404 DCHECK(tracks.get()); | 1414 DCHECK(tracks.get()); |
1405 DCHECK_GT(tracks->tracks().size(), 0u); | 1415 DCHECK_GT(tracks->tracks().size(), 0u); |
1406 | 1416 |
| 1417 std::vector<unsigned> track_ids; |
| 1418 bool found_audio_track = false; |
| 1419 bool found_video_track = false; |
| 1420 for (const auto& track : tracks->tracks()) { |
| 1421 if (track->type() == MediaTrack::Audio) { |
| 1422 DCHECK(!found_audio_track); |
| 1423 found_audio_track = true; |
| 1424 track_ids.push_back(kExternalAudioTrackId); |
| 1425 } else if (track->type() == MediaTrack::Video) { |
| 1426 DCHECK(!found_video_track); |
| 1427 found_video_track = true; |
| 1428 track_ids.push_back(kExternalVideoTrackId); |
| 1429 } else { |
| 1430 NOTREACHED(); |
| 1431 } |
| 1432 } |
| 1433 demuxer_->OnTrackIdsAssigned(*tracks.get(), track_ids); |
| 1434 |
1407 InitSegmentReceivedMock(tracks); | 1435 InitSegmentReceivedMock(tracks); |
1408 } | 1436 } |
1409 | 1437 |
1410 private: | 1438 private: |
1411 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); | 1439 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); |
1412 }; | 1440 }; |
1413 | 1441 |
1414 TEST_F(ChunkDemuxerTest, Init) { | 1442 TEST_F(ChunkDemuxerTest, Init) { |
1415 InSequence s; | 1443 InSequence s; |
1416 | 1444 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 // Test with 1 audio and 1 video stream. Send a second init segment in which | 1624 // Test with 1 audio and 1 video stream. Send a second init segment in which |
1597 // the audio and video track IDs change. Verify that appended buffers before | 1625 // the audio and video track IDs change. Verify that appended buffers before |
1598 // and after the second init segment map to the same underlying track buffers. | 1626 // and after the second init segment map to the same underlying track buffers. |
1599 CreateNewDemuxer(); | 1627 CreateNewDemuxer(); |
1600 ASSERT_TRUE( | 1628 ASSERT_TRUE( |
1601 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); | 1629 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); |
1602 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1630 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
1603 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1631 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
1604 ASSERT_TRUE(audio_stream); | 1632 ASSERT_TRUE(audio_stream); |
1605 ASSERT_TRUE(video_stream); | 1633 ASSERT_TRUE(video_stream); |
| 1634 ASSERT_EQ(audio_stream, |
| 1635 demuxer_->GetDemuxerStreamByTrackId(kExternalAudioTrackId)); |
| 1636 ASSERT_EQ(video_stream, |
| 1637 demuxer_->GetDemuxerStreamByTrackId(kExternalVideoTrackId)); |
1606 | 1638 |
1607 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), | 1639 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), |
1608 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); | 1640 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); |
1609 CheckExpectedRanges("{ [0,46) }"); | 1641 CheckExpectedRanges("{ [0,46) }"); |
1610 | 1642 |
1611 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1643 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
1612 AppendInitSegment(HAS_AUDIO | HAS_VIDEO | USE_ALTERNATE_AUDIO_TRACK_ID | | 1644 AppendInitSegment(HAS_AUDIO | HAS_VIDEO | USE_ALTERNATE_AUDIO_TRACK_ID | |
1613 USE_ALTERNATE_VIDEO_TRACK_ID); | 1645 USE_ALTERNATE_VIDEO_TRACK_ID); |
1614 AppendMuxedCluster(MuxedStreamInfo(kAlternateAudioTrackNum, "46K 69K", 63), | 1646 AppendMuxedCluster(MuxedStreamInfo(kAlternateAudioTrackNum, "46K 69K", 63), |
1615 MuxedStreamInfo(kAlternateVideoTrackNum, "60K", 23)); | 1647 MuxedStreamInfo(kAlternateVideoTrackNum, "60K", 23)); |
1616 CheckExpectedRanges("{ [0,92) }"); | 1648 CheckExpectedRanges("{ [0,92) }"); |
1617 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); | 1649 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); |
1618 CheckExpectedBuffers(video_stream, "0K 30 60K"); | 1650 CheckExpectedBuffers(video_stream, "0K 30 60K"); |
| 1651 ASSERT_EQ(audio_stream, |
| 1652 demuxer_->GetDemuxerStreamByTrackId(kExternalAudioTrackId)); |
| 1653 ASSERT_EQ(video_stream, |
| 1654 demuxer_->GetDemuxerStreamByTrackId(kExternalVideoTrackId)); |
1619 | 1655 |
1620 ShutdownDemuxer(); | 1656 ShutdownDemuxer(); |
1621 } | 1657 } |
1622 | 1658 |
1623 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { | 1659 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { |
1624 // Tests that non-key-frames following an init segment are allowed | 1660 // Tests that non-key-frames following an init segment are allowed |
1625 // and dropped, as expected if the initialization segment received | 1661 // and dropped, as expected if the initialization segment received |
1626 // algorithm correctly sets the needs random access point flag to true for all | 1662 // algorithm correctly sets the needs random access point flag to true for all |
1627 // track buffers. Note that the first initialization segment is insufficient | 1663 // track buffers. Note that the first initialization segment is insufficient |
1628 // to fully test this since needs random access point flag initializes to | 1664 // to fully test this since needs random access point flag initializes to |
(...skipping 3050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4679 cluster->size() - video_start); | 4715 cluster->size() - video_start); |
4680 | 4716 |
4681 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); | 4717 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); |
4682 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); | 4718 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); |
4683 CheckExpectedRanges("{ [30,90) }"); | 4719 CheckExpectedRanges("{ [30,90) }"); |
4684 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); | 4720 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); |
4685 CheckExpectedBuffers(video_stream, "71K 81"); | 4721 CheckExpectedBuffers(video_stream, "71K 81"); |
4686 } | 4722 } |
4687 | 4723 |
4688 } // namespace media | 4724 } // namespace media |
OLD | NEW |