comparison libmpeg2/decode.c @ 111:3b4ccfecb823

using setjmp/longjmp to handle sig11 in libmpeg2
author arpi_esp
date Thu, 15 Mar 2001 23:21:40 +0000
parents b7b038ee3fde
children 47515462adc0
comparison
equal deleted inserted replaced
110:96c5071626a0 111:3b4ccfecb823
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 #include <fcntl.h> 11 #include <fcntl.h>
12 #include <errno.h> 12 #include <errno.h>
13
14 #include <signal.h>
15 #include <setjmp.h>
16
13 17
14 #include "config.h" 18 #include "config.h"
15 19
16 #include "video_out.h" 20 #include "video_out.h"
17 #include <inttypes.h> 21 #include <inttypes.h>
273 } 277 }
274 278
275 return is_frame_done; 279 return is_frame_done;
276 } 280 }
277 281
282 static jmp_buf mpeg2_jmp_buf;
283
284 static void mpeg2_sighandler(int sig){
285 longjmp(mpeg2_jmp_buf,1);
286 }
278 287
279 int mpeg2_decode_data (vo_functions_t *output, uint8_t *current, uint8_t *end) 288 int mpeg2_decode_data (vo_functions_t *output, uint8_t *current, uint8_t *end)
280 { 289 {
281 //static uint8_t code = 0xff; 290 //static uint8_t code = 0xff;
282 //static uint8_t chunk_buffer[65536]; 291 //static uint8_t chunk_buffer[65536];
284 //static uint32_t shift = 0; 293 //static uint32_t shift = 0;
285 uint8_t code; 294 uint8_t code;
286 uint8_t *pos=NULL; 295 uint8_t *pos=NULL;
287 uint8_t *start=current; 296 uint8_t *start=current;
288 int ret = 0; 297 int ret = 0;
298 void* old_sigh;
299
300 if(setjmp(mpeg2_jmp_buf)!=0){
301 printf("@@@ FATAL!!!??? libmpeg2 returned from sig11 before the actual decoding! @@@\n");
302 return 0;
303 }
304
305 old_sigh=signal(SIGSEGV,mpeg2_sighandler);
289 306
290 // printf("RCVD %d bytes\n",end-current); 307 // printf("RCVD %d bytes\n",end-current);
291 308
292 while(current<end){ 309 while(current<end){
293 // FIND NEXT HEAD: 310 // FIND NEXT HEAD:
303 } 320 }
304 //-------------------- 321 //--------------------
305 if(pos){ 322 if(pos){
306 //if((code&0x100)!=0x100) printf("libmpeg2: FATAL! code=%X\n",code); 323 //if((code&0x100)!=0x100) printf("libmpeg2: FATAL! code=%X\n",code);
307 //printf("pos=%d chunk %3X size=%d next-code=%X\n",pos-start,code,current-pos,head|c); 324 //printf("pos=%d chunk %3X size=%d next-code=%X\n",pos-start,code,current-pos,head|c);
308 ret+=parse_chunk(output, code&0xFF, pos); 325 if(setjmp(mpeg2_jmp_buf)==0){
326 ret+=parse_chunk(output, code&0xFF, pos);
327 } else {
328 printf("@@@ libmpeg2 returned from sig11... @@@\n");
329 }
309 } 330 }
310 //-------------------- 331 //--------------------
311 pos=current;code=head|c; 332 pos=current;code=head|c;
312 } 333 }
313 334
335 signal(SIGSEGV,old_sigh); // restore sighandler
336
314 if(code==0x1FF) ret+=parse_chunk(output, 0xFF, NULL); // send 'end of frame' 337 if(code==0x1FF) ret+=parse_chunk(output, 0xFF, NULL); // send 'end of frame'
315 338
316 return ret; 339 return ret;
317 } 340 }
318 341