📄 seekable_stream_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__SEEKABLE_STREAM_ENCODER_H
#define FLAC__SEEKABLE_STREAM_ENCODER_H
#include "export.h"
#include "stream_encoder.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \file include/FLAC/seekable_stream_encoder.h
*
* \brief
* This module contains the functions which implement the seekable stream
* encoder.
*
* See the detailed documentation in the
* \link flac_seekable_stream_encoder seekable stream encoder \endlink module.
*/
/** \defgroup flac_seekable_stream_encoder FLAC/seekable_stream_encoder.h: seekable stream encoder interface
* \ingroup flac_encoder
*
* \brief
* This module contains the functions which implement the seekable stream
* encoder.
*
* The basic usage of this encoder is as follows:
* - The program creates an instance of an encoder using
* FLAC__seekable_stream_encoder_new().
* - The program overrides the default settings and sets callbacks using
* FLAC__seekable_stream_encoder_set_*() functions.
* - The program initializes the instance to validate the settings and
* prepare for encoding using FLAC__seekable_stream_encoder_init().
* - The program calls FLAC__seekable_stream_encoder_process() or
* FLAC__seekable_stream_encoder_process_interleaved() to encode data, which
* subsequently calls the callbacks when there is encoder data ready
* to be written.
* - The program finishes the encoding with FLAC__seekable_stream_encoder_finish(),
* which causes the encoder to encode any data still in its input pipe,
* rewrite the metadata with the final encoding statistics, and finally
* reset the encoder to the uninitialized state.
* - The instance may be used again or deleted with
* FLAC__seekable_stream_encoder_delete().
*
* The seekable stream encoder is a wrapper around the
* \link flac_stream_encoder stream encoder \endlink with callbacks for
* seeking the output and reporting the output stream position. This
* allows the encoder to go back and rewrite some of the metadata after
* encoding if necessary, and provides the metadata callback of the stream
* encoder internally. However, you must provide seek and tell callbacks
* (see FLAC__seekable_stream_encoder_set_seek_callback() and
* FLAC__seekable_stream_encoder_set_tell_callback()).
*
* Make sure to read the detailed description of the
* \link flac_stream_encoder stream encoder module \endlink since the
* seekable stream encoder inherits much of its behavior.
*
* \note
* If you are writing the FLAC data to a file, make sure it is open
* for update (e.g. mode "w+" for stdio streams). This is because after
* the first encoding pass, the encoder will try to seek back to the
* beginning of the stream, to the STREAMINFO block, to write some data
* there.
*
* \note
* The "set" functions may only be called when the encoder is in the
* state FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED, i.e. after
* FLAC__seekable_stream_encoder_new() or FLAC__seekable_stream_encoder_finish(), but
* before FLAC__seekable_stream_encoder_init(). If this is the case they will
* return \c true, otherwise \c false.
*
* \note
* FLAC__seekable_stream_encoder_finish() resets all settings to the constructor
* defaults, including the callbacks.
*
* \{
*/
/** State values for a FLAC__SeekableStreamEncoder
*
* The encoder's state can be obtained by calling FLAC__seekable_stream_encoder_get_state().
*/
typedef enum {
FLAC__SEEKABLE_STREAM_ENCODER_OK = 0,
/**< The encoder is in the normal OK state. */
FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR,
/**< An error occurred in the underlying stream encoder;
* check FLAC__seekable_stream_encoder_get_stream_encoder_state().
*/
FLAC__SEEKABLE_STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
/**< Memory allocation failed. */
FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR,
/**< The write callback returned an error. */
FLAC__SEEKABLE_STREAM_ENCODER_READ_ERROR,
/**< The read callback returned an error. */
FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR,
/**< The seek callback returned an error. */
FLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR,
/**< The tell callback returned an error. */
FLAC__SEEKABLE_STREAM_ENCODER_ALREADY_INITIALIZED,
/**< FLAC__seekable_stream_encoder_init() was called when the encoder was
* already initialized, usually because
* FLAC__seekable_stream_encoder_finish() was not called.
*/
FLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK,
/**< FLAC__seekable_stream_encoder_init() was called without all
* callbacks being set.
*/
FLAC__SEEKABLE_STREAM_ENCODER_INVALID_SEEKTABLE,
/**< An invalid seek table was passed is the metadata to
* FLAC__seekable_stream_encoder_set_metadata().
*/
FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED
/**< The encoder is in the uninitialized state. */
} FLAC__SeekableStreamEncoderState;
/** Maps a FLAC__SeekableStreamEncoderState to a C string.
*
* Using a FLAC__SeekableStreamEncoderState as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__SeekableStreamEncoderStateString[];
/** Return values for the FLAC__SeekableStreamEncoder seek callback.
*/
typedef enum {
FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK,
/**< The seek was OK and encoding can continue. */
FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_ERROR
/**< An unrecoverable error occurred. The encoder will return from the process call. */
} FLAC__SeekableStreamEncoderSeekStatus;
/** Maps a FLAC__SeekableStreamEncoderSeekStatus to a C string.
*
* Using a FLAC__SeekableStreamEncoderSeekStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__SeekableStreamEncoderSeekStatusString[];
/** Return values for the FLAC__SeekableStreamEncoder tell callback.
*/
typedef enum {
FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK,
/**< The tell was OK and encoding can continue. */
FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_ERROR
/**< An unrecoverable error occurred. The encoder will return from the process call. */
} FLAC__SeekableStreamEncoderTellStatus;
/** Maps a FLAC__SeekableStreamEncoderTellStatus to a C string.
*
* Using a FLAC__SeekableStreamEncoderTellStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__SeekableStreamEncoderTellStatusString[];
/***********************************************************************
*
* class FLAC__SeekableStreamEncoder
*
***********************************************************************/
struct FLAC__SeekableStreamEncoderProtected;
struct FLAC__SeekableStreamEncoderPrivate;
/** The opaque structure definition for the seekable stream encoder type.
* See the \link flac_seekable_stream_encoder seekable stream encoder module \endlink
* for a detailed description.
*/
typedef struct {
struct FLAC__SeekableStreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
struct FLAC__SeekableStreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
} FLAC__SeekableStreamEncoder;
/** Signature for the seek callback.
* See FLAC__seekable_stream_encoder_set_seek_callback() for more info.
*
* \param encoder The encoder instance calling the callback.
* \param absolute_byte_offset The offset from the beginning of the stream
* to seek to.
* \param client_data The callee's client data set through
* FLAC__seekable_stream_encoder_set_client_data().
* \retval FLAC__SeekableStreamEncoderSeekStatus
* The callee's return status.
*/
typedef FLAC__SeekableStreamEncoderSeekStatus (*FLAC__SeekableStreamEncoderSeekCallback)(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
/** Signature for the tell callback.
* See FLAC__seekable_stream_encoder_set_tell_callback() for more info.
*
* \warning
* The callback must return the true current byte offset of the output to
* which the encoder is writing. If you are buffering the output, make
* sure and take this into account. If you are writing directly to a
* FILE* from your write callback, ftell() is sufficient. If you are
* writing directly to a file descriptor from your write callback, you
* can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to
* these points to rewrite metadata after encoding.
*
* \param encoder The encoder instance calling the callback.
* \param absolute_byte_offset The address at which to store the current
* position of the output.
* \param client_data The callee's client data set through
* FLAC__seekable_stream_encoder_set_client_data().
* \retval FLAC__SeekableStreamEncoderTellStatus
* The callee's return status.
*/
typedef FLAC__SeekableStreamEncoderTellStatus (*FLAC__SeekableStreamEncoderTellCallback)(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
/** Signature for the write callback.
* See FLAC__seekable_stream_encoder_set_write_callback()
* and FLAC__StreamEncoderWriteCallback for more info.
*
* \param encoder The encoder instance calling the callback.
* \param buffer An array of encoded data of length \a bytes.
* \param bytes The byte length of \a buffer.
* \param samples The number of samples encoded by \a buffer.
* \c 0 has a special meaning; see
* FLAC__stream_encoder_set_write_callback().
* \param current_frame The number of current frame being encoded.
* \param client_data The callee's client data set through
* FLAC__seekable_stream_encoder_set_client_data().
* \retval FLAC__StreamEncoderWriteStatus
* The callee's return status.
*/
typedef FLAC__StreamEncoderWriteStatus (*FLAC__SeekableStreamEncoderWriteCallback)(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
/***********************************************************************
*
* Class constructor/destructor
*
***********************************************************************/
/** Create a new seekable stream encoder instance. The instance is created with
* default settings; see the individual FLAC__seekable_stream_encoder_set_*()
* functions for each setting's default.
*
* \retval FLAC__SeekableStreamEncoder*
* \c NULL if there was an error allocating memory, else the new instance.
*/
FLAC_API FLAC__SeekableStreamEncoder *FLAC__seekable_stream_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__seekable_stream_encoder_delete(FLAC__SeekableStreamEncoder *encoder);
/***********************************************************************
*
* Public class method prototypes
*
***********************************************************************/
/** This is inherited from FLAC__StreamEncoder; see
* FLAC__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__seekable_stream_encoder_set_verify(FLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
/** This is inherited from FLAC__StreamEncoder; see
* FLAC__stream_encoder_set_streamable_subset().
*
* \default \c true
* \param encoder An encoder instance to set.
* \param value See above.
* \assert
* \code encoder != NULL \endcode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -