keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Contains implementation of a class NV21JpegCompressor that encapsulates a |
| 19 | * converter between NV21, and JPEG formats. |
| 20 | */ |
| 21 | |
| 22 | #define LOG_NDEBUG 0 |
| 23 | #define LOG_TAG "EmulatedCamera_JPEG" |
huans | 005c10e | 2018-07-06 16:12:30 -0700 | [diff] [blame] | 24 | #include <log/log.h> |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 25 | #include <assert.h> |
| 26 | #include <dlfcn.h> |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 27 | #include "JpegCompressor.h" |
| 28 | |
| 29 | namespace android { |
| 30 | |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 31 | void* NV21JpegCompressor::mDl = NULL; |
| 32 | |
| 33 | static void* getSymbol(void* dl, const char* signature) { |
| 34 | void* res = dlsym(dl, signature); |
| 35 | assert (res != NULL); |
| 36 | |
| 37 | return res; |
| 38 | } |
| 39 | |
Bjoern Johansson | a11bd58 | 2016-08-17 15:24:44 -0700 | [diff] [blame] | 40 | typedef void (*InitFunc)(JpegStub* stub); |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 41 | typedef void (*CleanupFunc)(JpegStub* stub); |
| 42 | typedef int (*CompressFunc)(JpegStub* stub, const void* image, |
Bjoern Johansson | a11bd58 | 2016-08-17 15:24:44 -0700 | [diff] [blame] | 43 | int width, int height, int quality, ExifData* exifData); |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 44 | typedef void (*GetCompressedImageFunc)(JpegStub* stub, void* buff); |
| 45 | typedef size_t (*GetCompressedSizeFunc)(JpegStub* stub); |
| 46 | |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 47 | NV21JpegCompressor::NV21JpegCompressor() |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 48 | { |
Yahan Zhou | 89c64e7 | 2017-06-07 12:57:15 -0700 | [diff] [blame] | 49 | const char dlName[] = "/vendor/lib/hw/camera.goldfish.jpeg.so"; |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 50 | if (mDl == NULL) { |
| 51 | mDl = dlopen(dlName, RTLD_NOW); |
| 52 | } |
| 53 | assert(mDl != NULL); |
| 54 | |
| 55 | InitFunc f = (InitFunc)getSymbol(mDl, "JpegStub_init"); |
Bjoern Johansson | a11bd58 | 2016-08-17 15:24:44 -0700 | [diff] [blame] | 56 | (*f)(&mStub); |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | NV21JpegCompressor::~NV21JpegCompressor() |
| 60 | { |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 61 | CleanupFunc f = (CleanupFunc)getSymbol(mDl, "JpegStub_cleanup"); |
| 62 | (*f)(&mStub); |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /**************************************************************************** |
| 66 | * Public API |
| 67 | ***************************************************************************/ |
| 68 | |
| 69 | status_t NV21JpegCompressor::compressRawImage(const void* image, |
| 70 | int width, |
| 71 | int height, |
Bjoern Johansson | a11bd58 | 2016-08-17 15:24:44 -0700 | [diff] [blame] | 72 | int quality, |
| 73 | ExifData* exifData) |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 74 | { |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 75 | CompressFunc f = (CompressFunc)getSymbol(mDl, "JpegStub_compress"); |
Bjoern Johansson | a11bd58 | 2016-08-17 15:24:44 -0700 | [diff] [blame] | 76 | return (status_t)(*f)(&mStub, image, width, height, quality, exifData); |
keunyoung | c86ea2b | 2013-03-12 16:25:31 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
| 80 | size_t NV21JpegCompressor::getCompressedSize() |
| 81 | { |
| 82 | GetCompressedSizeFunc f = (GetCompressedSizeFunc)getSymbol(mDl, |
| 83 | "JpegStub_getCompressedSize"); |
| 84 | return (*f)(&mStub); |
| 85 | } |
| 86 | |
| 87 | void NV21JpegCompressor::getCompressedImage(void* buff) |
| 88 | { |
| 89 | GetCompressedImageFunc f = (GetCompressedImageFunc)getSymbol(mDl, |
| 90 | "JpegStub_getCompressedImage"); |
| 91 | (*f)(&mStub, buff); |
keunyoung | 8a94683 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | }; /* namespace android */ |