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

📄 mono.c

📁 1. 8623L平台
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#define ALLOW_OS_CODE 1#include <sys/types.h>#include "../samples/common.h"#include "../samples/command_ids.h"#include "rmlocalremote.h"#include "../rmremoteapi/include/rmremoteapi.h"#include "../rmrtk/include/rmrtk.h"/* #### Begin CARDEA code #### */#include "rmupnp/rmlibwmdrmnd/include/ms_cardea.h"/* #### End CARDEA code #### *//* #### 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 #### */#include "mono.h"#if 1#define MONODBG ENABLE#else#define MONODBG DISABLE#endif#define MAX_DIR_RECURSION 8#define SRM_SIZE 5 * 1024#define SRM_PATH "/mnt/sigma/hdcp.srm"#define ERROR_CLEANUP(i)	do { error = (i); goto cleanup; }  while(0)struct dcc_context dcc_info = {0,};// callback for the application to receive dcc contextvoid RMDCCInfo(struct dcc_context *dcc_info){	RMDBGLOG((ENABLE, "got dcc info @ 0x%08lx\n", (RMuint32) dcc_info));	// nothing to do for mono}// callback to pass stream information to the application, DRM protected, number of chapters, etcvoid RMFileStreamInfoCallback(struct RMFileStreamInfo *streamInfo){	// nothing to do for mono	RMDBGLOG((ENABLE, "got stream info!\n"));}RM_EXTERN_C_BLOCKSTARTvoid RMremoteResetState(void);void setMonoAuto(void);RM_EXTERN_C_BLOCKENDstatic struct playback_cmdline play_opt;static struct display_cmdline disp_opt;static struct video_cmdline video_opt;static struct demux_cmdline demux_opt;struct mono_context mono_opt;static RMdirectory directory[MAX_DIR_RECURSION];static RMascii path[256];static RMuint32 path_index[MAX_DIR_RECURSION];/* returns TRUE to play the file and FALSE to skip it */static RMascii *filename;static RMascii *remote_dev;RMremoteHandle rh = (RMremoteHandle) NULL;RMbool osd_enabled = FALSE;#if 0 // 8 bits color#define INFO_FACE_FOREGROUND_COLOR 0x2a#define INFO_FACE_BACKGROUND_COLOR 0x00#define DATA_FACE_FOREGROUND_COLOR 0x15#define DATA_FACE_BACKGROUND_COLOR 0x00#define MONO_DEFAULT_RECT_FORGROUND_COLOR 0x00#else // true color#define INFO_FACE_FOREGROUND_COLOR 0xff555555#define INFO_FACE_BACKGROUND_COLOR 0xff000000#define DATA_FACE_FOREGROUND_COLOR 0xff808080#define DATA_FACE_BACKGROUND_COLOR 0xff000000#define MONO_DEFAULT_RECT_FORGROUND_COLOR 0xff000000#endifstatic RtkProp info_face ={	scale: 24,	fgColor: INFO_FACE_FOREGROUND_COLOR,	bgColor: INFO_FACE_BACKGROUND_COLOR,};static RtkProp data_face ={	scale: 32,	fgColor: DATA_FACE_FOREGROUND_COLOR,	bgColor: DATA_FACE_BACKGROUND_COLOR,};/* this is the EOS callback, must be implemented by curacao */void RMEOSCallback(){	/* mono doesnt do anything */	RMDBGLOG((ENABLE, "RMEOSCallback() called, awaiting a command\n"));	RMDBGLOG((ENABLE, "reset remote state to playing\n"));	RMremoteResetState();	}// Write SRM to non-volatile memory or other persistent storagestatic RMstatus Write_SRM(RMuint8 *pSRM, RMuint32 Size) {	RMstatus err = RM_OK;	RMfile fd;	RMnonAscii *naname;	RMuint32 size;		// read /mnt/sigma/hdcp.srm	RMDBGLOG((ENABLE, "Writing new SRM file to non-volatile memory at %s\n", SRM_PATH));	naname = RMnonAsciiFromAscii(SRM_PATH);	fd = RMOpenFile(naname, RM_FILE_OPEN_WRITE);	RMFreeNonAscii(naname);	if (fd) {		err = RMWriteFile(fd, pSRM, Size, &size);		RMCloseFile(fd);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Error, could not write persistent SRM file!\n"));			err = RM_ERROR;		} else {			if (Size != size) err = RM_ERROR;		}	} else {		RMDBGLOG((ENABLE, "Error: could not open persistent SRM file for writing\n"));		err = RM_ERROR;	}		return err;}// Read SRM from non-volatile memory or other persistent storagestatic RMstatus Read_SRM(RMuint8 *pSRM, RMuint32 *pSize) {	RMstatus err;	RMfile fd;	RMnonAscii *naname;	RMuint32 size, max_size = SRM_SIZE;	static const RMuint8 SRM_empty[] = {		0x80, 0x00, 0x00, 0x01,  // version		0x00, 0x00, 0x00, 0x2b,  // length		// no keys		// "DCP LLC" production DSS signature		0xd2, 0x48, 0x9e, 0x49, 0xd0, 0x57, 0xae, 0x31, 		0x5b, 0x1a, 0xbc, 0xe0, 0x0e, 0x4f, 0x6b, 0x92, 		0xa6, 0xba, 0x03, 0x3b, 0x98, 0xcc, 0xed, 0x4a, 		0x97, 0x8f, 0x5d, 0xd2, 0x27, 0x29, 0x25, 0x19, 		0xa5, 0xd5, 0xf0, 0x5d, 0x5e, 0x56, 0x3d, 0x0e 	};		// note max data size	if (pSize && *pSize) max_size = *pSize;	size = 0;		// read /mnt/sigma/hdcp.srm	RMDBGLOG((ENABLE, "Reading current HDCP SRM file from non-volatile memory at %s\n", SRM_PATH));	naname = RMnonAsciiFromAscii(SRM_PATH);	fd = RMOpenFile(naname, RM_FILE_OPEN_READ);	RMFreeNonAscii(naname);	if (fd) {		err = RMReadFile(fd, pSRM, SRM_SIZE, &size);		RMCloseFile(fd);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Error, could not read persistent HDCP SRM file!\n"));			size = 0;		} else {			RMDBGLOG((ENABLE, "Read %lu bytes of the persistent HDCP SRM file.\n", size));			if (pSize) *pSize = size;		}	} else {		RMDBGLOG((ENABLE, "Error: could not open persistent HDCP SRM file!\n"));	}		// Fallback: empty, valid SRM	if (size == 0) {		RMDBGLOG((ENABLE, "Fall back to empty, valid HDCP SRM\n"));		size = RMmin(sizeof(SRM_empty) / sizeof(RMuint8), max_size);		RMMemcpy(pSRM, SRM_empty, size);		if (pSize) *pSize = size;		Write_SRM(pSRM, size);	}		return RM_OK;}// Read SRM from current medium and update if more recent than previous onestatic RMstatus Update_SRM(RMascii *filename, struct DH_control *pDH, RMuint8 *pSRM){	RMstatus err = RM_OK;	RMdirectory directory;	RMascii path[2048];	RMdirectoryEntry entry;	RMfile fd;	RMnonAscii *naname;	RMuint32 size;	RMbool update = FALSE;		if (pSRM == NULL) {		RMDBGLOG((ENABLE, "SRM pointer invalid!\n"));		return RM_ERROR;	}		directory = open_directory(filename); 	if (directory == NULL) { 		// Single file, nothing to do 		return RM_OK;	}	RMDBGLOG((MONODBG, "%s is a directory\n", filename));	RMCopyAscii (path, filename);	if (path[RMasciiLength(path) - 1] != '/') {		RMAppendAscii (path, "/");	}		while (RMSUCCEEDED(RMReadDirectory(directory, &entry))) {		if (		    (! strcmp((char*)entry.name, "HDCP.SRM")) || 		    (! strcmp((char*)entry.name, "HDCP.srm"))		) {			RMAppendAscii (path, (RMascii*)entry.name);			RMDBGLOG((MONODBG, "Found HDCP SRM file: %s\n", path));			naname = RMnonAsciiFromAscii(path);			fd = RMOpenFile(naname, RM_FILE_OPEN_READ);			RMFreeNonAscii(naname);			if (fd) {				err = RMReadFile(fd, pSRM, SRM_SIZE, &size);				RMCloseFile(fd);				if (RMFAILED(err)) {					RMDBGLOG((ENABLE, "Error, could not read SRM file %s!\n", path));					break;				}				RMDBGLOG((MONODBG, "Successfully read %lu bytes of HDCP SRM in %s\n", size, path));				err = DHValidateSRM(pDH, pSRM, &update);				if (RMSUCCEEDED(err) && update) {					err = Write_SRM(pSRM, size);					if (RMFAILED(err)) {						RMDBGLOG((ENABLE, "Error: Failed to store new HDCP SRM in flash memory!\n"));					}				}			} else {				RMDBGLOG((ENABLE, "Error: could not open HDCP SRM file %s\n", path));				err = RM_ERROR;			}			break;		}	}	RMCloseDirectory(directory);		return err;}static inline RMascii *get_next_filename(void){	static RMuint32 rec_depth = 0;	RMdirectoryEntry entry;		while( RMReadDirectory(directory[rec_depth], &entry) == RM_OK ){		if(entry.name[0] == '.') /* skip . .. and hidden files */			continue;		path[path_index[rec_depth]] = '\0';		RMAppendAscii (path, (RMascii*)entry.name);		directory[rec_depth+1] = open_directory(path);		if(directory[rec_depth+1] != NULL) {			if((!mono_opt.recurse_dirs) || (rec_depth+1 >= MAX_DIR_RECURSION))				continue;			rec_depth++;			RMAppendAscii (path, "/");			path_index[rec_depth] = RMasciiLength(path);			RMDBGLOG((MONODBG, "==============%s is a directory\n", entry.name));			return get_next_filename();		}		else			return path;	}	RMCloseDirectory(directory[rec_depth]);	if(rec_depth) {		rec_depth--;		return get_next_filename();	}	return NULL;}static inline enum rfp_application get_app(struct rfp_stream_info *stream_info){	switch(stream_info->system_type){	case RM_SYSTEM_MPEG4:		return APP_MP4;	case RM_SYSTEM_ASF:		return APP_ASF;	case RM_SYSTEM_ELEMENTARY_VIDEO:		switch(stream_info->video_type){		case RM_VIDEO_MPEG12:		case RM_VIDEO_MPEG4:		case RM_VIDEO_H263:		case RM_VIDEO_H264:		case RM_VIDEO_WMV:		case RM_VIDEO_VC1:		case RM_VIDEO_DIVX3:		case RM_VIDEO_DIVX4:		case RM_VIDEO_XVID:		case RM_VIDEO_MJPEG:			return APP_VIDEO;		case RM_VIDEO_BMP:		case RM_VIDEO_TIFF:		case RM_VIDEO_GIF:		case RM_VIDEO_PNG:			return APP_PICTURE;		case RM_VIDEO_JPEG:			switch(mono_opt.jpeg_decode){			case mono_decode_soft:				return APP_PICTURE;			case mono_decode_hard:				return APP_VIDEO;			case mono_decode_auto:				return APP_PICTURE;			}		case RM_VIDEO_UNKNOWN:			break;		}		break;	case RM_SYSTEM_ELEMENTARY_AUDIO:		return APP_AUDIO;	case RM_SYSTEM_MPEG1:	case RM_SYSTEM_MPEG2_TRANSPORT:	case RM_SYSTEM_MPEG2_TRANSPORT_192:	case RM_SYSTEM_MPEG2_PROGRAM:	case RM_SYSTEM_MPEG2_DVD:		switch(mono_opt.demux_decode){		case mono_decode_soft:			return APP_DEMUX_SOFT;		case mono_decode_hard:			return APP_DEMUX;		case mono_decode_auto:			return APP_DEMUX;		}		break;	case RM_SYSTEM_AVI:		return APP_AVI;	case RM_SYSTEM_MPEG2_DVD_AUDIO:	case RM_SYSTEM_DIVX_MP3:	case RM_SYSTEM_DIVX_AC3:	case RM_SYSTEM_DIVX_MPEG1:	case RM_SYSTEM_DIVX_PCM:	case RM_SYSTEM_DIVX_WMA:	case RM_SYSTEM_DIVX_WMV9_MP3:	case RM_SYSTEM_DIVX_WMV9_AC3:	case RM_SYSTEM_DIVX_WMV9_MPEG1:	case RM_SYSTEM_DIVX_WMV9_PCM:	case RM_SYSTEM_DIVX3_MP3:	case RM_SYSTEM_DIVX3_AC3:	case RM_SYSTEM_DIVX3_MPEG1:	case RM_SYSTEM_DIVX3_PCM:	case RM_SYSTEM_RIFFCDXA:	case RM_SYSTEM_ID3:	case RM_SYSTEM_UNKNOWN:		break;	}	return NOT_SUPPORTED;}static inline RMstatus gui_enable_osd(RMbool enable){	RMstatus err = RM_OK;		if(enable && !osd_enabled){		err = DCCSetSurfaceSource(dcc_info.pDCC, mono_opt.osd_scaler, mono_opt.osd_source);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Cannot set the surface source %d\n", err));			return RM_ERROR;		}		err = DCCInsertPictureInMultiplePictureOSDVideoSource(mono_opt.osd_source, 0, 0);		if (RMFAILED(err)) {			fprintf(stderr, "Cannot insert picture inside surface %d\n", err);			return RM_ERROR;		}		osd_enabled = TRUE;	}	if(!enable && osd_enabled){		DCCSetSurfaceSource(dcc_info.pDCC, mono_opt.osd_scaler, NULL);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Cannot set the surface source %d\n", err));			return RM_ERROR;		}		osd_enabled = FALSE;	}	return RM_OK;}static inline RMstatus gui_show_stream_info(RMascii *filename, struct rfp_stream_info *stream_info){    	RtkPoint point;	RtkProp prop;	RMascii filename_copy[256], *basename,  *tmp, *audio_type_string = NULL;	RMstatus err;	RMCopyAscii(filename_copy, play_opt.filename); /* if too long, will need to be modified */	basename = filename_copy;	while(RMFindAsciiCharacter (basename, '/', &tmp))		basename = ++tmp;	if(RMasciiLength(basename)>30){		basename[27] = '\0';		RMAppendAscii (basename, "...");	}	switch(stream_info->audio_type){	case eAudioFormat_MPEG1:		audio_type_string = "MPEG1";		break;	case eAudioFormat_MPEG2:		audio_type_string = "MPEG2";		break;	case eAudioFormat_AC3:		audio_type_string = "AC3";		break;	case eAudioFormat_PCM:		audio_type_string = "PCM";		break;	case eAudioFormat_DTS:		audio_type_string = "DTS";		break;	case eAudioFormat_DVD_AUDIO:		audio_type_string = "DVD AUDIO";		break;	case eAudioFormat_REVERSE_PCM:		audio_type_string = "Reverse PCM";		break;	case eAudioFormat_AAC:		audio_type_string = "AAC";		break;	case eAudioFormat_AAC_DSI:		audio_type_string = "AAC with DSI";		break;	case eAudioFormat_AAC_ADIF:		audio_type_string = "AAC ADIF";		break;	case eAudioFormat_AAC_ADTS:		audio_type_string = "AAC ADTS";		break;	case eAudioFormat_AAC_LATM:		audio_type_string = "AAC LATM";		break;	case eAudioFormat_MPEG1_LAYER3:		audio_type_string = "MPEG1 Layer 3";		break;	case eAudioFormat_MPEG2_LAYER1:		audio_type_string = "MPEG2 Layer 1";		break;	case eAudioFormat_MPEG2_LAYER2:		audio_type_string = "MPEG2 Layer 2";		break;	case eAudioFormat_MPEG2_LAYER3:		audio_type_string = "MPEG2 Layer 3";		break;	case eAudioFormat_WMA:		audio_type_string = "WMA";		break;	case eAudioFormat_WMAPRO:		audio_type_string = "WMA PRO";		break;	case eAudioFormat_WMATS:		audio_type_string = "WMATS";

⌨️ 快捷键说明

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