📄 exolmpegts.c
字号:
/*
* Copyright (c) 2004, 2005 Koninklijke Philips Electronics N V. Includes code
* copyright (c) 2004 by VCom Electronics Inc; copyright transferred by verbal
* agreement between Tim Meakin and Jonathan Coxhead, November 2004. All rights
* reserved.
*
* This source code and any compilation or derivative thereof is the proprietary
* information of Koninklijke Philips Electronics N V and is confidential in
* nature. Under no circumstances is this software to be exposed to or placed
* under an Open Source License of any type without the express written
* permission of Koninklijke Philips Electronics N V.
*
* #############################################################################
*
* Module: %name: exolMpegTs.c % %version: 1 %
*
* %date_created: Fri Mar 11 12:34:55 2005 % %created_by: jcoxhead %
*
* %date_modified: Fri Jun 14 11:31:56 2002 %
*
* #############################################################################
*/
/*
* DESCRIPTION: Transport Stream Demux Task
*
* NOTES: See figure below.
*
* |---------------------------> PSI Data----->
* |
* |
* | |--> User Data---->
* | |
* |--> Video--> VdecMpeg-->|
* | |
* | |--> VrendGfxVo--->
* |
* Fread/FGPI--> MpegTs--> |
* (Transport |
* Stream) | |--> AdecAc3-->|
* | | |
* |--> Audio--> . or |--> ArendAO-->
* (Main) | |
* |--> AdecMp3-->|
*
*
* --------------------------------------------------------------------------
*/
#define AVSYNC // needed by "tmolFgpiWrapper.h"
#include "exolMpegTS.h"
#include <ops/custom_defs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sys_conf.h"
#include <tmml.h>
#include <tmMainStreaming.h>
#include <tmosal.h>
#include <tmDbg.h>
#include <tmVideoMode.h>
#include <tmolArendAO.h>
#include <tmolVrendGfxVo.h>
#include <tmhwVdiVdoRout.h>
#include <tmolAdecMp3.h>
#include <tmolVdecMpeg.h>
#include <tsaClock.h>
#include <tmArith.h>
#include <mmio.h>
#include <tmVencAna.h>
#include <tmbslVencAna.h>
#include <tmolFgpiWrapper.h>
#include <tmolFread.h>
#include <tmolAdecAc3.h>
#include <tmolDemuxMpegTS.h>
#if TMFL_NEED_TIME_DOCTOR
#include <tmtdCommon.h>
#include <tmtdApi.h>
#include <tmtdOsal.h>
#endif
#include "watchdog.h"
#include "psi_task.h"
#include "user_data_task.h"
#include "private_data_task.h"
//---------------------------------------------------------------------------
// Defines and Macros
//---------------------------------------------------------------------------
#define STORE_DEBUG_IN_RAM 0
#define DEFAULT_PATH "c:\\"
#define DEFAULT_INFILE "in.trp"
#define DEFAULT_USER_DATA_OUTFILE "user_data.dat"
#define DEFAULT_PSI_DATA_OUTFILE "psi.dat"
#define INPUT_TO_DEMUX_BUFFER_SIZE (((16 * KB) / TP_PACKET_LENGTH) * TP_PACKET_LENGTH)
#define NROF_INPUT_TO_DEMUX_PACKETS 100
#define NROF_DEMUX_TO_VDEC_BUFFERS 20
#define NROF_DEMUX_TO_VDEC_PACKETS 25
#define NROF_DEMUX_TO_ADEC_PACKETS 50
#define NROF_DEMUX_TO_PSI_PACKETS 30
#define NROF_VDEC_TO_VREND_PACKETS (20 * 2)
#define NROF_VDEC_TO_VREND_BUFFERS 3
#define NROF_VDEC_USER_DATA_PACKETS (NROF_VDEC_TO_VREND_PACKETS * 6)
#define VDEC_USER_DATA_BUF_SIZE (1 * KB)
#define DEMUX_STACKSIZE (100 * KB)
#define ABOVE_LIMIT_BITRATE 1500
#define DTS_THRESHOLD ((Int)(frequency / gFrameRate))
#define SMALL_STACK_SIZE 4096
#define MAX_BUFFERS_PER_PACKET 200
#define FRAME_STRIDE 768
#define FRAME_HEIGHT 576
#define MAX_IMAGE_BUF_SIZE (FRAME_STRIDE * FRAME_HEIGHT)
#define PLL1_CTL 0x00047004
#define DDS1_CTL 0x00047014
#define DDS2_CTL 0x00047018
#define DDS3_CTL 0x0004701C
#define DDS8_CTL 0x00047030
#define QVCP_CLK_OUT 0x00047200
#define QVCP_CLK_PIX 0x00047204
#define QVCP_CLK_PROC 0x00047208
#define CLK_FGPO_CTL 0x00047414
#define CLK_FGPI_CTL 0x00047418
#define RESET_CTL 0x00060000
#define VDI_MODE 0x00063000
#define VDO_MODE 0x00063004
#define LCD_CTL 0x00073000
#define GPIO_MODE_CONTROL3 0x0010400C
#define DEFAULT_MP3_AUDIO_PID 0xC0
#define SYNC_LOCK_THRESHOLD_AC3 20000
#define SYNC_UNLOCK_THRESHOLD_AC3 20000
#define SYNC_LOCK_THRESHOLD_MP3 2000
#define SYNC_UNLOCK_THRESHOLD_MP3 2000
#define SYNC_DELAY (12000 + 30000) // End-to-end time from packet arrival (before demuxing) to rendering
#define BAD_TIMESTAMP_THRESHOLD 48000
#define DTS_SYNC_DELAY 2000 // Time from packet arrival to decoding
#define PRI_BASE 10
#define PSI_DATA_TASK_PRIORITY (PRI_BASE)
#define USER_DATA_TASK_PRIORITY (PRI_BASE)
#define WATCHDOG_TASK_PRIORITY (PRI_BASE)
#define VDEC_PRIORITY (PRI_BASE + 20)
#define VREND_PRIORITY (PRI_BASE + 53) // Must be set to 63
#define DEMUX_PRIORITY (PRI_BASE + 10)
#define AREND_PRIORITY (PRI_BASE + 40)
#define ADEC_MP3_PRIORITY (PRI_BASE + 40)
#define NROF_ADEC_TO_AREND_PACKETS (12 * 2)
#define PRIVATE_DATA_TASK_PRIORITY (PRI_BASE)
#define DEFAULT_PRIVATE_DATA_OUTFILE "private_data.dat"
#define NROF_DEMUX_TO_PRIVATE_DATA_PACKETS 30
#define FGPI_PRIORITY (PRI_BASE + 50) // Not used
#define FGPI_RECORD_SIZE TP_PACKET_LENGTH
#define FREAD_PRIORITY (PRI_BASE)
#define ADEC_AC3_PRIORITY (PRI_BASE + 40)
#define DEFAULT_AC3_AUDIO_PID 0x80
#define AC3_STACKSIZE (8 * KB)
DBG_UNIT (dbgTsDemux)
//---------------------------------------------------------------------------
// Type Definitions
//---------------------------------------------------------------------------
typedef enum
{
AC3_AUDIO_STREAM = 1,
MP3_AUDIO_STREAM = 2
} Audiostream_t;
typedef struct
{
ptsaInOutDescriptor_t TsDemuxToVdecIoDescriptor;
ptsaInOutDescriptor_t TsDemuxToMainAdecIoDescriptor;
ptsaInOutDescriptor_t TsDemuxPsiDataIoDescriptor;
ptsaInOutDescriptor_t VdecToVrendGfxVoIoDescriptor;
ptsaInOutDescriptor_t VdecUserDataIoDescriptor;
ptsaInOutDescriptor_t AdecToArendIoDescriptor;
ptsaInOutDescriptor_t FgpiToTsDemuxIoDescriptor;
ptsaInOutDescriptor_t FreadToTsDemuxIoDescriptor;
ptsaInOutDescriptor_t TsDemuxPrivateDataIoDescriptor;
} IoDescripts_s, *pIoDescripts_s;
typedef struct // Fast General Purpose Input (FGPI) component
{
Int FgpiInst; // Component instance
ptmolFgpiWrapperCapabilities_t FgpiCap; // Component capability
ptmolFgpiWrapperInstanceSetup_t FgpiSetup; // Component setup structure
ptsaControlDescriptor_t FgpiControl; // Control descriptor variable
tmosalSemHandle_t FgpiEndOfStreamSema; // Semaphore
tmosalSemHandle_t FgpiStopCompletedSema; // Semaphore
} FgpiInst_s, *pFgpiInst_s;
typedef struct // File Reader component
{
Int FreadInst; // Component instance
ptmolFreadCapabilities_t FreadCap; // Component capability
ptmolFreadInstanceSetup_t FreadSetup; // Component setup structure
ptsaControlDescriptor_t FreadControl; // Control descriptor variable
tmosalSemHandle_t FreadEndOfStreamSema; // Semaphore
tmosalSemHandle_t FreadStopCompletedSema; // Semaphore
} FreadInst_s, *pFreadInst_s;
typedef struct // MPEG Video Decoder component
{
Int VdecMpegInst; // Component instance
ptmolVdecMpegCapabilities_t VdecMpegCap; // Component capability
ptmolVdecMpegInstanceSetup_t VdecMpegSetup; // Component setup structure
ptsaControlDescriptor_t VdecMpegControl; // Control descriptor variable
tmosalSemHandle_t VdecMpegEndOfStreamSema; // Semaphore
tmosalSemHandle_t VdecMpegStopCompletedSema; // Semaphore
} VdecMpegInst_s, *pVdecMpegInst_s;
typedef struct // Dolby AC3 Audio Decoder component
{
Int AdecAc3Inst; // Component instance
ptmAdecAc3Capabilities_t AdecAc3Cap; // Component capability
ptmolAdecAc3InstanceSetup_t AdecAc3Setup; // Component setup structure
ptsaControlDescriptor_t AdecAc3Control; // Control descriptor variable
tmosalSemHandle_t AdecAc3EndOfStreamSema; // Semaphore
tmosalSemHandle_t AdecAc3StopCompletedSema; // Semaphore
} AdecAc3Inst_s, *pAdecAc3Inst_s;
typedef struct // MPEG Audio Decoder component
{
Int AdecMp3Inst; // Component instance
ptmolAdecMP3Capabilities_t AdecMp3Cap; // Component capability
ptmolAdecMP3InstanceSetup_t AdecMp3Setup; // Component setup structure
ptsaControlDescriptor_t AdecMp3Control; // Control descriptor variable
tmosalSemHandle_t AdecMp3EndOfStreamSema; // Semaphore
tmosalSemHandle_t AdecMp3StopCompletedSema; // Semaphore
} AdecMp3Inst_s, *pAdecMp3Inst_s;
typedef struct // Audio Renderer component
{
Int ArendAoInst; // Component instance
ptmolArendAOCapabilities_t ArendAoCap; // Component capability
ptmolArendAOInstanceSetup_t ArendAoSetup; // Component setup structure
ptsaControlDescriptor_t ArendAoControl; // Control descriptor variable
tmosalSemHandle_t ArendAoEndOfStreamSema; // Semaphore
tmosalSemHandle_t ArendAoStopCompletedSema; // Semaphore
} ArendAoInst_s, *pArendAoInst_s;
typedef struct // Video Renderer component
{
Int VrendGfxVoInst; // Component instance
ptmolVrendGfxVoCapabilities_t VrendGfxVoCap; // Component capability
ptmolVrendGfxVoInstanceSetup_t VrendGfxVoSetup; // Component setup structure
ptsaControlDescriptor_t VrendGfxVoControl; // Control descriptor variable
tmosalSemHandle_t VrendGfxVoEndOfStreamSema; // Semaphore
tmosalSemHandle_t VrendGfxVoStopCompletedSema; // Semaphore
} VrendGfxVoInst_s, *pVrendGfxVoInst_s;
typedef struct // MPEG Transport Stream Demux component
{
Int DemuxMpegTsInst; // Component instance
ptmolDemuxMpegTsCapabilities_t DemuxMpegTsCap; // Component capability
ptmolDemuxMpegTsInstanceSetup_t DemuxMpegTsSetup; // Component setup structure
ptsaControlDescriptor_t DemuxMpegTsControl; // Control descriptor variable
tmosalSemHandle_t DemuxMpegTsEndOfStreamSema; // Semaphore
tmosalSemHandle_t DemuxMpegTsStopCompletedSema; // Semaphore
} DemuxMpegTsInst_s, *pDemuxMpegTsInst_s;
typedef struct // Analog Video Encoder component
{
ptmVencAna_t VencAnaInst; // Component instance
tmosalSemHandle_t VencAnaSema; // Semaphore
} VencAnaInst_s, *pVencAnaInst_s;
//---------------------------------------------------------------------------
// Global Shared Data
//---------------------------------------------------------------------------
static tmAvFormat_t gDemuxInputFormat =
{
sizeof( gDemuxInputFormat ), // size
0, // hash
0, // referenceCount
avdcSystem, // dataClass
stfMPEG2Transport // dataType
};
tmosalSemHandle_t tmalSyncPsiSema = 0;
Bool bKillPsiDataTask = False;
Bool bKilluserDataTask = False;
Bool bKillWatchDogTask = False;
Bool bKillPrivateDataTask = False;
//---------------------------------------------------------------------------
// Global Data
//---------------------------------------------------------------------------
static tmAvFormat_t gDemuxVideoOutputFormat =
{
sizeof (tmAvFormat_t), // size
0, // hash
0, // referenceCount
avdcVideo, // dataClass
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -