📄 simple_player.cpp
字号:
/* /////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2001-2007 Intel Corporation. All Rights Reserved.
//
// Intel(R) Integrated Performance Primitives
// Video Coding (ippvc)
//
*/
// simple_player.cpp : Defines the entry point for the console application.
//
#if defined (WIN32) || defined (WIN64)
#include <conio.h>
#endif // WIN32
#include <stdio.h>
#include <stdarg.h>
#include <ippi.h>
#include <ippcore.h>
#include <ippvc.h>
#include "vm_debug.h"
#include "vm_time.h"
#include "vm_sys_info.h"
#include "umc_sys_info.h"
#include "umc_video_processing.h"
#include "avsync.h"
#include "codec_pipeline.h"
#if defined(ARM) || defined(_ARM_)
const Ipp32u cuiDisplayWidth = 640;
const Ipp32u cuiDisplayHeight = 480;
const UMC::ColorFormat cDispColorFormat = UMC::RGB565;
#else // defined(ARM) || defined(_ARM_)
const Ipp32u cuiDisplayWidth = 800;
const Ipp32u cuiDisplayHeight = 600;
#ifdef OSX32
const UMC::ColorFormat cDispColorFormat = UMC::RGB24;
#else
const UMC::ColorFormat cDispColorFormat = UMC::YV12;
#endif // OSX32
#endif // defined(ARM) || defined(_ARM_)
const Ipp32u culReduceCoeff = UMC::FLAG_CCNV_CONVERT;
//Ipp64f cpu_use = 0;
void PerfToFile(AVSync& rAVSync,
AVSync::CommonCtl& r_cc,
UMC :: SysInfo& m_csysinfo,
vm_char* m_sz_curr_filename,
vm_char* m_sz_perf_filename,
Ipp32s iFlag)
{
vm_char tmpbuf[128]={0,};
vm_file* perf_file;
AVSync::Stat Stat;
vm_char* stream_name = NULL;
//UMC :: SysInfo m_csysinfo;
UMC :: sSystemInfo* m_ssysteminfo;
m_ssysteminfo = (UMC::sSystemInfo *)m_csysinfo.GetSysInfo();
switch(iFlag)
{
case 0:
IppLibraryVersion *ipplibversion;
perf_file = vm_file_open(m_sz_perf_filename, VM_STRING("a"));
if(perf_file){
stream_name = vm_string_strrchr(m_sz_curr_filename, (Ipp32s)('\\'));
if(!stream_name)stream_name = m_sz_curr_filename;
else stream_name++;
vm_file_fseek( perf_file, 0, VM_FILE_SEEK_END);
if(!vm_file_ftell( perf_file))
vm_string_fprintf(perf_file, VM_STRING("Date,Time,Comp.name,OS,CPU,Num.CPU,CPU freq.,MEM,VGA,App,App description,App ver.,Ipp Type,Ipp ver.,Ipp Desc.,Streams(S) name,Status,S.Type,S.Res.,S.FR,S.BR,Video(V)Type,V.Format,V.Num,V.D/E(FpS),V.D/E(MHz),V.RR(Fps),V.S(F),Audio(A)Type,A.Freq.,A.NC,A.(BpS),A.BR,A.D/E(MHz),CPU Usage (%%),Max Cpu Usage (%%),Work.Time\n"));
vm_sys_info_get_date(tmpbuf,MMDDYY);
vm_string_fprintf(perf_file,VM_STRING("%s,"), tmpbuf);
vm_sys_info_get_time(tmpbuf,HHMMSS);
vm_string_fprintf(perf_file,VM_STRING("%s,"), tmpbuf);
vm_string_fprintf(perf_file,VM_STRING("%s,"), m_ssysteminfo->computer_name);
vm_string_fprintf(perf_file,VM_STRING("%s,"), m_ssysteminfo->os_name);
vm_string_fprintf(perf_file,VM_STRING("%s,"), m_ssysteminfo->proc_name);
vm_string_fprintf(perf_file,VM_STRING("%d,"), m_ssysteminfo->num_proc);
vm_string_fprintf(perf_file,VM_STRING("%.2f,"), (Ipp64f)m_ssysteminfo->cpu_freq);
vm_string_fprintf(perf_file,VM_STRING("%d,"), m_ssysteminfo->phys_mem);
vm_string_fprintf(perf_file,VM_STRING("%s,"), m_ssysteminfo->video_card);
vm_string_fprintf(perf_file,VM_STRING("%s,"),m_ssysteminfo->program_name);
vm_string_fprintf(perf_file,VM_STRING("UMC Simple Player,"));//,m_ssysteminfo->description);
vm_string_fprintf(perf_file,VM_STRING(",")); // ver. of applications
ipplibversion = (IppLibraryVersion*)ippvcGetLibVersion();
vm_string_fprintf(perf_file,VM_STRING("%s,"), ipplibversion->targetCpu);
vm_string_fprintf(perf_file,VM_STRING("%d.%d.%d.%d,"), ipplibversion->major,ipplibversion->minor,ipplibversion->majorBuild,ipplibversion->build);
vm_string_fprintf(perf_file,VM_STRING("%s (%s),"), ipplibversion->Version,ipplibversion->BuildDate);
vm_string_fprintf(perf_file,VM_STRING("%s,"), stream_name);
vm_string_fprintf(perf_file,VM_STRING("FAIL\n"));
vm_file_fclose(perf_file);
}
break;
case 1:
perf_file = vm_file_open(m_sz_perf_filename, VM_STRING("r+"));
if(perf_file) {
vm_file_fseek( perf_file, -5, VM_FILE_SEEK_END);
vm_string_fprintf(perf_file,VM_STRING("PASSED,"));
UMC::Status umcRes = rAVSync.GetStat(Stat);
vm_string_fprintf(perf_file,VM_STRING("%s,"), UMC::GetStreamTypeString(rAVSync.GetSystemStreamType()));
vm_string_fprintf(perf_file,VM_STRING("%dx%d,"),rAVSync.GetSrcFrmWidth(),rAVSync.GetSrcFrmHeight());
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"),(rAVSync.GetSrcFrmRate() ? rAVSync.GetSrcFrmRate() : 30.));
vm_string_fprintf(perf_file,VM_STRING("%d,"),rAVSync.GetSrcFrmBitRate());
vm_string_fprintf(perf_file,VM_STRING("%s,"), UMC::GetVideoTypeString(rAVSync.GetVideoStreamType()));
// vm_string_fprintf(perf_file,VM_STRING("%s,"), UMC::GetFormatTypeString(rAVSync.GetVideoFormatType()));
vm_string_fprintf(perf_file,VM_STRING("%s,"), UMC::GetFormatTypeString(r_cc.cformat));
vm_string_fprintf(perf_file,VM_STRING("%d,"), Stat.uiFrameNum);
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), Stat.dfDecodeRate);
if(Stat.dfDecodeRate)
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), rAVSync.GetSrcFrmRate()?(Ipp64f)(rAVSync.GetSrcFrmRate()/Stat.dfDecodeRate*(m_ssysteminfo->cpu_freq)):(30./Stat.dfDecodeRate*(m_ssysteminfo->cpu_freq)));
else
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), 0.0);
if(Stat.dfRenderTime)
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), (Ipp64f)(Stat.uiFrameNum/Stat.dfRenderTime));
else
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), 0.0);
vm_string_fprintf(perf_file,VM_STRING("%d,"), Stat.uiSkippedNum);
vm_string_fprintf(perf_file,VM_STRING("%s,"), UMC::GetAudioTypeString(rAVSync.GetAudioStreamType()));
vm_string_fprintf(perf_file,VM_STRING("%d,"), rAVSync.GetAudioSmplFreq());
vm_string_fprintf(perf_file,VM_STRING("%d,"), rAVSync.GetAudioNChannel());
vm_string_fprintf(perf_file,VM_STRING("%d,"), rAVSync.GetAudioBitPerSmpl());
vm_string_fprintf(perf_file,VM_STRING("%d,"), rAVSync.GetAudioBitRate());
//if((Ipp32s)Stat.dfAudioDecodeRate)
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), Stat.dfAudioDecodeRate*m_ssysteminfo->cpu_freq);
//else
// vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), 0.0);
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), m_csysinfo.GetAvgCpuUsage());
vm_string_fprintf(perf_file,VM_STRING("%.2lf,"), m_csysinfo.GetMaxCpuUsage());
vm_string_fprintf(perf_file,VM_STRING("%02d:%02d:%02d,"),(Ipp32s)Stat.dfRenderTime/3600,(Ipp32s)(Stat.dfRenderTime)%3600/60,(Ipp32s)Stat.dfRenderTime%3600%60);
vm_string_fprintf(perf_file,VM_STRING("\n" ));
vm_file_fclose(perf_file);
}
break;
default:
break;
}
}
UMC::Status AddPerfRecord(vm_char* szProfFileName, vm_char* szMessage, ...)
{
UMC::Status umcRes = UMC::UMC_OK;
vm_file* pFile = NULL;
if (NULL != szProfFileName && 0 != szProfFileName[0])
{ pFile = vm_file_open(szProfFileName, VM_STRING("a+t")); }
if (NULL != pFile)
{
va_list vl;
va_start( vl, szMessage );
vm_string_vfprintf(pFile, szMessage, vl);
va_end(vl);
}
if (NULL != pFile)
{ vm_file_fclose(pFile); }
return umcRes;
}
UMC::Status PlaySingleFile(AVSync& rAVSync,
AVSync::CommonCtl& r_cc,
vm_char* szFileName,
vm_char* szProfFileName,
Ipp32u uiIterateNum,
vm_char* pcStopFlag)
{
UMC::Status umcRes = UMC::UMC_OK;
UMC :: SysInfo m_csysinfo;
VM_ASSERT(0 < uiIterateNum);
UMC::LocalReaderContext readContext;
vm_string_strcpy(readContext.m_szFileName, szFileName);
r_cc.pReadContext = &readContext;
if (UMC::UMC_OK == umcRes &&
NULL != szProfFileName &&
0 != szProfFileName[0])
{
if (vm_string_strcmp(VM_STRING(".csv"),
szProfFileName +
(vm_string_strrchr(szProfFileName,
(vm_char)('.')) - szProfFileName)))
{
umcRes =
AddPerfRecord(szProfFileName,
VM_STRING("Stream %s, %d iterations:\n"),
szFileName,
uiIterateNum);
}else{
PerfToFile(rAVSync,r_cc,m_csysinfo,szFileName,szProfFileName,0);
}
}
Ipp32u uiFrameNum = 0;
Ipp64f dfDecodeTime = 0.0;
Ipp64f dfRenderTime = 0.0;
Ipp64f dfAudioDecTime = 0.0;
Ipp64f dfAudioTime = 0.0;
for (Ipp32u uiTeration = 0;
UMC::UMC_OK == umcRes && uiTeration < uiIterateNum;
uiTeration++)
{
AVSync::Stat Stat;
umcRes = rAVSync.Init(r_cc);
r_cc.rectDisp.bottom = rAVSync.GetDstFrmHeight();
r_cc.rectDisp.right = rAVSync.GetDstFrmWidth();
r_cc.rectRange.bottom = rAVSync.GetDstFrmHeight();
r_cc.rectRange.right = rAVSync.GetDstFrmWidth();
rAVSync.ResizeDisplay(r_cc.rectDisp,r_cc.rectRange);
m_csysinfo.GetCpuUsage();
if (UMC::UMC_OK == umcRes)
{ umcRes = rAVSync.Start(); }
Ipp32u i = 0;
while (UMC::UMC_OK == umcRes && rAVSync.IsPlaying())
{
#if defined(WIN32)
#if defined(_WIN32_WCE)
if (0 == *pcStopFlag)
{
#else // defined(_WIN32_WCE)
if (kbhit())
{
_getch();
#endif // defined(_WIN32_WCE)
umcRes = rAVSync.Stop(); }
else
#endif // defined(WIN32) && !defined(_WIN32_WCE)
{
umcRes = rAVSync.GetStat(Stat);
// if (i >= 100) {
if (i < Stat.uiFramesDecoded)
{
if (UMC::UMC_OK == umcRes)
{
Ipp64f dfDecTime = (Stat.dfDecodeRate) ? 1000/Stat.dfDecodeRate : 0;
Ipp64f dfConvertTime = (Stat.dfConversionRate) ? 1000/Stat.dfConversionRate : 0;
//vm_debug_trace(VM_DEBUG_NONE,
vm_string_printf( VM_STRING("DecRate:%.2f fps(Dec %.2fms/f + Conv %.2fms/f = %.2fms/f) RndrRate %.2ffps Audio Dec %.2fchnls \r\n"),
Stat.dfDecodeRate,
dfDecTime - dfConvertTime,
dfConvertTime,
dfDecTime,
Stat.dfRenderRate,
(Stat.dfAudioDecodeTime) ? Stat.dfAudioPlayTime/Stat.dfAudioDecodeTime : 0);
}
// i = 0;
i += 100;
}
// i++;
vm_time_sleep(300/*500*/);
m_csysinfo.GetCpuUsage();
}
}
m_csysinfo.GetCpuUsage();
if (UMC::UMC_OK == umcRes &&
NULL != szProfFileName &&
0 != szProfFileName[0])
{
umcRes = rAVSync.GetStat(Stat);
uiFrameNum += Stat.uiFramesDecoded;
dfDecodeTime += Stat.dfDecodeTime;
dfRenderTime += Stat.dfRenderTime;
dfAudioDecTime += Stat.dfAudioDecodeTime;
dfAudioTime += Stat.dfAudioPlayTime;
if (uiTeration == uiIterateNum - 1)
{
if(vm_string_strcmp(VM_STRING(".csv"),szProfFileName+(vm_string_strrchr(szProfFileName, (vm_char)('.')) - szProfFileName)))
AddPerfRecord(szProfFileName,
VM_STRING("DecRate: %.2f fps(%.2f ms/f) Rndr rate %.2f fps Audio Dec %.2f chnls\n\n"),
(dfDecodeTime) ? (Ipp64f)uiFrameNum / dfDecodeTime : 0,
(uiFrameNum) ? dfDecodeTime * 1000 / uiFrameNum : 0,
(dfRenderTime) ? (Ipp64f)uiFrameNum / dfRenderTime : 0,
(dfAudioDecTime) ? dfAudioTime / dfAudioDecTime : 0);
else PerfToFile(rAVSync,r_cc,m_csysinfo,szFileName,szProfFileName,1);
}
}
rAVSync.Stop();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -