⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldecod.c

📁 Mobile IP VCEG的信道模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/*!
 *	\file
 *			Ldecod.c	
 *	\brief
 *			TML decoder project main()
 *	\author
 *			Main contributors (see contributors.h for copyright, address and affiliation details)
 *
 *			Inge Lille-Lang鴜       <inge.lille-langoy@telenor.com>
 *			Rickard Sjoberg         <rickard.sjoberg@era.ericsson.se>
 *			Stephan Wenger		    <stewe@cs.tu-berlin.de>
 *			Jani Lainema		    <jani.lainema@nokia.com>
 *			Sebastian Purreiter		<sebastian.purreiter@mch.siemens.de>
 *			Byeong-Moon Jeon		<jeonbm@lge.com>
 *      Gabi Blaettermann               <blaetter@hhi.de>
 *
 *	\note	tags are used for document system "doxygen"
 *			available at http://www.stack.nl/~dimitri/doxygen/index.html
 *
 *		
 * 
 * 	\note
 *		-Limitations:
 *			Using different NAL's the assignment of partition-id to containing
 *			syntax elements may got lost, if this information is not transmitted.
 *			The same has to be stated for the partitionlength if partitions are
 *			merged by the NAL. \par
 *		
 *			The presented solution in Q15-K-16 solves both of this problems as the
 *			departitioner parses the bitstream before decoding. Due to syntax element 
 *			dependencies both, partition bounds and partitionlength information can
 *			be parsed by the departitioner. \par
 *		
 *		-Handling partition information in external file:
 *			As the TML is still a work in progress, it makes sense to handle this 
 *			information for simplification in an external file, here called partition 
 *			information file, which can be found by the extension .dp extending the 
 *			original encoded H.26L bitstream. In this file partition-ids followed by its
 *			partitionlength is written. Instead of parsing the bitstream we get the 
 *			partition information now out of this file. 
 *			This information is assumed to be never sent over transmission channels 
 *			(simulation scenarios) as it's information we allways get using a 
 *			"real" departitioner before decoding \par
 *
 *		-Extension of Interim File Format:
 *			Therefore a convention has to be made within the interim file format.
 *			The underlying NAL has to take care of fulfilling these conventions.
 *			All partitions have to be bytealigned to be readable by the decoder, 
 *			So if the NAL-encoder merges partitions, >>this is only possible to use the 
 *			VLC	structure of the H.26L bitstream<<, this bitaligned structure has to be 
 *			broken up by the NAL-decoder. In this case the NAL-decoder is responsable to 
 *			read the partitionlength information from the partition information file.
 *			Partitionlosses are signaled with a partition of zero length containing no
 *			syntax elements.
 *
 *	
 */

#include "contributors.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>

#include "global.h"
#include "elements.h"
#include "bitsbuf.h"

#define TML			"6"
#define VERSION		"6.50"
#define LOGFILE		"log.dec"
#define DATADECFILE	"data.dec"
#define TRACEFILE	"trace_dec.txt"

/*! 
 *	\fn		main()
 *	\brief	main function for TML decoder
 */

int main(int argc, char **argv)
{
    struct inp_par    *inp;         /* input parameters from input configuration file   */
	struct snr_par    *snr;         /* statistics                                       */
	struct img_par    *img;         /* image parameters                                 */

    /* allocate memory for the structures */
	inp =  (struct inp_par *)calloc(1, sizeof(struct inp_par));
	snr =  (struct snr_par *)calloc(1, sizeof(struct snr_par));
	img =  (struct img_par *)calloc(1, sizeof(struct img_par));

	/* Read Configuration File */
    if (argc != 2)
	{
		fprintf(stdout,"Usage: %s <config.dat> \n",argv[0]);
		fprintf(stdout,"\t<config.dat> defines decoder parameters\n");
		exit(-1);
	}
    
    /* Initializes Configuration Parameters with configuration file */
	init_conf(inp, argv[1]);
	
    /* Allocate Slice data struct */
	malloc_slice(inp,img);

	init(img);
	img->number=0;

	/* B pictures */
	Bframe_ctr=0;

    /* time for total decoding session */
    tot_time = 0;
   
    while (decode_one_frame(img, inp, snr) != EOS);
    
    // B PICTURE : save the last P picture
	write_prev_Pframe(img, p_out);

    report(inp, img, snr);

    free_slice(inp,img);
    free_mem4global_buffers(inp, img);

	CloseBitstreamFile();

    fclose(p_out);
    fclose(p_ref);
#if TRACE
    fclose(p_trace);
#endif
	return 0;
}


/*!
 *	\fn		init()
 *	\brief	Initilize some arrays
 */
void init(struct img_par *img)	/*!< image parameters */
{
	int i;
	/* initilize quad matrix used in snr routine */

	for (i=0; i <  256; i++)
	{
		img->quad[i]=i*i; /* fix from TML 1, truncation removed */
	}
}

/************************************************************************
*
*  Name :       init_conf(struct inp_par *inp, char *config_filename)
*
*  Description: Read input from configuration file
*
*  Input      : Name of configuration filename
*
*  Output     : none
*
************************************************************************/

