| 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 { | |
| 56 public: | |
| 57 TegraFunctionSymbolFinder() : initialized_(false) { | |
| 58 if (!dlopen("/usr/lib/libtegrav4l2.so", | |
| 59 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE)) | |
| 60 return; | |
| 61 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \ | |
| 62 do { \ | |
| 63 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \ | |
| 64 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \ | |
| 65 if (TegraV4L2_##name == NULL) { \ | |
| 66 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \ | |
| 67 return; \ | |
| 68 } \ | |
| 69 } while (0) | |
| 70 | |
| 71 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Open); | |
| 72 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Close); | |
| 73 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Ioctl); | |
| 74 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Poll); | |
| 75 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(SetDevicePollInterrupt); | |
| 76 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(ClearDevicePollInterrupt); | |
| 77 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Mmap); | |
| 78 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Munmap); | |
| 79 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(UseEglImage); | |
| 80 #undef TEGRAV4L2_DLSYM | |
| 81 initialized_ = true; | |
| 82 } | |
| 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 | |
| 93 TegraV4L2Device::TegraV4L2Device() {} | 54 TegraV4L2Device::TegraV4L2Device() {} |
| 94 | 55 |
| 95 TegraV4L2Device::~TegraV4L2Device() { | 56 TegraV4L2Device::~TegraV4L2Device() { |
| 96 Close(); | 57 Close(); |
| 97 } | 58 } |
| 98 | 59 |
| 99 int TegraV4L2Device::Ioctl(int flags, void* arg) { | 60 int TegraV4L2Device::Ioctl(int flags, void* arg) { |
| 100 return HANDLE_EINTR(TegraV4L2_Ioctl(device_fd_, flags, arg)); | 61 return HANDLE_EINTR(TegraV4L2_Ioctl(device_fd_, flags, arg)); |
| 101 } | 62 } |
| 102 | 63 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 131 | 92 |
| 132 bool TegraV4L2Device::ClearDevicePollInterrupt() { | 93 bool TegraV4L2Device::ClearDevicePollInterrupt() { |
| 133 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) { | 94 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) { |
| 134 LOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt"; | 95 LOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt"; |
| 135 return false; | 96 return false; |
| 136 } | 97 } |
| 137 return true; | 98 return true; |
| 138 } | 99 } |
| 139 | 100 |
| 140 bool TegraV4L2Device::Initialize() { | 101 bool TegraV4L2Device::Initialize() { |
| 141 return g_tegra_function_symbol_finder_.Get().initialized(); | 102 static bool initialized = []() { |
| 103 if (!dlopen("/usr/lib/libtegrav4l2.so", |
| 104 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE)) { |
| 105 return false; |
| 106 } |
| 107 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \ |
| 108 do { \ |
| 109 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \ |
| 110 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \ |
| 111 if (TegraV4L2_##name == NULL) { \ |
| 112 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \ |
| 113 return false; \ |
| 114 } \ |
| 115 } while (0) |
| 116 |
| 117 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Open); |
| 118 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Close); |
| 119 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Ioctl); |
| 120 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Poll); |
| 121 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(SetDevicePollInterrupt); |
| 122 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(ClearDevicePollInterrupt); |
| 123 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Mmap); |
| 124 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Munmap); |
| 125 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(UseEglImage); |
| 126 #undef TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR |
| 127 return true; |
| 128 }(); |
| 129 |
| 130 return initialized; |
| 142 } | 131 } |
| 143 | 132 |
| 144 bool TegraV4L2Device::Open(Type type, uint32_t /* v4l2_pixfmt */) { | 133 bool TegraV4L2Device::Open(Type type, uint32_t /* v4l2_pixfmt */) { |
| 145 return OpenInternal(type); | 134 return OpenInternal(type); |
| 146 } | 135 } |
| 147 | 136 |
| 148 bool TegraV4L2Device::OpenInternal(Type type) { | 137 bool TegraV4L2Device::OpenInternal(Type type) { |
| 149 const char* device_path = nullptr; | 138 const char* device_path = nullptr; |
| 150 | 139 |
| 151 switch (type) { | 140 switch (type) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 261 |
| 273 bool TegraV4L2Device::IsImageProcessingSupported() { | 262 bool TegraV4L2Device::IsImageProcessingSupported() { |
| 274 return false; | 263 return false; |
| 275 } | 264 } |
| 276 | 265 |
| 277 bool TegraV4L2Device::IsJpegDecodingSupported() { | 266 bool TegraV4L2Device::IsJpegDecodingSupported() { |
| 278 return false; | 267 return false; |
| 279 } | 268 } |
| 280 | 269 |
| 281 } // namespace media | 270 } // namespace media |
| OLD | NEW |