/* gethdr.c, header decoding */ /* * tmndecode * Copyright (C) 1995 Telenor R&D * Karl Olav Lillevold * * based on mpeg2decode, (C) 1994, MPEG Software Simulation Group * and mpeg2play, (C) 1994 Stefan Eckart * */ #include #include "config.h" #include "global.h" /* private prototypes */ static void getpicturehdr _ANSI_ARGS_((void)); /* * decode headers from one input stream * until an End of Sequence or picture start code * is found */ int getheader() { unsigned int code, gob; for (;;) { /* look for startcode */ restart: startcode(); if(verbose>0){ printf("Startcode in getheader:"); printbits(showbits(22),22,22); printf("\n"); } code = getbits(PSC_LENGTH); gob = getbits(5); if (gob == SEC) return 0; if (gob == 0 && showbits(22) == PSCODE) { getbits(22); getpicturehdr(); if (syntax_arith_coding) /* reset decoder after receiving */ decoder_reset(); /* fixed length PSC string */ return gob + 1; }else{ if(verbose>0){ printf("Startcode in getheader:"); printbits(showbits(22),22,22); printf("\n"); } goto restart; } } } /* align to start of next startcode */ void startcode() { /* search for new start code in base layer */ while (showbits(PSC_LENGTH)!=1l) flushbits(1); } unsigned int en_startcode() { /* search for new start code in enhance layer*/ while (en_showbits(PSC_LENGTH)!=1l) en_flushbits(1); return(en_showbits(22)); } void en_picstart() { /* search for new picture start code */ do{ while (en_showbits(22)!= PSCODE){ en_flushbits(1); } en_getbits(22); }while(en_showbits(22) != PSCODE); } /* decode picture header */ static void getpicturehdr() { int pos, pei, tmp; static int prev_temp_ref; pos = ld->bitcnt; prev_temp_ref = temp_ref; temp_ref = getbits(8); en_picstart(); en_getbits(22); en_temp_ref = en_getbits(8); if(temp_ref != en_temp_ref) { printf("the temp of base is not equal to that of enhance\n"); printf("temp_ref = %d, en_temp_ref = %d\n",temp_ref, en_temp_ref); exit(-5); } enhance_error = 0; trd = temp_ref - prev_temp_ref; if (trd <= 0) trd += 256; tmp = getbits(1); /* always "1" */ if (!tmp) if (!quiet) printf("warning: spare in picture header should be \"1\"\n"); tmp = getbits(1); /* always "0" */ if (tmp) if (!quiet) printf("warning: H.261 distinction bit should be \"0\"\n"); tmp = getbits(1); /* split_screen_indicator */ if (tmp) { if (!quiet) printf("warning: split-screen not supported in this version\n"); /* exit (-1); */ } tmp = getbits(1); /* document_camera_indicator */ if (tmp) if (!quiet) printf("warning: document camera indicator not supported in this version\n"); tmp = getbits(1); /* freeze_picture_release */ if (tmp) if (!quiet) printf("warning: frozen picture not supported in this version\n"); source_format = getbits(3); source_format = 2; pict_type = getbits(1); mv_outside_frame = getbits(1); mv_outside_frame = 1; syntax_arith_coding = getbits(1); syntax_arith_coding = 0; adv_pred_mode = getbits(1); adv_pred_mode = 1; pb_frame = getbits(1); quant = getbits(5); tmp = getbits(1); if (tmp) { if (!quiet) printf("warning: CPM not supported in this version\n"); /* exit(-1); */ } if (pb_frame) { trb = getbits(3); bquant = getbits(2); if(trb >= trd) trb = 1; } pei = getbits(1); if (pei) getbits(8); /* extra info. (not used) */ if (verbose>0) { printf("picture header (byte %d)\n",(pos>>3)-4); if (verbose>1) { printf(" temp_ref=%d\n",temp_ref); printf(" pict_type=%d\n",pict_type); printf(" source_format=%d\n", source_format); printf(" quant=%d\n",quant); if (syntax_arith_coding) printf(" SAC coding mode used \n"); if (mv_outside_frame) printf(" unrestricted motion vector mode used\n"); if (adv_pred_mode) printf(" advanced prediction mode used\n"); if (pb_frame) { printf(" pb-frames mode used\n"); printf(" trb=%d\n",trb); printf(" bquant=%d\n", bquant); } } } }