Chromium Code Reviews| Index: media/filters/decoder_stream.cc |
| diff --git a/media/filters/decoder_stream.cc b/media/filters/decoder_stream.cc |
| index 5c02547a2309e2b163ac242da56b7638b160c8d1..99594215f7d66e0e1df4fd46a636aeb74376c05d 100644 |
| --- a/media/filters/decoder_stream.cc |
| +++ b/media/filters/decoder_stream.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/location.h" |
| #include "base/logging.h" |
| #include "base/single_thread_task_runner.h" |
| +#include "media/base/audio_decoder.h" |
| #include "media/base/bind_to_current_loop.h" |
| #include "media/base/decoder_buffer.h" |
| #include "media/base/demuxer_stream.h" |
| @@ -28,6 +29,11 @@ const char* GetTraceString<DemuxerStream::VIDEO>() { |
| return "DecoderStream<VIDEO>::Decode"; |
| } |
| +template <> |
| +const char* GetTraceString<DemuxerStream::AUDIO>() { |
| + return "DecoderStream<AUDIO>::Decode"; |
| +} |
| + |
| template <DemuxerStream::Type StreamType> |
| DecoderStream<StreamType>::DecoderStream( |
| const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| @@ -65,7 +71,6 @@ void DecoderStream<StreamType>::Initialize(DemuxerStream* stream, |
| // TODO(xhwang): DecoderSelector only needs a config to select a decoder. |
| decoder_selector_->SelectDecoder( |
| stream, |
| - StatisticsCB(), |
| base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, |
| weak_factory_.GetWeakPtr())); |
| } |
| @@ -88,13 +93,21 @@ void DecoderStream<StreamType>::Read(const ReadCB& read_cb) { |
| return; |
| } |
| - read_cb_ = read_cb; |
| + read_cb_ = BindToCurrentLoop(read_cb); |
|
rileya (GONE FROM CHROMIUM)
2014/03/10 18:22:25
Is this reasonable? This fixes a failure in ffmpeg
xhwang
2014/03/10 18:36:31
In general we want to avoid unnecessary posts. For
|
| if (state_ == STATE_FLUSHING_DECODER) { |
| FlushDecoder(); |
| return; |
| } |
| + scoped_refptr<Output> output = decoder_->GetDecodeOutput(); |
| + |
| + // If the decoder has queued output ready to go we don't need a demuxer read. |
| + if (output) { |
| + SatisfyRead(OK, output); |
| + return; |
| + } |
| + |
| ReadFromDemuxerStream(); |
| } |
| @@ -185,6 +198,12 @@ bool DecoderStream<StreamType>::CanReadWithoutStalling() const { |
| return decoder_->CanReadWithoutStalling(); |
| } |
| +template <> |
| +bool DecoderStream<DemuxerStream::AUDIO>::CanReadWithoutStalling() const { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + return true; |
| +} |
| + |
| template <DemuxerStream::Type StreamType> |
| void DecoderStream<StreamType>::OnDecoderSelected( |
| scoped_ptr<Decoder> selected_decoder, |
| @@ -319,6 +338,7 @@ void DecoderStream<StreamType>::OnDecodeOutputReady( |
| return; |
| } |
| + DCHECK(output); |
| SatisfyRead(OK, output); |
| } |
| @@ -387,12 +407,10 @@ void DecoderStream<StreamType>::ReinitializeDecoder() { |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| DCHECK_EQ(state_, STATE_FLUSHING_DECODER) << state_; |
| - // TODO(rileya): Specialize this for audio, or, better yet, change |
| - // DemuxerStream config getters to be templated. |
| - DCHECK(stream_->video_decoder_config().IsValidConfig()); |
| + DCHECK(StreamTraits::GetDecoderConfig(*stream_).IsValidConfig()); |
| state_ = STATE_REINITIALIZING_DECODER; |
| decoder_->Initialize( |
| - stream_->video_decoder_config(), |
| + StreamTraits::GetDecoderConfig(*stream_), |
| base::Bind(&DecoderStream<StreamType>::OnDecoderReinitialized, |
| weak_factory_.GetWeakPtr())); |
| } |
| @@ -492,5 +510,6 @@ void DecoderStream<StreamType>::OnDecoderStopped() { |
| } |
| template class DecoderStream<DemuxerStream::VIDEO>; |
| +template class DecoderStream<DemuxerStream::AUDIO>; |
| } // namespace media |