📄 main.cpp
字号:
}
if (isSplitterRequired) {
audio_codec_params->m_pData = &in_data;
audio_codec_params->m_pData->SetBufferPointer((Ipp8u *)(spl_info->m_ppTrackInfo[trNumber]->m_pDecSpecInfo->GetDataPointer()),
spl_info->m_ppTrackInfo[trNumber]->m_pDecSpecInfo->GetDataSize());
audio_codec_params->m_pData->SetDataSize(spl_info->m_ppTrackInfo[trNumber]->m_pDecSpecInfo->GetDataSize());
audio_codec_params->m_pData->SetTime(0, 0);
pMediaBuffer = DynamicCast < MediaBuffer > (new SampleBuffer);
if (NULL == pMediaBuffer) {
vm_string_printf(VM_STRING("Memory allocation error\n"));
err = -1;
break;
}
} else {
audio_codec_params->m_pData = NULL;
pMediaBuffer = DynamicCast < MediaBuffer > (new LinearBuffer);
if (NULL == pMediaBuffer) {
vm_string_printf(VM_STRING("Memory allocation error\n"));
err = -1;
break;
}
}
media_buffer_params =
DynamicCast < MediaBufferParams > (new MediaBufferParams);
/* **********************************************************
* please, be attentive!
* size 1 frame of HE-AAC is 2048 sample (sample is 16 bit)
* so, size of memory has to be (nCh * 2048 * sizeof(Ipp16s))
* **********************************************************/
pOut = new MediaData(1024*2*10*2);// nCh = 10
if (NULL == pOut) {
vm_string_printf(VM_STRING("Memory allocation error\n"));
err = -1;
break;
}
media_buffer_params->m_numberOfFrames = 10;
media_buffer_params->m_prefInputBufferSize = 768 * 10;
codec_init.m_pCodec = pAudioCodec;
codec_init.m_pMediaBuffer = pMediaBuffer;
codec_init.m_pCodecInitParams = audio_codec_params;
codec_init.m_pMediaBufferParams = media_buffer_params;
sts = dual_treaded_codec.InitCodec(&codec_init);
if (sts != UMC_OK) {
vm_string_printf(VM_STRING("Failed to initalize codec plugin\n"));
return sts;
}
if (!params.isMP4MuxerRequired) {
err = p_out_file->Open(params.output_file, AudioFile::AFM_CREATE);
if (err) {
vm_debug_trace1(VM_DEBUG_ALL, __VM_STRING("Can't create output file '%s'"),
params.output_file);
vm_string_printf(__VM_STRING("Can't create output file '%s'"),
params.output_file);
err = -3;
break;
}
}
if (isSplitterRequired) {
sts = dual_treaded_codec.LockInputBuffer(&inMediaBuffer);
if (sts == UMC_OK) {
memcpy(inMediaBuffer.GetBufferPointer(), in_data.GetDataPointer(),
in_data.GetDataSize());
inMediaBuffer.SetDataSize(in_data.GetDataSize());
dual_treaded_codec.UnLockInputBuffer(&inMediaBuffer);
} // if (sts == UMC::UMC_OK)
} // if (isSplitterRequired)
if (params.isMP4MuxerRequired) {
pFileWriter = new FileWriter;
pFileWriterParams = new FileWriterParams;
pMP4Muxer = new MP4Muxer;
pMP4MuxerParams = new MuxerParams;
if ((pFileWriter == NULL) || (pFileWriterParams == NULL) ||
(pMP4Muxer == NULL) || (pMP4MuxerParams == NULL)) {
return UMC_ERR_FAILED;
}
pFileWriterParams->m_portion_size = 0;
vm_string_strcpy(pFileWriterParams->m_file_name,params.output_file);
umcRes = pFileWriter->Init(pFileWriterParams);
if (umcRes != UMC_OK)
return UMC_ERR_FAILED;
pMP4TrackParams = new TrackParams;
pMP4TrackParams->type = AUDIO_TRACK;
audio_codec_params->m_info_out.stream_type = AAC_AUDIO;
pMP4TrackParams->info.audio = &audio_codec_params->m_info_out;
pMP4MuxerParams->m_lpDataWriter = pFileWriter;
pMP4MuxerParams->m_nNumberOfTracks = 1;
pMP4MuxerParams->pTrackParams = pMP4TrackParams;
umcRes = pMP4Muxer->Init(pMP4MuxerParams);
if (umcRes != UMC_OK)
return UMC_ERR_NOT_INITIALIZED;
}
if (sts == UMC_OK) {
t_freq = vm_time_get_frequency();
t_end = 0;
if (!vm_string_strncmp(params.codec_name, VM_STRING("ac3_dec"), 7)) {
pAudioCodec->SetParams(DynamicCast<BaseCodecParams>(&(params.ac3dec_params)));
}
if (isSplitterRequired) {
do {
sts = dual_treaded_codec.LockInputBuffer(&inMediaBuffer);
if (sts == UMC_OK) {
umcRes = spl->GetNextData(&in_data, trNumber);
while (umcRes == UMC_ERR_NOT_ENOUGH_DATA) {
vm_time_sleep(5);
umcRes = spl->GetNextData(&in_data, trNumber);
}
memcpy(inMediaBuffer.GetBufferPointer(), in_data.GetDataPointer(),
in_data.GetDataSize());
inMediaBuffer.SetDataSize(in_data.GetDataSize());
VM_ASSERT(in_data.GetDataSize() <= inMediaBuffer.GetBufferSize());
dual_treaded_codec.UnLockInputBuffer(&inMediaBuffer);
}
do {
t_start = vm_time_get_tick();
sts = dual_treaded_codec.GetFrame(pOut);
t_end += (vm_time_get_tick() - t_start);
if (sts == UMC_OK) {
Ipp64f start, end;
p_out_file->Write(pOut->GetDataPointer(), pOut->GetDataSize());
numFramesToProcess++;
// vm_string_printf(VM_STRING("m_frame_num = %d\r"), numFramesToProcess);
pOut->GetTime(start, end);
}
} while (sts == UMC_OK);
} while ((umcRes != UMC_ERR_END_OF_STREAM) && (sts != UMC_ERR_INVALID_STREAM));
} else { /*** encoding ***/
do {
sts = dual_treaded_codec.LockInputBuffer(&inMediaBuffer);
if (sts == UMC_OK) {
size_t needSize = inMediaBuffer.GetBufferSize();
if (is_input_wav) {
if (info_file_in.resolution == 16) {
needSize = needSize & (~1);
} else if (info_file_in.resolution == 24) {
needSize = (needSize / 3) * 3;
} if (info_file_in.resolution == 32) {
needSize = needSize & (~3);
}
}
size = p_in_file->Read(inMediaBuffer.GetBufferPointer(), needSize);
inMediaBuffer.SetDataSize(size);
/* we should transform 24 and 32 bits input to 16 bits one */
if (is_input_wav) {
Ipp16s *tmp16 = (Ipp16s*)inMediaBuffer.GetBufferPointer();
int ii;
if (info_file_in.resolution == 24) {
Ipp8u *tmp8 = (Ipp8u*)inMediaBuffer.GetBufferPointer();
for (ii = 0; ii < size/3; ii++) {
#ifdef _BIG_ENDIAN_
Ipp32s tmp = (((((Ipp32s)tmp8[0]) << 24) >> 8) +
(((Ipp32s)tmp8[1]) << 8) +
((Ipp32s)tmp8[2]));
# else
Ipp32s tmp = (((((Ipp32s)tmp8[2]) << 24) >> 8) +
(((Ipp32s)tmp8[1]) << 8) +
((Ipp32s)tmp8[0]));
#endif
tmp16[ii] = (Ipp16s)((tmp + 128) >> 8);
tmp8 += 3;
}
inMediaBuffer.SetDataSize(2*(size/3));
} else if (info_file_in.resolution == 32) {
Ipp32s *tmp32 = (Ipp32s*)inMediaBuffer.GetBufferPointer();
for (ii = 0; ii < size/4; ii++) {
tmp16[ii] = (Ipp16s)((tmp32[ii] + 32768) >> 16);
}
inMediaBuffer.SetDataSize(2*(size/4));
}
}
if (size == needSize)
dual_treaded_codec.UnLockInputBuffer(&inMediaBuffer);
else
dual_treaded_codec.UnLockInputBuffer(&inMediaBuffer, UMC_ERR_END_OF_STREAM);
}
do {
t_start = vm_time_get_tick();
sts = dual_treaded_codec.GetFrame(pOut);
t_end += (vm_time_get_tick() - t_start);
if (params.isMP4MuxerRequired) {
if (sts == UMC_OK) {
umcRes = pMP4Muxer->PutData(pOut, 0);
if (umcRes != UMC_OK)
return UMC_ERR_FAILED;
} else {
int a = 0;
}
numFramesToProcess++;
vm_string_printf(VM_STRING("%d frames muxed\r"), numFramesToProcess);
} else {
if (sts == UMC_OK) {
Ipp64f start, end;
p_out_file->Write(pOut->GetDataPointer(), pOut->GetDataSize());
if (params.is_text_out) {
dbg_dump_array_16s((Ipp16s *)pOut->GetDataPointer(),
pOut->GetDataSize() / 2, VM_STRING("%s%07d.txt"),
params.output_txt, numFramesToProcess);
}
numFramesToProcess++;
// vm_string_printf(VM_STRING("m_frame_num = %d\r"), numFramesToProcess);
pOut->GetTime(start, end);
}
}
} while (sts == UMC_OK);
} while ((size) && (sts != UMC_ERR_INVALID_STREAM));
}
t_encode_time = (Ipp64f)((Ipp64s) (t_end)) / (Ipp64s) t_freq;
}
pAudioCodec->GetInfo(audio_codec_params);
//-----------------------------------------------------------------------------------------------------
/*
Ipp32f dur;
Ipp32s cpu_freq;
ippGetCpuFreqMhz(&cpu_freq);
pAudioCodec->GetDuration(&dur);
vm_string_printf(VM_STRING
("encoding/decoding time, sec : %f [%06d frames]\n"),
t_encode_time, numFramesToProcess);
vm_string_printf(VM_STRING("stream duration, sec : %f\n"), dur);
t_encode_time /= dur;
vm_string_printf(VM_STRING("performance,(sec/sec) : %f\n"),
t_encode_time);
//vm_string_printf(VM_STRING
// ("* multiply the performance by the cpu frequency to convert into mhz\n"));
vm_string_printf(VM_STRING("performance,(MHz) : %f\n"),
t_encode_time * cpu_freq );
*/
//-----------------------------------------------------------------------------------------------------
if (audio_codec_params->m_info_out.stream_type == PCM_AUDIO) {
info_file_out.format_tag = 1;
info_file_out.channels_number = audio_codec_params->m_info_out.channels;
info_file_out.sample_rate =
audio_codec_params->m_info_out.sample_frequency;
info_file_out.resolution = audio_codec_params->m_info_out.bitPerSample;
info_file_out.channel_mask = audio_codec_params->m_info_out.channel_mask;
wav_file_out.SetInfo(&info_file_out);
}
break;
} // while (1)
if (params.isMP4MuxerRequired) {
pMP4Muxer->PutEndOfStream(0);
delete pFileWriterParams;
delete pMP4Muxer;
delete pMP4MuxerParams;
delete pMP4TrackParams;
delete pFileWriter;
} else {
p_out_file->Close();
}
if (!isSplitterRequired)
p_in_file->Close();
if (pOut)
delete pOut;
if (pAudioCodec)
delete pAudioCodec;
pAudioCodec = NULL;
if (pMediaBuffer)
delete pMediaBuffer;
pMediaBuffer = NULL;
if (acp_allocated) {
if (audio_codec_params)
delete audio_codec_params;
}
audio_codec_params = NULL;
if (media_buffer_params)
delete media_buffer_params;
media_buffer_params = NULL;
if (!err) {
// vm_string_printf(VM_STRING("Processing is completed successfully\n"));
}
return err;
}
void LoadPlugins(Factory & factory)
{
// / Register static plugins into factory
factory.InitStatic();
#ifndef STATIC_OBJECTS_ONLY
#if defined (_WIN32_WCE)
factory.Load(VM_STRING("aac_dec_i.dll"));
factory.Load(VM_STRING("aac_enc_i.dll"));
factory.Load(VM_STRING("mp3_dec_i.dll"));
factory.Load(VM_STRING("mp3_enc_i.dll"));
#elif defined (WIN32)
factory.Load(VM_STRING("mp3_dec.dll"));
factory.Load(VM_STRING("mp3_dec_i.dll"));
factory.Load(VM_STRING("mp3_enc.dll"));
factory.Load(VM_STRING("mp3_enc_i.dll"));
factory.Load(VM_STRING("aac_dec.dll"));
factory.Load(VM_STRING("aac_dec_i.dll"));
factory.Load(VM_STRING("aac_enc.dll"));
factory.Load(VM_STRING("aac_enc_i.dll"));
factory.Load(VM_STRING("ac3_dec.dll"));
factory.Load(VM_STRING("dts_dec_d.dll"));
#elif defined (LINUX32)
factory.Load("libmp3_dec.so");
factory.Load("libmp3_dec_i.so");
factory.Load("libmp3_enc.so");
factory.Load("libmp3_enc_i.so");
factory.Load("libaac_dec.so");
factory.Load("libaac_dec_i.so");
factory.Load("libaac_enc.so");
factory.Load("libaac_enc_i.so");
factory.Load("libac3_dec.so");
#endif
#else /* STATIC_OBJECTS_ONLY */
#error Please select platform for building
#endif /* STATIC_OBJECTS_ONLY */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -