| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/codec/video_decoder_vp8.h" | 5 #include "remoting/codec/video_decoder_vp8.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/media.h" | 10 #include "media/base/media.h" |
| 11 #include "media/base/yuv_convert.h" | 11 #include "media/base/yuv_convert.h" |
| 12 #include "remoting/base/util.h" | 12 #include "remoting/base/util.h" |
| 13 | 13 |
| 14 extern "C" { | 14 extern "C" { |
| 15 #define VPX_CODEC_DISABLE_COMPAT 1 | 15 #define VPX_CODEC_DISABLE_COMPAT 1 |
| 16 #include "third_party/libvpx/libvpx.h" | 16 #include "third_party/libvpx/libvpx.h" |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace remoting { | 19 namespace remoting { |
| 20 | 20 |
| 21 DecoderVp8::DecoderVp8() | 21 VideoDecoderVp8::VideoDecoderVp8() |
| 22 : state_(kUninitialized), | 22 : state_(kUninitialized), |
| 23 codec_(NULL), | 23 codec_(NULL), |
| 24 last_image_(NULL), | 24 last_image_(NULL), |
| 25 screen_size_(SkISize::Make(0, 0)) { | 25 screen_size_(SkISize::Make(0, 0)) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 DecoderVp8::~DecoderVp8() { | 28 VideoDecoderVp8::~VideoDecoderVp8() { |
| 29 if (codec_) { | 29 if (codec_) { |
| 30 vpx_codec_err_t ret = vpx_codec_destroy(codec_); | 30 vpx_codec_err_t ret = vpx_codec_destroy(codec_); |
| 31 CHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec"; | 31 CHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec"; |
| 32 } | 32 } |
| 33 delete codec_; | 33 delete codec_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void DecoderVp8::Initialize(const SkISize& screen_size) { | 36 void VideoDecoderVp8::Initialize(const SkISize& screen_size) { |
| 37 DCHECK(!screen_size.isEmpty()); | 37 DCHECK(!screen_size.isEmpty()); |
| 38 | 38 |
| 39 screen_size_ = screen_size; | 39 screen_size_ = screen_size; |
| 40 state_ = kReady; | 40 state_ = kReady; |
| 41 } | 41 } |
| 42 | 42 |
| 43 Decoder::DecodeResult DecoderVp8::DecodePacket(const VideoPacket* packet) { | 43 VideoDecoder::DecodeResult VideoDecoderVp8::DecodePacket( |
| 44 const VideoPacket* packet) { |
| 44 DCHECK_EQ(kReady, state_); | 45 DCHECK_EQ(kReady, state_); |
| 45 | 46 |
| 46 // Initialize the codec as needed. | 47 // Initialize the codec as needed. |
| 47 if (!codec_) { | 48 if (!codec_) { |
| 48 codec_ = new vpx_codec_ctx_t(); | 49 codec_ = new vpx_codec_ctx_t(); |
| 49 | 50 |
| 50 // TODO(hclam): Scale the number of threads with number of cores of the | 51 // TODO(hclam): Scale the number of threads with number of cores of the |
| 51 // machine. | 52 // machine. |
| 52 vpx_codec_dec_cfg config; | 53 vpx_codec_dec_cfg config; |
| 53 config.w = 0; | 54 config.w = 0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 remoting_rect.y(), | 93 remoting_rect.y(), |
| 93 remoting_rect.width(), | 94 remoting_rect.width(), |
| 94 remoting_rect.height()); | 95 remoting_rect.height()); |
| 95 region.op(rect, SkRegion::kUnion_Op); | 96 region.op(rect, SkRegion::kUnion_Op); |
| 96 } | 97 } |
| 97 | 98 |
| 98 updated_region_.op(region, SkRegion::kUnion_Op); | 99 updated_region_.op(region, SkRegion::kUnion_Op); |
| 99 return DECODE_DONE; | 100 return DECODE_DONE; |
| 100 } | 101 } |
| 101 | 102 |
| 102 bool DecoderVp8::IsReadyForData() { | 103 bool VideoDecoderVp8::IsReadyForData() { |
| 103 return state_ == kReady; | 104 return state_ == kReady; |
| 104 } | 105 } |
| 105 | 106 |
| 106 VideoPacketFormat::Encoding DecoderVp8::Encoding() { | 107 VideoPacketFormat::Encoding VideoDecoderVp8::Encoding() { |
| 107 return VideoPacketFormat::ENCODING_VP8; | 108 return VideoPacketFormat::ENCODING_VP8; |
| 108 } | 109 } |
| 109 | 110 |
| 110 void DecoderVp8::Invalidate(const SkISize& view_size, | 111 void VideoDecoderVp8::Invalidate(const SkISize& view_size, |
| 111 const SkRegion& region) { | 112 const SkRegion& region) { |
| 112 DCHECK_EQ(kReady, state_); | 113 DCHECK_EQ(kReady, state_); |
| 113 DCHECK(!view_size.isEmpty()); | 114 DCHECK(!view_size.isEmpty()); |
| 114 | 115 |
| 115 for (SkRegion::Iterator i(region); !i.done(); i.next()) { | 116 for (SkRegion::Iterator i(region); !i.done(); i.next()) { |
| 116 SkIRect rect = i.rect(); | 117 SkIRect rect = i.rect(); |
| 117 rect = ScaleRect(rect, view_size, screen_size_); | 118 rect = ScaleRect(rect, view_size, screen_size_); |
| 118 updated_region_.op(rect, SkRegion::kUnion_Op); | 119 updated_region_.op(rect, SkRegion::kUnion_Op); |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 | 122 |
| 122 void DecoderVp8::RenderFrame(const SkISize& view_size, | 123 void VideoDecoderVp8::RenderFrame(const SkISize& view_size, |
| 123 const SkIRect& clip_area, | 124 const SkIRect& clip_area, |
| 124 uint8* image_buffer, | 125 uint8* image_buffer, |
| 125 int image_stride, | 126 int image_stride, |
| 126 SkRegion* output_region) { | 127 SkRegion* output_region) { |
| 127 DCHECK_EQ(kReady, state_); | 128 DCHECK_EQ(kReady, state_); |
| 128 DCHECK(!view_size.isEmpty()); | 129 DCHECK(!view_size.isEmpty()); |
| 129 | 130 |
| 130 // Early-return and do nothing if we haven't yet decoded any frames. | 131 // Early-return and do nothing if we haven't yet decoded any frames. |
| 131 if (!last_image_) | 132 if (!last_image_) |
| 132 return; | 133 return; |
| 133 | 134 |
| 134 SkIRect source_clip = SkIRect::MakeWH(last_image_->d_w, last_image_->d_h); | 135 SkIRect source_clip = SkIRect::MakeWH(last_image_->d_w, last_image_->d_h); |
| 135 | 136 |
| 136 // ScaleYUVToRGB32WithRect does not currently support up-scaling. We won't | 137 // ScaleYUVToRGB32WithRect does not currently support up-scaling. We won't |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 rect); | 203 rect); |
| 203 | 204 |
| 204 output_region->op(rect, SkRegion::kUnion_Op); | 205 output_region->op(rect, SkRegion::kUnion_Op); |
| 205 } | 206 } |
| 206 | 207 |
| 207 updated_region_.op(ScaleRect(clip_area, view_size, screen_size_), | 208 updated_region_.op(ScaleRect(clip_area, view_size, screen_size_), |
| 208 SkRegion::kDifference_Op); | 209 SkRegion::kDifference_Op); |
| 209 } | 210 } |
| 210 | 211 |
| 211 } // namespace remoting | 212 } // namespace remoting |
| OLD | NEW |