Rev 2421 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2421 | Rev 2427 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include "system.h" |
6 | #include "system.h" |
7 | #include |
7 | #include "../winlib/winlib.h" |
8 | #include "sound.h" |
8 | #include "sound.h" |
9 | #include "fplay.h" |
9 | #include "fplay.h" |
10 | 10 | ||
11 | #define CAPTION_HEIGHT 24 |
11 | #define CAPTION_HEIGHT 24 |
12 | 12 | ||
- | 13 | extern int res_pause_btn[]; |
|
- | 14 | extern int res_pause_btn_pressed[]; |
|
- | 15 | ||
- | 16 | extern int res_play_btn[]; |
|
- | 17 | extern int res_play_btn_pressed[]; |
|
- | 18 | ||
- | 19 | ||
13 | typedef struct |
20 | typedef struct |
14 | { |
21 | { |
15 | AVPicture picture; |
22 | AVPicture picture; |
16 | double pts; |
23 | double pts; |
17 | volatile int ready; |
24 | volatile int ready; |
18 | }vframe_t; |
25 | }vframe_t; |
19 | 26 | ||
20 | vframe_t frames[4]; |
27 | vframe_t frames[4]; |
21 | 28 | ||
22 | struct SwsContext *cvt_ctx = NULL; |
29 | struct SwsContext *cvt_ctx = NULL; |
23 | 30 | ||
24 | int vfx = 0; |
31 | int vfx = 0; |
25 | int dfx = 0; |
32 | int dfx = 0; |
26 | 33 | ||
27 | render_t *main_render; |
34 | render_t *main_render; |
28 | 35 | ||
29 | int width; |
36 | int width; |
30 | int height; |
37 | int height; |
31 | 38 | ||
32 | AVRational video_time_base; |
39 | AVRational video_time_base; |
33 | AVFrame *Frame; |
40 | AVFrame *Frame; |
34 | 41 | ||
35 | volatile uint32_t driver_lock; |
42 | volatile uint32_t driver_lock; |
36 | 43 | ||
37 | void get_client_rect(rect_t *rc); |
44 | void get_client_rect(rect_t *rc); |
38 | 45 | ||
39 | 46 | ||
40 | int init_video(AVCodecContext *ctx) |
47 | int init_video(AVCodecContext *ctx) |
41 | { |
48 | { |
42 | int i; |
49 | int i; |
43 | 50 | ||
44 | width = ctx->width; |
51 | width = ctx->width; |
45 | height = ctx->height; |
52 | height = ctx->height; |
46 | 53 | ||
47 | 54 | ||
48 | printf("w = %d h = %d\n\r", width, height); |
55 | printf("w = %d h = %d\n\r", width, height); |
49 | 56 | ||
50 | // __asm__ __volatile__("int3"); |
57 | // __asm__ __volatile__("int3"); |
51 | 58 | ||
52 | main_render = create_render(ctx->width, ctx->height, |
59 | main_render = create_render(ctx->width, ctx->height, |
53 | ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT); |
60 | ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT); |
54 | // render = create_render(ctx->width, ctx->height, |
61 | // render = create_render(ctx->width, ctx->height, |
55 | // ctx->pix_fmt, 0); |
62 | // ctx->pix_fmt, 0); |
56 | // |
63 | // |
57 | if( main_render == NULL) |
64 | if( main_render == NULL) |
58 | { |
65 | { |
59 | printf("Cannot create render\n\r"); |
66 | printf("Cannot create render\n\r"); |
60 | return 0; |
67 | return 0; |
61 | }; |
68 | }; |
62 | 69 | ||
63 | Frame = avcodec_alloc_frame(); |
70 | Frame = avcodec_alloc_frame(); |
64 | if ( Frame == NULL ) |
71 | if ( Frame == NULL ) |
65 | { |
72 | { |
66 | printf("Cannot alloc video frame\n\r"); |
73 | printf("Cannot alloc video frame\n\r"); |
67 | return 0; |
74 | return 0; |
68 | }; |
75 | }; |
69 | 76 | ||
70 | for( i=0; i < 4; i++) |
77 | for( i=0; i < 4; i++) |
71 | { |
78 | { |
72 | int ret; |
79 | int ret; |
73 | 80 | ||
74 | // printf("alloc picture %d %d %x\n", |
81 | // printf("alloc picture %d %d %x\n", |
75 | // ctx->width, ctx->height, ctx->pix_fmt ); |
82 | // ctx->width, ctx->height, ctx->pix_fmt ); |
76 | 83 | ||
77 | ret = avpicture_alloc(&frames[i].picture, ctx->pix_fmt, |
84 | ret = avpicture_alloc(&frames[i].picture, ctx->pix_fmt, |
78 | ctx->width, ctx->height); |
85 | ctx->width, ctx->height); |
79 | if ( ret != 0 ) |
86 | if ( ret != 0 ) |
80 | { |
87 | { |
81 | printf("Cannot alloc video buffer\n\r"); |
88 | printf("Cannot alloc video buffer\n\r"); |
82 | return 0; |
89 | return 0; |
83 | }; |
90 | }; |
84 | 91 | ||
85 | frames[i].pts = 0; |
92 | frames[i].pts = 0; |
86 | frames[i].ready = 0; |
93 | frames[i].ready = 0; |
87 | }; |
94 | }; |
88 | 95 | ||
89 | create_thread(video_thread, ctx, 1024*1024); |
96 | create_thread(video_thread, ctx, 1024*1024); |
90 | 97 | ||
91 | delay(50); |
98 | delay(50); |
92 | return 1; |
99 | return 1; |
93 | }; |
100 | }; |
94 | 101 | ||
95 | int decode_video(AVCodecContext *ctx, queue_t *qv) |
102 | int decode_video(AVCodecContext *ctx, queue_t *qv) |
96 | { |
103 | { |
97 | AVPacket pkt; |
104 | AVPacket pkt; |
98 | double pts; |
105 | double pts; |
99 | int frameFinished; |
106 | int frameFinished; |
100 | 107 | double current_clock; |
|
- | 108 | ||
101 | if(frames[dfx].ready != 0 ) |
109 | if(frames[dfx].ready != 0 ) |
102 | return 1; |
110 | return 1; |
103 | 111 | ||
104 | if( get_packet(qv, &pkt) == 0 ) |
112 | if( get_packet(qv, &pkt) == 0 ) |
105 | return 0; |
113 | return 0; |
106 | 114 | ||
- | 115 | current_clock = -80.0 + get_master_clock(); |
|
- | 116 | ||
- | 117 | if( pkt.dts == AV_NOPTS_VALUE && |
|
- | 118 | Frame->reordered_opaque != AV_NOPTS_VALUE) |
|
- | 119 | pts = Frame->reordered_opaque; |
|
- | 120 | else if(pkt.dts != AV_NOPTS_VALUE) |
|
- | 121 | pts= pkt.dts; |
|
- | 122 | else |
|
- | 123 | pts= 0; |
|
- | 124 | ||
- | 125 | pts *= av_q2d(video_time_base)*1000.0; |
|
- | 126 | ||
- | 127 | if( pts > current_clock) |
|
- | 128 | { |
|
107 | frameFinished = 0; |
129 | frameFinished = 0; |
108 | 130 | ||
109 | ctx->reordered_opaque = pkt.pts; |
131 | ctx->reordered_opaque = pkt.pts; |
110 | 132 | ||
111 | if(avcodec_decode_video2(ctx, Frame, &frameFinished, &pkt) <= 0) |
133 | if(avcodec_decode_video2(ctx, Frame, &frameFinished, &pkt) <= 0) |
112 | printf("video decoder error\n"); |
134 | printf("video decoder error\n"); |
113 | 135 | ||
114 | if(frameFinished) |
136 | if(frameFinished) |
115 | { |
137 | { |
116 | AVPicture *dst_pic; |
138 | AVPicture *dst_pic; |
117 | 139 | ||
118 | - | ||
119 | if( pkt.dts == AV_NOPTS_VALUE && |
140 | if( pkt.dts == AV_NOPTS_VALUE && |
120 | Frame->reordered_opaque != AV_NOPTS_VALUE) |
141 | Frame->reordered_opaque != AV_NOPTS_VALUE) |
121 | pts = Frame->reordered_opaque; |
142 | pts = Frame->reordered_opaque; |
122 | else if(pkt.dts != AV_NOPTS_VALUE) |
143 | else if(pkt.dts != AV_NOPTS_VALUE) |
123 | pts= pkt.dts; |
144 | pts= pkt.dts; |
124 | else |
145 | else |
125 | pts= 0; |
146 | pts= 0; |
126 | 147 | ||
127 | // pts = *(int64_t*)av_opt_ptr(avcodec_get_frame_class(), |
148 | // pts = *(int64_t*)av_opt_ptr(avcodec_get_frame_class(), |
128 | // Frame, "best_effort_timestamp"); |
149 | // Frame, "best_effort_timestamp"); |
129 | 150 | ||
130 | // if (pts == AV_NOPTS_VALUE) |
151 | // if (pts == AV_NOPTS_VALUE) |
131 | // pts = 0; |
152 | // pts = 0; |
132 | 153 | ||
133 | pts *= av_q2d(video_time_base); |
154 | pts *= av_q2d(video_time_base); |
134 | 155 | ||
135 | dst_pic = &frames[dfx].picture; |
156 | dst_pic = &frames[dfx].picture; |
136 | 157 | ||
137 | av_image_copy(dst_pic->data, dst_pic->linesize, |
158 | av_image_copy(dst_pic->data, dst_pic->linesize, |
138 | (const uint8_t**)Frame->data, |
159 | (const uint8_t**)Frame->data, |
139 | Frame->linesize, ctx->pix_fmt, ctx->width, ctx->height); |
160 | Frame->linesize, ctx->pix_fmt, ctx->width, ctx->height); |
140 | 161 | ||
141 | frames[dfx].pts = pts*1000.0; |
162 | frames[dfx].pts = pts*1000.0; |
142 | frames[dfx].ready = 1; |
163 | frames[dfx].ready = 1; |
143 | 164 | ||
144 | dfx++; |
165 | dfx++; |
145 | dfx&= 3; |
166 | dfx&= 3; |
146 | }; |
167 | }; |
147 | av_free_packet(&pkt); |
168 | }; |
- | 169 | av_free_packet(&pkt); |
|
148 | 170 | ||
149 | return 1; |
171 | return 1; |
150 | } |
172 | } |
151 | 173 | ||
152 | extern volatile uint32_t status; |
174 | extern volatile enum player_state player_state; |
153 | rect_t win_rect; |
175 | //rect_t win_rect; |
154 | 176 | ||
155 | 177 | ||
156 | int MainWindowProc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
178 | int MainWindowProc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
157 | { |
179 | { |
158 | window_t *win; |
180 | window_t *win; |
159 | 181 | ||
160 | win = (window_t*)ctrl; |
182 | win = (window_t*)ctrl; |
161 | 183 | ||
162 | switch(msg) |
184 | switch(msg) |
163 | { |
185 | { |
164 | case MSG_SIZE: |
186 | case MSG_SIZE: |
165 | //printf("MSG_SIZE\n"); |
187 | //printf("MSG_SIZE\n"); |
166 | render_adjust_size(main_render, win); |
188 | render_adjust_size(main_render, win); |
167 | break; |
189 | break; |
168 | 190 | ||
169 | case MSG_DRAW_CLIENT: |
191 | case MSG_DRAW_CLIENT: |
170 | render_draw_client(main_render); |
192 | render_draw_client(main_render); |
171 | break; |
193 | break; |
172 | 194 | ||
- | 195 | case MSG_LBTNDOWN: |
|
- | 196 | if(player_state == PAUSE) |
|
- | 197 | { |
|
- | 198 | win->panel.play_btn->img_default = res_play_btn; |
|
- | 199 | win->panel.play_btn->img_hilite = res_play_btn; |
|
- | 200 | win->panel.play_btn->img_pressed = res_play_btn_pressed; |
|
- | 201 | send_message(win->panel.play_btn, MSG_PAINT, 0, 0); |
|
- | 202 | player_state = PLAY_RESTART; |
|
- | 203 | ||
- | 204 | } |
|
- | 205 | else if(player_state == PLAY) |
|
- | 206 | { |
|
- | 207 | win->panel.play_btn->img_default = res_pause_btn; |
|
- | 208 | win->panel.play_btn->img_hilite = res_pause_btn; |
|
- | 209 | win->panel.play_btn->img_pressed = res_pause_btn_pressed; |
|
- | 210 | send_message(win->panel.play_btn, MSG_PAINT, 0, 0); |
|
- | 211 | player_state = PAUSE; |
|
- | 212 | } |
|
- | 213 | break; |
|
- | 214 | ||
173 | case MSG_COMMAND: |
215 | case MSG_COMMAND: |
174 | switch((short)arg1) |
216 | switch((short)arg1) |
175 | { |
217 | { |
176 | case ID_CLOSE: |
218 | case ID_PLAY: |
177 | exit(0); |
219 | if(player_state == PAUSE) |
- | 220 | { |
|
- | 221 | win->panel.play_btn->img_default = res_play_btn; |
|
- | 222 | win->panel.play_btn->img_hilite = res_play_btn; |
|
- | 223 | win->panel.play_btn->img_pressed = res_play_btn_pressed; |
|
- | 224 | player_state = PLAY_RESTART; |
|
- | 225 | } |
|
- | 226 | else if(player_state == PLAY) |
|
- | 227 | { |
|
- | 228 | win->panel.play_btn->img_default = res_pause_btn; |
|
- | 229 | win->panel.play_btn->img_hilite = res_pause_btn; |
|
- | 230 | win->panel.play_btn->img_pressed = res_pause_btn_pressed; |
|
- | 231 | player_state = PAUSE; |
|
- | 232 | } |
|
- | 233 | break; |
|
- | 234 | default: |
|
- | 235 | break; |
|
178 | }; |
236 | } |
179 | break; |
237 | break; |
180 | 238 | ||
181 | default: |
239 | default: |
182 | def_window_proc(ctrl,msg,arg1,arg2); |
240 | def_window_proc(ctrl,msg,arg1,arg2); |
183 | }; |
241 | }; |
184 | return 0; |
242 | return 0; |
185 | }; |
243 | }; |
186 | 244 | ||
187 | void render_time(render_t *render) |
245 | void render_time(render_t *render) |
188 | { |
246 | { |
189 | double ctime; |
247 | double ctime; /* milliseconds */ |
190 | double fdelay; |
248 | double fdelay; /* milliseconds */ |
191 | 249 | ||
- | 250 | //again: |
|
- | 251 | ||
192 | if(status == 0) |
252 | if(player_state == CLOSED) |
193 | { |
253 | { |
194 | render->win->win_command = WIN_CLOSED; |
254 | render->win->win_command = WIN_CLOSED; |
195 | return; |
255 | return; |
196 | }; |
256 | } |
- | 257 | else if(player_state != PLAY) |
|
- | 258 | { |
|
- | 259 | yield(); |
|
- | 260 | return; |
|
- | 261 | }; |
|
197 | 262 | ||
198 | if(frames[vfx].ready == 1 ) |
263 | if(frames[vfx].ready == 1 ) |
199 | { |
264 | { |
200 | ctime = get_master_clock(); |
265 | ctime = get_master_clock(); |
201 | fdelay = (frames[vfx].pts - ctime); |
266 | fdelay = (frames[vfx].pts - ctime); |
202 | 267 | ||
203 | // printf("pts %f time %f delay %f\n", |
268 | // printf("pts %f time %f delay %f\n", |
204 | // frames[vfx].pts, ctime, fdelay); |
269 | // frames[vfx].pts, ctime, fdelay); |
205 | 270 | ||
206 | if(fdelay < 0.0 ) |
271 | if(fdelay > 20.0) |
207 | { |
- | |
208 | int next_vfx; |
- | |
209 | fdelay = 0; |
- | |
210 | next_vfx = (vfx+1) & 3; |
- | |
211 | if( frames[next_vfx].ready == 1 ) |
- | |
212 | { |
272 | { |
213 | if(frames[next_vfx].pts <= ctime) |
- | |
214 | { |
- | |
215 | frames[vfx].ready = 0; // skip this frame |
- | |
216 | vfx++; |
- | |
217 | vfx&= 3; |
- | |
218 | } |
- | |
219 | else |
- | |
220 | { |
- | |
221 | if( (frames[next_vfx].pts - ctime) < |
- | |
222 | ( ctime - frames[vfx].pts) ) |
- | |
223 | { |
273 | delay(2); |
224 | frames[vfx].ready = 0; // skip this frame |
- | |
225 | vfx++; |
- | |
226 | vfx&= 3; |
- | |
227 | fdelay = (frames[next_vfx].pts - ctime); |
- | |
228 | } |
- | |
229 | } |
- | |
230 | }; |
- | |
231 | }; |
- | |
232 | - | ||
233 | if(fdelay > 10.0) |
- | |
234 | { |
- | |
235 | // delay( (uint32_t)(fdelay/10.0)); |
- | |
236 | yield(); |
274 | // yield(); |
237 | return; |
275 | return; |
238 | }; |
276 | }; |
239 | 277 | ||
240 | main_render->draw(main_render, &frames[vfx].picture); |
278 | main_render->draw(main_render, &frames[vfx].picture); |
241 | frames[vfx].ready = 0; |
279 | frames[vfx].ready = 0; |
242 | vfx++; |
280 | vfx++; |
243 | vfx&= 3; |
281 | vfx&= 3; |
244 | }; |
282 | } |
245 | } |
- | |
246 | 283 | else yield(); |
|
- | 284 | ||
- | 285 | } |
|
- | 286 | ||
- | 287 | ||
- | 288 | ||
- | 289 | ||
247 | extern char *movie_file; |
290 | extern char *movie_file; |
248 | 291 | ||
249 | int video_thread(void *param) |
292 | int video_thread(void *param) |
250 | { |
293 | { |
251 | window_t *MainWindow; |
294 | window_t *MainWindow; |
252 | 295 | ||
253 | init_winlib(); |
296 | init_winlib(); |
254 | 297 | ||
255 | MainWindow = create_window(movie_file,0, |
298 | MainWindow = create_window(movie_file,0, |
256 | 10,10,width+14,height+29,MainWindowProc); |
299 | 10,10,width,height+29+75,MainWindowProc); |
257 | 300 | ||
258 | // printf("MainWindow %x\n", MainWindow); |
301 | // printf("MainWindow %x\n", MainWindow); |
259 | 302 | ||
260 | main_render->win = MainWindow; |
303 | main_render->win = MainWindow; |
261 | 304 | ||
262 | show_window(MainWindow, NORMAL); |
305 | show_window(MainWindow, NORMAL); |
263 | run_render(MainWindow, main_render); |
306 | run_render(MainWindow, main_render); |
264 | 307 | ||
265 | // printf("exit thread\n"); |
308 | // printf("exit thread\n"); |
266 | status = 0; |
309 | player_state = CLOSED; |
267 | return 0; |
310 | return 0; |
268 | }; |
311 | }; |
269 | 312 | ||
270 | 313 | ||
271 | void draw_hw_picture(render_t *render, AVPicture *picture); |
314 | void draw_hw_picture(render_t *render, AVPicture *picture); |
272 | void draw_sw_picture(render_t *render, AVPicture *picture); |
315 | void draw_sw_picture(render_t *render, AVPicture *picture); |
273 | 316 | ||
274 | render_t *create_render(uint32_t width, uint32_t height, |
317 | render_t *create_render(uint32_t width, uint32_t height, |
275 | uint32_t ctx_format, uint32_t flags) |
318 | uint32_t ctx_format, uint32_t flags) |
276 | { |
319 | { |
277 | render_t *render; |
320 | render_t *render; |
278 | 321 | ||
279 | // __asm__ __volatile__("int3"); |
322 | // __asm__ __volatile__("int3"); |
280 | 323 | ||
281 | render = (render_t*)malloc(sizeof(render_t)); |
324 | render = (render_t*)malloc(sizeof(render_t)); |
282 | memset(render, 0, sizeof(render_t)); |
325 | memset(render, 0, sizeof(render_t)); |
283 | 326 | ||
284 | render->ctx_width = width; |
327 | render->ctx_width = width; |
285 | render->ctx_height = height; |
328 | render->ctx_height = height; |
286 | render->ctx_format = ctx_format; |
329 | render->ctx_format = ctx_format; |
287 | 330 | ||
288 | mutex_lock(&driver_lock); |
331 | mutex_lock(&driver_lock); |
289 | render->caps = InitPixlib(flags); |
332 | render->caps = InitPixlib(flags); |
290 | mutex_unlock(&driver_lock); |
333 | mutex_unlock(&driver_lock); |
291 | 334 | ||
292 | if(render->caps==0) |
335 | if(render->caps==0) |
293 | { |
336 | { |
294 | printf("FPlay render engine: Hardware acceleration disabled\n"); |
337 | printf("FPlay render engine: Hardware acceleration disabled\n"); |
295 | render->draw = draw_sw_picture; |
338 | render->draw = draw_sw_picture; |
296 | } |
339 | } |
297 | else |
340 | else |
298 | { |
341 | { |
299 | render->target = 0; |
342 | render->target = 0; |
300 | render->draw = draw_hw_picture; |
343 | render->draw = draw_hw_picture; |
301 | }; |
344 | }; |
302 | 345 | ||
303 | render->state = EMPTY; |
346 | render->state = EMPTY; |
304 | return render; |
347 | return render; |
305 | }; |
348 | }; |
306 | 349 | ||
307 | int render_set_size(render_t *render, int width, int height) |
350 | int render_set_size(render_t *render, int width, int height) |
308 | { |
351 | { |
309 | int i; |
352 | int i; |
310 | 353 | ||
311 | render->layout = 0; |
354 | render->layout = 0; |
312 | render->rcvideo.l = 0; |
355 | render->rcvideo.l = 0; |
313 | render->rcvideo.t = 0; |
356 | render->rcvideo.t = 0; |
314 | render->rcvideo.r = width; |
357 | render->rcvideo.r = width; |
315 | render->rcvideo.b = height; |
358 | render->rcvideo.b = height; |
316 | 359 | ||
317 | if( render->win_height > height ) |
360 | if( render->win_height > height ) |
318 | { |
361 | { |
319 | int yoffs; |
362 | int yoffs; |
320 | yoffs = (render->win_height-height)/2; |
363 | yoffs = (render->win_height-height)/2; |
321 | if(yoffs) |
364 | if(yoffs) |
322 | { |
365 | { |
323 | render->rctop.t = 0; |
366 | render->rctop.t = 0; |
324 | render->rctop.b = yoffs; |
367 | render->rctop.b = yoffs; |
325 | render->rcvideo.t = yoffs; |
368 | render->rcvideo.t = yoffs; |
326 | render->layout |= HAS_TOP; |
369 | render->layout |= HAS_TOP; |
327 | } |
370 | } |
328 | 371 | ||
329 | yoffs = render->win_height-(render->rcvideo.t+render->rcvideo.b); |
372 | yoffs = render->win_height-(render->rcvideo.t+render->rcvideo.b); |
330 | if(yoffs) |
373 | if(yoffs) |
331 | { |
374 | { |
332 | render->rcbottom.t = render->rcvideo.t+render->rcvideo.b; |
375 | render->rcbottom.t = render->rcvideo.t+render->rcvideo.b; |
333 | render->rcbottom.b = yoffs; |
376 | render->rcbottom.b = yoffs; |
334 | render->layout |= HAS_BOTTOM; |
377 | render->layout |= HAS_BOTTOM; |
335 | } |
378 | } |
336 | } |
379 | } |
337 | 380 | ||
338 | if( render->win_width > width ) |
381 | if( render->win_width > width ) |
339 | { |
382 | { |
340 | int xoffs; |
383 | int xoffs; |
341 | xoffs = (render->win_width-width)/2; |
384 | xoffs = (render->win_width-width)/2; |
342 | if(xoffs) |
385 | if(xoffs) |
343 | { |
386 | { |
344 | render->rcleft.r = xoffs; |
387 | render->rcleft.r = xoffs; |
345 | render->rcvideo.l = xoffs; |
388 | render->rcvideo.l = xoffs; |
346 | render->layout |= HAS_LEFT; |
389 | render->layout |= HAS_LEFT; |
347 | } |
390 | } |
348 | xoffs = render->win_width-(render->rcvideo.l+render->rcvideo.r); |
391 | xoffs = render->win_width-(render->rcvideo.l+render->rcvideo.r); |
349 | if(xoffs) |
392 | if(xoffs) |
350 | { |
393 | { |
351 | render->rcright.l = render->rcvideo.l+render->rcvideo.r; |
394 | render->rcright.l = render->rcvideo.l+render->rcvideo.r; |
352 | render->rcright.r = xoffs; |
395 | render->rcright.r = xoffs; |
353 | render->layout |= HAS_RIGHT; |
396 | render->layout |= HAS_RIGHT; |
354 | } |
397 | } |
355 | }; |
398 | }; |
356 | 399 | ||
357 | if(render->state == EMPTY) |
400 | if(render->state == EMPTY) |
358 | { |
401 | { |
359 | if(render->caps & HW_TEX_BLIT) |
402 | if(render->caps & HW_TEX_BLIT) |
360 | { |
403 | { |
361 | for( i=0; i < 4; i++) |
404 | for( i=0; i < 4; i++) |
362 | { |
405 | { |
363 | render->bitmap[i].width = render->ctx_width; |
406 | render->bitmap[i].width = render->ctx_width; |
364 | render->bitmap[i].height = render->ctx_height; |
407 | render->bitmap[i].height = render->ctx_height; |
365 | 408 | ||
366 | if( create_bitmap(&render->bitmap[i]) != 0 ) |
409 | if( create_bitmap(&render->bitmap[i]) != 0 ) |
367 | { |
410 | { |
368 | status = 0; |
411 | player_state = CLOSED; |
369 | /* |
412 | /* |
370 | * Epic fail. Need exit_thread() here |
413 | * Epic fail. Need exit_thread() here |
371 | * |
414 | * |
372 | */ |
415 | */ |
373 | return 0; |
416 | return 0; |
374 | }; |
417 | }; |
375 | } |
418 | } |
376 | } |
419 | } |
377 | else |
420 | else |
378 | { |
421 | { |
379 | render->bitmap[0].width = width; |
422 | render->bitmap[0].width = width; |
380 | render->bitmap[0].height = height; |
423 | render->bitmap[0].height = height; |
381 | 424 | ||
382 | if( create_bitmap(&render->bitmap[0]) != 0 ) |
425 | if( create_bitmap(&render->bitmap[0]) != 0 ) |
383 | return 0; |
426 | return 0; |
384 | }; |
427 | }; |
385 | render->state = INIT; |
428 | render->state = INIT; |
386 | return 0; |
429 | return 0; |
387 | }; |
430 | }; |
388 | 431 | ||
389 | if(render->caps & HW_TEX_BLIT) /* hw scaler */ |
432 | if(render->caps & HW_TEX_BLIT) /* hw scaler */ |
390 | return 0; |
433 | return 0; |
391 | 434 | ||
392 | render->bitmap[0].width = width; |
435 | render->bitmap[0].width = width; |
393 | render->bitmap[0].height = height; |
436 | render->bitmap[0].height = height; |
394 | resize_bitmap(&render->bitmap[0]); |
437 | resize_bitmap(&render->bitmap[0]); |
395 | 438 | ||
396 | return 0; |
439 | return 0; |
397 | }; |
440 | }; |
398 | 441 | ||
399 | void render_adjust_size(render_t *render, window_t *win) |
442 | void render_adjust_size(render_t *render, window_t *win) |
400 | { |
443 | { |
401 | uint32_t right, bottom, new_w, new_h; |
444 | uint32_t right, bottom, new_w, new_h; |
402 | uint32_t s, sw, sh; |
445 | uint32_t s, sw, sh; |
403 | uint8_t state; |
446 | uint8_t state; |
404 | 447 | ||
405 | 448 | ||
406 | right = win->w; |
449 | right = win->w; |
407 | bottom = win->h-CAPTION_HEIGHT; |
450 | bottom = win->h-CAPTION_HEIGHT-75; |
408 | render->win_state = win->win_state; |
451 | render->win_state = win->win_state; |
409 | 452 | ||
410 | if(render->win_state == MINIMIZED) |
453 | if(render->win_state == MINIMIZED) |
411 | return; |
454 | return; |
412 | 455 | ||
413 | if(render->win_state == ROLLED) |
456 | if(render->win_state == ROLLED) |
414 | return; |
457 | return; |
415 | 458 | ||
416 | if( right == render->win_width && |
459 | if( right == render->win_width && |
417 | bottom == render->win_height) |
460 | bottom == render->win_height) |
418 | return; |
461 | return; |
419 | 462 | ||
420 | new_w = bottom*render->ctx_width/render->ctx_height; |
463 | new_w = bottom*render->ctx_width/render->ctx_height; |
421 | new_h = right*render->ctx_height/render->ctx_width; |
464 | new_h = right*render->ctx_height/render->ctx_width; |
422 | 465 | ||
423 | // printf("new_w %d new_h %d\n", new_w, new_h); |
466 | // printf("new_w %d new_h %d\n", new_w, new_h); |
424 | 467 | ||
425 | s = right * bottom; |
468 | s = right * bottom; |
426 | sw = right * new_h; |
469 | sw = right * new_h; |
427 | sh = bottom * new_w; |
470 | sh = bottom * new_w; |
428 | 471 | ||
429 | if( abs(s-sw) > abs(s-sh)) |
472 | if( abs(s-sw) > abs(s-sh)) |
430 | new_h = bottom; |
473 | new_h = bottom; |
431 | else |
474 | else |
432 | new_w = right; |
475 | new_w = right; |
433 | 476 | ||
434 | if(new_w < 64) |
477 | if(new_w < 64) |
435 | { |
478 | { |
436 | new_w = 64; |
479 | new_w = 64; |
437 | new_h = 64*render->ctx_height/render->ctx_width; |
480 | new_h = 64*render->ctx_height/render->ctx_width; |
438 | }; |
481 | }; |
439 | 482 | ||
440 | render->win_width = win->w; |
483 | render->win_width = win->w; |
441 | render->win_height = win->h-CAPTION_HEIGHT; |
484 | render->win_height = win->h-CAPTION_HEIGHT-75; |
442 | render_set_size(render, new_w, new_h); |
485 | render_set_size(render, new_w, new_h); |
443 | }; |
486 | }; |
444 | 487 | ||
445 | void draw_hw_picture(render_t *render, AVPicture *picture) |
488 | void draw_hw_picture(render_t *render, AVPicture *picture) |
446 | { |
489 | { |
447 | int dst_width, dst_height; |
490 | int dst_width, dst_height; |
448 | bitmap_t *bitmap; |
491 | bitmap_t *bitmap; |
449 | uint8_t *data[4]; |
492 | uint8_t *data[4]; |
450 | int linesize[4]; |
493 | int linesize[4]; |
451 | int ret; |
494 | int ret; |
452 | 495 | ||
- | 496 | if(render->win_state == MINIMIZED || |
|
453 | if(render->win_state == ROLLED) |
497 | render->win_state == ROLLED) |
454 | return; |
498 | return; |
455 | 499 | ||
456 | if(render->caps & HW_TEX_BLIT) |
500 | if(render->caps & HW_TEX_BLIT) |
457 | { |
501 | { |
458 | dst_width = render->ctx_width; |
502 | dst_width = render->ctx_width; |
459 | dst_height = render->ctx_height; |
503 | dst_height = render->ctx_height; |
460 | } |
504 | } |
461 | else |
505 | else |
462 | { |
506 | { |
463 | dst_width = render->win_width; |
507 | dst_width = render->win_width; |
464 | dst_height = render->win_height; |
508 | dst_height = render->win_height; |
465 | }; |
509 | }; |
466 | 510 | ||
467 | cvt_ctx = sws_getCachedContext(cvt_ctx, |
511 | cvt_ctx = sws_getCachedContext(cvt_ctx, |
468 | render->ctx_width, render->ctx_height, render->ctx_format, |
512 | render->ctx_width, render->ctx_height, render->ctx_format, |
469 | dst_width, dst_height, PIX_FMT_BGRA, |
513 | dst_width, dst_height, PIX_FMT_BGRA, |
470 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
514 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
471 | if(cvt_ctx == NULL) |
515 | if(cvt_ctx == NULL) |
472 | { |
516 | { |
473 | printf("Cannot initialize the conversion context!\n"); |
517 | printf("Cannot initialize the conversion context!\n"); |
474 | return ; |
518 | return ; |
475 | }; |
519 | }; |
476 | 520 | ||
477 | bitmap = &render->bitmap[render->target]; |
521 | bitmap = &render->bitmap[render->target]; |
478 | 522 | ||
479 | ret = lock_bitmap(bitmap); |
523 | ret = lock_bitmap(bitmap); |
480 | if( ret != 0) |
524 | if( ret != 0) |
481 | { |
525 | { |
482 | printf("Cannot lock the bitmap!\n"); |
526 | printf("Cannot lock the bitmap!\n"); |
483 | return ; |
527 | return ; |
484 | } |
528 | } |
485 | 529 | ||
486 | // printf("sws_getCachedContext\n"); |
530 | // printf("sws_getCachedContext\n"); |
487 | data[0] = bitmap->data; |
531 | data[0] = bitmap->data; |
488 | data[1] = bitmap->data+1; |
532 | data[1] = bitmap->data+1; |
489 | data[2] = bitmap->data+2; |
533 | data[2] = bitmap->data+2; |
490 | data[3] = bitmap->data+3; |
534 | data[3] = bitmap->data+3; |
491 | 535 | ||
492 | linesize[0] = bitmap->pitch; |
536 | linesize[0] = bitmap->pitch; |
493 | linesize[1] = bitmap->pitch; |
537 | linesize[1] = bitmap->pitch; |
494 | linesize[2] = bitmap->pitch; |
538 | linesize[2] = bitmap->pitch; |
495 | linesize[3] = bitmap->pitch; |
539 | linesize[3] = bitmap->pitch; |
496 | 540 | ||
497 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
541 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
498 | picture->linesize, 0, render->ctx_height, data, linesize); |
542 | picture->linesize, 0, render->ctx_height, data, linesize); |
499 | // printf("sws_scale\n"); |
543 | // printf("sws_scale\n"); |
500 | 544 | ||
501 | blit_bitmap(bitmap, render->rcvideo.l, |
545 | blit_bitmap(bitmap, render->rcvideo.l, |
502 | CAPTION_HEIGHT+render->rcvideo.t, |
546 | CAPTION_HEIGHT+render->rcvideo.t, |
503 | render->rcvideo.r, render->rcvideo.b); |
547 | render->rcvideo.r, render->rcvideo.b); |
504 | // printf("blit_bitmap\n"); |
548 | render->last_bitmap = bitmap; |
- | 549 | // printf("blit_bitmap\n"); |
|
505 | 550 | ||
506 | 551 | ||
507 | render->target++; |
552 | render->target++; |
508 | render->target&= 3; |
553 | render->target&= 3; |
509 | } |
554 | } |
510 | 555 | ||
511 | void draw_sw_picture(render_t *render, AVPicture *picture) |
556 | void draw_sw_picture(render_t *render, AVPicture *picture) |
512 | { |
557 | { |
513 | uint8_t *data[4]; |
558 | uint8_t *data[4]; |
514 | int linesize[4]; |
559 | int linesize[4]; |
515 | 560 | ||
516 | if(render->win_state == MINIMIZED || |
561 | if(render->win_state == MINIMIZED || |
517 | render->win_state == ROLLED) |
562 | render->win_state == ROLLED) |
518 | return; |
563 | return; |
519 | 564 | ||
520 | cvt_ctx = sws_getCachedContext(cvt_ctx, |
565 | cvt_ctx = sws_getCachedContext(cvt_ctx, |
521 | render->ctx_width, render->ctx_height, |
566 | render->ctx_width, render->ctx_height, |
522 | render->ctx_format, |
567 | render->ctx_format, |
523 | render->rcvideo.r, render->rcvideo.b, |
568 | render->rcvideo.r, render->rcvideo.b, |
524 | PIX_FMT_BGRA, SWS_FAST_BILINEAR, NULL, NULL, NULL); |
569 | PIX_FMT_BGRA, SWS_FAST_BILINEAR, NULL, NULL, NULL); |
525 | if(cvt_ctx == NULL) |
570 | if(cvt_ctx == NULL) |
526 | { |
571 | { |
527 | printf("Cannot initialize the conversion context!\n"); |
572 | printf("Cannot initialize the conversion context!\n"); |
528 | return ; |
573 | return ; |
529 | } |
574 | } |
530 | 575 | ||
531 | data[0] = render->bitmap[0].data; |
576 | data[0] = render->bitmap[0].data; |
532 | data[1] = render->bitmap[0].data+1; |
577 | data[1] = render->bitmap[0].data+1; |
533 | data[2] = render->bitmap[0].data+2; |
578 | data[2] = render->bitmap[0].data+2; |
534 | data[3] = render->bitmap[0].data+3; |
579 | data[3] = render->bitmap[0].data+3; |
535 | 580 | ||
536 | 581 | ||
537 | linesize[0] = render->bitmap[0].pitch; |
582 | linesize[0] = render->bitmap[0].pitch; |
538 | linesize[1] = render->bitmap[0].pitch; |
583 | linesize[1] = render->bitmap[0].pitch; |
539 | linesize[2] = render->bitmap[0].pitch; |
584 | linesize[2] = render->bitmap[0].pitch; |
540 | linesize[3] = render->bitmap[0].pitch; |
585 | linesize[3] = render->bitmap[0].pitch; |
541 | 586 | ||
542 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
587 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
543 | picture->linesize, 0, render->ctx_height, data, linesize); |
588 | picture->linesize, 0, render->ctx_height, data, linesize); |
544 | 589 | ||
545 | blit_bitmap(&render->bitmap[0], render->rcvideo.l, |
590 | blit_bitmap(&render->bitmap[0], render->rcvideo.l, |
546 | render->rcvideo.t+CAPTION_HEIGHT, |
591 | render->rcvideo.t+CAPTION_HEIGHT, |
547 | render->rcvideo.r, render->rcvideo.b); |
592 | render->rcvideo.r, render->rcvideo.b); |
548 | } |
593 | render->last_bitmap = &render->bitmap[0]; |
- | 594 | } |
|
549 | 595 | ||
550 | void render_draw_client(render_t *render) |
596 | void render_draw_client(render_t *render) |
551 | { |
597 | { |
552 | if(render->win_state == MINIMIZED || |
598 | if(render->win_state == MINIMIZED || |
553 | render->win_state == ROLLED) |
599 | render->win_state == ROLLED) |
554 | return; |
600 | return; |
555 | 601 | ||
- | 602 | if(player_state == PAUSE) |
|
- | 603 | { |
|
- | 604 | main_render->draw(main_render, &frames[vfx].picture); |
|
- | 605 | }; |
|
- | 606 | ||
556 | if(render->layout & HAS_TOP) |
607 | if(render->layout & HAS_TOP) |
557 | draw_bar(0, CAPTION_HEIGHT, render->win_width, |
608 | draw_bar(0, CAPTION_HEIGHT, render->win_width, |
558 | render->rctop.b, 0); |
609 | render->rctop.b, 0); |
559 | if(render->layout & HAS_LEFT) |
610 | if(render->layout & HAS_LEFT) |
560 | draw_bar(0, render->rcvideo.t+CAPTION_HEIGHT, render->rcleft.r, |
611 | draw_bar(0, render->rcvideo.t+CAPTION_HEIGHT, render->rcleft.r, |
561 | render->rcvideo.b, 0); |
612 | render->rcvideo.b, 0); |
562 | if(render->layout & HAS_RIGHT) |
613 | if(render->layout & HAS_RIGHT) |
563 | draw_bar(render->rcright.l, render->rcvideo.t+CAPTION_HEIGHT, |
614 | draw_bar(render->rcright.l, render->rcvideo.t+CAPTION_HEIGHT, |
564 | render->rcright.r, render->rcvideo.b, 0); |
615 | render->rcright.r, render->rcvideo.b, 0); |
565 | if(render->layout & HAS_BOTTOM) |
616 | if(render->layout & HAS_BOTTOM) |
566 | draw_bar(0, render->rcbottom.t+CAPTION_HEIGHT, |
617 | draw_bar(0, render->rcbottom.t+CAPTION_HEIGHT, |
567 | render->win_width, render->rcbottom.b, 0); |
618 | render->win_width, render->rcbottom.b, 0); |
568 | }>> |
619 | }>>=>> |
569 | >=>>=>> |
620 | |
- | 621 | ||
- | 622 | ||
- | 623 |