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(dqbuf.timestamp.tv_usec))); |
668 output_record.at_device = false; | 669 output_record.at_device = false; |
669 output_record.buffer_ref.reset(); | 670 output_record.buffer_ref.reset(); |
670 free_output_buffers_.push_back(dqbuf.index); | 671 free_output_buffers_.push_back(dqbuf.index); |
671 output_buffer_queued_count_--; | 672 output_buffer_queued_count_--; |
672 } | 673 } |
673 } | 674 } |
674 | 675 |
675 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { | 676 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { |
676 DVLOG(3) << "EnqueueInputRecord()"; | 677 DVLOG(3) << "EnqueueInputRecord()"; |
677 DCHECK(!free_input_buffers_.empty()); | 678 DCHECK(!free_input_buffers_.empty()); |
678 DCHECK(!encoder_input_queue_.empty()); | 679 DCHECK(!encoder_input_queue_.empty()); |
679 | 680 |
680 // Enqueue an input (VIDEO_OUTPUT) buffer. | 681 // Enqueue an input (VIDEO_OUTPUT) buffer. |
681 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); | 682 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); |
682 const int index = free_input_buffers_.back(); | 683 const int index = free_input_buffers_.back(); |
683 InputRecord& input_record = input_buffer_map_[index]; | 684 InputRecord& input_record = input_buffer_map_[index]; |
684 DCHECK(!input_record.at_device); | 685 DCHECK(!input_record.at_device); |
685 struct v4l2_buffer qbuf; | 686 struct v4l2_buffer qbuf; |
686 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; | 687 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; |
687 memset(&qbuf, 0, sizeof(qbuf)); | 688 memset(&qbuf, 0, sizeof(qbuf)); |
688 memset(qbuf_planes, 0, sizeof(qbuf_planes)); | 689 memset(qbuf_planes, 0, sizeof(qbuf_planes)); |
689 qbuf.index = index; | 690 qbuf.index = index; |
690 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 691 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
691 qbuf.m.planes = qbuf_planes; | 692 qbuf.m.planes = qbuf_planes; |
| 693 qbuf.timestamp.tv_usec = frame->timestamp().InMicroseconds(); |
692 | 694 |
693 DCHECK_EQ(device_input_format_, frame->format()); | 695 DCHECK_EQ(device_input_format_, frame->format()); |
694 for (size_t i = 0; i < input_planes_count_; ++i) { | 696 for (size_t i = 0; i < input_planes_count_; ++i) { |
695 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( | 697 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( |
696 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) | 698 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) |
697 .GetArea()); | 699 .GetArea()); |
698 | 700 |
699 switch (input_memory_type_) { | 701 switch (input_memory_type_) { |
700 case V4L2_MEMORY_USERPTR: | 702 case V4L2_MEMORY_USERPTR: |
701 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; | 703 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 reqbufs.count = 0; | 1246 reqbufs.count = 0; |
1245 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1247 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1246 reqbufs.memory = V4L2_MEMORY_MMAP; | 1248 reqbufs.memory = V4L2_MEMORY_MMAP; |
1247 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1249 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
1248 | 1250 |
1249 output_buffer_map_.clear(); | 1251 output_buffer_map_.clear(); |
1250 free_output_buffers_.clear(); | 1252 free_output_buffers_.clear(); |
1251 } | 1253 } |
1252 | 1254 |
1253 } // namespace media | 1255 } // namespace media |
OLD | NEW |