Skip to content

Commit

Permalink
Merge branch 'fix-oggflac-serial' of https://github.com/anthonyde/MPD
Browse files Browse the repository at this point in the history
…into v0.23.x
  • Loading branch information
MaxKellermann committed Sep 20, 2022
2 parents 88d92ac + 9ab9b97 commit 15ff7c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ver 0.23.10 (not yet released)
* encoder
- flac: fix failure when libFLAC is built without Ogg support
* Windows
- log to stdout by default, don't require "log_file" setting

Expand Down
12 changes: 7 additions & 5 deletions src/encoder/plugins/FlacEncoderPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FlacEncoder final : public Encoder {

FLAC__StreamEncoder *const fse;
const unsigned compression;
const bool oggflac;

PcmBuffer expand_buffer;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 15ff7c4

Please sign in to comment.