| Index: content/common/gpu/media/tegra_jpeg_codec_device.cc
|
| diff --git a/content/common/gpu/media/tegra_jpeg_codec_device.cc b/content/common/gpu/media/tegra_jpeg_codec_device.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9a13fb2b29bfaf8ad5c7b6666c087de55e7f0d20
|
| --- /dev/null
|
| +++ b/content/common/gpu/media/tegra_jpeg_codec_device.cc
|
| @@ -0,0 +1,130 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <dlfcn.h>
|
| +#include <fcntl.h>
|
| +
|
| +#include "base/debug/trace_event.h"
|
| +#include "base/lazy_instance.h"
|
| +#include "base/posix/eintr_wrapper.h"
|
| +#include "content/common/gpu/media/tegra_jpeg_codec_device.h"
|
| +#include "ui/gl/gl_bindings.h"
|
| +
|
| +namespace content {
|
| +
|
| +typedef void (*TegraJpeg_DestroyDecoderT) (long int handle);
|
| +typedef long int (*TegraJpeg_CreateDecoderT) (void);
|
| +typedef bool (*TegraJpeg_ReadHeaderT) (long int handle,
|
| + const unsigned char* input_buffer, size_t input_size,
|
| + unsigned int* outWidth, unsigned int* outHeight);
|
| +typedef bool (*TegraJpeg_DecodeT) (long int handle,
|
| + unsigned char** output_buffer,
|
| + unsigned int* row_bytes);
|
| +
|
| +
|
| +#define TEGRAJPEG_SYM(name) name##T name = NULL
|
| +
|
| +TEGRAJPEG_SYM(TegraJpeg_DestroyDecoder);
|
| +TEGRAJPEG_SYM(TegraJpeg_CreateDecoder);
|
| +TEGRAJPEG_SYM(TegraJpeg_ReadHeader);
|
| +TEGRAJPEG_SYM(TegraJpeg_Decode);
|
| +
|
| +#undef TEGRAJPEG_SYM
|
| +
|
| +
|
| +class TegraFunctionSymbolFinder {
|
| + public:
|
| + TegraFunctionSymbolFinder() : initialized_(false) {
|
| + int symbol_lookup_failed = 0;
|
| + const char *errmsg = dlerror(); //clear any previous errors.
|
| + static void *h_tegralib = dlopen("/system/vendor/lib/libnvjtegra.so",
|
| + RTLD_NOW | RTLD_GLOBAL );//) {
|
| + if (!h_tegralib) {
|
| + LOG(ERROR) << "Failed to load libnvjtegra.so";
|
| + return;
|
| + }
|
| +#define NV_DLSYM_LINK(handle,name) \
|
| + name = (name##T) (dlsym(handle, #name)); \
|
| + errmsg = dlerror(); \
|
| + if (name == NULL) { \
|
| + LOG(ERROR) << "Failed to load symbol "<<__FUNCTION__<<" name: " \
|
| + <<#name<<errmsg; \
|
| + symbol_lookup_failed = 1; \
|
| + }
|
| +
|
| + NV_DLSYM_LINK(h_tegralib, TegraJpeg_DestroyDecoder);
|
| + NV_DLSYM_LINK(h_tegralib, TegraJpeg_CreateDecoder);
|
| + NV_DLSYM_LINK(h_tegralib, TegraJpeg_ReadHeader);
|
| + NV_DLSYM_LINK(h_tegralib, TegraJpeg_Decode);
|
| +
|
| + if (!symbol_lookup_failed)
|
| + initialized_ = true;
|
| + }
|
| +
|
| + bool initialized() { return initialized_; }
|
| +
|
| + private:
|
| + bool initialized_;
|
| +};
|
| +
|
| +base::LazyInstance<TegraFunctionSymbolFinder> g_tegra_function_symbol_finder_ =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +TegraJpegCodecDevice::TegraJpegCodecDevice(Type type)
|
| + : type_(type)
|
| + , hDecoder_(0) {
|
| +}
|
| +
|
| +TegraJpegCodecDevice::~TegraJpegCodecDevice() {
|
| + DVLOG(1) << "Destroying Tegra JPEG Decoder";
|
| + TegraJpeg_DestroyDecoder(hDecoder_);
|
| +}
|
| +
|
| +bool TegraJpegCodecDevice::Initialize() {
|
| + switch (type_) {
|
| + case kDecoder:
|
| + DVLOG(1) << "Initializing Tegra JPEG Decoder";
|
| + break;
|
| + case kEncoder:
|
| + //device_path = kEncoderDevice;
|
| + DVLOG(1) << "Device type " << type_ << " not supported on this platform";
|
| + return false;
|
| + case kImageProcessor:
|
| + DVLOG(1) << "Device type " << type_ << " not supported on this platform";
|
| + return false;
|
| + }
|
| + if (!g_tegra_function_symbol_finder_.Get().initialized()) {
|
| + LOG(ERROR) << "Unable to initialize functions";
|
| + return false;
|
| + }
|
| +
|
| + hDecoder_ = TegraJpeg_CreateDecoder();
|
| + if (!hDecoder_)
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool TegraJpegCodecDevice::Decode(const unsigned char* input_buffer,
|
| + size_t input_size, unsigned char** output_buffer,
|
| + unsigned* outWidth, unsigned* outHeight,
|
| + unsigned* row_bytes) {
|
| + *output_buffer = NULL;
|
| + *row_bytes = 0;
|
| + *outWidth = 0;
|
| + *outHeight = 0;
|
| + bool success = false;
|
| +
|
| + success = TegraJpeg_ReadHeader(hDecoder_, input_buffer, input_size, outWidth,
|
| + outHeight);
|
| + if (success == false) {
|
| + LOG(ERROR) << "Unable to read JPEG Header";
|
| + return false;
|
| + }
|
| + success = TegraJpeg_Decode(hDecoder_, output_buffer, row_bytes);
|
| +
|
| + return success;
|
| +}
|
| +
|
| +} // namespace content
|
|
|