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

📄 avio.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    aiInstSup.input = aaaNone;
    aiInstSup.size = AUD_BUFSIZE;
    aiInstSup.base1 = audBuf[0];
    aiInstSup.base2 = audBuf[1];

    aiInstSup.overrunEnable = True;
    aiInstSup.hbeEnable = True;
    aiInstSup.buf1fullEnable = True;
    aiInstSup.buf2fullEnable = True;

    /*
     * Start them
     */

    if (err = aiInstanceSetup(aiInst, &aiInstSup))
        my_abort("aiInstanceSetup", err);

    if (err = aoStart(aoInst))
        my_abort("aoStart", err);
    if (err = aiStart(aiInst))
        my_abort("aiStart", err);
}



/***************************************************************
 *                                                             *
 *                Video ISRs                                   *
 *                                                             *
 ***************************************************************/

void
_voISR(void)
{
    UInt32   vo_status = MMIO(VO_STATUS);
    Int      votmpNum;

    if (voYTR(vo_status))
        voAckYTR_ACK();
    if (voURUN(vo_status))
        voAckURUN_ACK();
    if (voHBE(vo_status))
        voAckHBE_ACK();
    if (voBUF2EMPTY(vo_status))
        voAckBFR2_ACK();
    if (voBUF1EMPTY(vo_status)) {
        if (voFIELD2(vo_status)) {
            voYUVChangeBuffer(voInst,
                      (UInt32) vidBuf[voNum].Y + fullStride,
                      (UInt32) vidBuf[voNum].U + (fullStride >> 1),
                      (UInt32) vidBuf[voNum].V + (fullStride >> 1));
        }
        else {
            votmpNum = (voNum + 1) % VID_NUMBUFS;
            if (vidBuf[votmpNum].flag == VID_RDY_VO) {
                vidBuf[voNum].flag = VID_RDY_VI;
                voNum = votmpNum;
            }
            voYUVChangeBuffer(voInst,
                      vidBuf[voNum].Y,
                      vidBuf[voNum].U,
                      vidBuf[voNum].V);
        }
    }
    voAckBFR1_ACK();
}

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

void
_viISR(void)
{
    UInt32   vi_status = MMIO(VI_STATUS);
    Int      oddField;
    Int      vitmpNum;

    oddField = viExtractODD(vi_status);

    if ((vi_status & 0x1) == 0) {

        /*
         * This is due to hardware bug 21390, a spurious interrupt
         * may occur. Since we have only enabled capture_enable (0x1)
         * we should not check on threshold_reached (0x2)
         */
        return;
    }
    if (viHBE(vi_status)) {

        /*
         * Highway bandwidth, VI needs more bandwidth. You can play
         * with the highway arbitration setting
         */
        viAckHBE_ACK();
        return;
    }

    if (firstField) {
        firstField = False;

        if (!oddField) {
            /* skip even field to get sync */
            firstField = True;
        }
        else {

            /* always start with odd field */
            viYUVChangeBuffer(viInst,
                      (UInt32) vidBuf[viNum].Y + fullStride,
                      (UInt32) vidBuf[viNum].U + (fullStride >> 1),
                      (UInt32) vidBuf[viNum].V + (fullStride >> 1));
        }
    }
    else {
        vitmpNum = (viNum + 1) % VID_NUMBUFS;
        if (vidBuf[vitmpNum].flag == VID_RDY_VI) {
            vidBuf[viNum].flag = VID_RDY_VO;
            viNum = vitmpNum;
        }
        /* always change the buffer */
        viYUVChangeBuffer(viInst,
                  vidBuf[viNum].Y,
                  vidBuf[viNum].U,
                  vidBuf[viNum].V);

        firstField = True;
    }
    viAckCAP_ACK(); /* read comments above on the acknowledge */
}

void
viISR(void)
{
#pragma TCS_handler
    AppModel_suspend_scheduling();
    AppModel_run_on_sstack((AppModel_Fun)_viISR, Null);
    AppModel_resume_scheduling();
}


/***************************************************************
 *                                                             *
 *                Video Device Library Calls                   *
 *                                                             *
 ***************************************************************/

static int
OpenVoAPI()
{
    voInstanceSetup_t voInstSup;
    voYUVSetup_t      voYUVSup;
    tmLibdevErr_t     err;

    if (err = voOpen(&voInst))
        my_abort("voOpen", err);

    memset((char *) (&voInstSup), 0, sizeof(voInstanceSetup_t));
    voInstSup.interruptPriority = intPRIO_3;
    voInstSup.isr = voISR;
    voInstSup.videoStandard = (tmVideoAnalogStandard_t) videoStandard;
    voInstSup.adapterType = (tmVideoAnalogAdapter_t) adapterType;

    voFrequencyToDDS(27000000.0, &voInstSup.ddsFrequency);

    voInstSup.hbeEnable = True;
    voInstSup.underrunEnable = True;

    if (err = voInstanceSetup(voInst, &voInstSup))
        my_abort("voInstanceSetup", err);


    memset((char *) (&voYUVSup), 0, sizeof(voYUVSetup_t));
    voYUVSup.mode = vo422_COSITED_UNSCALED;
    voYUVSup.buf1emptyEnable = True;
    voYUVSup.yThresholdEnable = False;
    voYUVSup.yThreshold = 0;
    voYUVSup.yBase = vidBuf[voNum].Y;
    voYUVSup.uBase = vidBuf[voNum].U;
    voYUVSup.vBase = vidBuf[voNum].V;

    voYUVSup.imageVertOffset = 0;
    voYUVSup.imageHorzOffset = 0;
    voYUVSup.imageHeight = (fullHeight >> 1);
    voYUVSup.yStride = (2 * fullStride);
    voYUVSup.uStride = fullStride;
    voYUVSup.vStride = fullStride;
    voYUVSup.imageWidth = fullWidth;

    if (err = voYUVSetup(voInst, &voYUVSup))
        my_abort("voYUVSetup", err);

    return (0);
}

