Skip to content

Commit

Permalink
264_enc: apply encode base class for AVC SVC-T
Browse files Browse the repository at this point in the history
Calling base class's functions to set framerate and bitrate for
AVC SVC-T encoding.

Signed-off-by: wudping <[email protected]>
  • Loading branch information
dongpingx committed Jun 22, 2017
1 parent c436060 commit 8c975f1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
19 changes: 6 additions & 13 deletions encoder/vaapiencoder_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,7 @@ void VaapiEncoderBase::fill(VAEncMiscParameterRateControl* rateControl, uint32_t
#if VA_CHECK_VERSION(0, 39, 4)
rateControl->rc_flags.bits.temporal_id = temproalID;
#endif
rateControl->bits_per_second = ((temproalID == 0) ?
m_videoParamCommon.rcParams.bitRate : m_videoParamCommon.temporalLayers.bitRate[temproalID-1]);
rateControl->bits_per_second = m_videoParamCommon.temporalLayers.bitRate[temproalID];
rateControl->initial_qp = m_videoParamCommon.rcParams.initQP;
rateControl->min_qp = m_videoParamCommon.rcParams.minQP;
/*FIXME: where to find max_qp */
Expand All @@ -471,14 +470,9 @@ void VaapiEncoderBase::fill(VAEncMiscParameterFrameRate* frameRate, uint32_t tem
#if VA_CHECK_VERSION(0, 39, 4)
frameRate->framerate_flags.bits.temporal_id = temproalID;
#endif
const VideoFrameRate* rate;
if (!temproalID) {
rate = &m_videoParamCommon.frameRate;
} else {
rate = &m_videoParamCommon.temporalLayers.frameRate[temproalID-1];
}
frameRate->framerate = (rate->frameRateNum<<16) | rate->frameRateDenom;
frameRate->framerate = m_videoParamCommon.temporalLayers.frameRate[temproalID].frameRateNum | (m_videoParamCommon.temporalLayers.frameRate[temproalID].frameRateDenom << 16);
}

bool VaapiEncoderBase::ensureRateControl(VaapiEncPicture* picture, uint32_t temproalID)
{
VAEncMiscParameterRateControl* rateControl = NULL;
Expand Down Expand Up @@ -514,13 +508,12 @@ bool VaapiEncoderBase::ensureMiscParams (VaapiEncPicture* picture)
if (mode == RATE_CONTROL_CBR ||
mode == RATE_CONTROL_VBR) {
//+1 for layer 0
uint32_t layers = m_videoParamCommon.temporalLayers.numLayers + 1;
uint32_t layers = m_videoParamCommon.temporalLayers.numLayers;
for (uint32_t i = 0; i < layers; i++) {
if (!ensureRateControl(picture, i))
return false;

return false;
if (!ensureFrameRate(picture, i))
return false;
return false;
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion encoder/vaapiencoder_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class VaapiEncoderBase : public IVideoEncoder {
//rate control related things
void fill(VAEncMiscParameterHRD*) const ;
void fill(VAEncMiscParameterRateControl*, uint32_t temproalID = 0) const ;
void fill(VAEncMiscParameterFrameRate*, uint32_t temproalID) const;
void fill(VAEncMiscParameterFrameRate*, uint32_t temproalID = 0) const;
virtual bool ensureMiscParams(VaapiEncPicture*);
bool ensureRateControl(VaapiEncPicture * picture, uint32_t temproalID);
bool ensureFrameRate(VaapiEncPicture * picture, uint32_t temproalID);
Expand Down
18 changes: 14 additions & 4 deletions encoder/vaapiencoder_h264.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,16 @@ void VaapiEncoderH264::resetParams ()
DEBUG("resetParams, ensureCodedBufferSize");
ensureCodedBufferSize();

m_temporalLayerNum = m_videoParamCommon.temporalLayers.numLayers + 1;
m_temporalLayerNum = m_videoParamCommon.temporalLayers.numLayers;
for (uint32_t i = 0; i < m_temporalLayerNum - 1; i++) {
uint32_t expTemId = (1 << (m_temporalLayerNum - 1 - i));
m_videoParamCommon.temporalLayers.frameRate[i].frameRateDenom = expTemId;
m_videoParamCommon.temporalLayers.frameRate[i].frameRateNum = fps();
}
//The highest layer's bitrate and framerate are bitRate() and fps().
m_videoParamCommon.temporalLayers.frameRate[m_temporalLayerNum - 1].frameRateDenom = 0;
m_videoParamCommon.temporalLayers.frameRate[m_temporalLayerNum - 1].frameRateNum = fps();
m_videoParamCommon.temporalLayers.bitRate[m_temporalLayerNum - 1] = bitRate();

// enable prefix nal unit for simulcast or svc-t
if (m_temporalLayerNum > 1 || m_videoParamAVC.priorityId)
Expand Down Expand Up @@ -1300,9 +1309,6 @@ void VaapiEncoderH264::fill(
/* Generates additional control parameters */
bool VaapiEncoderH264::ensureMiscParams(VaapiEncPicture* picture)
{
if (!VaapiEncoderBase::ensureMiscParams(picture))
return false;

VideoRateControl mode = rateControlMode();
if (mode == RATE_CONTROL_CBR || mode == RATE_CONTROL_VBR) {
#if VA_CHECK_VERSION(0, 39, 4)
Expand All @@ -1316,6 +1322,10 @@ bool VaapiEncoderH264::ensureMiscParams(VaapiEncPicture* picture)
}
#endif
}

if (!VaapiEncoderBase::ensureMiscParams(picture))
return false;

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion encoder/vaapiencoder_vp8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ bool VaapiEncoderVP8::fill(VAEncPictureParameterBufferVP8* picParam, const Pictu
}

picParam->coded_buf = picture->getCodedBufferID();
picParam->ref_flags.bits.temporal_id = picture->m_temporalID;
//picParam->ref_flags.bits.temporal_id = picture->m_temporalID;

picParam->pic_flags.bits.show_frame = 1;
/*TODO: multi partition*/
Expand Down
7 changes: 2 additions & 5 deletions interface/VideoEncoderDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ typedef struct VideoFrameRate {
uint32_t frameRateDenom;
}VideoFrameRate;
typedef struct VideoTemproalLayers {
//how many layers higher than layer 0
//layer 0 framerate is VideoParamsCommon.frameRate
//layer 0 bitrate is VideoParamsCommon.rcParams.bitRate
//layer 1 framterate is frameRate[0]
//layer 1 birate is bitRate[0]
//framerate of the highest layer is VideoParamsCommon.frameRate
//bitrate of the highest layer is VideoParamsCommon.rcParams.bitRate
uint8_t numLayers;
VideoFrameRate frameRate[32];
uint32_t bitRate[32];
Expand Down

0 comments on commit 8c975f1

Please sign in to comment.