| 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 } else { | 658 } else { |
| 659 memcpy(target_data, output_data, output_size); | 659 memcpy(target_data, output_data, output_size); |
| 660 } | 660 } |
| 661 | 661 |
| 662 DVLOG(3) << "Dequeue(): returning " | 662 DVLOG(3) << "Dequeue(): returning " |
| 663 << "bitstream_buffer_id=" << output_record.buffer_ref->id | 663 << "bitstream_buffer_id=" << output_record.buffer_ref->id |
| 664 << ", size=" << output_size | 664 << ", size=" << output_size |
| 665 << ", key_frame=" << key_frame; | 665 << ", key_frame=" << key_frame; |
| 666 child_task_runner_->PostTask( | 666 child_task_runner_->PostTask( |
| 667 FROM_HERE, | 667 FROM_HERE, |
| 668 base::Bind(&Client::BitstreamBufferReady, client_, | 668 base::Bind( |
| 669 output_record.buffer_ref->id, output_size, key_frame)); | 669 &Client::BitstreamBufferReady, client_, |
| 670 output_record.buffer_ref->id, output_size, key_frame, |
| 671 base::TimeDelta::FromMicroseconds( |
| 672 dqbuf.timestamp.tv_usec + |
| 673 dqbuf.timestamp.tv_sec * base::Time::kMicrosecondsPerSecond))); |
| 670 output_record.at_device = false; | 674 output_record.at_device = false; |
| 671 output_record.buffer_ref.reset(); | 675 output_record.buffer_ref.reset(); |
| 672 free_output_buffers_.push_back(dqbuf.index); | 676 free_output_buffers_.push_back(dqbuf.index); |
| 673 output_buffer_queued_count_--; | 677 output_buffer_queued_count_--; |
| 674 } | 678 } |
| 675 } | 679 } |
| 676 | 680 |
| 677 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { | 681 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { |
| 678 DVLOG(3) << "EnqueueInputRecord()"; | 682 DVLOG(3) << "EnqueueInputRecord()"; |
| 679 DCHECK(!free_input_buffers_.empty()); | 683 DCHECK(!free_input_buffers_.empty()); |
| 680 DCHECK(!encoder_input_queue_.empty()); | 684 DCHECK(!encoder_input_queue_.empty()); |
| 681 | 685 |
| 682 // Enqueue an input (VIDEO_OUTPUT) buffer. | 686 // Enqueue an input (VIDEO_OUTPUT) buffer. |
| 683 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); | 687 scoped_refptr<media::VideoFrame> frame = encoder_input_queue_.front(); |
| 684 const int index = free_input_buffers_.back(); | 688 const int index = free_input_buffers_.back(); |
| 685 InputRecord& input_record = input_buffer_map_[index]; | 689 InputRecord& input_record = input_buffer_map_[index]; |
| 686 DCHECK(!input_record.at_device); | 690 DCHECK(!input_record.at_device); |
| 687 struct v4l2_buffer qbuf; | 691 struct v4l2_buffer qbuf; |
| 688 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; | 692 struct v4l2_plane qbuf_planes[VIDEO_MAX_PLANES]; |
| 689 memset(&qbuf, 0, sizeof(qbuf)); | 693 memset(&qbuf, 0, sizeof(qbuf)); |
| 690 memset(qbuf_planes, 0, sizeof(qbuf_planes)); | 694 memset(qbuf_planes, 0, sizeof(qbuf_planes)); |
| 691 qbuf.index = index; | 695 qbuf.index = index; |
| 692 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 696 qbuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 693 qbuf.m.planes = qbuf_planes; | 697 qbuf.m.planes = qbuf_planes; |
| 698 qbuf.timestamp.tv_sec = static_cast<time_t>(frame->timestamp().InSeconds()); |
| 699 qbuf.timestamp.tv_usec = |
| 700 frame->timestamp().InMicroseconds() - |
| 701 frame->timestamp().InSeconds() * base::Time::kMicrosecondsPerSecond; |
| 694 | 702 |
| 695 DCHECK_EQ(device_input_format_, frame->format()); | 703 DCHECK_EQ(device_input_format_, frame->format()); |
| 696 for (size_t i = 0; i < input_planes_count_; ++i) { | 704 for (size_t i = 0; i < input_planes_count_; ++i) { |
| 697 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( | 705 qbuf.m.planes[i].bytesused = base::checked_cast<__u32>( |
| 698 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) | 706 media::VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_) |
| 699 .GetArea()); | 707 .GetArea()); |
| 700 | 708 |
| 701 switch (input_memory_type_) { | 709 switch (input_memory_type_) { |
| 702 case V4L2_MEMORY_USERPTR: | 710 case V4L2_MEMORY_USERPTR: |
| 703 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; | 711 qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused; |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 reqbufs.count = 0; | 1256 reqbufs.count = 0; |
| 1249 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1257 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1250 reqbufs.memory = V4L2_MEMORY_MMAP; | 1258 reqbufs.memory = V4L2_MEMORY_MMAP; |
| 1251 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1259 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
| 1252 | 1260 |
| 1253 output_buffer_map_.clear(); | 1261 output_buffer_map_.clear(); |
| 1254 free_output_buffers_.clear(); | 1262 free_output_buffers_.clear(); |
| 1255 } | 1263 } |
| 1256 | 1264 |
| 1257 } // namespace media | 1265 } // namespace media |
| OLD | NEW |