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

📄 testapp1.c

📁 5105 AV输出FILTER, 解析源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************

File name  : testapp1.c

Description: Test application #1 (RODOW).This will perform the single AV decode
for feed from Packet Injector and satellite.The application supports normal mode
as well as debug mode.For Debug mode environment variable DEBUG_MODE needs to be
enabled.

COPYRIGHT (C) 2005 STMicroelectronics

******************************************************************************/

/* Includes ---------------------------------------------------------------- */

#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <task.h>

/* STAPI header------------------------------------------------------------- */
#include "stddefs.h"
#include "stlite.h"
#include "stcommon.h"
#include "stdevice.h"
#include "sttbx.h"
#include "stsys.h"

#include "sections.h"
#include "errors.h"
#include "avmem.h"
#include "evt.h"
#include "aud.h"
#include "fdma.h"
#include "tuner.h"
#include "vid.h"
#include "denc.h"
#include "vtg.h"
#include "layer.h"
#include "vout.h"
#include "vmix.h"

#include "clkrv.h"
#include "stpti_hal.h"
#include "regevent.h"

/* test application specific */
#include "lists.h"      /* satellite Transponder and Channel lists */
#include "service.h"
#include "transport.h"

/* Debug mode specific header */
#if defined(DEBUG_MODE)
    #include "tst.h"
    #include "comdbg.h"
    #include "decode.h"
    #include "tunerdbg.h"
#endif /* end of DEBUG_MODE */

/* Private Types------------------------------------------------------------ */

/* Private Constant--------------------------------------------------------- */
#define AC3_AUDIO_SAMPLING_FREQUENCY        48000
#define MPEG1_AUDIO_SAMPLING_FREQUENCY      44100
#define MPEG2_AUDIO_SAMPLING_FREQUENCY      44100
#define MAX_TRY_TUNER_LOCK                  4
#define COUNT_FOR_PRINT                     30

/* Private Variables ------------------------------------------------------- */
static BOOL PacketInjectorUsed  = FALSE;

#if defined(DEBUG_MODE)
    SERVICE_Mode_t          SERVICE_Mode    = SERVICE_MODE_DVB;
    SERVICE_Display_t       SERVICE_Display = SERVICE_DISPLAY_PAL;
#endif /* end of DEBUG_MODE */

/* Private Functions prototypes --------------------------------------------------- */
static ST_ErrorCode_t Decode_Start(int Channel, int Transponder);
static ST_ErrorCode_t AVInfrastucture_Init(void);
static ST_ErrorCode_t AVInfrastucture_Configure(SERVICE_Display_t SERVICE_Display, SERVICE_Mode_t SERVICE_Mode);
static ST_ErrorCode_t Decode_StartStream( U16                Pid,
                                          LISTS_StreamType_t StreamType,
                                          SERVICE_Display_t  SERVICE_Display,
                                          SERVICE_Mode_t     SERVICE_Mode);
static ST_ErrorCode_t SelectFrequency(int Transponder);

#if !defined(DEBUG_MODE)
    static void Forever(STPTI_Pid_t VideoPid, STPTI_Pid_t AudioPid, int Transponder, SERVICE_Mode_t SERVICE_Mode);
#endif

/*=========================================================================*/

/* Function description */
/*-------------------------------------------------------------------------
 * Function: TestApplication
 * Decription: Entry point from main()
 * Input   : none
 * Output  :
 * Return  : Error code
 * ----------------------------------------------------------------------*/
ST_ErrorCode_t TestApplication(void)
{
    ST_ErrorCode_t  ST_ErrorCode=ST_NO_ERROR;
    SERVICE_Mode_t  SERVICE_Mode = MODE_DVB;
    int             Index = 0;
    int             Transponder = 0, Channel = 0;  /* default indexes for packet injector */


    /* setup tuner in any valid mode and
       if failure then presume that a packet injector is being used. */

    ST_ErrorCode = TUNER_Setup( SERVICE_Mode );
    if (ST_ErrorCode != ST_NO_ERROR)
    {
        PacketInjectorUsed = TRUE;
        STTBX_Print(( "Using: %s\n", LISTS_TransponderList[Transponder].InfoString ));
        ST_ErrorCode = Decode_Start( Channel, Transponder );   /* only return on failure */
        return( ST_ErrorCode ); /* failed */
    }

    while (LISTS_ChannelSelection[Index] != ENDOFLIST)
    {
        Channel = LISTS_ChannelSelection[Index];
        Transponder = LISTS_ChannelList[Channel].Transponder;

        /* configure tuner if mode change between DVB/DTV required */
        if (SERVICE_Mode != LISTS_TransponderList[Transponder].Mode)
        {
            STTBX_Print(( "Switching tuner mode.\n" ));
            SERVICE_Mode = LISTS_TransponderList[Transponder].Mode;

            ST_ErrorCode = TUNER_Quit();
            if (ST_ErrorCode != ST_NO_ERROR)
            {
                return( ST_ErrorCode ); /* fail */
            }

            ST_ErrorCode = TUNER_Setup( SERVICE_Mode );
            if (ST_ErrorCode != ST_NO_ERROR)
            {
                return( ST_ErrorCode ); /* fail */
            }
        }

        STTBX_Print(( "Lock to Transponder/Channel #%d: %s\n", Transponder, LISTS_TransponderList[Transponder].InfoString ));
        ST_ErrorCode = SelectFrequency( Transponder );              /* tune into specific frequency */

        if (ST_ErrorCode == ST_NO_ERROR)
        {
            ST_ErrorCode = Decode_Start( Channel, Transponder );   /* only return on failure */
            break;  /* out of while() */
        }

        Index++;
    }

    return( ST_ErrorCode ); /* failed */
}

/*-------------------------------------------------------------------------
 * Function : SelectFrequency
 * Input    : Index into Transponder list
 * Output   :
 * Return   : Error code
 * ----------------------------------------------------------------------*/
static ST_ErrorCode_t SelectFrequency( int Transponder )
{
    ST_ErrorCode_t          ST_ErrorCode;
    STTUNER_TunerInfo_t     TUNERInfo;
    STTUNER_Scan_t          ScanParams;
    U32                     TunerFrequency;

    ScanParams  = TUNER_Scans[0];  /* defaults for all types */

    /* Set specific parameters */
    TunerFrequency          = LISTS_TransponderList[Transponder].Frequency;
    ScanParams.Band         = LISTS_TransponderList[Transponder].FrequencyBand;

    #ifdef STTUNER_USE_SAT
        ScanParams.LNBToneState = LISTS_TransponderList[Transponder].LNBToneState;
        ScanParams.Polarization = LISTS_TransponderList[Transponder].Polarization;
    #endif

    #if defined (STTUNER_USE_SAT) || defined (STTUNER_USE_TER)
        ScanParams.FECRates     = LISTS_TransponderList[Transponder].FECRates;
    #endif

    #if defined (STTUNER_USE_SAT) || defined (STTUNER_USE_CAB)
        ScanParams.SymbolRate   = LISTS_TransponderList[Transponder].SymbolRate;
    #endif

    ScanParams.Modulation   = LISTS_TransponderList[Transponder].Modulation;
    ScanParams.AGC          = LISTS_TransponderList[Transponder].AGC;

    #ifdef STTUNER_MINIDRIVER
        ScanParams.Frequency    = TunerFrequency;
    #endif

    ST_ErrorCode = TUNER_SetFrequency(TunerFrequency, &ScanParams); /* blocks on semaphore in tuner.c */

    if ( ST_ErrorCode == ST_NO_ERROR )
    {
        ST_ErrorCode = STTUNER_GetTunerInfo(TUNER_Handle, &TUNERInfo);
        if ( ST_ErrorCode == ST_NO_ERROR )
        {
            if ( TUNERInfo.Status != STTUNER_STATUS_LOCKED )
            {
                STTBX_Print(( "TUNERInfo.Status != STTUNER_STATUS_LOCKED\n" ));
                ST_ErrorCode = (ST_ErrorCode_t) STTUNER_EV_SCAN_FAILED; /* failed */
            }
        }
    }
    return( ST_ErrorCode );
}


/*-------------------------------------------------------------------------
 * Function : Decode_Start
 * Input    : Index into Channel and Transponder lists
 * Output   :
 * Return   : only returns on failure
 * ----------------------------------------------------------------------*/
static ST_ErrorCode_t Decode_Start(int Channel, int Transponder)
{
    ST_ErrorCode_t      ST_ErrorCode;
    SERVICE_Display_t   SERVICE_Display;
    SERVICE_Mode_t      SERVICE_Mode;

    #if defined(SELECT_DEVICE_STB5118)
        partition_status_t  partitionStatus;
        U32                 TotalFreeSize;
    #endif

    SERVICE_Display     = LISTS_ChannelList[Channel].Display;
    SERVICE_Mode        = LISTS_TransponderList[Transponder].Mode;

    ST_ErrorCode = AVInfrastucture_Init();
    if (ST_ErrorCode != ST_NO_ERROR)
        return( ST_ErrorCode );

    ST_ErrorCode = AVInfrastucture_Configure( SERVICE_Display, SERVICE_Mode );
    if (ST_ErrorCode != ST_NO_ERROR)
        return( ST_ErrorCode );

    STTBX_Print(( "\nChannel #%d: %s\n", Channel, LISTS_ChannelList[Channel].ChannelName ));

    ST_ErrorCode = RegisterEvents();
    if (ST_ErrorCode != ST_NO_ERROR)
        return( ST_ErrorCode );

    #ifdef AC3_DECODE
        /* Start AC3 Audio on SPDIF*/
        ST_ErrorCode = Decode_StartStream( LISTS_ChannelList[Channel].AudioPid,
                                           AC3,
                                           SERVICE_Display, SERVICE_Mode );
        if (ST_ErrorCode != ST_NO_ERROR)
            return( ST_ErrorCode );
    #else

    /* Start Audio */
        ST_ErrorCode = Decode_StartStream( LISTS_ChannelList[Channel].AudioPid,
                                           LISTS_ChannelList[Channel].AudioType,
                                           SERVICE_Display, SERVICE_Mode );
        if (ST_ErrorCode != ST_NO_ERROR)
            return( ST_ErrorCode );
    #endif /* End of AC3 Mode */



    /* Start Video */
    ST_ErrorCode = Decode_StartStream( LISTS_ChannelList[Channel].VideoPid,
                                       MP1V,
                                       SERVICE_Display, SERVICE_Mode );
    if (ST_ErrorCode != ST_NO_ERROR)
        return( ST_ErrorCode );


    /* PCR */
    ST_ErrorCode = Decode_StartStream( LISTS_ChannelList[Channel].PcrPid, PCR,
                                       SERVICE_Display, SERVICE_Mode );
    if (ST_ErrorCode != ST_NO_ERROR)
        return( ST_ErrorCode );

    #if defined(SELECT_DEVICE_STB5118)
        partition_status(SystemPartition,&partitionStatus,0);
        STTBX_Print(("System Partition Size %d Used %d Free %d\n", partitionStatus.partition_status_size,
        partitionStatus.partition_status_used,partitionStatus.partition_status_free));

        partition_status(NcachePartition,&partitionStatus,0);
        STTBX_Print(("Ncache Partition Size %d Used %d Free %d\n", partitionStatus.partition_status_size,
        partitionStatus.partition_status_used,partitionStatus.partition_status_free));

        STAVMEM_GetFreeSize(AVMEM_DeviceName, &TotalFreeSize);
        STTBX_Print(("AVMEM  Partition Size %d Used %d Free %d\n", AVMEM_SIZE,(AVMEM_SIZE-TotalFreeSize),TotalFreeSize));
    #endif /* end of SELECT_DEVICE_STB5118*/

    #if defined(DEBUG_MODE) /* debug code for testapp1 */
        /* Start Testtool */
        ST_ErrorCode = TST_Start();

        /* Normal application mode */
    #else
        Forever( LISTS_ChannelList[Channel].VideoPid,
                     LISTS_ChannelList[Channel].AudioPid, Transponder, SERVICE_Mode);
    #endif /* End of debug mode */

    return( ST_ErrorCode );
}

/* --------------------------------------------------------------------------- */
/* ---------------------------- support functions ---------------------------- */
/* --------------------------------------------------------------------------- */

/*-------------------------------------------------------------------------
 * Function : AVInfrastucture_Init
 * Input    : none
 * Output   :
 * Return   : Error code
 * ----------------------------------------------------------------------*/
static ST_ErrorCode_t AVInfrastucture_Init(void)
{
    ST_ErrorCode_t ST_ErrorCode;

    ST_ErrorCode = FDMA_Setup();
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = AVMEM_Setup();
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = CLKRV_Setup();

    return( ST_ErrorCode );
}

/*-------------------------------------------------------------------------
 * Function : AVInfrastucture_Configure
 * Input    : display (PAL/NTSC) and TS (DVB/DTV) modes
 * Output   :
 * Return   : Error code
 * ----------------------------------------------------------------------*/
static ST_ErrorCode_t AVInfrastucture_Configure(SERVICE_Display_t SERVICE_Display, SERVICE_Mode_t SERVICE_Mode)
{
    ST_ErrorCode_t ST_ErrorCode;

    PTI_PacketInjectorUsed = PacketInjectorUsed;

    ST_ErrorCode = PTI_Setup( SERVICE_Mode );
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = DENC_Setup( SERVICE_Display );
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = VTG_Setup( SERVICE_Display );
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = LAYER_Setup();
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = VOUT_Setup();
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = VMIX_Setup();
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = VID_Setup();
    if (ST_ErrorCode != ST_NO_ERROR) return ( ST_ErrorCode );

    ST_ErrorCode = AUD_Setup( SERVICE_Mode );

    return( ST_ErrorCode );

⌨️ 快捷键说明

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