Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: remoting/codec/video_encoder_vp8.cc

Issue 23477059: Simplify VideoEncoder interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/time.h" 9 #include "base/time/time.h"
10 #include "media/base/yuv_convert.h" 10 #include "media/base/yuv_convert.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (vpx_codec_control(codec_.get(), VP8E_SET_CPUUSED, 16)) 137 if (vpx_codec_control(codec_.get(), VP8E_SET_CPUUSED, 16))
138 return false; 138 return false;
139 139
140 // Use the lowest level of noise sensitivity so as to spend less time 140 // Use the lowest level of noise sensitivity so as to spend less time
141 // on motion estimation and inter-prediction mode. 141 // on motion estimation and inter-prediction mode.
142 if (vpx_codec_control(codec_.get(), VP8E_SET_NOISE_SENSITIVITY, 0)) 142 if (vpx_codec_control(codec_.get(), VP8E_SET_NOISE_SENSITIVITY, 0))
143 return false; 143 return false;
144 return true; 144 return true;
145 } 145 }
146 146
147 void VideoEncoderVp8::PrepareImage(const webrtc::DesktopFrame* frame, 147 void VideoEncoderVp8::PrepareImage(const webrtc::DesktopFrame& frame,
148 SkRegion* updated_region) { 148 SkRegion* updated_region) {
149 if (frame->updated_region().is_empty()) { 149 if (frame.updated_region().is_empty()) {
150 updated_region->setEmpty(); 150 updated_region->setEmpty();
151 return; 151 return;
152 } 152 }
153 153
154 // Align the region to macroblocks, to avoid encoding artefacts. 154 // Align the region to macroblocks, to avoid encoding artefacts.
155 // This also ensures that all rectangles have even-aligned top-left, which 155 // This also ensures that all rectangles have even-aligned top-left, which
156 // is required for ConvertRGBToYUVWithRect() to work. 156 // is required for ConvertRGBToYUVWithRect() to work.
157 std::vector<SkIRect> aligned_rects; 157 std::vector<SkIRect> aligned_rects;
158 for (webrtc::DesktopRegion::Iterator r(frame->updated_region()); 158 for (webrtc::DesktopRegion::Iterator r(frame.updated_region());
159 !r.IsAtEnd(); r.Advance()) { 159 !r.IsAtEnd(); r.Advance()) {
160 const webrtc::DesktopRect& rect = r.rect(); 160 const webrtc::DesktopRect& rect = r.rect();
161 aligned_rects.push_back(AlignRect( 161 aligned_rects.push_back(AlignRect(
162 SkIRect::MakeLTRB(rect.left(), rect.top(), rect.right(), rect.bottom()))); 162 SkIRect::MakeLTRB(rect.left(), rect.top(), rect.right(), rect.bottom())));
163 } 163 }
164 DCHECK(!aligned_rects.empty()); 164 DCHECK(!aligned_rects.empty());
165 updated_region->setRects(&aligned_rects[0], aligned_rects.size()); 165 updated_region->setRects(&aligned_rects[0], aligned_rects.size());
166 166
167 // Clip back to the screen dimensions, in case they're not macroblock aligned. 167 // Clip back to the screen dimensions, in case they're not macroblock aligned.
168 // The conversion routines don't require even width & height, so this is safe 168 // The conversion routines don't require even width & height, so this is safe
169 // even if the source dimensions are not even. 169 // even if the source dimensions are not even.
170 updated_region->op(SkIRect::MakeWH(image_->w, image_->h), 170 updated_region->op(SkIRect::MakeWH(image_->w, image_->h),
171 SkRegion::kIntersect_Op); 171 SkRegion::kIntersect_Op);
172 172
173 // Convert the updated region to YUV ready for encoding. 173 // Convert the updated region to YUV ready for encoding.
174 const uint8* rgb_data = frame->data(); 174 const uint8* rgb_data = frame.data();
175 const int rgb_stride = frame->stride(); 175 const int rgb_stride = frame.stride();
176 const int y_stride = image_->stride[0]; 176 const int y_stride = image_->stride[0];
177 DCHECK_EQ(image_->stride[1], image_->stride[2]); 177 DCHECK_EQ(image_->stride[1], image_->stride[2]);
178 const int uv_stride = image_->stride[1]; 178 const int uv_stride = image_->stride[1];
179 uint8* y_data = image_->planes[0]; 179 uint8* y_data = image_->planes[0];
180 uint8* u_data = image_->planes[1]; 180 uint8* u_data = image_->planes[1];
181 uint8* v_data = image_->planes[2]; 181 uint8* v_data = image_->planes[2];
182 for (SkRegion::Iterator r(*updated_region); !r.done(); r.next()) { 182 for (SkRegion::Iterator r(*updated_region); !r.done(); r.next()) {
183 const SkIRect& rect = r.rect(); 183 const SkIRect& rect = r.rect();
184 ConvertRGB32ToYUVWithRect( 184 ConvertRGB32ToYUVWithRect(
185 rgb_data, y_data, u_data, v_data, 185 rgb_data, y_data, u_data, v_data,
(...skipping 18 matching lines...) Expand all
204 204
205 uint8* map = active_map_.get() + top * active_map_width_; 205 uint8* map = active_map_.get() + top * active_map_width_;
206 for (int y = top; y <= bottom; ++y) { 206 for (int y = top; y <= bottom; ++y) {
207 for (int x = left; x <= right; ++x) 207 for (int x = left; x <= right; ++x)
208 map[x] = 1; 208 map[x] = 1;
209 map += active_map_width_; 209 map += active_map_width_;
210 } 210 }
211 } 211 }
212 } 212 }
213 213
214 void VideoEncoderVp8::Encode( 214 scoped_ptr<VideoPacket> VideoEncoderVp8::Encode(
215 const webrtc::DesktopFrame* frame, 215 const webrtc::DesktopFrame& frame) {
216 const DataAvailableCallback& data_available_callback) { 216 DCHECK_LE(32, frame.size().width());
217 DCHECK_LE(32, frame->size().width()); 217 DCHECK_LE(32, frame.size().height());
218 DCHECK_LE(32, frame->size().height());
219 218
220 base::Time encode_start_time = base::Time::Now(); 219 base::Time encode_start_time = base::Time::Now();
221 220
222 if (!initialized_ || 221 if (!initialized_ ||
223 !frame->size().equals(webrtc::DesktopSize(image_->w, image_->h))) { 222 !frame.size().equals(webrtc::DesktopSize(image_->w, image_->h))) {
224 bool ret = Init(frame->size()); 223 bool ret = Init(frame.size());
225 // TODO(hclam): Handle error better. 224 // TODO(hclam): Handle error better.
226 CHECK(ret) << "Initialization of encoder failed"; 225 CHECK(ret) << "Initialization of encoder failed";
227 initialized_ = ret; 226 initialized_ = ret;
228 } 227 }
229 228
230 // Convert the updated capture data ready for encode. 229 // Convert the updated capture data ready for encode.
231 SkRegion updated_region; 230 SkRegion updated_region;
232 PrepareImage(frame, &updated_region); 231 PrepareImage(frame, &updated_region);
233 232
234 // Update active map based on updated region. 233 // Update active map based on updated region.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 break; 276 break;
278 default: 277 default:
279 break; 278 break;
280 } 279 }
281 } 280 }
282 281
283 // Construct the VideoPacket message. 282 // Construct the VideoPacket message.
284 packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); 283 packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8);
285 packet->set_flags(VideoPacket::FIRST_PACKET | VideoPacket::LAST_PACKET | 284 packet->set_flags(VideoPacket::FIRST_PACKET | VideoPacket::LAST_PACKET |
286 VideoPacket::LAST_PARTITION); 285 VideoPacket::LAST_PARTITION);
287 packet->mutable_format()->set_screen_width(frame->size().width()); 286 packet->mutable_format()->set_screen_width(frame.size().width());
288 packet->mutable_format()->set_screen_height(frame->size().height()); 287 packet->mutable_format()->set_screen_height(frame.size().height());
289 packet->set_capture_time_ms(frame->capture_time_ms()); 288 packet->set_capture_time_ms(frame.capture_time_ms());
290 packet->set_encode_time_ms( 289 packet->set_encode_time_ms(
291 (base::Time::Now() - encode_start_time).InMillisecondsRoundedUp()); 290 (base::Time::Now() - encode_start_time).InMillisecondsRoundedUp());
292 if (!frame->dpi().is_zero()) { 291 if (!frame.dpi().is_zero()) {
293 packet->mutable_format()->set_x_dpi(frame->dpi().x()); 292 packet->mutable_format()->set_x_dpi(frame.dpi().x());
294 packet->mutable_format()->set_y_dpi(frame->dpi().y()); 293 packet->mutable_format()->set_y_dpi(frame.dpi().y());
295 } 294 }
296 for (SkRegion::Iterator r(updated_region); !r.done(); r.next()) { 295 for (SkRegion::Iterator r(updated_region); !r.done(); r.next()) {
297 Rect* rect = packet->add_dirty_rects(); 296 Rect* rect = packet->add_dirty_rects();
298 rect->set_x(r.rect().x()); 297 rect->set_x(r.rect().x());
299 rect->set_y(r.rect().y()); 298 rect->set_y(r.rect().y());
300 rect->set_width(r.rect().width()); 299 rect->set_width(r.rect().width());
301 rect->set_height(r.rect().height()); 300 rect->set_height(r.rect().height());
302 } 301 }
303 302
304 data_available_callback.Run(packet.Pass()); 303 return packet.Pass();
305 } 304 }
306 305
307 } // namespace remoting 306 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698