Rev 2349 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2349 | Rev 2415 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
- | 5 | #include |
|
- | 6 | #include "system.h" |
|
- | 7 | #include |
|
5 | #include "sound.h" |
8 | #include "sound.h" |
6 | #include "fplay.h" |
9 | #include "fplay.h" |
Line 7... | Line 10... | ||
7 | 10 | ||
Line 19... | Line 22... | ||
19 | 22 | ||
Line 20... | Line 23... | ||
20 | int vfx = 0; |
23 | int vfx = 0; |
21 | int dfx = 0; |
24 | int dfx = 0; |
Line 22... | Line 25... | ||
22 | 25 | ||
Line 23... | Line 26... | ||
23 | render_t *render; |
26 | render_t *main_render; |
24 | 27 | ||
Line 25... | Line 28... | ||
25 | int width; |
28 | int width; |
Line 43... | Line 46... | ||
43 | printf("w = %d h = %d\n\r", width, height); |
46 | printf("w = %d h = %d\n\r", width, height); |
Line 44... | Line 47... | ||
44 | 47 | ||
Line 45... | Line 48... | ||
45 | // __asm__ __volatile__("int3"); |
48 | // __asm__ __volatile__("int3"); |
46 | 49 | ||
- | 50 | main_render = create_render(ctx->width, ctx->height, |
|
- | 51 | ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT); |
|
- | 52 | // render = create_render(ctx->width, ctx->height, |
|
47 | render = create_render(ctx->width, ctx->height, |
53 | // ctx->pix_fmt, 0); |
48 | ctx->pix_fmt, HW_BIT_BLIT|HW_TEX_BLIT); |
54 | // |
49 | if( render == NULL) |
55 | if( main_render == NULL) |
50 | { |
56 | { |
51 | printf("Cannot create render\n\r"); |
57 | printf("Cannot create render\n\r"); |
Line 83... | Line 89... | ||
83 | delay(50); |
89 | delay(50); |
84 | return 1; |
90 | return 1; |
85 | }; |
91 | }; |
Line 86... | Line -... | ||
86 | - | ||
87 | int frameFinished=0; |
- | |
88 | static int frame_count; |
- | |
89 | 92 | ||
90 | int decode_video(AVCodecContext *ctx, queue_t *qv) |
93 | int decode_video(AVCodecContext *ctx, queue_t *qv) |
91 | { |
94 | { |
92 | AVPacket pkt; |
95 | AVPacket pkt; |
93 | double pts; |
96 | double pts; |
Line 94... | Line 97... | ||
94 | double av_time; |
97 | int frameFinished; |
95 | 98 | ||
Line 96... | Line 99... | ||
96 | if(frames[dfx].ready != 0 ) |
99 | if(frames[dfx].ready != 0 ) |
Line 128... | Line 131... | ||
128 | pts *= av_q2d(video_time_base); |
131 | pts *= av_q2d(video_time_base); |
Line 129... | Line 132... | ||
129 | 132 | ||
Line 130... | Line 133... | ||
130 | dst_pic = &frames[dfx].picture; |
133 | dst_pic = &frames[dfx].picture; |
- | 134 | ||
131 | 135 | av_image_copy(dst_pic->data, dst_pic->linesize, |
|
Line 132... | Line 136... | ||
132 | av_image_copy(dst_pic->data, dst_pic->linesize, Frame->data, |
136 | (const uint8_t**)Frame->data, |
133 | Frame->linesize, ctx->pix_fmt, ctx->width, ctx->height); |
137 | Frame->linesize, ctx->pix_fmt, ctx->width, ctx->height); |
Line 145... | Line 149... | ||
145 | 149 | ||
Line 146... | Line 150... | ||
146 | extern volatile uint32_t status; |
150 | extern volatile uint32_t status; |
147 | rect_t win_rect; |
151 | rect_t win_rect; |
Line -... | Line 152... | ||
- | 152 | ||
148 | 153 | ||
149 | int check_events() |
154 | int MainWindowProc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
150 | { |
155 | { |
Line 151... | Line 156... | ||
151 | int ev; |
156 | window_t *win; |
Line 152... | Line 157... | ||
152 | 157 | ||
153 | ev = check_os_event(); |
158 | win = (window_t*)ctrl; |
154 | 159 | ||
155 | switch(ev) |
160 | switch(msg) |
156 | { |
- | |
157 | case 1: |
161 | { |
158 | render_adjust_size(render); |
- | |
159 | BeginDraw(); |
162 | case MSG_SIZE: |
Line 160... | Line 163... | ||
160 | DrawWindow(0,0,0,0, NULL, 0x000000,0x73); |
163 | //printf("MSG_SIZE\n"); |
161 | EndDraw(); |
164 | render_adjust_size(main_render, win); |
162 | break; |
- | |
163 | 165 | break; |
|
164 | case 3: |
- | |
165 | if(get_os_button()==1) |
- | |
166 | status = 0; |
- | |
167 | break; |
- | |
168 | }; |
- | |
169 | return 1; |
- | |
Line -... | Line 166... | ||
- | 166 | ||
170 | } |
167 | case MSG_DRAW_CLIENT: |
171 | 168 | render_draw_client(main_render); |
|
172 | 169 | break; |
|
173 | extern char *movie_file; |
170 | |
174 | - | ||
175 | int video_thread(void *param) |
171 | case MSG_COMMAND: |
176 | { |
- | |
177 | rect_t rc; |
172 | switch((short)arg1) |
Line -... | Line 173... | ||
- | 173 | { |
|
178 | AVCodecContext *ctx = param; |
174 | case ID_CLOSE: |
- | 175 | exit(0); |
|
- | 176 | }; |
|
- | 177 | break; |
|
Line 179... | Line 178... | ||
179 | 178 | ||
180 | BeginDraw(); |
179 | default: |
181 | DrawWindow(10, 10, width+9, height+26, movie_file, 0x000000,0x73); |
180 | def_window_proc(ctrl,msg,arg1,arg2); |
182 | EndDraw(); |
181 | }; |
Line -... | Line 182... | ||
- | 182 | return 0; |
|
- | 183 | }; |
|
- | 184 | ||
183 | 185 | void render_time(render_t *render) |
|
- | 186 | { |
|
Line 184... | Line 187... | ||
184 | render_adjust_size(render); |
187 | double ctime; |
185 | 188 | double fdelay; |
|
186 | while( status != 0) |
189 | |
187 | { |
190 | if(status == 0) |
Line 229... | Line 232... | ||
229 | { |
232 | { |
230 | delay( (uint32_t)(fdelay/10.0)); |
233 | delay( (uint32_t)(fdelay/10.0)); |
231 | }; |
234 | }; |
232 | 235 | ||
Line 233... | Line -... | ||
233 | // blit_bitmap(&frames[vfx].bitmap, 5, 22, width, height); |
- | |
234 | // frames[vfx].frame->linesize[0]); |
- | |
235 | render->draw(render, &frames[vfx].picture); |
236 | main_render->draw(main_render, &frames[vfx].picture); |
236 | frames[vfx].ready = 0; |
237 | frames[vfx].ready = 0; |
237 | vfx++; |
238 | vfx++; |
238 | vfx&= 3; |
239 | vfx&= 3; |
- | 240 | }; |
|
239 | } |
241 | } |
- | 242 | ||
240 | else |
243 | extern char *movie_file; |
- | 244 | ||
- | 245 | int video_thread(void *param) |
|
241 | { |
246 | { |
242 | yield(); |
247 | window_t *MainWindow; |
- | 248 | ||
243 | }; |
249 | init_winlib(); |
- | 250 | ||
- | 251 | MainWindow = create_window(movie_file,0, |
|
- | 252 | 10,10,width+14,height+29,MainWindowProc); |
|
- | 253 | ||
- | 254 | // printf("MainWindow %x\n", MainWindow); |
|
- | 255 | ||
- | 256 | main_render->win = MainWindow; |
|
- | 257 | ||
- | 258 | show_window(MainWindow, NORMAL); |
|
- | 259 | run_render(MainWindow, main_render); |
|
- | 260 | ||
- | 261 | // printf("exit thread\n"); |
|
244 | }; |
262 | status = 0; |
245 | return 0; |
263 | return 0; |
246 | }; |
264 | }; |
Line 247... | Line 265... | ||
247 | 265 | ||
248 | 266 | ||
Line 249... | Line 267... | ||
249 | void draw_hw_picture(render_t *render, AVPicture *picture); |
267 | void draw_hw_picture(render_t *render, AVPicture *picture); |
250 | void draw_sw_picture(render_t *render, AVPicture *picture); |
268 | void draw_sw_picture(render_t *render, AVPicture *picture); |
251 | 269 | ||
252 | render_t *create_render(uint32_t width, uint32_t height, |
270 | render_t *create_render(uint32_t width, uint32_t height, |
Line -... | Line 271... | ||
- | 271 | uint32_t ctx_format, uint32_t flags) |
|
- | 272 | { |
|
253 | uint32_t ctx_format, uint32_t flags) |
273 | render_t *render; |
254 | { |
274 | |
Line 255... | Line 275... | ||
255 | render_t *ren; |
275 | // __asm__ __volatile__("int3"); |
256 | 276 | ||
257 | render = (render_t*)malloc(sizeof(*ren)); |
277 | render = (render_t*)malloc(sizeof(render_t)); |
Line 283... | Line 303... | ||
283 | int render_set_size(render_t *render, int width, int height) |
303 | int render_set_size(render_t *render, int width, int height) |
284 | { |
304 | { |
285 | int i; |
305 | int i; |
Line -... | Line 306... | ||
- | 306 | ||
- | 307 | render->layout = 0; |
|
- | 308 | render->rcvideo.l = 0; |
|
286 | 309 | render->rcvideo.t = 0; |
|
287 | render->win_width = width; |
310 | render->rcvideo.r = width; |
- | 311 | render->rcvideo.b = height; |
|
288 | render->win_height = height; |
312 | |
- | 313 | if( render->win_height > height ) |
|
- | 314 | { |
|
- | 315 | int yoffs; |
|
- | 316 | yoffs = (render->win_height-height)/2; |
|
- | 317 | if(yoffs) |
|
- | 318 | { |
|
- | 319 | render->rctop.t = 0; |
|
- | 320 | render->rctop.b = yoffs; |
|
- | 321 | render->rcvideo.t = yoffs; |
|
- | 322 | render->layout |= HAS_TOP; |
|
- | 323 | } |
|
- | 324 | ||
- | 325 | yoffs = render->win_height-(render->rcvideo.t+render->rcvideo.b); |
|
- | 326 | if(yoffs) |
|
- | 327 | { |
|
- | 328 | render->rcbottom.t = render->rcvideo.t+render->rcvideo.b; |
|
- | 329 | render->rcbottom.b = yoffs; |
|
- | 330 | render->layout |= HAS_BOTTOM; |
|
- | 331 | } |
|
Line -... | Line 332... | ||
- | 332 | } |
|
- | 333 | ||
- | 334 | if( render->win_width > width ) |
|
289 | render->win_state = NORMAL; |
335 | { |
- | 336 | int xoffs; |
|
- | 337 | xoffs = (render->win_width-width)/2; |
|
- | 338 | if(xoffs) |
|
- | 339 | { |
|
- | 340 | render->rcleft.r = xoffs; |
|
- | 341 | render->rcvideo.l = xoffs; |
|
- | 342 | render->layout |= HAS_LEFT; |
|
- | 343 | } |
|
- | 344 | xoffs = render->win_width-(render->rcvideo.l+render->rcvideo.r); |
|
- | 345 | if(xoffs) |
|
- | 346 | { |
|
- | 347 | render->rcright.l = render->rcvideo.l+render->rcvideo.r; |
|
- | 348 | render->rcright.r = xoffs; |
|
- | 349 | render->layout |= HAS_RIGHT; |
|
Line 290... | Line 350... | ||
290 | 350 | } |
|
291 | // printf("%s %dx%d\n",__FUNCTION__, width, height); |
351 | }; |
292 | 352 | ||
293 | if(render->state == EMPTY) |
353 | if(render->state == EMPTY) |
Line 331... | Line 391... | ||
331 | 391 | ||
Line 332... | Line 392... | ||
332 | return 0; |
392 | return 0; |
333 | }; |
393 | }; |
Line 334... | Line 394... | ||
334 | 394 | ||
335 | void render_adjust_size(render_t *render) |
395 | void render_adjust_size(render_t *render, window_t *win) |
336 | { |
- | |
337 | char proc_info[1024]; |
- | |
338 | 396 | { |
|
339 | uint32_t right, bottom, new_w, new_h; |
397 | uint32_t right, bottom, new_w, new_h; |
340 | uint32_t s, sw, sh; |
398 | uint32_t s, sw, sh; |
Line 341... | Line -... | ||
341 | uint8_t state; |
- | |
Line 342... | Line 399... | ||
342 | 399 | uint8_t state; |
|
343 | get_proc_info(proc_info); |
400 | |
344 | 401 | ||
Line 345... | Line -... | ||
345 | right = *(uint32_t*)(proc_info+62)+1; |
- | |
346 | bottom = *(uint32_t*)(proc_info+66)+1; |
402 | right = win->w; |
347 | state = *(uint8_t*)(proc_info+70); |
- | |
348 | - | ||
349 | if(state & 2) |
- | |
350 | { render->win_state = MINIMIZED; |
- | |
351 | return; |
- | |
352 | } |
403 | bottom = win->h-29; |
353 | if(state & 4) |
- | |
Line 354... | Line 404... | ||
354 | { |
404 | render->win_state = win->win_state; |
- | 405 | ||
Line 355... | Line 406... | ||
355 | render->win_state = ROLLED; |
406 | if(render->win_state == MINIMIZED) |
356 | return; |
407 | return; |
357 | }; |
408 | |
Line 358... | Line 409... | ||
358 | 409 | if(render->win_state == ROLLED) |
|
359 | render->win_state = NORMAL; |
410 | return; |
Line 360... | Line -... | ||
360 | - | ||
361 | if( right == render->win_width && |
411 | |
Line 362... | Line 412... | ||
362 | bottom == render->win_height) |
412 | if( right == render->win_width && |
363 | return; |
413 | bottom == render->win_height) |
364 | 414 | return; |
|
Line 381... | Line 431... | ||
381 | { |
431 | { |
382 | new_w = 64; |
432 | new_w = 64; |
383 | new_h = 64*render->ctx_height/render->ctx_width; |
433 | new_h = 64*render->ctx_height/render->ctx_width; |
384 | }; |
434 | }; |
385 | __asm__ __volatile__( |
435 | |
386 | "int $0x40" |
- | |
387 | ::"a"(67), "b"(-1), "c"(-1), |
- | |
388 | "d"(new_w+9),"S"(new_h+26) |
- | |
389 | :"memory" ); |
- | |
390 | render_set_size(render, new_w, new_h); |
- | |
391 | - | ||
Line -... | Line 436... | ||
- | 436 | render->win_width = win->w; |
|
- | 437 | render->win_height = win->h-29; |
|
- | 438 | render_set_size(render, new_w, new_h); |
|
392 | }; |
439 | }; |
Line 393... | Line 440... | ||
393 | 440 | ||
394 | void draw_hw_picture(render_t *render, AVPicture *picture) |
441 | void draw_hw_picture(render_t *render, AVPicture *picture) |
395 | { |
442 | { |
- | 443 | int dst_width, dst_height; |
|
396 | int dst_width, dst_height; |
444 | bitmap_t *bitmap; |
397 | uint8_t *data[4]; |
445 | uint8_t *data[4]; |
- | 446 | int linesize[4]; |
|
Line 398... | Line 447... | ||
398 | int linesize[4]; |
447 | int ret; |
399 | 448 | ||
Line 400... | Line 449... | ||
400 | if(render->win_state != NORMAL) |
449 | if(render->win_state == ROLLED) |
401 | return; |
450 | return; |
402 | 451 | ||
Line 419... | Line 468... | ||
419 | { |
468 | { |
420 | printf("Cannot initialize the conversion context!\n"); |
469 | printf("Cannot initialize the conversion context!\n"); |
421 | return ; |
470 | return ; |
422 | }; |
471 | }; |
423 | // printf("sws_getCachedContext\n"); |
472 | |
- | 473 | bitmap = &render->bitmap[render->target]; |
|
- | 474 | ||
- | 475 | ret = lock_bitmap(bitmap); |
|
- | 476 | if( ret != 0) |
|
- | 477 | { |
|
- | 478 | printf("Cannot lock the bitmap!\n"); |
|
- | 479 | return ; |
|
- | 480 | } |
|
- | 481 | ||
- | 482 | // printf("sws_getCachedContext\n"); |
|
424 | data[0] = render->bitmap[render->target].data; |
483 | data[0] = bitmap->data; |
425 | data[1] = render->bitmap[render->target].data+1; |
484 | data[1] = bitmap->data+1; |
426 | data[2] = render->bitmap[render->target].data+2; |
485 | data[2] = bitmap->data+2; |
427 | data[3] = render->bitmap[render->target].data+3; |
486 | data[3] = bitmap->data+3; |
428 | 487 | ||
429 | linesize[0] = render->bitmap[render->target].pitch; |
488 | linesize[0] = bitmap->pitch; |
430 | linesize[1] = render->bitmap[render->target].pitch; |
489 | linesize[1] = bitmap->pitch; |
431 | linesize[2] = render->bitmap[render->target].pitch; |
490 | linesize[2] = bitmap->pitch; |
432 | linesize[3] = render->bitmap[render->target].pitch; |
491 | linesize[3] = bitmap->pitch; |
433 | 492 | ||
Line 434... | Line 493... | ||
434 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
493 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
435 | picture->linesize, 0, render->ctx_height, data, linesize); |
494 | picture->linesize, 0, render->ctx_height, data, linesize); |
436 | // printf("sws_scale\n"); |
495 | // printf("sws_scale\n"); |
Line 437... | Line 496... | ||
437 | 496 | ||
- | 497 | blit_bitmap(bitmap, render->rcvideo.l, |
|
438 | blit_bitmap(&render->bitmap[render->target], 5, 22, |
498 | 29+render->rcvideo.t, |
439 | render->win_width, render->win_height); |
499 | render->rcvideo.r, render->rcvideo.b); |
Line 440... | Line 500... | ||
440 | // printf("blit_bitmap\n"); |
500 | // printf("blit_bitmap\n"); |
441 | 501 | ||
442 | delay(2); |
502 | |
443 | render->target++; |
503 | render->target++; |
Line 444... | Line 504... | ||
444 | render->target&= 3; |
504 | render->target&= 3; |
445 | } |
505 | } |
446 | 506 | ||
447 | void draw_sw_picture(render_t *render, AVPicture *picture) |
507 | void draw_sw_picture(render_t *render, AVPicture *picture) |
Line -... | Line 508... | ||
- | 508 | { |
|
448 | { |
509 | uint8_t *data[4]; |
449 | uint8_t *data[4]; |
510 | int linesize[4]; |
Line 450... | Line 511... | ||
450 | int linesize[4]; |
511 | |
451 | 512 | if(render->win_state == MINIMIZED || |
|
452 | if(render->win_state != NORMAL) |
513 | render->win_state == ROLLED) |
453 | return; |
514 | return; |
454 | 515 | ||
455 | cvt_ctx = sws_getCachedContext(cvt_ctx, |
516 | cvt_ctx = sws_getCachedContext(cvt_ctx, |
456 | render->ctx_width, render->ctx_height, |
517 | render->ctx_width, render->ctx_height, |
457 | render->ctx_format, |
518 | render->ctx_format, |
458 | render->win_width, render->win_height, |
519 | render->rcvideo.r, render->rcvideo.b, |
Line 476... | Line 537... | ||
476 | 537 | ||
Line 477... | Line 538... | ||
477 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
538 | sws_scale(cvt_ctx, (const uint8_t* const *)picture->data, |
478 | picture->linesize, 0, render->ctx_height, data, linesize); |
539 | picture->linesize, 0, render->ctx_height, data, linesize); |
Line 479... | Line 540... | ||
479 | 540 | ||
- | 541 | blit_bitmap(&render->bitmap[0], render->rcvideo.l, |
|
480 | blit_bitmap(&render->bitmap[0], 5, 22, |
542 | render->rcvideo.t+29, |
481 | render->win_width, render->win_height); |
543 | render->rcvideo.r, render->rcvideo.b); |
Line -... | Line 544... | ||
- | 544 | } |
|
- | 545 | ||
- | 546 | void render_draw_client(render_t *render) |
|
- | 547 | { |
|
- | 548 | if(render->win_state == MINIMIZED || |
|
Line -... | Line 549... | ||
- | 549 | render->win_state == ROLLED) |
|
- | 550 | return; |
|
- | 551 | ||
- | 552 | if(render->layout & HAS_TOP) |
|
- | 553 | draw_bar(0, 29, render->win_width, |
|
- | 554 | render->rctop.b, 0); |
|
- | 555 | if(render->layout & HAS_LEFT) |
|
- | 556 | draw_bar(0, render->rcvideo.t+29, render->rcleft.r, |
|
- | 557 | render->rcvideo.b, 0); |
|
- | 558 | if(render->layout & HAS_RIGHT) |
|
- | 559 | draw_bar(render->rcright.l, render->rcvideo.t+29, |
|
- | 560 | render->rcright.r, render->rcvideo.b, 0); |
|
- | 561 | if(render->layout & HAS_BOTTOM) |