OLD | NEW |
---|---|
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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(&Client::BitstreamBufferReady, client_, |
667 output_record.buffer_ref->id, output_size, key_frame)); | 667 output_record.buffer_ref->id, output_size, key_frame, |
668 base::TimeDelta::FromMicroseconds( | |
669 static_cast<int64_t>(dqbuf.timestamp.tv_usec)))); | |
Pawel Osciak
2016/05/23 07:15:53
Do we need the cast? Also, we need both tv_sec and
shenghao
2016/05/24 10:50:19
Removed the cast. I think we only need the usec to
Pawel Osciak
2016/05/26 07:39:23
We need both, usec only stores < 1s part of the va
shenghao
2016/05/26 10:38:20
Done.
| |
668 output_record.at_device = false; | 670 output_record.at_device = false; |
669 output_record.buffer_ref.reset(); | 671 output_record.buffer_ref.reset(); |
670 free_output_buffers_.push_back(dqbuf.index); | 672 free_output_buffers_.push_back(dqbuf.index); |
671 output_buffer_queued_count_--; | 673 output_buffer_queued_count_--; |
672 } | 674 } |
673 } | 675 } |
674 | 676 |
675 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { | 677 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { |
676 DVLOG(3) << "EnqueueInputRecord()"; | 678 DVLOG(3) << "EnqueueInputRecord()"; |
677 DCHECK(!free_input_buffers_.empty()); | 679 DCHECK(!free_input_buffers_.empty()); |
678 DCHECK(!encoder_input_queue_.empty()); | 680 DCHECK(!encoder_input_queue_.empty()); |
679 | 681 |
680 // Enqueue an input (VIDEO_OUTPUT) buffer. | 682 // Enqueue an input (VIDEO_OUTPUT) buffer. |
681 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); | 683 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); |
682 const int index = free_input_buffers_.back(); | 684 const int index = free_input_buffers_.back(); |
683 InputRecord& input_record = input_buffer_map_[index]; | 685 InputRecord& input_record = input_buffer_map_[index]; |
684 DCHECK(!input_record.at_device); | 686 DCHECK(!input_record.at_device); |
685 struct v4l2_buffer qbuf; | 687 struct v4l2_buffer qbuf; |
686 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; | 688 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; |
687 memset(&qbuf, 0, sizeof(qbuf)); | 689 memset(&qbuf, 0, sizeof(qbuf)); |
688 memset(qbuf_planes, 0, sizeof(qbuf_planes)); | 690 memset(qbuf_planes, 0, sizeof(qbuf_planes)); |
689 qbuf.index = index; | 691 qbuf.index = index; |
690 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 692 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
691 qbuf.m.planes = qbuf_planes; | 693 qbuf.m.planes = qbuf_planes; |
694 struct timeval timestamp; | |
695 timestamp.tv_sec = static_cast<time_t>(frame->timestamp().InSeconds()); | |
696 timestamp.tv_usec = | |
Pawel Osciak
2016/05/23 07:15:52
I'm wondering if we need the casts?
shenghao
2016/05/24 10:50:19
Done.
| |
697 static_cast<suseconds_t>(frame->timestamp().InMicroseconds()); | |
698 qbuf.timestamp = timestamp; | |
692 | 699 |
Pawel Osciak
2016/05/23 07:15:52
Do we need the temporary timestamp, could we just
shenghao
2016/05/24 10:50:19
Done.
| |
693 DCHECK_EQ(device_input_format_, frame->format()); | 700 DCHECK_EQ(device_input_format_, frame->format()); |
694 for (size_t i = 0; i < input_planes_count_; ++i) { | 701 for (size_t i = 0; i < input_planes_count_; ++i) { |
695 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( | 702 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( |
696 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) | 703 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) |
697 .GetArea()); | 704 .GetArea()); |
698 | 705 |
699 switch (input_memory_type_) { | 706 switch (input_memory_type_) { |
700 case V4L2_MEMORY_USERPTR: | 707 case V4L2_MEMORY_USERPTR: |
701 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; | 708 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; |
702 qbuf.m.planes[i].m.userptr = | 709 qbuf.m.planes[i].m.userptr = |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1244 reqbufs.count = 0; | 1251 reqbufs.count = 0; |
1245 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1252 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1246 reqbufs.memory = V4L2_MEMORY_MMAP; | 1253 reqbufs.memory = V4L2_MEMORY_MMAP; |
1247 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1254 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
1248 | 1255 |
1249 output_buffer_map_.clear(); | 1256 output_buffer_map_.clear(); |
1250 free_output_buffers_.clear(); | 1257 free_output_buffers_.clear(); |
1251 } | 1258 } |
1252 | 1259 |
1253 } // namespace media | 1260 } // namespace media |
OLD | NEW |