430 lines
11 KiB
C
Executable File
430 lines
11 KiB
C
Executable File
/******************************************************************************
|
|
|
|
Copyright (C), 2001-2011, Hisilicon Tech. Co., Ltd.
|
|
|
|
******************************************************************************
|
|
File Name : tsplay.c
|
|
Version : Initial Draft
|
|
Author : Hisilicon multimedia software group
|
|
Created : 2010/01/26
|
|
Description :
|
|
History :
|
|
1.Date : 2010/01/26
|
|
Author : sdk
|
|
Modification: Created file
|
|
|
|
******************************************************************************/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <pthread.h>
|
|
|
|
#include "hi_unf_common.h"
|
|
#include "hi_unf_ecs.h"
|
|
#include "hi_unf_avplay.h"
|
|
#include "hi_unf_sound.h"
|
|
#include "hi_unf_disp.h"
|
|
#include "hi_unf_vo.h"
|
|
#include "hi_unf_demux.h"
|
|
#include "hi_adp_hdmi.h"
|
|
#include "hi_adp_mpi.h"
|
|
|
|
#include "HA.AUDIO.MP3.decode.h"
|
|
#include "HA.AUDIO.MP2.decode.h"
|
|
#include "HA.AUDIO.AAC.decode.h"
|
|
#include "HA.AUDIO.DRA.decode.h"
|
|
#include "HA.AUDIO.PCM.decode.h"
|
|
#include "HA.AUDIO.WMA9STD.decode.h"
|
|
#include "HA.AUDIO.AMRNB.codec.h"
|
|
|
|
|
|
FILE *g_pTsFile = HI_NULL;
|
|
static pthread_t g_TsThd;
|
|
static pthread_mutex_t g_TsMutex;
|
|
static HI_BOOL g_bStopTsThread = HI_FALSE;
|
|
HI_HANDLE g_TsBuf;
|
|
PMT_COMPACT_TBL *g_pProgTbl = HI_NULL;
|
|
|
|
#define PLAY_DMX_ID 0
|
|
|
|
HI_VOID TsTthread(HI_VOID *args)
|
|
{
|
|
HI_UNF_STREAM_BUF_S StreamBuf;
|
|
HI_U32 Readlen;
|
|
HI_S32 Ret;
|
|
|
|
while (!g_bStopTsThread)
|
|
{
|
|
pthread_mutex_lock(&g_TsMutex);
|
|
Ret = HI_UNF_DMX_GetTSBuffer(g_TsBuf, 188*50, &StreamBuf, 1000);
|
|
if (Ret != HI_SUCCESS )
|
|
{
|
|
pthread_mutex_unlock(&g_TsMutex);
|
|
continue;
|
|
}
|
|
|
|
Readlen = fread(StreamBuf.pu8Data, sizeof(HI_S8), 188*50, g_pTsFile);
|
|
if(Readlen <= 0)
|
|
{
|
|
printf("read ts file end and rewind!\n");
|
|
rewind(g_pTsFile);
|
|
pthread_mutex_unlock(&g_TsMutex);
|
|
continue;
|
|
}
|
|
|
|
Ret = HIADP_DMX_PushTsBuffer(g_TsBuf, &StreamBuf, 0, Readlen);
|
|
if (Ret != HI_SUCCESS )
|
|
{
|
|
printf("call HI_UNF_DMX_PutTSBuffer failed.\n");
|
|
}
|
|
pthread_mutex_unlock(&g_TsMutex);
|
|
}
|
|
|
|
Ret = HI_UNF_DMX_ResetTSBuffer(g_TsBuf);
|
|
if (Ret != HI_SUCCESS )
|
|
{
|
|
printf("call HI_UNF_DMX_ResetTSBuffer failed.\n");
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
HI_S32 main(HI_S32 argc, HI_CHAR *argv[])
|
|
{
|
|
HI_S32 Ret;
|
|
HI_HANDLE hWin;
|
|
HI_HANDLE hAvplay;
|
|
HI_UNF_AVPLAY_ATTR_S AvplayAttr;
|
|
HI_UNF_SYNC_ATTR_S SyncAttr;
|
|
HI_UNF_AVPLAY_STOP_OPT_S Stop;
|
|
HI_CHAR InputCmd[32];
|
|
HI_UNF_ENC_FMT_E enFormat = HI_UNF_ENC_FMT_1080i_50;
|
|
HI_U32 ProgNum;
|
|
HI_HANDLE hTrack;
|
|
HI_UNF_AUDIOTRACK_ATTR_S stTrackAttr;
|
|
HI_UNF_AVPLAY_TVP_ATTR_S stAvTVPAttr;
|
|
HI_UNF_AVPLAY_AUD_SECURITY_ATTR_S stAudSecAttr;
|
|
|
|
if (3 == argc)
|
|
{
|
|
enFormat = HIADP_Disp_StrToFmt(argv[2]);
|
|
}
|
|
else if (2 == argc)
|
|
{
|
|
enFormat = HI_UNF_ENC_FMT_1080i_50;
|
|
}
|
|
else
|
|
{
|
|
printf("Usage: sample_tsplay file [vo_format]\n"
|
|
" vo_format:2160P_30|2160P_24|1080P_60|1080P_50|1080i_60|[1080i_50]|720P_60|720P_50\n");
|
|
printf("Example:./sample_tsplay ./test.ts 1080i_50\n");
|
|
return 0;
|
|
}
|
|
|
|
g_pTsFile = fopen(argv[1], "rb");
|
|
if (!g_pTsFile)
|
|
{
|
|
printf("open file %s error!\n", argv[1]);
|
|
return -1;
|
|
}
|
|
|
|
HI_SYS_Init();
|
|
|
|
HIADP_MCE_Exit();
|
|
|
|
Ret = HIADP_Snd_Init();
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call HIADP_Snd_Init failed.\n");
|
|
goto SYS_DEINIT;
|
|
}
|
|
|
|
Ret = HIADP_Disp_Init(enFormat);
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call HIADP_Disp_Init failed.\n");
|
|
goto SND_DEINIT;
|
|
}
|
|
|
|
Ret = HIADP_VO_Init(HI_UNF_VO_DEV_MODE_NORMAL);
|
|
Ret |= HIADP_VO_CreatWin(HI_NULL, &hWin);
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call HIADP_VO_Init failed.\n");
|
|
HIADP_VO_DeInit();
|
|
goto DISP_DEINIT;
|
|
}
|
|
|
|
Ret = HI_UNF_DMX_Init();
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call HI_UNF_DMX_Init failed.\n");
|
|
goto VO_DEINIT;
|
|
}
|
|
|
|
Ret = HI_UNF_DMX_AttachTSPort(PLAY_DMX_ID,HI_UNF_DMX_PORT_RAM_0);
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call HI_UNF_DMX_AttachTSPort failed.\n");
|
|
goto DMX_DEINIT;
|
|
}
|
|
|
|
Ret = HI_UNF_DMX_CreateTSBuffer(HI_UNF_DMX_PORT_RAM_0, 0x200000, &g_TsBuf);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_DMX_CreateTSBuffer failed.\n");
|
|
goto DMX_DEINIT;
|
|
}
|
|
|
|
Ret = HIADP_AVPlay_RegADecLib();
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call RegADecLib failed.\n");
|
|
goto TSBUF_FREE;
|
|
}
|
|
|
|
Ret = HI_UNF_AVPLAY_Init();
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_AVPLAY_Init failed.\n");
|
|
goto DMX_DEINIT;
|
|
}
|
|
|
|
Ret = HI_UNF_AVPLAY_GetDefaultConfig(&AvplayAttr, HI_UNF_AVPLAY_STREAM_TYPE_TS);
|
|
AvplayAttr.u32DemuxId = PLAY_DMX_ID;
|
|
Ret |= HI_UNF_AVPLAY_Create(&AvplayAttr, &hAvplay);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_AVPLAY_Create failed.\n");
|
|
goto AVPLAY_DEINIT;
|
|
}
|
|
|
|
stAvTVPAttr.bEnable = HI_TRUE;
|
|
Ret = HI_UNF_AVPLAY_SetAttr(hAvplay, HI_UNF_AVPLAY_ATTR_ID_TVP, &stAvTVPAttr);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("set tvp error\n");
|
|
goto AVPLAY_DEINIT;
|
|
}
|
|
|
|
Ret = HI_UNF_AVPLAY_ChnOpen(hAvplay, HI_UNF_AVPLAY_MEDIA_CHAN_VID, HI_NULL);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_AVPLAY_ChnOpen failed.\n");
|
|
goto AVPLAY_DESTROY;
|
|
}
|
|
|
|
stAudSecAttr.bEnable = HI_FALSE;
|
|
Ret = HI_UNF_AVPLAY_SetAttr(hAvplay, HI_UNF_AVPLAY_ATTR_ID_AUD_SECURITY, &stAudSecAttr);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("set security aud dmx chn fail.\n");
|
|
goto VCHN_CLOSE;
|
|
}
|
|
|
|
Ret = HI_UNF_AVPLAY_ChnOpen(hAvplay, HI_UNF_AVPLAY_MEDIA_CHAN_AUD, HI_NULL);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_AVPLAY_ChnOpen failed.\n");
|
|
goto VCHN_CLOSE;
|
|
}
|
|
|
|
Ret = HI_UNF_VO_AttachWindow(hWin, hAvplay);
|
|
if (HI_SUCCESS != Ret)
|
|
{
|
|
printf("call HI_UNF_VO_AttachWindow failed:%#x.\n",Ret);
|
|
goto ACHN_CLOSE;
|
|
}
|
|
|
|
Ret = HI_UNF_VO_SetWindowEnable(hWin, HI_TRUE);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_VO_SetWindowEnable failed.\n");
|
|
goto WIN_DETACH;
|
|
}
|
|
|
|
Ret = HI_UNF_SND_GetDefaultTrackAttr(HI_UNF_SND_TRACK_TYPE_MASTER, &stTrackAttr);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_SND_GetDefaultTrackAttr failed.\n");
|
|
goto WIN_DETACH;
|
|
}
|
|
Ret = HI_UNF_SND_CreateTrack(HI_UNF_SND_0, &stTrackAttr, &hTrack);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_SND_CreateTrack failed.\n");
|
|
goto WIN_DETACH;
|
|
}
|
|
|
|
Ret = HI_UNF_SND_Attach(hTrack, hAvplay);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_SND_Attach failed.\n");
|
|
goto TRACK_DESTROY;
|
|
}
|
|
|
|
Ret = HI_UNF_AVPLAY_GetAttr(hAvplay, HI_UNF_AVPLAY_ATTR_ID_SYNC, &SyncAttr);
|
|
SyncAttr.enSyncRef = HI_UNF_SYNC_REF_AUDIO;
|
|
Ret |= HI_UNF_AVPLAY_SetAttr(hAvplay, HI_UNF_AVPLAY_ATTR_ID_SYNC, &SyncAttr);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HI_UNF_AVPLAY_SetAttr failed.\n");
|
|
goto SND_DETACH;
|
|
}
|
|
|
|
pthread_mutex_init(&g_TsMutex,NULL);
|
|
g_bStopTsThread = HI_FALSE;
|
|
pthread_create(&g_TsThd, HI_NULL, (HI_VOID *)TsTthread, HI_NULL);
|
|
|
|
HIADP_Search_Init();
|
|
Ret = HIADP_Search_GetAllPmt(PLAY_DMX_ID, &g_pProgTbl);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HIADP_Search_GetAllPmt failed.\n");
|
|
goto PSISI_FREE;
|
|
}
|
|
|
|
ProgNum = 0;
|
|
|
|
pthread_mutex_lock(&g_TsMutex);
|
|
rewind(g_pTsFile);
|
|
HI_UNF_DMX_ResetTSBuffer(g_TsBuf);
|
|
|
|
Ret = HIADP_AVPlay_PlayProg(hAvplay, g_pProgTbl, ProgNum, HI_TRUE);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HIADP_AVPlay_PlayProg failed.\n");
|
|
goto AVPLAY_STOP;
|
|
}
|
|
|
|
pthread_mutex_unlock(&g_TsMutex);
|
|
|
|
while (1)
|
|
{
|
|
static HI_U32 u32TplaySpeed = 2;
|
|
printf("please input 'q' to quit!\n");
|
|
SAMPLE_GET_INPUTCMD(InputCmd);
|
|
|
|
if ('q' == InputCmd[0])
|
|
{
|
|
printf("prepare to quit!\n");
|
|
break;
|
|
}
|
|
|
|
if ('t' == InputCmd[0])
|
|
{
|
|
HI_UNF_AVPLAY_TPLAY_OPT_S stTplayOpt;
|
|
printf("%dx tplay\n",u32TplaySpeed);
|
|
|
|
stTplayOpt.enTplayDirect = HI_UNF_AVPLAY_TPLAY_DIRECT_FORWARD;
|
|
stTplayOpt.u32SpeedInteger = u32TplaySpeed;
|
|
stTplayOpt.u32SpeedDecimal = 0;
|
|
|
|
HI_UNF_AVPLAY_SetDecodeMode(hAvplay, HI_UNF_VCODEC_MODE_I);
|
|
HI_UNF_AVPLAY_Tplay(hAvplay,&stTplayOpt);
|
|
u32TplaySpeed = (32 == u32TplaySpeed * 2) ? (2) : (u32TplaySpeed * 2) ;
|
|
continue;
|
|
}
|
|
|
|
if ('r' == InputCmd[0])
|
|
{
|
|
printf("resume\n");
|
|
HI_UNF_AVPLAY_SetDecodeMode(hAvplay, HI_UNF_VCODEC_MODE_NORMAL);
|
|
HI_UNF_AVPLAY_Resume(hAvplay,HI_NULL);
|
|
u32TplaySpeed = 2;
|
|
continue;
|
|
}
|
|
|
|
if ('g' == InputCmd[0])
|
|
{
|
|
HI_UNF_AVPLAY_STATUS_INFO_S stStatusInfo;
|
|
HI_UNF_AVPLAY_GetStatusInfo(hAvplay,&stStatusInfo);
|
|
printf("localtime %u playtime %u\n",stStatusInfo.stSyncStatus.u32LocalTime,stStatusInfo.stSyncStatus.u32PlayTime);
|
|
continue;
|
|
}
|
|
|
|
ProgNum = atoi(InputCmd);
|
|
if (ProgNum == 0)
|
|
ProgNum = 1;
|
|
|
|
pthread_mutex_lock(&g_TsMutex);
|
|
rewind(g_pTsFile);
|
|
HI_UNF_DMX_ResetTSBuffer(g_TsBuf);
|
|
|
|
Ret = HIADP_AVPlay_PlayProg(hAvplay, g_pProgTbl, ProgNum - 1, HI_TRUE);
|
|
if (Ret != HI_SUCCESS)
|
|
{
|
|
printf("call HIADP_AVPlay_PlayProg failed!\n");
|
|
break;
|
|
}
|
|
|
|
pthread_mutex_unlock(&g_TsMutex);
|
|
}
|
|
|
|
AVPLAY_STOP:
|
|
Stop.enMode = HI_UNF_AVPLAY_STOP_MODE_BLACK;
|
|
Stop.u32TimeoutMs = 0;
|
|
HI_UNF_AVPLAY_Stop(hAvplay, HI_UNF_AVPLAY_MEDIA_CHAN_VID | HI_UNF_AVPLAY_MEDIA_CHAN_AUD, &Stop);
|
|
|
|
PSISI_FREE:
|
|
HIADP_Search_FreeAllPmt(g_pProgTbl);
|
|
g_pProgTbl = HI_NULL;
|
|
HIADP_Search_DeInit();
|
|
|
|
g_bStopTsThread = HI_TRUE;
|
|
pthread_join(g_TsThd, HI_NULL);
|
|
pthread_mutex_destroy(&g_TsMutex);
|
|
|
|
SND_DETACH:
|
|
HI_UNF_SND_Detach(hTrack, hAvplay);
|
|
|
|
TRACK_DESTROY:
|
|
HI_UNF_SND_DestroyTrack(hTrack);
|
|
|
|
WIN_DETACH:
|
|
HI_UNF_VO_SetWindowEnable(hWin, HI_FALSE);
|
|
HI_UNF_VO_DetachWindow(hWin, hAvplay);
|
|
|
|
ACHN_CLOSE:
|
|
HI_UNF_AVPLAY_ChnClose(hAvplay, HI_UNF_AVPLAY_MEDIA_CHAN_AUD);
|
|
|
|
VCHN_CLOSE:
|
|
HI_UNF_AVPLAY_ChnClose(hAvplay, HI_UNF_AVPLAY_MEDIA_CHAN_VID);
|
|
|
|
AVPLAY_DESTROY:
|
|
HI_UNF_AVPLAY_Destroy(hAvplay);
|
|
|
|
AVPLAY_DEINIT:
|
|
HI_UNF_AVPLAY_DeInit();
|
|
|
|
TSBUF_FREE:
|
|
HI_UNF_DMX_DestroyTSBuffer(g_TsBuf);
|
|
|
|
DMX_DEINIT:
|
|
HI_UNF_DMX_DetachTSPort(0);
|
|
HI_UNF_DMX_DeInit();
|
|
|
|
VO_DEINIT:
|
|
HI_UNF_VO_DestroyWindow(hWin);
|
|
HIADP_VO_DeInit();
|
|
|
|
DISP_DEINIT:
|
|
HIADP_Disp_DeInit();
|
|
|
|
SND_DEINIT:
|
|
HIADP_Snd_DeInit();
|
|
|
|
SYS_DEINIT:
|
|
HI_SYS_DeInit();
|
|
|
|
fclose(g_pTsFile);
|
|
g_pTsFile = HI_NULL;
|
|
|
|
return Ret;
|
|
}
|
|
|
|
|