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 kVideoTrackId = 10; |
| 100 const int kAudioTrackId = 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 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 | 1403 |
1394 // Map of source id to timestamp offset to use for the next AppendData() | 1404 // Map of source id to timestamp offset to use for the next AppendData() |
1395 // operation for that source id. | 1405 // operation for that source id. |
1396 std::map<std::string, base::TimeDelta> timestamp_offset_map_; | 1406 std::map<std::string, base::TimeDelta> timestamp_offset_map_; |
1397 | 1407 |
1398 public: | 1408 public: |
1399 void InitSegmentReceived(scoped_ptr<MediaTracks> tracks) { | 1409 void InitSegmentReceived(scoped_ptr<MediaTracks> tracks) { |
1400 DCHECK(tracks.get()); | 1410 DCHECK(tracks.get()); |
1401 DCHECK_GT(tracks->tracks().size(), 0u); | 1411 DCHECK_GT(tracks->tracks().size(), 0u); |
1402 | 1412 |
| 1413 std::vector<unsigned> track_ids; |
| 1414 for (const auto& track : tracks->tracks()) { |
| 1415 if (track->type() == MediaTrack::Audio) { |
| 1416 track_ids.push_back(kAudioTrackId); |
| 1417 } else if (track->type() == MediaTrack::Video) { |
| 1418 track_ids.push_back(kVideoTrackId); |
| 1419 } else { |
| 1420 NOTREACHED(); |
| 1421 } |
| 1422 } |
| 1423 demuxer_->OnTrackIdsAssigned(*tracks.get(), track_ids); |
| 1424 |
1403 InitSegmentReceivedMock(tracks); | 1425 InitSegmentReceivedMock(tracks); |
1404 } | 1426 } |
1405 | 1427 |
1406 private: | 1428 private: |
1407 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); | 1429 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); |
1408 }; | 1430 }; |
1409 | 1431 |
1410 TEST_F(ChunkDemuxerTest, Init) { | 1432 TEST_F(ChunkDemuxerTest, Init) { |
1411 InSequence s; | 1433 InSequence s; |
1412 | 1434 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 // Test with 1 audio and 1 video stream. Send a second init segment in which | 1614 // Test with 1 audio and 1 video stream. Send a second init segment in which |
1593 // the audio and video track IDs change. Verify that appended buffers before | 1615 // the audio and video track IDs change. Verify that appended buffers before |
1594 // and after the second init segment map to the same underlying track buffers. | 1616 // and after the second init segment map to the same underlying track buffers. |
1595 CreateNewDemuxer(); | 1617 CreateNewDemuxer(); |
1596 ASSERT_TRUE( | 1618 ASSERT_TRUE( |
1597 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); | 1619 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); |
1598 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1620 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
1599 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1621 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
1600 ASSERT_TRUE(audio_stream); | 1622 ASSERT_TRUE(audio_stream); |
1601 ASSERT_TRUE(video_stream); | 1623 ASSERT_TRUE(video_stream); |
| 1624 ASSERT_EQ(audio_stream, demuxer_->GetDemuxerStreamByTrackId(kAudioTrackId)); |
| 1625 ASSERT_EQ(video_stream, demuxer_->GetDemuxerStreamByTrackId(kVideoTrackId)); |
1602 | 1626 |
1603 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), | 1627 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), |
1604 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); | 1628 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); |
1605 CheckExpectedRanges("{ [0,46) }"); | 1629 CheckExpectedRanges("{ [0,46) }"); |
1606 | 1630 |
1607 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1631 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
1608 AppendInitSegment(HAS_AUDIO | HAS_VIDEO | USE_ALTERNATE_AUDIO_TRACK_ID | | 1632 AppendInitSegment(HAS_AUDIO | HAS_VIDEO | USE_ALTERNATE_AUDIO_TRACK_ID | |
1609 USE_ALTERNATE_VIDEO_TRACK_ID); | 1633 USE_ALTERNATE_VIDEO_TRACK_ID); |
1610 AppendMuxedCluster(MuxedStreamInfo(kAlternateAudioTrackNum, "46K 69K", 63), | 1634 AppendMuxedCluster(MuxedStreamInfo(kAlternateAudioTrackNum, "46K 69K", 63), |
1611 MuxedStreamInfo(kAlternateVideoTrackNum, "60K", 23)); | 1635 MuxedStreamInfo(kAlternateVideoTrackNum, "60K", 23)); |
1612 CheckExpectedRanges("{ [0,92) }"); | 1636 CheckExpectedRanges("{ [0,92) }"); |
1613 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); | 1637 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); |
1614 CheckExpectedBuffers(video_stream, "0K 30 60K"); | 1638 CheckExpectedBuffers(video_stream, "0K 30 60K"); |
| 1639 ASSERT_EQ(audio_stream, demuxer_->GetDemuxerStreamByTrackId(kAudioTrackId)); |
| 1640 ASSERT_EQ(video_stream, demuxer_->GetDemuxerStreamByTrackId(kVideoTrackId)); |
1615 | 1641 |
1616 ShutdownDemuxer(); | 1642 ShutdownDemuxer(); |
1617 } | 1643 } |
1618 | 1644 |
1619 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { | 1645 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { |
1620 // Tests that non-key-frames following an init segment are allowed | 1646 // Tests that non-key-frames following an init segment are allowed |
1621 // and dropped, as expected if the initialization segment received | 1647 // and dropped, as expected if the initialization segment received |
1622 // algorithm correctly sets the needs random access point flag to true for all | 1648 // algorithm correctly sets the needs random access point flag to true for all |
1623 // track buffers. Note that the first initialization segment is insufficient | 1649 // track buffers. Note that the first initialization segment is insufficient |
1624 // to fully test this since needs random access point flag initializes to | 1650 // 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... |
4675 cluster->size() - video_start); | 4701 cluster->size() - video_start); |
4676 | 4702 |
4677 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); | 4703 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); |
4678 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); | 4704 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); |
4679 CheckExpectedRanges("{ [30,90) }"); | 4705 CheckExpectedRanges("{ [30,90) }"); |
4680 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); | 4706 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); |
4681 CheckExpectedBuffers(video_stream, "71K 81"); | 4707 CheckExpectedBuffers(video_stream, "71K 81"); |
4682 } | 4708 } |
4683 | 4709 |
4684 } // namespace media | 4710 } // namespace media |
OLD | NEW |