📄 getvlc.c
字号:
/* getvlc.c, variable length decoding *//* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. *//* * Disclaimer of Warranty * * These software programs are available to the user without any license fee or * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims * any and all warranties, whether express, implied, or statuary, including any * implied warranties or merchantability or of fitness for a particular * purpose. In no event shall the copyright-holder be liable for any * incidental, punitive, or consequential damages of any kind whatsoever * arising from the use of these programs. * * This disclaimer of warranty extends to the user of these programs and user's * customers, employees, agents, transferees, successors, and assigns. * * The MPEG Software Simulation Group does not represent or warrant that the * programs furnished hereunder are free of infringement of any third-party * patents. * * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, * are subject to royalty fees to patent holders. Many of these patents are * general enough such that they are unavoidable regardless of implementation * design. * */#include <stdio.h>#include "config.h"#include "global.h"#include "getvlc.h"/* private prototypes *//* generic picture macroblock type processing functions */static int Get_I_macroblock_type _ANSI_ARGS_((void));static int Get_P_macroblock_type _ANSI_ARGS_((void));static int Get_B_macroblock_type _ANSI_ARGS_((void));static int Get_D_macroblock_type _ANSI_ARGS_((void));/* spatial picture macroblock type processing functions */static int Get_I_Spatial_macroblock_type _ANSI_ARGS_((void));static int Get_P_Spatial_macroblock_type _ANSI_ARGS_((void));static int Get_B_Spatial_macroblock_type _ANSI_ARGS_((void));static int Get_SNR_macroblock_type _ANSI_ARGS_((void));int Get_macroblock_type(){ int macroblock_type = 0; if (ld->scalable_mode==SC_SNR) macroblock_type = Get_SNR_macroblock_type(); else { switch (picture_coding_type) { case I_TYPE: macroblock_type = ld->pict_scal ? Get_I_Spatial_macroblock_type() : Get_I_macroblock_type(); break; case P_TYPE: macroblock_type = ld->pict_scal ? Get_P_Spatial_macroblock_type() : Get_P_macroblock_type(); break; case B_TYPE: macroblock_type = ld->pict_scal ? Get_B_Spatial_macroblock_type() : Get_B_macroblock_type(); break; case D_TYPE: macroblock_type = Get_D_macroblock_type(); break; default: printf("Get_macroblock_type(): unrecognized picture coding type\n"); break; } } return macroblock_type;}static int Get_I_macroblock_type(){#ifdef TRACE if (Trace_Flag) printf("macroblock_type(I) ");#endif /* TRACE */ if (Get_Bits1()) {#ifdef TRACE if (Trace_Flag) printf("(1): Intra (1)\n");#endif /* TRACE */ return 1; } if (!Get_Bits1()) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; }#ifdef TRACE if (Trace_Flag) printf("(01): Intra, Quant (17)\n");#endif /* TRACE */ return 17;}static char *MBdescr[]={ "", "Intra", "No MC, Coded", "", "Bwd, Not Coded", "", "Bwd, Coded", "", "Fwd, Not Coded", "", "Fwd, Coded", "", "Interp, Not Coded", "", "Interp, Coded", "", "", "Intra, Quant", "No MC, Coded, Quant", "", "", "", "Bwd, Coded, Quant", "", "", "", "Fwd, Coded, Quant", "", "", "", "Interp, Coded, Quant", ""};static int Get_P_macroblock_type(){ int code;#ifdef TRACE if (Trace_Flag) printf("macroblock_type(P) (");#endif /* TRACE */ if ((code = Show_Bits(6))>=8) { code >>= 3; Flush_Buffer(PMBtab0[code].len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,3,PMBtab0[code].len); printf("): %s (%d)\n",MBdescr[(int)PMBtab0[code].val],PMBtab0[code].val); }#endif /* TRACE */ return PMBtab0[code].val; } if (code==0) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; return 0; } Flush_Buffer(PMBtab1[code].len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,6,PMBtab1[code].len); printf("): %s (%d)\n",MBdescr[(int)PMBtab1[code].val],PMBtab1[code].val); }#endif /* TRACE */ return PMBtab1[code].val;}static int Get_B_macroblock_type(){ int code;#ifdef TRACE if (Trace_Flag) printf("macroblock_type(B) (");#endif /* TRACE */ if ((code = Show_Bits(6))>=8) { code >>= 2; Flush_Buffer(BMBtab0[code].len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,4,BMBtab0[code].len); printf("): %s (%d)\n",MBdescr[(int)BMBtab0[code].val],BMBtab0[code].val); }#endif /* TRACE */ return BMBtab0[code].val; } if (code==0) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; return 0; } Flush_Buffer(BMBtab1[code].len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,6,BMBtab1[code].len); printf("): %s (%d)\n",MBdescr[(int)BMBtab1[code].val],BMBtab1[code].val); }#endif /* TRACE */ return BMBtab1[code].val;}static int Get_D_macroblock_type(){ if (!Get_Bits1()) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag=1; } return 1;}/* macroblock_type for pictures with spatial scalability */static int Get_I_Spatial_macroblock_type(){ int code;#ifdef TRACE if (Trace_Flag) printf("macroblock_type(I,spat) (");#endif /* TRACE */ code = Show_Bits(4); if (code==0) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; return 0; }#ifdef TRACE if (Trace_Flag) { Print_Bits(code,4,spIMBtab[code].len); printf("): %02x\n",spIMBtab[code].val); }#endif /* TRACE */ Flush_Buffer(spIMBtab[code].len); return spIMBtab[code].val;}static int Get_P_Spatial_macroblock_type(){ int code;#ifdef TRACE if (Trace_Flag) printf("macroblock_type(P,spat) (");#endif /* TRACE */ code = Show_Bits(7); if (code<2) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; return 0; } if (code>=16) { code >>= 3; Flush_Buffer(spPMBtab0[code].len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,4,spPMBtab0[code].len); printf("): %02x\n",spPMBtab0[code].val); }#endif /* TRACE */ return spPMBtab0[code].val; } Flush_Buffer(spPMBtab1[code].len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,7,spPMBtab1[code].len); printf("): %02x\n",spPMBtab1[code].val); }#endif /* TRACE */ return spPMBtab1[code].val;}static int Get_B_Spatial_macroblock_type(){ int code; VLCtab *p;#ifdef TRACE if (Trace_Flag) printf("macroblock_type(B,spat) (");#endif /* TRACE */ code = Show_Bits(9); if (code>=64) p = &spBMBtab0[(code>>5)-2]; else if (code>=16) p = &spBMBtab1[(code>>2)-4]; else if (code>=8) p = &spBMBtab2[code-8]; else { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; return 0; } Flush_Buffer(p->len);#ifdef TRACE if (Trace_Flag) { Print_Bits(code,9,p->len); printf("): %02x\n",p->val); }#endif /* TRACE */ return p->val;}static int Get_SNR_macroblock_type(){ int code;#ifdef TRACE /* *CH* */ if (Trace_Flag) printf("macroblock_type(SNR) (");#endif TRACE code = Show_Bits(3); if (code==0) { if (!Quiet_Flag) printf("Invalid macroblock_type code\n"); Fault_Flag = 1; return 0; } Flush_Buffer(SNRMBtab[code].len);#ifdef TRACE /* *CH* */ if (Trace_Flag) { Print_Bits(code,3,SNRMBtab[code].len); printf("): %s (%d)\n",MBdescr[(int)SNRMBtab[code].val],SNRMBtab[code].val); }#endif TRACE return SNRMBtab[code].val;}int Get_motion_code(){ int code;#ifdef TRACE if (Trace_Flag) printf("motion_code (");#endif /* TRACE */ if (Get_Bits1()) {#ifdef TRACE if (Trace_Flag) printf("0): 0\n");#endif /* TRACE */ return 0; } if ((code = Show_Bits(9))>=64) { code >>= 6; Flush_Buffer(MVtab0[code].len);#ifdef TRACE if (Trace_Flag)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -