- 显示设备初始化
sstar_disp_init(&stDispPubAttr);//显示初始化
MI_SYS_Init();//sstart 中间件接口初始化
MI_DISP_SetPubAttr(0, pstDispPubAttr);//配置视频输出设备的公共属性
MI_DISP_Enable(0);//启用视频输出设备。
MI_DISP_BindVideoLayer(0, 0);//绑定视频层到指定设备
MI_DISP_SetVideoLayerAttr(0, &stLayerAttr);//设定视频层属性
MI_DISP_EnableVideoLayer(0);//使能视频层
MI_DISP_SetInputPortAttr(0, 0, &stInputPortAttr);//配置指定视频输入端口的属性
MI_DISP_EnableInputPort(0, 0);//启用指定的视频输入端口
MI_DISP_SetInputPortSyncMode(0, 0, E_MI_DISP_SYNC_MODE_FREE_RUN);//设定指定的视频输入端口同步模式
MI_PANEL_Init(eLinkType);//初始化 PANEL
MI_PANEL_SetPanelParam(&stPanelParam);//设置 PANEL INFO
- //init SDK
sstar_vdec_init();
MI_VDEC_InitDev(&stVdecInitParam)//初始化设备
MI_VDEC_CreateChn(stVdecChn, &stVdecChnAttr)//创建通道
MI_VDEC_StartChn(stVdecChn)//设置编码通道
MI_VDEC_SetOutputPortAttr(0, &stOutputPortAttr)//设置输出端口属性
MI_SYS_SetChnOutputPortDepth(&stChnPort, 0, 5)//设置通道 OutputPort 的深度
MI_SYS_BindChnPort(&stSrcChnPort, &stDstChnPort, 30, 30)//数据源输出端口到接收者输入端口的绑定
MI_DISP_SetVideoLayerRotateMode(0, &stRotateConfig);//是否要翻转,翻转就设定
- 初始化声卡
sstar_ao_init();
/* set ao public attr*/设置 AO 设备属性
MI_AO_SetPubAttr(AoDevId, &stSetAttr);
/* get ao device*/获取 AO 设备属性
MI_AO_GetPubAttr(AoDevId, &stGetAttr);
/* enable ao device */启用 AO 设备
MI_AO_Enable(AoDevId);
/* enable ao channel of device*/启用 AO 通道
MI_AO_EnableChn(AoDevId, AoChn);
/* if test AO Volume */设置 AO 设备音量大小
s32SetVolumeDb = 0;
MI_AO_SetVolume(AoDevId, s32SetVolumeDb); // 音量[-60dB ~ 30dB]
/* get AO volume */获取 AO 设备音量大小
MI_AO_GetVolume(AoDevId, &s32GetVolumeDb);
pthread_create(&tid_audio, NULL, sstar_audio_thread, (void *)audio_file);
wav_head_len = find_wav_data(wave_file);
int g_AoReadFd = open((const char *)wave_file, O_RDONLY, 0666);
s32Ret = read(g_AoReadFd, &g_stWavHeaderInput, sizeof(WaveFileHeader_t));
// 拉高公版声音功放IO
system("echo 12 > /sys/class/gpio/export");
system("echo out > /sys/class/gpio/gpio12/direction");
system("echo 1 > /sys/class/gpio/gpio12/value");
while(!bExit)
{
s32Ret = read(g_AoReadFd, &u8TempBuf, g_s32NeedSize);
s32Ret = MI_AO_SendFrame(AUDIO_DEV, AUDIO_CHN, &stAoSendFrame, -1);
}
4.解码h264码流
(1)用ffmpeg
AVFormatContext *pFormatCtx;
PLAY:
pFormatCtx = avformat_alloc_context();//申请空间
avformat_open_input(&pFormatCtx, filename, NULL, NULL) ;//打开设备
AVPacket *packet = av_malloc(sizeof(AVPacket));//申请内存空间
while (av_read_frame(pFormatCtx, packet) >= 0)//一直读h264文件
{
MI_VDEC_SendStream(0, &stVdecStream, 20))//将解码后码流发送到下一模块(播放/显示模块)
av_packet_unref(packet);//释放内存,不释放会爆掉
}
av_packet_free(&packet);//释放
avformat_close_input(&pFormatCtx);//关闭
EXIT:
(2)用SDK api
pthread_create(&tid_video, NULL, sstar_video_thread, (void *)filename);
pSlice2FrmBuf = (unsigned char*)malloc(MAX_ONE_FRM_SIZE);
if (_bReOrderSlice) {
pSliceReOrder = (unsigned char *)malloc(MAX_ONE_FRM_SIZE);
}
char *video_file = (char *)arg;
pstNalu = AllocNALU(MAX_ONE_FRM_SIZE);
prctl(PR_SET_NAME, "send_thrd_0");
fReadFile = fopen(video_file, "rb"); //ES
pu8Buf = (MI_U8 *)malloc(MAX_ONE_FRM_SIZE);
while (!bExit)
{
s32Ret = GetAnnexbNALU(pstNalu, vdecChn, fReadFile);
if (MI_SUCCESS != (s32Ret = MI_VDEC_SendStream(vdecChn, &stVdecStream, s32TimeOutMs)))
u32SliceCount++;
}
free(pu8Buf);
FreeNALU(pstNalu);
fclose(fReadFile);
free(pSlice2FrmBuf);
printf("end of sstar_video_thread\n");