| 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_encoder_vp8.h" | 5 #include "remoting/codec/video_encoder_vp8.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "media/base/yuv_convert.h" | 10 #include "media/base/yuv_convert.h" |
| 11 #include "media/video/capture/screen/screen_capture_data.h" |
| 11 #include "remoting/base/util.h" | 12 #include "remoting/base/util.h" |
| 12 #include "remoting/capturer/capture_data.h" | |
| 13 #include "remoting/proto/video.pb.h" | 13 #include "remoting/proto/video.pb.h" |
| 14 | 14 |
| 15 extern "C" { | 15 extern "C" { |
| 16 #define VPX_CODEC_DISABLE_COMPAT 1 | 16 #define VPX_CODEC_DISABLE_COMPAT 1 |
| 17 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" | 17 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" |
| 18 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" | 18 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h" |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (vpx_codec_control(codec_.get(), VP8E_SET_CPUUSED, 16)) | 139 if (vpx_codec_control(codec_.get(), VP8E_SET_CPUUSED, 16)) |
| 140 return false; | 140 return false; |
| 141 | 141 |
| 142 // Use the lowest level of noise sensitivity so as to spend less time | 142 // Use the lowest level of noise sensitivity so as to spend less time |
| 143 // on motion estimation and inter-prediction mode. | 143 // on motion estimation and inter-prediction mode. |
| 144 if (vpx_codec_control(codec_.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) | 144 if (vpx_codec_control(codec_.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) |
| 145 return false; | 145 return false; |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void VideoEncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data, | 149 void VideoEncoderVp8::PrepareImage( |
| 150 SkRegion* updated_region) { | 150 scoped_refptr<media::ScreenCaptureData> capture_data, |
| 151 SkRegion* updated_region) { |
| 151 const SkRegion& region = capture_data->dirty_region(); | 152 const SkRegion& region = capture_data->dirty_region(); |
| 152 if (region.isEmpty()) { | 153 if (region.isEmpty()) { |
| 153 updated_region->setEmpty(); | 154 updated_region->setEmpty(); |
| 154 return; | 155 return; |
| 155 } | 156 } |
| 156 | 157 |
| 157 // Align the region to macroblocks, to avoid encoding artefacts. | 158 // Align the region to macroblocks, to avoid encoding artefacts. |
| 158 // This also ensures that all rectangles have even-aligned top-left, which | 159 // This also ensures that all rectangles have even-aligned top-left, which |
| 159 // is required for ConvertRGBToYUVWithRect() to work. | 160 // is required for ConvertRGBToYUVWithRect() to work. |
| 160 std::vector<SkIRect> aligned_rects; | 161 std::vector<SkIRect> aligned_rects; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 uint8* map = active_map_.get() + top * active_map_width_; | 206 uint8* map = active_map_.get() + top * active_map_width_; |
| 206 for (int y = top; y <= bottom; ++y) { | 207 for (int y = top; y <= bottom; ++y) { |
| 207 for (int x = left; x <= right; ++x) | 208 for (int x = left; x <= right; ++x) |
| 208 map[x] = 1; | 209 map[x] = 1; |
| 209 map += active_map_width_; | 210 map += active_map_width_; |
| 210 } | 211 } |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 | 214 |
| 214 void VideoEncoderVp8::Encode( | 215 void VideoEncoderVp8::Encode( |
| 215 scoped_refptr<CaptureData> capture_data, | 216 scoped_refptr<media::ScreenCaptureData> capture_data, |
| 216 bool key_frame, | 217 bool key_frame, |
| 217 const DataAvailableCallback& data_available_callback) { | 218 const DataAvailableCallback& data_available_callback) { |
| 218 DCHECK_LE(32, capture_data->size().width()); | 219 DCHECK_LE(32, capture_data->size().width()); |
| 219 DCHECK_LE(32, capture_data->size().height()); | 220 DCHECK_LE(32, capture_data->size().height()); |
| 220 | 221 |
| 221 base::Time encode_start_time = base::Time::Now(); | 222 base::Time encode_start_time = base::Time::Now(); |
| 222 | 223 |
| 223 if (!initialized_ || | 224 if (!initialized_ || |
| 224 (capture_data->size() != SkISize::Make(image_->w, image_->h))) { | 225 (capture_data->size() != SkISize::Make(image_->w, image_->h))) { |
| 225 bool ret = Init(capture_data->size()); | 226 bool ret = Init(capture_data->size()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 rect->set_x(r.rect().x()); | 302 rect->set_x(r.rect().x()); |
| 302 rect->set_y(r.rect().y()); | 303 rect->set_y(r.rect().y()); |
| 303 rect->set_width(r.rect().width()); | 304 rect->set_width(r.rect().width()); |
| 304 rect->set_height(r.rect().height()); | 305 rect->set_height(r.rect().height()); |
| 305 } | 306 } |
| 306 | 307 |
| 307 data_available_callback.Run(packet.Pass()); | 308 data_available_callback.Run(packet.Pass()); |
| 308 } | 309 } |
| 309 | 310 |
| 310 } // namespace remoting | 311 } // namespace remoting |
| OLD | NEW |