Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: content/common/gpu/media/v4l2_video_encode_accelerator.cc

Issue 1541353002: Add offset support to BitstreamBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nits and rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 12 #include <utility>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/numerics/safe_conversions.h" 17 #include "base/numerics/safe_conversions.h"
18 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
19 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
20 #include "content/common/gpu/media/shared_memory_region.h"
20 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" 21 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
21 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
22 #include "media/base/bitstream_buffer.h" 23 #include "media/base/bitstream_buffer.h"
23 24
24 #define NOTIFY_ERROR(x) \ 25 #define NOTIFY_ERROR(x) \
25 do { \ 26 do { \
26 LOG(ERROR) << "Setting error state:" << x; \ 27 LOG(ERROR) << "Setting error state:" << x; \
27 SetErrorState(x); \ 28 SetErrorState(x); \
28 } while (0) 29 } while (0)
29 30
(...skipping 14 matching lines...) Expand all
44 45
45 #define IOCTL_OR_LOG_ERROR(type, arg) \ 46 #define IOCTL_OR_LOG_ERROR(type, arg) \
46 do { \ 47 do { \
47 if (device_->Ioctl(type, arg) != 0) \ 48 if (device_->Ioctl(type, arg) != 0) \
48 PLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ 49 PLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \
49 } while (0) 50 } while (0)
50 51
51 namespace content { 52 namespace content {
52 53
53 struct V4L2VideoEncodeAccelerator::BitstreamBufferRef { 54 struct V4L2VideoEncodeAccelerator::BitstreamBufferRef {
54 BitstreamBufferRef(int32_t id, 55 BitstreamBufferRef(int32_t id, scoped_ptr<SharedMemoryRegion> shm)
55 scoped_ptr<base::SharedMemory> shm, 56 : id(id), shm(std::move(shm)) {}
56 size_t size)
57 : id(id), shm(std::move(shm)), size(size) {}
58 const int32_t id; 57 const int32_t id;
59 const scoped_ptr<base::SharedMemory> shm; 58 const scoped_ptr<SharedMemoryRegion> shm;
60 const size_t size;
61 }; 59 };
62 60
63 V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) { 61 V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) {
64 } 62 }
65 63
66 V4L2VideoEncodeAccelerator::InputRecord::~InputRecord() { 64 V4L2VideoEncodeAccelerator::InputRecord::~InputRecord() {
67 } 65 }
68 66
69 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord() 67 V4L2VideoEncodeAccelerator::OutputRecord::OutputRecord()
70 : at_device(false), address(NULL), length(0) { 68 : at_device(false), address(NULL), length(0) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( 222 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer(
225 const media::BitstreamBuffer& buffer) { 223 const media::BitstreamBuffer& buffer) {
226 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); 224 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id();
227 DCHECK(child_task_runner_->BelongsToCurrentThread()); 225 DCHECK(child_task_runner_->BelongsToCurrentThread());
228 226
229 if (buffer.size() < output_buffer_byte_size_) { 227 if (buffer.size() < output_buffer_byte_size_) {
230 NOTIFY_ERROR(kInvalidArgumentError); 228 NOTIFY_ERROR(kInvalidArgumentError);
231 return; 229 return;
232 } 230 }
233 231
234 scoped_ptr<base::SharedMemory> shm( 232 scoped_ptr<SharedMemoryRegion> shm(new SharedMemoryRegion(buffer, false));
235 new base::SharedMemory(buffer.handle(), false)); 233 if (!shm->Map()) {
236 if (!shm->Map(buffer.size())) {
237 NOTIFY_ERROR(kPlatformFailureError); 234 NOTIFY_ERROR(kPlatformFailureError);
238 return; 235 return;
239 } 236 }
240 237
241 scoped_ptr<BitstreamBufferRef> buffer_ref( 238 scoped_ptr<BitstreamBufferRef> buffer_ref(
242 new BitstreamBufferRef(buffer.id(), std::move(shm), buffer.size())); 239 new BitstreamBufferRef(buffer.id(), std::move(shm)));
243 encoder_thread_.message_loop()->PostTask( 240 encoder_thread_.message_loop()->PostTask(
244 FROM_HERE, 241 FROM_HERE,
245 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, 242 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask,
246 base::Unretained(this), 243 base::Unretained(this),
247 base::Passed(&buffer_ref))); 244 base::Passed(&buffer_ref)));
248 } 245 }
249 246
250 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( 247 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange(
251 uint32_t bitrate, 248 uint32_t bitrate,
252 uint32_t framerate) { 249 uint32_t framerate) {
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 reqbufs.count = 0; 1165 reqbufs.count = 0;
1169 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1166 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1170 reqbufs.memory = V4L2_MEMORY_MMAP; 1167 reqbufs.memory = V4L2_MEMORY_MMAP;
1171 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); 1168 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs);
1172 1169
1173 output_buffer_map_.clear(); 1170 output_buffer_map_.clear();
1174 free_output_buffers_.clear(); 1171 free_output_buffers_.clear();
1175 } 1172 }
1176 1173
1177 } // namespace content 1174 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698