summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMartijn van Beurden <mvanb1@gmail.com>2021-12-01 21:34:42 +0100
committerMartijn van Beurden <mvanb1@gmail.com>2022-05-02 07:59:01 +0200
commitb5f4a1535c19e476b4987cb587e089288dc1bf70 (patch)
treea7f2dd64855239e3d3ab011e2b9558289b08d23d /include
parent3fc5ba46375e48009cd9428091cd2ffd242de6b9 (diff)
downloadflac-b5f4a1535c19e476b4987cb587e089288dc1bf70.tar.gz
Add API functions to limit minimum bitrate
Quite a lot of decoders have trouble streaming or seeking in a file with frames that only consist of constant subframes because of the large difference between the largest and smallest subframe. To remedy this, this commit makes it possible to disable the use of constant subframes for the last subframe in case all others are constant with a new API function. This means the minimum bitrate for a FLAC file encoded with this function used is raised to 1bit/sample (i.e. 48kbit/s for 48kHz material). This commit also adds tests to the test suite
Diffstat (limited to 'include')
-rw-r--r--include/FLAC++/encoder.h2
-rw-r--r--include/FLAC/stream_encoder.h28
2 files changed, 30 insertions, 0 deletions
diff --git a/include/FLAC++/encoder.h b/include/FLAC++/encoder.h
index ce8d80a4..83ea4c2d 100644
--- a/include/FLAC++/encoder.h
+++ b/include/FLAC++/encoder.h
@@ -147,6 +147,7 @@ namespace FLAC {
virtual bool set_total_samples_estimate(FLAC__uint64 value); ///< See FLAC__stream_encoder_set_total_samples_estimate()
virtual bool set_metadata(::FLAC__StreamMetadata **metadata, uint32_t num_blocks); ///< See FLAC__stream_encoder_set_metadata()
virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, uint32_t num_blocks); ///< See FLAC__stream_encoder_set_metadata()
+ virtual bool set_limit_min_bitrate(bool value); ///< See FLAC__stream_encoder_set_limit_min_bitrate()
/* get_state() is not virtual since we want subclasses to be able to return their own state */
State get_state() const; ///< See FLAC__stream_encoder_get_state()
@@ -169,6 +170,7 @@ namespace FLAC {
virtual uint32_t get_max_residual_partition_order() const; ///< See FLAC__stream_encoder_get_max_residual_partition_order()
virtual uint32_t get_rice_parameter_search_dist() const; ///< See FLAC__stream_encoder_get_rice_parameter_search_dist()
virtual FLAC__uint64 get_total_samples_estimate() const; ///< See FLAC__stream_encoder_get_total_samples_estimate()
+ virtual bool get_limit_min_bitrate() const; ///< See FLAC__stream_encoder_get_limit_min_bitrate()
virtual ::FLAC__StreamEncoderInitStatus init(); ///< See FLAC__stream_encoder_init_stream()
virtual ::FLAC__StreamEncoderInitStatus init_ogg(); ///< See FLAC__stream_encoder_init_ogg_stream()
diff --git a/include/FLAC/stream_encoder.h b/include/FLAC/stream_encoder.h
index 0c611d04..03c116aa 100644
--- a/include/FLAC/stream_encoder.h
+++ b/include/FLAC/stream_encoder.h
@@ -1198,6 +1198,24 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__Stream
*/
FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, uint32_t num_blocks);
+/** Set to \c true to make the encoder not output frames which contain
+ * only constant subframes. This is beneficial for streaming
+ * applications: very small frames can cause problems with buffering
+ * as bitrates can drop as low 1kbit/s for CDDA audio encoded within
+ * subset. The minimum bitrate for a FLAC file encoded with this
+ * function used is raised to 1bit/sample (i.e. 48kbit/s for 48kHz
+ * material).
+ *
+ * \default \c false
+ * \param encoder An encoder instance to set.
+ * \param value Flag value (see above).
+ * \assert
+ * \code encoder != NULL \endcode
+ * \retval FLAC__bool
+ * \c false if the encoder is already initialized, else \c true.
+ */
+FLAC_API FLAC__bool FLAC__stream_encoder_set_limit_min_bitrate(FLAC__StreamEncoder *encoder, FLAC__bool value);
+
/** Get the current encoder state.
*
* \param encoder An encoder instance to query.
@@ -1425,6 +1443,16 @@ FLAC_API uint32_t FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC
*/
FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
+/** Get the "limit_min_bitrate" flag.
+ *
+ * \param encoder An encoder instance to query.
+ * \assert
+ * \code encoder != NULL \endcode
+ * \retval FLAC__bool
+ * See FLAC__stream_encoder_set_limit_min_bitrate().
+ */
+FLAC_API FLAC__bool FLAC__stream_encoder_get_limit_min_bitrate(const FLAC__StreamEncoder *encoder);
+
/** Initialize the encoder instance to encode native FLAC streams.
*
* This flavor of initialization sets up the encoder to encode to a