From 30cd31636fc13bb283204bf3cb6a1a295fb95e49 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Fri, 16 Jan 2004 00:16:45 +0000 Subject: [PATCH] revamp OggFLAC__SeekableStreamEncoder to derive from FLAC__StreamEncoder instead of FLAC__SeekableStreamEncoder --- include/OggFLAC/seekable_stream_encoder.h | 146 +++--- .../include/protected/seekable_stream_encoder.h | 1 + src/libOggFLAC/seekable_stream_encoder.c | 493 ++++++++++++++++----- 3 files changed, 457 insertions(+), 183 deletions(-) diff --git a/include/OggFLAC/seekable_stream_encoder.h b/include/OggFLAC/seekable_stream_encoder.h index 1a0cb85..768b6a0 100644 --- a/include/OggFLAC/seekable_stream_encoder.h +++ b/include/OggFLAC/seekable_stream_encoder.h @@ -34,6 +34,7 @@ #include "export.h" +#include "FLAC/stream_encoder.h" #include "FLAC/seekable_stream_encoder.h" #ifdef __cplusplus @@ -60,7 +61,7 @@ extern "C" { * from the FLAC seekable stream encoder. * * The interface here is nearly identical to FLAC's seekable stream - * encoder, including the callbacks, with the addition of + * encoder, including the callback(@@@@@@new read callback and why@@@), with the addition of * OggFLAC__seekable_stream_encoder_set_serial_number(). See the * \link flac_seekable_stream_encoder FLAC seekable stream encoder module \endlink * for full documentation. @@ -81,23 +82,42 @@ typedef enum { OggFLAC__SEEKABLE_STREAM_ENCODER_OGG_ERROR, /**< An error occurred in the underlying Ogg layer. */ - OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR, - /**< An error occurred in the underlying FLAC seekable stream encoder; - * check OggFLAC__stream_encoder_get_FLAC_seekable_stream_encoder_state(). + OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR, + /**< An error occurred in the underlying FLAC stream encoder; + * check OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state(). */ - OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK, - /**< The encoder was initialized before setting all the required callbacks. */ - OggFLAC__SEEKABLE_STREAM_ENCODER_MEMORY_ALLOCATION_ERROR, /**< Memory allocation failed. */ + OggFLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR, + /**< The write callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_READ_ERROR, + /**< The read callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR, + /**< The seek callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR, + /**< The tell callback returned an error. */ + OggFLAC__SEEKABLE_STREAM_ENCODER_ALREADY_INITIALIZED, /**< OggFLAC__seekable_stream_encoder_init() was called when the encoder was * already initialized, usually because * OggFLAC__seekable_stream_encoder_finish() was not called. */ + OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK, + /**< OggFLAC__seekable_stream_encoder_init() was called without all + * callbacks being set. + */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_SEEKTABLE, + /**< An invalid seek table was passed is the metadata to + * OggFLAC__seekable_stream_encoder_set_metadata(). + */ + OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED /**< The encoder is in the uninitialized state. */ @@ -217,7 +237,7 @@ OggFLAC_API void OggFLAC__seekable_stream_encoder_delete(OggFLAC__SeekableStream */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_serial_number(OggFLAC__SeekableStreamEncoder *encoder, long serial_number); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_verify() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_verify() * * \default \c false * \param encoder An encoder instance to set. @@ -229,7 +249,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_serial_number(OggFLA */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_verify(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_streamable_subset() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_streamable_subset() * * \default \c true * \param encoder An encoder instance to set. @@ -241,7 +261,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_verify(OggFLAC__Seek */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_streamable_subset(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_do_mid_side_stereo() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_mid_side_stereo() * * \default \c false * \param encoder An encoder instance to set. @@ -253,7 +273,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_streamable_subset(Og */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_loose_mid_side_stereo() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_loose_mid_side_stereo() * * \default \c false * \param encoder An encoder instance to set. @@ -265,7 +285,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(O */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_channels() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_channels() * * \default \c 2 * \param encoder An encoder instance to set. @@ -277,7 +297,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_loose_mid_side_stere */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_channels(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_bits_per_sample() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_bits_per_sample() * * \default \c 16 * \param encoder An encoder instance to set. @@ -289,7 +309,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_channels(OggFLAC__Se */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_bits_per_sample(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_sample_rate() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_sample_rate() * * \default \c 44100 * \param encoder An encoder instance to set. @@ -301,7 +321,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_bits_per_sample(OggF */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_sample_rate(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_blocksize() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_blocksize() * * \default \c 1152 * \param encoder An encoder instance to set. @@ -313,7 +333,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_sample_rate(OggFLAC_ */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_blocksize(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_max_lpc_order() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_lpc_order() * * \default \c 0 * \param encoder An encoder instance to set. @@ -325,7 +345,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_blocksize(OggFLAC__S */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_lpc_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_qlp_coeff_precision() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_precision() * * \default \c 0 * \param encoder An encoder instance to set. @@ -337,7 +357,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_lpc_order(OggFLA */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_qlp_coeff_prec_search() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_prec_search() * * \default \c false * \param encoder An encoder instance to set. @@ -349,7 +369,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision( */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_do_escape_coding() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_escape_coding() * * \default \c false * \param encoder An encoder instance to set. @@ -361,7 +381,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_se */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_escape_coding(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_do_exhaustive_model_search() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_exhaustive_model_search() * * \default \c false * \param encoder An encoder instance to set. @@ -373,7 +393,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_escape_coding(Ogg */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_min_residual_partition_order() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_min_residual_partition_order() * * \default \c 0 * \param encoder An encoder instance to set. @@ -385,7 +405,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_ */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_max_residual_partition_order() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_residual_partition_order() * * \default \c 0 * \param encoder An encoder instance to set. @@ -397,7 +417,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_min_residual_partiti */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_rice_parameter_search_dist() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_rice_parameter_search_dist() * * \default \c 0 * \param encoder An encoder instance to set. @@ -409,7 +429,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_residual_partiti */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_total_samples_estimate() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_total_samples_estimate() * * \default \c 0 * \param encoder An encoder instance to set. @@ -421,7 +441,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_rice_parameter_searc */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_total_samples_estimate(OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 value); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_set_metadata() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_metadata() * * \default \c NULL, 0 * \param encoder An encoder instance to set. @@ -472,8 +492,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_seek_callback(OggFLA OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_tell_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderTellCallback value); /** Set the write callback. - * This is inherited from FLAC__SeekableStreamEncoder; see - * FLAC__seekable_stream_encoder_set_write_callback(). + * This is inherited from FLAC__StreamEncoder; see + * FLAC__stream_encoder_set_write_callback(). * * \note * Unlike the FLAC seekable stream encoder write callback, the Ogg @@ -520,23 +540,9 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_client_data(OggFLAC_ */ OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_get_state(const OggFLAC__SeekableStreamEncoder *encoder); -/** Get the state of the underlying FLAC seekable stream encoder. - * Useful when the seekable stream encoder state is - * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__SeekableStreamEncoderState - * The FLAC seeekable stream encoder state. - */ -OggFLAC_API FLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_get_FLAC_seekable_stream_encoder_state(const OggFLAC__SeekableStreamEncoder *encoder); - /** Get the state of the underlying FLAC stream encoder. * Useful when the seekable stream encoder state is - * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR - * and the FLAC seekable stream encoder state is - * \c FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR. + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR. * * \param encoder An encoder instance to query. * \assert @@ -547,10 +553,8 @@ OggFLAC_API FLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_ge OggFLAC_API FLAC__StreamEncoderState OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__SeekableStreamEncoder *encoder); /** Get the state of the underlying FLAC encoder's verify decoder. - * Useful when the stream encoder state is - * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR - * and the FLAC seekable stream encoder state is - * \c FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR + * Useful when the seekable stream encoder state is + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR * and the FLAC stream encoder state is * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. * @@ -564,8 +568,8 @@ OggFLAC_API FLAC__StreamDecoderState OggFLAC__seekable_stream_encoder_get_verify /** Get the current encoder state as a C string. * This version automatically resolves - * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR - * by getting the FLAC seekable stream encoder's resolved state. + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR + * by getting the FLAC stream encoder's resolved state. * * \param encoder A encoder instance to query. * \assert @@ -576,11 +580,9 @@ OggFLAC_API FLAC__StreamDecoderState OggFLAC__seekable_stream_encoder_get_verify OggFLAC_API const char *OggFLAC__seekable_stream_encoder_get_resolved_state_string(const OggFLAC__SeekableStreamEncoder *encoder); /** Get relevant values about the nature of a verify decoder error. - * Inherited from FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(). - * Useful when the stream encoder state is - * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR - * and the FLAC seekable stream encoder state is - * \c FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR + * Inherited from FLAC__stream_encoder_get_verify_decoder_error_stats(). + * Useful when the seekable stream encoder state is + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR * and the FLAC stream encoder state is * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. * @@ -602,7 +604,7 @@ OggFLAC_API const char *OggFLAC__seekable_stream_encoder_get_resolved_state_stri */ OggFLAC_API void OggFLAC__seekable_stream_encoder_get_verify_decoder_error_stats(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_verify() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_verify() * * \param encoder An encoder instance to query. * \assert @@ -612,7 +614,7 @@ OggFLAC_API void OggFLAC__seekable_stream_encoder_get_verify_decoder_error_stats */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_verify(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_streamable_subset() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_streamable_subset() * * \param encoder An encoder instance to query. * \assert @@ -622,7 +624,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_verify(const OggFLAC */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_streamable_subset(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_do_mid_side_stereo() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_mid_side_stereo() * * \param encoder An encoder instance to query. * \assert @@ -632,7 +634,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_streamable_subset(co */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_loose_mid_side_stereo() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_loose_mid_side_stereo() * * \param encoder An encoder instance to query. * \assert @@ -642,7 +644,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(c */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_channels() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_channels() * * \param encoder An encoder instance to query. * \assert @@ -652,7 +654,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_loose_mid_side_stere */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_channels(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_bits_per_sample() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_bits_per_sample() * * \param encoder An encoder instance to query. * \assert @@ -662,7 +664,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_channels(const OggFLAC */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_bits_per_sample(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_sample_rate() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_sample_rate() * * \param encoder An encoder instance to query. * \assert @@ -672,7 +674,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_bits_per_sample(const */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_sample_rate(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_blocksize() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_blocksize() * * \param encoder An encoder instance to query. * \assert @@ -682,7 +684,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_sample_rate(const OggF */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_blocksize(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_max_lpc_order() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_max_lpc_order() * * \param encoder An encoder instance to query. * \assert @@ -692,7 +694,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_blocksize(const OggFLA */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_lpc_order(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_qlp_coeff_precision() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_qlp_coeff_precision() * * \param encoder An encoder instance to query. * \assert @@ -702,7 +704,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_lpc_order(const Og */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_qlp_coeff_prec_search() * * \param encoder An encoder instance to query. * \assert @@ -712,7 +714,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(co */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_do_escape_coding() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_escape_coding() * * \param encoder An encoder instance to query. * \assert @@ -722,7 +724,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_se */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_escape_coding(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_do_exhaustive_model_search() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_exhaustive_model_search() * * \param encoder An encoder instance to query. * \assert @@ -732,7 +734,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_escape_coding(con */ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_min_residual_partition_order() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_min_residual_partition_order() * * \param encoder An encoder instance to query. * \assert @@ -742,7 +744,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_ */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_man_residual_partition_order() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_man_residual_partition_order() * * \param encoder An encoder instance to query. * \assert @@ -752,7 +754,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_min_residual_partition */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_rice_parameter_search_dist() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_rice_parameter_search_dist() * * \param encoder An encoder instance to query. * \assert @@ -762,7 +764,7 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_residual_partition */ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(const OggFLAC__SeekableStreamEncoder *encoder); -/** This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_get_total_samples_estimate() +/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_total_samples_estimate() * * \param encoder An encoder instance to set. * \assert @@ -810,7 +812,7 @@ OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder OggFLAC_API void OggFLAC__seekable_stream_encoder_finish(OggFLAC__SeekableStreamEncoder *encoder); /** Submit data for encoding. - * This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_process(). + * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process(). * * \param encoder An initialized encoder instance in the OK state. * \param buffer An array of pointers to each channel's signal. @@ -826,7 +828,7 @@ OggFLAC_API void OggFLAC__seekable_stream_encoder_finish(OggFLAC__SeekableStream OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples); /** Submit data for encoding. - * This is inherited from FLAC__SeekableStreamEncoder; see FLAC__seekable_stream_encoder_process_interleaved(). + * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process_interleaved(). * * \param encoder An initialized encoder instance in the OK state. * \param buffer An array of channel-interleaved data (see above). diff --git a/src/libOggFLAC/include/protected/seekable_stream_encoder.h b/src/libOggFLAC/include/protected/seekable_stream_encoder.h index c869399..6644a93 100644 --- a/src/libOggFLAC/include/protected/seekable_stream_encoder.h +++ b/src/libOggFLAC/include/protected/seekable_stream_encoder.h @@ -38,6 +38,7 @@ typedef struct OggFLAC__SeekableStreamEncoderProtected { OggFLAC__SeekableStreamEncoderState state; OggFLAC__OggEncoderAspect ogg_encoder_aspect; + FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset; } OggFLAC__SeekableStreamEncoderProtected; #endif diff --git a/src/libOggFLAC/seekable_stream_encoder.c b/src/libOggFLAC/seekable_stream_encoder.c index 515c004..b467eb1 100644 --- a/src/libOggFLAC/seekable_stream_encoder.c +++ b/src/libOggFLAC/seekable_stream_encoder.c @@ -35,6 +35,11 @@ #include "OggFLAC/seekable_stream_encoder.h" #include "protected/seekable_stream_encoder.h" +#ifdef max +#undef max +#endif +#define max(a,b) ((a)>(b)?(a):(b)) + /*********************************************************************** * * Private class method prototypes @@ -42,14 +47,13 @@ ***********************************************************************/ /* unpublished debug routines */ -extern FLAC__bool FLAC__seekable_stream_encoder_disable_constant_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -extern FLAC__bool FLAC__seekable_stream_encoder_disable_fixed_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value); -extern FLAC__bool FLAC__seekable_stream_encoder_disable_verbatim_subframes(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value); +extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); +extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); +extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); static void set_defaults_(OggFLAC__SeekableStreamEncoder *encoder); -static FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__SeekableStreamEncoderTellStatus tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); +static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); +static void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data); /*********************************************************************** @@ -63,7 +67,11 @@ typedef struct OggFLAC__SeekableStreamEncoderPrivate { OggFLAC__SeekableStreamEncoderTellCallback tell_callback; OggFLAC__SeekableStreamEncoderWriteCallback write_callback; void *client_data; - FLAC__SeekableStreamEncoder *FLAC_seekable_stream_encoder; + FLAC__StreamEncoder *FLAC_stream_encoder; + FLAC__StreamMetadata_SeekTable *seek_table; + /* internal vars (all the above are class settings) */ + unsigned first_seekpoint_to_check; + FLAC__uint64 samples_written; } OggFLAC__SeekableStreamEncoderPrivate; @@ -76,10 +84,15 @@ typedef struct OggFLAC__SeekableStreamEncoderPrivate { OggFLAC_API const char * const OggFLAC__SeekableStreamEncoderStateString[] = { "OggFLAC__SEEKABLE_STREAM_ENCODER_OK", "OggFLAC__SEEKABLE_STREAM_ENCODER_OGG_ERROR", - "OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR", - "OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK", + "OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR", "OggFLAC__SEEKABLE_STREAM_ENCODER_MEMORY_ALLOCATION_ERROR", + "OggFLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR", + "OggFLAC__SEEKABLE_STREAM_ENCODER_READ_ERROR", + "OggFLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR", + "OggFLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR", "OggFLAC__SEEKABLE_STREAM_ENCODER_ALREADY_INITIALIZED", + "OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK", + "OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_SEEKTABLE", "OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED" }; @@ -111,8 +124,8 @@ OggFLAC_API OggFLAC__SeekableStreamEncoder *OggFLAC__seekable_stream_encoder_new return 0; } - encoder->private_->FLAC_seekable_stream_encoder = FLAC__seekable_stream_encoder_new(); - if(0 == encoder->private_->FLAC_seekable_stream_encoder) { + encoder->private_->FLAC_stream_encoder = FLAC__stream_encoder_new(); + if(0 == encoder->private_->FLAC_stream_encoder) { free(encoder->private_); free(encoder->protected_); free(encoder); @@ -131,11 +144,11 @@ OggFLAC_API void OggFLAC__seekable_stream_encoder_delete(OggFLAC__SeekableStream FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->protected_); FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); (void)OggFLAC__seekable_stream_encoder_finish(encoder); - FLAC__seekable_stream_encoder_delete(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__stream_encoder_delete(encoder->private_->FLAC_stream_encoder); free(encoder->private_); free(encoder->protected_); @@ -162,13 +175,32 @@ OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder if(!OggFLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) return encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_OGG_ERROR; - FLAC__seekable_stream_encoder_set_seek_callback(encoder->private_->FLAC_seekable_stream_encoder, seek_callback_); - FLAC__seekable_stream_encoder_set_tell_callback(encoder->private_->FLAC_seekable_stream_encoder, tell_callback_); - FLAC__seekable_stream_encoder_set_write_callback(encoder->private_->FLAC_seekable_stream_encoder, write_callback_); - FLAC__seekable_stream_encoder_set_client_data(encoder->private_->FLAC_seekable_stream_encoder, encoder); - - if(FLAC__seekable_stream_encoder_init(encoder->private_->FLAC_seekable_stream_encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK) - return encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR; + if(0 != encoder->private_->seek_table && !FLAC__format_seektable_is_legal(encoder->private_->seek_table)) + return encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_SEEKTABLE; + + /* + * These must be done before we init the stream encoder because that + * calls the write_callback, which uses these values. + */ + encoder->private_->first_seekpoint_to_check = 0; + encoder->private_->samples_written = 0; + encoder->protected_->streaminfo_offset = 0; + encoder->protected_->seektable_offset = 0; + encoder->protected_->audio_offset = 0; + + FLAC__stream_encoder_set_write_callback(encoder->private_->FLAC_stream_encoder, write_callback_); + FLAC__stream_encoder_set_metadata_callback(encoder->private_->FLAC_stream_encoder, metadata_callback_); + FLAC__stream_encoder_set_client_data(encoder->private_->FLAC_stream_encoder, encoder); + + if(FLAC__stream_encoder_init(encoder->private_->FLAC_stream_encoder) != FLAC__STREAM_ENCODER_OK) + return encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR; + + /* + * Initializing the stream encoder writes all the metadata, so we + * save the stream offset now. + */ + if(encoder->private_->tell_callback(encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK) + return encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR; return encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_OK; } @@ -182,9 +214,9 @@ OggFLAC_API void OggFLAC__seekable_stream_encoder_finish(OggFLAC__SeekableStream if(encoder->protected_->state == OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return; - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); - FLAC__seekable_stream_encoder_finish(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__stream_encoder_finish(encoder->private_->FLAC_stream_encoder); OggFLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect); @@ -198,7 +230,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_serial_number(OggFLA FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; OggFLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value); @@ -210,10 +242,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_verify(OggFLAC__Seek FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_verify(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_verify(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_streamable_subset(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -221,10 +253,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_streamable_subset(Og FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_streamable_subset(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_streamable_subset(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -232,10 +264,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(O FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_do_mid_side_stereo(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -243,10 +275,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_loose_mid_side_stere FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_loose_mid_side_stereo(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_channels(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -254,10 +286,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_channels(OggFLAC__Se FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_channels(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_channels(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_bits_per_sample(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -265,10 +297,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_bits_per_sample(OggF FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_bits_per_sample(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_bits_per_sample(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_sample_rate(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -276,10 +308,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_sample_rate(OggFLAC_ FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_sample_rate(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_sample_rate(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_blocksize(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -287,10 +319,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_blocksize(OggFLAC__S FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_blocksize(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_blocksize(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_lpc_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -298,10 +330,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_lpc_order(OggFLA FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_max_lpc_order(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_max_lpc_order(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -309,10 +341,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision( FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_qlp_coeff_precision(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -320,10 +352,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_se FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_escape_coding(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -331,10 +363,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_escape_coding(Ogg FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_do_escape_coding(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_do_escape_coding(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -342,10 +374,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_ FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_do_exhaustive_model_search(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -353,10 +385,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_min_residual_partiti FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_min_residual_partition_order(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -364,10 +396,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_residual_partiti FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_max_residual_partition_order(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(OggFLAC__SeekableStreamEncoder *encoder, unsigned value) @@ -375,10 +407,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_rice_parameter_searc FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_rice_parameter_search_dist(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_total_samples_estimate(OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 value) @@ -386,10 +418,10 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_total_samples_estima FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_set_total_samples_estimate(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_metadata(OggFLAC__SeekableStreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks) @@ -397,10 +429,19 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_metadata(OggFLAC__Se FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_set_metadata(encoder->private_->FLAC_seekable_stream_encoder, metadata, num_blocks); + if(0 != metadata && num_blocks > 0) { + unsigned i; + for(i = 0; i < num_blocks; i++) { + if(0 != metadata[i] && metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) { + encoder->private_->seek_table = &metadata[i]->data.seek_table; + break; /* take only the first one */ + } + } + } + return FLAC__stream_encoder_set_metadata(encoder->private_->FLAC_stream_encoder, metadata, num_blocks); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_seek_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderSeekCallback value) @@ -461,7 +502,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_disable_constant_subfram FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_disable_constant_subframes(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_disable_constant_subframes(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_disable_fixed_subframes(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -471,7 +512,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_disable_fixed_subframes( FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_disable_fixed_subframes(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_disable_fixed_subframes(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_disable_verbatim_subframes(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value) @@ -481,7 +522,7 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_disable_verbatim_subfram FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) return false; - return FLAC__seekable_stream_encoder_disable_verbatim_subframes(encoder->private_->FLAC_seekable_stream_encoder, value); + return FLAC__stream_encoder_disable_verbatim_subframes(encoder->private_->FLAC_stream_encoder, value); } OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_get_state(const OggFLAC__SeekableStreamEncoder *encoder) @@ -492,20 +533,13 @@ OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder return encoder->protected_->state; } -OggFLAC_API FLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_get_FLAC_seekable_stream_encoder_state(const OggFLAC__SeekableStreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_state(encoder->private_->FLAC_seekable_stream_encoder); -} - OggFLAC_API FLAC__StreamEncoderState OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__SeekableStreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_state(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__StreamDecoderState OggFLAC__seekable_stream_encoder_get_verify_decoder_state(const OggFLAC__SeekableStreamEncoder *encoder) @@ -513,22 +547,29 @@ OggFLAC_API FLAC__StreamDecoderState OggFLAC__seekable_stream_encoder_get_verify FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_verify_decoder_state(encoder->private_->FLAC_stream_encoder); } OggFLAC_API const char *OggFLAC__seekable_stream_encoder_get_resolved_state_string(const OggFLAC__SeekableStreamEncoder *encoder) { - if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_SEEKABLE_STREAM_ENCODER_ERROR) + FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + if(encoder->protected_->state != OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) return OggFLAC__SeekableStreamEncoderStateString[encoder->protected_->state]; else - return FLAC__seekable_stream_encoder_get_resolved_state_string(encoder->private_->FLAC_seekable_stream_encoder); + return FLAC__stream_encoder_get_resolved_state_string(encoder->private_->FLAC_stream_encoder); } OggFLAC_API void OggFLAC__seekable_stream_encoder_get_verify_decoder_error_stats(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got) { FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); - FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder->private_->FLAC_seekable_stream_encoder, absolute_sample, frame_number, channel, sample, expected, got); + FLAC__ASSERT(0 != encoder->protected_); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + FLAC__stream_encoder_get_verify_decoder_error_stats(encoder->private_->FLAC_stream_encoder, absolute_sample, frame_number, channel, sample, expected, got); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_verify(const OggFLAC__SeekableStreamEncoder *encoder) @@ -536,7 +577,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_verify(const OggFLAC FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_verify(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_verify(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_streamable_subset(const OggFLAC__SeekableStreamEncoder *encoder) @@ -544,7 +586,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_streamable_subset(co FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_streamable_subset(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_streamable_subset(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder) @@ -552,7 +595,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(c FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_do_mid_side_stereo(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder) @@ -560,7 +604,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_loose_mid_side_stere FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_loose_mid_side_stereo(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_channels(const OggFLAC__SeekableStreamEncoder *encoder) @@ -568,7 +613,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_channels(const OggFLAC FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_channels(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_channels(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_bits_per_sample(const OggFLAC__SeekableStreamEncoder *encoder) @@ -576,7 +622,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_bits_per_sample(const FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_bits_per_sample(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_bits_per_sample(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_sample_rate(const OggFLAC__SeekableStreamEncoder *encoder) @@ -584,7 +631,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_sample_rate(const OggF FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_sample_rate(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_sample_rate(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_blocksize(const OggFLAC__SeekableStreamEncoder *encoder) @@ -592,7 +640,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_blocksize(const OggFLA FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_blocksize(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_blocksize(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_lpc_order(const OggFLAC__SeekableStreamEncoder *encoder) @@ -600,7 +649,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_lpc_order(const Og FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_max_lpc_order(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_max_lpc_order(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(const OggFLAC__SeekableStreamEncoder *encoder) @@ -608,7 +658,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(co FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_qlp_coeff_precision(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__SeekableStreamEncoder *encoder) @@ -616,7 +667,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_se FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_escape_coding(const OggFLAC__SeekableStreamEncoder *encoder) @@ -624,7 +676,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_escape_coding(con FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_do_escape_coding(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_do_escape_coding(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search(const OggFLAC__SeekableStreamEncoder *encoder) @@ -632,7 +685,8 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_ FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_do_exhaustive_model_search(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder) @@ -640,7 +694,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_min_residual_partition FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_min_residual_partition_order(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder) @@ -648,7 +703,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_residual_partition FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_max_residual_partition_order(encoder->private_->FLAC_stream_encoder); } OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(const OggFLAC__SeekableStreamEncoder *encoder) @@ -656,7 +712,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_rice_parameter_search_ FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_rice_parameter_search_dist(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__uint64 OggFLAC__seekable_stream_encoder_get_total_samples_estimate(const OggFLAC__SeekableStreamEncoder *encoder) @@ -664,7 +721,8 @@ OggFLAC_API FLAC__uint64 OggFLAC__seekable_stream_encoder_get_total_samples_esti FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + return FLAC__stream_encoder_get_total_samples_estimate(encoder->private_->FLAC_stream_encoder); } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples) @@ -672,7 +730,13 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process(OggFLAC__Seekabl FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_process(encoder->private_->FLAC_seekable_stream_encoder, buffer, samples); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + if(!FLAC__stream_encoder_process(encoder->private_->FLAC_stream_encoder, buffer, samples)) { + encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR; + return false; + } + else + return true; } OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process_interleaved(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples) @@ -680,7 +744,13 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process_interleaved(OggF FLAC__ASSERT(0 != encoder); FLAC__ASSERT(0 != encoder->private_); FLAC__ASSERT(0 != encoder->protected_); - return FLAC__seekable_stream_encoder_process_interleaved(encoder->private_->FLAC_seekable_stream_encoder, buffer, samples); + FLAC__ASSERT(0 != encoder->private_->FLAC_stream_encoder); + if(!FLAC__stream_encoder_process_interleaved(encoder->private_->FLAC_stream_encoder, buffer, samples)) { + encoder->protected_->state = OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR; + return false; + } + else + return true; } /*********************************************************************** @@ -692,41 +762,242 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process_interleaved(OggF void set_defaults_(OggFLAC__SeekableStreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); encoder->private_->seek_callback = 0; encoder->private_->tell_callback = 0; encoder->private_->write_callback = 0; encoder->private_->client_data = 0; + + encoder->private_->seek_table = 0; + OggFLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect); } -FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *unused, FLAC__uint64 absolute_byte_offset, void *client_data) +FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *unused, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) { OggFLAC__SeekableStreamEncoder *encoder = (OggFLAC__SeekableStreamEncoder*)client_data; + FLAC__StreamEncoderWriteStatus status; + FLAC__uint64 output_position; + + (void)unused; /* silence compiler warning about unused parameter */ + FLAC__ASSERT(encoder->private_->FLAC_stream_encoder == unused); + + if(encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK) + return encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR; + + /* + * Watch for the STREAMINFO block and first SEEKTABLE block to go by and store their offsets. + */ + if(samples == 0) { + FLAC__MetadataType type = (buffer[0] & 0x7f); + if(type == FLAC__METADATA_TYPE_STREAMINFO) + encoder->protected_->streaminfo_offset = output_position; + else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0) + encoder->protected_->seektable_offset = output_position; + } - (void)unused; - FLAC__ASSERT(encoder->private_->FLAC_seekable_stream_encoder == unused); + /* + * Mark the current seek point if hit (if audio_offset == 0 that + * means we're still writing metadata and haven't hit the first + * frame yet) + */ + if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) { + const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder->private_->FLAC_stream_encoder); + const FLAC__uint64 frame_first_sample = encoder->private_->samples_written; + const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1; + FLAC__uint64 test_sample; + unsigned i; + for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) { + test_sample = encoder->private_->seek_table->points[i].sample_number; + if(test_sample > frame_last_sample) { + break; + } + else if(test_sample >= frame_first_sample) { + encoder->private_->seek_table->points[i].sample_number = frame_first_sample; + encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset; + encoder->private_->seek_table->points[i].frame_samples = blocksize; + encoder->private_->first_seekpoint_to_check++; + /* DO NOT: "break;" and here's why: + * The seektable template may contain more than one target + * sample for any given frame; we will keep looping, generating + * duplicate seekpoints for them, and we'll clean it up later, + * just before writing the seektable back to the metadata. + */ + } + else { + encoder->private_->first_seekpoint_to_check++; + } + } + } - return encoder->private_->seek_callback(encoder, absolute_byte_offset, encoder->private_->client_data); -} + status = OggFLAC__ogg_encoder_aspect_write_callback_wrapper(&encoder->protected_->ogg_encoder_aspect, FLAC__stream_encoder_get_total_samples_estimate(encoder->private_->FLAC_stream_encoder), buffer, bytes, samples, current_frame, (OggFLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback, encoder, encoder->private_->client_data); -FLAC__SeekableStreamEncoderTellStatus tell_callback_(const FLAC__SeekableStreamEncoder *unused, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - OggFLAC__SeekableStreamEncoder *encoder = (OggFLAC__SeekableStreamEncoder*)client_data; - - (void)unused; - FLAC__ASSERT(encoder->private_->FLAC_seekable_stream_encoder == unused); + if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { + encoder->private_->samples_written += samples; + } + else + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR; - return encoder->private_->tell_callback(encoder, absolute_byte_offset, encoder->private_->client_data); + return status; } -FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *unused, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) +void metadata_callback_(const FLAC__StreamEncoder *unused, const FLAC__StreamMetadata *metadata, void *client_data) { OggFLAC__SeekableStreamEncoder *encoder = (OggFLAC__SeekableStreamEncoder*)client_data; - const FLAC__uint64 total_samples_estimate = FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder->private_->FLAC_seekable_stream_encoder); + FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; + const FLAC__uint64 samples = metadata->data.stream_info.total_samples; + const unsigned min_framesize = metadata->data.stream_info.min_framesize; + const unsigned max_framesize = metadata->data.stream_info.max_framesize; + const unsigned bps = metadata->data.stream_info.bits_per_sample; + + FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); + + /* We get called by the stream encoder when the encoding process + * has finished so that we can update the STREAMINFO and SEEKTABLE + * blocks. + */ + + (void)unused; /* silence compiler warning about unused parameter */ + FLAC__ASSERT(encoder->private_->FLAC_stream_encoder == unused); + + /*@@@ reopen callback here? The docs currently require user to open files in update mode from the start */ + + /* All this is based on intimate knowledge of the stream header + * layout, but a change to the header format that would break this + * would also break all streams encoded in the previous format. + */ + + /* + * Write MD5 signature + */ + { + const unsigned md5_offset = + FLAC__STREAM_METADATA_HEADER_LENGTH + + ( + FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + + FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN + ) / 8; + + if(encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR; + return; + } + if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR; + return; + } + } - (void)unused; - FLAC__ASSERT(encoder->private_->FLAC_seekable_stream_encoder == unused); + /* + * Write total samples + */ + { + const unsigned total_samples_byte_offset = + FLAC__STREAM_METADATA_HEADER_LENGTH + + ( + FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + + FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + - 4 + ) / 8; + + b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F); + b[1] = (FLAC__byte)((samples >> 24) & 0xFF); + b[2] = (FLAC__byte)((samples >> 16) & 0xFF); + b[3] = (FLAC__byte)((samples >> 8) & 0xFF); + b[4] = (FLAC__byte)(samples & 0xFF); + if(encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR; + return; + } + if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR; + return; + } + } + + /* + * Write min/max framesize + */ + { + const unsigned min_framesize_offset = + FLAC__STREAM_METADATA_HEADER_LENGTH + + ( + FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + ) / 8; + + b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF); + b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF); + b[2] = (FLAC__byte)(min_framesize & 0xFF); + b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF); + b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF); + b[5] = (FLAC__byte)(max_framesize & 0xFF); + if(encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR; + return; + } + if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR; + return; + } + } - return OggFLAC__ogg_encoder_aspect_write_callback_wrapper(&encoder->protected_->ogg_encoder_aspect, total_samples_estimate, buffer, bytes, samples, current_frame, (OggFLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback, encoder, encoder->private_->client_data); + /* + * Write seektable + */ + if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) { + unsigned i; + + FLAC__format_seektable_sort(encoder->private_->seek_table); + + FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table)); + + if(encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR; + return; + } + + for(i = 0; i < encoder->private_->seek_table->num_points; i++) { + FLAC__uint64 xx; + unsigned x; + xx = encoder->private_->seek_table->points[i].sample_number; + b[7] = (FLAC__byte)xx; xx >>= 8; + b[6] = (FLAC__byte)xx; xx >>= 8; + b[5] = (FLAC__byte)xx; xx >>= 8; + b[4] = (FLAC__byte)xx; xx >>= 8; + b[3] = (FLAC__byte)xx; xx >>= 8; + b[2] = (FLAC__byte)xx; xx >>= 8; + b[1] = (FLAC__byte)xx; xx >>= 8; + b[0] = (FLAC__byte)xx; xx >>= 8; + xx = encoder->private_->seek_table->points[i].stream_offset; + b[15] = (FLAC__byte)xx; xx >>= 8; + b[14] = (FLAC__byte)xx; xx >>= 8; + b[13] = (FLAC__byte)xx; xx >>= 8; + b[12] = (FLAC__byte)xx; xx >>= 8; + b[11] = (FLAC__byte)xx; xx >>= 8; + b[10] = (FLAC__byte)xx; xx >>= 8; + b[9] = (FLAC__byte)xx; xx >>= 8; + b[8] = (FLAC__byte)xx; xx >>= 8; + x = encoder->private_->seek_table->points[i].frame_samples; + b[17] = (FLAC__byte)x; x >>= 8; + b[16] = (FLAC__byte)x; x >>= 8; + if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { + encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR; + return; + } + } + } } -- 2.7.4