📄 umc_h264_base.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) 2004 - 2007 Intel Corporation. All Rights Reserved.
//
#include <string.h>
#include "umc_h264_video_encoder.h"
#include "umc_h264_core_enc.h"
#define ENCODER_SUPPORTS_IYUV
//#define USE_IMPLICIT_WEIGHTED_BIPRED
namespace UMC_H264_ENCODER
{
////////////////////////
// Determine buffer size
template <class PixType, class CoeffsType>
Ipp32u H264CoreEncoder<PixType,CoeffsType>::GetBsBufferMaxSize(const Ipp32u w, const Ipp32u h)
{
Ipp32u wpadded, hpadded;
Ipp32u size;
wpadded = (w + 0xf) & ~0xf;
hpadded = (h + 0xf) & ~0xf;
size = wpadded * hpadded * sizeof(PixType);
return ((size)+(size>>1)+4096);
// TBD: see if buffer size can be reduced
}
template <class PixType, class CoeffsType>
Status H264CoreEncoder<PixType,CoeffsType>::Set_Key_Frame_Controls(const H264_Key_Frame_Controls &kfc)
{
// if the current interval is one, and the new interval is not one
// the next frame must be forced intra to generate a new reference
// frame, note the encoder's decoder will be called when the interval
// is not one in the main encode loop, see bSkipDecoder
if ( m_info.key_frame_controls.method == H264_KFCM_INTERVAL
&& m_info.key_frame_controls.interval == 1 // cur interval
&& !(kfc.method == H264_KFCM_INTERVAL && kfc.interval == 1)
)
{
m_bMakeNextFrameKey = true;
}
m_info.key_frame_controls = kfc;
if (kfc.method == H264_KFCM_INTERVAL)
m_uIntraFrameInterval = kfc.interval;
else
m_uIntraFrameInterval = 0;
if (kfc.method == H264_KFCM_INTERVAL)
m_uIDRFrameInterval = kfc.idr_interval;
else
m_uIDRFrameInterval = 0;
// Set BRC local variables
//if (m_info.rate_controls.method == H264_RCM_CBR)
//{
// return UMC_ERR_UNSUPPORTED;
//}
return UMC_OK;
}
template <class PixType, class CoeffsType>
Status H264CoreEncoder<PixType,CoeffsType>::Make_Next_Frame_Key()
{
m_bMakeNextFrameKey = true;
return UMC_OK;
}
template <class PixType, class CoeffsType>
Status H264CoreEncoder<PixType,CoeffsType>::Set_B_Frames(Ipp32u number_of_B_frames)
{
Status ps = UMC_OK;
Ipp32s i = 0;
// TBD, if we have already begun compressing frames, do we need to
// do more work here to change our B frame generation pattern?
if( eFrameType != NULL )
delete [] eFrameType;
if( eFrameSeq != NULL )
delete [] eFrameSeq;
m_info.B_frame_rate = number_of_B_frames;
profile_frequency = number_of_B_frames + 1;
eFrameType = new EnumPicCodType[profile_frequency];
eFrameSeq = new H264EncoderFrame<PixType>* [profile_frequency+1];
for(i = 0; i<=profile_frequency; i++) eFrameSeq[i] = NULL;
#ifdef USE_IMPLICIT_WEIGHTED_BIPRED
m_info.use_implicit_weighted_bipred =
(number_of_B_frames > 1) ? 1 : 0;
#else
m_info.use_implicit_weighted_bipred = 0;
#endif
eFrameType[0] = PREDPIC;
for (i = 1; i < profile_frequency; i++)
{
eFrameType[i] = BPREDPIC;
}
return ps;
}
#ifdef _TEST_PARM_
template <class PixType, class CoeffsType>
Status H264CoreEncoder<PixType,CoeffsType>::Set_Test_Value (Ipp32s test_value)
{
Status ps = UMC_OK;
m_info.Test_Value = test_value;
return ps;
}
#endif
template <class PixType, class CoeffsType>
Status H264CoreEncoder<PixType,CoeffsType>::Set_Num_Slices(Ipp32u number_of_slices)
{
Status ps = UMC_OK;
if (number_of_slices >= 1)
{
m_info.num_slices = (Ipp16u) number_of_slices;
if( m_Slices != NULL ) delete [] m_Slices;
m_Slices = new H264EncoderThreadPrivateSlice<PixType, CoeffsType>[m_info.num_slices*((m_info.coding_type == 1) + 1)]; //TODO fix for PicAFF/AFRM
Ipp32s i;
for(i = 0; i < m_info.num_slices*((m_info.coding_type == 1) + 1); i++) { //TODO fix for PicAFF/AFRM
ps = m_Slices[i].Init(m_info);
if(ps != UMC_OK) return(ps);
}
}
else
{
ps = UMC_ERR_INVALID_STREAM;
}
return ps;
}
template <class PixType, class CoeffsType>
Status H264CoreEncoder<PixType,CoeffsType>::Set_Deblocking_Loop_Filter(Ipp8u filter_idc, Ipp32s alpha, Ipp32s beta)
{
Status ps = UMC_OK;
if (filter_idc > 2)
{
ps = UMC_ERR_INVALID_STREAM;
} else if ((alpha > 12) || (alpha < -12) || (beta > 12) || (beta < -12)) {
ps = UMC_ERR_INVALID_STREAM;
} else {
m_info.deblocking_filter_idc = filter_idc;
m_info.deblocking_filter_alpha = alpha;
m_info.deblocking_filter_beta = beta;
}
return ps;
}
#pragma warning(disable:4661)
template class H264CoreEncoder<Ipp8u, Ipp16s>;
template class H264EncoderThreadPrivateSlice<Ipp8u, Ipp16s>;
#if defined BITDEPTH_9_12
template class H264CoreEncoder<Ipp16u, Ipp32s>;
template class H264EncoderThreadPrivateSlice<Ipp16u, Ipp32s>;
#endif // BITDEPTH_9_12
} //namespace UMC_H264_ENCODER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -