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

📄 evotest.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1995-2000 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : evotest.c   1.12
 *
 *  Last update              : 17:40:23 - 00/11/09
 *
 *  Description              :
 *
 *  This is an example program for enhanced video-out.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <tmlib/AppModel.h>
#include <tm1/tmVO.h>
#include <tm1/tmInterrupts.h>
#include <tm1/tmProcessor.h>
#include <ops/custom_defs.h>
#include <tmlib/tmlibc.h>
#include <tmlib/dprintf.h>

#include <tm1/tmHelp.h>

#define                YUV422        4
#define                YUV420        2
#define                NUM_VO_BUF    3

#define             CACHE_LINE_SIZE    64

typedef struct _videoBuf {    /* video buffer structure example */
    UInt32      Y;            /* buffer pointer for Y */
    UInt32      U;            /* buffer pointer for U */
    UInt32      V;            /* buffer pointer for V */
    UInt32      flag;         /* flags used in buffer management */
}           vBuf, *pvBuf;

static vBuf voBuf[NUM_VO_BUF];

static Int  overlayNum = 2;
static Int  displayNum = 0;
static Int  yFieldStride = 0;
static Int  uvFieldStride = 0;
static Int  overlayFieldStride = 0;
static volatile UInt voISRCount = 0;
static Int  bufWidth = 768;
static Int  bufHeight = 576;

static UInt videoStandard = vasNTSC;
static Int  voInst;
static voInstanceSetup_t voInstSup;
static voYUVSetup_t voYUVSup;
static voOverlaySetup_t voOverlaySup;

static voenhChromaKeyingSetup_t evoChrKeySup;
static voenhClipSetup_t evoClipSup;

static Int  SMALLNUMBER = 120;

static Int  cloudsWidth = 720;
static Int  cloudsHeight = 480;
static Int  cloudsStride = 720;

static Int  tinkerWidth = 176;
static Int  tinkerHeight = 266;

static Int  myAlpha0 = 250;
static Int  myAlpha1 = 250;

static Int  myStartLine = 64;
static Int  myStartPixel = 128;

static Int  myKeyY = 0;
static Int  myKeyU = 0;
static Int  myKeyV = 0;
static Int  myMaskY = 0;
static Int  myMaskUV = 0;

static Int  myHClipUV = 0;
static Int  myLClipUV = 0;
static Int  myHClipY = 0;
static Int  myLClipY = 0;

static char *Header = "\nTriMedia Enhanced Video-Out Example Program Version 1.0\n\n";

void 
evoUsage(void)
{
    printf("usage: evotest [ntsc|pal] \n");
}

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

/***** Command Line Interface **********************************************/
void 
evoCheckArgcv(Int argc, Char **argv)
{
    int         mark = 1;

    argc--;
    while (argc > 0) {
        if (strcmp(argv[mark], "ntsc") == 0) {       /* NTSC MODE */
            videoStandard = vasNTSC;
            argc--;
            mark++;
        }
        else if (strcmp(argv[mark], "pal") == 0) {    /* PAL MODE */
            videoStandard = vasPAL;
            argc--;
            mark++;
        }
        else {
            evoUsage();
            argc--;
            mark++;
        }
    }
}

/***** File Reading ******************************************/
Int 
readYUVFiles(char *baseName, Int hsize, Int vsize,
         UInt32 yBuf, UInt32 uBuf, UInt32 vBuf, Int fm)
{
    Int         count, ySize, uvSize;
    char        fn[80];
    FILE       *fp;

    ySize = hsize * vsize;
    if (fm == YUV422) {
        uvSize = ySize >> 1;
    }
    else if (fm == YUV420) {
        uvSize = ySize >> 2;
    }
    if (!yBuf)
        return (1);
    if (!uBuf)
        return (2);
    if (!vBuf)
        return (3);

    /* read Y file: binary */
    sprintf(fn, "%s.y", baseName);
    /* printf("File %s: ", fn); */
    fp = fopen(fn, "rb");
    if (!fp)
        return (4);
    count = fread((char *) yBuf, 1, ySize, fp);
    if (count != ySize)
        return 4;
    /* printf("Read %d bytes \n", count); */
    fclose(fp);
    _cache_copyback((void *) yBuf, ySize);

    /* read U file: binary */
    sprintf(fn, "%s.u", baseName);
    /* printf("File %s: ", fn); */
    fp = fopen(fn, "rb");
    if (!fp)
        return (4);
    count = fread((char *) uBuf, 1, uvSize, fp);
    if (count != uvSize)
        return 4;
    /* printf("Read %d bytes \n", count); */
    fclose(fp);
    _cache_copyback((void *) uBuf, uvSize);

    /* read V file: binary */
    sprintf(fn, "%s.v", baseName);
    /* printf("File %s: ", fn); */
    fp = fopen(fn, "rb");
    if (!fp)
        return (4);
    count = fread((char *) vBuf, 1, uvSize, fp);
    if (count != uvSize)
        return 4;
    /* printf("Read %d bytes \n", count); */
    fclose(fp);
    _cache_copyback((void *) vBuf, uvSize);

    return (0);
}

/***** Interrupt Service Routine *******************************************/
void 
_voTestISR()
{
    UInt32 vo_status = MMIO(VO_STATUS);

    voISRCount++;

    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 (vo_status & VO_BUF1EMPTY) {    /* bfr1 empty */
        if (!(vo_status & VO_FIELD2)) {
            voYUVChangeBuffer(voInst,
                      voBuf[displayNum].Y,
                      voBuf[displayNum].U,
                      voBuf[displayNum].V);
            voOverlayChangeBuffer(voInst,
                      voBuf[overlayNum].Y + overlayFieldStride);
            voAckBFR1_ACK();
            return;
        }
        /* from f1 to f2 */
        voYUVChangeBuffer(voInst,
                  voBuf[displayNum].Y + (yFieldStride),
                  voBuf[displayNum].U + (uvFieldStride),
                  voBuf[displayNum].V + (uvFieldStride));
        voOverlayChangeBuffer(voInst, voBuf[overlayNum].Y);
        voAckBFR1_ACK();
        return;
    }
}                /* end of vo ISR */

void 
voTestISR()
{
#pragma TCS_handler
    AppModel_suspend_scheduling();
    AppModel_run_on_sstack((AppModel_Fun)_voTestISR, Null);
    AppModel_resume_scheduling();
}

void YUV422ToOverlay(UInt32 yP, UInt32 uP, UInt32 vP,
          UInt32 ovP, Int width, Int height)
{
    UInt8 *pp;
    UInt8 *pY0;
    UInt8 *pY1;
    UInt8 *pU;
    UInt8 *pV;
    UInt  *tmpPtr;
    Int            i, j;

    pY0 = (UInt8 *) yP;
    pU = (UInt8 *) uP;
    pV = (UInt8 *) vP;
    pp = (UInt8 *) yP;
    pY1 = ++pp;

    tmpPtr = (UInt *) ovP;

    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++) {
#ifdef __LITTLE_ENDIAN__
            *tmpPtr = ((*pY1++ & 0xff) << 24) | (*pV++ & 0xff) << 16 |
                      ((*pY0++ & 0xff) << 8) | (*pU++ & 0xff) << 0;
#else
            *tmpPtr = ((*pY1++ & 0xff) << 8) | (*pV++ & 0xff) << 0 |
                      ((*pY0++ & 0xff) << 24) | (*pU++ & 0xff) << 16;
#endif /* __LITTLE_ENDIAN__ */
            tmpPtr++;
            pY1++;
            pY0++;
        }
    }    
}

void getTinkerToOverlay()
{
    Int         retVal = 0;
#ifndef __TCS_nohost__
    /* read in tinker to voBuf[1] */
    if (retVal = readYUVFiles("tinker176x266", tinkerWidth, tinkerHeight,
        voBuf[1].Y, voBuf[1].U, voBuf[1].V, YUV422)) {
        my_abort("readYUVFiles tinker", retVal);
    }
    /* convert YUV422 in voBuf[1] to overlay in voBuf[2] */
    YUV422ToOverlay(voBuf[1].Y, voBuf[1].U, voBuf[1].V, voBuf[2].Y, 
	tinkerWidth, tinkerHeight);
#endif
}

void voOpenInstAPI()
{
    tmLibdevErr_t retVal;

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

    memset((char *) (&voInstSup), 0, sizeof (voInstanceSetup_t));
    voInstSup.interruptPriority = intPRIO_3;
    voInstSup.isr = voTestISR;

⌨️ 快捷键说明

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