Chromium Code Reviews| 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 <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" | |
| 10 #include "base/posix/eintr_wrapper.h" | 9 #include "base/posix/eintr_wrapper.h" |
| 11 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 12 #include "media/gpu/tegra_v4l2_device.h" | 11 #include "media/gpu/tegra_v4l2_device.h" |
| 13 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
| 14 | 13 |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 const char kDecoderDevice[] = "/dev/tegra_avpchannel"; | 17 const char kDecoderDevice[] = "/dev/tegra_avpchannel"; |
| 19 const char kEncoderDevice[] = "/dev/nvhost-msenc"; | 18 const char kEncoderDevice[] = "/dev/nvhost-msenc"; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 45 TEGRAV4L2_SYM(Ioctl); | 44 TEGRAV4L2_SYM(Ioctl); |
| 46 TEGRAV4L2_SYM(Poll); | 45 TEGRAV4L2_SYM(Poll); |
| 47 TEGRAV4L2_SYM(SetDevicePollInterrupt); | 46 TEGRAV4L2_SYM(SetDevicePollInterrupt); |
| 48 TEGRAV4L2_SYM(ClearDevicePollInterrupt); | 47 TEGRAV4L2_SYM(ClearDevicePollInterrupt); |
| 49 TEGRAV4L2_SYM(Mmap); | 48 TEGRAV4L2_SYM(Mmap); |
| 50 TEGRAV4L2_SYM(Munmap); | 49 TEGRAV4L2_SYM(Munmap); |
| 51 TEGRAV4L2_SYM(UseEglImage); | 50 TEGRAV4L2_SYM(UseEglImage); |
| 52 | 51 |
| 53 #undef TEGRAV4L2_SYM | 52 #undef TEGRAV4L2_SYM |
| 54 | 53 |
| 55 class TegraFunctionSymbolFinder { | 54 bool InitializeTegraFunctionSymbolFinder() { |
|
Mark Mentovai
2017/01/31 21:33:56
This should be marked “static”, in an unnamed name
DaleCurtis
2017/01/31 22:04:33
Inlined.
| |
| 56 public: | 55 if (!dlopen("/usr/lib/libtegrav4l2.so", |
| 57 TegraFunctionSymbolFinder() : initialized_(false) { | 56 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE)) { |
| 58 if (!dlopen("/usr/lib/libtegrav4l2.so", | 57 return false; |
| 59 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE)) | 58 } |
| 60 return; | |
| 61 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \ | 59 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \ |
| 62 do { \ | 60 do { \ |
| 63 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \ | 61 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \ |
| 64 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \ | 62 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \ |
| 65 if (TegraV4L2_##name == NULL) { \ | 63 if (TegraV4L2_##name == NULL) { \ |
| 66 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \ | 64 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \ |
| 67 return; \ | 65 return false; \ |
| 68 } \ | 66 } \ |
| 69 } while (0) | 67 } while (0) |
| 70 | 68 |
| 71 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Open); | 69 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Open); |
| 72 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Close); | 70 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Close); |
| 73 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Ioctl); | 71 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Ioctl); |
| 74 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Poll); | 72 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Poll); |
| 75 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(SetDevicePollInterrupt); | 73 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(SetDevicePollInterrupt); |
| 76 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(ClearDevicePollInterrupt); | 74 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(ClearDevicePollInterrupt); |
| 77 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Mmap); | 75 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Mmap); |
| 78 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Munmap); | 76 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Munmap); |
| 79 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(UseEglImage); | 77 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(UseEglImage); |
| 80 #undef TEGRAV4L2_DLSYM | 78 #undef TEGRAV4L2_DLSYM |
|
Mark Mentovai
2017/01/31 21:33:56
This was never #defined, I think it means TEGRAV4L
DaleCurtis
2017/01/31 22:04:33
Good catch, fixed.
| |
| 81 initialized_ = true; | 79 return true; |
| 82 } | 80 } |
| 83 | |
| 84 bool initialized() { return initialized_; } | |
| 85 | |
| 86 private: | |
| 87 bool initialized_; | |
| 88 }; | |
| 89 | |
| 90 base::LazyInstance<TegraFunctionSymbolFinder> g_tegra_function_symbol_finder_ = | |
| 91 LAZY_INSTANCE_INITIALIZER; | |
| 92 | 81 |
| 93 TegraV4L2Device::TegraV4L2Device() {} | 82 TegraV4L2Device::TegraV4L2Device() {} |
| 94 | 83 |
| 95 TegraV4L2Device::~TegraV4L2Device() { | 84 TegraV4L2Device::~TegraV4L2Device() { |
| 96 Close(); | 85 Close(); |
| 97 } | 86 } |
| 98 | 87 |
| 99 int TegraV4L2Device::Ioctl(int flags, void* arg) { | 88 int TegraV4L2Device::Ioctl(int flags, void* arg) { |
| 100 return HANDLE_EINTR(TegraV4L2_Ioctl(device_fd_, flags, arg)); | 89 return HANDLE_EINTR(TegraV4L2_Ioctl(device_fd_, flags, arg)); |
| 101 } | 90 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 131 | 120 |
| 132 bool TegraV4L2Device::ClearDevicePollInterrupt() { | 121 bool TegraV4L2Device::ClearDevicePollInterrupt() { |
| 133 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) { | 122 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) { |
| 134 LOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt"; | 123 LOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt"; |
| 135 return false; | 124 return false; |
| 136 } | 125 } |
| 137 return true; | 126 return true; |
| 138 } | 127 } |
| 139 | 128 |
| 140 bool TegraV4L2Device::Initialize() { | 129 bool TegraV4L2Device::Initialize() { |
| 141 return g_tegra_function_symbol_finder_.Get().initialized(); | 130 static bool initialized = InitializeTegraFunctionSymbolFinder(); |
|
Mark Mentovai
2017/01/31 21:33:56
…written in-line here in a lambda.
DaleCurtis
2017/01/31 22:04:33
:)
| |
| 131 return initialized; | |
| 142 } | 132 } |
| 143 | 133 |
| 144 bool TegraV4L2Device::Open(Type type, uint32_t /* v4l2_pixfmt */) { | 134 bool TegraV4L2Device::Open(Type type, uint32_t /* v4l2_pixfmt */) { |
| 145 return OpenInternal(type); | 135 return OpenInternal(type); |
| 146 } | 136 } |
| 147 | 137 |
| 148 bool TegraV4L2Device::OpenInternal(Type type) { | 138 bool TegraV4L2Device::OpenInternal(Type type) { |
| 149 const char* device_path = nullptr; | 139 const char* device_path = nullptr; |
| 150 | 140 |
| 151 switch (type) { | 141 switch (type) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 262 |
| 273 bool TegraV4L2Device::IsImageProcessingSupported() { | 263 bool TegraV4L2Device::IsImageProcessingSupported() { |
| 274 return false; | 264 return false; |
| 275 } | 265 } |
| 276 | 266 |
| 277 bool TegraV4L2Device::IsJpegDecodingSupported() { | 267 bool TegraV4L2Device::IsJpegDecodingSupported() { |
| 278 return false; | 268 return false; |
| 279 } | 269 } |
| 280 | 270 |
| 281 } // namespace media | 271 } // namespace media |
| OLD | NEW |