[vlc-commits] fdkaac: simplify parameters checks
Rafaël Carré
git at videolan.org
Sat May 3 18:00:02 CEST 2014
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Fri May 2 16:06:55 2014 +0200| [590285ccc83fbeb8d363e0858182ac60facc5f33] | committer: Rafaël Carré
fdkaac: simplify parameters checks
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=590285ccc83fbeb8d363e0858182ac60facc5f33
---
modules/codec/fdkaac.c | 67 +++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 35 deletions(-)
diff --git a/modules/codec/fdkaac.c b/modules/codec/fdkaac.c
index 4920519..59960d1 100644
--- a/modules/codec/fdkaac.c
+++ b/modules/codec/fdkaac.c
@@ -180,14 +180,32 @@ static int OpenEncoder(vlc_object_t *p_this)
{
encoder_t *p_enc = (encoder_t *)p_this;
- if (p_enc->fmt_out.i_codec != VLC_FOURCC('l', 'a', 'a', 'c') &&
- p_enc->fmt_out.i_codec != VLC_FOURCC('h', 'a', 'a', 'c') &&
- p_enc->fmt_out.i_codec != VLC_FOURCC('s', 'a', 'a', 'c') &&
- p_enc->fmt_out.i_codec != VLC_CODEC_MP4A)
- {
+ config_ChainParse(p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg);
+
+ int i_aot;
+ switch (p_enc->fmt_out.i_codec) {
+ case VLC_CODEC_MP4A:
+ i_aot = var_InheritInteger(p_enc, ENC_CFG_PREFIX "profile");
+ break;
+ case VLC_FOURCC('l', 'a', 'a', 'c'):
+ i_aot = PROFILE_AAC_LC;
+ break;
+ case VLC_FOURCC('h', 'a', 'a', 'c'):
+ i_aot = PROFILE_AAC_HE;
+ break;
+ case VLC_FOURCC('s', 'a', 'a', 'c'):
+ i_aot = PROFILE_AAC_HE_v2;
+ break;
+ default:
return VLC_EGENERIC;
}
+ if (p_enc->fmt_in.audio.i_channels != 2)
+ if (i_aot == PROFILE_AAC_HE_v2 || i_aot == PROFILE_AAC_ELD) {
+ msg_Err(p_enc, "Selected profile %d can only be used with stereo", i_aot);
+ return VLC_EGENERIC;
+ }
+
uint16_t channel_config;
CHANNEL_MODE mode;
switch (p_enc->fmt_in.audio.i_channels) {
@@ -217,26 +235,8 @@ static int OpenEncoder(vlc_object_t *p_this)
p_enc->fmt_out.i_cat = AUDIO_ES;
p_enc->fmt_out.i_codec = VLC_CODEC_MP4A;
- config_ChainParse(p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg);
-
- int i_aot; /* This stores the aac profile chosen */
- if (p_enc->fmt_out.i_codec == VLC_FOURCC('l', 'a', 'a', 'c'))
- i_aot = PROFILE_AAC_LC;
- else if (p_enc->fmt_out.i_codec == VLC_FOURCC('h', 'a', 'a', 'c'))
- i_aot = PROFILE_AAC_HE;
- else if (p_enc->fmt_out.i_codec == VLC_FOURCC('s', 'a', 'a', 'c'))
- i_aot = PROFILE_AAC_HE_v2;
- else
- i_aot = var_InheritInteger(p_enc, ENC_CFG_PREFIX "profile");
-
- int i_vbr = var_InheritInteger(p_enc, ENC_CFG_PREFIX "vbr");
p_sys->i_pts_last = 0;
- if ((i_aot == PROFILE_AAC_HE || i_aot == PROFILE_AAC_HE_v2) && i_vbr > 3) {
- msg_Warn(p_enc, "Maximum VBR quality for this profile is 3, setting vbr=3");
- i_vbr = 3;
- }
-
AACENC_ERROR erraac;
erraac = aacEncOpen(&p_sys->handle, 0, p_enc->fmt_in.audio.i_channels);
if (erraac != AACENC_OK) {
@@ -244,14 +244,6 @@ static int OpenEncoder(vlc_object_t *p_this)
free(p_sys);
return VLC_EGENERIC;
}
- if (i_aot == PROFILE_AAC_HE_v2 && p_enc->fmt_in.audio.i_channels != 2) {
- msg_Err(p_enc, "The HE-AAC-v2 profile can only be used with stereo sources");
- goto error;
- }
- if (i_aot == PROFILE_AAC_ELD && p_enc->fmt_in.audio.i_channels != 2) {
- msg_Err(p_enc, "The ELD-AAC profile can only be used with stereo sources");
- goto error;
- }
#define SET_PARAM(P, V) do { \
AACENC_ERROR err = aacEncoder_SetParam(p_sys->handle, AACENC_ ## P, V); \
@@ -268,9 +260,15 @@ static int OpenEncoder(vlc_object_t *p_this)
SET_PARAM(SAMPLERATE, p_enc->fmt_out.audio.i_rate);
SET_PARAM(CHANNELMODE, mode);
SET_PARAM(CHANNELORDER, CH_ORDER_WG4);
- if (i_vbr != 0)
+
+ int i_vbr = var_InheritInteger(p_enc, ENC_CFG_PREFIX "vbr");
+ if (i_vbr != 0) {
+ if ((i_aot == PROFILE_AAC_HE || i_aot == PROFILE_AAC_HE_v2) && i_vbr > 3) {
+ msg_Warn(p_enc, "Maximum VBR quality for this profile is 3, setting vbr=3");
+ i_vbr = 3;
+ }
SET_PARAM(BITRATEMODE, i_vbr);
- else {
+ } else {
int i_bitrate = p_enc->fmt_out.i_bitrate;
if (i_bitrate == 0) {
i_bitrate = 96 * p_enc->fmt_in.audio.i_channels * p_enc->fmt_out.audio.i_rate / 44;
@@ -325,8 +323,7 @@ static int OpenEncoder(vlc_object_t *p_this)
return VLC_SUCCESS;
error:
- aacEncClose(&p_sys->handle);
- free(p_sys);
+ CloseEncoder(p_this);
return VLC_EGENERIC;
}
More information about the vlc-commits
mailing list