Skip to content

Commit

Permalink
Destroy the fallback decoder after enough sw frames are decoded.
Browse files Browse the repository at this point in the history
We only need to hold onto the GPU decoder long enough that previous
frames have been rendered; once we exceed kMaxFrames we know we've
exhausted all hardware frames and can destruct the decoder.

BUG=none
TEST=media_unittests

Review URL: https://codereview.chromium.org/1417183002

Cr-Commit-Position: refs/heads/master@{#355930}
  • Loading branch information
dalecurtis authored and Commit bot committed Oct 23, 2015
1 parent 8c44d69 commit 4c55978
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 11 additions & 2 deletions media/filters/decoder_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/trace_event/trace_event.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/decoder_buffer.h"
#include "media/base/limits.h"
#include "media/base/media_log.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_decoder.h"
Expand Down Expand Up @@ -50,11 +51,11 @@ DecoderStream<StreamType>::DecoderStream(
decoder_selector_(new DecoderSelector<StreamType>(task_runner,
decoders.Pass(),
media_log)),
decoded_frames_since_fallback_(0),
active_splice_(false),
decoding_eos_(false),
pending_decode_requests_(0),
weak_factory_(this) {
}
weak_factory_(this) {}

template <DemuxerStream::Type StreamType>
DecoderStream<StreamType>::~DecoderStream() {
Expand Down Expand Up @@ -243,6 +244,7 @@ void DecoderStream<StreamType>::OnDecoderSelected(
}

previous_decoder_ = decoder_.Pass();
decoded_frames_since_fallback_ = 0;
decoder_ = selected_decoder.Pass();
if (decrypting_demuxer_stream) {
decrypting_demuxer_stream_ = decrypting_demuxer_stream.Pass();
Expand Down Expand Up @@ -413,6 +415,13 @@ void DecoderStream<StreamType>::OnDecodeOutputReady(

// Store decoded output.
ready_outputs_.push_back(output);

// Destruct any previous decoder once we've decoded enough frames to ensure
// that it's no longer in use.
if (previous_decoder_ &&
++decoded_frames_since_fallback_ > limits::kMaxVideoFrames) {
previous_decoder_.reset();
}
}

template <DemuxerStream::Type StreamType>
Expand Down
12 changes: 9 additions & 3 deletions media/filters/decoder_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class MEDIA_EXPORT DecoderStream {
config_change_observer_cb_ = config_change_observer;
}

const Decoder* get_previous_decoder_for_testing() const {
return previous_decoder_.get();
}

private:
enum State {
STATE_UNINITIALIZED,
Expand Down Expand Up @@ -186,9 +190,11 @@ class MEDIA_EXPORT DecoderStream {
scoped_ptr<DecoderSelector<StreamType> > decoder_selector_;

scoped_ptr<Decoder> decoder_;
// TODO(watk): When falling back from H/W decoding to S/W decoding,
// destructing the GpuVideoDecoder too early results in black frames being
// displayed. |previous_decoder_| is used to keep it alive.
// When falling back from H/W decoding to S/W decoding, destructing the
// GpuVideoDecoder too early results in black frames being displayed.
// |previous_decoder_| is used to keep it alive. It is destroyed once we've
// decoded at least media::limits::kMaxVideoFrames frames after fallback.
int decoded_frames_since_fallback_;
scoped_ptr<Decoder> previous_decoder_;
scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_;

Expand Down
2 changes: 2 additions & 0 deletions media/filters/video_frame_stream_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@ TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) {
Initialize();
decoder1_->SimulateFailureToInit();
ReadUntilDecoderReinitialized(decoder1_);
ASSERT_TRUE(video_frame_stream_->get_previous_decoder_for_testing());
ReadAllFrames();
ASSERT_FALSE(video_frame_stream_->get_previous_decoder_for_testing());
}

TEST_P(VideoFrameStreamTest,
Expand Down

0 comments on commit 4c55978

Please sign in to comment.