Repository navigation
Conversation
…evel defaults `FLAC__stream_encoder_finish()` is documented to reset all settings to the constructor defaults (stream_encoder.h: "FLAC__stream_encoder_finish() resets all settings to the constructor defaults", and the `FLAC__stream_encoder_finish` description). It calls `set_defaults_()`, which zeroes the compression-level settings and then calls `FLAC__stream_encoder_set_compression_level(encoder, 5)`. At that point the state is still `FLAC__STREAM_ENCODER_OK`, so `set_compression_level()` returns `false` without doing anything, and the encoder is left with `do_mid_side_stereo = false`, `max_lpc_order = 0`, `max_residual_partition_order = 0`, etc. `FLAC__stream_encoder_new()` sets the state to `UNINITIALIZED` before calling `set_defaults_()`, so a new encoder gets level 5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FLAC__stream_encoder_finish()is documented to reset all settings to the constructor defaults (stream_encoder.h: "FLAC__stream_encoder_finish() resets all settings to the constructor defaults", and theFLAC__stream_encoder_finishdescription). It callsset_defaults_(), which zeroes the compression-level settings and then callsFLAC__stream_encoder_set_compression_level(encoder, 5). At that point the state is stillFLAC__STREAM_ENCODER_OK, soset_compression_level()returnsfalsewithout doing anything, and the encoder is left withdo_mid_side_stereo = false,max_lpc_order = 0,max_residual_partition_order = 0, etc.FLAC__stream_encoder_new()sets the state toUNINITIALIZEDbefore callingset_defaults_(), so a new encoder gets level 5.This is the same problem that #294 fixed for
FLAC__stream_encoder_new(), whereset_defaults_()used to run before the state was set toUNINITIALIZED(the comment there notes that the default became level 5 "as was intended"). The call infinish()still runs while the state isOK.Reproduction
Tested on master 59fa340. The program
encreuse.cin https://gist.github.com/GeekQAQ/4f489659d418c52779eff031d5654675 (withflac_common.h) encodes the same 8000 samples twice with one encoder, setting only channels, bits per sample and sample rate (no compression level):Calling
FLAC__stream_encoder_set_compression_level(encoder, 5)afterfinish()gives the same result as a new encoder (explicitmode).Change
finish()temporarily sets the state toFLAC__STREAM_ENCODER_UNINITIALIZEDwhile callingset_defaults_()and restores it afterwards, so the existing state handling after it is unchanged. With the change, the encoder afterfinish()reports the same settings and produces byte-identical output to a new encoder.test_libFLACpasses (ctestlibFLAC, ASan+UBSan build).