void
OpenViAPI()
{
    viInstanceSetup_t viInstSup;
    viYUVSetup_t    viYUVSup;
    tmLibdevErr_t   err;

    if (err = viOpen(&viInst))
        my_abort("viOpen", err);

    memset((char *) (&viInstSup), 0, sizeof(viInstanceSetup_t));

    viInstSup.interruptPriority = intPRIO_3;
    viInstSup.isr = viISR;
    viInstSup.videoStandard = (tmVideoAnalogStandard_t) videoStandard;
    viInstSup.adapterType = (tmVideoAnalogAdapter_t) adapterType;

    if (err = viInstanceSetup(viInst, &viInstSup))
        my_abort("viInstanceSetup", err);

    memset((char *) (&viYUVSup), 0, sizeof(viYUVSetup_t));

    viYUVSup.thresholdReachedEnable = False;
    viYUVSup.captureCompleteEnable = True;
    viYUVSup.cositedSampling = True;

    viYUVSup.mode = viFULLRES;
    viYUVSup.startX = 0;
    viYUVSup.startY = 21;
    viYUVSup.width = fullWidth;
    viYUVSup.yBase = vidBuf[viNum].Y;
    viYUVSup.uBase = vidBuf[viNum].U;
    viYUVSup.vBase = vidBuf[viNum].V;
    viYUVSup.height = (fullHeight >> 1);
    viYUVSup.yDelta = (fullStride - fullWidth) + fullStride + 1;
    viYUVSup.uDelta = ((fullStride - fullWidth) >> 1) + (fullStride >> 1) + 1;
    viYUVSup.vDelta = ((fullStride - fullWidth) >> 1) + (fullStride >> 1) + 1;

    if (err = viYUVSetup(viInst, &viYUVSup))
        my_abort("viYUVSetup", err);

}

static void
OpenVideoAPI(void)
{
    tmLibdevErr_t   err;

    /* pointers into a circular queue of video frames */
    voNum = 0;      /* output */
    viNum = 0;      /* input */

    OpenVoAPI();
    OpenViAPI();

    if (err = voStart(voInst))
        my_abort("voStart", err);

    if (err = viStart(viInst))
        my_abort("viStart", err);
}

void
avioUsage(void)
{
    printf("usage: avio [ntsc|pal] [cvbs|s-video] \n");
}

void
avioCheckArgcv(Int argc, Char **argv)
{
    Int             mark = 1;

    argc--;
    while (argc > 0) {
        if (strcmp(argv[mark], "ntsc") == 0) {  /* NTSC */
            videoStandard = vasNTSC;
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "pal") == 0) {  /* PAL */
            videoStandard = vasPAL;
            fullHeight = 576;
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "cvbs") == 0) { /* CVBS */
            adapterType = vaaCVBS;
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "s-video") == 0) {  /* S-Video */
            adapterType = vaaSvideo;
            argc--;
            mark++;
        }
        else {
            avioUsage();
            argc--;
            mark++;
            exit(-1);
        }
    }
}

int
main(int argc, char **argv)
{
    tmLibdevErr_t   err;

    SetDP();

    DP((Header));
    printf(Header);

    DP(("Running on ")); tmHelpReportSystem(Null);
    printf("Running on "); tmHelpReportSystem(stdout);

    vivoDetectworkarounds();

#ifndef __TCS_nohost__
    avioCheckArgcv(argc, argv);
#endif

    avioAlloc();
    OpenAudioAPI();
    OpenVideoAPI();

    while (1) {

#if 0               /* for debugging phase */
        if (AudioInSyncError) {
            printf("AudioInSyncError\n");
            AudioInSyncError = 0;
        }
        if (AudioOutSyncError) {
            printf("AudioOutSyncError\n");
            AudioOutSyncError = 0;
        }
#endif
    }

    if (err = aoClose(aoInst))
        my_abort("aoClose", err);
    if (err = aiClose(aiInst))
        my_abort("aiClose", err);
    if (err = voClose(voInst))
        my_abort("voClose", err);
    if (err = viClose(viInst))
        my_abort("viClose", err);
    exit(0);

}               /* end of main() */

⌨️ 快捷键说明

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