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

Side by Side Diff: content/renderer/media/rtc_video_encoder.cc

Issue 2105683002: RtcVideoEncoder: use the timestamp from encoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Shenghao's comment and run git cl format Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // CrOS Nyan provides invalid timestamp. Use the current time for now. 476 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks).
477 // TODO(wuchengli): use the timestamp in BitstreamBufferReady after Nyan is 477 int64_t capture_time_ms;
478 // fixed. http://crbug.com/620565. 478 uint32_t rtp_timestamp;
479 const int64_t capture_time_us = rtc::TimeMicros();
480 479
481 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). 480 if (!timestamp.is_zero()) {
482 const int64_t capture_time_ms = 481 capture_time_ms = timestamp.InMilliseconds();
483 capture_time_us / base::Time::kMicrosecondsPerMillisecond; 482 rtp_timestamp = static_cast<uint32_t>(timestamp.InMilliseconds()) * 90;
mcasas 2016/06/29 14:55:50 nit: s/timestamp.InMilliseconds()/capture_time_ms/
wuchengli 2016/07/01 06:19:09 Now I used the same calculation for both cases bec
484 483 } else {
485 const uint32_t rtp_timestamp = static_cast<uint32_t>( 484 // Fallback to the current time if encoder does not provide timestamp.
486 capture_time_us * 90 / base::Time::kMicrosecondsPerMillisecond); 485 const int64_t capture_time_us = rtc::TimeMicros();
486 capture_time_ms = capture_time_us / base::Time::kMicrosecondsPerMillisecond;
487 rtp_timestamp = static_cast<uint32_t>(
mcasas 2016/06/29 14:55:50 nit: We'd probably want |rtp_timestamp| to wrap ar
wuchengli 2016/07/01 06:19:09 Yes. We want RTC timestamp to wrap around. I added
488 capture_time_us * 90 / base::Time::kMicrosecondsPerMillisecond);
489 }
487 490
488 webrtc::EncodedImage image( 491 webrtc::EncodedImage image(
489 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, 492 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size,
490 output_buffer->mapped_size()); 493 output_buffer->mapped_size());
491 image._encodedWidth = input_visible_size_.width(); 494 image._encodedWidth = input_visible_size_.width();
492 image._encodedHeight = input_visible_size_.height(); 495 image._encodedHeight = input_visible_size_.height();
493 image._timeStamp = rtp_timestamp; 496 image._timeStamp = rtp_timestamp;
494 image.capture_time_ms_ = capture_time_ms; 497 image.capture_time_ms_ = capture_time_ms;
495 image._frameType = 498 image._frameType =
496 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); 499 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 scoped_refptr<media::VideoFrame> frame; 563 scoped_refptr<media::VideoFrame> frame;
561 if (next_frame->video_frame_buffer()->native_handle()) { 564 if (next_frame->video_frame_buffer()->native_handle()) {
562 frame = static_cast<media::VideoFrame*>( 565 frame = static_cast<media::VideoFrame*>(
563 next_frame->video_frame_buffer()->native_handle()); 566 next_frame->video_frame_buffer()->native_handle());
564 requires_copy = RequiresSizeChange(frame); 567 requires_copy = RequiresSizeChange(frame);
565 } else { 568 } else {
566 requires_copy = true; 569 requires_copy = true;
567 } 570 }
568 571
569 if (requires_copy) { 572 if (requires_copy) {
573 base::TimeDelta timestamp =
mcasas 2016/06/29 14:55:50 nit: const
wuchengli 2016/07/01 06:19:09 Done.
574 frame ? frame->timestamp()
575 : base::TimeDelta::FromMilliseconds(next_frame->ntp_time_ms());
570 base::SharedMemory* input_buffer = input_buffers_[index]; 576 base::SharedMemory* input_buffer = input_buffers_[index];
571 frame = media::VideoFrame::WrapExternalSharedMemory( 577 frame = media::VideoFrame::WrapExternalSharedMemory(
572 media::PIXEL_FORMAT_I420, input_frame_coded_size_, 578 media::PIXEL_FORMAT_I420, input_frame_coded_size_,
573 gfx::Rect(input_visible_size_), input_visible_size_, 579 gfx::Rect(input_visible_size_), input_visible_size_,
574 reinterpret_cast<uint8_t*>(input_buffer->memory()), 580 reinterpret_cast<uint8_t*>(input_buffer->memory()),
575 input_buffer->mapped_size(), input_buffer->handle(), 0, 581 input_buffer->mapped_size(), input_buffer->handle(), 0, timestamp);
576 base::TimeDelta::FromMilliseconds(next_frame->ntp_time_ms()));
577 if (!frame.get()) { 582 if (!frame.get()) {
578 LogAndNotifyError(FROM_HERE, "failed to create frame", 583 LogAndNotifyError(FROM_HERE, "failed to create frame",
579 media::VideoEncodeAccelerator::kPlatformFailureError); 584 media::VideoEncodeAccelerator::kPlatformFailureError);
580 return; 585 return;
581 } 586 }
582 // Do a strided copy of the input frame to match the input requirements for 587 // Do a strided copy of the input frame to match the input requirements for
583 // the encoder. 588 // the encoder.
584 // TODO(sheu): support zero-copy from WebRTC. http://crbug.com/269312 589 // TODO(sheu): support zero-copy from WebRTC. http://crbug.com/269312
585 if (libyuv::I420Copy(next_frame->video_frame_buffer()->DataY(), 590 if (libyuv::I420Copy(next_frame->video_frame_buffer()->DataY(),
586 next_frame->video_frame_buffer()->StrideY(), 591 next_frame->video_frame_buffer()->StrideY(),
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", 873 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess",
869 init_retval == WEBRTC_VIDEO_CODEC_OK); 874 init_retval == WEBRTC_VIDEO_CODEC_OK);
870 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { 875 if (init_retval == WEBRTC_VIDEO_CODEC_OK) {
871 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", 876 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile",
872 profile, 877 profile,
873 media::VIDEO_CODEC_PROFILE_MAX + 1); 878 media::VIDEO_CODEC_PROFILE_MAX + 1);
874 } 879 }
875 } 880 }
876 881
877 } // namespace content 882 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698