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

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 review comments and rebase Created 4 years, 9 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( 215 void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer(
218 const media::BitstreamBuffer& buffer) { 216 const media::BitstreamBuffer& buffer) {
219 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); 217 DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id();
220 DCHECK(child_task_runner_->BelongsToCurrentThread()); 218 DCHECK(child_task_runner_->BelongsToCurrentThread());
221 219
222 if (buffer.size() < output_buffer_byte_size_) { 220 if (buffer.size() < output_buffer_byte_size_) {
223 NOTIFY_ERROR(kInvalidArgumentError); 221 NOTIFY_ERROR(kInvalidArgumentError);
224 return; 222 return;
225 } 223 }
226 224
227 scoped_ptr<base::SharedMemory> shm( 225 scoped_ptr<SharedMemoryRegion> shm(new SharedMemoryRegion(buffer, false));
228 new base::SharedMemory(buffer.handle(), false)); 226 if (!shm->Map()) {
229 if (!shm->Map(buffer.size())) {
230 NOTIFY_ERROR(kPlatformFailureError); 227 NOTIFY_ERROR(kPlatformFailureError);
231 return; 228 return;
232 } 229 }
233 230
234 scoped_ptr<BitstreamBufferRef> buffer_ref( 231 scoped_ptr<BitstreamBufferRef> buffer_ref(
235 new BitstreamBufferRef(buffer.id(), std::move(shm), buffer.size())); 232 new BitstreamBufferRef(buffer.id(), std::move(shm)));
236 encoder_thread_.message_loop()->PostTask( 233 encoder_thread_.message_loop()->PostTask(
237 FROM_HERE, 234 FROM_HERE,
238 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask, 235 base::Bind(&V4L2VideoEncodeAccelerator::UseOutputBitstreamBufferTask,
239 base::Unretained(this), 236 base::Unretained(this),
240 base::Passed(&buffer_ref))); 237 base::Passed(&buffer_ref)));
241 } 238 }
242 239
243 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( 240 void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange(
244 uint32_t bitrate, 241 uint32_t bitrate,
245 uint32_t framerate) { 242 uint32_t framerate) {
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 reqbufs.count = 0; 1171 reqbufs.count = 0;
1175 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1172 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1176 reqbufs.memory = V4L2_MEMORY_MMAP; 1173 reqbufs.memory = V4L2_MEMORY_MMAP;
1177 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); 1174 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs);
1178 1175
1179 output_buffer_map_.clear(); 1176 output_buffer_map_.clear();
1180 free_output_buffers_.clear(); 1177 free_output_buffers_.clear();
1181 } 1178 }
1182 1179
1183 } // namespace content 1180 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/v4l2_video_decode_accelerator.cc ('k') | content/common/gpu/media/vaapi_jpeg_decode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698