comparison spudec.c @ 6778:f33d4ab7a6b2

Make spudec_assemble more resistent in the face of incomplete packets. Put the global spu_changed into spudec_handle_t.
author kmkaplan
date Wed, 24 Jul 2002 16:47:29 +0000
parents f82b8063f3e7
children d796833e77af
comparison
equal deleted inserted replaced
6777:a0414ad68a4e 6778:f33d4ab7a6b2
47 unsigned int orig_frame_width, orig_frame_height; 47 unsigned int orig_frame_width, orig_frame_height;
48 unsigned char* packet; 48 unsigned char* packet;
49 size_t packet_reserve; /* size of the memory pointed to by packet */ 49 size_t packet_reserve; /* size of the memory pointed to by packet */
50 unsigned int packet_offset; /* end of the currently assembled fragment */ 50 unsigned int packet_offset; /* end of the currently assembled fragment */
51 unsigned int packet_size; /* size of the packet once all fragments are assembled */ 51 unsigned int packet_size; /* size of the packet once all fragments are assembled */
52 unsigned int packet_pts; /* PTS for this packet */
52 unsigned int control_start; /* index of start of control data */ 53 unsigned int control_start; /* index of start of control data */
53 unsigned int palette[4]; 54 unsigned int palette[4];
54 unsigned int alpha[4]; 55 unsigned int alpha[4];
55 unsigned int cuspal[4]; 56 unsigned int cuspal[4];
56 unsigned int custom; 57 unsigned int custom;
73 unsigned char *scaled_image; 74 unsigned char *scaled_image;
74 unsigned char *scaled_aimage; 75 unsigned char *scaled_aimage;
75 int auto_palette; /* 1 if we lack a palette and must use an heuristic. */ 76 int auto_palette; /* 1 if we lack a palette and must use an heuristic. */
76 int font_start_level; /* Darkest value used for the computed font */ 77 int font_start_level; /* Darkest value used for the computed font */
77 vo_functions_t *hw_spu; 78 vo_functions_t *hw_spu;
79 int spu_changed;
78 } spudec_handle_t; 80 } spudec_handle_t;
79
80 static int spu_changed = 0;
81 81
82 static inline unsigned int get_be16(const unsigned char *p) 82 static inline unsigned int get_be16(const unsigned char *p)
83 { 83 {
84 return (p[0] << 8) + p[1]; 84 return (p[0] << 8) + p[1];
85 } 85 }
400 this->hw_spu->draw_frame((uint8_t**)&pkg); 400 this->hw_spu->draw_frame((uint8_t**)&pkg);
401 } else { 401 } else {
402 spudec_process_control(this, pts100); 402 spudec_process_control(this, pts100);
403 spudec_process_data(this); 403 spudec_process_data(this);
404 } 404 }
405 spu_changed = 1; 405 this->spu_changed = 1;
406 } 406 }
407 407
408 int spudec_changed(void * this) 408 int spudec_changed(void * this)
409 { 409 {
410 spudec_handle_t * spu = (spudec_handle_t*)this; 410 spudec_handle_t * spu = (spudec_handle_t*)this;
411 return (spu_changed|(spu->now_pts > spu->end_pts)); 411 return (spu->spu_changed || spu->now_pts > spu->end_pts);
412 } 412 }
413 413
414 void spudec_assemble(void *this, unsigned char *packet, unsigned int len, unsigned int pts100) 414 void spudec_assemble(void *this, unsigned char *packet, unsigned int len, unsigned int pts100)
415 { 415 {
416 spudec_handle_t *spu = (spudec_handle_t*)this; 416 spudec_handle_t *spu = (spudec_handle_t*)this;
417 // spudec_heartbeat(this, pts100); 417 // spudec_heartbeat(this, pts100);
418 if (len < 2) { 418 if (len < 2) {
419 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: packet too short\n"); 419 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: packet too short\n");
420 return; 420 return;
421 }
422 if (spu->packet_pts < pts100) {
423 spu->packet_pts = pts100;
424 spu->packet_offset = 0;
421 } 425 }
422 if (spu->packet_offset == 0) { 426 if (spu->packet_offset == 0) {
423 unsigned int len2 = get_be16(packet); 427 unsigned int len2 = get_be16(packet);
424 // Start new fragment 428 // Start new fragment
425 if (spu->packet_reserve < len2) { 429 if (spu->packet_reserve < len2) {
435 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid frag len / len2: %d / %d \n", len, len2); 439 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid frag len / len2: %d / %d \n", len, len2);
436 return; 440 return;
437 } 441 }
438 memcpy(spu->packet, packet, len); 442 memcpy(spu->packet, packet, len);
439 spu->packet_offset = len; 443 spu->packet_offset = len;
444 spu->packet_pts = pts100;
440 } 445 }
441 } else { 446 } else {
442 // Continue current fragment 447 // Continue current fragment
443 if (spu->packet_size < spu->packet_offset + len){ 448 if (spu->packet_size < spu->packet_offset + len){
444 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n"); 449 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n");
500 505
501 void spudec_draw(void *this, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) 506 void spudec_draw(void *this, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
502 { 507 {
503 spudec_handle_t *spu = (spudec_handle_t *)this; 508 spudec_handle_t *spu = (spudec_handle_t *)this;
504 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts && spu->image) 509 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts && spu->image)
510 {
505 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height, 511 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height,
506 spu->image, spu->aimage, spu->stride); 512 spu->image, spu->aimage, spu->stride);
513 spu->spu_changed = 0;
514 }
507 } 515 }
508 516
509 /* calc the bbox for spudec subs */ 517 /* calc the bbox for spudec subs */
510 void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox) 518 void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox)
511 { 519 {
601 scale_pixel *table_y; 609 scale_pixel *table_y;
602 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts) { 610 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts) {
603 if (spu->orig_frame_width == 0 || spu->orig_frame_height == 0 611 if (spu->orig_frame_width == 0 || spu->orig_frame_height == 0
604 || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys)) { 612 || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys)) {
605 if (spu->image) 613 if (spu->image)
614 {
606 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height, 615 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height,
607 spu->image, spu->aimage, spu->stride); 616 spu->image, spu->aimage, spu->stride);
617 spu->spu_changed = 0;
618 }
608 } 619 }
609 else { 620 else {
610 if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) { /* Resizing is needed */ 621 if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) { /* Resizing is needed */
611 /* scaled_x = scalex * x / 0x100 622 /* scaled_x = scalex * x / 0x100
612 scaled_y = scaley * y / 0x100 623 scaled_y = scaley * y / 0x100
885 /*set subs at the bottom, i don't like to put it at the very bottom, so -1 :)*/ 896 /*set subs at the bottom, i don't like to put it at the very bottom, so -1 :)*/
886 spu->scaled_start_row = dys - spu->scaled_height - 1; 897 spu->scaled_start_row = dys - spu->scaled_height - 1;
887 #endif 898 #endif
888 draw_alpha(spu->scaled_start_col, spu->scaled_start_row, spu->scaled_width, spu->scaled_height, 899 draw_alpha(spu->scaled_start_col, spu->scaled_start_row, spu->scaled_width, spu->scaled_height,
889 spu->scaled_image, spu->scaled_aimage, spu->scaled_stride); 900 spu->scaled_image, spu->scaled_aimage, spu->scaled_stride);
890 spu_changed = 0; 901 spu->spu_changed = 0;
891 } 902 }
892 } 903 }
893 } 904 }
894 else 905 else
895 { 906 {