blob: 3a66767c9df5c2eb66d5a5760260217706e7b5f2 [file] [log] [blame]
codeworkxf1be2fe2012-03-24 17:38:29 +01001/*
2 * Copyright (C) 2009 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#include <utils/Log.h>
18
19#include "SEC_OMX_Def.h"
20#include "SecFimc.h"
21#include "HardwareConverter.h"
22
23HardwareConverter::HardwareConverter()
24{
25 SecFimc* handle_fimc = new SecFimc();
26 mSecFimc = (void *)handle_fimc;
27
28 if (handle_fimc->create(SecFimc::DEV_2, SecFimc::MODE_MULTI_BUF, 1) == false)
29 bHWconvert_flag = 0;
30 else
31 bHWconvert_flag = 1;
32}
33
34HardwareConverter::~HardwareConverter()
35{
36 SecFimc* handle_fimc = (SecFimc*)mSecFimc;
37 handle_fimc->destroy();
38 delete mSecFimc;
39}
40
41bool HardwareConverter::convert(
42 void * src_addr,
43 void *dst_addr,
44 OMX_COLOR_FORMATTYPE src_format,
45 int32_t width,
46 int32_t height,
47 OMX_COLOR_FORMATTYPE dst_format)
48{
49 SecFimc* handle_fimc = (SecFimc*)mSecFimc;
50
51 int rotate_value = 0;
52 unsigned int src_crop_x = 0;
53 unsigned int src_crop_y = 0;
54 unsigned int src_crop_width = width;
55 unsigned int src_crop_height = height;
56
57 unsigned int dst_crop_x = 0;
58 unsigned int dst_crop_y = 0;
59 unsigned int dst_crop_width = width;
60 unsigned int dst_crop_height = height;
61
62 void **src_addr_array = (void **)src_addr;
63 void **dst_addr_array = (void **)dst_addr;
64
65 unsigned int src_har_format = OMXtoHarPixelFomrat(src_format);
66 unsigned int dst_har_format = OMXtoHarPixelFomrat(dst_format);
67
68 // set post processor configuration
69 if (!handle_fimc->setSrcParams(width, height, src_crop_x, src_crop_y,
70 &src_crop_width, &src_crop_height,
71 src_har_format)) {
72 LOGE("%s:: setSrcParms() failed", __func__);
73 return false;
74 }
75
76 if (!handle_fimc->setSrcAddr((unsigned int)src_addr_array[0],
77 (unsigned int)src_addr_array[1],
78 (unsigned int)src_addr_array[1],
79 src_har_format)) {
80 LOGE("%s:: setSrcPhyAddr() failed", __func__);
81 return false;
82 }
83
84 if (!handle_fimc->setRotVal(rotate_value)) {
85 LOGE("%s:: setRotVal() failed", __func__);
86 return false;
87 }
88
89 if (!handle_fimc->setDstParams(width, height, dst_crop_x, dst_crop_y,
90 &dst_crop_width, &dst_crop_height,
91 dst_har_format)) {
92 LOGE("%s:: setDstParams() failed", __func__);
93 return false;
94 }
95
96 switch (dst_format) {
97 case OMX_COLOR_FormatYUV420SemiPlanar:
98 if (!handle_fimc->setDstAddr((unsigned int)(dst_addr_array[0]),
99 (unsigned int)(dst_addr_array[1]),
100 (unsigned int)(dst_addr_array[1]))) {
101 LOGE("%s:: setDstPhyAddr() failed", __func__);
102 return false;
103 }
104 break;
105 case OMX_COLOR_FormatYUV420Planar:
106 default:
107 if (!handle_fimc->setDstAddr((unsigned int)(dst_addr_array[0]),
108 (unsigned int)(dst_addr_array[1]),
109 (unsigned int)(dst_addr_array[2]))) {
110 LOGE("%s:: setDstPhyAddr() failed", __func__);
111 return false;
112 }
113 break;
114 }
115
116 if (!handle_fimc->draw(0, 0)) {
117 LOGE("%s:: handleOneShot() failed", __func__);
118 return false;
119 }
120
121 return true;
122}
123
124unsigned int HardwareConverter::OMXtoHarPixelFomrat(OMX_COLOR_FORMATTYPE omx_format)
125{
126 unsigned int hal_format = 0;
127
128 switch (omx_format) {
129 case OMX_COLOR_FormatYUV420Planar:
130 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
131 break;
132 case OMX_COLOR_FormatYUV420SemiPlanar:
133 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_SP;
134 break;
135 case OMX_SEC_COLOR_FormatNV12TPhysicalAddress:
136 hal_format = HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED;
137 break;
138 default:
139 hal_format = HAL_PIXEL_FORMAT_YCbCr_420_P;
140 break;
141 }
142 return hal_format;
143}