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 | |
124 } // namespace | 80 } // namespace |
125 | 81 |
126 // static | 82 // static |
127 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP8() { | 83 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP8() { |
128 return scoped_ptr<VideoEncoderVpx>( | 84 return scoped_ptr<VideoEncoderVpx>( |
129 new VideoEncoderVpx(base::Bind(&CreateVP8Codec))); | 85 new VideoEncoderVpx(base::Bind(&CreateVP8Codec))); |
130 } | 86 } |
131 | 87 |
132 // static | |
133 scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP9() { | |
134 return scoped_ptr<VideoEncoderVpx>( | |
135 new VideoEncoderVpx(base::Bind(&CreateVP9Codec))); | |
136 } | |
137 | |
138 VideoEncoderVpx::~VideoEncoderVpx() {} | 88 VideoEncoderVpx::~VideoEncoderVpx() {} |
139 | 89 |
140 scoped_ptr<VideoPacket> VideoEncoderVpx::Encode( | 90 scoped_ptr<VideoPacket> VideoEncoderVpx::Encode( |
141 const webrtc::DesktopFrame& frame) { | 91 const webrtc::DesktopFrame& frame) { |
142 DCHECK_LE(32, frame.size().width()); | 92 DCHECK_LE(32, frame.size().width()); |
143 DCHECK_LE(32, frame.size().height()); | 93 DCHECK_LE(32, frame.size().height()); |
144 | 94 |
145 base::Time encode_start_time = base::Time::Now(); | 95 base::Time encode_start_time = base::Time::Now(); |
146 | 96 |
147 if (!codec_ || | 97 if (!codec_ || |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 uint8* map = active_map_.get() + top * active_map_width_; | 312 uint8* map = active_map_.get() + top * active_map_width_; |
363 for (int y = top; y <= bottom; ++y) { | 313 for (int y = top; y <= bottom; ++y) { |
364 for (int x = left; x <= right; ++x) | 314 for (int x = left; x <= right; ++x) |
365 map[x] = 1; | 315 map[x] = 1; |
366 map += active_map_width_; | 316 map += active_map_width_; |
367 } | 317 } |
368 } | 318 } |
369 } | 319 } |
370 | 320 |
371 } // namespace remoting | 321 } // namespace remoting |
OLD | NEW |