-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
243 lines (206 loc) · 5.44 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <config.h>
#include <disp_manager.h>
#include <pic_operation.h>
#include <render.h>
#include <convert_manager.h>
#include <video_manager.h>
#include <mbx.h>
typedef struct main_info{
int capture_pixel_format;
int display_pixel_format;
video_device_p video_dev;
video_convert_p video_convert;
video_buf_p video_buf;
video_buf_p frame_buf;
video_buf_p convert_buf;
MBX_Handle capture2convert;
MBX_Handle convert2display;
int convert_bpp;
int width;
int height;
}main_info_t, *main_info_p;
static void *capture_thread(void *arg);
static void *convert_thread(void *arg);
static void *display_thread(void *arg);
int main(int argc, char *argv[])
{
int error;
video_device_t video_dev;
video_buf_t video_buf;
video_buf_t convert_buf;
video_buf_t zoom_buf;
video_buf_t frame_buf;
video_convert_p video_convert;
int video_pixel_format;
int display_pixel_format;
int width, height, bpp;
pthread_t capture_id;
pthread_t convert_id;
pthread_t display_id;
main_info_t cfg_para;
if(argc != 2)
{
printf("Usage : video2lcd </dev/video0,1,2,3...>\n");
return -1;
}
error = display_module_init();
if(error)
{
printf("display_module_init failed!\n");
exit(0);
}
select_init_disp_dev("fb");
get_disp_resolution(&width, &height, &bpp);
get_videobuf_for_display(&frame_buf);
display_pixel_format = frame_buf.pixel_format;
cfg_para.display_pixel_format = display_pixel_format;
error = video_module_init();
if(error)
{
printf("display_module_init failed!\n");
exit(0);
}
error = video_device_init(argv[1], &video_dev);
if(error)
{
printf("video_video_module_init failed!\n");
exit(0);
}
video_pixel_format = video_dev.video_ops->get_format(&video_dev);
cfg_para.capture_pixel_format = video_pixel_format;
error = video_convert_init();
if(error)
{
printf("display_module_init failed!\n");
exit(0);
}
video_convert = get_video_convert_by_formats(video_pixel_format, display_pixel_format);
if(!video_convert)
{
printf("Get_video_convert_for_formats failed!\n");
exit(0);
}
error = video_dev.video_ops->start_device(&video_dev);
if(error)
{
printf("video device start failed!\n");
exit(0);
}
memset(&zoom_buf, 0, sizeof(zoom_buf));
memset(&video_buf, 0, sizeof(video_buf));
memset(&convert_buf, 0, sizeof(convert_buf));
convert_buf.pixel_datas.bpp = bpp;
convert_buf.pixel_format = display_pixel_format;
cfg_para.video_dev = &video_dev;
cfg_para.video_buf = &video_buf;
cfg_para.video_convert = video_convert;
cfg_para.convert_buf = &convert_buf;
cfg_para.frame_buf = &frame_buf;
cfg_para.width = width;
cfg_para.height = height;
cfg_para.convert_bpp = bpp;
cfg_para.capture2convert = MBX_create(2);
cfg_para.convert2display = MBX_create(2);
if(pthread_create(&capture_id, NULL, capture_thread, (void *)&cfg_para))
{
printf("Capture thread create failed!\n");
exit(0);
}
if(pthread_create(&convert_id, NULL, convert_thread, (void *)&cfg_para))
{
printf("Convert thread create failed!\n");
exit(0);
}
if(pthread_create(&display_id, NULL, display_thread, (void *)&cfg_para))
{
printf("Display thread create failed!\n");
exit(0);
}
pthread_join(capture_id, NULL);
pthread_join(convert_id, NULL);
pthread_join(display_id, NULL);
return 0;
}
static void *capture_thread(void *arg)
{
int error;
main_info_p cfg_para = (main_info_p)arg;
video_device_p video_dev = cfg_para->video_dev;
video_buf_p video_buf = cfg_para->video_buf;
MBX_post(cfg_para->capture2convert, video_buf, sizeof(video_buf_t));
while(1)
{
error = video_dev->video_ops->get_frame(video_dev, video_buf);
if(error)
{
printf("Get frame failed\n");
return NULL;
}
MBX_post(cfg_para->capture2convert, video_buf, sizeof(video_buf_t));
error = video_dev->video_ops->put_frame(video_dev, video_buf);
if(error)
{
printf("Put frame failed\n");
return NULL;
}
}
return NULL;
}
static void *convert_thread(void *arg)
{
int error;
main_info_p cfg_para = (main_info_p)arg;
video_buf_p convert_buf = cfg_para->convert_buf;
video_buf_t cap_buf;
video_convert_p video_convert = cfg_para->video_convert;
int count=0;
convert_buf->pixel_datas.bpp = cfg_para->convert_bpp;
convert_buf->pixel_format = cfg_para->display_pixel_format;
MBX_pend(cfg_para->capture2convert,&cap_buf);
while(1)
{count++;
MBX_pend(cfg_para->capture2convert,&cap_buf);
if(cfg_para->capture_pixel_format != cfg_para->display_pixel_format)
{
error = video_convert->convert(&cap_buf, convert_buf);
if(error)
{
printf("Video convert failed\n");
return NULL;
}
}
MBX_post(cfg_para->convert2display, convert_buf, sizeof(video_buf_t));
}
return NULL;
}
static void *display_thread(void *arg)
{
main_info_p cfg_para = (main_info_p)arg;
video_buf_t convert_buf;
video_buf_p frame_buf = cfg_para->frame_buf;
int top_left_x, top_left_y;
//int count = 0;
while(1)
{
MBX_pend(cfg_para->convert2display,&convert_buf);
//merge to framebuffer
top_left_x = (cfg_para->width - convert_buf.pixel_datas.width)/2;
top_left_y = (cfg_para->height - convert_buf.pixel_datas.height)/2;
//dbg_put_file(&convert_buf);
pic_merge(top_left_x, top_left_y, &convert_buf.pixel_datas, &frame_buf->pixel_datas);
//display
flush_video_pixel_data_to_disp(&frame_buf->pixel_datas);
}
return NULL;
}