Commit 250cefef authored by mikhal@google.com's avatar mikhal@google.com

Cast:Forcing VP8 codec initialization on a designated thread.

Makes sure that all interaction with the video decoder is done on the VIDEO_DECODER thread.
Logging which was removed here, will be added in a follow  up cl.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238535 0039d316-1c4b-4281-b951-d872f2087c98
parent 06153f0a
......@@ -90,7 +90,7 @@ class EncodeDecodeTest : public ::testing::Test {
int max_unacked_frames = 1;
encoder_.reset(new Vp8Encoder(encoder_config_, max_unacked_frames));
// Initialize to use one core.
decoder_.reset(new Vp8Decoder(1, cast_environment_));
decoder_.reset(new Vp8Decoder(cast_environment_));
}
virtual ~EncodeDecodeTest() {}
......
......@@ -19,18 +19,20 @@ void LogFrameDecodedEvent(CastEnvironment* const cast_environment,
// 0, frame_id);
}
Vp8Decoder::Vp8Decoder(int number_of_cores,
scoped_refptr<CastEnvironment> cast_environment)
Vp8Decoder::Vp8Decoder(scoped_refptr<CastEnvironment> cast_environment)
: decoder_(new vpx_dec_ctx_t()),
cast_environment_(cast_environment) {
InitDecode(number_of_cores);
// Make sure that we initialize the decoder from the correct thread.
cast_environment_->PostTask(CastEnvironment::VIDEO_DECODER, FROM_HERE,
base::Bind(&Vp8Decoder::InitDecoder, base::Unretained(this)));
}
Vp8Decoder::~Vp8Decoder() {}
void Vp8Decoder::InitDecode(int number_of_cores) {
vpx_codec_dec_cfg_t cfg;
cfg.threads = number_of_cores;
void Vp8Decoder::InitDecoder() {
vpx_codec_dec_cfg_t cfg;
// Initializing to use one core.
cfg.threads = 1;
vpx_codec_flags_t flags = VPX_CODEC_USE_POSTPROC;
if (vpx_codec_dec_init(decoder_.get(), vpx_codec_vp8_dx(), &cfg, flags)) {
......@@ -41,6 +43,7 @@ void Vp8Decoder::InitDecode(int number_of_cores) {
bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame,
const base::TimeTicks render_time,
const VideoFrameDecodedCallback& frame_decoded_cb) {
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_DECODER));
const int frame_id_int = static_cast<int>(encoded_frame->frame_id);
VLOG(1) << "VP8 decode frame:" << frame_id_int
<< " sized:" << encoded_frame->data.size();
......@@ -94,8 +97,8 @@ bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame,
// Log:: Decoding complete (should be called from the main thread).
cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind(
LogFrameDecodedEvent, cast_environment_,encoded_frame->frame_id));
VLOG(1) << "Decoded frame " << frame_id_int;
VLOG(1) << "Decoded frame " << frame_id_int;
// Frame decoded - return frame to the user via callback.
cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
base::Bind(frame_decoded_cb, base::Passed(&decoded_frame),
......
......@@ -21,8 +21,7 @@ namespace cast {
// thread.
class Vp8Decoder : public base::NonThreadSafe {
public:
Vp8Decoder(int number_of_cores,
scoped_refptr<CastEnvironment> cast_environment);
explicit Vp8Decoder(scoped_refptr<CastEnvironment> cast_environment);
~Vp8Decoder();
// Decode frame - The decoded frame will be passed via the callback.
......@@ -35,8 +34,7 @@ class Vp8Decoder : public base::NonThreadSafe {
private:
// Initialize the decoder.
void InitDecode(int number_of_cores);
void InitDecoder();
scoped_ptr<vpx_dec_ctx_t> decoder_;
scoped_refptr<CastEnvironment> cast_environment_;
};
......
......@@ -18,8 +18,7 @@ VideoDecoder::VideoDecoder(const VideoReceiverConfig& video_config,
vp8_decoder_() {
switch (video_config.codec) {
case kVp8:
// Initializing to use one core.
vp8_decoder_.reset(new Vp8Decoder(1, cast_environment));
vp8_decoder_.reset(new Vp8Decoder(cast_environment));
break;
case kH264:
NOTIMPLEMENTED();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment