Audaspace 1.4.0
A high level audio library.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
FFMPEGReader Class Reference

This class reads a sound file via ffmpeg. More...

#include <FFMPEGReader.h>

Inheritance diagram for FFMPEGReader:
Inheritance graph
[legend]

Public Member Functions

 FFMPEGReader (std::string filename, int stream=0)
 Creates a new reader.
 
 FFMPEGReader (std::shared_ptr< Buffer > buffer, int stream=0)
 Creates a new reader.
 
virtual ~FFMPEGReader ()
 Destroys the reader and closes the file.
 
virtual std::vector< StreamInfoqueryStreams ()
 Queries the streams of a sound file.
 
virtual bool isSeekable () const
 Tells whether the source provides seeking functionality or not.
 
virtual void seek (int position)
 Seeks to a specific position in the source.
 
virtual int getLength () const
 Returns an approximated length of the source in samples.
 
virtual int getPosition () const
 Returns the position of the source as a sample count value.
 
virtual Specs getSpecs () const
 Returns the specification of the reader.
 
virtual void read (int &length, bool &eos, sample_t *buffer)
 Request to read the next length samples out of the source.
 
- Public Member Functions inherited from IReader
virtual ~IReader ()
 Destroys the reader.
 
virtual bool isSeekable () const =0
 Tells whether the source provides seeking functionality or not.
 
virtual void seek (int position)=0
 Seeks to a specific position in the source.
 
virtual int getLength () const =0
 Returns an approximated length of the source in samples.
 
virtual int getPosition () const =0
 Returns the position of the source as a sample count value.
 
virtual Specs getSpecs () const =0
 Returns the specification of the reader.
 
virtual void read (int &length, bool &eos, sample_t *buffer)=0
 Request to read the next length samples out of the source.
 

Static Public Member Functions

static int read_packet (void *opaque, uint8_t *buf, int buf_size)
 Reads data to a memory buffer.
 
static int64_t seek_packet (void *opaque, int64_t offset, int whence)
 Seeks within data.
 

Detailed Description

This class reads a sound file via ffmpeg.

Warning
Seeking may not be accurate! Moreover the position is updated after a buffer reading call. So calling getPosition right after seek normally results in a wrong value.

Constructor & Destructor Documentation

◆ FFMPEGReader() [1/2]

FFMPEGReader::FFMPEGReader ( std::string  filename,
int  stream = 0 
)

Creates a new reader.

Parameters
filenameThe path to the file to be read.
streamThe index of the audio stream within the file if it contains multiple audio streams.
Exceptions
ExceptionThrown if the file specified does not exist or cannot be read with ffmpeg.

◆ FFMPEGReader() [2/2]

FFMPEGReader::FFMPEGReader ( std::shared_ptr< Buffer buffer,
int  stream = 0 
)

Creates a new reader.

Parameters
bufferThe buffer to read from.
streamThe index of the audio stream within the file if it contains multiple audio streams.
Exceptions
ExceptionThrown if the buffer specified cannot be read with ffmpeg.

Member Function Documentation

◆ getLength()

virtual int FFMPEGReader::getLength ( ) const
virtual

Returns an approximated length of the source in samples.

Returns
The length as sample count. May be negative if unknown.

Implements IReader.

◆ getPosition()

virtual int FFMPEGReader::getPosition ( ) const
virtual

Returns the position of the source as a sample count value.

Returns
The current position in the source. A negative value indicates that the position is unknown.
Warning
The value returned doesn't always have to be correct for readers, especially after seeking.

Implements IReader.

◆ getSpecs()

virtual Specs FFMPEGReader::getSpecs ( ) const
virtual

Returns the specification of the reader.

Returns
The Specs structure.

Implements IReader.

◆ isSeekable()

virtual bool FFMPEGReader::isSeekable ( ) const
virtual

Tells whether the source provides seeking functionality or not.

Warning
This doesn't mean that the seeking always has to succeed.
Returns
Always returns true for readers of buffering types.

Implements IReader.

◆ queryStreams()

virtual std::vector< StreamInfo > FFMPEGReader::queryStreams ( )
virtual

Queries the streams of a sound file.

Returns
A vector with as many streams as there are in the file.
Exceptions
ExceptionThrown if the file specified cannot be read.

◆ read()

virtual void FFMPEGReader::read ( int &  length,
bool &  eos,
sample_t buffer 
)
virtual

Request to read the next length samples out of the source.

The buffer supplied has the needed size.

Parameters
[in,out]lengthThe count of samples that should be read. Shall contain the real count of samples after reading, in case there were only fewer samples available. A smaller value also indicates the end of the reader.
[out]eosEnd of stream, whether the end is reached or not.
[in]bufferThe pointer to the buffer to read into.

Implements IReader.

◆ read_packet()

static int FFMPEGReader::read_packet ( void *  opaque,
uint8_t *  buf,
int  buf_size 
)
static

Reads data to a memory buffer.

This function is used for avio only.

Parameters
opaqueThe FFMPEGReader.
bufThe buffer to read to.
buf_sizeThe size of the buffer.
Returns
How many bytes have been read.

◆ seek()

virtual void FFMPEGReader::seek ( int  position)
virtual

Seeks to a specific position in the source.

Parameters
positionThe position to seek for measured in samples. To get from a given time to the samples you simply have to multiply the time value in seconds with the sample rate of the reader.
Warning
This may work or not, depending on the actual reader.

Implements IReader.

◆ seek_packet()

static int64_t FFMPEGReader::seek_packet ( void *  opaque,
int64_t  offset,
int  whence 
)
static

Seeks within data.

This function is used for avio only.

Parameters
opaqueThe FFMPEGReader.
offsetThe byte offset to seek to.
whenceThe seeking action.
Returns
The current position or the size of the data if requested.

The documentation for this class was generated from the following file: