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

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: change to kMicrosecondsPerMillisecond 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 446 }
447 DCHECK_EQ(GetStatus(), WEBRTC_VIDEO_CODEC_UNINITIALIZED); 447 DCHECK_EQ(GetStatus(), WEBRTC_VIDEO_CODEC_UNINITIALIZED);
448 SetStatus(WEBRTC_VIDEO_CODEC_OK); 448 SetStatus(WEBRTC_VIDEO_CODEC_OK);
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(): bitstream_buffer_id="
457 "bitstream_buffer_id=" << bitstream_buffer_id 457 << bitstream_buffer_id << ", payload_size=" << payload_size
458 << ", payload_size=" << payload_size 458 << ", key_frame=" << key_frame
459 << ", key_frame=" << key_frame; 459 << ", timestamp ms=" << timestamp.InMilliseconds();
460 DCHECK(thread_checker_.CalledOnValidThread()); 460 DCHECK(thread_checker_.CalledOnValidThread());
461 461
462 if (bitstream_buffer_id < 0 || 462 if (bitstream_buffer_id < 0 ||
463 bitstream_buffer_id >= static_cast<int>(output_buffers_.size())) { 463 bitstream_buffer_id >= static_cast<int>(output_buffers_.size())) {
464 LogAndNotifyError(FROM_HERE, "invalid bitstream_buffer_id", 464 LogAndNotifyError(FROM_HERE, "invalid bitstream_buffer_id",
465 media::VideoEncodeAccelerator::kPlatformFailureError); 465 media::VideoEncodeAccelerator::kPlatformFailureError);
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.
477 // TODO(wuchengli): use the timestamp in BitstreamBufferReady after Nyan is
478 // fixed. http://crbug.com/620565.
479 const int64_t capture_time_us = rtc::TimeMicros();
480
476 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks). 481 // Derive the capture time (in ms) and RTP timestamp (in 90KHz ticks).
477 // This is based on how input timestamps are calculated in 482 const int64_t capture_time_ms =
478 // webrtc/video/video_capture_input.cc. 483 capture_time_us / base::Time::kMicrosecondsPerMillisecond;
479 const uint32_t rtp_timestamp = 484
480 static_cast<uint32_t>(timestamp.InMilliseconds()) * 90; 485 const uint32_t rtp_timestamp = static_cast<uint32_t>(
486 capture_time_us * 90 / base::Time::kMicrosecondsPerMillisecond);
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