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/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "content/common/gpu/media/shared_memory_region.h" | |
17 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 18 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
19 #include "media/base/bitstream_buffer.h" | 20 #include "media/base/bitstream_buffer.h" |
20 | 21 |
21 #define NOTIFY_ERROR(x) \ | 22 #define NOTIFY_ERROR(x) \ |
22 do { \ | 23 do { \ |
23 LOG(ERROR) << "Setting error state:" << x; \ | 24 LOG(ERROR) << "Setting error state:" << x; \ |
24 SetErrorState(x); \ | 25 SetErrorState(x); \ |
25 } while (0) | 26 } while (0) |
26 | 27 |
(...skipping 14 matching lines...) Expand all Loading... | |
41 | 42 |
42 #define IOCTL_OR_LOG_ERROR(type, arg) \ | 43 #define IOCTL_OR_LOG_ERROR(type, arg) \ |
43 do { \ | 44 do { \ |
44 if (device_->Ioctl(type, arg) != 0) \ | 45 if (device_->Ioctl(type, arg) != 0) \ |
45 PLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ | 46 PLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ |
46 } while (0) | 47 } while (0) |
47 | 48 |
48 namespace content { | 49 namespace content { |
49 | 50 |
50 struct V4L2VideoEncodeAccelerator::BitstreamBufferRef { | 51 struct V4L2VideoEncodeAccelerator::BitstreamBufferRef { |
51 BitstreamBufferRef(int32 id, scoped_ptr<base::SharedMemory> shm, size_t size) | 52 BitstreamBufferRef(int32 id, scoped_ptr<SharedMemoryRegion> shm) |
52 : id(id), shm(shm.Pass()), size(size) {} | 53 : id(id), shm(shm.Pass()) {} |
Pawel Osciak
2015/12/31 02:05:54
std::move(shm) should work here.
Owen Lin
2016/01/04 08:54:17
Done.
| |
53 const int32 id; | 54 const int32 id; |
54 const scoped_ptr<base::SharedMemory> shm; | 55 const scoped_ptr<SharedMemoryRegion> shm; |
55 const size_t size; | |
56 }; | 56 }; |
57 | 57 |
58 V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) { | 58 V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) { |
59 } | 59 } |
60 | 60 |
61 V4L2VideoEncodeAccelerator::InputRecord::~InputRecord() { | 61 V4L2VideoEncodeAccelerator::InputRecord::~InputRecord() { |
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) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( | 213 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( |
214 const media::BitstreamBuffer& buffer) { | 214 const media::BitstreamBuffer& buffer) { |
215 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); | 215 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); |
216 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 216 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
217 | 217 |
218 if (buffer.size() < output_buffer_byte_size_) { | 218 if (buffer.size() < output_buffer_byte_size_) { |
219 NOTIFY_ERROR(kInvalidArgumentError); | 219 NOTIFY_ERROR(kInvalidArgumentError); |
220 return; | 220 return; |
221 } | 221 } |
222 | 222 |
223 scoped_ptr<base::SharedMemory> shm( | 223 scoped_ptr<SharedMemoryRegion> shm(new SharedMemoryRegion(buffer, false)); |
224 new base::SharedMemory(buffer.handle(), false)); | 224 if (!shm->Map()) { |
225 if (!shm->Map(buffer.size())) { | |
226 NOTIFY_ERROR(kPlatformFailureError); | 225 NOTIFY_ERROR(kPlatformFailureError); |
227 return; | 226 return; |
228 } | 227 } |
229 | 228 |
230 scoped_ptr<BitstreamBufferRef> buffer_ref( | 229 scoped_ptr<BitstreamBufferRef> buffer_ref( |
231 new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size())); | 230 new BitstreamBufferRef(buffer.id(), shm.Pass())); |
Pawel Osciak
2015/12/31 02:05:54
std::move(shm)
Owen Lin
2016/01/04 08:54:18
Done.
| |
232 encoder_thread_.message_loop()->PostTask( | 231 encoder_thread_.message_loop()->PostTask( |
233 FROM_HERE, | 232 FROM_HERE, |
234 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, | 233 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, |
235 base::Unretained(this), | 234 base::Unretained(this), |
236 base::Passed(&buffer_ref))); | 235 base::Passed(&buffer_ref))); |
237 } | 236 } |
238 | 237 |
239 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( | 238 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( |
240 uint32 bitrate, | 239 uint32 bitrate, |
241 uint32 framerate) { | 240 uint32 framerate) { |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 reqbufs.count = 0; | 1156 reqbufs.count = 0; |
1158 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1157 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1159 reqbufs.memory = V4L2_MEMORY_MMAP; | 1158 reqbufs.memory = V4L2_MEMORY_MMAP; |
1160 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1159 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
1161 | 1160 |
1162 output_buffer_map_.clear(); | 1161 output_buffer_map_.clear(); |
1163 free_output_buffers_.clear(); | 1162 free_output_buffers_.clear(); |
1164 } | 1163 } |
1165 | 1164 |
1166 } // namespace content | 1165 } // namespace content |
OLD | NEW |