OLD | NEW |
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/encoder_vp8.h" | 5 #include "remoting/base/encoder_vp8.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/base/callback.h" | 8 #include "media/base/callback.h" |
9 #include "media/base/yuv_convert.h" | 9 #include "media/base/yuv_convert.h" |
10 #include "remoting/base/capture_data.h" | 10 #include "remoting/base/capture_data.h" |
11 #include "remoting/base/util.h" | 11 #include "remoting/base/util.h" |
12 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
13 #include "third_party/skia/include/core/SkRegion.h" | |
14 | 13 |
15 extern "C" { | 14 extern "C" { |
16 #define VPX_CODEC_DISABLE_COMPAT 1 | 15 #define VPX_CODEC_DISABLE_COMPAT 1 |
17 #include "third_party/libvpx/libvpx.h" | 16 #include "third_party/libvpx/libvpx.h" |
18 } | 17 } |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // Defines the dimension of a macro block. This is used to compute the active | 21 // Defines the dimension of a macro block. This is used to compute the active |
23 // map for the encoder. | 22 // map for the encoder. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 141 } |
143 | 142 |
144 bool EncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, | 143 bool EncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, |
145 std::vector<gfx::Rect>* updated_rects) { | 144 std::vector<gfx::Rect>* updated_rects) { |
146 // Perform RGB->YUV conversion. | 145 // Perform RGB->YUV conversion. |
147 if (capture_data->pixel_format() != media::VideoFrame::RGB32) { | 146 if (capture_data->pixel_format() != media::VideoFrame::RGB32) { |
148 LOG(ERROR) << "Only RGB32 is supported"; | 147 LOG(ERROR) << "Only RGB32 is supported"; |
149 return false; | 148 return false; |
150 } | 149 } |
151 | 150 |
152 const SkRegion& region = capture_data->dirty_region(); | 151 const InvalidRects& rects = capture_data->dirty_rects(); |
153 const uint8* in = capture_data->data_planes().data[0]; | 152 const uint8* in = capture_data->data_planes().data[0]; |
154 const int in_stride = capture_data->data_planes().strides[0]; | 153 const int in_stride = capture_data->data_planes().strides[0]; |
155 const int plane_size = | 154 const int plane_size = |
156 capture_data->size().width() * capture_data->size().height(); | 155 capture_data->size().width() * capture_data->size().height(); |
157 uint8* y_out = yuv_image_.get(); | 156 uint8* y_out = yuv_image_.get(); |
158 uint8* u_out = yuv_image_.get() + plane_size; | 157 uint8* u_out = yuv_image_.get() + plane_size; |
159 uint8* v_out = yuv_image_.get() + plane_size + plane_size / 4; | 158 uint8* v_out = yuv_image_.get() + plane_size + plane_size / 4; |
160 const int y_stride = image_->stride[0]; | 159 const int y_stride = image_->stride[0]; |
161 const int uv_stride = image_->stride[1]; | 160 const int uv_stride = image_->stride[1]; |
162 | 161 |
163 DCHECK(updated_rects->empty()); | 162 DCHECK(updated_rects->empty()); |
164 for (SkRegion::Iterator r(region); !r.done(); r.next()) { | 163 for (InvalidRects::const_iterator r = rects.begin(); r != rects.end(); ++r) { |
165 // Align the rectangle, report it as updated. | 164 // Align the rectangle, report it as updated. |
166 SkIRect skRect = r.rect(); | 165 gfx::Rect rect = AlignAndClipRect(*r, image_->w, image_->h); |
167 gfx::Rect rect(skRect.fLeft, skRect.fTop, skRect.width(), skRect.height()); | |
168 rect = AlignAndClipRect(rect, image_->w, image_->h); | |
169 if (!rect.IsEmpty()) | 166 if (!rect.IsEmpty()) |
170 updated_rects->push_back(rect); | 167 updated_rects->push_back(rect); |
171 | 168 |
172 ConvertRGB32ToYUVWithRect(in, | 169 ConvertRGB32ToYUVWithRect(in, |
173 y_out, | 170 y_out, |
174 u_out, | 171 u_out, |
175 v_out, | 172 v_out, |
176 rect.x(), | 173 rect.x(), |
177 rect.y(), | 174 rect.y(), |
178 rect.width(), | 175 rect.width(), |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 rect->set_y(updated_rects[i].y()); | 284 rect->set_y(updated_rects[i].y()); |
288 rect->set_width(updated_rects[i].width()); | 285 rect->set_width(updated_rects[i].width()); |
289 rect->set_height(updated_rects[i].height()); | 286 rect->set_height(updated_rects[i].height()); |
290 } | 287 } |
291 | 288 |
292 data_available_callback->Run(message); | 289 data_available_callback->Run(message); |
293 delete data_available_callback; | 290 delete data_available_callback; |
294 } | 291 } |
295 | 292 |
296 } // namespace remoting | 293 } // namespace remoting |
OLD | NEW |