From 25872d9a33bab382843a161babd3e6e37bf57316 Mon Sep 17 00:00:00 2001 From: arpi_esp Date: Thu, 15 Mar 2001 23:21:40 +0000 Subject: [PATCH] using setjmp/longjmp to handle sig11 in libmpeg2 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@112 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpeg2/decode.c | 25 ++++++++++++++- mplayer.c | 80 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/libmpeg2/decode.c b/libmpeg2/decode.c index b5779b0139..467f704c48 100644 --- a/libmpeg2/decode.c +++ b/libmpeg2/decode.c @@ -11,6 +11,10 @@ #include #include +#include +#include + + #include "config.h" #include "video_out.h" @@ -275,6 +279,11 @@ static int parse_chunk (vo_functions_t * output, int code, uint8_t * buffer) return is_frame_done; } +static jmp_buf mpeg2_jmp_buf; + +static void mpeg2_sighandler(int sig){ + longjmp(mpeg2_jmp_buf,1); +} int mpeg2_decode_data (vo_functions_t *output, uint8_t *current, uint8_t *end) { @@ -286,6 +295,14 @@ int mpeg2_decode_data (vo_functions_t *output, uint8_t *current, uint8_t *end) uint8_t *pos=NULL; uint8_t *start=current; int ret = 0; + void* old_sigh; + + if(setjmp(mpeg2_jmp_buf)!=0){ + printf("@@@ FATAL!!!??? libmpeg2 returned from sig11 before the actual decoding! @@@\n"); + return 0; + } + + old_sigh=signal(SIGSEGV,mpeg2_sighandler); // printf("RCVD %d bytes\n",end-current); @@ -305,12 +322,18 @@ while(current=0x1B0){ // not slice code -> end of frame + // send END OF FRAME code: +#if 1 + videobuffer[videobuf_len+0]=0; + videobuffer[videobuf_len+1]=0; + videobuffer[videobuf_len+2]=1; + videobuffer[videobuf_len+3]=0xFF; + videobuf_len+=4; +#endif + if(!i) eof=1; // EOF + break; + } + } else { + //if(i==0x100) in_frame=1; // picture startcode + if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode + else if(!i){ eof=1; break;} // EOF + } + if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; + if(!read_video_packet(d_video)){ eof=1; break;} // EOF + //printf("read packet 0x%X, len=%d\n",i,videobuf_len); + } + + if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug + //printf("--- SEND %d bytes\n",videobuf_len); + if(grab_frames==1){ + FILE *f=fopen("grab.mpg","ab"); + fwrite(videobuffer,videobuf_len-4,1,f); + fclose(f); + } + ++dbg_es_sent; + //if(videobuf_len>4) + //my_write(data_fifo,(char*) &videobuf_len,4); + + { int t=0; + int x; + float l; + t-=GetTimer(); + mpeg2_decode_data(video_out, videobuffer, videobuffer+videobuf_len); + t+=GetTimer(); + //*** CMD=0 : Frame completed *** + //send_cmd(control_fifo2,0); // FRAME_COMPLETED command + x=frameratecode2framerate[picture->frame_rate_code]; //fps + ++dbg_es_rcvd; + l=(100+picture->repeat_count)*0.01f; + num_frames+=l; + picture->repeat_count=0; + video_time_usage+=t*0.000001; + if(x && !force_fps) default_fps=x*0.0001f; + if(!force_redraw){ + // increase video timers: + v_frame+=l/default_fps; + v_pts+=l/default_fps; + } + } + //if(eof) break; + +#else while(1){ int x; while(1){ @@ -1566,6 +1641,7 @@ switch(has_video){ } else printf("invalid cmd: 0x%X\n",x); } +#endif break; } } // switch