Skip to content

Commit

Permalink
flac: Only create Ogg FLAC decoder if FLAC_API_SUPPORTS_OGG_FLAC is true
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Aug 31, 2022
1 parent 4b49481 commit b40dcee
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/flac/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ bool FLACng::init()
{
/* Callback structure and decoder for main decoding loop */
auto flac_decoder = StreamDecoderPtr(FLAC__stream_decoder_new());
auto ogg_flac_decoder = StreamDecoderPtr(FLAC__stream_decoder_new());

if (!flac_decoder || !ogg_flac_decoder)
if (!flac_decoder)
{
AUDERR("Could not create the FLAC decoder instances!\n");
AUDERR("Could not create the main FLAC decoder instance!\n");
return false;
}

Expand All @@ -47,29 +45,36 @@ bool FLACng::init()
eof_callback, write_callback, metadata_callback, error_callback,
&s_cinfo);

auto ret2 = FLAC__stream_decoder_init_ogg_stream(ogg_flac_decoder.get(),
read_callback, seek_callback, tell_callback, length_callback,
eof_callback, write_callback, metadata_callback, error_callback,
&s_cinfo);

if (ret1 != FLAC__STREAM_DECODER_INIT_STATUS_OK)
{
AUDERR("Could not initialize the main FLAC decoder!\n");
return false;
}

if (ret2 != FLAC__STREAM_DECODER_INIT_STATUS_OK)
if (FLAC_API_SUPPORTS_OGG_FLAC)
{
/* Only treat this as error if Ogg FLAC support is available */
if (FLAC_API_SUPPORTS_OGG_FLAC)
auto ogg_flac_decoder = StreamDecoderPtr(FLAC__stream_decoder_new());
if (!ogg_flac_decoder)
{
AUDERR("Could not create the Ogg FLAC decoder instance!\n");
return false;
}

auto ret2 = FLAC__stream_decoder_init_ogg_stream(ogg_flac_decoder.get(),
read_callback, seek_callback, tell_callback, length_callback,
eof_callback, write_callback, metadata_callback, error_callback,
&s_cinfo);

if (ret2 != FLAC__STREAM_DECODER_INIT_STATUS_OK)
{
AUDERR("Could not initialize the Ogg FLAC decoder!\n");
return false;
}

s_ogg_decoder = std::move(ogg_flac_decoder);
}

s_decoder = std::move(flac_decoder);
s_ogg_decoder = std::move(ogg_flac_decoder);

return true;
}
Expand Down

0 comments on commit b40dcee

Please sign in to comment.