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

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

Issue 1935873002: Implement disabling and enabling media tracks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@track-control2
Patch Set: Updated comments + dchecks in ffmpeg demux stream Created 4 years, 6 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 <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 "base/strings/string_number_conversions.h"
18 #include "media/base/audio_decoder_config.h" 19 #include "media/base/audio_decoder_config.h"
19 #include "media/base/bind_to_current_loop.h" 20 #include "media/base/bind_to_current_loop.h"
20 #include "media/base/media_tracks.h" 21 #include "media/base/media_tracks.h"
21 #include "media/base/stream_parser_buffer.h" 22 #include "media/base/stream_parser_buffer.h"
22 #include "media/base/timestamp_constants.h" 23 #include "media/base/timestamp_constants.h"
23 #include "media/base/video_decoder_config.h" 24 #include "media/base/video_decoder_config.h"
24 #include "media/filters/frame_processor.h" 25 #include "media/filters/frame_processor.h"
25 #include "media/filters/stream_parser_factory.h" 26 #include "media/filters/stream_parser_factory.h"
26 27
27 using base::TimeDelta; 28 using base::TimeDelta;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 stream_->UnmarkEndOfStream(); 235 stream_->UnmarkEndOfStream();
235 } 236 }
236 237
237 // DemuxerStream methods. 238 // DemuxerStream methods.
238 void ChunkDemuxerStream::Read(const ReadCB& read_cb) { 239 void ChunkDemuxerStream::Read(const ReadCB& read_cb) {
239 base::AutoLock auto_lock(lock_); 240 base::AutoLock auto_lock(lock_);
240 DCHECK_NE(state_, UNINITIALIZED); 241 DCHECK_NE(state_, UNINITIALIZED);
241 DCHECK(read_cb_.is_null()); 242 DCHECK(read_cb_.is_null());
242 243
243 read_cb_ = BindToCurrentLoop(read_cb); 244 read_cb_ = BindToCurrentLoop(read_cb);
245
246 if (!is_enabled_) {
247 DVLOG(1) << "Read from disabled stream, returning EOS";
248 base::ResetAndReturn(&read_cb_).Run(kOk,
249 StreamParserBuffer::CreateEOSBuffer());
250 return;
251 }
252
244 CompletePendingReadIfPossible_Locked(); 253 CompletePendingReadIfPossible_Locked();
245 } 254 }
246 255
247 DemuxerStream::Type ChunkDemuxerStream::type() const { return type_; } 256 DemuxerStream::Type ChunkDemuxerStream::type() const { return type_; }
248 257
249 DemuxerStream::Liveness ChunkDemuxerStream::liveness() const { 258 DemuxerStream::Liveness ChunkDemuxerStream::liveness() const {
250 base::AutoLock auto_lock(lock_); 259 base::AutoLock auto_lock(lock_);
251 return liveness_; 260 return liveness_;
252 } 261 }
253 262
254 AudioDecoderConfig ChunkDemuxerStream::audio_decoder_config() { 263 AudioDecoderConfig ChunkDemuxerStream::audio_decoder_config() {
255 CHECK_EQ(type_, AUDIO); 264 CHECK_EQ(type_, AUDIO);
256 base::AutoLock auto_lock(lock_); 265 base::AutoLock auto_lock(lock_);
257 return stream_->GetCurrentAudioDecoderConfig(); 266 return stream_->GetCurrentAudioDecoderConfig();
258 } 267 }
259 268
260 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() { 269 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() {
261 CHECK_EQ(type_, VIDEO); 270 CHECK_EQ(type_, VIDEO);
262 base::AutoLock auto_lock(lock_); 271 base::AutoLock auto_lock(lock_);
263 return stream_->GetCurrentVideoDecoderConfig(); 272 return stream_->GetCurrentVideoDecoderConfig();
264 } 273 }
265 274
266 bool ChunkDemuxerStream::SupportsConfigChanges() { return true; } 275 bool ChunkDemuxerStream::SupportsConfigChanges() { return true; }
267 276
268 VideoRotation ChunkDemuxerStream::video_rotation() { 277 VideoRotation ChunkDemuxerStream::video_rotation() {
269 return VIDEO_ROTATION_0; 278 return VIDEO_ROTATION_0;
270 } 279 }
271 280
281 bool ChunkDemuxerStream::enabled() const {
282 base::AutoLock auto_lock(lock_);
283 return is_enabled_;
284 }
285
286 void ChunkDemuxerStream::set_enabled(bool enabled, base::TimeDelta timestamp) {
287 base::AutoLock auto_lock(lock_);
288
289 if (enabled == is_enabled_)
290 return;
291
292 is_enabled_ = enabled;
293 if (enabled) {
294 DCHECK(stream_);
295 stream_->Seek(timestamp);
296 } else if (!read_cb_.is_null()) {
297 DVLOG(1) << "Read from disabled stream, returning EOS";
298 base::ResetAndReturn(&read_cb_).Run(kOk,
299 StreamParserBuffer::CreateEOSBuffer());
300 }
301 }
302
272 TextTrackConfig ChunkDemuxerStream::text_track_config() { 303 TextTrackConfig ChunkDemuxerStream::text_track_config() {
273 CHECK_EQ(type_, TEXT); 304 CHECK_EQ(type_, TEXT);
274 base::AutoLock auto_lock(lock_); 305 base::AutoLock auto_lock(lock_);
275 return stream_->GetCurrentTextTrackConfig(); 306 return stream_->GetCurrentTextTrackConfig();
276 } 307 }
277 308
278 void ChunkDemuxerStream::SetStreamMemoryLimit(size_t memory_limit) { 309 void ChunkDemuxerStream::SetStreamMemoryLimit(size_t memory_limit) {
279 stream_->set_memory_limit(memory_limit); 310 stream_->set_memory_limit(memory_limit);
280 } 311 }
281 312
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 } 1196 }
1166 1197
1167 void ChunkDemuxer::ShutdownAllStreams() { 1198 void ChunkDemuxer::ShutdownAllStreams() {
1168 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1199 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1169 itr != source_state_map_.end(); ++itr) { 1200 itr != source_state_map_.end(); ++itr) {
1170 itr->second->Shutdown(); 1201 itr->second->Shutdown();
1171 } 1202 }
1172 } 1203 }
1173 1204
1174 } // namespace media 1205 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698