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

Side by Side Diff: media/gpu/tegra_v4l2_device.cc

Issue 2398883002: Add support for multiple V4L2 video devices of the same type. (Closed)
Patch Set: Fixes for image processor. Created 4 years, 2 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 <dlfcn.h> 5 #include <dlfcn.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <linux/videodev2.h> 7 #include <linux/videodev2.h>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 TEGRAV4L2_SYM(Mmap); 49 TEGRAV4L2_SYM(Mmap);
50 TEGRAV4L2_SYM(Munmap); 50 TEGRAV4L2_SYM(Munmap);
51 TEGRAV4L2_SYM(UseEglImage); 51 TEGRAV4L2_SYM(UseEglImage);
52 52
53 #undef TEGRAV4L2_SYM 53 #undef TEGRAV4L2_SYM
54 54
55 class TegraFunctionSymbolFinder { 55 class TegraFunctionSymbolFinder {
56 public: 56 public:
57 TegraFunctionSymbolFinder() : initialized_(false) { 57 TegraFunctionSymbolFinder() : initialized_(false) {
58 if (!dlopen("/usr/lib/libtegrav4l2.so", 58 if (!dlopen("/usr/lib/libtegrav4l2.so",
59 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE)) { 59 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE))
60 DLOG(ERROR) << "Failed to load libtegrav4l2.so";
61 return; 60 return;
62 }
63 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \ 61 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \
64 do { \ 62 do { \
65 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \ 63 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \
66 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \ 64 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \
67 if (TegraV4L2_##name == NULL) { \ 65 if (TegraV4L2_##name == NULL) { \
68 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \ 66 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \
69 return; \ 67 return; \
70 } \ 68 } \
71 } while (0) 69 } while (0)
72 70
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 135
138 bool TegraV4L2Device::ClearDevicePollInterrupt() { 136 bool TegraV4L2Device::ClearDevicePollInterrupt() {
139 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) { 137 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) {
140 LOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt"; 138 LOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt";
141 return false; 139 return false;
142 } 140 }
143 return true; 141 return true;
144 } 142 }
145 143
146 bool TegraV4L2Device::Initialize() { 144 bool TegraV4L2Device::Initialize() {
147 const char* device_path = NULL; 145 return g_tegra_function_symbol_finder_.Get().initialized();
146 }
147
148 bool TegraV4L2Device::Open(uint32_t /* v4l2_pixfmt */) {
149 return OpenInternal();
150 }
151
152 bool TegraV4L2Device::OpenInternal() {
153 const char* device_path = nullptr;
154
148 switch (type_) { 155 switch (type_) {
149 case kDecoder: 156 case V4L2Device::Type::kDecoder:
150 device_path = kDecoderDevice; 157 device_path = kDecoderDevice;
151 break; 158 break;
152 case kEncoder: 159 case V4L2Device::Type::kEncoder:
153 device_path = kEncoderDevice; 160 device_path = kEncoderDevice;
154 break; 161 break;
155 default: 162 default:
156 DVLOG(1) << "Device type " << type_ << " not supported on this platform"; 163 DVLOG(1) << "Device type not supported on this platform";
157 return false; 164 return false;
158 } 165 }
159 166
160 if (!g_tegra_function_symbol_finder_.Get().initialized()) {
161 DLOG(ERROR) << "Unable to initialize functions";
162 return false;
163 }
164 device_fd_ = HANDLE_EINTR( 167 device_fd_ = HANDLE_EINTR(
165 TegraV4L2_Open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); 168 TegraV4L2_Open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC));
166 if (device_fd_ == -1) { 169 if (device_fd_ == -1) {
167 DLOG(ERROR) << "Unable to open device " << device_path; 170 DLOG(ERROR) << "Unable to open device " << device_path;
168 return false; 171 return false;
169 } 172 }
170 return true; 173 return true;
171 } 174 }
172 175
173 std::vector<base::ScopedFD> TegraV4L2Device::GetDmabufsForV4L2Buffer( 176 std::vector<base::ScopedFD> TegraV4L2Device::GetDmabufsForV4L2Buffer(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 return eglDestroyImageKHR(egl_display, egl_image); 225 return eglDestroyImageKHR(egl_display, egl_image);
223 } 226 }
224 227
225 GLenum TegraV4L2Device::GetTextureTarget() { 228 GLenum TegraV4L2Device::GetTextureTarget() {
226 return GL_TEXTURE_2D; 229 return GL_TEXTURE_2D;
227 } 230 }
228 231
229 uint32_t TegraV4L2Device::PreferredInputFormat() { 232 uint32_t TegraV4L2Device::PreferredInputFormat() {
230 // TODO(posciak): We should support "dontcare" returns here once we 233 // TODO(posciak): We should support "dontcare" returns here once we
231 // implement proper handling (fallback, negotiation) for this in users. 234 // implement proper handling (fallback, negotiation) for this in users.
232 CHECK_EQ(type_, kEncoder); 235 CHECK_EQ(type_, Type::kEncoder);
233 return V4L2_PIX_FMT_YUV420M; 236 return V4L2_PIX_FMT_YUV420M;
234 } 237 }
235 238
239 std::vector<uint32_t> TegraV4L2Device::GetSupportedImageProcessorPixelformats(
240 v4l2_buf_type buf_type) {
241 return std::vector<uint32_t>();
242 }
243
244 VideoDecodeAccelerator::SupportedProfiles
245 TegraV4L2Device::GetSupportedDecodeProfiles(const size_t num_formats,
246 const uint32_t pixelformats[]) {
247 if (!OpenInternal())
248 return VideoDecodeAccelerator::SupportedProfiles();
249
250 return EnumerateSupportedDecodeProfiles(num_formats, pixelformats);
251 }
252
253 VideoEncodeAccelerator::SupportedProfiles
254 TegraV4L2Device::GetSupportedEncodeProfiles() {
255 if (!OpenInternal())
256 return VideoEncodeAccelerator::SupportedProfiles();
257
258 return EnumerateSupportedEncodeProfiles();
259 }
260
261 bool TegraV4L2Device::IsJpegDecodingSupported() {
262 return false;
263 }
264
236 } // namespace media 265 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698