📄 play_psfdemux.c
字号:
/* * * Copyright (c) Sigma Designs, Inc. 2002. All rights reserved. * *//** @file play_psfdemux.c @brief sample application for hardware demux of EM86xx @author Aurelia Popa-Radu @ingroup dccsamplecode*/#include "../samples/sample_os.h"#define ALLOW_OS_CODE 1#include "../dcc/include/dcc.h"#include "../samples/common.h"#include "command_ids.h"#include "play_psfdemux_helper.h"#include "psfdemux_common.h"#include "../gbuslib/include/gbus_fifo.h" /* needed for receiving data from DemuxOutput direct from DRAM fifo */#include "../samples/rmttx.h"/* ################## Begin DTCP code ################### */#if (EM86XX_CHIP == EM86XX_CHIPID_TANGO15)#include "../rmdtcp/include/dtcp_session.h"#else#include "../rmdtcpapi/include/dtcp_session.h"#endif/* ############### End DTCP code ####################### *//* to enable or disable the debug messages of this source file, put 1 or 0 below */#if 0#define LOCALDBG ENABLE#else#define LOCALDBG DISABLE#endif#if 0#define CALLDBG ENABLE#else#define CALLDBG DISABLE#endif#define COMMON_TIMEOUT_US (TIMEOUT_10MS)#define FORCE_MONITOR 0#define FORCE_DECRYPTION 1#define NO_FAST_AUDIO_RECOVERY_AFTER_TRICKMODE 0 // only to disable it (enabled by default), otherwise use -far cmdline option#define RM_DEVICES_STC 0x1#define RM_DEVICES_VIDEO 0x2#define RM_DEVICES_AUDIO 0x4#define RM_DEVICES_PSFDEMUX 0x8#define RM_DEVICES_ALL (RM_DEVICES_STC | RM_DEVICES_VIDEO | RM_DEVICES_AUDIO | RM_DEVICES_PSFDEMUX)#define KEYFLAGS (SET_KEY_DISPLAY | SET_KEY_PLAYBACK | SET_KEY_AUDIO | SET_KEY_DEBUG | SET_KEY_SPI)#define DMA_BUFFER_SIZE_LOG2 15 // 32k buffer#define DMA_BUFFER_COUNT 16 // 16*32k = 0x80000 = 0.5M #define DEMUX_FIFO_SIZE (1<<DMA_BUFFER_SIZE_LOG2) * DMA_BUFFER_COUNT // match the dma pool for standalone#define DEMUX_XFER_FIFO_COUNT DMA_BUFFER_COUNT // same as dma pool buffers - this application sends complete buffer every time. #define VIDEO_FIFO_SIZE ( 1792*1024) /* "-vfifo 1792", default same value as in play_demux and play_hwdemux */#define AUDIO_FIFO_SIZE ( 128*1024)#define SPU_FIFO_SIZE ( 104*1024)#define VIDEO_PTS_FIFO_COUNT (512) /* ~8 sec fifo for 60 frames/sec */#define VIDEO_INBAND_FIFO_COUNT (128)#ifdef WITH_MONO#define MAX_TASK_COUNT 1#else#define MAX_TASK_COUNT 3#endif/* ********* IMPORTANT ********* the value of OTHER_DMA_POOL_SIZE must be updated whenever more pools are required. during my tests its value was: 7 pools of 4 buffers of log2size 12 (4KB) = 114688 1 pool of 4 buffers of log2size 15 (32KB) = 131072 total = 245760 also, whenever we open a dmapool, it is allocated by chunks of size '1 << max_dmabuffer_log2_size' (one of mum.o/llad.o params optional parameters) therefore, the above values are: ( assuming max_dmabuffer_log2_size = 18 => (1<<18) = 256KB ) 7 pools = 7 * 256KB 1 pool = 1 * 256KB so we selected OTHER_DMA_POOL_SIZE = 8 * 256KB = 2MB */#define OTHER_DMA_POOL_SIZE (8 * (256 * 1024))#define FILE_PLAYBACK_START_POSITION 0x00000000 // byte position in file from where the playback starts - used for debug/************************************************************************************************Description of the events - masks correspondence: event, module - one event for all tasks mask bit position SOFT_IRQ_EVENT_ERROR, CPUBlock CPU_ERROR_EVENT_MASK bit0 event, module per task mask SOFT_IRQ_EVENT_XFER_RECEIVE_READY, DemuxTask DEMUX_RECEIVE_EVENT_MASK bit1 SOFT_IRQ_XFER_FIFO_READY, DemuxTask DEMUX_SEND_EVENT_MASK bit2, used only in file playback SOFT_IRQ_INBAND_COMMAND, DemuxTask DEMUX_EOS_EVENT_MASK bit2, same mask as send event SOFT_IRQ_INBAND_COMMAND, VideoDecoder VIDEO_EOS_EVENT_MASK bit3, used only in file playback SOFT_IRQ_INBAND_COMMAND, DisplayBlock DISPLAY_EOS_EVENT_MASK bit4, used only in file playback SOFT_IRQ_INBAND_COMMAND, AudioDecoder AUDIO_EOS_EVENT_MASK bit5, used only in file playback SOFT_IRQ_EVENT_DEMUX_SECTION_END, DemuxTask DEMUX_SECTION_EVENT_MASK bit6 SOFT_IRQ_EVENT_FILLING, DemuxTask DEMUX_THRESHOLD_EVENT_MASK bit7*************************************************************************************************//* 7 events = 1demux + 1video + 1display + 1audio for file playback + 1 xfer receive event + 1 section_end event/threshold when we don't use DMA */#define MAX_EVENT_COUNT_PER_TASK 7#define CPU_ERROR_EVENT_MASK (1<<0)#define DEMUX_RECEIVE_EVENT_MASK(i) (1<<(1+0+i*MAX_EVENT_COUNT_PER_TASK))#define DEMUX_SEND_EVENT_MASK(i) (1<<(1+1+i*MAX_EVENT_COUNT_PER_TASK))#define DEMUX_EOS_EVENT_MASK(i) (1<<(1+1+i*MAX_EVENT_COUNT_PER_TASK))#define VIDEO_EOS_EVENT_MASK(i) (1<<(1+2+i*MAX_EVENT_COUNT_PER_TASK))#define DISPLAY_EOS_EVENT_MASK(i) (1<<(1+3+i*MAX_EVENT_COUNT_PER_TASK))#define AUDIO_EOS_EVENT_MASK(i) (1<<(1+4+i*MAX_EVENT_COUNT_PER_TASK))#define DEMUX_SECTION_EVENT_MASK(i) (1<<(1+5+i*MAX_EVENT_COUNT_PER_TASK))#define DEMUX_THRESHOLD_EVENT_MASK(i) (1<<(1+6+i*MAX_EVENT_COUNT_PER_TASK))// av_flags#define VIDEO_PID_FROM_CMDLINE (1 << 0)#define PCR_PID_FROM_CMDLINE (1 << 1)#define AUDIO_PID_FROM_CMDLINE (1 << 2)#define AV_PIDS_ENABLE_FIRST_TIME (1 << 3)#define ECM0_PID_FROM_CMDLINE (1 << 4)#define ECM1_PID_FROM_CMDLINE (1 << 5)#define TTX_PID_FROM_CMDLINE (1 << 6)struct dvb_csa_key arte_dvb_key_table[] = {#ifdef ARTE_DVB_KEY_TABLE#include "keys/arte_dvb_key_table.h"#endif};/* STREAM-4.ts */struct dvb_csa_key stream_dvb_key_table[] = {#ifdef STREAM_DVB_KEY_TABLE#include "keys/stream_dvb_key_table.h"#endif};struct dvb_csa_key cweven_dvb_key_table[] = {#ifdef CWEVEN_DVB_KEY_TABLE#include "keys/cweven_dvb_key_table.h"#endif};struct dvb_csa_key cwodd_dvb_key_table[] = {#ifdef CWODD_DVB_KEY_TABLE#include "keys/cwodd_dvb_key_table.h"#endif}; struct dvb_csa_key ecm1_dvb_key_table[] = {#ifdef ECM1_DVB_KEY_TABLE#include "keys/ecm1_dvb_key_table.h"#endif}; struct dvb_csa_key ecm4_dvb_key_table[] = { /* to prove that ECM parsing is Ok invalidate key_byte_counter and scrambling settings */#ifdef ECM4_DVB_KEY_TABLE#include "keys/ecm4_dvb_key_table.h"#endif};struct dvb_csa_key cwtest_dvb_key_table[] = {#ifdef CWTEST_DVB_KEY_TABLE#define ORIGINAL_CWTEST // for file CWtest.trp//#define DVBCSA_ODD_TAR // for file phat_odd.mpg#include "keys/cwtest_dvb_key_table.h"#endif};/* vgs3.mpg */struct dvb_csa_key vgs3_dvb_key_table[] = { /* to prove that ECM parsing is Ok invalidate key_byte_counter and scrambling settings */#ifdef VGS3_DVB_KEY_TABLE#include "keys/vgs3_dvb_key_table.h"#endif};/* suitei05_KDDI_DRM.m2t */struct aes_key skf_aes_key_table[] = {#ifdef SKF_AES_KEY_TABLE#include "keys/skf_aes_key_table.h"#endif};/* dsodd.ts */struct aes_key dsodd_aes_key_table[] = {#ifdef DSODD_AES_KEY_TABLE#include "keys/dsodd_aes_key_table.h"#endif};/* scrambled.ts */struct aes_key scrambled_aes_key_table[] = {#ifdef SCRAMBLED_AES_KEY_TABLE#define AES_SCRAMBLED_ORIGINAL#include "keys/scrambled_aes_key_table.h"#endif};/* dscps.ts */struct aes_key dscps_aes_key_table[] = {#ifdef DSCPS_AES_KEY_TABLE#include "keys/dscps_aes_key_table.h"#endif};/* aes cbc+ofb keys for transport/mpeg2/Confidential/AES/11-7 */struct aes_key aes_cbc_ofb_key_table[] = {#ifdef AES_CBC_OFB_KEY_TABLE#define AES_CBC_OFB_HARDCODED_KEY//#define AES_KEY_1107//#define AES_KEY_SCR1111//#define AES_KEY_SCR1112#include "keys/aes_cbc_ofb_key_table.h"#endif};/* aes ecb keys (clear partial block) for transport/mpeg2/HD_underwater_encrypted.ts */struct aes_key aes_ecb_key_table[] = {#ifdef AES_ECB_KEY_TABLE#define AES_KEY_ICE_UNDER_CEMA//#define AES_KEY_TSDAT#include "keys/aes_ecb_key_table.h"#endif};/* aes nsa keys transport/mpeg2/Confidential/NSA/4fixed/scrambled/4FixedEcm_Ntsc_188_NSA.mpg */struct aes_key aes_nsa_key_table[] = {#ifdef AES_NSA_KEY_TABLE#define AES_NSA_4_FIXED#include "keys/aes_nsa_key_table.h"#endif};/* ############## AES_CBC_PRECIPHER TEST CODE BEGIN ############## *//* hardcoded keys for pre-encrypted test files (ex: mummy.2keys.800000.aes.m2t) */struct aes_2keys_test precipher_aes_key_table[] = {#ifdef PRECIPHER_AES_KEY_TABLE#include "keys/precipher_aes_key_table.h"#endif};/* ############## AES_CBC_PRECIPHER TEST CODE END ############### */struct dvb_arib_key arib_key_table[] = {#ifdef MULTI2_EIGHT_KEYS#define ARIB_KEY_TABLE#define MULTI2_STREAM_8_ECM#endif#ifdef ARIB_KEY_TABLE#define MULTI2_U17_TVSIZUOKA//#define MULTI2_TR27_ECM//#define MULTI2_TR26_ECM_X2//#define MULTI2_ARIB_STREAM_1_TO_7//#define ARIB_orig#include "keys/arib_key_table.h"#endif};static const RMuint8 HARDCODED_RECIPHER_ODD_KEY[] = { 0xEA, 0x0C, 0xC2, 0xAA, 0xFE, 0x98, 0x46, 0xB8, 0x9A, 0xA0, 0xC2, 0xA0, 0xBC, 0x24, 0x1A, 0xB2 };//{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };//{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };//{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };static const RMuint8 HARDCODED_RECIPHER_EVEN_KEY[] = { 0xEA, 0x0C, 0xC2, 0xAA, 0xFE, 0x98, 0x46, 0xB8, 0x9A, 0xA0, 0xC2, 0xA0, 0xBC, 0x24, 0x1A, 0xB2 };//{ 0xAA, 0xC2, 0x0C, 0xEA, 0xB8, 0x46, 0x98, 0xFE, 0xA0, 0xC2, 0xA0, 0x9A, 0xB2, 0x1A, 0x24, 0xBC };//{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };//{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };static const RMuint8 HARDCODED_RECIPHER_IV[] = { 0xA8, 0xF6, 0x7F, 0xD7, 0x53, 0x67, 0x64, 0x79, 0xBD, 0xCA, 0x94, 0x13, 0xB7, 0xB1, 0xB6, 0xBE };//{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };//{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };static RMstatus HwPlay(struct context_per_task *context);static RMstatus HwStop(struct context_per_task *context);static RMstatus OpenVideoDecoder(struct context_per_task *context);static RMstatus Play(struct context_per_task *pContext, RMuint32 devices, enum DCCVideoPlayCommand mode);static RMstatus Stop(struct context_per_task *pContext, RMuint32 devices);static RMstatus Pause(struct context_per_task *pContext, RMuint32 devices);static RMstatus ProcessKey(void);static void printTimeOfDay(struct timeval now){ RMuint64 secondsPerMinute = 60; RMuint64 secondsPerHour = 60 * secondsPerMinute; RMuint64 secondsPerDay = 24 * secondsPerHour; RMuint64 today, h, m; today = (now.tv_sec - ((now.tv_sec / secondsPerDay) * secondsPerDay)); h = today / secondsPerHour; today -= h * secondsPerHour; m = today / secondsPerMinute; today -= m * secondsPerMinute; fprintf(stderr, "time is %02llu:%02llu:%02llu.%llu\n", h, m, today, (RMuint64)now.tv_usec);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -