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

📄 tmndec.c

📁 H263的解码编码器
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************
 *
 *  tmndec.c, main(), initialization, options for tmndecode (H.263 decoder)
 */
#include <stdio.h>
#include <stdlib.h>
#include <tm1/tmICP.h>
#include <string.h>
#include <assert.h>
#include <tm1/mmio.h>
#include <tmlib/tmtypes.h>
#include <ops/custom_defs.h>
#include <tmlib/tmlibc.h>
#include <tm1/tmHelp.h>
#include <ctype.h>
#include <fcntl.h>

#define GLOBAL

#include "config.h"
#include "tmndec.h"
#include "global.h"

#define VIDEO_ADDR 0xfe000000    /* Start address of the screen */
#define VIDEO_STRIDE 2048        /* For 24 bit video it is 3xscreen width */
#define BPP 2                    /* # bytes per pixel */
#define PIX_OFFSET 0             /* OutPixOffset = 0 for vertical and 
                                  * horizontal filters 
                                  */
#define STRIDE    352
#define TRUE 1
#define FALSE 0

static unsigned long   dispAddr;
static int             dispStride;
static int             bpp;
static int             not555a;
static int             icpInst;   /* instance number for the ICP */
static unsigned char   *yBase;
static unsigned char   *uBase;
static unsigned char   *vBase;
static icpInstanceSetup_t          icpInstSup;
static icpCapabilities_t          *icpCapabilities;
static icpImageColorConversion_t   icpImage;

static volatile int interrupt_done;


void icpISR(void)
{
#pragma TCS_handler
#pragma TCS_atomic

    interrupt_done = 1;
    icpEnableACK_DONE();

    return;
}

static void my_abort(char * name, int err)
{
    assert(name != Null);
    fprintf(stderr, "%s failed, error code %x\n", name, err);
    exit(-1);
}

void icpDisplay(unsigned char *y, unsigned char *u, unsigned char *v)
{
    int         err;
   
    icpImage.yBase = y;
    icpImage.uBase = u;
    icpImage.vBase = v;

	interrupt_done = 0;
    if (err = icpColorConversion(icpInst, &icpImage))
        my_abort("icpColorConversion", err);
    while (icpCheckBUSY());
}

static void SetupICP()
{
    tmLibdevErr_t err;	

	if (err = icpGetCapabilities(&icpCapabilities))
        my_abort("icpGetCapabilities", err);

    if (err = icpOpen(&icpInst))
        my_abort("icpOpen", err);

    memset((Char *) &icpInstSup, 0, sizeof(icpInstanceSetup_t));
	
	icpInstSup.reset = 1;
    icpInstSup.interruptPriority = intPRIO_4;    /* Priority 4 Interrupt */
    icpInstSup.isr = &icpISR;                    /* User Interrupt service routine */

    if (err = icpInstanceSetup(icpInst, &icpInstSup))
        my_abort("icpInstanceSetup", err);

    interrupt_done = 0;
	if (err = icpLoadCoeff(icpInst, NULL))
       my_abort("icpLoadCoeff", err);
	while (!interrupt_done);

    memset((Char *) &icpImage, 0, sizeof(icpImageColorConversion_t));

	icpImage.yInputStride = STRIDE/2;
	icpImage.uvInputStride = STRIDE/4;
	icpImage.inputWidth = horizontal_size;
	icpImage.inputHeight = vertical_size;
	icpImage.outputWidth = horizontal_size;
	icpImage.outputHeight = vertical_size;
	icpImage.outputStride = dispStride;
	icpImage.outputImage = (unsigned char *)dispAddr;

    icpImage.filterBypass = icpBYPASS;
    icpImage.outputPixelOffset = 0.0;

    icpImage.inFormat = vdfYUV420Planar;    /* We know the input image format */
	icpImage.outputDestination = icpPCI;
	
#ifdef __LITTLE_ENDIAN__
	icpImage.littleEndian = True;
#else
#if defined(__BIG_ENDIAN__) && defined(__TCS_WinNT__)
	icpImage.littleEndian = True;
#else
	icpImage.littleEndian = False;
#endif
#endif
	
	icpImage.overlayEnable = 0;
	icpImage.bitMaskEnable = 0;

    if (bpp == 1)
		icpImage.outFormat = vdfRGB8A_233;
	else if (bpp == 2 && not555a)
		icpImage.outFormat = vdfRGB16;
	else if (bpp == 2 && (!not555a))
		icpImage.outFormat = vdfRGB15Alpha;
	else if (bpp == 3)
		icpImage.outFormat = vdfRGB24;
	else if (bpp == 4)
		icpImage.outFormat = vdfRGB24Alpha;
}

