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

📄 vldtest.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
            break;

        }
    }

    ERROR_IF_NOT_OK(vldClose(instance));
    printf("vldtest SUCCESS\n");
    exit(0);
}



/****************************************************************************
    static void error(char *fmt, ...)

    Just a convenient name for fprintf( stderr, ...)
    Notify host of the error and exit.
****************************************************************************/
static void 
error(char *fmt,...)
{
    va_list     ap;
    char        str[512];

    sprintf(str, "\nFATAL ERROR: ");
    va_start(ap, fmt);
    vsprintf(str + 14, fmt, ap);
    va_end(ap);

    DP(("%s\n", str));

    /*
     * Just in case there is a console open, enable all interrupts since
     * this might be from an ISR.
     */
    intSetIEN();
    printf("%s\n", str);
    printf("parsed frames = %d, parsed MBs in the last frame = %d\n",
           ParsedFrames, ParsedMbs);
    printf("vldtest FAIL\n");
    exit(1);
}



/************************************************************************
    static void inputEmptyCallback(Int32 flag)

    Supply more data to VLD.
    If flag is set, wait (block) until data is available.
    call vldSetEmptyFlag at the end to indicate the availability of data.
    flag is ignored here.
***********************************************************************/
static void 
inputEmptyCallback(Pointer vidStream, Int32 flag)
{
    ReadAddr = (Pointer) ((UInt32) ReadAddr + READSIZE);
 /*   DP(("ReadAddr = 0x%x\n", ReadAddr));
*/
    ERROR_IF_NOT_OK(vldInput(instance, ReadAddr, READSIZE));
    
    vldSetEmptyFlag(instance, False);
}




/************************************************************************
    static void vldIrqHandler(void)

    Interrupt handler
***********************************************************************/
static void 
_vldIrqHandler(void)
{

    UInt32      status;

    DP(("ISR\n"));

    status = vldGetSTATUS();
    if (status & VLD_STATUS_DMA_IN_DONE) {
	vldAckSTATUS_DMA_IN_DONE();
        /*
         * Do not wait for more data inside ISR. Set the flag and get
         * out if no data. Passing False to inputEmptyCallback means "do
         * not wait".
         */
        inputEmptyCallback(pvidStream, False);
    }
    else {
        error("Only VLD_STATUS_DMA_IN_DONE is allowed to interrupt for now,"
              "0x%x", status);
    }
}

static void 
vldIrqHandler(void)
{
#pragma      TCS_handler
    AppModel_suspend_scheduling();
    AppModel_run_on_sstack((AppModel_Fun)_vldIrqHandler, Null);
    AppModel_resume_scheduling();
}


/****************************************************************************
    static Int allocVldOutput(void)

    Allocate memory for VLD outputs.
    They are shared by CPU and VLD, so they should be cache-safe,
    that is, both ends need to be aligned to 64 bytes.

    Allocate big enough space for now.
****************************************************************************/
static Int 
allocVldOutput(void)
{

    Mbh = (vldMBHMpeg2_t *) cache_calloc_share(MAX_MBS,
                        sizeof (vldMBHMpeg2_t), -1);
    Token = (UInt32 *) cache_calloc_share(MAX_MBS * MAX_TOKENS_PER_MB,
                          sizeof (UInt32), -1);
    if (Mbh == NULL || Token == NULL) {
        return -1;
    }
    return 0;
}



/****************************************************************************
    static Int parseOffUptoPicture(void)

    Parse the stream off until we see picture start code
****************************************************************************/
static Int 
parseOffUptoPicture(void)
{
    UInt32      data;
    int         done = False;

    while (done == False) {
        ERROR_IF_NOT_OK(vldNextStartCode(instance, &data));
        DP(("next start code = 0x%x\n", data));
        if (data == PICTURE_START_CODE) {
            done = True;
        }
    }
    return 0;
}


/****************************************************************************
    static Int parseSeqHeader 

    Parses off the sequence header.
****************************************************************************/
static Int 
parseSeqHeader(void)
{
    
    UInt32 	data;
    Int 	i;
    
    DP(("Parse seq header \n"));
    /* Flush off sequence start code. */
       
    vldFlushBits(instance, 8);
    
    /* Get horizontal size of image space. */
    
    vldGetBits(instance, 12, &data);
    seqhead.h_size = data;
    DP(("h_size: %u \n", data));
    
    /* Get vertical size of image space. */
    
    vldGetBits(instance, 12, &data);
    seqhead.v_size = data;
    DP(("v_size: %u \n", data));

    /*
     * Sanity checking.  Better be multiple of 16
     */
    if ((seqhead.v_size & 0xf) || (seqhead.h_size & 0xf))
    {
	DP(("I cannot handle this image size (%d X %d)\n", 
	      seqhead.h_size, seqhead.v_size));
    }
    
    /* Parse off aspect ratio code. */
    
    vldGetBits(instance, 4, &data);
    seqhead.aspect_ratio = (unsigned char) data;
    DP(("aspect_ratio: %u \n", data));
    
    /* Parse off picture rate code. */
    
    vldGetBits(instance, 4, &data);
    seqhead.frame_rate = (unsigned char) data;
    DP(("frame rate code: %u \n", data));
    
    /* Parse off bit rate. */
    
    vldGetBits(instance, 18, &data);
    seqhead.bit_rate = data;
    DP(("bit_rate: %u \n", data));
    
    /* Flush marker bit. */
    
    vldFlushBits(instance, 1);
    
    /* Parse off vbv buffer size. */
    
    vldGetBits(instance, 10, &data);
    seqhead.vbv_buf_size = data;
    DP(("vbv_buf_size: %u \n", data));
    
    /* Parse off contrained parameter flag. */
    
    vldGetBits(instance, 1, &data);
    DP(("Cons_param_flag: %u \n", data));
    if (data) {
	seqhead.const_param_flag = True;
    } else
	seqhead.const_param_flag = False;
    
    /*
     * If intra_quant_matrix_flag set, parse off intra quant matrix values.
     */
    
    vldGetBits(instance, 1, &data);
    DP(("intra_quant_flag: %u \n", data));
    if (data) {
      for (i = 0; i < 64; i++) {
        vldGetBits(instance, 8, &data);
        seqhead.intra_quant_matrix[zigzag_direct[i]>>3][zigzag_direct[i] & 0x7] = (unsigned char) data;
      }
    }
    /*
     * If non intra quant matrix flag set, parse off non intra quant matrix
     * values.
     */
    
    vldGetBits(instance, 1, &data);
    if (data) {
      for (i = 0; i < 64; i++) {
        vldGetBits(instance, 8, &data);
        seqhead.non_intra_quant_matrix[zigzag_direct[i]>>3][zigzag_direct[i]& 0x7] = (unsigned char) data;
      }
    }
    
    /* Go to next start code. */
    vldNextStartCode(instance, &data);
    DP(("2nd vldNextstartCode: 0x%x \n", data));
    
    if (data == EXT_START_CODE) {
      vldFlushBits(instance, 8);
      vldGetBits(instance, 4, &data);
      DP(("ext_id: 0x%x \n", data));
      if (data == SEQ_EXT_ID) {
	seqext.ext_id = data;
	vldGetBits(instance, 8, &data);
	seqext.profile_level = data;
	DP(("profile_level: 0x%x \n", data));
	vldGetBits(instance, 3, &data);
	seqext.progressive_seq_flag = (data & 0x4) >> 2;
	DP(("progress_seq: %u \n",seqext.progressive_seq_flag));
	seqext.chroma_format = data & 0x3;
	DP(("chroma_format: %u \n", seqext.chroma_format));
	vldGetBits(instance, 4, &data);
	seqext.h_size_ext = (data & 0xc) >> 2;
	DP(("h_size_ext: %u\n", seqext.h_size_ext));
	seqext.v_size_ext = data & 0x3;
	DP(("v_size_ext: %u\n",seqext.v_size_ext));
        vldGetBits(instance, 12, &data);
	seqext.bit_rate_ext = data;
	DP(("bit_rate_ext: %u\n",seqext.bit_rate_ext));
 	vldGetBits(instance, 9, &data);
	seqext.vbv_buf_size_ext = data & 0xff;
	DP(("vbv_buf_ext: %u\n",seqext.vbv_buf_size_ext));
	vldGetBits(instance, 8, &data);
	seqext.low_delay = (data >> 7) & 0x1;
	DP(("low_delay: %u\n", seqext.low_delay));
	seqext.frame_rate_ext_n = (data >> 5) & 0x3;
	DP(("frame_rate_n: %u\n", seqext.frame_rate_ext_n));
	seqext.frame_rate_ext_d = data & 0x1f;
	DP(("frame_rate_d: %u\n", seqext.frame_rate_ext_d));
      }
      vldNextStartCode(instance, &data);
      DP(("3nd vldNextStartCode: 0x%x\n", data));
    }
	
    /*
     * If next start code is extension or user start code, parse off extension data.
     */
    while (data == EXT_START_CODE || data == USER_START_CODE) {
	vldFlushBits(instance, 8);

	/*
	 * Extension or User data ends when it hits the start code.
	 */
	vldNextStartCode(instance, &data);
	DP(("4th or more vldNextStartCode: 0x%x\n", data));
    }
    
    DP(("finished parse seq header \n"));
    return TMLIBDEV_OK;
}



/****************************************************************************
     static Int parseGOP(GoP *groupict) 
 
     Parses of group of pictures header from bit stream
     associated with vid_stream.
****************************************************************************/
static Int 
parseGOP(GoP *groupict)
{
    UInt32 data;
    
    DP(("Parse GOP \n"));
    /* Flush group of pictures start code */
    
    vldFlushBits(instance, 8);
    
    /* Parse off drop frame flag. */
    
    vldGetBits(instance, 1, &data);
    if (data) {
	groupict->drop_flag = True;
    } else
	groupict->drop_flag = False;
    
    /* Parse off hour component of time code. */
    
    vldGetBits(instance, 5, &data);
    groupict->tc_hours = data;
    
    /* Parse off minute component of time code. */
    
    vldGetBits(instance, 6, &data);
    groupict->tc_minutes = data;
    
    /* Flush marker bit. */
    
    vldFlushBits(instance, 1);
    
    /* Parse off second component of time code. */
    
    vldGetBits(instance, 6, &data);
    groupict->tc_seconds = data;
    
    /* Parse off picture count component of time code. */
    
    vldGetBits(instance, 6, &data);
    groupict->tc_pictures = data;
    
    /* Parse off closed gop and broken link flags. */
    
    vldGetBits(instance, 2, &data);
    if (data > 1) {
	groupict->closed_gop = True;
	if (data > 2) {
	    groupict->broken_link = True;
	} else
	    groupict->broken_link = False;
    } else {
	groupict->closed_gop = False;
	if (data) {
	    groupict->broken_link = True;
	} else
	    groupict->broken_link = False;
    }
    
    /* Goto next start code. */
    
    vldNextStartCode(instance, &data);
    DP(("vldNextStartCode: 0x%x\n", data));
    
    /*
     * If next start code is extension or user start code, parse off extension data.
     */
    while (data == EXT_START_CODE || data == USER_START_CODE) {
	vldFlushBits(instance, 8);

	/*
	 * Extension or User data ends when it hits the start code.
	 */
	vldNextStartCode(instance, &data);
    }

    DP(("finished parse GOP\n"));
    return TMLIBDEV_OK;
}


/************************************************************************
    static Int parsePict(vldPictureInfo_t *pictinfo)

    Parses picture header into pictinfo
****************************************************************************/
static Int 
parsePict(vldPictureInfo_t * pictinfo)
{
    UInt32      data;

    DP(("Parse picture \n"));

    vldFlushBits(instance, 8);

    /*
     * temporal reference
     */
    vldFlushBits(instance, 10);

    vldGetBits(instance, 3, &data);
    pictinfo->pictureType = data;

    /*
     * vbv delay
     */
    vldFlushBits(instance, 16);

    /* If P or B type frame... */

    if ((pictinfo->pictureType == 2) ||
        (pictinfo->pictureType == 3)) {

        /* Parse off forward vector full pixel flag. */
        vldFlushBits(instance, 1);

        /* Parse forw_r_code. */
        vldGetBits(instance, 3, &data);

        pictinfo->hForwRSize = data - 1;
        pictinfo->vForwRSize = data - 1;
    }

    /* If B type frame... */

    if (pictinfo->pictureType == 3) {

        /* Parse off back vector full pixel flag. */
        vldFlushBits(instance, 1);

        /* Parse back_r_code. */
        vldGetBits(instance, 3, &data);

        pictinfo->hBackRSize = data - 1;
        pictinfo->vBackRSize = data - 1;
    }

    /* parse off extra bit picture info. */
    vldGetBits(instance, 1, &data);
    while (data) {
        vldFlushBits(instance, 8);
        vldGetBits(instance, 1, &data);
    }

    /* Goto next start code. */
    ERROR_IF_NOT_OK(vldNextStartCode(instance, &data));
    DP(("NextstartCode in picture: 0x%x \n", data));

    if (data == EXT_START_CODE) {
        vldFlushBits(instance, 8);
        vldGetBits(instance, 4, &data);

⌨️ 快捷键说明

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