summaryrefslogtreecommitdiffstats
path: root/exynos/multimedia/utils/csc/exynos5/csc_fimc.cpp
blob: 42436244dc1c461c9d0035690c6d5a95ada876ab (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
218
219
220
221
222
223
224
225
/*
 * Copyright (C) 2009 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.
 */

/*
 * @file    csc_fimc.cpp
 *
 * @brief   csc_fimc use fimc1 to color space convertion
 *
 * @author  ShinWon Lee (shinwon.lee@samsung.com)
 *
 * @version 1.0
 *
 * @history
 *   2011.11.01 : Create
 */

#include <utils/Log.h>
#include <dlfcn.h>

#include "SecFimc.h"
#include "csc_fimc.h"

#define ALIGN(value, base) (((value) + (base) - 1) & ~((base) - 1))

unsigned int OMXtoHarPixelFomrat(OMX_COLOR_FORMATTYPE ColorFormat)
{
    unsigned int v4l2_format = 0;
    switch (ColorFormat) {
    case OMX_COLOR_FormatYUV420Planar:
        v4l2_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
        break;
    case OMX_COLOR_FormatYUV420SemiPlanar:
        v4l2_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
        break;
    default:
        v4l2_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
        break;
    }
    return v4l2_format;
}

/*
 * create and open fimc handle
 *
 * @return
 *   fimc handle
 */
void *csc_fimc_open()
{
    SecFimc *(*create_instance)();
    void (*destroy_instance)(void *);
    SecFimc *handle_fimc = NULL;
    void* hdl = NULL;

    hdl = dlopen("libfimc.so", RTLD_NOW);
    if (hdl == NULL) {
        ALOGE("%s:: load libfimc.so failed", __func__);
        return NULL;
    }

    create_instance = (SecFimc *(*)())dlsym(hdl, "create_instance");
    handle_fimc = (SecFimc *)create_instance();
    if (handle_fimc == NULL) {
        ALOGE("%s:: create handle_fimc failed", __func__);
        return NULL;
    }

    if (!handle_fimc->create(SecFimc::DEV_1, SecFimc::MODE_MULTI_BUF, 1)) {
        destroy_instance = (void (*)(void *))dlsym(hdl, "destroy_instance");
        destroy_instance(handle_fimc);
        ALOGE("%s:: create() failed", __func__);
        return NULL;
    }
    return (void *)handle_fimc;
}

/*
 * close and destroy fimc handle
 *
 * @param handle
 *   fimc handle[in]
 *
 * @return
 *   pass or fail
 */
CSC_FIMC_ERROR_CODE csc_fimc_close(void *handle)
{
    void (*destroy_instance)(void *);
    SecFimc *handle_fimc = (SecFimc *)handle;
    void* hdl = NULL;

    if (!handle_fimc->destroy()) {
        ALOGE("%s:: destroy() failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    hdl = dlopen("libfimc.so", RTLD_NOW);
    if (hdl == NULL) {
        ALOGE("%s:: load libfimc.so failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    destroy_instance = (void (*)(void *))dlsym(hdl, "destroy_instance");
    destroy_instance(handle);

    return CSC_FIMC_RET_OK;
}

/*
 * convert color space nv12t to omxformat
 *
 * @param handle
 *   fimc handle[in]
 *
 * @param dst_addr
 *   y,u,v address of dst_addr[out]
 *
 * @param src_addr
 *   y,uv address of src_addr.Format is nv12t[in]
 *
 * @param width
 *   width of dst image[in]
 *
 * @param height
 *   height of dst image[in]
 *
 * @param omxformat
 *   omxformat of dst image[in]
 *
 * @return
 *   pass or fail
 */
CSC_FIMC_ERROR_CODE csc_fimc_convert_nv12t(
    void *handle,
    void **dst_addr,
    void **src_addr,
    unsigned int width,
    unsigned int height,
    OMX_COLOR_FORMATTYPE omxformat)
{
    int rotate_value = 0;

    SecFimc *handle_fimc = (SecFimc *)handle;

    unsigned int src_crop_x = 0;
    unsigned int src_crop_y = 0;
    unsigned int src_crop_width = width;
    unsigned int src_crop_height = height;

    unsigned int dst_crop_x = 0;
    unsigned int dst_crop_y = 0;
    unsigned int dst_crop_width = width;
    unsigned int dst_crop_height = height;

    unsigned int HarPixelformat = 0;
    HarPixelformat = OMXtoHarPixelFomrat(omxformat);

    // set post processor configuration
    if (!handle_fimc->setSrcParams(width, height, src_crop_x, src_crop_y,
                                   &src_crop_width, &src_crop_height,
                                   HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED)) {
        ALOGE("%s:: setSrcParms() failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    if (!handle_fimc->setSrcAddr((unsigned int)src_addr[0],
                                 (unsigned int)src_addr[1],
                                 (unsigned int)src_addr[1],
                                 HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED)) {
        ALOGE("%s:: setSrcPhyAddr() failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    if (!handle_fimc->setRotVal(rotate_value)) {
        ALOGE("%s:: setRotVal() failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    if (!handle_fimc->setDstParams(width, height, dst_crop_x, dst_crop_y,
                                   &dst_crop_width, &dst_crop_height,
                                   HarPixelformat)) {
        ALOGE("%s:: setDstParams() failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    switch (omxformat) {
    case OMX_COLOR_FormatYUV420SemiPlanar:
        if (!handle_fimc->setDstAddr((unsigned int)(dst_addr[0]),
                                     (unsigned int)(dst_addr[1]),
                                     (unsigned int)(dst_addr[1]))) {
            ALOGE("%s:: setDstPhyAddr() failed", __func__);
            return CSC_FIMC_RET_FAIL;
        }
        break;
    case OMX_COLOR_FormatYUV420Planar:
    default:
        if (!handle_fimc->setDstAddr((unsigned int)(dst_addr[0]),
                                     (unsigned int)(dst_addr[1]),
                                     (unsigned int)(dst_addr[2]))) {
            ALOGE("%s:: setDstPhyAddr() failed", __func__);
            return CSC_FIMC_RET_FAIL;
        }
        break;
    }

    if (!handle_fimc->draw(0, 0)) {
        ALOGE("%s:: handleOneShot() failed", __func__);
        return CSC_FIMC_RET_FAIL;
    }

    return CSC_FIMC_RET_OK;
}