Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: remoting/base/decoder_vp8.cc

Issue 8985007: Refactoring of the client-side input pipeline and scaling dimension management. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/decoder_vp8.h" 5 #include "remoting/base/decoder_vp8.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/media.h" 8 #include "media/base/media.h"
9 #include "media/base/yuv_convert.h" 9 #include "media/base/yuv_convert.h"
10 #include "remoting/base/util.h" 10 #include "remoting/base/util.h"
11 11
12 extern "C" { 12 extern "C" {
13 #define VPX_CODEC_DISABLE_COMPAT 1 13 #define VPX_CODEC_DISABLE_COMPAT 1
14 #include "third_party/libvpx/libvpx.h" 14 #include "third_party/libvpx/libvpx.h"
15 } 15 }
16 16
17 namespace remoting { 17 namespace remoting {
18 18
19 DecoderVp8::DecoderVp8() 19 DecoderVp8::DecoderVp8()
20 : state_(kUninitialized), 20 : state_(kUninitialized),
21 codec_(NULL), 21 codec_(NULL),
22 last_image_(NULL), 22 last_image_(NULL),
23 clip_rect_(SkIRect::MakeEmpty()), 23 clip_rect_(SkIRect::MakeEmpty()) {
24 horizontal_scale_ratio_(1.0), 24 output_size_.setEmpty();
Sergey Ulanov 2011/12/20 00:05:35 Can we initialize output_size_ in the same way cli
Wez 2011/12/20 07:14:14 Done.
25 vertical_scale_ratio_(1.0) {
26 } 25 }
27 26
28 DecoderVp8::~DecoderVp8() { 27 DecoderVp8::~DecoderVp8() {
29 if (codec_) { 28 if (codec_) {
30 vpx_codec_err_t ret = vpx_codec_destroy(codec_); 29 vpx_codec_err_t ret = vpx_codec_destroy(codec_);
31 CHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec"; 30 CHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec";
32 } 31 }
33 delete codec_; 32 delete codec_;
34 } 33 }
35 34
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 RectVector rects; 93 RectVector rects;
95 rects.reserve(packet->dirty_rects_size()); 94 rects.reserve(packet->dirty_rects_size());
96 for (int i = 0; i < packet->dirty_rects_size(); ++i) { 95 for (int i = 0; i < packet->dirty_rects_size(); ++i) {
97 Rect remoting_rect = packet->dirty_rects(i); 96 Rect remoting_rect = packet->dirty_rects(i);
98 rects.push_back(SkIRect::MakeXYWH(remoting_rect.x(), 97 rects.push_back(SkIRect::MakeXYWH(remoting_rect.x(),
99 remoting_rect.y(), 98 remoting_rect.y(),
100 remoting_rect.width(), 99 remoting_rect.width(),
101 remoting_rect.height())); 100 remoting_rect.height()));
102 } 101 }
103 102
103 // TODO(wez): Fix the rest of the decode pipeline not to assume the frame
104 // size is the host dimensions, since it's not when scaling. If the host
105 // gets smaller, then the output size will be too big and we'll overrun the
106 // frame, so currently we render 1:1 in that case; the app will see the
107 // host size change and resize us if need be.
108 if ((output_size_.width() > static_cast<int>(frame_->width())) ||
109 (output_size_.height() > static_cast<int>(frame_->height()))) {
110 output_size_.set(frame_->width(), frame_->height());
111 }
112
104 if (!DoScaling()) 113 if (!DoScaling())
105 ConvertRects(rects, &updated_rects_); 114 ConvertRects(rects, &updated_rects_);
106 else 115 else
107 ScaleAndConvertRects(rects, &updated_rects_); 116 ScaleAndConvertRects(rects, &updated_rects_);
108 return DECODE_DONE; 117 return DECODE_DONE;
109 } 118 }
110 119
111 void DecoderVp8::GetUpdatedRects(RectVector* rects) { 120 void DecoderVp8::GetUpdatedRects(RectVector* rects) {
112 rects->swap(updated_rects_); 121 rects->swap(updated_rects_);
113 } 122 }
114 123
115 void DecoderVp8::Reset() { 124 void DecoderVp8::Reset() {
116 frame_ = NULL; 125 frame_ = NULL;
117 state_ = kUninitialized; 126 state_ = kUninitialized;
118 } 127 }
119 128
120 bool DecoderVp8::IsReadyForData() { 129 bool DecoderVp8::IsReadyForData() {
121 return state_ == kReady; 130 return state_ == kReady;
122 } 131 }
123 132
124 VideoPacketFormat::Encoding DecoderVp8::Encoding() { 133 VideoPacketFormat::Encoding DecoderVp8::Encoding() {
125 return VideoPacketFormat::ENCODING_VP8; 134 return VideoPacketFormat::ENCODING_VP8;
126 } 135 }
127 136
128 void DecoderVp8::SetScaleRatios(double horizontal_ratio, 137 void DecoderVp8::SetOutputDimensions(const SkISize& size) {
129 double vertical_ratio) { 138 output_size_ = size;
130 // TODO(hclam): Ratio greater than 1.0 is not supported. This is
131 // because we need to reallocate the backing video frame and this
132 // is not implemented yet.
133 if (horizontal_ratio > 1.0 || horizontal_ratio <= 0.0 ||
134 vertical_ratio > 1.0 || vertical_ratio <= 0.0) {
135 return;
136 }
137
138 horizontal_scale_ratio_ = horizontal_ratio;
139 vertical_scale_ratio_ = vertical_ratio;
140 } 139 }
141 140
142 void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { 141 void DecoderVp8::SetClipRect(const SkIRect& clip_rect) {
143 clip_rect_ = clip_rect; 142 clip_rect_ = clip_rect;
144 } 143 }
145 144
146 void DecoderVp8::RefreshRects(const RectVector& rects) { 145 void DecoderVp8::RefreshRects(const RectVector& rects) {
147 if (!DoScaling()) 146 if (!DoScaling())
148 ConvertRects(rects, &updated_rects_); 147 ConvertRects(rects, &updated_rects_);
149 else 148 else
150 ScaleAndConvertRects(rects, &updated_rects_); 149 ScaleAndConvertRects(rects, &updated_rects_);
151 } 150 }
152 151
153 bool DecoderVp8::DoScaling() const { 152 bool DecoderVp8::DoScaling() const {
154 return horizontal_scale_ratio_ != 1.0 || vertical_scale_ratio_ != 1.0; 153 return last_image_ &&
154 !output_size_.equals(last_image_->d_w, last_image_->d_h);
Jamie 2011/12/20 00:51:57 This will change the behaviour if DoScaling is eve
Wez 2011/12/20 07:14:14 DoScaling() determines whether we use the ConvertR
155 } 155 }
156 156
157 void DecoderVp8::ConvertRects(const RectVector& rects, 157 void DecoderVp8::ConvertRects(const RectVector& rects,
158 RectVector* output_rects) { 158 RectVector* output_rects) {
159 if (!last_image_) 159 if (!last_image_)
160 return; 160 return;
161 161
162 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane); 162 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane);
163 const int stride = frame_->stride(media::VideoFrame::kRGBPlane); 163 const int stride = frame_->stride(media::VideoFrame::kRGBPlane);
164 164
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (!last_image_) 198 if (!last_image_)
199 return; 199 return;
200 200
201 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane); 201 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane);
202 const int stride = frame_->stride(media::VideoFrame::kRGBPlane); 202 const int stride = frame_->stride(media::VideoFrame::kRGBPlane);
203 203
204 output_rects->clear(); 204 output_rects->clear();
205 output_rects->reserve(rects.size()); 205 output_rects->reserve(rects.size());
206 for (size_t i = 0; i < rects.size(); ++i) { 206 for (size_t i = 0; i < rects.size(); ++i) {
207 // Round down the image width and height. 207 // Round down the image width and height.
208 int image_width = RoundToTwosMultiple(last_image_->d_w); 208 SkISize image_size;
209 int image_height = RoundToTwosMultiple(last_image_->d_h); 209 image_size.set(RoundToTwosMultiple(last_image_->d_w),
210 RoundToTwosMultiple(last_image_->d_h));
210 211
211 // Clip by the rounded down dimension of the image for safety. 212 // Clip by the rounded down dimension of the image for safety.
212 SkIRect dest_rect = rects[i]; 213 SkIRect dest_rect = rects[i];
213 if (!dest_rect.intersect(SkIRect::MakeWH(image_width, image_height))) 214 if (!dest_rect.intersect(SkIRect::MakeSize(image_size)))
214 continue; 215 continue;
215 216
216 // Align the rectangle to avoid artifacts in color space conversion. 217 // Align the rectangle to avoid artifacts in color space conversion.
217 dest_rect = AlignRect(dest_rect); 218 dest_rect = AlignRect(dest_rect);
218 219
219 SkIRect scaled_rect = ScaleRect(dest_rect, 220 SkIRect scaled_rect = ScaleRect(dest_rect, image_size, output_size_);
220 horizontal_scale_ratio_,
221 vertical_scale_ratio_);
222 221
223 ScaleYUVToRGB32WithRect(last_image_->planes[0], 222 ScaleYUVToRGB32WithRect(last_image_->planes[0],
224 last_image_->planes[1], 223 last_image_->planes[1],
225 last_image_->planes[2], 224 last_image_->planes[2],
226 data_start, 225 data_start,
227 dest_rect, 226 dest_rect,
228 scaled_rect, 227 scaled_rect,
229 last_image_->stride[0], 228 last_image_->stride[0],
230 last_image_->stride[1], 229 last_image_->stride[1],
231 stride); 230 stride);
232 output_rects->push_back(scaled_rect); 231 output_rects->push_back(scaled_rect);
233 } 232 }
234 } 233 }
235 234
236 } // namespace remoting 235 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/decoder_vp8.h ('k') | remoting/base/util.h » ('j') | remoting/base/util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698