diff options
author | Josh Coalson <jcoalson@users.sourceforce.net> | 2001-06-13 17:59:57 +0000 |
---|---|---|
committer | Josh Coalson <jcoalson@users.sourceforce.net> | 2001-06-13 17:59:57 +0000 |
commit | 0a15c14c6ee1d1fbaf3fe17c09dad8518100d79b (patch) | |
tree | 6e2ced5ac9778380b7d324bf7c0bd5f25f0a67f4 /include | |
parent | 244ce1114c2827ad8485f8999413652c5a0b7b0e (diff) | |
download | flac-0a15c14c6ee1d1fbaf3fe17c09dad8518100d79b.tar.gz |
rename FLAC__Encoder to FLAC__StreamEncoder, OOPize encoder and decoder interfaces
Diffstat (limited to 'include')
-rw-r--r-- | include/FLAC/Makefile.am | 7 | ||||
-rw-r--r-- | include/FLAC/all.h | 2 | ||||
-rw-r--r-- | include/FLAC/file_decoder.h | 56 | ||||
-rw-r--r-- | include/FLAC/stream_decoder.h | 61 | ||||
-rw-r--r-- | include/FLAC/stream_encoder.h | 160 |
5 files changed, 209 insertions, 77 deletions
diff --git a/include/FLAC/Makefile.am b/include/FLAC/Makefile.am index 7bfd4f7e..a79041a1 100644 --- a/include/FLAC/Makefile.am +++ b/include/FLAC/Makefile.am @@ -17,11 +17,12 @@ includedir = ${prefix}/include/FLAC -include_HEADERS = all.h \ +include_HEADERS = \ + all.h \ assert.h \ - encoder.h \ file_decoder.h \ format.h \ ordinals.h \ seek_table.h \ - stream_decoder.h + stream_decoder.h \ + stream_encoder.h diff --git a/include/FLAC/all.h b/include/FLAC/all.h index cc19d242..3a4c13db 100644 --- a/include/FLAC/all.h +++ b/include/FLAC/all.h @@ -21,11 +21,11 @@ #define FLAC__ALL_H #include "assert.h" -#include "encoder.h" #include "file_decoder.h" #include "format.h" #include "ordinals.h" #include "seek_table.h" #include "stream_decoder.h" +#include "stream_encoder.h" #endif diff --git a/include/FLAC/file_decoder.h b/include/FLAC/file_decoder.h index c219a8a3..e64507e5 100644 --- a/include/FLAC/file_decoder.h +++ b/include/FLAC/file_decoder.h @@ -31,35 +31,75 @@ typedef enum { FLAC__FILE_DECODER_SEEK_ERROR, FLAC__FILE_DECODER_STREAM_ERROR, FLAC__FILE_DECODER_MD5_ERROR, + FLAC__FILE_DECODER_STREAM_DECODER_ERROR, + FLAC__FILE_DECODER_ALREADY_INITIALIZED, FLAC__FILE_DECODER_UNINITIALIZED } FLAC__FileDecoderState; extern const char *FLAC__FileDecoderStateString[]; +/*********************************************************************** + * + * class FLAC__FileDecoder : public FLAC__StreamDecoder + * + ***********************************************************************/ + +struct FLAC__FileDecoderProtected; struct FLAC__FileDecoderPrivate; typedef struct { - /* this field may not change once FLAC__file_decoder_init() is called */ - bool check_md5; /* if true, generate MD5 signature of decoded data and compare against signature in the Encoding metadata block */ - - FLAC__FileDecoderState state; /* must be FLAC__FILE_DECODER_UNINITIALIZED when passed to FLAC__file_decoder_init() */ - struct FLAC__FileDecoderPrivate *guts; /* must be 0 when passed to FLAC__file_decoder_init() */ + struct FLAC__FileDecoderProtected *protected; + struct FLAC__FileDecoderPrivate *private; } FLAC__FileDecoder; -FLAC__FileDecoder *FLAC__file_decoder_get_new_instance(); -void FLAC__file_decoder_free_instance(FLAC__FileDecoder *decoder); +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +FLAC__FileDecoder *FLAC__file_decoder_new(); +void FLAC__file_decoder_delete(FLAC__FileDecoder *); + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/* + * Initialize the instance; should be called after construction and + * before any other calls. Will set and return the decoder state, + * which will be FLAC__FILE_DECODER_OK if initialization succeeded. + */ FLAC__FileDecoderState FLAC__file_decoder_init( FLAC__FileDecoder *decoder, + bool check_md5, const char *filename, FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data), void (*metadata_callback)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data), void (*error_callback)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data), void *client_data ); -/* only returns false if check_md5 is set AND the stored MD5 sum is non-zero AND the stored MD5 sum and computed MD5 sum do not match */ +/* + * only returns false if check_md5 is set AND the stored MD5 sum + * is non-zero AND the stored MD5 sum and computed MD5 sum do not + * match + */ bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder); + +/* + * methods to return the file decoder state and check_md5 flag + */ +FLAC__FileDecoderState FLAC__file_decoder_state(const FLAC__FileDecoder *decoder); +bool FLAC__file_decoder_check_md5(const FLAC__FileDecoder *decoder); + +/* + * methods for decoding the data + */ bool FLAC__file_decoder_process_whole_file(FLAC__FileDecoder *decoder); bool FLAC__file_decoder_process_metadata(FLAC__FileDecoder *decoder); bool FLAC__file_decoder_process_one_frame(FLAC__FileDecoder *decoder); bool FLAC__file_decoder_process_remaining_frames(FLAC__FileDecoder *decoder); + bool FLAC__file_decoder_seek_absolute(FLAC__FileDecoder *decoder, uint64 sample); #endif diff --git a/include/FLAC/stream_decoder.h b/include/FLAC/stream_decoder.h index 46ade23e..a34ba80f 100644 --- a/include/FLAC/stream_decoder.h +++ b/include/FLAC/stream_decoder.h @@ -31,6 +31,7 @@ typedef enum { FLAC__STREAM_DECODER_ABORTED, FLAC__STREAM_DECODER_UNPARSEABLE_STREAM, FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR, + FLAC__STREAM_DECODER_ALREADY_INITIALIZED, FLAC__STREAM_DECODER_UNINITIALIZED } FLAC__StreamDecoderState; extern const char *FLAC__StreamDecoderStateString[]; @@ -55,20 +56,40 @@ typedef enum { } FLAC__StreamDecoderErrorStatus; extern const char *FLAC__StreamDecoderErrorStatusString[]; +/*********************************************************************** + * + * class FLAC__StreamDecoder + * + ***********************************************************************/ + +struct FLAC__StreamDecoderProtected; struct FLAC__StreamDecoderPrivate; typedef struct { - /* these fields are read-only and valid as of the last write_callback() */ - unsigned channels; - FLAC__ChannelAssignment channel_assignment; - unsigned bits_per_sample; - unsigned sample_rate; /* in Hz */ - unsigned blocksize; /* in samples (per channel) */ - FLAC__StreamDecoderState state; /* must be FLAC__STREAM_DECODER_UNINITIALIZED when passed to FLAC__stream_decoder_init() */ - struct FLAC__StreamDecoderPrivate *guts; /* must be 0 when passed to FLAC__stream_decoder_init() */ + struct FLAC__StreamDecoderProtected *protected; + struct FLAC__StreamDecoderPrivate *private; } FLAC__StreamDecoder; -FLAC__StreamDecoder *FLAC__stream_decoder_get_new_instance(); -void FLAC__stream_decoder_free_instance(FLAC__StreamDecoder *decoder); +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +FLAC__StreamDecoder *FLAC__stream_decoder_new(); +void FLAC__stream_decoder_delete(FLAC__StreamDecoder *); + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/* + * Initialize the instance; should be called after construction and + * before any other calls. Will set and return the decoder state which + * will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization + * succeeded. + */ FLAC__StreamDecoderState FLAC__stream_decoder_init( FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadStatus (*read_callback)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data), @@ -78,8 +99,28 @@ FLAC__StreamDecoderState FLAC__stream_decoder_init( void *client_data ); void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder); + +/* + * methods to return the stream decoder state, number of channels, + * channel assignment, bits-per-sample, sample rate in Hz, and + * blocksize in samples. + */ +FLAC__StreamDecoderState FLAC__stream_decoder_state(const FLAC__StreamDecoder *decoder); +unsigned FLAC__stream_decoder_channels(const FLAC__StreamDecoder *decoder); +FLAC__ChannelAssignment FLAC__stream_decoder_channel_assignment(const FLAC__StreamDecoder *decoder); +unsigned FLAC__stream_decoder_bits_per_sample(const FLAC__StreamDecoder *decoder); +unsigned FLAC__stream_decoder_sample_rate(const FLAC__StreamDecoder *decoder); +unsigned FLAC__stream_decoder_blocksize(const FLAC__StreamDecoder *decoder); + +/* + * state control methods + */ bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder); bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder); + +/* + * methods for decoding the data + */ bool FLAC__stream_decoder_process_whole_stream(FLAC__StreamDecoder *decoder); bool FLAC__stream_decoder_process_metadata(FLAC__StreamDecoder *decoder); bool FLAC__stream_decoder_process_one_frame(FLAC__StreamDecoder *decoder); diff --git a/include/FLAC/stream_encoder.h b/include/FLAC/stream_encoder.h index ff12fab0..8f50e01e 100644 --- a/include/FLAC/stream_encoder.h +++ b/include/FLAC/stream_encoder.h @@ -17,71 +17,121 @@ * Boston, MA 02111-1307, USA. */ -#ifndef FLAC__ENCODER_H -#define FLAC__ENCODER_H +#ifndef FLAC__STREAM_ENCODER_H +#define FLAC__STREAM_ENCODER_H #include "format.h" typedef enum { - FLAC__ENCODER_WRITE_OK = 0, - FLAC__ENCODER_WRITE_FATAL_ERROR -} FLAC__EncoderWriteStatus; -extern const char *FLAC__EncoderWriteStatusString[]; + FLAC__STREAM_ENCODER_OK = 0, + FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS, + FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE, + FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE, + FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE, + FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION, + FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH, + FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH, + FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE, + FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER, + FLAC__STREAM_ENCODER_NOT_STREAMABLE, + FLAC__STREAM_ENCODER_FRAMING_ERROR, + FLAC__STREAM_ENCODER_INVALID_SEEK_TABLE, + FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING, + FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING, /* that is, the write_callback returned an error */ + FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR, + FLAC__STREAM_ENCODER_ALREADY_INITIALIZED, + FLAC__STREAM_ENCODER_UNINITIALIZED +} FLAC__StreamEncoderState; +extern const char *FLAC__StreamEncoderStateString[]; typedef enum { - FLAC__ENCODER_OK = 0, - FLAC__ENCODER_UNINITIALIZED, - FLAC__ENCODER_INVALID_NUMBER_OF_CHANNELS, - FLAC__ENCODER_INVALID_BITS_PER_SAMPLE, - FLAC__ENCODER_INVALID_SAMPLE_RATE, - FLAC__ENCODER_INVALID_BLOCK_SIZE, - FLAC__ENCODER_INVALID_QLP_COEFF_PRECISION, - FLAC__ENCODER_MID_SIDE_CHANNELS_MISMATCH, - FLAC__ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH, - FLAC__ENCODER_ILLEGAL_MID_SIDE_FORCE, - FLAC__ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER, - FLAC__ENCODER_NOT_STREAMABLE, - FLAC__ENCODER_FRAMING_ERROR, - FLAC__ENCODER_INVALID_SEEK_TABLE, - FLAC__ENCODER_FATAL_ERROR_WHILE_ENCODING, - FLAC__ENCODER_FATAL_ERROR_WHILE_WRITING, /* that is, the write_callback returned an error */ - FLAC__ENCODER_MEMORY_ALLOCATION_ERROR -} FLAC__EncoderState; -extern const char *FLAC__EncoderStateString[]; + FLAC__STREAM_ENCODER_WRITE_OK = 0, + FLAC__STREAM_ENCODER_WRITE_FATAL_ERROR +} FLAC__StreamEncoderWriteStatus; +extern const char *FLAC__StreamEncoderWriteStatusString[]; -struct FLAC__EncoderPrivate; +/*********************************************************************** + * + * class FLAC__StreamEncoder + * + ***********************************************************************/ + +struct FLAC__StreamEncoderProtected; +struct FLAC__StreamEncoderPrivate; typedef struct { - /* - * none of these fields may change once FLAC__encoder_init() is called - */ - struct FLAC__EncoderPrivate *guts; /* must be 0 when passed to FLAC__encoder_init() */ - FLAC__EncoderState state; /* must be FLAC__ENCODER_UNINITIALIZED when passed to FLAC__encoder_init() */ - bool streamable_subset; - bool do_mid_side_stereo; /* 0 or 1; 1 only if channels==2 */ - bool loose_mid_side_stereo; /* 0 or 1; 1 only if channels==2 and do_mid_side_stereo==true */ - unsigned channels; /* must be <= FLAC__MAX_CHANNELS */ - unsigned bits_per_sample; /* do not give the encoder wider data than what you specify here or bad things will happen! */ - unsigned sample_rate; - unsigned blocksize; - unsigned max_lpc_order; /* 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER */ - unsigned qlp_coeff_precision; /* >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize; */ + struct FLAC__StreamEncoderProtected *protected; + struct FLAC__StreamEncoderPrivate *private; +} FLAC__StreamEncoder; + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +FLAC__StreamEncoder *FLAC__stream_encoder_new(); +void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder); + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/* + * Initialize the instance; should be called after construction and + * before any other calls. Will set and return the encoder state, + * which will be FLAC__STREAM_ENCODER_OK if initialization succeeded. + */ +FLAC__StreamEncoderState FLAC__stream_encoder_init( + FLAC__StreamEncoder *encoder, + bool streamable_subset, + bool do_mid_side_stereo, /* 0 or 1; 1 only if channels==2 */ + bool loose_mid_side_stereo, /* 0 or 1; 1 only if channels==2 and do_mid_side_stereo==true */ + unsigned channels, /* must be <= FLAC__MAX_CHANNELS */ + unsigned bits_per_sample, /* do not give the encoder wider data than what you specify here or bad things will happen! */ + unsigned sample_rate, + unsigned blocksize, + unsigned max_lpc_order, /* 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER */ + unsigned qlp_coeff_precision, /* >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize; */ /* qlp_coeff_precision+bits_per_sample must be < 32 */ - bool do_qlp_coeff_prec_search; /* 0 => use qlp_coeff_precision, 1 => search around qlp_coeff_precision, take best */ - bool do_exhaustive_model_search; /* 0 => use estimated bits per residual for scoring, 1 => generate all, take shortest */ - unsigned min_residual_partition_order; /* 0 => estimate Rice parameter based on residual variance; >0 => partition residual, use parameter for each */ - unsigned max_residual_partition_order; /* based on mean; min_ and max_ specify the min and max Rice partition order */ - unsigned rice_parameter_search_dist; /* 0 => try only calc'd parameter k; else try all [k-dist..k+dist] parameters, use best */ - uint64 total_samples_estimate; /* may be 0 if unknown. this will be a placeholder in the metadata block until the actual total is calculated */ - const FLAC__StreamMetaData_SeekTable *seek_table; /* optional seek_table to prepend, 0 => no seek table */ - unsigned padding; /* size of PADDING block to add (goes after seek table); 0 => do not add a PADDING block */ -} FLAC__Encoder; + bool do_qlp_coeff_prec_search, /* 0 => use qlp_coeff_precision, 1 => search around qlp_coeff_precision, take best */ + bool do_exhaustive_model_search, /* 0 => use estimated bits per residual for scoring, 1 => generate all, take shortest */ + unsigned min_residual_partition_order, /* 0 => estimate Rice parameter based on residual variance; >0 => partition residual, use parameter for each */ + unsigned max_residual_partition_order, /* based on mean; min_ and max_ specify the min and max Rice partition order */ + unsigned rice_parameter_search_dist, /* 0 => try only calc'd parameter k; else try all [k-dist..k+dist] parameters, use best */ + uint64 total_samples_estimate, /* may be 0 if unknown. this will be a placeholder in the metadata block until the actual total is calculated */ + const FLAC__StreamMetaData_SeekTable *seek_table, /* optional seek_table to prepend, 0 => no seek table */ + unsigned padding, /* size of PADDING block to add (goes after seek table); 0 => do not add a PADDING block */ + FLAC__StreamEncoderWriteStatus (*write_callback)(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data), + void (*metadata_callback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data), + void *client_data +); +void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder); +/* + * various "get" methods + */ +FLAC__StreamEncoderState FLAC__stream_encoder_state(const FLAC__StreamEncoder *encoder); +bool FLAC__stream_encoder_streamable_subset(const FLAC__StreamEncoder *encoder); +bool FLAC__stream_encoder_do_mid_side_stereo(const FLAC__StreamEncoder *encoder); +bool FLAC__stream_encoder_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_channels(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_bits_per_sample(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_sample_rate(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_blocksize(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_max_lpc_order(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_qlp_coeff_precision(const FLAC__StreamEncoder *encoder); +bool FLAC__stream_encoder_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder); +bool FLAC__stream_encoder_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_min_residual_partition_order(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_max_residual_partition_order(const FLAC__StreamEncoder *encoder); +unsigned FLAC__stream_encoder_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder); -FLAC__Encoder *FLAC__encoder_get_new_instance(); -void FLAC__encoder_free_instance(FLAC__Encoder *encoder); -FLAC__EncoderState FLAC__encoder_init(FLAC__Encoder *encoder, FLAC__EncoderWriteStatus (*write_callback)(const FLAC__Encoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data), void (*metadata_callback)(const FLAC__Encoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data), void *client_data); -void FLAC__encoder_finish(FLAC__Encoder *encoder); -bool FLAC__encoder_process(FLAC__Encoder *encoder, const int32 *buf[], unsigned samples); -bool FLAC__encoder_process_interleaved(FLAC__Encoder *encoder, const int32 buf[], unsigned samples); +/* + * methods for encoding the data + */ +bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const int32 *buf[], unsigned samples); +bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const int32 buf[], unsigned samples); #endif |