fdkaacenc: Add support for setting peak bitrate

This commit is contained in:
Sanchayan Maity 2021-01-31 22:00:36 +05:30
parent 734593ccab
commit 595dd7a1ed
3 changed files with 53 additions and 3 deletions

View file

@ -16739,7 +16739,21 @@
"readable": true,
"type": "gint",
"writable": true
}
},
"peak-bitrate": {
"blurb": "Peak Bitrate to adjust maximum bits per audio frame. Bitrate is in bits/second. (0 = Not set)",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "0",
"max": "2147483647",
"min": "0",
"mutable": "null",
"readable": true,
"type": "gint",
"writable": true
}
},
"rank": "primary"
}
@ -237425,4 +237439,4 @@
"tracers": {},
"url": "Unknown package origin"
}
}
}

View file

@ -39,10 +39,12 @@ enum
{
PROP_0,
PROP_AFTERBURNER,
PROP_BITRATE
PROP_BITRATE,
PROP_PEAK_BITRATE
};
#define DEFAULT_BITRATE (0)
#define DEFAULT_PEAK_BITRATE (0)
#define SAMPLE_RATES " 8000, " \
"11025, " \
@ -113,6 +115,9 @@ gst_fdkaacenc_set_property (GObject * object, guint prop_id,
case PROP_AFTERBURNER:
self->afterburner = g_value_get_boolean (value);
break;
case PROP_PEAK_BITRATE:
self->peak_bitrate = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -133,6 +138,9 @@ gst_fdkaacenc_get_property (GObject * object, guint prop_id,
case PROP_AFTERBURNER:
g_value_set_boolean (value, self->afterburner);
break;
case PROP_PEAK_BITRATE:
g_value_set_int (value, self->peak_bitrate);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -434,6 +442,17 @@ gst_fdkaacenc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
return FALSE;
}
if (self->peak_bitrate) {
if ((err = aacEncoder_SetParam (self->enc, AACENC_PEAK_BITRATE,
self->peak_bitrate)) != AACENC_OK) {
GST_ERROR_OBJECT (self, "Unable to set peak bitrate %d: %d",
self->peak_bitrate, err);
return FALSE;
}
GST_INFO_OBJECT (self, "Setting peak bitrate to %d", self->peak_bitrate);
}
if (self->afterburner) {
if ((err =
aacEncoder_SetParam (self->enc, AACENC_AFTERBURNER,
@ -631,6 +650,7 @@ gst_fdkaacenc_init (GstFdkAacEnc * self)
self->enc = NULL;
self->is_drained = TRUE;
self->afterburner = FALSE;
self->peak_bitrate = DEFAULT_PEAK_BITRATE;
gst_audio_encoder_set_drainable (GST_AUDIO_ENCODER (self), TRUE);
}
@ -660,6 +680,21 @@ gst_fdkaacenc_class_init (GstFdkAacEncClass * klass)
0, G_MAXINT, DEFAULT_BITRATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstFdkAacEnc:peak-bitrate:
*
* Peak Bitrate to adjust maximum bits per audio frame.
*
* Since: 1.22
*/
g_object_class_install_property (object_class, PROP_PEAK_BITRATE,
g_param_spec_int ("peak-bitrate",
"Peak Bitrate",
"Peak Bitrate to adjust maximum bits per audio frame. "
"Bitrate is in bits/second. (0 = Not set)",
0, G_MAXINT, DEFAULT_PEAK_BITRATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstFdkAacEnc:afterburner:
*

View file

@ -52,6 +52,7 @@ struct _GstFdkAacEnc {
const GstAudioChannelPosition *aac_positions;
gboolean is_drained;
guint peak_bitrate;
gboolean afterburner;
};