FFSampledSP
Loading...
Searching...
No Matches
FFUtils.h File Reference
#include <jni.h>
#include <math.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/channel_layout.h>
#include <libavutil/opt.h>
#include <libavutil/timestamp.h>
#include <libswresample/swresample.h>

Go to the source code of this file.

Data Structures

struct  FFAudioIO
 Central context representing the native peer to the Java FFNativePeerInputStream object. More...

Functions

void logWarning (FFAudioIO *, int, const char *)
 Log a warning.
void logFine (FFAudioIO *, int, const char *)
 Log a debug message.
void throwUnsupportedAudioFileExceptionIfError (JNIEnv *, int, const char *)
 Throws an UnsupportedAudioFileException.
void throwIOExceptionIfError (JNIEnv *, int, const char *)
 Throws an IOException.
void throwIndexOutOfBoundsExceptionIfError (JNIEnv *, int, int)
 Throws an IndexOutOfBoundsException.
void throwFileNotFoundExceptionIfError (JNIEnv *, int, const char *)
 Throws a FileNotFoundException.
int ff_open_stream (JNIEnv *, AVStream *, AVCodecContext **)
 Opens the given stream, i.e.
int ff_open_format_context (JNIEnv *, AVFormatContext **, const char *, int)
 Opens the input file/url and allocates a AVFormatContext for it, but does not open the audio stream with an appropriate decoder.
int ff_open_file (JNIEnv *, AVFormatContext **, AVStream **, AVCodecContext **, int *, const char *, int)
 Opens the input file/url, allocates a AVFormatContext for it and opens the audio stream with an appropriate decoder.
int ff_init_audioio (JNIEnv *, FFAudioIO *)
 Initialize our main context FFAudioIO, so that SwrContext, decode buffers and the encoder are set to reasonable values.
void ff_audioio_free (FFAudioIO *)
 Free all resources held by aio and then itself.
int ff_fill_buffer (FFAudioIO *)
 Reads frames via av_read_frame, decodes them, and writes the result to the Java-side nativeBuffer.
AVCodec * ff_find_encoder (enum AVSampleFormat, int, int, int)
 Finds an AVCodec encoder for the given sample format, bits per sample, byte order and signed/unsigned encoding.
int ff_init_encoder (JNIEnv *, FFAudioIO *, AVCodec *)
 Allocates and initializes the encoder context and frame in FFAudioIO.
int ff_big_endian (enum AVCodecID)
 Indicates whether the given id belongs to a big endian codec.

Variables

const uint32_t CODEC_TAG_DRMS

Function Documentation

◆ ff_audioio_free()

void ff_audioio_free ( FFAudioIO * aio)

Free all resources held by aio and then itself.

Definition at line 1169 of file FFUtils.c.

◆ ff_big_endian()

int ff_big_endian ( enum AVCodecID codec_id)

Indicates whether the given id belongs to a big endian codec.

Parameters
codec_idcodec id
Returns
true if the codec id belongs to a big endian codec.

Definition at line 1221 of file FFUtils.c.

◆ ff_fill_buffer()

int ff_fill_buffer ( FFAudioIO * aio)

Reads frames via av_read_frame, decodes them, and writes the result to the Java-side nativeBuffer.

Parameters
aiocurrent FFAudioIO
Returns
a negative number, if something went wrong

Definition at line 1107 of file FFUtils.c.

◆ ff_find_encoder()

AVCodec * ff_find_encoder ( enum AVSampleFormat sampleFormat,
int bits,
int big_endian,
int signedSamples )

Finds an AVCodec encoder for the given sample format, bits per sample, byte order and signed/unsigned encoding.

This method never returns a planar, but always a packed codec.

Parameters
sampleFormatAVSampleFormat
bitsbits per sample
big_endiantrue or false
signedSamplestrue, if the samples are signed
Returns
an appropriate encoder or NULL, if none can be found

Definition at line 528 of file FFUtils.c.

◆ ff_init_audioio()

int ff_init_audioio ( JNIEnv * env,
FFAudioIO * aio )

Initialize our main context FFAudioIO, so that SwrContext, decode buffers and the encoder are set to reasonable values.

Parameters
JNIEnvenv
aioour context, FFAudioIO
Returns
a negative value, if something went wrong

Definition at line 663 of file FFUtils.c.

◆ ff_init_encoder()

int ff_init_encoder ( JNIEnv * env,
FFAudioIO * aio,
AVCodec * encoder )

Allocates and initializes the encoder context and frame in FFAudioIO.

As parameters serve the output parameters of the SwrContext from FFAudioIO. Therefore the SwrContext must be setup first for this to be successful.

Parameters
envJNIEnv
aioFFAudioIO (our context)
encoderAVCodec to use to setup the encoder AVCodecContext
Returns
a negative value, if something goes wrong

Definition at line 591 of file FFUtils.c.

◆ ff_open_file()

int ff_open_file ( JNIEnv * env,
AVFormatContext ** format_context,
AVStream ** openedStream,
AVCodecContext ** context,
int * stream_index,
const char * url,
int io_buffer_size )

Opens the input file/url, allocates a AVFormatContext for it and opens the audio stream with an appropriate decoder.

Parameters
envJNIEnv
format_contextAVFormatContext
openedStreamopened audio AVStream
stream_index[in]index of the desired audio stream
stream_index[out]index of the selected stream (index of all streams)
urlURL to open
Returns
negative value, if something went wrong

Definition at line 378 of file FFUtils.c.

◆ ff_open_format_context()

int ff_open_format_context ( JNIEnv * env,
AVFormatContext ** format_context,
const char * url,
int io_buffer_size )

Opens the input file/url and allocates a AVFormatContext for it, but does not open the audio stream with an appropriate decoder.

Parameters
envJNIEnv
format_contextAVFormatContext
urlURL to open
Returns
negative value, if something went wrong

Definition at line 297 of file FFUtils.c.

◆ ff_open_stream()

int ff_open_stream ( JNIEnv * env,
AVStream * stream,
AVCodecContext ** context )

Opens the given stream, i.e.

sets up a decoder.

Parameters
envJNIEnv
streamAVStream

Definition at line 93 of file FFUtils.c.

◆ logFine()

void logFine ( FFAudioIO * aio,
int err,
const char * message )

Log a debug message.

Definition at line 284 of file FFUtils.c.

◆ logWarning()

void logWarning ( FFAudioIO * aio,
int err,
const char * message )

Log a warning.

Definition at line 277 of file FFUtils.c.

◆ throwFileNotFoundExceptionIfError()

void throwFileNotFoundExceptionIfError ( JNIEnv * env,
int err,
const char * message )

Throws a FileNotFoundException.

Definition at line 228 of file FFUtils.c.

◆ throwIndexOutOfBoundsExceptionIfError()

void throwIndexOutOfBoundsExceptionIfError ( JNIEnv * env,
int err,
int index )

Throws an IndexOutOfBoundsException.

Definition at line 199 of file FFUtils.c.

◆ throwIOExceptionIfError()

void throwIOExceptionIfError ( JNIEnv * env,
int err,
const char * message )

Throws an IOException.

Definition at line 213 of file FFUtils.c.

◆ throwUnsupportedAudioFileExceptionIfError()

void throwUnsupportedAudioFileExceptionIfError ( JNIEnv * env,
int err,
const char * message )

Throws an UnsupportedAudioFileException.

Definition at line 182 of file FFUtils.c.

Variable Documentation

◆ CODEC_TAG_DRMS

const uint32_t CODEC_TAG_DRMS
extern

Definition at line 27 of file FFUtils.c.