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

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

Issue 1812543003: Allow muting/unmuting audio through media track API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-sb-tracks6
Patch Set: Added VideoTrackSelectDeselect test case Created 4 years, 8 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
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 1397
1388 // Map of source id to timestamp offset to use for the next AppendData() 1398 // Map of source id to timestamp offset to use for the next AppendData()
1389 // operation for that source id. 1399 // operation for that source id.
1390 std::map<std::string, base::TimeDelta> timestamp_offset_map_; 1400 std::map<std::string, base::TimeDelta> timestamp_offset_map_;
1391 1401
1392 public: 1402 public:
1393 void InitSegmentReceived(scoped_ptr<MediaTracks> tracks) { 1403 void InitSegmentReceived(scoped_ptr<MediaTracks> tracks) {
1394 DCHECK(tracks.get()); 1404 DCHECK(tracks.get());
1395 DCHECK_GT(tracks->tracks().size(), 0u); 1405 DCHECK_GT(tracks->tracks().size(), 0u);
1396 1406
1407 std::vector<unsigned> track_ids;
1408 for (const auto& track : tracks->tracks()) {
1409 if (track->type() == MediaTrack::Audio) {
1410 track_ids.push_back(kAudioTrackId);
1411 } else if (track->type() == MediaTrack::Video) {
1412 track_ids.push_back(kVideoTrackId);
1413 } else {
1414 NOTREACHED();
1415 }
1416 }
1417 demuxer_->OnTrackIdsAssigned(*tracks.get(), track_ids);
1418
1397 InitSegmentReceivedMock(tracks); 1419 InitSegmentReceivedMock(tracks);
1398 } 1420 }
1399 1421
1400 private: 1422 private:
1401 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 1423 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
1402 }; 1424 };
1403 1425
1404 TEST_F(ChunkDemuxerTest, Init) { 1426 TEST_F(ChunkDemuxerTest, Init) {
1405 InSequence s; 1427 InSequence s;
1406 1428
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 // Test with 1 audio and 1 video stream. Send a second init segment in which 1608 // Test with 1 audio and 1 video stream. Send a second init segment in which
1587 // the audio and video track IDs change. Verify that appended buffers before 1609 // the audio and video track IDs change. Verify that appended buffers before
1588 // and after the second init segment map to the same underlying track buffers. 1610 // and after the second init segment map to the same underlying track buffers.
1589 CreateNewDemuxer(); 1611 CreateNewDemuxer();
1590 ASSERT_TRUE( 1612 ASSERT_TRUE(
1591 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); 1613 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false));
1592 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1614 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1593 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1615 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1594 ASSERT_TRUE(audio_stream); 1616 ASSERT_TRUE(audio_stream);
1595 ASSERT_TRUE(video_stream); 1617 ASSERT_TRUE(video_stream);
1618 ASSERT_EQ(audio_stream, demuxer_->GetDemuxerStreamByTrackId(kAudioTrackId));
1619 ASSERT_EQ(video_stream, demuxer_->GetDemuxerStreamByTrackId(kVideoTrackId));
1596 1620
1597 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), 1621 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23),
1598 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); 1622 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30));
1599 CheckExpectedRanges("{ [0,46) }"); 1623 CheckExpectedRanges("{ [0,46) }");
1600 1624
1601 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); 1625 EXPECT_CALL(*this, InitSegmentReceivedMock(_));
1602 AppendInitSegment(HAS_AUDIO | HAS_VIDEO | USE_ALTERNATE_AUDIO_TRACK_ID | 1626 AppendInitSegment(HAS_AUDIO | HAS_VIDEO | USE_ALTERNATE_AUDIO_TRACK_ID |
1603 USE_ALTERNATE_VIDEO_TRACK_ID); 1627 USE_ALTERNATE_VIDEO_TRACK_ID);
1604 AppendMuxedCluster(MuxedStreamInfo(kAlternateAudioTrackNum, "46K 69K", 63), 1628 AppendMuxedCluster(MuxedStreamInfo(kAlternateAudioTrackNum, "46K 69K", 63),
1605 MuxedStreamInfo(kAlternateVideoTrackNum, "60K", 23)); 1629 MuxedStreamInfo(kAlternateVideoTrackNum, "60K", 23));
1606 CheckExpectedRanges("{ [0,92) }"); 1630 CheckExpectedRanges("{ [0,92) }");
1607 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); 1631 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K");
1608 CheckExpectedBuffers(video_stream, "0K 30 60K"); 1632 CheckExpectedBuffers(video_stream, "0K 30 60K");
1633 ASSERT_EQ(audio_stream, demuxer_->GetDemuxerStreamByTrackId(kAudioTrackId));
1634 ASSERT_EQ(video_stream, demuxer_->GetDemuxerStreamByTrackId(kVideoTrackId));
1609 1635
1610 ShutdownDemuxer(); 1636 ShutdownDemuxer();
1611 } 1637 }
1612 1638
1613 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { 1639 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) {
1614 // Tests that non-key-frames following an init segment are allowed 1640 // Tests that non-key-frames following an init segment are allowed
1615 // and dropped, as expected if the initialization segment received 1641 // and dropped, as expected if the initialization segment received
1616 // algorithm correctly sets the needs random access point flag to true for all 1642 // algorithm correctly sets the needs random access point flag to true for all
1617 // track buffers. Note that the first initialization segment is insufficient 1643 // track buffers. Note that the first initialization segment is insufficient
1618 // to fully test this since needs random access point flag initializes to 1644 // to fully test this since needs random access point flag initializes to
(...skipping 3050 matching lines...) Expand 10 before | Expand all | Expand 10 after
4669 cluster->size() - video_start); 4695 cluster->size() - video_start);
4670 4696
4671 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); 4697 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }");
4672 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); 4698 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }");
4673 CheckExpectedRanges("{ [30,90) }"); 4699 CheckExpectedRanges("{ [30,90) }");
4674 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); 4700 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K");
4675 CheckExpectedBuffers(video_stream, "71K 81"); 4701 CheckExpectedBuffers(video_stream, "71K 81");
4676 } 4702 }
4677 4703
4678 } // namespace media 4704 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698