1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
From 8c5e88c38c6ef5c9864016b90dfc3ae49cc11ddb Mon Sep 17 00:00:00 2001
From: Hou Qi <qi.hou@nxp.com>
Date: Fri, 2 Sep 2022 17:10:12 +0800
Subject: [PATCH 05/17] V4L2Buffer: Allocate correct v4l2 buffers for queues
For single plane queue, need to fill v4l2_planes_[0] with
correct size quried from v4l2 driver.
Upstream-Status: Inappropriate [NXP specific]
---
media/gpu/v4l2/v4l2_device.cc | 45 ++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/media/gpu/v4l2/v4l2_device.cc b/media/gpu/v4l2/v4l2_device.cc
index 8194d8646637c..9614eb8e71668 100644
--- a/media/gpu/v4l2/v4l2_device.cc
+++ b/media/gpu/v4l2/v4l2_device.cc
@@ -210,24 +210,30 @@ V4L2Buffer::V4L2Buffer(scoped_refptr<V4L2Device> device,
DCHECK(V4L2_TYPE_IS_MULTIPLANAR(type));
DCHECK_LE(format.fmt.pix_mp.num_planes, std::size(v4l2_planes_));
- memset(&v4l2_buffer_, 0, sizeof(v4l2_buffer_));
- memset(v4l2_planes_, 0, sizeof(v4l2_planes_));
- v4l2_buffer_.m.planes = v4l2_planes_;
- // Just in case we got more planes than we want.
- v4l2_buffer_.length =
- std::min(static_cast<size_t>(format.fmt.pix_mp.num_planes),
- std::size(v4l2_planes_));
+ if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
+ memset(&v4l2_buffer_, 0, sizeof(v4l2_buffer_));
+ memset(v4l2_planes_, 0, sizeof(v4l2_planes_));
+ v4l2_buffer_.m.planes = v4l2_planes_;
+ // Just in case we got more planes than we want.
+ v4l2_buffer_.length =
+ std::min(static_cast<size_t>(format.fmt.pix_mp.num_planes),
+ std::size(v4l2_planes_));
+ }
v4l2_buffer_.index = buffer_id;
v4l2_buffer_.type = type;
v4l2_buffer_.memory = memory;
- plane_mappings_.resize(v4l2_buffer_.length);
+ plane_mappings_.resize(V4L2_TYPE_IS_MULTIPLANAR(type) ? v4l2_buffer_.length : 1);
}
V4L2Buffer::~V4L2Buffer() {
if (v4l2_buffer_.memory == V4L2_MEMORY_MMAP) {
- for (size_t i = 0; i < plane_mappings_.size(); i++)
- if (plane_mappings_[i] != nullptr)
- device_->Munmap(plane_mappings_[i], v4l2_buffer_.m.planes[i].length);
+ for (size_t i = 0; i < plane_mappings_.size(); i++) {
+ if (plane_mappings_[i] != nullptr) {
+ unsigned int length = V4L2_TYPE_IS_MULTIPLANAR(v4l2_buffer_.type) ?
+ v4l2_buffer_.m.planes[i].length : v4l2_buffer_.length;
+ device_->Munmap(plane_mappings_[i], length);
+ }
+ }
}
}
@@ -238,6 +244,13 @@ bool V4L2Buffer::Query() {
return false;
}
+ if (!V4L2_TYPE_IS_MULTIPLANAR(v4l2_buffer_.type)) {
+ v4l2_planes_[0].bytesused = v4l2_buffer_.bytesused;
+ v4l2_planes_[0].length = v4l2_buffer_.length;
+ v4l2_planes_[0].data_offset = 0;
+ memcpy (&v4l2_planes_[0].m, &v4l2_buffer_.m, sizeof (v4l2_buffer_.m));
+ }
+
DCHECK(plane_mappings_.size() == v4l2_buffer_.length);
return true;
@@ -260,9 +273,13 @@ void* V4L2Buffer::GetPlaneMapping(const size_t plane) {
return nullptr;
}
- p = device_->Mmap(nullptr, v4l2_buffer_.m.planes[plane].length,
+ unsigned int length = V4L2_TYPE_IS_MULTIPLANAR(v4l2_buffer_.type) ?
+ v4l2_buffer_.m.planes[plane].length : v4l2_planes_[plane].length;
+ unsigned int mem_offset = V4L2_TYPE_IS_MULTIPLANAR(v4l2_buffer_.type) ?
+ v4l2_buffer_.m.planes[plane].m.mem_offset : v4l2_planes_[plane].m.mem_offset;
+ p = device_->Mmap(nullptr, length,
PROT_READ | PROT_WRITE, MAP_SHARED,
- v4l2_buffer_.m.planes[plane].m.mem_offset);
+ mem_offset);
if (p == MAP_FAILED) {
VPLOGF(1) << "mmap() failed: ";
return nullptr;
@@ -1131,7 +1148,7 @@ size_t V4L2Queue::AllocateBuffers(size_t count, enum v4l2_memory memory) {
VQLOGF(1) << "Cannot get format.";
return 0;
}
- planes_count_ = format->fmt.pix_mp.num_planes;
+ planes_count_ = V4L2_TYPE_IS_MULTIPLANAR(format->type) ? format->fmt.pix_mp.num_planes : 1;
DCHECK_LE(planes_count_, static_cast<size_t>(VIDEO_MAX_PLANES));
struct v4l2_requestbuffers reqbufs;
--
2.17.1
|