Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/decoder_stream.h" | 5 #include "media/filters/decoder_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "media/base/audio_decoder.h" | |
| 13 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 14 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
| 15 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
| 16 #include "media/base/video_decoder.h" | 17 #include "media/base/video_decoder.h" |
| 17 #include "media/filters/decrypting_demuxer_stream.h" | 18 #include "media/filters/decrypting_demuxer_stream.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 // TODO(rileya) Devise a better way of specifying trace/UMA/etc strings for | 22 // TODO(rileya) Devise a better way of specifying trace/UMA/etc strings for |
| 22 // templated classes such as this. | 23 // templated classes such as this. |
| 23 template <DemuxerStream::Type StreamType> | 24 template <DemuxerStream::Type StreamType> |
| 24 static const char* GetTraceString(); | 25 static const char* GetTraceString(); |
| 25 | 26 |
| 26 template <> | 27 template <> |
| 27 const char* GetTraceString<DemuxerStream::VIDEO>() { | 28 const char* GetTraceString<DemuxerStream::VIDEO>() { |
| 28 return "DecoderStream<VIDEO>::Decode"; | 29 return "DecoderStream<VIDEO>::Decode"; |
| 29 } | 30 } |
| 30 | 31 |
| 32 template <> | |
| 33 const char* GetTraceString<DemuxerStream::AUDIO>() { | |
| 34 return "DecoderStream<AUDIO>::Decode"; | |
| 35 } | |
| 36 | |
| 31 template <DemuxerStream::Type StreamType> | 37 template <DemuxerStream::Type StreamType> |
| 32 DecoderStream<StreamType>::DecoderStream( | 38 DecoderStream<StreamType>::DecoderStream( |
| 33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 39 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 34 ScopedVector<Decoder> decoders, | 40 ScopedVector<Decoder> decoders, |
| 35 const SetDecryptorReadyCB& set_decryptor_ready_cb) | 41 const SetDecryptorReadyCB& set_decryptor_ready_cb) |
| 36 : task_runner_(task_runner), | 42 : task_runner_(task_runner), |
| 37 weak_factory_(this), | 43 weak_factory_(this), |
| 38 state_(STATE_UNINITIALIZED), | 44 state_(STATE_UNINITIALIZED), |
| 39 stream_(NULL), | 45 stream_(NULL), |
| 40 decoder_selector_( | 46 decoder_selector_( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 58 DCHECK(!init_cb.is_null()); | 64 DCHECK(!init_cb.is_null()); |
| 59 | 65 |
| 60 statistics_cb_ = statistics_cb; | 66 statistics_cb_ = statistics_cb; |
| 61 init_cb_ = init_cb; | 67 init_cb_ = init_cb; |
| 62 stream_ = stream; | 68 stream_ = stream; |
| 63 | 69 |
| 64 state_ = STATE_INITIALIZING; | 70 state_ = STATE_INITIALIZING; |
| 65 // TODO(xhwang): DecoderSelector only needs a config to select a decoder. | 71 // TODO(xhwang): DecoderSelector only needs a config to select a decoder. |
| 66 decoder_selector_->SelectDecoder( | 72 decoder_selector_->SelectDecoder( |
| 67 stream, | 73 stream, |
| 68 StatisticsCB(), | |
| 69 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, | 74 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, |
| 70 weak_factory_.GetWeakPtr())); | 75 weak_factory_.GetWeakPtr())); |
| 71 } | 76 } |
| 72 | 77 |
| 73 template <DemuxerStream::Type StreamType> | 78 template <DemuxerStream::Type StreamType> |
| 74 void DecoderStream<StreamType>::Read(const ReadCB& read_cb) { | 79 void DecoderStream<StreamType>::Read(const ReadCB& read_cb) { |
| 75 DVLOG(2) << __FUNCTION__; | 80 DVLOG(2) << __FUNCTION__; |
| 76 DCHECK(task_runner_->BelongsToCurrentThread()); | 81 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 77 DCHECK(state_ == STATE_NORMAL || state_ == STATE_FLUSHING_DECODER || | 82 DCHECK(state_ == STATE_NORMAL || state_ == STATE_FLUSHING_DECODER || |
| 78 state_ == STATE_ERROR) << state_; | 83 state_ == STATE_ERROR) << state_; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 } | 317 } |
| 313 | 318 |
| 314 if (status == Decoder::kNotEnoughData) { | 319 if (status == Decoder::kNotEnoughData) { |
| 315 if (state_ == STATE_NORMAL) | 320 if (state_ == STATE_NORMAL) |
| 316 ReadFromDemuxerStream(); | 321 ReadFromDemuxerStream(); |
| 317 else if (state_ == STATE_FLUSHING_DECODER) | 322 else if (state_ == STATE_FLUSHING_DECODER) |
| 318 FlushDecoder(); | 323 FlushDecoder(); |
| 319 return; | 324 return; |
| 320 } | 325 } |
| 321 | 326 |
| 327 DCHECK(output); | |
| 322 SatisfyRead(OK, output); | 328 SatisfyRead(OK, output); |
| 323 } | 329 } |
| 324 | 330 |
| 325 template <DemuxerStream::Type StreamType> | 331 template <DemuxerStream::Type StreamType> |
| 326 void DecoderStream<StreamType>::ReadFromDemuxerStream() { | 332 void DecoderStream<StreamType>::ReadFromDemuxerStream() { |
| 327 DVLOG(2) << __FUNCTION__; | 333 DVLOG(2) << __FUNCTION__; |
| 328 DCHECK_EQ(state_, STATE_NORMAL) << state_; | 334 DCHECK_EQ(state_, STATE_NORMAL) << state_; |
| 329 DCHECK(!read_cb_.is_null()); | 335 DCHECK(!read_cb_.is_null()); |
| 330 DCHECK(reset_cb_.is_null()); | 336 DCHECK(reset_cb_.is_null()); |
| 331 DCHECK(stop_cb_.is_null()); | 337 DCHECK(stop_cb_.is_null()); |
| 332 | 338 |
| 333 state_ = STATE_PENDING_DEMUXER_READ; | 339 state_ = STATE_PENDING_DEMUXER_READ; |
| 334 stream_->Read(base::Bind(&DecoderStream<StreamType>::OnBufferReady, | 340 stream_->Read(base::Bind(&DecoderStream<StreamType>::OnBufferReady, |
| 335 weak_factory_.GetWeakPtr())); | 341 weak_factory_.GetWeakPtr())); |
| 336 } | 342 } |
| 337 | 343 |
| 344 template <> | |
| 345 void DecoderStream<DemuxerStream::AUDIO>::ReadFromDemuxerStream() { | |
| 346 DVLOG(2) << __FUNCTION__; | |
| 347 DCHECK_EQ(state_, STATE_NORMAL) << state_; | |
| 348 DCHECK(!read_cb_.is_null()); | |
| 349 DCHECK(reset_cb_.is_null()); | |
| 350 DCHECK(stop_cb_.is_null()); | |
| 351 DCHECK(decoder_); | |
| 352 | |
| 353 if (decoder_->HasQueuedData()) { | |
| 354 Decode(NULL); | |
|
DaleCurtis
2014/02/21 21:48:48
Won't this happen naturally as the decoder is drai
rileya (GONE FROM CHROMIUM)
2014/02/21 23:04:02
I just realized how unintuitive this looks now, ha
xhwang
2014/02/21 23:57:56
Some random ideas:
1, See comment above, if you h
rileya (GONE FROM CHROMIUM)
2014/02/24 21:04:11
1) Sounds good, done.
2) Yup, this was originally
rileya (GONE FROM CHROMIUM)
2014/02/24 21:07:50
s/VRD/GVD/
Not sure how I messed that up haha...
| |
| 355 } else { | |
| 356 state_ = STATE_PENDING_DEMUXER_READ; | |
| 357 stream_->Read( | |
| 358 base::Bind(&DecoderStream<DemuxerStream::AUDIO>::OnBufferReady, | |
| 359 weak_factory_.GetWeakPtr())); | |
| 360 } | |
| 361 } | |
| 362 | |
| 338 template <DemuxerStream::Type StreamType> | 363 template <DemuxerStream::Type StreamType> |
| 339 void DecoderStream<StreamType>::OnBufferReady( | 364 void DecoderStream<StreamType>::OnBufferReady( |
| 340 DemuxerStream::Status status, | 365 DemuxerStream::Status status, |
| 341 const scoped_refptr<DecoderBuffer>& buffer) { | 366 const scoped_refptr<DecoderBuffer>& buffer) { |
| 342 DVLOG(2) << __FUNCTION__; | 367 DVLOG(2) << __FUNCTION__; |
| 343 DCHECK(task_runner_->BelongsToCurrentThread()); | 368 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 344 DCHECK_EQ(state_, STATE_PENDING_DEMUXER_READ) << state_; | 369 DCHECK_EQ(state_, STATE_PENDING_DEMUXER_READ) << state_; |
| 345 DCHECK_EQ(buffer.get() != NULL, status == DemuxerStream::kOk) << status; | 370 DCHECK_EQ(buffer.get() != NULL, status == DemuxerStream::kOk) << status; |
| 346 DCHECK(!read_cb_.is_null()); | 371 DCHECK(!read_cb_.is_null()); |
| 347 DCHECK(stop_cb_.is_null()); | 372 DCHECK(stop_cb_.is_null()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 DCHECK(status == DemuxerStream::kOk) << status; | 405 DCHECK(status == DemuxerStream::kOk) << status; |
| 381 Decode(buffer); | 406 Decode(buffer); |
| 382 } | 407 } |
| 383 | 408 |
| 384 template <DemuxerStream::Type StreamType> | 409 template <DemuxerStream::Type StreamType> |
| 385 void DecoderStream<StreamType>::ReinitializeDecoder() { | 410 void DecoderStream<StreamType>::ReinitializeDecoder() { |
| 386 DVLOG(2) << __FUNCTION__; | 411 DVLOG(2) << __FUNCTION__; |
| 387 DCHECK(task_runner_->BelongsToCurrentThread()); | 412 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 388 DCHECK_EQ(state_, STATE_FLUSHING_DECODER) << state_; | 413 DCHECK_EQ(state_, STATE_FLUSHING_DECODER) << state_; |
| 389 | 414 |
| 390 // TODO(rileya): Specialize this for audio, or, better yet, change | 415 DCHECK(StreamTraits::GetDecoderConfig(*stream_).IsValidConfig()); |
| 391 // DemuxerStream config getters to be templated. | |
| 392 DCHECK(stream_->video_decoder_config().IsValidConfig()); | |
| 393 state_ = STATE_REINITIALIZING_DECODER; | 416 state_ = STATE_REINITIALIZING_DECODER; |
| 394 decoder_->Initialize( | 417 decoder_->Initialize( |
| 395 stream_->video_decoder_config(), | 418 StreamTraits::GetDecoderConfig(*stream_), |
| 396 base::Bind(&DecoderStream<StreamType>::OnDecoderReinitialized, | 419 base::Bind(&DecoderStream<StreamType>::OnDecoderReinitialized, |
| 397 weak_factory_.GetWeakPtr())); | 420 weak_factory_.GetWeakPtr())); |
| 398 } | 421 } |
| 399 | 422 |
| 400 template <DemuxerStream::Type StreamType> | 423 template <DemuxerStream::Type StreamType> |
| 401 void DecoderStream<StreamType>::OnDecoderReinitialized(PipelineStatus status) { | 424 void DecoderStream<StreamType>::OnDecoderReinitialized(PipelineStatus status) { |
| 402 DVLOG(2) << __FUNCTION__; | 425 DVLOG(2) << __FUNCTION__; |
| 403 DCHECK(task_runner_->BelongsToCurrentThread()); | 426 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 404 DCHECK_EQ(state_, STATE_REINITIALIZING_DECODER) << state_; | 427 DCHECK_EQ(state_, STATE_REINITIALIZING_DECODER) << state_; |
| 405 DCHECK(stop_cb_.is_null()); | 428 DCHECK(stop_cb_.is_null()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 DCHECK(!stop_cb_.is_null()); | 508 DCHECK(!stop_cb_.is_null()); |
| 486 | 509 |
| 487 state_ = STATE_STOPPED; | 510 state_ = STATE_STOPPED; |
| 488 stream_ = NULL; | 511 stream_ = NULL; |
| 489 decoder_.reset(); | 512 decoder_.reset(); |
| 490 decrypting_demuxer_stream_.reset(); | 513 decrypting_demuxer_stream_.reset(); |
| 491 base::ResetAndReturn(&stop_cb_).Run(); | 514 base::ResetAndReturn(&stop_cb_).Run(); |
| 492 } | 515 } |
| 493 | 516 |
| 494 template class DecoderStream<DemuxerStream::VIDEO>; | 517 template class DecoderStream<DemuxerStream::VIDEO>; |
| 518 template class DecoderStream<DemuxerStream::AUDIO>; | |
| 495 } // namespace media | 519 } // namespace media |
| OLD | NEW |