Loading...
Searching...
No Matches
opusenc.h
/* Copyright (c) 2017 Jean-Marc Valin */
/*
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.
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 COPYRIGHT OWNER
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 OPUSENC_H
# define OPUSENC_H
# if defined(__cplusplus)
extern "C" {
# endif
#include <stddef.h>
#include <opus.h>
#ifndef OPE_EXPORT
# if defined(WIN32)
# if defined(OPE_BUILD) && defined(DLL_EXPORT)
# define OPE_EXPORT __declspec(dllexport)
# else
# define OPE_EXPORT
# endif
# elif defined(__GNUC__) && defined(OPE_BUILD)
# define OPE_EXPORT __attribute__ ((visibility ("default")))
# else
# define OPE_EXPORT
# endif
#endif
/* Bump this when we change the API. */
#define OPE_API_VERSION 0
#define OPE_OK 0
/* Based on the relevant libopus code minus 10. */
#define OPE_BAD_ARG -11
#define OPE_INTERNAL_ERROR -13
#define OPE_UNIMPLEMENTED -15
#define OPE_ALLOC_FAIL -17
/* Specific to libopusenc. */
#define OPE_CANNOT_OPEN -30
#define OPE_TOO_LATE -31
#define OPE_INVALID_PICTURE -32
#define OPE_INVALID_ICON -33
#define OPE_WRITE_FAIL -34
#define OPE_CLOSE_FAIL -35
/* These are the "raw" request values -- they should usually not be used. */
#define OPE_SET_DECISION_DELAY_REQUEST 14000
#define OPE_GET_DECISION_DELAY_REQUEST 14001
#define OPE_SET_MUXING_DELAY_REQUEST 14002
#define OPE_GET_MUXING_DELAY_REQUEST 14003
#define OPE_SET_COMMENT_PADDING_REQUEST 14004
#define OPE_GET_COMMENT_PADDING_REQUEST 14005
#define OPE_SET_SERIALNO_REQUEST 14006
#define OPE_GET_SERIALNO_REQUEST 14007
#define OPE_SET_PACKET_CALLBACK_REQUEST 14008
/*#define OPE_GET_PACKET_CALLBACK_REQUEST 14009*/
#define OPE_SET_HEADER_GAIN_REQUEST 14010
#define OPE_GET_HEADER_GAIN_REQUEST 14011
#define OPE_GET_NB_STREAMS_REQUEST 14013
#define OPE_GET_NB_COUPLED_STREAMS_REQUEST 14015
/* Macros to trigger compilation errors when the wrong types are provided to a CTL. */
/* These macros are not part of the API and are only for use within the macros below. */
#define ope_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
#define ope_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
#define ope_check_packet_func(x) ((void)((void (*)(void *, const unsigned char *, opus_int32, opus_uint32))0 == (x)), (x))
#define ope_check_void_ptr(x) ((void)((void *)0 == (x)), (x))
#define OPE_SET_DECISION_DELAY(x) OPE_SET_DECISION_DELAY_REQUEST, ope_check_int(x)
#define OPE_GET_DECISION_DELAY(x) OPE_GET_DECISION_DELAY_REQUEST, ope_check_int_ptr(x)
#define OPE_SET_MUXING_DELAY(x) OPE_SET_MUXING_DELAY_REQUEST, ope_check_int(x)
#define OPE_GET_MUXING_DELAY(x) OPE_GET_MUXING_DELAY_REQUEST, ope_check_int_ptr(x)
#define OPE_SET_COMMENT_PADDING(x) OPE_SET_COMMENT_PADDING_REQUEST, ope_check_int(x)
#define OPE_GET_COMMENT_PADDING(x) OPE_GET_COMMENT_PADDING_REQUEST, ope_check_int_ptr(x)
#define OPE_SET_SERIALNO(x) OPE_SET_SERIALNO_REQUEST, ope_check_int(x)
#define OPE_GET_SERIALNO(x) OPE_GET_SERIALNO_REQUEST, ope_check_int_ptr(x)
#define OPE_SET_PACKET_CALLBACK(x,u) OPE_SET_PACKET_CALLBACK_REQUEST, ope_check_packet_func(x), ope_check_void_ptr(u)
/*#define OPE_GET_PACKET_CALLBACK(x,u) OPE_GET_PACKET_CALLBACK_REQUEST, (x), (u)*/
#define OPE_SET_HEADER_GAIN(x) OPE_SET_HEADER_GAIN_REQUEST, ope_check_int(x)
#define OPE_GET_HEADER_GAIN(x) OPE_GET_HEADER_GAIN_REQUEST, ope_check_int_ptr(x)
#define OPE_GET_NB_STREAMS(x) OPE_GET_NB_STREAMS_REQUEST, ope_check_int_ptr(x)
#define OPE_GET_NB_COUPLED_STREAMS(x) OPE_GET_NB_COUPLED_STREAMS_REQUEST, ope_check_int_ptr(x)
typedef int (*ope_write_func)(void *user_data, const unsigned char *ptr, opus_int32 len);
typedef int (*ope_close_func)(void *user_data);
typedef void (*ope_packet_func)(void *user_data, const unsigned char *packet_ptr, opus_int32 packet_len, opus_uint32 flags);
typedef struct {
ope_write_func write;
ope_close_func close;
} OpusEncCallbacks;
typedef struct OggOpusComments OggOpusComments;
typedef struct OggOpusEnc OggOpusEnc;
OPE_EXPORT OggOpusComments *ope_comments_create(void);
OPE_EXPORT OggOpusComments *ope_comments_copy(OggOpusComments *comments);
OPE_EXPORT void ope_comments_destroy(OggOpusComments *comments);
OPE_EXPORT int ope_comments_add(OggOpusComments *comments, const char *tag, const char *val);
OPE_EXPORT int ope_comments_add_string(OggOpusComments *comments, const char *tag_and_val);
OPE_EXPORT int ope_comments_add_picture(OggOpusComments *comments, const char *filename, int picture_type, const char *description);
OPE_EXPORT int ope_comments_add_picture_from_memory(OggOpusComments *comments, const char *ptr, size_t size, int picture_type, const char *description);
OPE_EXPORT OggOpusEnc *ope_encoder_create_file(const char *path, OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error);
OPE_EXPORT OggOpusEnc *ope_encoder_create_callbacks(const OpusEncCallbacks *callbacks, void *user_data,
OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error);
OPE_EXPORT OggOpusEnc *ope_encoder_create_pull(OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error);
OPE_EXPORT int ope_encoder_deferred_init_with_mapping(OggOpusEnc *enc, int family, int streams,
int coupled_streams, const unsigned char *mapping);
OPE_EXPORT int ope_encoder_write_float(OggOpusEnc *enc, const float *pcm, int samples_per_channel);
OPE_EXPORT int ope_encoder_write(OggOpusEnc *enc, const opus_int16 *pcm, int samples_per_channel);
OPE_EXPORT int ope_encoder_get_page(OggOpusEnc *enc, unsigned char **page, opus_int32 *len, int flush);
OPE_EXPORT int ope_encoder_drain(OggOpusEnc *enc);
OPE_EXPORT void ope_encoder_destroy(OggOpusEnc *enc);
OPE_EXPORT int ope_encoder_chain_current(OggOpusEnc *enc, OggOpusComments *comments);
OPE_EXPORT int ope_encoder_continue_new_file(OggOpusEnc *enc, const char *path, OggOpusComments *comments);
OPE_EXPORT int ope_encoder_continue_new_callbacks(OggOpusEnc *enc, void *user_data, OggOpusComments *comments);
OPE_EXPORT int ope_encoder_flush_header(OggOpusEnc *enc);
OPE_EXPORT int ope_encoder_ctl(OggOpusEnc *enc, int request, ...);
OPE_EXPORT const char *ope_strerror(int error);
OPE_EXPORT const char *ope_get_version_string(void);
OPE_EXPORT int ope_get_abi_version(void);
# if defined(__cplusplus)
}
# endif
#endif
ope_write_func
int(* ope_write_func)(void *user_data, const unsigned char *ptr, opus_int32 len)
Called for writing a page.
Definition opusenc.h:171
ope_close_func
int(* ope_close_func)(void *user_data)
Called for closing a stream.
Definition opusenc.h:179
ope_packet_func
void(* ope_packet_func)(void *user_data, const unsigned char *packet_ptr, opus_int32 packet_len, opus_uint32 flags)
Called on every packet encoded (including header).
Definition opusenc.h:187
ope_comments_copy
OPE_EXPORT OggOpusComments * ope_comments_copy(OggOpusComments *comments)
Create a deep copy of a comments object.
ope_comments_add
OPE_EXPORT int ope_comments_add(OggOpusComments *comments, const char *tag, const char *val)
Add a comment.
ope_comments_create
OPE_EXPORT OggOpusComments * ope_comments_create(void)
Create a new comments object.
ope_comments_destroy
OPE_EXPORT void ope_comments_destroy(OggOpusComments *comments)
Destroys a comments object.
ope_comments_add_picture
OPE_EXPORT int ope_comments_add_picture(OggOpusComments *comments, const char *filename, int picture_type, const char *description)
Add a picture from a file.
ope_comments_add_picture_from_memory
OPE_EXPORT int ope_comments_add_picture_from_memory(OggOpusComments *comments, const char *ptr, size_t size, int picture_type, const char *description)
Add a picture already in memory.
ope_comments_add_string
OPE_EXPORT int ope_comments_add_string(OggOpusComments *comments, const char *tag_and_val)
Add a comment as a single tag=value string.
ope_encoder_create_callbacks
OPE_EXPORT OggOpusEnc * ope_encoder_create_callbacks(const OpusEncCallbacks *callbacks, void *user_data, OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error)
Create a new OggOpus stream to be handled using callbacks.
ope_encoder_drain
OPE_EXPORT int ope_encoder_drain(OggOpusEnc *enc)
Finalizes the stream, but does not deallocate the object.
ope_encoder_create_pull
OPE_EXPORT OggOpusEnc * ope_encoder_create_pull(OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error)
Create a new OggOpus stream to be used along with.ope_encoder_get_page().
ope_get_version_string
OPE_EXPORT const char * ope_get_version_string(void)
Returns a string representing the version of libopusenc being used at run time.
ope_encoder_get_page
OPE_EXPORT int ope_encoder_get_page(OggOpusEnc *enc, unsigned char **page, opus_int32 *len, int flush)
Get the next page from the stream (only if using ope_encoder_create_pull()).
ope_encoder_write_float
OPE_EXPORT int ope_encoder_write_float(OggOpusEnc *enc, const float *pcm, int samples_per_channel)
Add/encode any number of float samples to the stream.
ope_encoder_continue_new_callbacks
OPE_EXPORT int ope_encoder_continue_new_callbacks(OggOpusEnc *enc, void *user_data, OggOpusComments *comments)
Ends the stream and create a new file (callback-based).
ope_encoder_continue_new_file
OPE_EXPORT int ope_encoder_continue_new_file(OggOpusEnc *enc, const char *path, OggOpusComments *comments)
Ends the stream and create a new file.
ope_encoder_create_file
OPE_EXPORT OggOpusEnc * ope_encoder_create_file(const char *path, OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error)
Create a new OggOpus file.
ope_encoder_flush_header
OPE_EXPORT int ope_encoder_flush_header(OggOpusEnc *enc)
Write out the header now rather than wait for audio to begin.
ope_strerror
OPE_EXPORT const char * ope_strerror(int error)
Converts a libopusenc error code into a human readable string.
ope_encoder_destroy
OPE_EXPORT void ope_encoder_destroy(OggOpusEnc *enc)
Deallocates the obect.
ope_get_abi_version
OPE_EXPORT int ope_get_abi_version(void)
ABI version for this header.
ope_encoder_write
OPE_EXPORT int ope_encoder_write(OggOpusEnc *enc, const opus_int16 *pcm, int samples_per_channel)
Add/encode any number of 16-bit linear samples to the stream.
ope_encoder_deferred_init_with_mapping
OPE_EXPORT int ope_encoder_deferred_init_with_mapping(OggOpusEnc *enc, int family, int streams, int coupled_streams, const unsigned char *mapping)
Deferred initialization of the encoder to force an explicit channel mapping.
ope_encoder_ctl
OPE_EXPORT int ope_encoder_ctl(OggOpusEnc *enc, int request,...)
Sets encoder options.
ope_encoder_chain_current
OPE_EXPORT int ope_encoder_chain_current(OggOpusEnc *enc, OggOpusComments *comments)
Ends the stream and create a new stream within the same file.
OpusEncCallbacks
Callback functions for accessing the stream.
Definition opusenc.h:190
OpusEncCallbacks::write
ope_write_func write
Callback for writing to the stream.
Definition opusenc.h:192
OpusEncCallbacks::close
ope_close_func close
Callback for closing the stream.
Definition opusenc.h:194