void get_parameters(int argc, char *argv[],
                    unsigned long *disp_addr, int *stride, int *bpp, int *not555a)
{
    int         ok;
    char        temp;

    ok = TRUE;
    while (ok && (--argc > 0)) {
        if ((*++argv)[0] == '-') {
            /* It is an option. */
            if (strcmp(*argv, "-d") == 0) {
                if (--argc > 0) {
                    if (sscanf(*++argv, "%x %c", disp_addr, &temp) != 1) {
                        printf("Error: hex. number expected as -d argument.\n");
                        ok = FALSE;
                    }
                }
                else {
                    printf("Error in display address: option "
                           "-d requires argument.\n");
                    ok = FALSE;
                }
            }
            else if (strcmp(*argv, "-s") == 0) {
                if (--argc > 0) {
                    if (sscanf(*++argv, "%d %c", stride, &temp) != 1) {
                        fprintf(stderr, "Error: Integer expected as -s "
                                        "argument.\n");
                        ok = FALSE;
                    }
                }
                else {
                    fprintf(stderr, "Error: option -s requires argument.\n");
                    ok = FALSE;
                }

            }
            else if (strcmp(*argv, "-b") == 0) {
                if (--argc > 0) {
                    if (sscanf(*++argv, "%d %c", bpp, &temp) != 1) {
                        fprintf(stderr, "Error: Integer expected as "
                                        "-b argument.\n");
                        ok = FALSE;
                    }
                }
                else {
                    fprintf(stderr, "Error: option -b requires argument.\n");
                    ok = FALSE;
                }

            }
            else if (strcmp(*argv, "-not555a") == 0) {
                *not555a = 1;
            }
            else {
                printf("Error: invalid option '%s'.\n", *argv);
                ok = FALSE;
            }
        }
    }

    if (!ok) {
        printf("Usage: icptest.out [options]\n");
        printf("Options:\n");
        printf("  -d #  hexadecimal, Video address   (default: 0xFE000000)\n");
        printf("  -s #  integer    , Video stride    (default: 2400 (for 800x600x3 display) \n");
        printf("  -b #  integer    , Bytes per pixel (default: 3 (for 800x600x3 display) \n");
        printf("  -not555a         , When RGB 16 mode is required. RGB 15 + alpha is default \n");
        exit(1);
    }
    return;
}


/* private data */
static int loopflag;

static void initdecoder _ANSI_ARGS_((void));
static void options _ANSI_ARGS_((int *argcp, char *argvp[]));
static int getval _ANSI_ARGS_((char *argv[]));



int main(int argc, char * argv[])   
{   	
	int first, framenum;

    int runtime;
    unsigned int startTime=0, stopTime=0;

/*
#ifdef WINDOWS
printf("windows defined!\n");
#else 
 printf("windows not defined!\n");
#endif

#ifdef USE_TIME
printf("use time defined!\n");
#else 
  printf("use time not defined!\n");
#endif

#ifdef DISPLAY
printf("display defined!\n");
#else
 printf("display not defined!\n");
#endif

#ifndef WIN32
printf("win32 not defined!\n");
getchar();
#else 
	printf("win32 defined!\n");
    getchar();
#endif
*/	

	dispAddr = (unsigned long) VIDEO_ADDR;
    dispStride = VIDEO_STRIDE;                   /* For PCI it is the video stride */
    bpp = BPP;
    not555a = 0;
	
    printf("Running on "); tmHelpReportSystem(stdout);
	
    get_parameters(argc, argv, &dispAddr, &dispStride, &bpp, &not555a);
    printf("  Display address  0x%x, Stride: %d, Bytes per pixel: %d\n",
		   dispAddr, dispStride, bpp);

   
#ifdef USE_TIME
  /* default is read frame rate from bitstream */
  framerate=99;
#endif
/*
   options(&argc,argv);
*/
  openfilename = "streamout.263";
  loopflag = 0;                      /* No looping for output to file */
  framerate = 99;                     /* No delay necessary when output to file */
  outtype = T_WIN;
  
  /* pointer to name of output files */
  if (outtype==T_X11 || outtype == T_WIN)
    outputname = "";
  else
    outputname = "new.263";

  ld = &base; 

  /* open MPEG input file(s) */
  if ((base.infile=open(openfilename,O_RDONLY|O_BINARY))<0) 
  {
    sprintf(errortext,"Input file %s not found\n",openfilename);
    error(errortext);
  }

  first = 1;

  do 
  {
    if (base.infile!=0)
      lseek(base.infile,0l,0);
    initbits();
    framenum = 0;
    temp_ref = 0;
    prev_temp_ref =1; 

    while (getheader()) 
	{
      if (first) 
	  {
        initdecoder();
        startTime = clock();
        if (framerate > 0)
          targetTime = clock();
        first = 0;
      }

⌨️ 快捷键说明

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