From af8c0ad5904bf7bc97ec2d4dfb8f883397009c9d Mon Sep 17 00:00:00 2001 From: Daeho Ro <40587651+daeho-ro@users.noreply.github.com> Date: Mon, 20 Jul 2026 20:44:34 +0900 Subject: [PATCH] FaacEncoder: support faac >= 2.0 (faac_* API) faac 2.0 removed the legacy faacEnc* API and bumped the library SONAME to 1. Detect the new API via FAAC_VERSION_MAJOR and use it when available, keeping the faacEnc* path for faac 1.x. Encoder settings and behavior are unchanged on both paths. --- darkice/src/FaacEncoder.cpp | 76 +++++++++++++++++++++++++++++++++++++ darkice/src/FaacEncoder.h | 19 ++++++++++ 2 files changed, 95 insertions(+) diff --git a/darkice/src/FaacEncoder.cpp b/darkice/src/FaacEncoder.cpp index bb32c0a..9fb147c 100644 --- a/darkice/src/FaacEncoder.cpp +++ b/darkice/src/FaacEncoder.cpp @@ -56,6 +56,33 @@ static const char fileid[] = "$Id$"; /* =============================================== local function prototypes */ +#if FAAC_VERSION_MAJOR >= 1 +/*------------------------------------------------------------------------------ + * Map the removed faacEnc* calls used below onto the faac >= 2.0 API + *----------------------------------------------------------------------------*/ +static int +faacEncEncode( faac_encoder * encoder, + int32_t * inputBuffer, + unsigned int samplesInput, + unsigned char * outputBuffer, + unsigned int bufferSize ) +{ + uint32_t bytesWritten = 0; + + if ( faac_encoder_encode( encoder, inputBuffer, samplesInput, + outputBuffer, bufferSize, &bytesWritten) < 0 ) { + return -1; + } + return (int) bytesWritten; +} + +static void +faacEncClose( faac_encoder * encoder ) +{ + faac_encoder_close( &encoder); +} +#endif // FAAC_VERSION_MAJOR >= 1 + /* ============================================================= module code */ @@ -76,6 +103,54 @@ FaacEncoder :: open ( void ) "faac lib opening underlying sink error"); } +#if FAAC_VERSION_MAJOR >= 1 + faac_library_info libInfo; + + libInfo.struct_size = sizeof(libInfo); + if ( faac_get_library_info( &libInfo) == FAAC_OK ) { + reportEvent(1, "Using faac codec version", libInfo.version); + } + + faac_params params; + faac_status status; + + if ( (status = faac_params_init( ¶ms)) < 0 ) { + throw Exception(__FILE__, __LINE__, + "error initializing faac parameters", + faac_strerror(status)); + } + + params.sample_rate = getOutSampleRate(); + params.num_channels = getInChannel(); + params.object_type = FAAC_OBJ_LOW; + params.mpeg_version = FAAC_MPEG2; + params.use_tns = true; + params.short_control = FAAC_SHORTCTL_NORMAL; + params.use_lfe = false; + params.joint_mode = FAAC_JOINT_MS; + params.bit_rate = getOutBitrate() * 1000 / getOutChannel(); + params.bandwidth = (uint32_t) lowpass; + params.quant_quality = (uint32_t) (getOutQuality() * 1000.0); + params.output_format = FAAC_STREAM_ADTS; + params.input_format = FAAC_INPUT_16BIT; + + if ( (status = faac_encoder_open( ¶ms, &encoderHandle)) < 0 ) { + throw Exception(__FILE__, __LINE__, + "error configuring faac library", + faac_strerror(status)); + } + + faac_encoder_info encInfo; + + encInfo.struct_size = sizeof(encInfo); + if ( (status = faac_encoder_get_info( encoderHandle, &encInfo)) < 0 ) { + throw Exception(__FILE__, __LINE__, + "error querying faac encoder properties", + faac_strerror(status)); + } + inputSamples = encInfo.frame_samples * getInChannel(); + maxOutputBytes = encInfo.max_output_bytes; +#else char * faacVersion; char * faacCopyright; faacEncGetVersion(&faacVersion, &faacCopyright); @@ -106,6 +181,7 @@ FaacEncoder :: open ( void ) throw Exception(__FILE__, __LINE__, "error configuring faac library"); } +#endif // FAAC_VERSION_MAJOR >= 1 // initialize the resampling coverter if needed if ( converter ) { diff --git a/darkice/src/FaacEncoder.h b/darkice/src/FaacEncoder.h index 1944c2f..bed5d10 100644 --- a/darkice/src/FaacEncoder.h +++ b/darkice/src/FaacEncoder.h @@ -47,6 +47,11 @@ #error configure with faac #endif +/* faac < 2.0 (legacy faacEnc* API) does not define version macros */ +#ifndef FAAC_VERSION_MAJOR +#define FAAC_VERSION_MAJOR 0 +#endif + #include "Ref.h" #include "Exception.h" @@ -86,7 +91,11 @@ class FaacEncoder : public AudioEncoder, public virtual Reporter /** * The handle to the AAC encoder instance. */ +#if FAAC_VERSION_MAJOR >= 1 + faac_encoder * encoderHandle; +#else faacEncHandle encoderHandle; +#endif /** * The maximum number of input samples to supply to the encoder. @@ -392,11 +401,21 @@ class FaacEncoder : public AudioEncoder, public virtual Reporter inline const char * getFaacVersion( void ) { +#if FAAC_VERSION_MAJOR >= 1 + faac_library_info info; + + info.struct_size = sizeof(info); + if ( faac_get_library_info( &info) < 0 ) { + return "unknown"; + } + return info.version; +#else char * id; char * copyright; faacEncGetVersion(&id, ©right); return id; +#endif } /**