📄 tmndec.c
字号:
/************************************************************************ * * tmndec.c, main(), initialization, options for tmndecode (H.263 decoder) * Copyright (C) 1995, 1996 Telenor R&D, Norway * * Contacts: * Robert Danielsen <Robert.Danielsen@nta.no> * * Telenor Research and Development http://www.nta.no/brukere/DVC/ * P.O.Box 83 tel.: +47 63 84 84 00 * N-2007 Kjeller, Norway fax.: +47 63 81 00 76 * * Copyright (C) 1997 University of BC, Canada * Modified by: Michael Gallant <mikeg@ee.ubc.ca> * Guy Cote <guyc@ee.ubc.ca> * Berna Erol <bernae@ee.ubc.ca> * * Contacts: * Michael Gallant <mikeg@ee.ubc.ca> * * UBC Image Processing Laboratory http://www.ee.ubc.ca/image * 2356 Main Mall tel.: +1 604 822 4051 * Vancouver BC Canada V6T1Z4 fax.: +1 604 822 5949 * ************************************************************************//* Disclaimer of Warranty * * These software programs are available to the user without any license fee * or royalty on an "as is" basis. The University of British Columbia * 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 University of British Columbia does not represent or warrant that the * programs furnished hereunder are free of infringement of any * third-party patents. * * Commercial implementations of H.263, 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. * *//* modified to support annex O true B frames, mikeg@ee.ubc.ca * * based on mpeg2decode, (C) 1994, MPEG Software Simulation Group and * mpeg2play, (C) 1994 Stefan Eckart <stefan@lis.e-technik.tu-muenchen.de> * */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <fcntl.h>#include <string.h>#define GLOBAL#include "config.h"#include "tmndec.h"#include "global.h"#ifdef WIN32#include <io.h>#endif#ifdef SINGLE_TEST
unsigned char *vo_buf;
int init_fb=1;
#endif/* private prototypes */static void initdecoder _ANSI_ARGS_ ((void));static void options _ANSI_ARGS_ ((int *argcp, char **argvp[]));static int getval _ANSI_ARGS_ ((char *argv[]));static void flushdisplaybuffer _ANSI_ARGS_ ((int framenum));/* private data *///static int loopflag;int main (int argc, char *argv[]){ int first, framenum; int gob; trace = 0;// options (&argc, &argv);refidct=0; if (trace) { if ((trace_file = fopen (trace_file_name, "wt")) == NULL) { printf ("Unable to open trace file"); exit (-1); } }
#ifdef RUN_ON_BOARD
extern int get_FB_MEM();
extern int start_clock();
get_FB_MEM();
start_clock();
int init_fb=1;
#else vo_buf=(unsigned char *)malloc(200*1024);
if(vo_buf==NULL)
printf("malloc vo_buf error\n");
#endif /* pointer to name of output files */ outputname = "out%d"; ld = &base; /* open H263plus input file(s) */ if ((base.infile = open (argv[1], O_RDONLY | O_BINARY)) < 0) { sprintf (errortext, "Input file %s not found\n", argv[1]); error (errortext); } first = 1; // do // { if (base.infile != 0) lseek (base.infile, 0l, 0); initbits (); initoptions (); framenum = 0; temp_ref = 0; prev_non_disposable_temp_ref = next_non_disposable_temp_ref = 0; while ((gob = getheader ())) { if (first) { base_source_format = source_format; initdecoder (); first = 0; } getpicture (&framenum, gob); framenum++; } flushdisplaybuffer (framenum);// } while (loopflag); close (base.infile);
#ifdef RUN_ON_BOARD
#else
if(vo_buf!=NULL)
free(vo_buf);
#endif return 0;}static void initdecoder (){ int i, cc, size; FILE *cleared; /* clip table */ if (!(clp = (unsigned char *) malloc (1024))) error ("malloc failed\n"); clp += 384; for (i = -384; i < 640; i++) clp[i] = (i < 0) ? 0 : ((i > 255) ? 255 : i); /* MPEG-1 = TMN parameters */ matrix_coefficients = 5; blk_cnt = 6; for (i=0; i<MAX_LAYERS; i++) enhancement_layer_init[i] = OFF; for (cc = 0; cc < 3; cc++) { if (cc == 0) size = coded_picture_width * coded_picture_height; else size = chrom_width * chrom_height; /* Used for bidirectional and direct prediction mode for true B * pictures, one for forward and one for backward. */ if (!(next_I_P_frame[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); if (!(prev_I_P_frame[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); if (!(current_frame[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); if (!(bframe[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); prev_frame[cc] = current_frame[cc]; if (!(tmp_f[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); if (!(tmp_b[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); /* Stores frame in display buffer */ if (!(buffered_frame[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); } for (cc = 0; cc < 3; cc++) { if (cc == 0) { size = (coded_picture_width + 64) * (coded_picture_height + 64); /* Stores framed version of previous inter-picture, luminance. */ if (!(edgeframeorig[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); edgeframe[cc] = edgeframeorig[cc] + (coded_picture_width + 64) * 32 + 32; /* Required for true B frames backward, bidir, and direct * prediction. Stores future inter-picture, luminance */ if (!(nextedgeframeorig[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); nextedgeframe[cc] = nextedgeframeorig[cc] + (coded_picture_width + 64) * 32 + 32; } else { size = (chrom_width + 32) * (chrom_height + 32); /* Stores framed version of previous inter-picture, chrominance. */ if (!(edgeframeorig[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); edgeframe[cc] = edgeframeorig[cc] + (chrom_width + 32) * 16 + 16; /* Required for true B frames backward, bidir, and direct * prediction. Stores future inter-picture, chrominance. */ if (!(nextedgeframeorig[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); nextedgeframe[cc] = nextedgeframeorig[cc] + (chrom_width + 32) * 16 + 16; } } if (expand) { for (cc = 0; cc < 3; cc++) { if (cc == 0) size = coded_picture_width * coded_picture_height * 4; else size = chrom_width * chrom_height * 4; if (!(exnewframe[cc] = (unsigned char *) malloc (size))) error ("malloc failed\n"); } } /* Clear output file for concatenated storing *//* if (outtype == T_YUV_CONC) { if ((cleared = fopen (outputname, "wb")) == NULL) error ("couldn't clear outputfile\n"); else fclose (cleared); }*/ /* IDCT */ if (refidct) init_idctref (); else init_idct (); prev_mv_outside_frame = prev_sac = prev_adv_pred = prev_aic = prev_df = 0; prev_slice_struct = prev_rps = prev_isd = prev_aivlc = prev_mq = 0; prev_4mv = prev_long_vectors = prev_obmc = 0;}void error (char *text){ fprintf (stderr, text); exit (1);}/* trace output */void printbits (int code, int bits, int len){ int i; for (i = 0; i < len; i++) fprintf (trace_file, "%d", (code >> (bits - 1 - i)) & 1);}static int getval (char *argv[]){ int val; if (sscanf (argv[1] + 2, "%d", &val) != 1) return 0; while (isdigit (argv[1][2])) argv[1]++; return val;}/********************************************************************** * * Name: flushdisplaybuffer * Description: empties last frame from display buffer when sequence * fully decoded * Input: frame number * Returns: * Side effects: * * Date: 971102 Author: mikeg@ee.ubc.ca * ***********************************************************************/void flushdisplaybuffer (int framenum){ /* Ensure the dimensions are set properly for displaying the last picture in * the display buffer */ coded_picture_width = horizontal_size = lines[base_source_format]; coded_picture_height = vertical_size = pels[base_source_format]; mb_width = horizontal_size / 16; mb_height = vertical_size / 16; chrom_width = coded_picture_width >> 1; chrom_height = coded_picture_height >> 1;// if (expand && outtype == T_X11)// {// /* display this image and keep frame already in storage where it is. */// interpolate_image (buffered_frame[0], exnewframe[0],// coded_picture_width, coded_picture_height);// interpolate_image (buffered_frame[1], exnewframe[1], chrom_width, chrom_height);// interpolate_image (buffered_frame[2], exnewframe[2], chrom_width, chrom_height);// // storeframe (exnewframe, framenum);// } else// { storeframe (buffered_frame, framenum); //}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -