• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
24 #include <log/log.h>
25 #include <assert.h>
26 #include <dlfcn.h>
27 #include "JpegCompressor.h"
28 
29 namespace android {
30 
31 void* NV21JpegCompressor::mDl = NULL;
32 
getSymbol(void * dl,const char * signature)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 
40 typedef void (*InitFunc)(JpegStub* stub);
41 typedef void (*CleanupFunc)(JpegStub* stub);
42 typedef int (*CompressFunc)(JpegStub* stub, const void* image,
43         int width, int height, int quality, ExifData* exifData);
44 typedef void (*GetCompressedImageFunc)(JpegStub* stub, void* buff);
45 typedef size_t (*GetCompressedSizeFunc)(JpegStub* stub);
46 
NV21JpegCompressor()47 NV21JpegCompressor::NV21JpegCompressor()
48 {
49 #ifdef __LP64__
50     const char dlName[] = "/vendor/lib64/hw/camera.ranchu.jpeg.so";
51 #else
52     const char dlName[] = "/vendor/lib/hw/camera.ranchu.jpeg.so";
53 #endif
54     if (mDl == NULL) {
55         mDl = dlopen(dlName, RTLD_NOW);
56     }
57     assert(mDl != NULL);
58 
59     InitFunc f = (InitFunc)getSymbol(mDl, "JpegStub_init");
60     (*f)(&mStub);
61 }
62 
~NV21JpegCompressor()63 NV21JpegCompressor::~NV21JpegCompressor()
64 {
65     CleanupFunc f = (CleanupFunc)getSymbol(mDl, "JpegStub_cleanup");
66     (*f)(&mStub);
67 }
68 
69 /****************************************************************************
70  * Public API
71  ***************************************************************************/
72 
compressRawImage(const void * image,int width,int height,int quality,ExifData * exifData)73 status_t NV21JpegCompressor::compressRawImage(const void* image,
74                                               int width,
75                                               int height,
76                                               int quality,
77                                               ExifData* exifData)
78 {
79     CompressFunc f = (CompressFunc)getSymbol(mDl, "JpegStub_compress");
80     return (status_t)(*f)(&mStub, image, width, height, quality, exifData);
81 }
82 
83 
getCompressedSize()84 size_t NV21JpegCompressor::getCompressedSize()
85 {
86     GetCompressedSizeFunc f = (GetCompressedSizeFunc)getSymbol(mDl,
87             "JpegStub_getCompressedSize");
88     return (*f)(&mStub);
89 }
90 
getCompressedImage(void * buff)91 void NV21JpegCompressor::getCompressedImage(void* buff)
92 {
93     GetCompressedImageFunc f = (GetCompressedImageFunc)getSymbol(mDl,
94             "JpegStub_getCompressedImage");
95     (*f)(&mStub, buff);
96 }
97 
98 }; /* namespace android */
99