| 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 <string.h> | 8 #include <string.h> |
| 9 #include <sys/eventfd.h> | 9 #include <sys/eventfd.h> |
| 10 #include <sys/ioctl.h> | 10 #include <sys/ioctl.h> |
| 11 #include <sys/mman.h> | 11 #include <sys/mman.h> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "content/common/gpu/media/shared_memory_region.h" |
| 19 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 20 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
| 20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 21 #include "media/base/bitstream_buffer.h" | 22 #include "media/base/bitstream_buffer.h" |
| 22 | 23 |
| 23 #define NOTIFY_ERROR(x) \ | 24 #define NOTIFY_ERROR(x) \ |
| 24 do { \ | 25 do { \ |
| 25 LOG(ERROR) << "Setting error state:" << x; \ | 26 LOG(ERROR) << "Setting error state:" << x; \ |
| 26 SetErrorState(x); \ | 27 SetErrorState(x); \ |
| 27 } while (0) | 28 } while (0) |
| 28 | 29 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 #define IOCTL_OR_LOG_ERROR(type, arg) \ | 45 #define IOCTL_OR_LOG_ERROR(type, arg) \ |
| 45 do { \ | 46 do { \ |
| 46 if (device_->Ioctl(type, arg) != 0) \ | 47 if (device_->Ioctl(type, arg) != 0) \ |
| 47 PLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ | 48 PLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ |
| 48 } while (0) | 49 } while (0) |
| 49 | 50 |
| 50 namespace content { | 51 namespace content { |
| 51 | 52 |
| 52 struct V4L2VideoEncodeAccelerator::BitstreamBufferRef { | 53 struct V4L2VideoEncodeAccelerator::BitstreamBufferRef { |
| 53 BitstreamBufferRef(int32_t id, | 54 BitstreamBufferRef(int32_t id, scoped_ptr<SharedMemoryRegion> shm) |
| 54 scoped_ptr<base::SharedMemory> shm, | 55 : id(id), shm(std::move(shm)) {} |
| 55 size_t size) | |
| 56 : id(id), shm(shm.Pass()), size(size) {} | |
| 57 const int32_t id; | 56 const int32_t id; |
| 58 const scoped_ptr<base::SharedMemory> shm; | 57 const scoped_ptr<SharedMemoryRegion> shm; |
| 59 const size_t size; | |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) { | 60 V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) { |
| 63 } | 61 } |
| 64 | 62 |
| 65 V4L2VideoEncodeAccelerator::InputRecord::~InputRecord() { | 63 V4L2VideoEncodeAccelerator::InputRecord::~InputRecord() { |
| 66 } | 64 } |
| 67 | 65 |
| 68 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() | 66 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() |
| 69 : at_device(false), address(NULL), length(0) { | 67 : at_device(false), address(NULL), length(0) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( | 221 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( |
| 224 const media::BitstreamBuffer& buffer) { | 222 const media::BitstreamBuffer& buffer) { |
| 225 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); | 223 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); |
| 226 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 224 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
| 227 | 225 |
| 228 if (buffer.size() < output_buffer_byte_size_) { | 226 if (buffer.size() < output_buffer_byte_size_) { |
| 229 NOTIFY_ERROR(kInvalidArgumentError); | 227 NOTIFY_ERROR(kInvalidArgumentError); |
| 230 return; | 228 return; |
| 231 } | 229 } |
| 232 | 230 |
| 233 scoped_ptr<base::SharedMemory> shm( | 231 scoped_ptr<SharedMemoryRegion> shm(new SharedMemoryRegion(buffer, false)); |
| 234 new base::SharedMemory(buffer.handle(), false)); | 232 if (!shm->Map()) { |
| 235 if (!shm->Map(buffer.size())) { | |
| 236 NOTIFY_ERROR(kPlatformFailureError); | 233 NOTIFY_ERROR(kPlatformFailureError); |
| 237 return; | 234 return; |
| 238 } | 235 } |
| 239 | 236 |
| 240 scoped_ptr<BitstreamBufferRef> buffer_ref( | 237 scoped_ptr<BitstreamBufferRef> buffer_ref( |
| 241 new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size())); | 238 new BitstreamBufferRef(buffer.id(), std::move(shm))); |
| 242 encoder_thread_.message_loop()->PostTask( | 239 encoder_thread_.message_loop()->PostTask( |
| 243 FROM_HERE, | 240 FROM_HERE, |
| 244 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, | 241 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, |
| 245 base::Unretained(this), | 242 base::Unretained(this), |
| 246 base::Passed(&buffer_ref))); | 243 base::Passed(&buffer_ref))); |
| 247 } | 244 } |
| 248 | 245 |
| 249 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( | 246 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( |
| 250 uint32_t bitrate, | 247 uint32_t bitrate, |
| 251 uint32_t framerate) { | 248 uint32_t framerate) { |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 reqbufs.count = 0; | 1164 reqbufs.count = 0; |
| 1168 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1165 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1169 reqbufs.memory = V4L2_MEMORY_MMAP; | 1166 reqbufs.memory = V4L2_MEMORY_MMAP; |
| 1170 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1167 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
| 1171 | 1168 |
| 1172 output_buffer_map_.clear(); | 1169 output_buffer_map_.clear(); |
| 1173 free_output_buffers_.clear(); | 1170 free_output_buffers_.clear(); |
| 1174 } | 1171 } |
| 1175 | 1172 |
| 1176 } // namespace content | 1173 } // namespace content |
| OLD | NEW |