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

Side by Side Diff: content/common/gpu/media/tegra_jpeg_codec_device.cc

Issue 825863002: WIP: Add hardware jpeg decode on tegra platform Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 5 years, 12 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
« no previous file with comments | « content/common/gpu/media/tegra_jpeg_codec_device.h ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <dlfcn.h>
6 #include <fcntl.h>
7
8 #include "base/debug/trace_event.h"
9 #include "base/lazy_instance.h"
10 #include "base/posix/eintr_wrapper.h"
11 #include "content/common/gpu/media/tegra_jpeg_codec_device.h"
12 #include "ui/gl/gl_bindings.h"
13
14 namespace content {
15
16 typedef void (*TegraJpeg_DestroyDecoderT) (long int handle);
17 typedef long int (*TegraJpeg_CreateDecoderT) (void);
18 typedef bool (*TegraJpeg_ReadHeaderT) (long int handle,
19 const unsigned char* input_buffer, size_t input_size,
20 unsigned int* outWidth, unsigned int* outHeight);
21 typedef bool (*TegraJpeg_DecodeT) (long int handle,
22 unsigned char** output_buffer,
23 unsigned int* row_bytes);
24
25
26 #define TEGRAJPEG_SYM(name) name##T name = NULL
27
28 TEGRAJPEG_SYM(TegraJpeg_DestroyDecoder);
29 TEGRAJPEG_SYM(TegraJpeg_CreateDecoder);
30 TEGRAJPEG_SYM(TegraJpeg_ReadHeader);
31 TEGRAJPEG_SYM(TegraJpeg_Decode);
32
33 #undef TEGRAJPEG_SYM
34
35
36 class TegraFunctionSymbolFinder {
37 public:
38 TegraFunctionSymbolFinder() : initialized_(false) {
39 int symbol_lookup_failed = 0;
40 const char *errmsg = dlerror(); //clear any previous errors.
41 static void *h_tegralib = dlopen("/system/vendor/lib/libnvjtegra.so",
42 RTLD_NOW | RTLD_GLOBAL );//) {
43 if (!h_tegralib) {
44 LOG(ERROR) << "Failed to load libnvjtegra.so";
45 return;
46 }
47 #define NV_DLSYM_LINK(handle,name) \
48 name = (name##T) (dlsym(handle, #name)); \
49 errmsg = dlerror(); \
50 if (name == NULL) { \
51 LOG(ERROR) << "Failed to load symbol "<<__FUNCTION__<<" name: " \
52 <<#name<<errmsg; \
53 symbol_lookup_failed = 1; \
54 }
55
56 NV_DLSYM_LINK(h_tegralib, TegraJpeg_DestroyDecoder);
57 NV_DLSYM_LINK(h_tegralib, TegraJpeg_CreateDecoder);
58 NV_DLSYM_LINK(h_tegralib, TegraJpeg_ReadHeader);
59 NV_DLSYM_LINK(h_tegralib, TegraJpeg_Decode);
60
61 if (!symbol_lookup_failed)
62 initialized_ = true;
63 }
64
65 bool initialized() { return initialized_; }
66
67 private:
68 bool initialized_;
69 };
70
71 base::LazyInstance<TegraFunctionSymbolFinder> g_tegra_function_symbol_finder_ =
72 LAZY_INSTANCE_INITIALIZER;
73
74 TegraJpegCodecDevice::TegraJpegCodecDevice(Type type)
75 : type_(type)
76 , hDecoder_(0) {
77 }
78
79 TegraJpegCodecDevice::~TegraJpegCodecDevice() {
80 DVLOG(1) << "Destroying Tegra JPEG Decoder";
81 TegraJpeg_DestroyDecoder(hDecoder_);
82 }
83
84 bool TegraJpegCodecDevice::Initialize() {
85 switch (type_) {
86 case kDecoder:
87 DVLOG(1) << "Initializing Tegra JPEG Decoder";
88 break;
89 case kEncoder:
90 //device_path = kEncoderDevice;
91 DVLOG(1) << "Device type " << type_ << " not supported on this platform";
92 return false;
93 case kImageProcessor:
94 DVLOG(1) << "Device type " << type_ << " not supported on this platform";
95 return false;
96 }
97 if (!g_tegra_function_symbol_finder_.Get().initialized()) {
98 LOG(ERROR) << "Unable to initialize functions";
99 return false;
100 }
101
102 hDecoder_ = TegraJpeg_CreateDecoder();
103 if (!hDecoder_)
104 return false;
105
106 return true;
107 }
108
109 bool TegraJpegCodecDevice::Decode(const unsigned char* input_buffer,
110 size_t input_size, unsigned char** output_buffer,
111 unsigned* outWidth, unsigned* outHeight,
112 unsigned* row_bytes) {
113 *output_buffer = NULL;
114 *row_bytes = 0;
115 *outWidth = 0;
116 *outHeight = 0;
117 bool success = false;
118
119 success = TegraJpeg_ReadHeader(hDecoder_, input_buffer, input_size, outWidth,
120 outHeight);
121 if (success == false) {
122 LOG(ERROR) << "Unable to read JPEG Header";
123 return false;
124 }
125 success = TegraJpeg_Decode(hDecoder_, output_buffer, row_bytes);
126
127 return success;
128 }
129
130 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/tegra_jpeg_codec_device.h ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698