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