void init_conf(struct inp_par *inp,
               char *config_filename)
{
	FILE *fd;
    int NAL_mode;
    //char string[255];

    /* read the decoder configuration file */
	if((fd=fopen(config_filename,"r")) == NULL)           
	{
		fprintf(stdout,"Error: Control file %s not found\n",config_filename);
		exit(0);
	}

	fscanf(fd,"%s",inp->infile);                /* H.26L compressed input bitsream */ 
	fscanf(fd,"%*[^\n]");

	fscanf(fd,"%s",inp->outfile);               /* YUV 4:2:2 input format */
	fscanf(fd,"%*[^\n]");

	fscanf(fd,"%s",inp->reffile);               /* reference file */
	fscanf(fd,"%*[^\n]");

    /* Symbol mode */
	fscanf(fd,"%d,",&inp->symbol_mode);        /* 0: UVLC 1: CABAC */
	fscanf(fd,"%*[^\n]");
	if (inp->symbol_mode != UVLC && inp->symbol_mode != CABAC)
	{
		sprintf(errortext, "Unsupported symbol mode=%d, use UVLC=0 or CABAC=1\n",inp->symbol_mode);
		error(errortext);
	}

	/* Frame buffer size */
	fscanf(fd,"%d,",&inp->buf_cycle);
	fscanf(fd,"%*[^\n]");
	if (inp->buf_cycle < 1)
	{
		sprintf(errortext, "Frame Buffer Size is %d. It has to be at least 1\n",inp->buf_cycle);
		error(errortext);
	}

	fscanf(fd,"%d",&(NAL_mode));                /* NAL mode */
    fscanf(fd,"%*[^\n]");

    switch(NAL_mode)
	{
	case 0:
		inp->of_mode = PAR_OF_26L;
		/* Note: Data Partitioning in 26L File Format not yet supported */
		inp->partition_mode = PAR_DP_1;
		break;
	default:
		printf("NAL mode %i is not supported\n", NAL_mode);
		exit(1);
	}


#if TRACE
	sprintf(string,"%s",TRACEFILE);
	if ((p_trace=fopen(string,"w"))==0)             /* append new statistic at the end */
	{
		printf("Error open file %s!\n",string);
		exit(0);
	}
#endif
    	
    
//    if ((p_in=fopen(inp->infile,"rb"))==0)
//	{
//		fprintf(stdout,"Input file %s does not exist \n",inp->infile);
//		exit(0);
//	}
	
	if (OpenBitstreamFile (inp->infile) < 0) {
			printf ("Cannot open bitstream file '%s'\n", inp->infile);
			exit (-1);
	}
	if ((p_out=fopen(inp->outfile,"wb"))==0)
	{
		fprintf(stdout,"Error open file %s  \n",inp->outfile);
		exit(0);
	}

    fprintf(stdout,"--------------------------------------------------------------------------\n");
	fprintf(stdout," Decoder config file                    : %s \n",config_filename);
	fprintf(stdout,"--------------------------------------------------------------------------\n");
	fprintf(stdout," Input H.26L bitstream                  : %s \n",inp->infile);
	fprintf(stdout," Output decoded YUV 4:2:0               : %s \n",inp->outfile);
	fprintf(stdout," Output status file                     : %s \n",LOGFILE);
	if ((p_ref=fopen(inp->reffile,"rb"))==0)
	{
		fprintf(stdout," Input reference file                   : %s does not exist \n",inp->reffile);
		fprintf(stdout,"                                          SNR values are not available\n");
	}
	else
		fprintf(stdout," Input reference file                   : %s \n",inp->reffile);
	fprintf(stdout,"--------------------------------------------------------------------------\n");


	fprintf(stdout,"Frame   TR    QP  SnrY    SnrU    SnrV   Time(ms)\n");
}
/************************************************************************
*
*  Name :       void report()
*
*  Description: Reports the gathered information to appropriate outputs
*
*  Input      : struct inp_par *inp, 
*				struct img_par *img, 
*				struct snr_par *stat
*
*  Output     : None
*
************************************************************************/
void report(struct inp_par *inp, struct img_par *img, struct snr_par *snr)
{
    char string[255];
    FILE *p_log;

#ifndef WIN32
    time_t	now;
    struct tm	*l_time;
#else
    char timebuf[128];
#endif

	fprintf(stdout,"-------------------- Average SNR all frames ------------------------------\n");
	fprintf(stdout," SNR Y(dB)           : %5.2f\n",snr->snr_ya);
	fprintf(stdout," SNR U(dB)           : %5.2f\n",snr->snr_ua);
	fprintf(stdout," SNR V(dB)           : %5.2f\n",snr->snr_va);
	fprintf(stdout," Total decoding time : %.3f sec \n",tot_time*0.001); 
	fprintf(stdout,"--------------------------------------------------------------------------\n");
	fprintf(stdout," Exit TML %s decoder, ver %s \n",TML,VERSION);

	/* write to log file */

	sprintf(string, "%s", LOGFILE);
	if (fopen(string,"r")==0)                    /* check if file exist */
	{
		if ((p_log=fopen(string,"a"))==0)
		{
			fprintf(stdout,"Error open file %s for appending\n",string);
			exit(0);
		}
		else                                              /* Create header to new file */
		{
			fprintf(p_log," ------------------------------------------------------------------------------------------\n");
			fprintf(p_log,"|  Decoder statistics. This file is made first time, later runs are appended               |\n");
			fprintf(p_log," ------------------------------------------------------------------------------------------ \n");
			fprintf(p_log,"| Date  | Time  |    Sequence        |#Img|Format|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -