📄 umc_aac_encoder.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) 2003-2005 Intel Corporation. All Rights Reserved.////////// Created: 13-Aug-2003 17:42*/#include <string.h>#include "umc_audio_codec.h"#include "umc_aac_encoder.h"#include "umc_aac_encoder_params.h"#include "ipps.h"#include "aaccmn_adts.h"namespace UMC {#ifdef __cplusplusextern "C" {#endifvoid enc_adts_header(sAdts_fixed_header *pFixedHeader, sAdts_variable_header *pVarHeader, sBitsreamBuffer *pBS);#ifdef __cplusplus}#endif/****************************************************************************/AACEncoder::AACEncoder(){ state = NULL;}/****************************************************************************/AACEncoder::~AACEncoder(){ Close();}/****************************************************************************/IppBool AACEncoder::CheckBitRate(int br, int& ind){ if (br == 0) return ippFalse; return ippTrue;}/****************************************************************************/Status AACEncoder::Init(BaseCodecParams* init){ AACEncoderParams* pAACEncoderParams; AudioCodecParams* pAudioCodecInit = DynamicCast<AudioCodecParams, BaseCodecParams>(init); if (!pAudioCodecInit) return UMC_NULL_PTR; m_sampling_frequency = pAudioCodecInit->m_info_in.sample_frequency; m_channel_number = pAudioCodecInit->m_info_in.channels; m_bitrate = pAudioCodecInit->m_info_out.bitrate*1000; pAACEncoderParams = DynamicCast<AACEncoderParams, BaseCodecParams>(init); if (pAACEncoderParams) { m_audioObjectType = pAACEncoderParams->audioObjectType; } else { m_audioObjectType = AOT_AAC_LC; } if ((m_audioObjectType != AOT_AAC_LC) && (m_audioObjectType != AOT_AAC_LTP)) return UMC_FAILED_TO_INITIALIZE; if (m_audioObjectType == AOT_AAC_MAIN) m_adtsProfile = 0; else if (m_audioObjectType == AOT_AAC_LC) m_adtsProfile = 1; else if (m_audioObjectType == AOT_AAC_SSR) m_adtsProfile = 2; else if (m_audioObjectType == AOT_AAC_LTP) m_adtsProfile = 3; else m_adtsProfile = 4; m_adtsID = 1; if (m_adtsProfile >= 3) m_adtsID = 0; if (aacencInit(&state, m_sampling_frequency, m_channel_number, m_bitrate, m_audioObjectType) != AAC_OK) return UMC_FAILED_TO_INITIALIZE; return UMC_OK;}/****************************************************************************/Status AACEncoder::Close(){ aacencClose(state); state = NULL; return UMC_OK;}/****************************************************************************/Status AACEncoder::GetInfo(BaseCodecParams* info){ if (!info) return UMC_NULL_PTR; info->m_SuggestedInputSize = m_channel_number*sizeof(short)*1024; AudioCodecParams* pAudioCodecInfo = DynamicCast<AudioCodecParams, BaseCodecParams>(info); if (!pAudioCodecInfo) return UMC_OK; pAudioCodecInfo->m_info_in.bitPerSample = 16; pAudioCodecInfo->m_info_out.bitrate = m_bitrate; pAudioCodecInfo->m_info_in.channels = m_channel_number; pAudioCodecInfo->m_info_out.channels = m_channel_number; pAudioCodecInfo->m_info_in.sample_frequency = m_sampling_frequency; pAudioCodecInfo->m_info_out.sample_frequency = m_sampling_frequency; pAudioCodecInfo->m_info_in.stream_type = PCM_AUDIO; pAudioCodecInfo->m_info_out.stream_type = AAC_AUDIO; return UMC_OK;}/****************************************************************************/Status AACEncoder::GetFrame(MediaData* in, MediaData* out){ Ipp8u *outPointer; AACStatus result; int nSamples; int nEncodedBytes, headerBytes; sBitsreamBuffer BS; sBitsreamBuffer *pBS = &BS; sAdts_fixed_header adts_fixed_header; sAdts_variable_header adts_variable_header; int sampling_frequency_index; int rested_bytes; double pts_end; nSamples = (in->GetDataSize()/sizeof(short)); if (nSamples < m_channel_number * 1024) return UMC_NOT_ENOUGH_DATA; nSamples = m_channel_number * 1024; outPointer = (Ipp8u *)out->GetDataPointer(); result = aacencGetSampleFrequencyIndex(&sampling_frequency_index, state); INIT_BITSTREAM(pBS, outPointer) // Put to bistream ADTS header ! // Fixed header. adts_fixed_header.ID = m_adtsID; adts_fixed_header.Layer = 0; adts_fixed_header.protection_absent = 1; adts_fixed_header.Profile = m_adtsProfile; adts_fixed_header.sampling_frequency_index = sampling_frequency_index; adts_fixed_header.private_bit = 0; adts_fixed_header.channel_configuration = m_channel_number; adts_fixed_header.original_copy = 0; adts_fixed_header.Home = 0; // Variable header ! adts_variable_header.copyright_identification_bit = 0; adts_variable_header.copyright_identification_start = 0; adts_variable_header.aac_frame_length = 0; adts_variable_header.adts_buffer_fullness = 0x7FF; adts_variable_header.no_raw_data_blocks_in_frame = 0; enc_adts_header(&adts_fixed_header, &adts_variable_header, pBS); SAVE_BITSTREAM(pBS) Byte_alignment(pBS); GET_BITS_COUNT(pBS, headerBytes) headerBytes >>= 3; result = aacencGetFrame((Ipp16s *)in->GetDataPointer(), &nEncodedBytes, outPointer + headerBytes, state); adts_variable_header.aac_frame_length = headerBytes + nEncodedBytes; INIT_BITSTREAM(pBS, outPointer) enc_adts_header(&adts_fixed_header, &adts_variable_header, pBS); SAVE_BITSTREAM(pBS) rested_bytes = in->GetDataSize()- nSamples*sizeof(short); pts_end = in->GetTime()+(float)(nSamples/m_channel_number)/(float)(m_sampling_frequency); out->SetTime(in->GetTime(), pts_end); out->SetDataSize(headerBytes + nEncodedBytes); in->MoveDataPointer(nSamples*sizeof(short)); if (rested_bytes) { in->SetTime(pts_end); } return UMC_OK;}/****************************************************************************/Status AACEncoder::GetDuration(float* p_duration){ aacencGetDuration(p_duration, state); return UMC_OK;}/****************************************************************************/};//namespace UMC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -