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

📄 vitest.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
        /* Get the video standard from specified adapter */
        if ((err = viGetAdapterVideoStandard(viInst, adapterType, 0, &videoStandard))
            || videoStandard == vasNone)
            fprintf(stderr, "\nCould not determine the input standard\n");
        else if (videoStandard == vasNTSC)
            fprintf(stderr, "\nI think I am getting NTSC input\n");
        else if (videoStandard == vasPAL)
            fprintf(stderr, "\nI think I am getting PAL input\n");
        else if (videoStandard == vasSECAM)
            fprintf(stderr, "\nI think I am getting SECAM input\n");
    }
    
    memset((Char *) &viInstSup, 0, sizeof (viInstanceSetup_t));

    viInstSup.interruptPriority = intPRIO_4;
    viInstSup.isr = viMyISR;
    viInstSup.videoStandard = videoStandard;    
    viInstSup.adapterType = adapterType;

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

    memset((Char *) &viYUVInstSup, 0, sizeof (viYUVSetup_t));
    viYUVInstSup.thresholdReachedEnable = False;
    viYUVInstSup.captureCompleteEnable = True;
    viYUVInstSup.cositedSampling = True;
    viYUVInstSup.mode = viHALFRES;

    /* Try to get horizontal and vertical start position from vi */
    if (viGetDefaultAcquisitionWnd(viInst, &startX, &startY, &endX, &endY) == TMLIBDEV_OK)
    {
        if (viYUVInstSup.mode == viHALFRES)
            /* Make sure startX is a multiple of 4 */
            viYUVInstSup.startX = (startX + 3) & 0xFC;
        else
            viYUVInstSup.startX = startX;

        viYUVInstSup.startY = startY;
    }
    else
    {
        /* If not available by vi, use defaults */ 
        viYUVInstSup.startX = 4;
        viYUVInstSup.startY = 11;
    }

    viYUVInstSup.width = vidWidth;
    viYUVInstSup.height = vidHeight;
    viYUVInstSup.yBase = viBuf[0].Y;
    viYUVInstSup.uBase = viBuf[0].U;
    viYUVInstSup.vBase = viBuf[0].V;

    viYUVInstSup.yDelta = 33;    /* (384 - 352) + 1 */
    viYUVInstSup.uDelta = 17;    /* (192 - 176) + 1 */
    viYUVInstSup.vDelta = 17;

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


/***************************************************************/
/*                                                             */
/*                User Interface                               */
/*                                                             */
/***************************************************************/

static void
viUsage()
{
    printf("usage: ld vitest.out [-d f9000000] "
           "[-s 2400] [-b 3] [-not555a] [-l 1000] [pal|ntsc] [cvbs|s-video]\n");

}

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

    if (argc == 1)
        viUsage();

    argc--;
    while (argc > 0) {
        if (strcmp(argv[mark], "-d") == 0) {
            argc--;
            mark++;
            sscanf(argv[mark], "%x", &DPhyAdr);
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "-s") == 0) {
            argc--;
            mark++;
            sscanf(argv[mark], "%d", &Dstride);
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "-b") == 0) {
            argc--;
            mark++;
            sscanf(argv[mark], "%d", &Dbpp);
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "-l") == 0) {
            argc--;
            mark++;
            sscanf(argv[mark], "%d", &LOOPCOUNT);
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "-not555a") == 0) {
            argc--;
            mark++;
            not555a = 1;
        }
        else if (strcmp(argv[mark], "ntsc") == 0) {       /* NTSC */
            videoStandard = vasNTSC;
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "pal") == 0) {        /* PAL */
            videoStandard = vasPAL;
            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 {
            viUsage();
            argc--;
            mark++;
        }
    }

    /*
     * Try to locate the video memory on the specified address
     */

#ifndef __TCS_nohost__
    if (((Int *) DPhyAdr)[0] == 0) {
        fprintf(stderr, "I could be wrong but is %x indeed\n"
            "the address of your video buffer?\n"
            "I am going to write into it directly.....\n"
            "You can verify the address in\n"
            "\tControl Panel\\System\\device Manager"
            "\\Display Adapter\\<whatever>\\Resources\n"
            "Press any key to continue, ^C to quit\n", DPhyAdr);
        getchar();
    }
#endif
}

/***************************************************************/
/*                                                             */
/*                Rest                                         */
/*                                                             */
/***************************************************************/

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

static void
AllocBuffers()
{
    Int         i, szY, szUV, err;
    pprocCapabilities_t cap;

    szY = yScanWidth * (yScanHeight + 4);
    szUV = uvScanWidth * (uvScanHeight + 4);


    /*
     * workaround when dummycode is needed: remap U to SDRAM base,
     * hardware bug fixed in tm1s1.1
     */
    if (err = procGetCapabilities(&cap))
        my_abort("procGetCapabilities", err);

    if (cap->revisionID <= PROC_REVISION_1_0S && cap->deviceID <= PROC_DEVICE_TM1000) {
    fprintf(stderr, "Detected tm1s1.0 or older version of chip. "
        "They are no longer supported.\n" 
        "Please contact Philips TriMedia to exchange to "
        "a newer version of chip.\n");
    exit(-1);
    }

    for (i = 0; i < NUM_VI_BUF; i++) {

        viBuf[i].Y = _cache_malloc(szY, -1);
        viBuf[i].U = _cache_malloc(szUV, -1);
        viBuf[i].V = _cache_malloc(szUV, -1);

        viBuf[i].flag = VI_READY;

        /*
         * Always start with clean memory,VI does not overwrite
         * everything and ICP does not like the extra data to be non
         * zero
         */
        memset(viBuf[i].Y, 0, szY);
        memset(viBuf[i].U, 0, szUV);
        memset(viBuf[i].V, 0, szUV);
        _cache_copyback((Char *) viBuf[i].Y, szY);
        _cache_copyback((Char *) viBuf[i].U, szUV);
        _cache_copyback((Char *) viBuf[i].V, szUV);

        /*
         * printf("Allocated viBuf i %d Y %x U %x V %x\n", i,
         * viBuf[i].Y, viBuf[i].U, viBuf[i].V);
         */
    }
}

int
main(Int argc, Char **argv)
{
    Int         i;
    Int         err;

    DPsize(64000);
    DP((Header));
    DP(("Running on ")); tmHelpReportSystem(Null);
    printf(Header);
    printf("Running on "); tmHelpReportSystem(stdout);

#ifndef __TCS_nohost__
    viCheckArgcv(argc, argv);
#else
    argc = 0;
    argv = NULL;
#endif

    AllocBuffers();
    SetupICP();
    SetupVI();

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

    for (i = 0; i < LOOPCOUNT; i++) {

        /*
         * Idle looping until it captures one even field
         */
        got1SField = 0;

        while (got1SField == 0);

        icpDisplay();

#if 0
        if ((i + 1) % 100 == 0) {
            viSetSaturation(viInst, 0);
        }
        if ((i + 1) % 200 == 0) {
            viSetHue(viInst, 10);
        }
        if ((i + 1) % 300 == 0) {
            viSetContrast(viInst, 32);
        }
        if ((i + 1) % 400 == 0) {
            viSetBrightness(viInst, 32);
        }
#endif
    }
    if (err = viStop(viInst))
        my_abort("viStop", err);

    printf("vitest: Completed %d frames\n", LOOPCOUNT);

    if (err = icpClose(icpInst))
        my_abort("icpClose", err);

    if (err = viClose(viInst))
        my_abort("viClose", err);

    exit(0);
}

⌨️ 快捷键说明

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