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