xref: /rockchip-linux_mpp/mpp/legacy/ppOp.cpp (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2  * Copyright 2015 Rockchip Electronics Co. LTD
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 #define LOG_TAG "PpOp"
18 
19 #include "vpu.h"
20 #include "ppOp.h"
21 
22 namespace android
23 {
24 
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 
60 #if BUILD_PPOP_TEST
61 #define SRC_WIDTH           (1920)//(1920)
62 #define SRC_HEIGHT          (1080)//(1080)
63 #define SRC_SIZE            (SRC_WIDTH*SRC_HEIGHT*2)
64 
65 #define DST_WIDTH           (720)//(720)
66 #define DST_HEIGHT          (1280)
67 #define DST_SIZE            (DST_WIDTH*DST_HEIGHT*2)
68 
69 #include "vpu_mem.h"
70 #include "vpu.h"
71 #include "ppOp.h"
72 
main()73 int main()
74 {
75     FILE *fpr, *fpw;
76     int   wid_alig16 = ((SRC_WIDTH + 15) & (~0xf));
77     int   hei_alig16 = ((SRC_HEIGHT + 15) & (~0xf));
78     int   src_vir_width = 1920;//2048;
79     int   src_vir_height = 1088;//1088;
80     int   dst_vir_width = 800;//800;
81     int   dst_vir_height = 1280;//1280;
82     int   framecnt = 0;
83     char *tmpbuf = (char *)malloc(src_vir_width * src_vir_height / 2);
84     RK_S32 ret = 0, i,  j;
85 
86     ALOGI("ppOp test start\n");
87     VPUMemLinear_t src, dst;
88     android::PP_OP_HANDLE hnd;
89     int vpuFd = VPUClientInit(VPU_PP);
90     ret |= VPUMallocLinear(&src, src_vir_width * src_vir_height * 2); //SRC_SIZE);
91     ret |= VPUMallocLinear(&dst, dst_vir_width * dst_vir_height * 2); //DST_SIZE);
92     if (ret) {
93         ALOGE("failed to malloc vpu_mem");
94         goto end;
95     }
96     if (vpuFd < 0) {
97         ALOGE("failed to open vpu client");
98         goto end;
99     }
100 
101     {
102 #if 0
103         int i,  j;
104         char *tmp = (char *)src.vir_addr;
105         for (i = 0; i < SRC_HEIGHT; i++) {
106             memset(tmp, (i & 0xff), SRC_WIDTH);
107             tmp += SRC_WIDTH;
108         }
109 #endif
110 
111 #if 1
112         char *tmp = (char *)src.vir_addr;
113         fpr = fopen("/sdcard/testin.yuv", "rb");
114         for (i = 0; i < SRC_HEIGHT; i++) {
115             if (fpr)fread(tmp, 1, SRC_WIDTH, fpr);
116             tmp += src_vir_width;
117         }
118         tmp = (char *)src.vir_addr;
119         if (fpr)fread(&tmp[src_vir_width * src_vir_height], 1, SRC_WIDTH * SRC_HEIGHT / 2, fpr);
120         if (fpr)fclose(fpr);
121 
122         for (i = 0; i < SRC_HEIGHT / 2; i++) { //planar to semi planar
123             for (j = 0; j < SRC_WIDTH / 2; j++) { //planar to semi planar
124                 tmpbuf[i * src_vir_width + j * 2 + 0] = tmp[src_vir_width * src_vir_height + i * SRC_WIDTH / 2 + j];
125                 tmpbuf[i * src_vir_width + j * 2 + 1] = tmp[src_vir_width * src_vir_height + SRC_WIDTH * SRC_HEIGHT / 4 + i * SRC_WIDTH / 2 + j];
126             }
127         }
128         memcpy(&tmp[src_vir_width * src_vir_height], tmpbuf, src_vir_width * src_vir_height / 2);
129         //memset(&tmp[SRC_WIDTH*SRC_HEIGHT], 0x80, SRC_WIDTH*SRC_HEIGHT/2);
130 #endif
131         VPUMemClean(&src);
132     }
133 
134     while (1) {
135         printf("framecnt=%d\n", framecnt);
136 
137         if (framecnt++ >= 1)
138             break;
139 
140         wid_alig16 = ((SRC_WIDTH + 15) & (~0xf));
141         hei_alig16 = ((SRC_HEIGHT + 15) & (~0xf));
142 
143         android::PP_OPERATION opt;
144         memset(&opt, 0, sizeof(opt));
145         opt.srcAddr     = src.phy_addr;
146         opt.srcFormat   = PP_IN_FORMAT_YUV420SEMI;
147         opt.srcWidth    = SRC_WIDTH;
148         opt.srcHeight   = SRC_HEIGHT;
149         opt.srcHStride  = src_vir_width;
150         opt.srcVStride  = src_vir_height;
151         opt.srcX   = 0;
152         opt.srcY   = 0;
153         if (wid_alig16 != SRC_WIDTH)
154             opt.srcCrop8R = 1;
155         if (hei_alig16 != SRC_HEIGHT)
156             opt.srcCrop8D = 1;
157 
158         wid_alig16 = ((DST_WIDTH + 15) & (~0xf));
159         hei_alig16 = ((DST_HEIGHT + 15) & (~0xf));
160 
161         opt.dstAddr     = dst.phy_addr;
162         opt.dstFormat   = PP_OUT_FORMAT_YUV420INTERLAVE;
163         opt.dstWidth    = DST_WIDTH;
164         opt.dstHeight   = DST_HEIGHT;
165         opt.dstHStride  = dst_vir_width;
166         opt.dstVStride  = dst_vir_height;
167         opt.dstX   = 0;
168         opt.dstY   = 0;
169 
170         opt.deinterlace = 0;
171 
172         opt.rotation    = PP_ROTATION_RIGHT_90;//PP_ROTATION_RIGHT_90;//PP_ROTATION_RIGHT_90;//PP_ROTATION_RIGHT_90;
173 
174         opt.vpuFd       = vpuFd;
175         ret |= android::ppOpInit(&hnd, &opt);
176         if (ret) {
177             ALOGE("ppOpInit failed");
178             hnd = NULL;
179             goto end;
180         }
181         ret = android::ppOpPerform(hnd);
182         if (ret) {
183             ALOGE("ppOpPerform failed");
184         }
185         ret = android::ppOpSync(hnd);
186         if (ret) {
187             ALOGE("ppOpSync failed");
188         }
189         ret = android::ppOpRelease(hnd);
190         if (ret) {
191             ALOGE("ppOpPerform failed");
192         }
193 
194         VPUMemInvalidate(&dst);
195         {
196 #if 0
197             int i,  j, ret = 0;
198             char *tmp = (char *)dst.vir_addr;
199             /*for(i=0; i<3; i++)
200             {
201                 printf("col out_pos=%d, 0x%x\n", i*DST_WIDTH, tmp[i*DST_WIDTH]);
202             }
203             for(i=0; i<3; i++)
204             {
205                 printf("las out_pos=%d, 0x%x\n", (DST_HEIGHT-1-i)*DST_WIDTH, tmp[(DST_HEIGHT-1-i)*DST_WIDTH]);
206             }*/
207             for (i = 0; i < DST_HEIGHT; i++) {
208                 for (j = 0; j < DST_WIDTH; j++) {
209                     if ( tmp[i * DST_WIDTH + j] != (i & 0xff))
210                         ret = 1;
211                 }
212             }
213             if ( ret)
214                 printf("framecount=%d pp operation is failed!\n", (framecnt - 1));
215             else
216                 printf("framecount=%d pp operation is suceess!\n", (framecnt - 1));
217 
218             memset(dst.vir_addr, 0xff, DST_SIZE);
219             VPUMemClean(&dst);
220 #endif
221 
222 #if 1
223             char *tmp = (char *)dst.vir_addr;
224             //memset(&tmp[DST_WIDTH*DST_HEIGHT], 0x80, DST_WIDTH*DST_HEIGHT/2);
225             //VPUMemClean(&dst);
226             fpw = fopen("/data/testout.yuv", "wb+");
227 
228             if (fpw)fwrite((char *)(dst.vir_addr), 1, dst_vir_width * dst_vir_height * 3 / 2, fpw);
229             if (fpw)fclose(fpw);
230 #endif
231         }
232     }
233 
234 end:
235     if (tmpbuf)free(tmpbuf);
236     if (src.phy_addr) VPUFreeLinear(&src);
237     if (dst.phy_addr) VPUFreeLinear(&dst);
238     if (vpuFd > 0) VPUClientRelease(vpuFd);
239     ALOGI("ppOp test end\n");
240     return 0;
241 }
242 
243 #endif
244 
245