📄 main.cpp
字号:
/****************************************************************************
* 版权信息:(C)2007,深圳市中兴通讯股份有限公司版权所有
* 系统名称:CMMB解码播放SDK子系统
* 文件名称:IControl.h
* 文件说明:Cmmb解码播放SDK Demo程序
* 作 者:阮亚平
* 版本信息:1.0
* 设计日期:2007-5-17
* 修改记录:
* 日 期 版 本 修改人 修改摘要
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include "DABEmu.h"
#include "cmmbdemodulatorconfig.h"
#include "IControl.h"
////////////////////////////DESCRAMBLER_TY
//#define DESCRAMBLER_TY
#ifdef DESCRAMBLER_TY
#include "zte_ca.h"
CA_MODULE_OPERATIONS g_tCAModuleOperations;
CA_DATA g_tCAData;
#endif
////////////////////////////DESCRAMBLER_TY
unsigned char * pPacketData = NULL;
IControl* g_pControl = NULL;
PLAY_CALLBACK_ARRAY CallBacks;
#ifndef Assert
#define Assert(condition) ((void) 0) //临时定义
#endif
#if 1
#include <stdarg.h>
extern int g_nShowLogLevel;
#ifdef __cplusplus
extern "C" {
#endif
void write_log (int lvl, const char* fmt, ...)
{
if(lvl >= g_nShowLogLevel)
{
char sTmp[4096]={0};
va_list args;
va_start(args, fmt);
vsnprintf(sTmp, sizeof(sTmp), fmt, args);
va_end(args);
printf("%s \n", sTmp);
}
}
#ifdef __cplusplus
}
#endif
#endif
typedef enum
{
E_SUM2_ERROR = -2,
E_SUM1_ERROR,
E_DATA_ERROR,
E_NO_DATA,
}E_CALLBACK_ERROR_RET;
int channelid = 0;
//#define SUBFRAME_FILE
#ifdef SUBFRAME_FILE
FILE *pFile = fopen("test.src", "wb");
#endif
unsigned int sInitialSec = 0;
unsigned int Milliseconds()
{
struct timeval t;
int theErr = ::gettimeofday(&t, NULL);
if ( theErr != 0 )
{
Assert(theErr == 0);
}
if(sInitialSec == 0)
{
sInitialSec = t.tv_sec;
}
unsigned int curTime;
curTime = t.tv_sec - sInitialSec;
curTime *= 1000; // sec -> msec
curTime += t.tv_usec / 1000; // usec -> msec
return (curTime);
}
bool g_bLivePlay = false;
bool g_bstartplay = false;
int g_istopNum = 0;
unsigned int g_u32CurTick = 0;
unsigned int g_u32StartTick = 0;
unsigned int g_u32ReadCount = 0;
extern int g_streamspi;
int GetStreamData(void* wParam, void* lParam, long& bHandled)
{
if (g_bLivePlay)
{
int ret = 0;
int length = 0;
int ioffset = 0;
switch((int)wParam)
{
case PLAYER_CALLBACK_READ_DATA:
{
while (g_bstartplay)
{
length = GetNextSubFrameforCallBack(g_streamspi, pPacketData, ioffset);
if (length == -1)
{
printf("xingxing : Get Next Frame Err!\n");
++g_istopNum;
if (g_istopNum == 20)
{
g_istopNum = 0;
break;
}
EmuBegin(channelid);
continue;
}
if (length > 2)
{
g_istopNum = 0;
ret = length;
printf("xingxing : curent frame length is %d.\n", length);
bHandled = (int &)pPacketData + ioffset;
break;
}
else if (length == -2)
{
++g_istopNum;
if (g_istopNum == 50)
{
printf("xingxing : no data!\n");
g_istopNum = 0;
break;
}
usleep(1000*50);
}
}
g_istopNum = 0;
}
break;
case PLAYER_CALLBACK_NOTIFY:
{
EResultCode eRet = (EResultCode)((int)lParam);
switch(eRet)
{
case RS_FAIL:
//表示通知解析复用子帧解析错误,用于重新启动驱
{
EmuBegin(channelid);
printf("eRet is RS_FAIL,startSPI:.\n");
break;
}
case RS_INVALIDARG:
//表示读数据错误(读不到指定长度的数据),暂时不做处理
printf("PLAYER_CALLBACK_NOTIFY:%d.\n", eRet);
break;
default:
//其它
break;
}
}
break;
}
return ret;
}
else
{
int ret = 0;
switch((int)wParam)
{
case PLAYER_CALLBACK_READ_DATA:
{
int length, tmp;
tmp = (int)lParam;
tmp = 1;
length = tmp;
unsigned char* pTemp = pPacketData;
if (pTemp)
{
/*g_u32CurTick = Milliseconds();
printf("g_u32StartTick = %u, g_u32CurTick=%u, g_u32ReadCount=%u\n", g_u32StartTick, g_u32CurTick, g_u32ReadCount);
if((g_u32StartTick == 0 )
|| (g_u32CurTick - g_u32StartTick) >= (g_u32ReadCount+1)*1000)*/
{
if(g_u32StartTick == 0)
{
g_u32StartTick = g_u32CurTick;
}
do
{
if ( length < tmp )
{
EmuBegin(channelid);
}
length = DABQUEUE_ReadBlock(pTemp, tmp);
} while( length < tmp );
if(length > 0)
g_u32ReadCount ++;
}
/*else
{
length = 0;
}*/
ret = length;
bHandled = (int &)pTemp;
}
}
break;
case PLAYER_CALLBACK_NOTIFY:
{
EResultCode eRet = (EResultCode)((int)lParam);
/*
switch(eRet)
{
case RS_FAIL:
//表示通知解析复用子帧解析错误,用于重新启动驱动
break;
case RS_INVALIDARG:
//表示读数据错误(读不到指定长度的数据),暂时不做处理
break;
default:
//其它
break;
}*/
printf("PLAYER_CALLBACK_NOTIFY:%d\n", eRet);
}
break;
default:
{
ret = -1;
}
break;
}
return ret;
}
}
int GetCMMBMuxFrame(void* wParam, void* lParam, long& bHandled)
{
int ret = 0;
switch((int)wParam)
{
case PLAYER_CALLBACK_READ_DATA:
{
int length, tmp;
tmp = (int)lParam;
tmp = 1;
length = tmp;
unsigned char* pTemp = pPacketData;
if (pTemp)
{
{
do
{
if ( length < tmp )
{
EmuBegin(0);
}
length = DABQUEUE_ReadBlock_Frame(pTemp, tmp);
} while( length < tmp );
}
ret = length;
bHandled = (int &)pTemp;
}
}
break;
case PLAYER_CALLBACK_NOTIFY:
{
EResultCode eRet = (EResultCode)((int)lParam);
printf("PLAYER_CALLBACK_NOTIFY:%d\n", eRet);
}
break;
default:
{
ret = -1;
}
break;
}
return ret;
}
int GetDescrambleMSF(unsigned char* pInMSFData, int nInMSFLength,
unsigned char* pOutMSFData, int *pOutMSFLength)
{
////////////////////////////DESCRAMBLER_TY
#ifdef DESCRAMBLER_TY
if(NULL == g_tCAModuleOperations.ca_descramble
|| CA_OK != g_tCAModuleOperations.ca_descramble(&g_tCAData, NULL,
pInMSFData, nInMSFLength,
pOutMSFData, pOutMSFLength))
{
//解扰失败
;
}
#else
memcpy(pOutMSFData, pInMSFData, nInMSFLength);
*pOutMSFLength = nInMSFLength;
#endif
////////////////////////////DESCRAMBLER_TY
return 0;
}
/**************************************************************
函数名称 : GetSDP
作者 : 刘志强
设计日期 : 2007年5月30日
功能描述 :
参数 : const char *pInFileName -输入SDP文件名
参数 : char *szSDP -输出SDP数据
参数 : int& retLen -输出SDP长度
返回值 : int -0 表示调用成功
**************************************************************/
int GetSDP(const char *pInFileName,char *szSDP,int& retLen)
{
FILE *fp = NULL;
fp = fopen(pInFileName,"r+b");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -