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/gpu/rtc_video_encoder.h" | 5 #include "content/renderer/media/gpu/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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 media::VideoEncodeAccelerator::kPlatformFailureError); | 461 media::VideoEncodeAccelerator::kPlatformFailureError); |
| 462 return; | 462 return; |
| 463 } | 463 } |
| 464 base::SharedMemory* output_buffer = output_buffers_[bitstream_buffer_id]; | 464 base::SharedMemory* output_buffer = output_buffers_[bitstream_buffer_id]; |
| 465 if (payload_size > output_buffer->mapped_size()) { | 465 if (payload_size > output_buffer->mapped_size()) { |
| 466 LogAndNotifyError(FROM_HERE, "invalid payload_size", | 466 LogAndNotifyError(FROM_HERE, "invalid payload_size", |
| 467 media::VideoEncodeAccelerator::kPlatformFailureError); | 467 media::VideoEncodeAccelerator::kPlatformFailureError); |
| 468 return; | 468 return; |
| 469 } | 469 } |
| 470 output_buffers_free_count_--; | 470 output_buffers_free_count_--; |
| 471 | 471 |
|
nisse-chromium (ooo August 14)
2017/02/15 07:53:18
I'd suggest reading system clock up front,
int64_
Stefan
2017/02/15 12:31:24
You should then also make sure that two frames don
emircan
2017/02/15 19:35:34
Done.
emircan
2017/02/15 19:35:34
Done.
| |
| 472 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). | 472 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). |
| 473 int64_t capture_time_us, capture_time_ms; | 473 int64_t capture_time_us; |
| 474 uint32_t rtp_timestamp; | 474 uint32_t rtp_timestamp; |
| 475 | |
| 476 if (!timestamp.is_zero()) { | 475 if (!timestamp.is_zero()) { |
| 477 capture_time_us = timestamp.InMicroseconds();; | 476 capture_time_us = timestamp.InMicroseconds(); |
| 478 capture_time_ms = timestamp.InMilliseconds(); | |
| 479 } else { | 477 } else { |
| 480 // Fallback to the current time if encoder does not provide timestamp. | 478 // Fallback to the current time if encoder does not provide timestamp. |
| 481 capture_time_us = rtc::TimeMicros(); | 479 capture_time_us = rtc::TimeMicros(); |
| 482 capture_time_ms = capture_time_us / base::Time::kMicrosecondsPerMillisecond; | |
| 483 } | 480 } |
| 484 // RTP timestamp can wrap around. Get the lower 32 bits. | 481 // RTP timestamp can wrap around. Get the lower 32 bits. |
| 485 rtp_timestamp = static_cast<uint32_t>( | 482 rtp_timestamp = static_cast<uint32_t>( |
| 486 capture_time_us * 90 / base::Time::kMicrosecondsPerMillisecond); | 483 capture_time_us * 90 / base::Time::kMicrosecondsPerMillisecond); |
| 487 | 484 |
| 488 webrtc::EncodedImage image( | 485 webrtc::EncodedImage image( |
| 489 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, | 486 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, |
| 490 output_buffer->mapped_size()); | 487 output_buffer->mapped_size()); |
| 491 image._encodedWidth = input_visible_size_.width(); | 488 image._encodedWidth = input_visible_size_.width(); |
| 492 image._encodedHeight = input_visible_size_.height(); | 489 image._encodedHeight = input_visible_size_.height(); |
| 493 image._timeStamp = rtp_timestamp; | 490 image._timeStamp = rtp_timestamp; |
| 494 image.capture_time_ms_ = capture_time_ms; | 491 // This should be always based on system clock, so leave setting this field to |
| 492 // rtp code. | |
| 493 image.capture_time_ms_ = -1; | |
| 495 image._frameType = | 494 image._frameType = |
| 496 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); | 495 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); |
| 497 image._completeFrame = true; | 496 image._completeFrame = true; |
| 498 | 497 |
| 499 ReturnEncodedImage(image, bitstream_buffer_id, picture_id_); | 498 ReturnEncodedImage(image, bitstream_buffer_id, picture_id_); |
| 500 // Picture ID must wrap after reaching the maximum. | 499 // Picture ID must wrap after reaching the maximum. |
| 501 picture_id_ = (picture_id_ + 1) & 0x7FFF; | 500 picture_id_ = (picture_id_ + 1) & 0x7FFF; |
| 502 } | 501 } |
| 503 | 502 |
| 504 void RTCVideoEncoder::Impl::NotifyError( | 503 void RTCVideoEncoder::Impl::NotifyError( |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 879 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
| 881 init_retval == WEBRTC_VIDEO_CODEC_OK); | 880 init_retval == WEBRTC_VIDEO_CODEC_OK); |
| 882 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 881 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
| 883 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 882 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
| 884 profile, | 883 profile, |
| 885 media::VIDEO_CODEC_PROFILE_MAX + 1); | 884 media::VIDEO_CODEC_PROFILE_MAX + 1); |
| 886 } | 885 } |
| 887 } | 886 } |
| 888 | 887 |
| 889 } // namespace content | 888 } // namespace content |
| OLD | NEW |