| Index: remoting/base/decoder_vp8.cc
|
| diff --git a/remoting/base/decoder_vp8.cc b/remoting/base/decoder_vp8.cc
|
| index 452cd1f74fba84e4018afd973c779cb6a701cef5..a8d52456f73df2a163853719fd2dddfd0e8036f3 100644
|
| --- a/remoting/base/decoder_vp8.cc
|
| +++ b/remoting/base/decoder_vp8.cc
|
| @@ -18,12 +18,7 @@ extern "C" {
|
| namespace remoting {
|
|
|
| DecoderVp8::DecoderVp8()
|
| - : state_(kWaitingForBeginRect),
|
| - rect_x_(0),
|
| - rect_y_(0),
|
| - rect_width_(0),
|
| - rect_height_(0),
|
| - updated_rects_(NULL),
|
| + : state_(kUninitialized),
|
| codec_(NULL) {
|
| }
|
|
|
| @@ -35,71 +30,22 @@ DecoderVp8::~DecoderVp8() {
|
| delete codec_;
|
| }
|
|
|
| -bool DecoderVp8::BeginDecode(scoped_refptr<media::VideoFrame> frame,
|
| - UpdatedRects* updated_rects,
|
| - Task* partial_decode_done,
|
| - Task* decode_done) {
|
| - DCHECK(!partial_decode_done_.get());
|
| - DCHECK(!decode_done_.get());
|
| - DCHECK(!updated_rects_);
|
| - DCHECK_EQ(kWaitingForBeginRect, state_);
|
| -
|
| - partial_decode_done_.reset(partial_decode_done);
|
| - decode_done_.reset(decode_done);
|
| - updated_rects_ = updated_rects;
|
| +void DecoderVp8::Initialize(scoped_refptr<media::VideoFrame> frame,
|
| + const gfx::Rect& clip, int bytes_per_src_pixel) {
|
| + DCHECK_EQ(kUninitialized, state_);
|
|
|
| if (frame->format() != media::VideoFrame::RGB32) {
|
| LOG(INFO) << "DecoderVp8 only supports RGB32 as output";
|
| - return false;
|
| + state_ = kError;
|
| + return;
|
| }
|
| frame_ = frame;
|
| - return true;
|
| -}
|
| -
|
| -bool DecoderVp8::PartialDecode(ChromotingHostMessage* message) {
|
| - scoped_ptr<ChromotingHostMessage> msg_deleter(message);
|
| - DCHECK(message->has_update_stream_packet());
|
| -
|
| - bool ret = true;
|
| - if (message->update_stream_packet().has_begin_rect())
|
| - ret = HandleBeginRect(message);
|
| - if (ret && message->update_stream_packet().has_rect_data())
|
| - ret = HandleRectData(message);
|
| - if (ret && message->update_stream_packet().has_end_rect())
|
| - ret = HandleEndRect(message);
|
| - return ret;
|
| -}
|
|
|
| -void DecoderVp8::EndDecode() {
|
| - DCHECK_EQ(kWaitingForBeginRect, state_);
|
| - decode_done_->Run();
|
| -
|
| - partial_decode_done_.reset();
|
| - decode_done_.reset();
|
| - frame_ = NULL;
|
| - updated_rects_ = NULL;
|
| + state_ = kReady;
|
| }
|
|
|
| -bool DecoderVp8::HandleBeginRect(ChromotingHostMessage* message) {
|
| - DCHECK_EQ(kWaitingForBeginRect, state_);
|
| - state_ = kWaitingForRectData;
|
| -
|
| - rect_width_ = message->update_stream_packet().begin_rect().width();
|
| - rect_height_ = message->update_stream_packet().begin_rect().height();
|
| - rect_x_ = message->update_stream_packet().begin_rect().x();
|
| - rect_y_ = message->update_stream_packet().begin_rect().y();
|
| -
|
| - PixelFormat pixel_format =
|
| - message->update_stream_packet().begin_rect().pixel_format();
|
| - if (pixel_format != PixelFormatYv12)
|
| - return false;
|
| - return true;
|
| -}
|
| -
|
| -bool DecoderVp8::HandleRectData(ChromotingHostMessage* message) {
|
| - DCHECK_EQ(kWaitingForRectData, state_);
|
| - DCHECK_EQ(0,
|
| - message->update_stream_packet().rect_data().sequence_number());
|
| +void DecoderVp8::DecodeBytes(const std::string& encoded_bytes) {
|
| + DCHECK_EQ(kReady, state_);
|
|
|
| // Initialize the codec as needed.
|
| if (!codec_) {
|
| @@ -112,25 +58,21 @@ bool DecoderVp8::HandleRectData(ChromotingHostMessage* message) {
|
| LOG(INFO) << "Cannot initialize codec.";
|
| delete codec_;
|
| codec_ = NULL;
|
| - return false;
|
| + state_ = kError;
|
| + return;
|
| }
|
| }
|
|
|
| + LOG(WARNING) << "Decoding " << encoded_bytes.size();
|
| +
|
| // Do the actual decoding.
|
| vpx_codec_err_t ret = vpx_codec_decode(
|
| - codec_,
|
| - (uint8_t*)message->update_stream_packet().rect_data().data().c_str(),
|
| - message->update_stream_packet().rect_data().data().size(),
|
| - NULL, 0);
|
| + codec_, reinterpret_cast<const uint8*>(encoded_bytes.data()),
|
| + encoded_bytes.size(), NULL, 0);
|
| if (ret != VPX_CODEC_OK) {
|
| - LOG(INFO) << "Decoding failed:"
|
| - << vpx_codec_err_to_string(ret)
|
| - << "\n"
|
| - << "Details: "
|
| - << vpx_codec_error(codec_)
|
| - << "\n"
|
| + LOG(INFO) << "Decoding failed:" << vpx_codec_err_to_string(ret) << "\n"
|
| + << "Details: " << vpx_codec_error(codec_) << "\n"
|
| << vpx_codec_error_detail(codec_);
|
| - return false;
|
| }
|
|
|
| // Gets the decoded data.
|
| @@ -138,28 +80,28 @@ bool DecoderVp8::HandleRectData(ChromotingHostMessage* message) {
|
| vpx_image_t* image = vpx_codec_get_frame(codec_, &iter);
|
| if (!image) {
|
| LOG(INFO) << "No video frame decoded";
|
| - return false;
|
| }
|
|
|
| // Perform YUV conversion.
|
| media::ConvertYUVToRGB32(image->planes[0], image->planes[1], image->planes[2],
|
| frame_->data(media::VideoFrame::kRGBPlane),
|
| - rect_width_, rect_height_,
|
| + frame_->width(), frame_->height(),
|
| image->stride[0], image->stride[1],
|
| frame_->stride(media::VideoFrame::kRGBPlane),
|
| media::YV12);
|
| +}
|
| +
|
| +void DecoderVp8::Reset() {
|
| + frame_ = NULL;
|
| + state_ = kUninitialized;
|
| +}
|
|
|
| - updated_rects_->clear();
|
| - updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_,
|
| - rect_width_, rect_height_));
|
| - partial_decode_done_->Run();
|
| - return true;
|
| +bool DecoderVp8::IsReadyForData() {
|
| + return state_ == kReady;
|
| }
|
|
|
| -bool DecoderVp8::HandleEndRect(ChromotingHostMessage* message) {
|
| - DCHECK_EQ(kWaitingForRectData, state_);
|
| - state_ = kWaitingForBeginRect;
|
| - return true;
|
| +VideoPacketFormat::Encoding DecoderVp8::Encoding() {
|
| + return VideoPacketFormat::ENCODING_VP8;
|
| }
|
|
|
| } // namespace remoting
|
|
|