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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <linux/videodev2.h> | 6 #include <linux/videodev2.h> |
7 #include <poll.h> | 7 #include <poll.h> |
8 #include <sys/eventfd.h> | 8 #include <sys/eventfd.h> |
9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() | 64 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() |
65 : at_device(false), address(NULL), length(0) { | 65 : at_device(false), address(NULL), length(0) { |
66 } | 66 } |
67 | 67 |
68 V4L2VideoEncodeAccelerator::OutputRecord::~OutputRecord() { | 68 V4L2VideoEncodeAccelerator::OutputRecord::~OutputRecord() { |
69 } | 69 } |
70 | 70 |
71 V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator( | 71 V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator( |
72 scoped_ptr<V4L2Device> device) | 72 const scoped_refptr<V4L2Device>& device) |
73 : child_message_loop_proxy_(base::MessageLoopProxy::current()), | 73 : child_message_loop_proxy_(base::MessageLoopProxy::current()), |
74 output_buffer_byte_size_(0), | 74 output_buffer_byte_size_(0), |
75 device_input_format_(media::VideoFrame::UNKNOWN), | 75 device_input_format_(media::VideoFrame::UNKNOWN), |
76 input_planes_count_(0), | 76 input_planes_count_(0), |
77 output_format_fourcc_(0), | 77 output_format_fourcc_(0), |
78 encoder_state_(kUninitialized), | 78 encoder_state_(kUninitialized), |
79 stream_header_size_(0), | 79 stream_header_size_(0), |
80 device_(device.Pass()), | 80 device_(device), |
81 input_streamon_(false), | 81 input_streamon_(false), |
82 input_buffer_queued_count_(0), | 82 input_buffer_queued_count_(0), |
83 input_memory_type_(V4L2_MEMORY_USERPTR), | 83 input_memory_type_(V4L2_MEMORY_USERPTR), |
84 output_streamon_(false), | 84 output_streamon_(false), |
85 output_buffer_queued_count_(0), | 85 output_buffer_queued_count_(0), |
86 encoder_thread_("V4L2EncoderThread"), | 86 encoder_thread_("V4L2EncoderThread"), |
87 device_poll_thread_("V4L2EncoderDevicePollThread"), | 87 device_poll_thread_("V4L2EncoderDevicePollThread"), |
88 weak_this_ptr_factory_(this) { | 88 weak_this_ptr_factory_(this) { |
89 weak_this_ = weak_this_ptr_factory_.GetWeakPtr(); | 89 weak_this_ = weak_this_ptr_factory_.GetWeakPtr(); |
90 } | 90 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 131 |
132 if (!SetFormats(input_format, output_profile)) { | 132 if (!SetFormats(input_format, output_profile)) { |
133 LOG(ERROR) << "Failed setting up formats"; | 133 LOG(ERROR) << "Failed setting up formats"; |
134 return false; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 if (input_format != device_input_format_) { | 137 if (input_format != device_input_format_) { |
138 DVLOG(1) << "Input format not supported by the HW, will convert to " | 138 DVLOG(1) << "Input format not supported by the HW, will convert to " |
139 << media::VideoFrame::FormatToString(device_input_format_); | 139 << media::VideoFrame::FormatToString(device_input_format_); |
140 | 140 |
141 scoped_ptr<V4L2Device> device = | 141 scoped_refptr<V4L2Device> device = |
142 V4L2Device::Create(V4L2Device::kImageProcessor); | 142 V4L2Device::Create(V4L2Device::kImageProcessor); |
143 image_processor_.reset(new V4L2ImageProcessor(device.Pass())); | 143 image_processor_.reset(new V4L2ImageProcessor(device)); |
144 | 144 |
145 // Convert from input_format to device_input_format_, keeping the size | 145 // Convert from input_format to device_input_format_, keeping the size |
146 // at visible_size_ and requiring the output buffers to be of at least | 146 // at visible_size_ and requiring the output buffers to be of at least |
147 // input_allocated_size_. | 147 // input_allocated_size_. |
148 if (!image_processor_->Initialize( | 148 if (!image_processor_->Initialize( |
149 input_format, | 149 input_format, |
150 device_input_format_, | 150 device_input_format_, |
151 visible_size_, | 151 visible_size_, |
152 visible_size_, | 152 visible_size_, |
153 input_allocated_size_, | 153 input_allocated_size_, |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 IOCTL_OR_ERROR_RETURN(VIDIOC_S_PARM, &parms); | 835 IOCTL_OR_ERROR_RETURN(VIDIOC_S_PARM, &parms); |
836 } | 836 } |
837 | 837 |
838 bool V4L2VideoEncodeAccelerator::SetOutputFormat( | 838 bool V4L2VideoEncodeAccelerator::SetOutputFormat( |
839 media::VideoCodecProfile output_profile) { | 839 media::VideoCodecProfile output_profile) { |
840 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 840 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); |
841 DCHECK(!input_streamon_); | 841 DCHECK(!input_streamon_); |
842 DCHECK(!output_streamon_); | 842 DCHECK(!output_streamon_); |
843 | 843 |
844 output_format_fourcc_ = | 844 output_format_fourcc_ = |
845 V4L2Device::VideoCodecProfileToV4L2PixFmt(output_profile); | 845 V4L2Device::VideoCodecProfileToV4L2PixFmt(output_profile, false); |
846 if (!output_format_fourcc_) { | 846 if (!output_format_fourcc_) { |
847 LOG(ERROR) << "Initialize(): invalid output_profile=" << output_profile; | 847 LOG(ERROR) << "Initialize(): invalid output_profile=" << output_profile; |
848 return false; | 848 return false; |
849 } | 849 } |
850 | 850 |
851 output_buffer_byte_size_ = kOutputBufferSize; | 851 output_buffer_byte_size_ = kOutputBufferSize; |
852 | 852 |
853 struct v4l2_format format; | 853 struct v4l2_format format; |
854 memset(&format, 0, sizeof(format)); | 854 memset(&format, 0, sizeof(format)); |
855 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 855 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 reqbufs.count = 0; | 1145 reqbufs.count = 0; |
1146 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1146 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1147 reqbufs.memory = V4L2_MEMORY_MMAP; | 1147 reqbufs.memory = V4L2_MEMORY_MMAP; |
1148 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1148 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
1149 | 1149 |
1150 output_buffer_map_.clear(); | 1150 output_buffer_map_.clear(); |
1151 free_output_buffers_.clear(); | 1151 free_output_buffers_.clear(); |
1152 } | 1152 } |
1153 | 1153 |
1154 } // namespace content | 1154 } // namespace content |
OLD | NEW |