| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 scoped_refptr<V4L2Device> device = | 175 scoped_refptr<V4L2Device> device = |
| 176 V4L2Device::Create(V4L2Device::kImageProcessor); | 176 V4L2Device::Create(V4L2Device::kImageProcessor); |
| 177 image_processor_.reset(new V4L2ImageProcessor(device)); | 177 image_processor_.reset(new V4L2ImageProcessor(device)); |
| 178 | 178 |
| 179 // Convert from input_format to device_input_format_, keeping the size | 179 // Convert from input_format to device_input_format_, keeping the size |
| 180 // at visible_size_ and requiring the output buffers to be of at least | 180 // at visible_size_ and requiring the output buffers to be of at least |
| 181 // input_allocated_size_. Unretained is safe because |this| owns image | 181 // input_allocated_size_. Unretained is safe because |this| owns image |
| 182 // processor and there will be no callbacks after processor destroys. | 182 // processor and there will be no callbacks after processor destroys. |
| 183 if (!image_processor_->Initialize( | 183 if (!image_processor_->Initialize( |
| 184 input_format, device_input_format_, V4L2_MEMORY_USERPTR, | 184 input_format, device_input_format_, V4L2_MEMORY_USERPTR, |
| 185 visible_size_, visible_size_, visible_size_, input_allocated_size_, | 185 V4L2_MEMORY_MMAP, visible_size_, visible_size_, visible_size_, |
| 186 kImageProcBufferCount, | 186 input_allocated_size_, kImageProcBufferCount, |
| 187 base::Bind(&V4L2VideoEncodeAccelerator::ImageProcessorError, | 187 base::Bind(&V4L2VideoEncodeAccelerator::ImageProcessorError, |
| 188 base::Unretained(this)))) { | 188 base::Unretained(this)))) { |
| 189 LOG(ERROR) << "Failed initializing image processor"; | 189 LOG(ERROR) << "Failed initializing image processor"; |
| 190 return false; | 190 return false; |
| 191 } | 191 } |
| 192 // The output of image processor is the input of encoder. Output coded | 192 // The output of image processor is the input of encoder. Output coded |
| 193 // width of processor must be the same as input coded width of encoder. | 193 // width of processor must be the same as input coded width of encoder. |
| 194 // Output coded height of processor can be larger but not smaller than the | 194 // Output coded height of processor can be larger but not smaller than the |
| 195 // input coded height of encoder. For example, suppose input size of encoder | 195 // input coded height of encoder. For example, suppose input size of encoder |
| 196 // is 320x193. It is OK if the output of processor is 320x208. | 196 // is 320x193. It is OK if the output of processor is 320x208. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 DVLOG(3) << "Encode(): force_keyframe=" << force_keyframe; | 252 DVLOG(3) << "Encode(): force_keyframe=" << force_keyframe; |
| 253 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 253 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
| 254 | 254 |
| 255 if (image_processor_) { | 255 if (image_processor_) { |
| 256 if (free_image_processor_output_buffers_.size() > 0) { | 256 if (free_image_processor_output_buffers_.size() > 0) { |
| 257 int output_buffer_index = free_image_processor_output_buffers_.back(); | 257 int output_buffer_index = free_image_processor_output_buffers_.back(); |
| 258 free_image_processor_output_buffers_.pop_back(); | 258 free_image_processor_output_buffers_.pop_back(); |
| 259 // Unretained is safe because |this| owns image processor and there will | 259 // Unretained is safe because |this| owns image processor and there will |
| 260 // be no callbacks after processor destroys. | 260 // be no callbacks after processor destroys. |
| 261 image_processor_->Process( | 261 image_processor_->Process( |
| 262 frame, output_buffer_index, | 262 frame, output_buffer_index, std::vector<base::ScopedFD>(), |
| 263 base::Bind(&V4L2VideoEncodeAccelerator::FrameProcessed, | 263 base::Bind(&V4L2VideoEncodeAccelerator::FrameProcessed, |
| 264 base::Unretained(this), force_keyframe, | 264 base::Unretained(this), force_keyframe, |
| 265 frame->timestamp())); | 265 frame->timestamp())); |
| 266 } else { | 266 } else { |
| 267 ImageProcessorInputRecord record; | 267 ImageProcessorInputRecord record; |
| 268 record.frame = frame; | 268 record.frame = frame; |
| 269 record.force_keyframe = force_keyframe; | 269 record.force_keyframe = force_keyframe; |
| 270 image_processor_input_queue_.push(record); | 270 image_processor_input_queue_.push(record); |
| 271 } | 271 } |
| 272 } else { | 272 } else { |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 reqbufs.count = 0; | 1340 reqbufs.count = 0; |
| 1341 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1341 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1342 reqbufs.memory = V4L2_MEMORY_MMAP; | 1342 reqbufs.memory = V4L2_MEMORY_MMAP; |
| 1343 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1343 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
| 1344 | 1344 |
| 1345 output_buffer_map_.clear(); | 1345 output_buffer_map_.clear(); |
| 1346 free_output_buffers_.clear(); | 1346 free_output_buffers_.clear(); |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 } // namespace media | 1349 } // namespace media |
| OLD | NEW |