OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_vpx.h" | 5 #include "remoting/codec/video_encoder_vpx.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 return ScopedVpxCodec(); | 70 return ScopedVpxCodec(); |
71 | 71 |
72 // Use the lowest level of noise sensitivity so as to spend less time | 72 // Use the lowest level of noise sensitivity so as to spend less time |
73 // on motion estimation and inter-prediction mode. | 73 // on motion estimation and inter-prediction mode. |
74 if (vpx_codec_control(codec.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) | 74 if (vpx_codec_control(codec.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) |
75 return ScopedVpxCodec(); | 75 return ScopedVpxCodec(); |
76 | 76 |
77 return codec.Pass(); | 77 return codec.Pass(); |
78 } | 78 } |
79 | 79 |
| 80 ScopedVpxCodec CreateVP9Codec(const webrtc::DesktopSize& size) { |
| 81 ScopedVpxCodec codec(new vpx_codec_ctx_t); |
| 82 |
| 83 // Configure the encoder. |
| 84 vpx_codec_enc_cfg_t config; |
| 85 const vpx_codec_iface_t* algo = vpx_codec_vp9_cx(); |
| 86 CHECK(algo); |
| 87 vpx_codec_err_t ret = vpx_codec_enc_config_default(algo, &config, 0); |
| 88 if (ret != VPX_CODEC_OK) |
| 89 return ScopedVpxCodec(); |
| 90 |
| 91 //config.rc_target_bitrate = size.width() * size.height() * |
| 92 // config.rc_target_bitrate / config.g_w / config.g_h; |
| 93 config.g_w = size.width(); |
| 94 config.g_h = size.height(); |
| 95 config.g_pass = VPX_RC_ONE_PASS; |
| 96 |
| 97 // Only the default profile is currently supported for VP9 encoding. |
| 98 config.g_profile = 0; |
| 99 |
| 100 // Start emitting packets immediately. |
| 101 config.g_lag_in_frames = 0; |
| 102 |
| 103 // Prevent VP9 from ruining output quality with quantization. |
| 104 config.rc_max_quantizer = 0; |
| 105 |
| 106 if (vpx_codec_enc_init(codec.get(), algo, &config, 0)) |
| 107 return ScopedVpxCodec(); |
| 108 |
| 109 // VP9 encode doesn't yet support Realtime, so falls back to Good quality, |
| 110 // for which 4 is the lowest CPU usage. |
| 111 // Note that this is configured via the same parameter as for VP8. |
| 112 if (vpx_codec_control(codec.get(), VP8E_SET_CPUUSED, 4)) |
| 113 return ScopedVpxCodec(); |
| 114 |
| 115 // Use the lowest level of noise sensitivity so as to spend less time |
| 116 // on motion estimation and inter-prediction mode. |
| 117 // Note that this is configured via the same parameter as for VP8. |
| 118 if (vpx_codec_control(codec.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) |
| 119 return ScopedVpxCodec(); |
| 120 |
| 121 return codec.Pass(); |
| 122 } |
| 123 |
80 } // namespace | 124 } // namespace |
81 | 125 |
82 // static | 126 // static |
83 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP8() { | 127 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP8() { |
84 return scoped_ptr<VideoEncoderVpx>( | 128 return scoped_ptr<VideoEncoderVpx>( |
85 new VideoEncoderVpx(base::Bind(&CreateVP8Codec))); | 129 new VideoEncoderVpx(base::Bind(&CreateVP8Codec))); |
86 } | 130 } |
87 | 131 |
| 132 // static |
| 133 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP9() { |
| 134 return scoped_ptr<VideoEncoderVpx>( |
| 135 new VideoEncoderVpx(base::Bind(&CreateVP9Codec))); |
| 136 } |
| 137 |
88 VideoEncoderVpx::~VideoEncoderVpx() {} | 138 VideoEncoderVpx::~VideoEncoderVpx() {} |
89 | 139 |
90 scoped_ptr<VideoPacket> VideoEncoderVpx::Encode( | 140 scoped_ptr<VideoPacket> VideoEncoderVpx::Encode( |
91 const webrtc::DesktopFrame& frame) { | 141 const webrtc::DesktopFrame& frame) { |
92 DCHECK_LE(32, frame.size().width()); | 142 DCHECK_LE(32, frame.size().width()); |
93 DCHECK_LE(32, frame.size().height()); | 143 DCHECK_LE(32, frame.size().height()); |
94 | 144 |
95 base::Time encode_start_time = base::Time::Now(); | 145 base::Time encode_start_time = base::Time::Now(); |
96 | 146 |
97 if (!codec_ || | 147 if (!codec_ || |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 uint8* map = active_map_.get() + top * active_map_width_; | 362 uint8* map = active_map_.get() + top * active_map_width_; |
313 for (int y = top; y <= bottom; ++y) { | 363 for (int y = top; y <= bottom; ++y) { |
314 for (int x = left; x <= right; ++x) | 364 for (int x = left; x <= right; ++x) |
315 map[x] = 1; | 365 map[x] = 1; |
316 map += active_map_width_; | 366 map += active_map_width_; |
317 } | 367 } |
318 } | 368 } |
319 } | 369 } |
320 | 370 |
321 } // namespace remoting | 371 } // namespace remoting |
OLD | NEW |