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_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 // Value of 2 means using the real time profile. This is basically a | |
98 // redundant option since we explicitly select real time mode when doing | |
99 // encoding. | |
Jamie
2013/10/21 18:15:28
You're not using 2 for VP9. Please update either t
Wez
2013/10/22 01:12:33
Done.
| |
100 config.g_profile = 0; | |
101 | |
102 // Start emitting packets immediately. | |
103 config.g_lag_in_frames = 0; | |
104 | |
105 // Using 2 threads gives a great boost in performance for most systems with | |
106 // adequate processing power. NB: Going to multiple threads on low end | |
107 // windows systems can really hurt performance. | |
108 // http://crbug.com/99179 | |
109 //config.g_threads = (base::SysInfo::NumberOfProcessors() > 2) ? 2 : 1; | |
110 //config.rc_min_quantizer = 20; | |
111 //config.rc_max_quantizer = 30; | |
112 //config.g_timebase.num = 1; | |
113 //config.g_timebase.den = 20; | |
114 | |
115 if (vpx_codec_enc_init(codec.get(), algo, &config, 0)) | |
116 return ScopedVpxCodec(); | |
117 | |
118 // Value of 16 will have the smallest CPU load. This turns off subpixel | |
119 // motion search. | |
Jamie
2013/10/21 18:15:28
You're not using 16 for VP9. Please update either
Wez
2013/10/22 01:12:33
Done.
| |
120 if (vpx_codec_control(codec.get(), VP8E_SET_CPUUSED, 4)) | |
Jamie
2013/10/21 18:15:28
Is this use of a VP8_ constant correct for the VP9
Wez
2013/10/22 01:12:33
Yup. Updated comment to make that explicit.
| |
121 return ScopedVpxCodec(); | |
122 | |
123 // Use the lowest level of noise sensitivity so as to spend less time | |
124 // on motion estimation and inter-prediction mode. | |
125 if (vpx_codec_control(codec.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) | |
126 return ScopedVpxCodec(); | |
127 | |
128 return codec.Pass(); | |
129 } | |
130 | |
80 } // namespace | 131 } // namespace |
81 | 132 |
82 // static | 133 // static |
83 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP8() { | 134 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP8() { |
84 return scoped_ptr<VideoEncoderVpx>( | 135 return scoped_ptr<VideoEncoderVpx>( |
85 new VideoEncoderVpx(base::Bind(&CreateVP8Codec))); | 136 new VideoEncoderVpx(base::Bind(&CreateVP8Codec))); |
86 } | 137 } |
87 | 138 |
139 // static | |
140 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP9() { | |
141 return scoped_ptr<VideoEncoderVpx>( | |
142 new VideoEncoderVpx(base::Bind(&CreateVP9Codec))); | |
143 } | |
144 | |
88 VideoEncoderVpx::~VideoEncoderVpx() {} | 145 VideoEncoderVpx::~VideoEncoderVpx() {} |
89 | 146 |
90 scoped_ptr<VideoPacket> VideoEncoderVpx::Encode( | 147 scoped_ptr<VideoPacket> VideoEncoderVpx::Encode( |
91 const webrtc::DesktopFrame& frame) { | 148 const webrtc::DesktopFrame& frame) { |
92 DCHECK_LE(32, frame.size().width()); | 149 DCHECK_LE(32, frame.size().width()); |
93 DCHECK_LE(32, frame.size().height()); | 150 DCHECK_LE(32, frame.size().height()); |
94 | 151 |
95 base::Time encode_start_time = base::Time::Now(); | 152 base::Time encode_start_time = base::Time::Now(); |
96 | 153 |
97 if (!codec_ || | 154 if (!codec_ || |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 uint8* map = active_map_.get() + top * active_map_width_; | 368 uint8* map = active_map_.get() + top * active_map_width_; |
312 for (int y = top; y <= bottom; ++y) { | 369 for (int y = top; y <= bottom; ++y) { |
313 for (int x = left; x <= right; ++x) | 370 for (int x = left; x <= right; ++x) |
314 map[x] = 1; | 371 map[x] = 1; |
315 map += active_map_width_; | 372 map += active_map_width_; |
316 } | 373 } |
317 } | 374 } |
318 } | 375 } |
319 | 376 |
320 } // namespace remoting | 377 } // namespace remoting |
OLD | NEW |