Chromium Code Reviews| 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 "content/renderer/media/rtc_video_encoder.h" | 5 #include "content/renderer/media/rtc_video_encoder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 return; | 466 return; |
| 467 } | 467 } |
| 468 base::SharedMemory* output_buffer = output_buffers_[bitstream_buffer_id]; | 468 base::SharedMemory* output_buffer = output_buffers_[bitstream_buffer_id]; |
| 469 if (payload_size > output_buffer->mapped_size()) { | 469 if (payload_size > output_buffer->mapped_size()) { |
| 470 LogAndNotifyError(FROM_HERE, "invalid payload_size", | 470 LogAndNotifyError(FROM_HERE, "invalid payload_size", |
| 471 media::VideoEncodeAccelerator::kPlatformFailureError); | 471 media::VideoEncodeAccelerator::kPlatformFailureError); |
| 472 return; | 472 return; |
| 473 } | 473 } |
| 474 output_buffers_free_count_--; | 474 output_buffers_free_count_--; |
| 475 | 475 |
| 476 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). | 476 uint32_t capture_time_ms = 0; |
| 477 // This is based on how input timestamps are calculated in | 477 //if (timestamp.is_zero()) { |
| 478 // webrtc/video/video_capture_input.cc. | 478 // Some platform does not pass captured timestamp through. Use the current |
| 479 const uint32_t rtp_timestamp = | 479 // time instead. |
| 480 static_cast<uint32_t>(timestamp.InMilliseconds()) * 90; | 480 capture_time_ms = rtc::TimeMicros() / 1000; |
| 481 //} else { | |
| 482 // capture_time_ms = static_cast<uint32_t>(timestamp.InMilliseconds()); | |
| 483 //} | |
| 481 | 484 |
| 482 webrtc::EncodedImage image( | 485 webrtc::EncodedImage image( |
| 483 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, | 486 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, |
| 484 output_buffer->mapped_size()); | 487 output_buffer->mapped_size()); |
| 485 image._encodedWidth = input_visible_size_.width(); | 488 image._encodedWidth = input_visible_size_.width(); |
| 486 image._encodedHeight = input_visible_size_.height(); | 489 image._encodedHeight = input_visible_size_.height(); |
| 487 image._timeStamp = rtp_timestamp; | 490 // This is based on how input timestamps are calculated in |
| 488 image.capture_time_ms_ = timestamp.InMilliseconds(); | 491 // webrtc/video/video_capture_input.cc. |
| 492 image._timeStamp = capture_time_ms * 90; | |
| 493 image.capture_time_ms_ = capture_time_ms; | |
| 489 image._frameType = | 494 image._frameType = |
| 490 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); | 495 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); |
| 491 image._completeFrame = true; | 496 image._completeFrame = true; |
| 492 | 497 |
| 493 ReturnEncodedImage(image, bitstream_buffer_id, picture_id_); | 498 ReturnEncodedImage(image, bitstream_buffer_id, picture_id_); |
| 494 // Picture ID must wrap after reaching the maximum. | 499 // Picture ID must wrap after reaching the maximum. |
| 495 picture_id_ = (picture_id_ + 1) & 0x7FFF; | 500 picture_id_ = (picture_id_ + 1) & 0x7FFF; |
| 496 } | 501 } |
| 497 | 502 |
| 498 void RTCVideoEncoder::Impl::NotifyError( | 503 void RTCVideoEncoder::Impl::NotifyError( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 requires_copy = true; | 565 requires_copy = true; |
| 561 } | 566 } |
| 562 | 567 |
| 563 if (requires_copy) { | 568 if (requires_copy) { |
| 564 base::SharedMemory* input_buffer = input_buffers_[index]; | 569 base::SharedMemory* input_buffer = input_buffers_[index]; |
| 565 frame = media::VideoFrame::WrapExternalSharedMemory( | 570 frame = media::VideoFrame::WrapExternalSharedMemory( |
| 566 media::PIXEL_FORMAT_I420, input_frame_coded_size_, | 571 media::PIXEL_FORMAT_I420, input_frame_coded_size_, |
| 567 gfx::Rect(input_visible_size_), input_visible_size_, | 572 gfx::Rect(input_visible_size_), input_visible_size_, |
| 568 reinterpret_cast<uint8_t*>(input_buffer->memory()), | 573 reinterpret_cast<uint8_t*>(input_buffer->memory()), |
| 569 input_buffer->mapped_size(), input_buffer->handle(), 0, | 574 input_buffer->mapped_size(), input_buffer->handle(), 0, |
| 570 base::TimeDelta::FromMilliseconds(next_frame->ntp_time_ms())); | 575 base::TimeDelta::FromMilliseconds(next_frame->ntp_time_ms())); |
|
wuchengli
2016/06/17 03:50:51
maybe because this line should also be reverted?
| |
| 571 if (!frame.get()) { | 576 if (!frame.get()) { |
| 572 LogAndNotifyError(FROM_HERE, "failed to create frame", | 577 LogAndNotifyError(FROM_HERE, "failed to create frame", |
| 573 media::VideoEncodeAccelerator::kPlatformFailureError); | 578 media::VideoEncodeAccelerator::kPlatformFailureError); |
| 574 return; | 579 return; |
| 575 } | 580 } |
| 576 // Do a strided copy of the input frame to match the input requirements for | 581 // Do a strided copy of the input frame to match the input requirements for |
| 577 // the encoder. | 582 // the encoder. |
| 578 // TODO(sheu): support zero-copy from WebRTC. http://crbug.com/269312 | 583 // TODO(sheu): support zero-copy from WebRTC. http://crbug.com/269312 |
| 579 if (libyuv::I420Copy(next_frame->video_frame_buffer()->DataY(), | 584 if (libyuv::I420Copy(next_frame->video_frame_buffer()->DataY(), |
| 580 next_frame->video_frame_buffer()->StrideY(), | 585 next_frame->video_frame_buffer()->StrideY(), |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 862 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 867 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
| 863 init_retval == WEBRTC_VIDEO_CODEC_OK); | 868 init_retval == WEBRTC_VIDEO_CODEC_OK); |
| 864 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 869 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
| 865 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 870 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
| 866 profile, | 871 profile, |
| 867 media::VIDEO_CODEC_PROFILE_MAX + 1); | 872 media::VIDEO_CODEC_PROFILE_MAX + 1); |
| 868 } | 873 } |
| 869 } | 874 } |
| 870 | 875 |
| 871 } // namespace content | 876 } // namespace content |
| OLD | NEW |