summaryrefslogtreecommitdiff
path: root/libhwjpeg/ExynosJpegEncoder.cpp
blob: 6c2aaca65314d2a5e5134d206b5230c418884a4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * Copyright Samsung Electronics Co.,LTD.
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <math.h>
#include <sys/poll.h>
#include <cutils/log.h>
#include <utils/Log.h>

#include "ExynosJpegApi.h"

#define JPEG_ERROR_LOG(fmt,...)

#define NUM_JPEG_ENC_IN_PLANES (1)
#define NUM_JPEG_ENC_OUT_PLANES (1)
#define NUM_JPEG_ENC_IN_BUFS (1)
#define NUM_JPEG_ENC_OUT_BUFS (1)

ExynosJpegEncoder::ExynosJpegEncoder()
{
    t_iJpegFd = -1;
    t_bFlagCreate = false;
}

ExynosJpegEncoder::~ExynosJpegEncoder()
{
    if (t_bFlagCreate == true)
        this->destroy();
}

int ExynosJpegEncoder::create(void)
{
    return ExynosJpegBase::create(MODE_ENCODE);
}

int ExynosJpegEncoder::destroy(void)
{
    return ExynosJpegBase::destroy(NUM_JPEG_ENC_IN_BUFS, NUM_JPEG_ENC_OUT_BUFS);
}

int ExynosJpegEncoder::setJpegConfig(void *pConfig)
{
    return ExynosJpegBase::setJpegConfig(MODE_ENCODE, pConfig);
}

int ExynosJpegEncoder::checkInBufType(void)
{
    return checkBufType(&t_stJpegInbuf);
}

int ExynosJpegEncoder::checkOutBufType(void)
{
    return checkBufType(&t_stJpegOutbuf);
}

int ExynosJpegEncoder::getInBuf(char **pcBuf, int *piInputSize, int iSize)
{
    return getBuf(t_bFlagCreateInBuf, &t_stJpegInbuf, pcBuf, piInputSize, iSize, t_iPlaneNum);
}

int ExynosJpegEncoder::getOutBuf(char **pcBuf, int *piOutputSize)
{
    return getBuf(t_bFlagCreateOutBuf, &t_stJpegOutbuf, pcBuf, piOutputSize,
                    NUM_JPEG_ENC_OUT_PLANES, NUM_JPEG_ENC_OUT_PLANES);
}

int ExynosJpegEncoder::setInBuf(char **pcBuf, int *iSize)
{
    int iRet = ERROR_NONE;
    iRet = setBuf(&t_stJpegInbuf, pcBuf, iSize, t_iPlaneNum);

    if (iRet == ERROR_NONE)
        t_bFlagCreateInBuf = true;

    return iRet;
}

int  ExynosJpegEncoder::setOutBuf(char *pcBuf, int iSize)
{
    int iRet = ERROR_NONE;
    iRet = setBuf(&t_stJpegOutbuf, &pcBuf, &iSize, NUM_JPEG_ENC_OUT_PLANES);

    if (iRet == ERROR_NONE)
        t_bFlagCreateOutBuf = true;

    return iRet;
}

int ExynosJpegEncoder::getInBuf(int *piBuf, int *piInputSize, int iSize)
{
    return getBuf(t_bFlagCreateInBuf, &t_stJpegInbuf, piBuf, piInputSize, iSize, t_iPlaneNum);
}

int ExynosJpegEncoder::getOutBuf(int *piBuf, int *piOutputSize)
{
    return getBuf(t_bFlagCreateOutBuf, &t_stJpegOutbuf, piBuf, piOutputSize,
                    NUM_JPEG_ENC_OUT_PLANES, NUM_JPEG_ENC_OUT_PLANES);
}

int ExynosJpegEncoder::setInBuf(int *piBuf, int *iSize)
{
    int iRet = ERROR_NONE;
    iRet = setBuf(&t_stJpegInbuf, piBuf, iSize, t_iPlaneNum);

    if (iRet == ERROR_NONE)
        t_bFlagCreateInBuf = true;

    return iRet;
}

int ExynosJpegEncoder::setOutBuf(int piBuf, int iSize)
{
    int iRet = ERROR_NONE;
    iRet = setBuf(&t_stJpegOutbuf, &piBuf, &iSize, NUM_JPEG_ENC_OUT_PLANES);

    if (iRet == ERROR_NONE)
        t_bFlagCreateOutBuf = true;

    return iRet;
}

int ExynosJpegEncoder::getSize(int *piW, int *piH)
{
    if (t_bFlagCreate == false)
        return ERROR_JPEG_DEVICE_NOT_CREATE_YET;

    if (t_stJpegConfig.width == 0 && t_stJpegConfig.height == 0)
        return ERROR_SIZE_NOT_SET_YET;

    *piW = t_stJpegConfig.width;
    *piH = t_stJpegConfig.height;

    return ERROR_NONE;
}

int ExynosJpegEncoder::getColorFormat(void)
{
    return t_stJpegConfig.pix.enc_fmt.in_fmt;
}

int ExynosJpegEncoder::setColorFormat(int iV4l2ColorFormat)
{
    return ExynosJpegBase::setColorFormat(MODE_ENCODE, iV4l2ColorFormat);
}

int ExynosJpegEncoder::setJpegFormat(int iV4l2JpegFormat)
{
    return ExynosJpegBase::setJpegFormat(MODE_ENCODE, iV4l2JpegFormat);
}

int ExynosJpegEncoder::setColorBufSize(int *piBufSize, int iSize)
{
    return ExynosJpegBase::setColorBufSize(MODE_ENCODE, piBufSize, iSize);
}

int ExynosJpegEncoder::updateConfig(void)
{
    return ExynosJpegBase::updateConfig(MODE_ENCODE,
                    NUM_JPEG_ENC_IN_BUFS, NUM_JPEG_ENC_OUT_BUFS,
                    NUM_JPEG_ENC_IN_PLANES, NUM_JPEG_ENC_OUT_PLANES);
}

int ExynosJpegEncoder::setQuality(int iV4l2Quality)
{
    if (t_bFlagCreate == false)
        return ERROR_JPEG_DEVICE_NOT_CREATE_YET;

    t_stJpegConfig.enc_qual = iV4l2Quality;

    return ERROR_NONE;
}

int ExynosJpegEncoder::getJpegSize(void)
{
    if (t_bFlagCreate == false)
        return 0;

    int iSize = -1;
    iSize = t_stJpegConfig.sizeJpeg;

    if (iSize < 0) {
        JPEG_ERROR_LOG("%s::Fail to JPEG output buffer!!\n", __func__);
        return 0;
    }

    return iSize;
}

int ExynosJpegEncoder::encode(void)
{
    return ExynosJpegBase::execute(t_iPlaneNum, NUM_JPEG_ENC_OUT_PLANES);
}