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

Side by Side Diff: media/gpu/v4l2_video_encode_accelerator.cc

Issue 1996453003: RTC Video Encoder: Use capturer timestamp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/gpu/v4l2_video_encode_accelerator.h" 5 #include "media/gpu/v4l2_video_encode_accelerator.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <linux/videodev2.h> 8 #include <linux/videodev2.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } else { 656 } else {
657 memcpy(target_data, output_data, output_size); 657 memcpy(target_data, output_data, output_size);
658 } 658 }
659 659
660 DVLOG(3) << "Dequeue(): returning " 660 DVLOG(3) << "Dequeue(): returning "
661 "bitstream_buffer_id=" 661 "bitstream_buffer_id="
662 << output_record.buffer_ref->id << ", size=" << output_size 662 << output_record.buffer_ref->id << ", size=" << output_size
663 << ", key_frame=" << key_frame; 663 << ", key_frame=" << key_frame;
664 child_task_runner_->PostTask( 664 child_task_runner_->PostTask(
665 FROM_HERE, 665 FROM_HERE,
666 base::Bind(&Client::BitstreamBufferReady, client_, 666 base::Bind(
667 output_record.buffer_ref->id, output_size, key_frame)); 667 &Client::BitstreamBufferReady, client_,
668 output_record.buffer_ref->id, output_size, key_frame,
669 base::TimeDelta::FromMicroseconds(
Pawel Osciak 2016/05/27 04:46:38 Perhaps we could use Time::FromTimeVal()...
shenghao 2016/05/30 09:18:02 Talked offline. Time::FromTimeVal() does not fit o
670 dqbuf.timestamp.tv_usec +
671 dqbuf.timestamp.tv_sec * base::Time::kMicrosecondsPerSecond)));
668 output_record.at_device = false; 672 output_record.at_device = false;
669 output_record.buffer_ref.reset(); 673 output_record.buffer_ref.reset();
670 free_output_buffers_.push_back(dqbuf.index); 674 free_output_buffers_.push_back(dqbuf.index);
671 output_buffer_queued_count_--; 675 output_buffer_queued_count_--;
672 } 676 }
673 } 677 }
674 678
675 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { 679 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() {
676 DVLOG(3) << "EnqueueInputRecord()"; 680 DVLOG(3) << "EnqueueInputRecord()";
677 DCHECK(!free_input_buffers_.empty()); 681 DCHECK(!free_input_buffers_.empty());
678 DCHECK(!encoder_input_queue_.empty()); 682 DCHECK(!encoder_input_queue_.empty());
679 683
680 // Enqueue an input (VIDEO_OUTPUT) buffer. 684 // Enqueue an input (VIDEO_OUTPUT) buffer.
681 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); 685 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front();
682 const int index = free_input_buffers_.back(); 686 const int index = free_input_buffers_.back();
683 InputRecord& input_record = input_buffer_map_[index]; 687 InputRecord& input_record = input_buffer_map_[index];
684 DCHECK(!input_record.at_device); 688 DCHECK(!input_record.at_device);
685 struct v4l2_buffer qbuf; 689 struct v4l2_buffer qbuf;
686 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; 690 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES];
687 memset(&qbuf, 0, sizeof(qbuf)); 691 memset(&qbuf, 0, sizeof(qbuf));
688 memset(qbuf_planes, 0, sizeof(qbuf_planes)); 692 memset(qbuf_planes, 0, sizeof(qbuf_planes));
689 qbuf.index = index; 693 qbuf.index = index;
690 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 694 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
691 qbuf.m.planes = qbuf_planes; 695 qbuf.m.planes = qbuf_planes;
696 qbuf.timestamp.tv_sec = static_cast<time_t>(frame->timestamp().InSeconds());
Pawel Osciak 2016/05/27 04:46:38 ... and Time::ToTimeVal().
shenghao 2016/05/30 09:18:02 Talked offline. Time::ToTimeVal() does not fit our
697 qbuf.timestamp.tv_usec =
698 frame->timestamp().InMicroseconds() -
699 frame->timestamp().InSeconds() * base::Time::kMicrosecondsPerSecond;
692 700
693 DCHECK_EQ(device_input_format_, frame->format()); 701 DCHECK_EQ(device_input_format_, frame->format());
694 for (size_t i = 0; i < input_planes_count_; ++i) { 702 for (size_t i = 0; i < input_planes_count_; ++i) {
695 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( 703 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>(
696 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) 704 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_)
697 .GetArea()); 705 .GetArea());
698 706
699 switch (input_memory_type_) { 707 switch (input_memory_type_) {
700 case V4L2_MEMORY_USERPTR: 708 case V4L2_MEMORY_USERPTR:
701 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; 709 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused;
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 reqbufs.count = 0; 1252 reqbufs.count = 0;
1245 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1253 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1246 reqbufs.memory = V4L2_MEMORY_MMAP; 1254 reqbufs.memory = V4L2_MEMORY_MMAP;
1247 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); 1255 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs);
1248 1256
1249 output_buffer_map_.clear(); 1257 output_buffer_map_.clear();
1250 free_output_buffers_.clear(); 1258 free_output_buffers_.clear();
1251 } 1259 }
1252 1260
1253 } // namespace media 1261 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698