Chromium Code Reviews| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 CHECK(algo); | 92 CHECK(algo); |
| 93 vpx_codec_err_t ret = vpx_codec_enc_config_default(algo, &config, 0); | 93 vpx_codec_err_t ret = vpx_codec_enc_config_default(algo, &config, 0); |
| 94 if (ret != VPX_CODEC_OK) | 94 if (ret != VPX_CODEC_OK) |
| 95 return false; | 95 return false; |
| 96 | 96 |
| 97 // Initialize active map. | 97 // Initialize active map. |
| 98 active_map_width_ = (size.width() + kMacroBlockSize - 1) / kMacroBlockSize; | 98 active_map_width_ = (size.width() + kMacroBlockSize - 1) / kMacroBlockSize; |
| 99 active_map_height_ = (size.height() + kMacroBlockSize - 1) / kMacroBlockSize; | 99 active_map_height_ = (size.height() + kMacroBlockSize - 1) / kMacroBlockSize; |
| 100 active_map_.reset(new uint8[active_map_width_ * active_map_height_]); | 100 active_map_.reset(new uint8[active_map_width_ * active_map_height_]); |
| 101 | 101 |
| 102 // TODO(hclam): Tune the parameters to better suit the application. | |
| 103 config.rc_target_bitrate = size.width() * size.height() * | 102 config.rc_target_bitrate = size.width() * size.height() * |
| 104 config.rc_target_bitrate / config.g_w / config.g_h; | 103 config.rc_target_bitrate / config.g_w / config.g_h; |
| 105 config.g_w = size.width(); | 104 config.g_w = size.width(); |
| 106 config.g_h = size.height(); | 105 config.g_h = size.height(); |
| 107 config.g_pass = VPX_RC_ONE_PASS; | 106 config.g_pass = VPX_RC_ONE_PASS; |
| 108 config.g_profile = 1; | 107 |
| 109 config.g_threads = 1; | 108 // Value of 2 means using the real time profile. This is basically a |
| 109 // redundant option since we explicitly select real time mode when doing | |
| 110 // encoding. | |
| 111 config.g_profile = 2; | |
|
Wez
2011/06/20 19:55:01
Is the value 2 not defined somewhere as e.g. kVpxR
Alpha Left Google
2011/06/20 20:02:08
The value is not defined in the VP8 API. It basica
| |
| 112 | |
| 113 // Use 2 threads to do encoding. | |
| 114 config.g_threads = 2; | |
|
Wez
2011/06/20 19:55:01
nit: Why use 2, not 3 or 4 or 7? I'd expect a com
Lambros
2011/06/20 20:02:07
Drive-by: I'd also like to know where the numbers
| |
| 110 config.rc_min_quantizer = 20; | 115 config.rc_min_quantizer = 20; |
| 111 config.rc_max_quantizer = 30; | 116 config.rc_max_quantizer = 30; |
| 112 config.g_timebase.num = 1; | 117 config.g_timebase.num = 1; |
| 113 config.g_timebase.den = 20; | 118 config.g_timebase.den = 20; |
| 114 | 119 |
| 115 if (vpx_codec_enc_init(codec_.get(), algo, &config, 0)) | 120 if (vpx_codec_enc_init(codec_.get(), algo, &config, 0)) |
| 116 return false; | 121 return false; |
| 122 | |
| 123 // Value of 16 will have the smallest CPU load. This turns off subpixel | |
| 124 // motion search. | |
| 125 if (vpx_codec_control(codec_.get(), VP8E_SET_CPUUSED, 16)) | |
| 126 return false; | |
| 127 | |
| 128 // Use the lowest level of noise sensitivity so as to spend less time | |
| 129 // on motion estimation and inter-prediction mode. | |
| 130 if (vpx_codec_control(codec_.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) | |
| 131 return false; | |
| 117 return true; | 132 return true; |
| 118 } | 133 } |
| 119 | 134 |
| 120 static int RoundToTwosMultiple(int x) { | 135 static int RoundToTwosMultiple(int x) { |
| 121 return x & (~1); | 136 return x & (~1); |
| 122 } | 137 } |
| 123 | 138 |
| 124 // Align the sides of the rectangle to multiples of 2 (expanding outwards). | 139 // Align the sides of the rectangle to multiples of 2 (expanding outwards). |
| 125 static gfx::Rect AlignRect(const gfx::Rect& rect) { | 140 static gfx::Rect AlignRect(const gfx::Rect& rect) { |
| 126 int x = RoundToTwosMultiple(rect.x()); | 141 int x = RoundToTwosMultiple(rect.x()); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 rect->set_y(updated_rects[i].y()); | 296 rect->set_y(updated_rects[i].y()); |
| 282 rect->set_width(updated_rects[i].width()); | 297 rect->set_width(updated_rects[i].width()); |
| 283 rect->set_height(updated_rects[i].height()); | 298 rect->set_height(updated_rects[i].height()); |
| 284 } | 299 } |
| 285 | 300 |
| 286 data_available_callback->Run(message); | 301 data_available_callback->Run(message); |
| 287 delete data_available_callback; | 302 delete data_available_callback; |
| 288 } | 303 } |
| 289 | 304 |
| 290 } // namespace remoting | 305 } // namespace remoting |
| OLD | NEW |