📄 codec_pipeline.cpp
字号:
}
}
}
if (NULL != rpRender)
vm_string_printf(VM_STRING("Audio Render :\t\t%s\n"), UMC::GetAudioRenderTypeString((UMC::AudioRenderType)ulPrefferedRender));
return umcRes;
}
Status
CodecPipeline::SelectAudioRender(sAudioStreamInfo& rAudioInfo,
ModuleContext& rContext,
AudioRender*& rpAudioRender,
Ipp32u ulPrefferedRender,
vm_char* szOutputAudio)
{
Status umcRes = UMC_OK;
delete rpAudioRender;
FWAudioRenderParams AudioRenderInit;
AudioRenderInit.info = rAudioInfo;
AudioRenderInit.pModuleContext = &rContext;
AudioRenderInit.pOutFile = (vm_string_strlen(szOutputAudio))? szOutputAudio:NULL;
if (UMC_OK == umcRes) {
umcRes = SelectAudioRender(AudioRenderInit, rpAudioRender,ulPrefferedRender);
if (UMC_OK != umcRes) {
vm_debug_message(__VM_STRING("CodecPipeline::SelectAudioRender Failed to init"));
}
}
return umcRes;
}
Status
CodecPipeline::SelectAudioDecoder(sAudioStreamInfo& rAudioInfo,
BaseCodec*& rpAudioDecoder)
{
Status umcRes = UMC_OK;
delete rpAudioDecoder;
#if defined(UMC_ENABLE_AMR_AUDIO_DECODER)
USC_LoadCodec loadUsc;
LoadedCodec lCodec;
Ipp32s lCallResult;
#endif
if (UMC_OK == umcRes)
{
switch(rAudioInfo.stream_type)
{
#if defined(UMC_ENABLE_AMR_AUDIO_DECODER)
case AMR_NB_AUDIO:
strcpy((char*)lCodec.codecName, "GSMAMR");
lCallResult = loadUsc.LoadUSCCodecByName(&lCodec);
if (lCallResult)
{
umcRes = UMC_ERR_ALLOC;
break;
}
rpAudioDecoder = DynamicCast<BaseCodec>(new SpeechDecoder((USC_Fxns*)lCodec.USC_Fns));
if (NULL == rpAudioDecoder)
umcRes = UMC_ERR_ALLOC;
break;
#endif
case PCM_AUDIO:
case LPCM_AUDIO:
rpAudioDecoder = NULL;
break;
#if defined(UMC_ENABLE_MP3_AUDIO_DECODER)
case MP1L1_AUDIO:
case MP1L2_AUDIO:
case MP1L3_AUDIO:
case MP2L1_AUDIO:
case MP2L2_AUDIO:
case MP2L3_AUDIO:
case MPEG1_AUDIO:
case MPEG2_AUDIO:
rpAudioDecoder = DynamicCast<BaseCodec>(new MP3Decoder);
if (NULL == rpAudioDecoder)
{ umcRes = UMC_ERR_ALLOC; }
break;
#elif defined(UMC_ENABLE_MP3_INT_AUDIO_DECODER)
case MP1L2_AUDIO:
case MP1L3_AUDIO:
case MP2L2_AUDIO:
case MP2L3_AUDIO:
case MPEG1_AUDIO:
case MPEG2_AUDIO:
rpAudioDecoder = DynamicCast<BaseCodec>(new MP3DecoderInt);
if (NULL == rpAudioDecoder)
{ umcRes = UMC_ERR_ALLOC; }
break;
#endif // defined(UMC_ENABLE_MP3_AUDIO_DECODER)
#if defined(UMC_ENABLE_AAC_AUDIO_DECODER)
case AAC_AUDIO:
case AAC_MPEG4_STREAM:
rpAudioDecoder = DynamicCast<BaseCodec>(new AACDecoder);
if (NULL == rpAudioDecoder)
{ umcRes = UMC_ERR_ALLOC; }
break;
#elif defined(UMC_ENABLE_AAC_INT_AUDIO_DECODER)
case AAC_AUDIO:
case AAC_MPEG4_STREAM:
rpAudioDecoder = DynamicCast<BaseCodec>(new AACDecoderInt);
if (NULL == rpAudioDecoder)
{ umcRes = UMC_ERR_ALLOC; }
break;
#endif // defined(UMC_ENABLE_AAC_INT_AUDIO_DECODER)
#if defined(UMC_ENABLE_AC3_AUDIO_DECODER)
case AC3_AUDIO:
rpAudioDecoder = DynamicCast<BaseCodec>(new AC3Decoder);
if (NULL == rpAudioDecoder)
{ umcRes = UMC_ERR_ALLOC; }
break;
#endif // defined(UMC_ENABLE_AC3_AUDIO_DECODER)
case UNDEF_AUDIO:
case TWINVQ_AUDIO:
default:
vm_debug_message(VM_STRING("Unsupported audio format!\n"));
rpAudioDecoder = NULL;
umcRes = UMC_ERR_INVALID_STREAM;
break;
}
}
if (UMC_OK != umcRes)
{ vm_debug_trace(VM_DEBUG_INFO,VM_STRING("BaseCodec::SelectAudioDecoder failed!\n")); }
return umcRes;
}
Status
CodecPipeline::SelectDTAudioDecoder(sAudioStreamInfo& rAudioInfo,
BaseCodec*& rpAudioDecoder,
DualThreadedCodec*& rpDSAudioCodec,
MediaBuffer*& rpMediaBuffer,
MediaData* pDecSpecInfo)
{
Status umcRes = UMC_OK;
if (UMC_OK == umcRes)
{ umcRes = SelectAudioDecoder(rAudioInfo, rpAudioDecoder); }
// Init from splitter
if (UMC_OK == umcRes &&
UNDEF_AUDIO != rAudioInfo.stream_type &&
NULL != rpAudioDecoder)
{
AudioCodecParams audioParams;
MediaBufferParams CyclicBufferPrm;
DualThreadCodecParams CodecPrm;
if (NULL != rpDSAudioCodec) { delete rpDSAudioCodec; }
if (NULL != rpMediaBuffer) { delete rpMediaBuffer; }
rpDSAudioCodec = new DualThreadedCodec;
if (NULL == rpAudioDecoder) { umcRes = UMC_ERR_ALLOC; }
if (UMC_OK == umcRes) {
if (rAudioInfo.stream_type != UMC::AAC_MPEG4_STREAM)
rpMediaBuffer = DynamicCast<MediaBuffer>(new LinearBuffer);
else {
// due to nature of AAC bitstream wrapped into MP4 files
// sample buffer is required
rpMediaBuffer = DynamicCast<MediaBuffer>(new SampleBuffer);
}
if (NULL == rpMediaBuffer) { umcRes = UMC_ERR_ALLOC; }
}
if (UMC_OK == umcRes) {
audioParams.m_info_in = rAudioInfo;
audioParams.m_info_out = rAudioInfo;
audioParams.m_pData = pDecSpecInfo;
// audioParams.m_info_in.channels = audioParams.m_info.channels;
// audioParams.m_info_out.channels = audioParams.m_info.channels;
CyclicBufferPrm.m_numberOfFrames = 100;
if(pDecSpecInfo)
{
Ipp32s size = pDecSpecInfo->GetDataSize();
CyclicBufferPrm.m_prefInputBufferSize = (size < 188) ? 188: size;
}
else
CyclicBufferPrm.m_prefInputBufferSize = 2304;
CodecPrm.m_pCodec = rpAudioDecoder;
CodecPrm.m_pMediaBuffer = rpMediaBuffer;
CodecPrm.m_pCodecInitParams = &audioParams;
CodecPrm.m_pMediaBufferParams = &CyclicBufferPrm;
umcRes = rpDSAudioCodec->InitCodec(&CodecPrm);
// It's not a loop but some approach to error handling
if (pDecSpecInfo)
for (;;)
{
MediaData data;
umcRes = rpMediaBuffer->LockInputBuffer(&data);
if (UMC_OK != umcRes)
{ break; }
if (data.GetBufferSize() < pDecSpecInfo->GetDataSize())
{
umcRes = UMC_ERR_ALLOC;
break;
}
// copy
memcpy(data.GetDataPointer(),pDecSpecInfo->GetDataPointer(),pDecSpecInfo->GetDataSize());
data.SetDataSize(pDecSpecInfo->GetDataSize());
data.SetTime(pDecSpecInfo->GetTime());
umcRes = rpMediaBuffer->UnLockInputBuffer(&data);
break;
}
}
if (UMC_OK != umcRes) {
if (NULL != rpAudioDecoder) {
delete rpAudioDecoder;
rpAudioDecoder = NULL;
}
if (NULL != rpDSAudioCodec) {
delete rpDSAudioCodec;
rpDSAudioCodec = NULL;
}
if (NULL != rpMediaBuffer) {
delete rpMediaBuffer;
rpMediaBuffer = NULL;
}
}
}
if (UMC_OK != umcRes)
{ vm_debug_trace(VM_DEBUG_INFO,VM_STRING("DualThreadedCodec::SelectDualThreadedCodec failed!\n")); }
return umcRes;
}
Status CodecPipeline::SelectSplitter(SourceInfo *lpSourceInfo,
Ipp32u uiSplitterFlags,
Splitter*& rpSplitter,
Ipp32u uiSelectedVideoPID,
Ipp32u uiSelectedAudioPID)
{
Status umcRes = UMC_OK;
SourceInfoCam *lpCamInfo = NULL;
SourceInfoNet *lpNetInfo = NULL;
SourceInfoFile *lpFileInfo = NULL;
SelfDestructionObject<SplitterParams> lpSplParams;
// delete existing splitter
if (rpSplitter)
delete rpSplitter;
rpSplitter = NULL;
// try to create cam splitter
if (lpCamInfo = DynamicCast<SourceInfoCam> (lpSourceInfo))
{
#if defined(WIN32) && !defined(_WIN32_WCE) && defined (UMC_ENABLE_TRANSCODING)
lpSplParams = new SplitterParams();
if (NULL == lpSplParams)
umcRes = UMC::UMC_ERR_FAILED;
rpSplitter = new CaptureEx();
#endif // defined(WIN32) && !defined(_WIN32_WCE)
if (NULL == rpSplitter)
umcRes = UMC::UMC_ERR_FAILED;
}
// try to create net splitter
else if (lpNetInfo = DynamicCast<SourceInfoNet> (lpSourceInfo))
{
umcRes = UMC::UMC_ERR_NOT_IMPLEMENTED;
}
// try to create file splitter
else if (lpFileInfo = DynamicCast<SourceInfoFile> (lpSourceInfo))
{
return SelectSplitter(lpFileInfo->m_lpDataReader,
uiSplitterFlags,
rpSplitter,
uiSelectedVideoPID,
uiSelectedAudioPID);
}
// try to create unknown splitter
else
umcRes = UMC::UMC_ERR_UNSUPPORTED;
// initialize created splitter
if (UMC_OK == umcRes)
{
lpSplParams->m_lFlags = uiSplitterFlags;
umcRes = rpSplitter->Init(*lpSplParams);
if (UMC_OK != umcRes)
vm_debug_message(__VM_STRING("Failed to initialize splitter "));
}
return umcRes;
} //Status CodecPipeline::SelectSplitter(SourceInfo *lpSourceInfo,
Status
CodecPipeline::SelectSplitter(DataReader* pDataReader,
Ipp32u uiSplitterFlags,
Splitter*& rpSplitter,
Ipp32u uiSelectedVideoPID,
Ipp32u uiSelectedAudioPID)
{
Status umcRes = UMC_OK;
SelfDestructionObject<SplitterParams> lpSplParams;
if(rpSplitter)
delete rpSplitter;
rpSplitter = 0;
lpSplParams = new SplitterParams();
if (0 == lpSplParams)
{ umcRes = UMC_ERR_ALLOC;}
if (UMC_OK == umcRes) {
switch(Splitter::GetStreamType(pDataReader))
{
#if defined(UMC_ENABLE_MPEG2_SPLITTER)
case MPEGx_SYSTEM_STREAM:
rpSplitter = new ThreadedDemuxer();
break;
#endif // UMC_ENABLE_MPEG2_SPLITTER
#if defined(UMC_ENABLE_MP4_SPLITTER)
case MP4_ATOM_STREAM:
rpSplitter = new MP4Splitter();
break;
#endif // defined(UMC_ENABLE_ATOM_SPLITTER)
#if defined(UMC_ENABLE_AVI_SPLITTER)
case AVI_STREAM:
rpSplitter = (Splitter*)new AVISplitter();
break;
#endif // defined(UMC_ENABLE_AVI_SPLITTER)
#if defined(UMC_ENABLE_VC1_SPLITTER)
case VC1_PURE_VIDEO_STREAM:
rpSplitter = (Splitter*)new VC1Splitter();
break;
#endif
#if defined(UMC_ENABLE_AVS_SPLITTER)
case AVS_PURE_VIDEO_STREAM:
rpSplitter = (Splitter*)new AVSSplitter();
break;
#endif
default:
umcRes = UMC_ERR_UNSUPPORTED;
}
}
if (UMC_OK == umcRes && NULL == rpSplitter)
{ umcRes = UMC_ERR_ALLOC; }
if (UMC_OK == umcRes) {
lpSplParams->m_lFlags = uiSplitterFlags;
lpSplParams->m_pDataReader = pDataReader;
lpSplParams->m_uiSelectedAudioPID = uiSelectedAudioPID;
lpSplParams->m_uiSelectedVideoPID = uiSelectedVideoPID;
umcRes = rpSplitter->Init(*lpSplParams);
if (UMC_OK == umcRes)
umcRes = rpSplitter->Run();
if (UMC_OK != umcRes) {
vm_debug_message(VM_STRING("Failed to initialize splitter\n"));
}
}
return umcRes;
}
Status
CodecPipeline::SelectVideoDecoder(sVideoStreamInfo& rVideoInfo,
MediaData* pDecSpecInfo,
Ipp32u lInterpolation,
Ipp32u lDeinterlacing,
Ipp32u numThreads,
Ipp32u ulVideoDecoderFlags,
BaseCodec& rColorConverter,
VideoDecoder*& rpVideoDecoder)
{
Status umcRes = UMC_OK;
VideoDecoderParams VDecParams;
if (rpVideoDecoder) {
delete rpVideoDecoder;
rpVideoDecoder = NULL;
}
rpVideoDecoder = CreateVideoDecoder(rVideoInfo.stream_type);
if (!rpVideoDecoder) {
return UMC_ERR_UNSUPPORTED;
}
VDecParams.info.stream_type = rVideoInfo.stream_type;
if (pDecSpecInfo && pDecSpecInfo->GetDataSize()) {
VDecParams.m_pData = pDecSpecInfo;
}
if (UMC_OK == umcRes) {
VideoProcessingParams postProcessingParams;
postProcessingParams.m_DeinterlacingMethod = (DeinterlacingMethod)lDeinterlacing;
postProcessingParams.InterpolationMethod = lInterpolation;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -