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

Side by Side Diff: media/filters/chunk_demuxer.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: Avoid ChunkDemuxer/PipelineImpl deadlock 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
« no previous file with comments | « media/filters/chunk_demuxer.h ('k') | media/filters/chunk_demuxer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <list> 9 #include <list>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "media/base/audio_decoder_config.h" 18 #include "media/base/audio_decoder_config.h"
19 #include "media/base/bind_to_current_loop.h" 19 #include "media/base/bind_to_current_loop.h"
20 #include "media/base/media_tracks.h"
20 #include "media/base/stream_parser_buffer.h" 21 #include "media/base/stream_parser_buffer.h"
21 #include "media/base/timestamp_constants.h" 22 #include "media/base/timestamp_constants.h"
22 #include "media/base/video_decoder_config.h" 23 #include "media/base/video_decoder_config.h"
23 #include "media/filters/frame_processor.h" 24 #include "media/filters/frame_processor.h"
24 #include "media/filters/stream_parser_factory.h" 25 #include "media/filters/stream_parser_factory.h"
25 26
26 using base::TimeDelta; 27 using base::TimeDelta;
27 28
28 namespace media { 29 namespace media {
29 30
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 StartReturningData(); 996 StartReturningData();
996 997
997 if (duration_ == kNoTimestamp()) 998 if (duration_ == kNoTimestamp())
998 duration_ = kInfiniteDuration(); 999 duration_ = kInfiniteDuration();
999 1000
1000 // The demuxer is now initialized after the |start_timestamp_| was set. 1001 // The demuxer is now initialized after the |start_timestamp_| was set.
1001 ChangeState_Locked(INITIALIZED); 1002 ChangeState_Locked(INITIALIZED);
1002 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); 1003 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
1003 } 1004 }
1004 1005
1005 ChunkDemuxerStream* 1006 ChunkDemuxerStream* ChunkDemuxer::CreateDemuxerStream(
1006 ChunkDemuxer::CreateDemuxerStream(DemuxerStream::Type type) { 1007 const MediaTrack& media_track) {
1007 switch (type) { 1008 // Demuxer streams can only be created when ChunkDemuxer::AppendData is in
1008 case DemuxerStream::AUDIO: 1009 // progress.
1010 lock_.AssertAcquired();
1011 switch (media_track.type()) {
1012 case MediaTrack::Audio:
1009 if (audio_) 1013 if (audio_)
1010 return NULL; 1014 return NULL;
1011 audio_.reset( 1015 audio_.reset(
1012 new ChunkDemuxerStream(DemuxerStream::AUDIO, splice_frames_enabled_)); 1016 new ChunkDemuxerStream(DemuxerStream::AUDIO, splice_frames_enabled_));
1013 return audio_.get(); 1017 return audio_.get();
1014 break; 1018 break;
1015 case DemuxerStream::VIDEO: 1019 case MediaTrack::Video:
1016 if (video_) 1020 if (video_)
1017 return NULL; 1021 return NULL;
1018 video_.reset( 1022 video_.reset(
1019 new ChunkDemuxerStream(DemuxerStream::VIDEO, splice_frames_enabled_)); 1023 new ChunkDemuxerStream(DemuxerStream::VIDEO, splice_frames_enabled_));
1020 return video_.get(); 1024 return video_.get();
1021 break; 1025 break;
1022 case DemuxerStream::TEXT: { 1026 case MediaTrack::Text: {
1023 return new ChunkDemuxerStream(DemuxerStream::TEXT, 1027 return new ChunkDemuxerStream(DemuxerStream::TEXT,
1024 splice_frames_enabled_); 1028 splice_frames_enabled_);
1025 break; 1029 break;
1026 } 1030 }
1027 case DemuxerStream::UNKNOWN:
1028 case DemuxerStream::NUM_TYPES:
1029 NOTREACHED();
1030 return NULL;
1031 } 1031 }
1032 NOTREACHED(); 1032 NOTREACHED();
1033 return NULL; 1033 return NULL;
1034 } 1034 }
1035 1035
1036 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, 1036 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream,
1037 const TextTrackConfig& config) { 1037 const TextTrackConfig& config) {
1038 lock_.AssertAcquired(); 1038 lock_.AssertAcquired();
1039 DCHECK_NE(state_, SHUTDOWN); 1039 DCHECK_NE(state_, SHUTDOWN);
1040 host_->AddTextStream(text_stream, config); 1040 host_->AddTextStream(text_stream, config);
1041 } 1041 }
1042 1042
1043 void ChunkDemuxer::OnTrackIdsAssigned(const MediaTracks& tracks,
1044 const std::vector<unsigned>& track_ids) {
1045 // New tracks and therefore track id assignements can happen only during
1046 // ChunkDemuxer::AppendData processing, which should be holding the lock.
1047 lock_.AssertAcquired();
1048
1049 const auto& new_track_id_map = tracks.OnTrackIdsAssigned(track_ids);
1050
1051 // ChunkDemuxer might have multiple media track sets (since it can have
1052 // multiple SourceBuffers), so we need to merge the map for the current set of
1053 // tracks with the global |track_id_to_demux_stream_| map shared across all
1054 // SourceBuffers.
1055 for (const auto& it : new_track_id_map) {
1056 track_id_to_demux_stream_[it.first] = it.second;
1057 }
1058 }
1059
1060 const DemuxerStream* ChunkDemuxer::GetDemuxerStreamByTrackId(
1061 unsigned track_id) const {
1062 base::AutoLock auto_lock(lock_);
1063 const auto& it = track_id_to_demux_stream_.find(track_id);
1064 CHECK(it != track_id_to_demux_stream_.end());
1065 return it->second;
1066 }
1067
1043 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { 1068 bool ChunkDemuxer::IsValidId(const std::string& source_id) const {
1044 lock_.AssertAcquired(); 1069 lock_.AssertAcquired();
1045 return source_state_map_.count(source_id) > 0u; 1070 return source_state_map_.count(source_id) > 0u;
1046 } 1071 }
1047 1072
1048 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { 1073 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) {
1049 DCHECK(duration_ != new_duration); 1074 DCHECK(duration_ != new_duration);
1050 user_specified_duration_ = -1; 1075 user_specified_duration_ = -1;
1051 duration_ = new_duration; 1076 duration_ = new_duration;
1052 host_->SetDuration(new_duration); 1077 host_->SetDuration(new_duration);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1164 }
1140 1165
1141 void ChunkDemuxer::ShutdownAllStreams() { 1166 void ChunkDemuxer::ShutdownAllStreams() {
1142 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1167 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1143 itr != source_state_map_.end(); ++itr) { 1168 itr != source_state_map_.end(); ++itr) {
1144 itr->second->Shutdown(); 1169 itr->second->Shutdown();
1145 } 1170 }
1146 } 1171 }
1147 1172
1148 } // namespace media 1173 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.h ('k') | media/filters/chunk_demuxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698