1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <string.h>
5 #include <time.h>
6 #include <rtthread.h>
7 #include <hal_mem.h>
8 #include <log.h>
9 #include <video/sunxi_display2.h>
10 #include "disp_layer_cfg.h"
11 #include "disp_mem.h"
12
13 #define FILE_PATH "/mnt/F/FourPeople_1280x720_30.bin" /* "/mnt/E/vidyo4_1280x720_30.bin" ok*/
14 #define WIDTH 1280
15 #define HEIGHT 720
16 #define CROP_X 0LL
17 #define CROP_Y 0LL
18 #define CROP_W 1280LL
19 #define CROP_H 720LL
20 #define SCREEN_W 800
21 #define SCREEN_H 480
22 #define ZORDER 4
23
24 #define FILE_SIZE 489600
25 #define LAYER_ID 0 //must layer 0 and other layer will be used when using lbc input
26 #define CHANNEL_ID 0 //must channel 0
27
28 #define LBC_IS_LOSSY 1
29 //#define LBC_PITCH 12312
30 #define LBC_RC_EN 0
31 //#define LBC_SEG_BIT 123
32
33 int msleep(unsigned int msecs);
34 extern int disp_ioctl(int cmd, void *arg);
35 extern int disp_release(void);
36 extern int disp_open(void);
37
cal(u32 * seg_tar_bits_out,u32 * seg_line_tar_bits_out,u32 seg_rc_en)38 void cal(u32 *seg_tar_bits_out, u32 *seg_line_tar_bits_out, u32 seg_rc_en)
39 {
40 u32 seg_width = 16, seg_height = 4;
41 u32 bit_depth = 8;
42 u32 enc_c_ratio = 333;
43 u32 cmp_ratio = 400;
44 u32 ALIGN = 128;
45 u32 frm_width = WIDTH;
46 u32 seg_tar_bits = 0, dec_segline_tar_bits = 0;
47
48 seg_tar_bits = ((seg_width * seg_height * bit_depth * cmp_ratio * 3 / 2000) / ALIGN) * ALIGN;
49 if (seg_rc_en == 0)
50 {
51 dec_segline_tar_bits = ((frm_width + seg_width - 1) / seg_width) * seg_tar_bits;
52 }
53 else if (seg_rc_en == 1)
54 {
55 dec_segline_tar_bits = ((frm_width + seg_width - 1) / seg_width * seg_width * seg_height * bit_depth * cmp_ratio * 3 / 2000 + ALIGN - 1) / ALIGN * ALIGN;
56 }
57
58 *seg_tar_bits_out = seg_tar_bits/8;
59 *seg_line_tar_bits_out = dec_segline_tar_bits/8;
60 printf("seg_bit:%d pitch=%d\n",seg_tar_bits/8,dec_segline_tar_bits/8);
61 }
62
lbc_test(int argc,char ** argv)63 int lbc_test(int argc, char **argv)
64 {
65 unsigned long arg[6];
66 int id, width, height, ret, sw, sh, fb_width, fb_height, i, n;
67 struct test_layer_cfg test_config;
68 struct test_layer_cfg *test_cfg;
69 test_cfg = &test_config;
70 u32 pitch,seg_bit;
71
72 cal(&seg_bit,&pitch, LBC_RC_EN);
73 memset(test_cfg, 0, sizeof(struct test_layer_cfg));
74
75
76 printf("request mem_id 0\n");
77 disp_open();
78 disp_mem(0, WIDTH, HEIGHT, 0, FILE_PATH);
79 test_cfg->mem_id = 0;
80 test_cfg->screen_id = 0;
81
82
83 test_cfg->layer_cfg.info.fb.crop.x = CROP_X << 32;
84 test_cfg->layer_cfg.info.fb.crop.y = CROP_Y << 32;
85 test_cfg->layer_cfg.info.fb.crop.width = CROP_W << 32;
86 test_cfg->layer_cfg.info.fb.crop.height = CROP_H << 32;
87
88
89 test_cfg->layer_cfg.info.fb.size[0].width = WIDTH;
90 test_cfg->layer_cfg.info.fb.size[0].height = HEIGHT;
91 test_cfg->layer_cfg.info.fb.size[1].width = WIDTH/2;
92 test_cfg->layer_cfg.info.fb.size[1].height = HEIGHT/2;
93 test_cfg->layer_cfg.info.fb.size[2].width = WIDTH/2;
94 test_cfg->layer_cfg.info.fb.size[2].height = HEIGHT/2;
95 test_cfg->layer_cfg.enable = 1;
96
97
98 test_cfg->layer_cfg.info.screen_win.x = 0;
99 test_cfg->layer_cfg.info.screen_win.y = 0;
100 test_cfg->layer_cfg.info.screen_win.width = SCREEN_W;
101 test_cfg->layer_cfg.info.screen_win.height = SCREEN_H;
102
103 test_cfg->layer_cfg.info.alpha_mode = 0;
104 test_cfg->layer_cfg.info.alpha_value = 255;
105 test_cfg->layer_cfg.info.zorder = ZORDER;
106
107 test_cfg->layer_cfg.layer_id = LAYER_ID;
108 test_cfg->layer_cfg.channel = CHANNEL_ID;
109
110
111
112 test_cfg->layer_cfg.info.fb.lbc_en = 1;
113 test_cfg->layer_cfg.info.fb.lbc_info.is_lossy = LBC_IS_LOSSY;
114 test_cfg->layer_cfg.info.fb.lbc_info.rc_en = LBC_RC_EN;
115 test_cfg->layer_cfg.info.fb.lbc_info.pitch = pitch;
116 test_cfg->layer_cfg.info.fb.lbc_info.seg_bit = seg_bit;
117
118
119 test_cfg->layer_cfg.info.fb.format = DISP_FORMAT_YUV420_P;//must be this format
120
121
122
123 printf("Start get mem addr\n");
124
125 arg[0] = test_cfg->mem_id;
126 arg[1] = 0;
127 arg[2] = 0;
128 arg[3] = 0;
129 test_cfg->layer_cfg.info.fb.addr[0] = disp_mem_getadr(test_cfg->mem_id);
130
131 //test_cfg->layer_cfg.info.fb.addr[1] =
132 // (test_cfg->layer_cfg.info.fb.addr[0] +
133 // WIDTH * HEIGHT);
134 //test_cfg->layer_cfg.info.fb.addr[2] =
135 // (test_cfg->layer_cfg.info.fb.addr[0] +
136 // WIDTH * HEIGHT * 5 / 4);
137
138
139 arg[0] = test_cfg->screen_id;
140 arg[1] = (unsigned long)&test_cfg->layer_cfg;
141 arg[2] = 1;
142 arg[3] = 0;
143 printf("Start show layer\n");
144 ret = disp_ioctl(DISP_LAYER_SET_CONFIG, (void *)arg);
145 if (0 != ret)
146 printf("fail to set layer cfg %d\n",ret);
147 disp_release();
148
149
150 printf("press any key to clear layer\n");
151 getchar();
152
153 disp_layer_clear_all(0);
154
155 disp_mem_clear(0);
156
157 return 0;
158 }
159
160
161
162
163
164 FINSH_FUNCTION_EXPORT_ALIAS(lbc_test, __cmd_disp_lbc_test, disp lbc test);
165
166