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

📄 play_psfdemux_multicast.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * * 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 "../rmlibcw/include/rmsocket.h"// this will add a field to the context, see psfdemux_common.h#define MULTICAST 1 #define MAX_MULTICAST_STREAMS 10#include "psfdemux_common.h"/**************************** macros ******************************/#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	32	// 32 * 32k = 0x200000 = 1M #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 DUMP_SOCKET_DATA	0#define	FORCE_DECRYPTION	1#define SOCKET_BLOCKING_READ_SLEEP 3000//#define AUTO_CHANGE_CHANNEL#ifdef WITH_MONO#define MAX_TASK_COUNT		1#else#define MAX_TASK_COUNT		3#endif#define MAX_EVENT_COUNT_PER_TASK     5 /* 4 events (demux, video, display, audio) for file playback and 1 receive event per task */#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 VIDEO_PID_FROM_CMDLINE    1#define PCR_PID_FROM_CMDLINE      2#define AUDIO_PID_FROM_CMDLINE    4#define AV_PIDS_ENABLE_FIRST_TIME 8#define LOOP_KEY_TABLE /* Allow the Key table to loop when it reaches the end */#if defined(WITH_AACS)#define MAX_SP			6#define PACKET_SIZE		192#define AACS_IBC_CMD_MT		2#define AACS_IBC_CMD_PLAY_ITEM  4#endif/* 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#endifstruct dvb_csa_key arte_dvb_key_table[] = {	{ TRUE, 0, EMhwlibScramblingBits_10, { 0xfc, 0x32, 0x54, 0x76, 0x94, 0xba, 0xdc, 0xfe },	 { 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00},	  ECM0_SECTION_ENTRY }, /* arte key starts from LSB (byte 0) */};struct dvb_csa_key cweven_dvb_key_table[] = {	{ FALSE, 0xffffffff, EMhwlibScramblingBits_None, { 0x34, 0x18, 0x3c, 0xe0, 0x41, 0xc2, 0x03, 0x7c },	 { 0x00, 0x00, 0x00, 0x00, 0x91, 0x01, 0x02, 0x05, 0xFF, 0x02, 0x00, 0x17, 0x14, 0x00, 0x6E, 0x26}, },};struct dvb_csa_key cwodd_dvb_key_table[] = {	{ FALSE, 0xffffffff, EMhwlibScramblingBits_None, { 0x7e, 0x7e, 0x00, 0x00, 0xc8, 0x03, 0xc6, 0xff },	 { 0x00, 0x00, 0x00, 0x00, 0x91, 0x01, 0x02, 0x05, 0xFF, 0x02, 0x00, 0x17, 0x15, 0x00, 0x8F, 0x26}, },};	struct dvb_csa_key ecm1_dvb_key_table[] = {	{ TRUE, 0, EMhwlibScramblingBits_11, { 0x8b, 0xbe, 0xba, 0x13, 0x69, 0xb2, 0xfb, 0xbc },	 { 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00},	  ECM0_SECTION_ENTRY }, /* 1ECM key starts from LSB (byte 0) */};struct dvb_csa_key ecm4_dvb_key_table[] = {	/* to prove that ECM parsing is Ok invalidate key_byte_counter and scrambling settings */	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, /*0x00000000, EMhwlibScramblingBits_10,*/ { 0x5e, 0x2d, 0x29, 0x08, 0xbd, 0x2d, 0x61, 0x2f },	 { 0x00, 0x02, 0x2D, 0x5E, 0xE4, 0x00, 0x49, 0x15, 0x09, 0x04, 0x00, 0x00, 0x01, 0x4D, 0x04, 0x4E}, }, /* 4ECM key starts from LSB (byte 0) */	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, /*0x00E3F3F0, EMhwlibScramblingBits_11,*/ { 0x5c, 0x2c, 0x28, 0x08, 0xba, 0x2c, 0x60, 0x2e },	 { 0x00, 0x02, 0x2C, 0x5C, 0xE4, 0x00, 0x45, 0x15, 0x09, 0x04, 0x00, 0x00, 0x01, 0x4D, 0x04, 0x4E}, },	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, /*0x01E61c00, EMhwlibScramblingBits_10,*/ { 0x62, 0x2f, 0x2b, 0x08, 0xbf, 0x2f, 0x63, 0x2d },	 { 0x00, 0x02, 0x2F, 0x62, 0xE4, 0x00, 0x51, 0x15, 0x09, 0x04, 0x00, 0x00, 0x01, 0x4D, 0x04, 0x4E}, },	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, /*0x02e56880, EMhwlibScramblingBits_11,*/ { 0x60, 0x2e, 0x2a, 0x08, 0xbc, 0x2e, 0x62, 0x2c },	 { 0x00, 0x02, 0x2E, 0x60, 0xE4, 0x00, 0x4D, 0x15, 0x09, 0x04, 0x00, 0x00, 0x01, 0x4D, 0x04, 0x4E}, },};struct dvb_csa_key vgs3_key_table[] = {	/* to prove that ECM parsing is Ok invalidate key_byte_counter and scrambling settings */	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, { 0x7A, 0x03, 0xFF, 0x78, 0x74, 0x80, 0x01, 0xF3},	 { 0x00, 0x00, 0x00, 0x00, 0x91, 0x01, 0x02, 0x05, 0xFF, 0x02, 0x00, 0x17, 0x64, 0x00, 0xBA, 0x26}, }, /* vgs3 key starts from LSB (byte 0) */	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, { 0x8B, 0x3F, 0x0E, 0x3E, 0x7E, 0x00, 0x78, 0x06},	 { 0x00, 0x00, 0x00, 0x00, 0x91, 0x01, 0x02, 0x05, 0xFF, 0x02, 0x00, 0x17, 0x65, 0x00, 0xC0, 0x26}, },	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, { 0x20, 0x60, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00},	 { 0x00, 0x00, 0x00, 0x00, 0x91, 0x01, 0x02, 0x05, 0xFF, 0x02, 0x00, 0x17, 0x66, 0x00, 0xC6, 0x26}, },	{  FALSE, 0xffffffff, EMhwlibScramblingBits_None, { 0xAF, 0x00, 0xE0, 0xCF, 0xF8, 0x00, 0x00, 0xF8},	 { 0x00, 0x00, 0x00, 0x00, 0x91, 0x01, 0x02, 0x05, 0xFF, 0x02, 0x00, 0x17, 0x67, 0x00, 0xCC, 0x26}, },};static RMstatus HwPlay(struct context_per_task *context);static RMstatus HwStop(struct context_per_task *context);	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);}#define GET_DATA_FIFO_INFO(pRUA, ModuleId, checkStarvation)		\	{								\		struct DataFIFOInfo DataFIFOInfo;			\		RMreal fullness;					\		RUAGetProperty(pRUA, ModuleId, RMGenericPropertyID_DataFIFOInfo, &DataFIFOInfo, sizeof(DataFIFOInfo)); \		fullness = (RMreal)((100./DataFIFOInfo.Size)*DataFIFOInfo.Readable); \		fprintf(stderr, "Data %lx: st=%08lx sz=%ld wr=%ld rd=%ld --> f : %.02f\n", ModuleId, DataFIFOInfo.StartAddress,	\			DataFIFOInfo.Size, DataFIFOInfo.Writable,  DataFIFOInfo.Readable, fullness); \		if ((fullness < 2) && checkStarvation) {		\			struct timeval now;				\									\			gettimeofday(&now, NULL);			\			RMDBGLOG((ENABLE, "close to starvation at\n")); \			printTimeOfDay(now);				\		}							\	}								\#define GET_XFER_FIFO_INFO(pRUA, ModuleId, checkStarvation)		\	{								\		struct XferFIFOInfo_type XferFIFOInfo;			\		RMreal fullness;					\		RUAGetProperty(pRUA, ModuleId, RMGenericPropertyID_XferFIFOInfo, &XferFIFOInfo, sizeof(XferFIFOInfo)); \		fullness = (RMreal)((100./XferFIFOInfo.Size)*XferFIFOInfo.Readable); \		fprintf(stderr, "XFER %lx: st=%08lx sz=%ld wr=%ld rd=%ld er=%lx --> f : %.02f	\n", ModuleId, XferFIFOInfo.StartAddress, \			XferFIFOInfo.Size, XferFIFOInfo.Writable,  XferFIFOInfo.Readable, XferFIFOInfo.Erasable, fullness); \		if ((fullness < 2) && checkStarvation) {		\			struct timeval now;				\									\			gettimeofday(&now, NULL);			\			RMDBGLOG((ENABLE, "close to starvation at\n")); \			printTimeOfDay(now);				\		}							\	}								\#define MONITOR_INTERVAL_US 250000static void monitor(struct context_per_task *context, RMbool alwaysShow){		/* the bitrate reading of this probe is accurate only if the blocking call is RUASendData */	struct timeval now;		static struct timeval last;		static int first = 1;	RMuint64 elapsed; 		RMuint64 ptime; 		struct dcc_context *dcc_info = context->dcc_info;	gettimeofday(&now, NULL);	elapsed = (now.tv_sec - last.tv_sec) * 1000000;			elapsed += (now.tv_usec - last.tv_usec);	if (elapsed > MONITOR_INTERVAL_US || first || alwaysShow){		RMuint64 bitrate = (RMuint64)context->bitrate * 1000000;		bitrate /= elapsed;		context->meanBitrate += bitrate;		context->meanCount++;		DCCSTCGetTime(dcc_info->pStcSource, &ptime, 90000);					fprintf(stderr, "\n*****************************\n");		fprintf(stderr, "timeofday %llu.%llu secs since epoch\n", (RMuint64)now.tv_sec, (RMuint64)now.tv_usec);		printTimeOfDay(now);		fprintf(stderr, "STC = %llu (%llu secs)\n", ptime, (ptime/90000));				fprintf(stderr, "socket read speed %llu bytes/sec (%llu bits/sec), readTime %llu tries %lu\n", 			context->readSpeed, 			context->readSpeed * 8,			context->readTime, 			context->tries);		context->readSpeed = 0;		context->readTime = 0;		context->tries = 0;		fprintf(stderr, "Demux :\n"); 		GET_DATA_FIFO_INFO(dcc_info->pRUA, context->demux_task, FALSE);		GET_XFER_FIFO_INFO(dcc_info->pRUA, context->demux_task, FALSE);		fprintf(stderr, "bitrate: mean %llu bit/sec, pseudo-instantaneus %llu bit/sec (%lu bytes/%llu us)\n", 			context->meanBitrate / context->meanCount,			bitrate, 			context->bitrate >> 3, 			elapsed);		fprintf(stderr, "Video :\n"); 					GET_DATA_FIFO_INFO(dcc_info->pRUA, dcc_info->video_decoder, TRUE);		GET_XFER_FIFO_INFO(dcc_info->pRUA, dcc_info->video_decoder, TRUE);					fprintf(stderr, "Audio :\n"); 					GET_DATA_FIFO_INFO(dcc_info->pRUA, dcc_info->audio_decoder, TRUE);		GET_XFER_FIFO_INFO(dcc_info->pRUA, dcc_info->audio_decoder, TRUE);		fprintf(stderr, "*****************************\n");					gettimeofday(&last, NULL);		first = 0;		context->bitrate = 0;		fflush(stderr);			}					        	return;}/****************************** global variables ******************************//* these should be made local */static RMuint32			task_count = 0;static struct dcc_context       *pdcc_info[MAX_TASK_COUNT];static struct context_per_task	Tasks[MAX_TASK_COUNT] = {{0,},}; static struct RM_PSM_Context    PSMcontext;static RMuint32			output_count_per_task;static RMuint32			idle_port = 0xff;static RMbool			timedbg = FALSE;enum AudioDecoder_Codec_type    stream_type_6 = AudioDecoder_Codec_DTS;#ifndef WITH_MONO/* these can stay global as they are only used by the standalone play_psfdemux app */static RMbool			load_ucode = TRUE;static struct playback_cmdline  playback_options[MAX_TASK_COUNT]; static struct display_cmdline   display_options[MAX_TASK_COUNT]; static struct video_cmdline     video_options[MAX_TASK_COUNT]; static struct audio_cmdline     audio_options[MAX_TASK_COUNT]; static struct demux_cmdline     demux_options[MAX_TASK_COUNT]; static struct display_context   disp_info[MAX_TASK_COUNT]; static struct dh_context        dh_info[MAX_TASK_COUNT] = {{0,},}; #endifstatic RMbool global_dump_socket_data = FALSE;#if DUMP_SOCKET_DATAstatic FILE *global_saveFile[MAX_TASK_COUNT];#endifstatic RMstatus InitPidTablePerTask(struct context_per_task *context){	RMstatus err;	RMuint32 i;	RMDBGLOG((CALLDBG, "initPIDTablePerTask (context @0x%08lx)\n", (RMuint32)context));#ifdef USE_HW_FIXED_PID_ENTRY	/* set the fixed Pid entries available only for EM8634 */	struct EMhwlibFixedPidEntry_type fixed_entry;	struct EMhwlibOutputMask_type out;	RMuint32 dummy;		RMDBGLOG((CALLDBG, "initPIDTablePerTask - useHWFixedPIDEntry\n"));	/* PAT */	fixed_entry.input_type = EMhwlibPid_Ts;	fixed_entry.flags = TS_FLAGS;	err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_PATPidEntry, &fixed_entry, sizeof(fixed_entry), 0);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "InitPidTablePerTask Error RMDemuxTaskPropertyID_PATPidEntry"));		return err;	}	out.output_mask[0] = PAT_OUTPUT_MASK;	err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_PATPidEntryAddOutputs, &out, sizeof(out), 0);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "InitPidTablePerTask Error RMDemuxTaskPropertyID_PATPidEntryAddOutputs"));		return err;

⌨️ 快捷键说明

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