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> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/message_loop/message_loop_proxy.h" | |
15 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
17 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 16 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
18 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
19 #include "media/base/bitstream_buffer.h" | 18 #include "media/base/bitstream_buffer.h" |
20 | 19 |
21 #define NOTIFY_ERROR(x) \ | 20 #define NOTIFY_ERROR(x) \ |
22 do { \ | 21 do { \ |
23 LOG(ERROR) << "Setting error state:" << x; \ | 22 LOG(ERROR) << "Setting error state:" << x; \ |
24 SetErrorState(x); \ | 23 SetErrorState(x); \ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 62 |
64 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() | 63 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() |
65 : at_device(false), address(NULL), length(0) { | 64 : at_device(false), address(NULL), length(0) { |
66 } | 65 } |
67 | 66 |
68 V4L2VideoEncodeAccelerator::OutputRecord::~OutputRecord() { | 67 V4L2VideoEncodeAccelerator::OutputRecord::~OutputRecord() { |
69 } | 68 } |
70 | 69 |
71 V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator( | 70 V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator( |
72 const scoped_refptr<V4L2Device>& device) | 71 const scoped_refptr<V4L2Device>& device) |
73 : child_message_loop_proxy_(base::MessageLoopProxy::current()), | 72 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
74 output_buffer_byte_size_(0), | 73 output_buffer_byte_size_(0), |
75 device_input_format_(media::VideoFrame::UNKNOWN), | 74 device_input_format_(media::VideoFrame::UNKNOWN), |
76 input_planes_count_(0), | 75 input_planes_count_(0), |
77 output_format_fourcc_(0), | 76 output_format_fourcc_(0), |
78 encoder_state_(kUninitialized), | 77 encoder_state_(kUninitialized), |
79 stream_header_size_(0), | 78 stream_header_size_(0), |
80 device_(device), | 79 device_(device), |
81 input_streamon_(false), | 80 input_streamon_(false), |
82 input_buffer_queued_count_(0), | 81 input_buffer_queued_count_(0), |
83 input_memory_type_(V4L2_MEMORY_USERPTR), | 82 input_memory_type_(V4L2_MEMORY_USERPTR), |
(...skipping 24 matching lines...) Expand all Loading... |
108 << media::VideoFrame::FormatToString(input_format) | 107 << media::VideoFrame::FormatToString(input_format) |
109 << ", input_visible_size=" << input_visible_size.ToString() | 108 << ", input_visible_size=" << input_visible_size.ToString() |
110 << ", output_profile=" << output_profile | 109 << ", output_profile=" << output_profile |
111 << ", initial_bitrate=" << initial_bitrate; | 110 << ", initial_bitrate=" << initial_bitrate; |
112 | 111 |
113 visible_size_ = input_visible_size; | 112 visible_size_ = input_visible_size; |
114 | 113 |
115 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 114 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
116 client_ = client_ptr_factory_->GetWeakPtr(); | 115 client_ = client_ptr_factory_->GetWeakPtr(); |
117 | 116 |
118 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 117 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
119 DCHECK_EQ(encoder_state_, kUninitialized); | 118 DCHECK_EQ(encoder_state_, kUninitialized); |
120 | 119 |
121 struct v4l2_capability caps; | 120 struct v4l2_capability caps; |
122 memset(&caps, 0, sizeof(caps)); | 121 memset(&caps, 0, sizeof(caps)); |
123 const __u32 kCapsRequired = V4L2_CAP_VIDEO_CAPTURE_MPLANE | | 122 const __u32 kCapsRequired = V4L2_CAP_VIDEO_CAPTURE_MPLANE | |
124 V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_STREAMING; | 123 V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_STREAMING; |
125 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_QUERYCAP, &caps); | 124 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_QUERYCAP, &caps); |
126 if ((caps.capabilities & kCapsRequired) != kCapsRequired) { | 125 if ((caps.capabilities & kCapsRequired) != kCapsRequired) { |
127 LOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP: " | 126 LOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP: " |
128 "caps check failed: 0x" << std::hex << caps.capabilities; | 127 "caps check failed: 0x" << std::hex << caps.capabilities; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 165 |
167 if (!encoder_thread_.Start()) { | 166 if (!encoder_thread_.Start()) { |
168 LOG(ERROR) << "Initialize(): encoder thread failed to start"; | 167 LOG(ERROR) << "Initialize(): encoder thread failed to start"; |
169 return false; | 168 return false; |
170 } | 169 } |
171 | 170 |
172 RequestEncodingParametersChange(initial_bitrate, kInitialFramerate); | 171 RequestEncodingParametersChange(initial_bitrate, kInitialFramerate); |
173 | 172 |
174 encoder_state_ = kInitialized; | 173 encoder_state_ = kInitialized; |
175 | 174 |
176 child_message_loop_proxy_->PostTask( | 175 child_task_runner_->PostTask( |
177 FROM_HERE, | 176 FROM_HERE, |
178 base::Bind(&Client::RequireBitstreamBuffers, | 177 base::Bind(&Client::RequireBitstreamBuffers, client_, kInputBufferCount, |
179 client_, | 178 image_processor_.get() |
180 kInputBufferCount, | 179 ? image_processor_->input_allocated_size() |
181 image_processor_.get() ? | 180 : input_allocated_size_, |
182 image_processor_->input_allocated_size() : | |
183 input_allocated_size_, | |
184 output_buffer_byte_size_)); | 181 output_buffer_byte_size_)); |
185 return true; | 182 return true; |
186 } | 183 } |
187 | 184 |
188 void V4L2VideoEncodeAccelerator::ImageProcessorError() { | 185 void V4L2VideoEncodeAccelerator::ImageProcessorError() { |
189 LOG(ERROR) << "Image processor error"; | 186 LOG(ERROR) << "Image processor error"; |
190 NOTIFY_ERROR(kPlatformFailureError); | 187 NOTIFY_ERROR(kPlatformFailureError); |
191 } | 188 } |
192 | 189 |
193 void V4L2VideoEncodeAccelerator::Encode( | 190 void V4L2VideoEncodeAccelerator::Encode( |
194 const scoped_refptr<media::VideoFrame>& frame, | 191 const scoped_refptr<media::VideoFrame>& frame, |
195 bool force_keyframe) { | 192 bool force_keyframe) { |
196 DVLOG(3) << "Encode(): force_keyframe=" << force_keyframe; | 193 DVLOG(3) << "Encode(): force_keyframe=" << force_keyframe; |
197 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 194 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
198 | 195 |
199 if (image_processor_) { | 196 if (image_processor_) { |
200 image_processor_->Process( | 197 image_processor_->Process( |
201 frame, | 198 frame, |
202 base::Bind(&V4L2VideoEncodeAccelerator::FrameProcessed, | 199 base::Bind(&V4L2VideoEncodeAccelerator::FrameProcessed, |
203 weak_this_, | 200 weak_this_, |
204 force_keyframe)); | 201 force_keyframe)); |
205 } else { | 202 } else { |
206 encoder_thread_.message_loop()->PostTask( | 203 encoder_thread_.message_loop()->PostTask( |
207 FROM_HERE, | 204 FROM_HERE, |
208 base::Bind(&V4L2VideoEncodeAccelerator::EncodeTask, | 205 base::Bind(&V4L2VideoEncodeAccelerator::EncodeTask, |
209 base::Unretained(this), | 206 base::Unretained(this), |
210 frame, | 207 frame, |
211 force_keyframe)); | 208 force_keyframe)); |
212 } | 209 } |
213 } | 210 } |
214 | 211 |
215 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( | 212 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( |
216 const media::BitstreamBuffer& buffer) { | 213 const media::BitstreamBuffer& buffer) { |
217 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); | 214 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); |
218 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 215 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
219 | 216 |
220 if (buffer.size() < output_buffer_byte_size_) { | 217 if (buffer.size() < output_buffer_byte_size_) { |
221 NOTIFY_ERROR(kInvalidArgumentError); | 218 NOTIFY_ERROR(kInvalidArgumentError); |
222 return; | 219 return; |
223 } | 220 } |
224 | 221 |
225 scoped_ptr<base::SharedMemory> shm( | 222 scoped_ptr<base::SharedMemory> shm( |
226 new base::SharedMemory(buffer.handle(), false)); | 223 new base::SharedMemory(buffer.handle(), false)); |
227 if (!shm->Map(buffer.size())) { | 224 if (!shm->Map(buffer.size())) { |
228 NOTIFY_ERROR(kPlatformFailureError); | 225 NOTIFY_ERROR(kPlatformFailureError); |
229 return; | 226 return; |
230 } | 227 } |
231 | 228 |
232 scoped_ptr<BitstreamBufferRef> buffer_ref( | 229 scoped_ptr<BitstreamBufferRef> buffer_ref( |
233 new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size())); | 230 new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size())); |
234 encoder_thread_.message_loop()->PostTask( | 231 encoder_thread_.message_loop()->PostTask( |
235 FROM_HERE, | 232 FROM_HERE, |
236 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, | 233 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, |
237 base::Unretained(this), | 234 base::Unretained(this), |
238 base::Passed(&buffer_ref))); | 235 base::Passed(&buffer_ref))); |
239 } | 236 } |
240 | 237 |
241 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( | 238 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( |
242 uint32 bitrate, | 239 uint32 bitrate, |
243 uint32 framerate) { | 240 uint32 framerate) { |
244 DVLOG(3) << "RequestEncodingParametersChange(): bitrate=" << bitrate | 241 DVLOG(3) << "RequestEncodingParametersChange(): bitrate=" << bitrate |
245 << ", framerate=" << framerate; | 242 << ", framerate=" << framerate; |
246 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 243 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
247 | 244 |
248 encoder_thread_.message_loop()->PostTask( | 245 encoder_thread_.message_loop()->PostTask( |
249 FROM_HERE, | 246 FROM_HERE, |
250 base::Bind( | 247 base::Bind( |
251 &V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask, | 248 &V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask, |
252 base::Unretained(this), | 249 base::Unretained(this), |
253 bitrate, | 250 bitrate, |
254 framerate)); | 251 framerate)); |
255 } | 252 } |
256 | 253 |
257 void V4L2VideoEncodeAccelerator::Destroy() { | 254 void V4L2VideoEncodeAccelerator::Destroy() { |
258 DVLOG(3) << "Destroy()"; | 255 DVLOG(3) << "Destroy()"; |
259 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 256 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
260 | 257 |
261 // We're destroying; cancel all callbacks. | 258 // We're destroying; cancel all callbacks. |
262 client_ptr_factory_.reset(); | 259 client_ptr_factory_.reset(); |
263 weak_this_ptr_factory_.InvalidateWeakPtrs(); | 260 weak_this_ptr_factory_.InvalidateWeakPtrs(); |
264 | 261 |
265 if (image_processor_.get()) | 262 if (image_processor_.get()) |
266 image_processor_.release()->Destroy(); | 263 image_processor_.release()->Destroy(); |
267 | 264 |
268 // If the encoder thread is running, destroy using posted task. | 265 // If the encoder thread is running, destroy using posted task. |
269 if (encoder_thread_.IsRunning()) { | 266 if (encoder_thread_.IsRunning()) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 break; | 309 break; |
313 } | 310 } |
314 } | 311 } |
315 | 312 |
316 return profiles; | 313 return profiles; |
317 } | 314 } |
318 | 315 |
319 void V4L2VideoEncodeAccelerator::FrameProcessed( | 316 void V4L2VideoEncodeAccelerator::FrameProcessed( |
320 bool force_keyframe, | 317 bool force_keyframe, |
321 const scoped_refptr<media::VideoFrame>& frame) { | 318 const scoped_refptr<media::VideoFrame>& frame) { |
322 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 319 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
323 DVLOG(3) << "FrameProcessed(): force_keyframe=" << force_keyframe; | 320 DVLOG(3) << "FrameProcessed(): force_keyframe=" << force_keyframe; |
324 | 321 |
325 encoder_thread_.message_loop()->PostTask( | 322 encoder_thread_.message_loop()->PostTask( |
326 FROM_HERE, | 323 FROM_HERE, |
327 base::Bind(&V4L2VideoEncodeAccelerator::EncodeTask, | 324 base::Bind(&V4L2VideoEncodeAccelerator::EncodeTask, |
328 base::Unretained(this), | 325 base::Unretained(this), |
329 frame, | 326 frame, |
330 force_keyframe)); | 327 force_keyframe)); |
331 } | 328 } |
332 | 329 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 } else { | 572 } else { |
576 memcpy(target_data, output_data, output_size); | 573 memcpy(target_data, output_data, output_size); |
577 } | 574 } |
578 } else { | 575 } else { |
579 memcpy(target_data, output_data, output_size); | 576 memcpy(target_data, output_data, output_size); |
580 } | 577 } |
581 | 578 |
582 DVLOG(3) << "Dequeue(): returning " | 579 DVLOG(3) << "Dequeue(): returning " |
583 "bitstream_buffer_id=" << output_record.buffer_ref->id | 580 "bitstream_buffer_id=" << output_record.buffer_ref->id |
584 << ", size=" << output_size << ", key_frame=" << key_frame; | 581 << ", size=" << output_size << ", key_frame=" << key_frame; |
585 child_message_loop_proxy_->PostTask( | 582 child_task_runner_->PostTask( |
586 FROM_HERE, | 583 FROM_HERE, |
587 base::Bind(&Client::BitstreamBufferReady, | 584 base::Bind(&Client::BitstreamBufferReady, client_, |
588 client_, | 585 output_record.buffer_ref->id, output_size, key_frame)); |
589 output_record.buffer_ref->id, | |
590 output_size, | |
591 key_frame)); | |
592 output_record.at_device = false; | 586 output_record.at_device = false; |
593 output_record.buffer_ref.reset(); | 587 output_record.buffer_ref.reset(); |
594 free_output_buffers_.push_back(dqbuf.index); | 588 free_output_buffers_.push_back(dqbuf.index); |
595 output_buffer_queued_count_--; | 589 output_buffer_queued_count_--; |
596 } | 590 } |
597 } | 591 } |
598 | 592 |
599 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { | 593 bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() { |
600 DVLOG(3) << "EnqueueInputRecord()"; | 594 DVLOG(3) << "EnqueueInputRecord()"; |
601 DCHECK(!free_input_buffers_.empty()); | 595 DCHECK(!free_input_buffers_.empty()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 // touch encoder state from this thread. | 759 // touch encoder state from this thread. |
766 encoder_thread_.message_loop()->PostTask( | 760 encoder_thread_.message_loop()->PostTask( |
767 FROM_HERE, | 761 FROM_HERE, |
768 base::Bind(&V4L2VideoEncodeAccelerator::ServiceDeviceTask, | 762 base::Bind(&V4L2VideoEncodeAccelerator::ServiceDeviceTask, |
769 base::Unretained(this))); | 763 base::Unretained(this))); |
770 } | 764 } |
771 | 765 |
772 void V4L2VideoEncodeAccelerator::NotifyError(Error error) { | 766 void V4L2VideoEncodeAccelerator::NotifyError(Error error) { |
773 DVLOG(1) << "NotifyError(): error=" << error; | 767 DVLOG(1) << "NotifyError(): error=" << error; |
774 | 768 |
775 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { | 769 if (!child_task_runner_->BelongsToCurrentThread()) { |
776 child_message_loop_proxy_->PostTask( | 770 child_task_runner_->PostTask( |
777 FROM_HERE, | 771 FROM_HERE, base::Bind(&V4L2VideoEncodeAccelerator::NotifyError, |
778 base::Bind( | 772 weak_this_, error)); |
779 &V4L2VideoEncodeAccelerator::NotifyError, weak_this_, error)); | |
780 return; | 773 return; |
781 } | 774 } |
782 | 775 |
783 if (client_) { | 776 if (client_) { |
784 client_->NotifyError(error); | 777 client_->NotifyError(error); |
785 client_ptr_factory_.reset(); | 778 client_ptr_factory_.reset(); |
786 } | 779 } |
787 } | 780 } |
788 | 781 |
789 void V4L2VideoEncodeAccelerator::SetErrorState(Error error) { | 782 void V4L2VideoEncodeAccelerator::SetErrorState(Error error) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 parms.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 827 parms.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
835 // Note that we are provided "frames per second" but V4L2 expects "time per | 828 // Note that we are provided "frames per second" but V4L2 expects "time per |
836 // frame"; hence we provide the reciprocal of the framerate here. | 829 // frame"; hence we provide the reciprocal of the framerate here. |
837 parms.parm.output.timeperframe.numerator = 1; | 830 parms.parm.output.timeperframe.numerator = 1; |
838 parms.parm.output.timeperframe.denominator = framerate; | 831 parms.parm.output.timeperframe.denominator = framerate; |
839 IOCTL_OR_ERROR_RETURN(VIDIOC_S_PARM, &parms); | 832 IOCTL_OR_ERROR_RETURN(VIDIOC_S_PARM, &parms); |
840 } | 833 } |
841 | 834 |
842 bool V4L2VideoEncodeAccelerator::SetOutputFormat( | 835 bool V4L2VideoEncodeAccelerator::SetOutputFormat( |
843 media::VideoCodecProfile output_profile) { | 836 media::VideoCodecProfile output_profile) { |
844 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 837 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
845 DCHECK(!input_streamon_); | 838 DCHECK(!input_streamon_); |
846 DCHECK(!output_streamon_); | 839 DCHECK(!output_streamon_); |
847 | 840 |
848 output_format_fourcc_ = | 841 output_format_fourcc_ = |
849 V4L2Device::VideoCodecProfileToV4L2PixFmt(output_profile, false); | 842 V4L2Device::VideoCodecProfileToV4L2PixFmt(output_profile, false); |
850 if (!output_format_fourcc_) { | 843 if (!output_format_fourcc_) { |
851 LOG(ERROR) << "Initialize(): invalid output_profile=" << output_profile; | 844 LOG(ERROR) << "Initialize(): invalid output_profile=" << output_profile; |
852 return false; | 845 return false; |
853 } | 846 } |
854 | 847 |
(...skipping 14 matching lines...) Expand all Loading... |
869 size_t adjusted_output_buffer_size = | 862 size_t adjusted_output_buffer_size = |
870 base::checked_cast<size_t>(format.fmt.pix_mp.plane_fmt[0].sizeimage); | 863 base::checked_cast<size_t>(format.fmt.pix_mp.plane_fmt[0].sizeimage); |
871 output_buffer_byte_size_ = adjusted_output_buffer_size; | 864 output_buffer_byte_size_ = adjusted_output_buffer_size; |
872 | 865 |
873 return true; | 866 return true; |
874 } | 867 } |
875 | 868 |
876 bool V4L2VideoEncodeAccelerator::NegotiateInputFormat( | 869 bool V4L2VideoEncodeAccelerator::NegotiateInputFormat( |
877 media::VideoFrame::Format input_format) { | 870 media::VideoFrame::Format input_format) { |
878 DVLOG(3) << "NegotiateInputFormat()"; | 871 DVLOG(3) << "NegotiateInputFormat()"; |
879 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 872 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
880 DCHECK(!input_streamon_); | 873 DCHECK(!input_streamon_); |
881 DCHECK(!output_streamon_); | 874 DCHECK(!output_streamon_); |
882 | 875 |
883 device_input_format_ = media::VideoFrame::UNKNOWN; | 876 device_input_format_ = media::VideoFrame::UNKNOWN; |
884 input_planes_count_ = 0; | 877 input_planes_count_ = 0; |
885 | 878 |
886 uint32 input_format_fourcc = | 879 uint32 input_format_fourcc = |
887 V4L2Device::VideoFrameFormatToV4L2PixFmt(input_format); | 880 V4L2Device::VideoFrameFormatToV4L2PixFmt(input_format); |
888 if (!input_format_fourcc) { | 881 if (!input_format_fourcc) { |
889 LOG(ERROR) << "Unsupported input format"; | 882 LOG(ERROR) << "Unsupported input format"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 922 |
930 device_input_format_ = input_format; | 923 device_input_format_ = input_format; |
931 input_planes_count_ = input_planes_count; | 924 input_planes_count_ = input_planes_count; |
932 return true; | 925 return true; |
933 } | 926 } |
934 | 927 |
935 bool V4L2VideoEncodeAccelerator::SetFormats( | 928 bool V4L2VideoEncodeAccelerator::SetFormats( |
936 media::VideoFrame::Format input_format, | 929 media::VideoFrame::Format input_format, |
937 media::VideoCodecProfile output_profile) { | 930 media::VideoCodecProfile output_profile) { |
938 DVLOG(3) << "SetFormats()"; | 931 DVLOG(3) << "SetFormats()"; |
939 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 932 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
940 DCHECK(!input_streamon_); | 933 DCHECK(!input_streamon_); |
941 DCHECK(!output_streamon_); | 934 DCHECK(!output_streamon_); |
942 | 935 |
943 if (!SetOutputFormat(output_profile)) | 936 if (!SetOutputFormat(output_profile)) |
944 return false; | 937 return false; |
945 | 938 |
946 if (!NegotiateInputFormat(input_format)) | 939 if (!NegotiateInputFormat(input_format)) |
947 return false; | 940 return false; |
948 | 941 |
949 struct v4l2_crop crop; | 942 struct v4l2_crop crop; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 DCHECK(input_buffer_map_.empty()); | 1062 DCHECK(input_buffer_map_.empty()); |
1070 input_buffer_map_.resize(reqbufs.count); | 1063 input_buffer_map_.resize(reqbufs.count); |
1071 for (size_t i = 0; i < input_buffer_map_.size(); ++i) | 1064 for (size_t i = 0; i < input_buffer_map_.size(); ++i) |
1072 free_input_buffers_.push_back(i); | 1065 free_input_buffers_.push_back(i); |
1073 | 1066 |
1074 return true; | 1067 return true; |
1075 } | 1068 } |
1076 | 1069 |
1077 bool V4L2VideoEncodeAccelerator::CreateOutputBuffers() { | 1070 bool V4L2VideoEncodeAccelerator::CreateOutputBuffers() { |
1078 DVLOG(3) << "CreateOutputBuffers()"; | 1071 DVLOG(3) << "CreateOutputBuffers()"; |
1079 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1072 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
1080 DCHECK(!output_streamon_); | 1073 DCHECK(!output_streamon_); |
1081 | 1074 |
1082 struct v4l2_requestbuffers reqbufs; | 1075 struct v4l2_requestbuffers reqbufs; |
1083 memset(&reqbufs, 0, sizeof(reqbufs)); | 1076 memset(&reqbufs, 0, sizeof(reqbufs)); |
1084 reqbufs.count = kOutputBufferCount; | 1077 reqbufs.count = kOutputBufferCount; |
1085 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1078 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1086 reqbufs.memory = V4L2_MEMORY_MMAP; | 1079 reqbufs.memory = V4L2_MEMORY_MMAP; |
1087 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs); | 1080 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs); |
1088 | 1081 |
1089 DCHECK(output_buffer_map_.empty()); | 1082 DCHECK(output_buffer_map_.empty()); |
(...skipping 21 matching lines...) Expand all Loading... |
1111 output_buffer_map_[i].address = address; | 1104 output_buffer_map_[i].address = address; |
1112 output_buffer_map_[i].length = buffer.m.planes[0].length; | 1105 output_buffer_map_[i].length = buffer.m.planes[0].length; |
1113 free_output_buffers_.push_back(i); | 1106 free_output_buffers_.push_back(i); |
1114 } | 1107 } |
1115 | 1108 |
1116 return true; | 1109 return true; |
1117 } | 1110 } |
1118 | 1111 |
1119 void V4L2VideoEncodeAccelerator::DestroyInputBuffers() { | 1112 void V4L2VideoEncodeAccelerator::DestroyInputBuffers() { |
1120 DVLOG(3) << "DestroyInputBuffers()"; | 1113 DVLOG(3) << "DestroyInputBuffers()"; |
1121 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1114 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
1122 DCHECK(!input_streamon_); | 1115 DCHECK(!input_streamon_); |
1123 | 1116 |
1124 struct v4l2_requestbuffers reqbufs; | 1117 struct v4l2_requestbuffers reqbufs; |
1125 memset(&reqbufs, 0, sizeof(reqbufs)); | 1118 memset(&reqbufs, 0, sizeof(reqbufs)); |
1126 reqbufs.count = 0; | 1119 reqbufs.count = 0; |
1127 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1120 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1128 reqbufs.memory = input_memory_type_; | 1121 reqbufs.memory = input_memory_type_; |
1129 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1122 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
1130 | 1123 |
1131 input_buffer_map_.clear(); | 1124 input_buffer_map_.clear(); |
1132 free_input_buffers_.clear(); | 1125 free_input_buffers_.clear(); |
1133 } | 1126 } |
1134 | 1127 |
1135 void V4L2VideoEncodeAccelerator::DestroyOutputBuffers() { | 1128 void V4L2VideoEncodeAccelerator::DestroyOutputBuffers() { |
1136 DVLOG(3) << "DestroyOutputBuffers()"; | 1129 DVLOG(3) << "DestroyOutputBuffers()"; |
1137 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | 1130 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
1138 DCHECK(!output_streamon_); | 1131 DCHECK(!output_streamon_); |
1139 | 1132 |
1140 for (size_t i = 0; i < output_buffer_map_.size(); ++i) { | 1133 for (size_t i = 0; i < output_buffer_map_.size(); ++i) { |
1141 if (output_buffer_map_[i].address != NULL) | 1134 if (output_buffer_map_[i].address != NULL) |
1142 device_->Munmap(output_buffer_map_[i].address, | 1135 device_->Munmap(output_buffer_map_[i].address, |
1143 output_buffer_map_[i].length); | 1136 output_buffer_map_[i].length); |
1144 } | 1137 } |
1145 | 1138 |
1146 struct v4l2_requestbuffers reqbufs; | 1139 struct v4l2_requestbuffers reqbufs; |
1147 memset(&reqbufs, 0, sizeof(reqbufs)); | 1140 memset(&reqbufs, 0, sizeof(reqbufs)); |
1148 reqbufs.count = 0; | 1141 reqbufs.count = 0; |
1149 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1142 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1150 reqbufs.memory = V4L2_MEMORY_MMAP; | 1143 reqbufs.memory = V4L2_MEMORY_MMAP; |
1151 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1144 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
1152 | 1145 |
1153 output_buffer_map_.clear(); | 1146 output_buffer_map_.clear(); |
1154 free_output_buffers_.clear(); | 1147 free_output_buffers_.clear(); |
1155 } | 1148 } |
1156 | 1149 |
1157 } // namespace content | 1150 } // namespace content |
OLD | NEW |