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

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

Issue 2071953003: RtcVideoEncoder: use the current timestamp for encoded frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update the comment Created 4 years, 6 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK); 449 SignalAsyncWaiter(WEBRTC_VIDEO_CODEC_OK);
450 } 450 }
451 451
452 void RTCVideoEncoder::Impl::BitstreamBufferReady(int32_t bitstream_buffer_id, 452 void RTCVideoEncoder::Impl::BitstreamBufferReady(int32_t bitstream_buffer_id,
453 size_t payload_size, 453 size_t payload_size,
454 bool key_frame, 454 bool key_frame,
455 base::TimeDelta timestamp) { 455 base::TimeDelta timestamp) {
456 DVLOG(3) << "Impl::BitstreamBufferReady(): " 456 DVLOG(3) << "Impl::BitstreamBufferReady(): "
457 "bitstream_buffer_id=" << bitstream_buffer_id 457 "bitstream_buffer_id=" << bitstream_buffer_id
458 << ", payload_size=" << payload_size 458 << ", payload_size=" << payload_size
459 << ", key_frame=" << key_frame; 459 << ", key_frame=" << key_frame
460 << ", timestamp ms=" << timestamp.InMilliseconds();
460 DCHECK(thread_checker_.CalledOnValidThread()); 461 DCHECK(thread_checker_.CalledOnValidThread());
461 462
462 if (bitstream_buffer_id < 0 || 463 if (bitstream_buffer_id < 0 ||
463 bitstream_buffer_id >= static_cast<int>(output_buffers_.size())) { 464 bitstream_buffer_id >= static_cast<int>(output_buffers_.size())) {
464 LogAndNotifyError(FROM_HERE, "invalid bitstream_buffer_id", 465 LogAndNotifyError(FROM_HERE, "invalid bitstream_buffer_id",
465 media::VideoEncodeAccelerator::kPlatformFailureError); 466 media::VideoEncodeAccelerator::kPlatformFailureError);
466 return; 467 return;
467 } 468 }
468 base::SharedMemory* output_buffer = output_buffers_[bitstream_buffer_id]; 469 base::SharedMemory* output_buffer = output_buffers_[bitstream_buffer_id];
469 if (payload_size > output_buffer->mapped_size()) { 470 if (payload_size > output_buffer->mapped_size()) {
470 LogAndNotifyError(FROM_HERE, "invalid payload_size", 471 LogAndNotifyError(FROM_HERE, "invalid payload_size",
471 media::VideoEncodeAccelerator::kPlatformFailureError); 472 media::VideoEncodeAccelerator::kPlatformFailureError);
472 return; 473 return;
473 } 474 }
474 output_buffers_free_count_--; 475 output_buffers_free_count_--;
475 476
477 // CrOS Nyan provides invalid timestamp. Use the current time for now.
478 // TODO(wuchengli): use the timestamp in BitstreamBufferReady after Nyan is
479 // fixed.
mcasas 2016/06/17 10:32:42 Can you add a https://crbug.com/ to this comment f
wuchengli 2016/06/17 10:44:36 Done. PS1 has a http://crosbug.com/p/ bug. I just
480 const int64_t capture_time_us = rtc::TimeMicros();
481
476 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). 482 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks).
477 // This is based on how input timestamps are calculated in 483 const int64_t capture_time_ms = capture_time_us / 1000;
mcasas 2016/06/17 10:32:42 s/1000/base::Time::kNanosecondsPerMicrosecond/ fro
wuchengli 2016/06/17 10:44:36 Done.
478 // webrtc/video/video_capture_input.cc. 484
479 const uint32_t rtp_timestamp = 485 const uint32_t rtp_timestamp =
480 static_cast<uint32_t>(timestamp.InMilliseconds()) * 90; 486 static_cast<uint32_t>(capture_time_us * 90 / 1000);
mcasas 2016/06/17 10:32:42 Same here
wuchengli 2016/06/17 10:44:36 Done.
481 487
482 webrtc::EncodedImage image( 488 webrtc::EncodedImage image(
483 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size, 489 reinterpret_cast<uint8_t*>(output_buffer->memory()), payload_size,
484 output_buffer->mapped_size()); 490 output_buffer->mapped_size());
485 image._encodedWidth = input_visible_size_.width(); 491 image._encodedWidth = input_visible_size_.width();
486 image._encodedHeight = input_visible_size_.height(); 492 image._encodedHeight = input_visible_size_.height();
487 image._timeStamp = rtp_timestamp; 493 image._timeStamp = rtp_timestamp;
488 image.capture_time_ms_ = timestamp.InMilliseconds(); 494 image.capture_time_ms_ = capture_time_ms;
489 image._frameType = 495 image._frameType =
490 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); 496 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta);
491 image._completeFrame = true; 497 image._completeFrame = true;
492 498
493 ReturnEncodedImage(image, bitstream_buffer_id, picture_id_); 499 ReturnEncodedImage(image, bitstream_buffer_id, picture_id_);
494 // Picture ID must wrap after reaching the maximum. 500 // Picture ID must wrap after reaching the maximum.
495 picture_id_ = (picture_id_ + 1) & 0x7FFF; 501 picture_id_ = (picture_id_ + 1) & 0x7FFF;
496 } 502 }
497 503
498 void RTCVideoEncoder::Impl::NotifyError( 504 void RTCVideoEncoder::Impl::NotifyError(
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", 868 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess",
863 init_retval == WEBRTC_VIDEO_CODEC_OK); 869 init_retval == WEBRTC_VIDEO_CODEC_OK);
864 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { 870 if (init_retval == WEBRTC_VIDEO_CODEC_OK) {
865 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", 871 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile",
866 profile, 872 profile,
867 media::VIDEO_CODEC_PROFILE_MAX + 1); 873 media::VIDEO_CODEC_PROFILE_MAX + 1);
868 } 874 }
869 } 875 }
870 876
871 } // namespace content 877 } // 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