📄 file_encoder.h
字号:
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2002,2003,2004,2005 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FLAC__FILE_ENCODER_H
#define FLAC__FILE_ENCODER_H
#include "export.h"
#include "seekable_stream_encoder.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \file include/FLAC/file_encoder.h
*
* \brief
* This module contains the functions which implement the file
* encoder.
*
* See the detailed documentation in the
* \link flac_file_encoder file encoder \endlink module.
*/
/** \defgroup flac_file_encoder FLAC/file_encoder.h: file encoder interface
* \ingroup flac_encoder
*
* \brief
* This module contains the functions which implement the file
* encoder.
*
* The basic usage of this encoder is as follows:
* - The program creates an instance of an encoder using
* FLAC__file_encoder_new().
* - The program overrides the default settings using
* FLAC__file_encoder_set_*() functions.
* - The program initializes the instance to validate the settings and
* prepare for encoding using FLAC__file_encoder_init().
* - The program calls FLAC__file_encoder_process() or
* FLAC__file_encoder_process_interleaved() to encode data, which
* subsequently writes data to the output file.
* - The program finishes the encoding with FLAC__file_encoder_finish(),
* which causes the encoder to encode any data still in its input pipe,
* rewind and write the STREAMINFO metadata to file, and finally reset
* the encoder to the uninitialized state.
* - The instance may be used again or deleted with
* FLAC__file_encoder_delete().
*
* The file encoder is a wrapper around the
* \link flac_seekable_stream_encoder seekable stream encoder \endlink which supplies all
* callbacks internally; the user need specify only the filename.
*
* Make sure to read the detailed description of the
* \link flac_seekable_stream_encoder seekable stream encoder module \endlink since the
* \link flac_stream_encoder stream encoder module \endlink since the
* file encoder inherits much of its behavior from them.
*
* \note
* The "set" functions may only be called when the encoder is in the
* state FLAC__FILE_ENCODER_UNINITIALIZED, i.e. after
* FLAC__file_encoder_new() or FLAC__file_encoder_finish(), but
* before FLAC__file_encoder_init(). If this is the case they will
* return \c true, otherwise \c false.
*
* \note
* FLAC__file_encoder_finish() resets all settings to the constructor
* defaults.
*
* \{
*/
/** State values for a FLAC__FileEncoder
*
* The encoder's state can be obtained by calling FLAC__file_encoder_get_state().
*/
typedef enum {
FLAC__FILE_ENCODER_OK = 0,
/**< The encoder is in the normal OK state. */
FLAC__FILE_ENCODER_NO_FILENAME,
/**< FLAC__file_encoder_init() was called without first calling
* FLAC__file_encoder_set_filename().
*/
FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR,
/**< An error occurred in the underlying seekable stream encoder;
* check FLAC__file_encoder_get_seekable_stream_encoder_state().
*/
FLAC__FILE_ENCODER_FATAL_ERROR_WHILE_WRITING,
/**< A fatal error occurred while writing to the encoded file. */
FLAC__FILE_ENCODER_ERROR_OPENING_FILE,
/**< An error occurred opening the output file for writing. */
FLAC__FILE_ENCODER_MEMORY_ALLOCATION_ERROR,
/**< Memory allocation failed. */
FLAC__FILE_ENCODER_ALREADY_INITIALIZED,
/**< FLAC__file_encoder_init() was called when the encoder was
* already initialized, usually because
* FLAC__file_encoder_finish() was not called.
*/
FLAC__FILE_ENCODER_UNINITIALIZED
/**< The encoder is in the uninitialized state. */
} FLAC__FileEncoderState;
/** Maps a FLAC__FileEncoderState to a C string.
*
* Using a FLAC__FileEncoderState as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__FileEncoderStateString[];
/***********************************************************************
*
* class FLAC__FileEncoder
*
***********************************************************************/
struct FLAC__FileEncoderProtected;
struct FLAC__FileEncoderPrivate;
/** The opaque structure definition for the file encoder type.
* See the \link flac_file_encoder file encoder module \endlink
* for a detailed description.
*/
typedef struct {
struct FLAC__FileEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
struct FLAC__FileEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
} FLAC__FileEncoder;
/** Signature for the progress callback.
* See FLAC__file_encoder_set_progress_callback() for more info.
*
* \param encoder The encoder instance calling the callback.
* \param bytes_written Bytes written so far.
* \param samples_written Samples written so far.
* \param frames_written Frames written so far.
* \param total_frames_estimate The estimate of the total number of
* frames to be written.
* \param client_data The callee's client data set through
* FLAC__file_encoder_set_client_data().
*/
typedef void (*FLAC__FileEncoderProgressCallback)(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
/***********************************************************************
*
* Class constructor/destructor
*
***********************************************************************/
/** Create a new file encoder instance. The instance is created with
* default settings; see the individual FLAC__file_encoder_set_*()
* functions for each setting's default.
*
* \retval FLAC__FileEncoder*
* \c NULL if there was an error allocating memory, else the new instance.
*/
FLAC_API FLAC__FileEncoder *FLAC__file_encoder_new();
/** Free an encoder instance. Deletes the object pointed to by \a encoder.
*
* \param encoder A pointer to an existing encoder.
* \assert
* \code encoder != NULL \endcode
*/
FLAC_API void FLAC__file_encoder_delete(FLAC__FileEncoder *encoder);
/***********************************************************************
*
* Public class method prototypes
*
***********************************************************************/
/** This is inherited from FLAC__SeekableStreamEncoder; see
* FLAC__seekable_stream_encoder_set_verify().
*
* \default \c true
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
FLAC_API FLAC__bool FLAC__file_encoder_set_verify(FLAC__FileEncoder *encoder, FLAC__bool value);
/** This is inherited from FLAC__SeekableStreamEncoder; see
* FLAC__seekable_stream_encoder_set_streamable_subset().
*
* \default \c true
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
FLAC_API FLAC__bool FLAC__file_encoder_set_streamable_subset(FLAC__FileEncoder *encoder, FLAC__bool value);
/** This is inherited from FLAC__SeekableStreamEncoder; see
* FLAC__seekable_stream_encoder_set_do_mid_side_stereo().
*
* \default \c false
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
FLAC_API FLAC__bool FLAC__file_encoder_set_do_mid_side_stereo(FLAC__FileEncoder *encoder, FLAC__bool value);
/** This is inherited from FLAC__SeekableStreamEncoder; see
* FLAC__seekable_stream_encoder_set_loose_mid_side_stereo().
*
* \default \c false
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
FLAC_API FLAC__bool FLAC__file_encoder_set_loose_mid_side_stereo(FLAC__FileEncoder *encoder, FLAC__bool value);
/** This is inherited from FLAC__SeekableStreamEncoder; see
* FLAC__seekable_stream_encoder_set_channels().
*
* \default \c 2
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
FLAC_API FLAC__bool FLAC__file_encoder_set_channels(FLAC__FileEncoder *encoder, unsigned value);
/** This is inherited from FLAC__SeekableStreamEncoder; see
* FLAC__seekable_stream_encoder_set_bits_per_sample().
*
* \warning
* Do not feed the encoder data that is wider than the value you
* set here or you will generate an invalid stream.
*
* \default \c 16
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
* \c false if the encoder is already initialized, else \c true.
*/
FLAC_API FLAC__bool FLAC__file_encoder_set_bits_per_sample(FLAC__FileEncoder *encoder, unsigned value);
/** This is inherited from FLAC__SeekableStreamEncoder; see
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -