From 9ab9b97f204a0088271daaf71cbff4b6ea1d1a8a Mon Sep 17 00:00:00 2001 From: Anthony DeRossi Date: Wed, 14 Sep 2022 17:56:23 -0700 Subject: [PATCH] encoder/flac: only set a serial number for oggflac This fixes a bug introduced in 87fa6bca where the FLAC encoder fails to initialize unless libFLAC is built with Ogg support. When libFLAC is built without Ogg support, FLAC__stream_encoder_set_ogg_serial_number unconditionally returns false. --- src/encoder/plugins/FlacEncoderPlugin.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/encoder/plugins/FlacEncoderPlugin.cxx b/src/encoder/plugins/FlacEncoderPlugin.cxx index d55715db5..1fec31dd5 100644 --- a/src/encoder/plugins/FlacEncoderPlugin.cxx +++ b/src/encoder/plugins/FlacEncoderPlugin.cxx @@ -38,6 +38,7 @@ class FlacEncoder final : public Encoder { FLAC__StreamEncoder *const fse; const unsigned compression; + const bool oggflac; PcmBuffer expand_buffer; @@ -122,7 +123,7 @@ flac_encoder_init(const ConfigBlock &block) } static void -flac_encoder_setup(FLAC__StreamEncoder *fse, unsigned compression, +flac_encoder_setup(FLAC__StreamEncoder *fse, unsigned compression, bool oggflac, const AudioFormat &audio_format) { unsigned bits_per_sample; @@ -157,7 +158,7 @@ flac_encoder_setup(FLAC__StreamEncoder *fse, unsigned compression, throw FormatRuntimeError("error setting flac sample rate to %d", audio_format.sample_rate); - if (!FLAC__stream_encoder_set_ogg_serial_number(fse, + if (oggflac && !FLAC__stream_encoder_set_ogg_serial_number(fse, GenerateSerial())) throw FormatRuntimeError("error setting ogg serial number"); } @@ -166,11 +167,12 @@ FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, u :Encoder(_oggchaining), audio_format(_audio_format), fse(_fse), compression(_compression), + oggflac(_oggflac), output_buffer(8192) { /* this immediately outputs data through callback */ - auto init_status = _oggflac ? + auto init_status = oggflac ? FLAC__stream_encoder_init_ogg_stream(fse, nullptr, WriteCallback, nullptr, nullptr, nullptr, @@ -209,7 +211,7 @@ PreparedFlacEncoder::Open(AudioFormat &audio_format) throw std::runtime_error("FLAC__stream_encoder_new() failed"); try { - flac_encoder_setup(fse, compression, audio_format); + flac_encoder_setup(fse, compression, oggflac, audio_format); } catch (...) { FLAC__stream_encoder_delete(fse); throw; @@ -222,7 +224,7 @@ void FlacEncoder::SendTag(const Tag &tag) { /* re-initialize encoder since flac_encoder_finish resets everything */ - flac_encoder_setup(fse, compression, audio_format); + flac_encoder_setup(fse, compression, oggflac, audio_format); FLAC__StreamMetadata *metadata = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); FLAC__StreamMetadata_VorbisComment_Entry entry;