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

📄 image.c

📁 TMS320DM6437下的图像采集例程!很有学习价值
💻 C
📖 第 1 页 / 共 2 页
字号:

    encStatus.size    = sizeof(VIDENC_Status);
    encDynParams.size = sizeof(VIDENC_DynamicParams);
    status = IMGENC_control(enc, XDM_SETPARAMS, &encDynParams, &encStatus);
    if (status != VIDENC_EOK) {
        printf("Encoder XDM_SETPARAMS FAILED, status = 0x%lx\n", 
                status);
        goto end;
    }

    /* Set Dynamic Params for Decoder */
    initVD_DynamicParams(&decDynParams);

    decStatus.size    = sizeof(VIDDEC_Status);
    decDynParams.size = sizeof(VIDDEC_DynamicParams);
    status = IMGDEC_control(dec, XDM_SETPARAMS, &decDynParams, &decStatus);
    if (status != VIDDEC_EOK) {
        printf("Decoder XDM_SETPARAMS FAILED, status = 0x%lx\n", 
                status);
        goto end;
    }

    /* use engine to encode, then decode the data */
    encode_decode(enc, dec ,fh_enc);

end:
    /* teardown the codecs */
    if (enc) {
        IMGENC_delete(enc);
    }
    if (dec) {
        IMGDEC_delete(dec);
    }

    /* close the engine */
    if (ce) {
        Engine_close(ce);
    }

    /* free buffers */
    if (encodedBuf) {
        Memory_contigFree(encodedBuf, framesize);
    }

    /* Free Video Driver resources:  */
    if (hGioVpfeCcdc)  {
       for (i=0; i<FRAME_BUFF_CNT && status == 0; i++) {
            FVID_freeBuffer(hGioVpfeCcdc, frameBuffTable[i]);
       }
    }

    /* Delete Channels */
    if (hGioVpfeCcdc)  {
       FVID_delete(hGioVpfeCcdc);
    }
    if (hGioVpbeVid0)  {
       FVID_delete(hGioVpbeVid0);
    }
    if (hGioVpbeVenc)  {
       FVID_delete(hGioVpbeVenc);
    }

    printf("video_encdec done.\n");
    return (0);
}


/*
 *  ======== initVE_StaticParams ========
 */
static Void initVE_StaticParams(IMGENC_Params * vencParams)
{
    /* Set Constant Bit Rate, YUV422 Interlaced, little endian: */
    vencParams->size                  = sizeof(VIDENC_Params);
    vencParams->encodingPreset        = XDM_DEFAULT;
    vencParams->rateControlPreset     = IVIDEO_LOW_DELAY;
    vencParams->maxHeight             = inputHeight; 
    vencParams->maxWidth              = inputWidth; 
    vencParams->maxFrameRate          = maxFrameRate;
    vencParams->maxBitRate            = VE_MAX_BR;
    vencParams->dataEndianness        = XDM_BYTE;
    vencParams->maxInterFrameInterval = 0;
    vencParams->inputChromaFormat     = XDM_YUV_422ILE;
    vencParams->inputContentType      = IVIDEO_PROGRESSIVE;

    return;
}       


/*
 * ======== initVE_DynamicParams ========
 */
static Void initVE_DynamicParams(VIDENC_DynamicParams *encDynParams)
{
  encDynParams->inputHeight     = inputHeight;
  encDynParams->inputWidth      = inputWidth;
  encDynParams->refFrameRate    = maxFrameRate;
  encDynParams->targetFrameRate = maxFrameRate;
  encDynParams->targetBitRate   = VE_MAX_BR;
  encDynParams->intraFrameInterval  = intraFrameInterval;
  encDynParams->generateHeader  = XDM_ENCODE_AU;    
  encDynParams->captureWidth    = 0;      
  encDynParams->forceIFrame     = 0;       

  return;
}


/*
 *  ======== initVD_StaticParams ========
 */
static Void initVD_StaticParams(VIDDEC_Params * vdecParams)
{
    /* Set Constant Bit Rate, YUV422 Interlaced, little endian: */
    vdecParams->size                 = sizeof(VIDDEC_Params);

    vdecParams->maxHeight            = inputHeight;
    vdecParams->maxWidth             = inputWidth;
    vdecParams->maxFrameRate         = 0;
    vdecParams->maxBitRate           = 0;
    vdecParams->dataEndianness       = XDM_BYTE;
    vdecParams->forceChromaFormat    = XDM_YUV_422ILE;

    return ;
}    

/*
 * ======== initVD_DynamicParams ========
 */
static Void initVD_DynamicParams(IMGDEC_DynamicParams *decDynParams)
{
  decDynParams->decodeHeader    = XDM_DECODE_AU;
  decDynParams->displayWidth    = 0;
  decDynParams->frameSkipMode   = IVIDEO_NO_SKIP;

  return;
}

/*
 *  ======== encode_decode ========
 */
static Void encode_decode(IMGENC_Handle enc, IMGDEC_Handle dec,FILE *fh_enc)
{
    Int32                       n;

    XDM_BufDesc                 inBufDesc;
    XDM_BufDesc                 encodedBufDesc;
    XDM_BufDesc                 outBufDesc;
    Int32                       status;

    XDAS_Int32                  ibufSizes;
    XDAS_Int32                  ebufSizes;
    XDAS_Int32                  obufSizes;

    IMGDEC_InArgs               decInArgs;
    IMGDEC_OutArgs              decOutArgs;

    IMGENC_InArgs               encInArgs;
    IMGENC_OutArgs              encOutArgs;

    XDAS_Int8                   *src;
    XDAS_Int8                   *encoded;
    XDAS_Int8                   *dst;

    /* Initialize .size fields */
    encInArgs.size = sizeof(encInArgs);
    decInArgs.size = sizeof(decInArgs);
    encOutArgs.size = sizeof(encOutArgs);
    decOutArgs.size = sizeof(decOutArgs);

    /* Set numbufs for vencParams.inputChromaFormat = XDM_YUV_422ILE: */
    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;

    ibufSizes = ebufSizes = obufSizes = framesize;

    inBufDesc.bufSizes       = &ibufSizes;
    encodedBufDesc.bufSizes  = &ebufSizes;
    outBufDesc.bufSizes      = &obufSizes;

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    printf("Starting encode/decode loopback ...\n");
    for (n=0;;n++) {
        /* prepare "per loop" buffer descriptor settings */
        inBufDesc.bufs = &src;
        encoded = encodedBuf;
        encodedBufDesc.bufs = &encodedBuf;
        outBufDesc.bufs = &dst;

        /* grab a fresh video input frame */
        FVID_exchange(hGioVpfeCcdc, &frameBuffPtr);
        
        /* Set as input buffer to Encoder: */
        src = frameBuffPtr->frame.frameBufferPtr;

        /* encode the frame */
        status = VIDENC_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        Memory_cacheWbInv(encoded, encOutArgs.bytesGenerated);
        fwrite(encoded, encOutArgs.bytesGenerated, 1, fh_enc);
        if (status != VIDENC_EOK) {
            printf("Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, encOutArgs.extendedError);
            break;
        }

        /* Reuse the video input frame for display exchange:  */
        dst = frameBuffPtr->frame.frameBufferPtr;
        if (encOutArgs.bytesGenerated == 0)
        {
          printf("Frame %d dropped\n", n);
        }

        /* decode the frame 
        decInArgs.numBytes = encOutArgs.bytesGenerated;

        status = VIDDEC_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);
           
        if (status != VIDDEC_EOK) {
            printf("Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }
        else {
            Memory_cacheWbInv(dst, framesize);
        }

        /* display the video frame 
        FVID_exchange(hGioVpbeVid0, &frameBuffPtr);*/
    }
}

/*
 * ======== read_JP1 ========
 * Read the PAL/NTSC jumper.
 *
 */
static int read_JP1(void)
{
    int jp1 = -1;

    /* Retry, as I2C sometimes fails: */
    while (jp1 == -1) {
      jp1 = EVMDM6437_DIP_get(JP1_JUMPER); 
      TSK_sleep(1);
    }
    return(jp1);
}       

⌨️ 快捷键说明

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