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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 codec_.get(), image_.get(), timestamp, 1, 0, VPX_DL_REALTIME); | 279 codec_.get(), image_.get(), timestamp, 1, 0, VPX_DL_REALTIME); |
280 DCHECK_EQ(ret, VPX_CODEC_OK) | 280 DCHECK_EQ(ret, VPX_CODEC_OK) |
281 << "Encoding error: " << vpx_codec_err_to_string(ret) << "\n" | 281 << "Encoding error: " << vpx_codec_err_to_string(ret) << "\n" |
282 << "Details: " << vpx_codec_error(codec_.get()) << "\n" | 282 << "Details: " << vpx_codec_error(codec_.get()) << "\n" |
283 << vpx_codec_error_detail(codec_.get()); | 283 << vpx_codec_error_detail(codec_.get()); |
284 | 284 |
285 // Read the encoded data. | 285 // Read the encoded data. |
286 vpx_codec_iter_t iter = NULL; | 286 vpx_codec_iter_t iter = NULL; |
287 bool got_data = false; | 287 bool got_data = false; |
288 | 288 |
289 // TODO(hclam): Make sure we get exactly one frame from the packet. | 289 // TODO(hclam): Make sure we get exactly one frame from the packet. |
Sergey Ulanov
2014/09/03 01:11:25
this TODO can be removed
| |
290 // TODO(hclam): We should provide the output buffer to avoid one copy. | 290 // TODO(hclam): We should provide the output buffer to avoid one copy. |
291 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 291 scoped_ptr<VideoPacket> packet( |
292 helper_.CreateVideoPacketWithUpdatedRegion(frame, updated_region)); | |
293 packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); | |
292 | 294 |
293 while (!got_data) { | 295 while (!got_data) { |
294 const vpx_codec_cx_pkt_t* vpx_packet = | 296 const vpx_codec_cx_pkt_t* vpx_packet = |
295 vpx_codec_get_cx_data(codec_.get(), &iter); | 297 vpx_codec_get_cx_data(codec_.get(), &iter); |
296 if (!vpx_packet) | 298 if (!vpx_packet) |
297 continue; | 299 continue; |
298 | 300 |
299 switch (vpx_packet->kind) { | 301 switch (vpx_packet->kind) { |
300 case VPX_CODEC_CX_FRAME_PKT: | 302 case VPX_CODEC_CX_FRAME_PKT: |
301 got_data = true; | 303 got_data = true; |
302 packet->set_data(vpx_packet->data.frame.buf, vpx_packet->data.frame.sz); | 304 packet->set_data(vpx_packet->data.frame.buf, vpx_packet->data.frame.sz); |
303 break; | 305 break; |
304 default: | 306 default: |
305 break; | 307 break; |
306 } | 308 } |
307 } | 309 } |
308 | 310 |
309 // Construct the VideoPacket message. | 311 // Note the time taken to encode the pixel data. |
310 packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); | |
311 packet->mutable_format()->set_screen_width(frame.size().width()); | |
312 packet->mutable_format()->set_screen_height(frame.size().height()); | |
313 packet->set_capture_time_ms(frame.capture_time_ms()); | |
314 packet->set_encode_time_ms( | 312 packet->set_encode_time_ms( |
315 (base::TimeTicks::Now() - encode_start_time).InMillisecondsRoundedUp()); | 313 (base::TimeTicks::Now() - encode_start_time).InMillisecondsRoundedUp()); |
316 if (!frame.dpi().is_zero()) { | |
317 packet->mutable_format()->set_x_dpi(frame.dpi().x()); | |
318 packet->mutable_format()->set_y_dpi(frame.dpi().y()); | |
319 } | |
320 for (webrtc::DesktopRegion::Iterator r(updated_region); !r.IsAtEnd(); | |
321 r.Advance()) { | |
322 Rect* rect = packet->add_dirty_rects(); | |
323 rect->set_x(r.rect().left()); | |
324 rect->set_y(r.rect().top()); | |
325 rect->set_width(r.rect().width()); | |
326 rect->set_height(r.rect().height()); | |
327 } | |
328 | 314 |
329 return packet.Pass(); | 315 return packet.Pass(); |
330 } | 316 } |
331 | 317 |
332 VideoEncoderVpx::VideoEncoderVpx(bool use_vp9) | 318 VideoEncoderVpx::VideoEncoderVpx(bool use_vp9) |
333 : use_vp9_(use_vp9), | 319 : use_vp9_(use_vp9), |
334 lossless_encode_(false), | 320 lossless_encode_(false), |
335 lossless_color_(false), | 321 lossless_color_(false), |
336 active_map_width_(0), | 322 active_map_width_(0), |
337 active_map_height_(0) { | 323 active_map_height_(0) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 uint8* map = active_map_.get() + top * active_map_width_; | 445 uint8* map = active_map_.get() + top * active_map_width_; |
460 for (int y = top; y <= bottom; ++y) { | 446 for (int y = top; y <= bottom; ++y) { |
461 for (int x = left; x <= right; ++x) | 447 for (int x = left; x <= right; ++x) |
462 map[x] = 1; | 448 map[x] = 1; |
463 map += active_map_width_; | 449 map += active_map_width_; |
464 } | 450 } |
465 } | 451 } |
466 } | 452 } |
467 | 453 |
468 } // namespace remoting | 454 } // namespace remoting |
OLD | NEW |