1 /*
2 *
3 * Copyright 2015 Rockchip Electronics Co., LTD.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #define LOG_TAG "PpOp"
19
20 #include "ppOp.h"
21 #include "vpu.h"
22 #include "securec.h"
23
24 namespace ppOp {
ppOpInit(PP_OP_HANDLE * hnd,PP_OPERATION * init)25 status_t ppOpInit(PP_OP_HANDLE *hnd, PP_OPERATION *init)
26 {
27 (void)hnd;
28 (void)init;
29 return 0;
30 }
31
ppOpSet(PP_OP_HANDLE hnd,PP_SET_OPT opt,RK_U32 val)32 status_t ppOpSet(PP_OP_HANDLE hnd, PP_SET_OPT opt, RK_U32 val)
33 {
34 (void)hnd;
35 (void)opt;
36 (void)val;
37 return 0;
38 }
39
ppOpPerform(PP_OP_HANDLE hnd)40 status_t ppOpPerform(PP_OP_HANDLE hnd)
41 {
42 (void)hnd;
43 return 0; // VPU_REG_NUM_PP;
44 }
45
ppOpSync(PP_OP_HANDLE hnd)46 status_t ppOpSync(PP_OP_HANDLE hnd)
47 {
48 (void)hnd;
49 return 0;
50 }
51
ppOpRelease(PP_OP_HANDLE hnd)52 status_t ppOpRelease(PP_OP_HANDLE hnd)
53 {
54 (void)hnd;
55 return 0;
56 }
57 }
58
59 #if BUILD_PPOP_TEST
60 #define SRC_WIDTH (1920) // (1920)
61 #define SRC_HEIGHT (1080) // (1080)
62 #define SRC_SIZE (SRC_WIDTH*SRC_HEIGHT*2)
63 #define DST_WIDTH (720) // (720)
64 #define DST_HEIGHT (1280)
65 #define DST_SIZE (DST_WIDTH*DST_HEIGHT*2)
66
67 #include "vpu_mem.h"
68 #include "vpu.h"
69 #include "ppOp.h"
70
main()71 int main()
72 {
73 FILE *fpr, *fpw;
74 int wid_alig16 = ((SRC_WIDTH + 15) & (~0xf)); // wid_alig16 15
75 int hei_alig16 = ((SRC_HEIGHT + 15) & (~0xf)); // wid_alig16 15
76 int src_vir_width = 1920; // 2048;
77 int src_vir_height = 1088; // 1088;
78 int dst_vir_width = 800; // 800;
79 int dst_vir_height = 1280; // 1280;
80 int framecnt = 0;
81 char *tmpbuf = (char *)malloc(src_vir_width * src_vir_height / 2); // src_vir_height / 2
82 RK_S32 ret = 0, i, j;
83
84 ALOGI("ppOp test start\n");
85 VPUMemLinear_t src, dst;
86 ppOp::PP_OP_HANDLE hnd;
87 int vpuFd = VPUClientInit(VPU_PP);
88 ret |= VPUMallocLinear(&src, src_vir_width * src_vir_height * 2); // SRC_SIZE) 2;
89 ret |= VPUMallocLinear(&dst, dst_vir_width * dst_vir_height * 2); // DST_SIZE) 2;
90 if (ret) {
91 HDF_LOGE("failed to malloc vpu_mem");
92 goto end;
93 }
94 if (vpuFd < 0) {
95 HDF_LOGE("failed to open vpu client");
96 goto end;
97 }
98 {
99 #if 1
100 char *tmp = (char *)src.vir_addr;
101 fpr = fopen("/sdcard/testin.yuv", "rb");
102 for (i = 0; i < SRC_HEIGHT; i++) {
103 if (fpr)fread(tmp, 1, SRC_WIDTH, fpr);
104 tmp += src_vir_width;
105 }
106 tmp = (char *)src.vir_addr;
107 if (fpr)fread(&tmp[src_vir_width * src_vir_height], 1, SRC_WIDTH * SRC_HEIGHT / 2, fpr); // SRC_HEIGHT / 2
108 if (fpr)fclose(fpr);
109
110 for (i = 0; i < SRC_HEIGHT / 2; i++) { // 2 planar to semi planar
111 for (j = 0; j < SRC_WIDTH / 2; j++) { // 2 planar to semi planar
112 tmpbuf[i * src_vir_width + j * 2 + 0] = // SRC_HEIGHT / 2
113 tmp[src_vir_width * src_vir_height + i * SRC_WIDTH / 2 + j]; // SRC_WIDTH / 2
114 tmpbuf[i * src_vir_width + j * 2 + 1] = // SRC_HEIGHT / 2
115 tmp[src_vir_width * src_vir_height + \
116 SRC_WIDTH * SRC_HEIGHT / 4 + i * SRC_WIDTH / 2 + j]; // SRC_HEIGHT / 4 2
117 }
118 }
119 if (memcpy_s(&tmp[src_vir_width * src_vir_height], src_vir_width * src_vir_height / 2, // SRC_HEIGHT / 2
120 tmpbuf, src_vir_width * src_vir_height / 2) != EOK) { // SRC_HEIGHT / 2
121 HDF_LOGE("memcpy_s no");
122 }
123 #endif
124 VPUMemClean(&src);
125 }
126
127 while (1) {
128 printf("framecnt=%d\n", framecnt);
129
130 if (framecnt++ >= 1)
131 break;
132
133 wid_alig16 = ((SRC_WIDTH + 15) & (~0xf)); // wid_alig16 15
134 hei_alig16 = ((SRC_HEIGHT + 15) & (~0xf)); // hei_alig16 15
135
136 ppOp::PP_OPERATION opt;
137 memset_s(&opt, sizeof(opt), 0, sizeof(opt));
138 opt.srcAddr = src.phy_addr;
139 opt.srcFormat = PP_IN_FORMAT_YUV420SEMI;
140 opt.srcWidth = SRC_WIDTH;
141 opt.srcHeight = SRC_HEIGHT;
142 opt.srcHStride = src_vir_width;
143 opt.srcVStride = src_vir_height;
144 opt.srcX = 0;
145 opt.srcY = 0;
146 if (wid_alig16 != SRC_WIDTH)
147 opt.srcCrop8R = 1;
148 if (hei_alig16 != SRC_HEIGHT)
149 opt.srcCrop8D = 1;
150
151 wid_alig16 = ((DST_WIDTH + 15) & (~0xf)); // wid_alig16 15
152 hei_alig16 = ((DST_HEIGHT + 15) & (~0xf)); // hei_alig16 15
153
154 opt.dstAddr = dst.phy_addr;
155 opt.dstFormat = PP_OUT_FORMAT_YUV420INTERLAVE;
156 opt.dstWidth = DST_WIDTH;
157 opt.dstHeight = DST_HEIGHT;
158 opt.dstHStride = dst_vir_width;
159 opt.dstVStride = dst_vir_height;
160 opt.dstX = 0;
161 opt.dstY = 0;
162
163 opt.deinterlace = 0;
164
165 opt.rotation = PP_ROTATION_RIGHT_90; // PP_ROTATION_RIGHT_90
166
167 opt.vpuFd = vpuFd;
168 ret |= ppOp::ppOpInit(&hnd, &opt);
169 if (ret) {
170 HDF_LOGE("ppOpInit failed");
171 hnd = nullptr;
172 goto end;
173 }
174 ret = ppOp::ppOpPerform(hnd);
175 if (ret) {
176 HDF_LOGE("ppOpPerform failed");
177 }
178 ret = ppOp::ppOpSync(hnd);
179 if (ret) {
180 HDF_LOGE("ppOpSync failed");
181 }
182 ret = ppOp::ppOpRelease(hnd);
183 if (ret) {
184 HDF_LOGE("ppOpPerform failed");
185 }
186 VPUMemInvalidate(&dst);
187 {
188 #if 1
189 char *tmp = (char *)dst.vir_addr;
190 fpw = fopen("/data/testout.yuv", "wb+");
191 if (fpw)fwrite((char *)(dst.vir_addr), \
192 1, dst_vir_width * dst_vir_height * 3 / 2, fpw); // dst_vir_height * 3 / 2
193 if (fpw)fclose(fpw);
194 #endif
195 }
196 }
197
198 end:
199 if (tmpbuf)free(tmpbuf);
200 if (src.phy_addr) VPUFreeLinear(&src);
201 if (dst.phy_addr) VPUFreeLinear(&dst);
202 if (vpuFd > 0) VPUClientRelease(vpuFd);
203 ALOGI("ppOp test end\n");
204 return 0;
205 }
206
207 #endif
208