155 lines
3.3 KiB
C++
155 lines
3.3 KiB
C++
/**
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_CORE_AUDIO_H
|
|
#define OCARINA_CORE_AUDIO_H
|
|
|
|
extern "C" {
|
|
#include <core/tags/track.h>
|
|
}
|
|
#include <gst/gst.h>
|
|
#include <string>
|
|
#include <stdint.h>
|
|
|
|
|
|
struct audio_ops {
|
|
/* Called when a track is loaded. */
|
|
void (*on_load)(struct track *, GstState);
|
|
};
|
|
|
|
|
|
/**
|
|
* The audio driver class gives us an interface for using multiple
|
|
* audio frameworks for audio playback.
|
|
*/
|
|
class AudioDriver {
|
|
protected:
|
|
void (*on_error) (); /**< Error handling callback function. */
|
|
|
|
public:
|
|
AudioDriver(); /**< Default AudioDriver constructor. */
|
|
virtual ~AudioDriver(); /**< AudioDriver destructor. */
|
|
|
|
|
|
/**
|
|
* Called to check if the audio library is currently playing a track.
|
|
*
|
|
* @return True if audio library is playing, false otherwise.
|
|
*/
|
|
virtual bool is_playing() = 0;
|
|
|
|
|
|
/**
|
|
* Seek to a specific position in the current track.
|
|
*
|
|
* @param offset Position from the beginning of the track where we will seek to, in nanoseconds.
|
|
*/
|
|
virtual void seek_to(int64_t offset) = 0;
|
|
|
|
/**
|
|
* Return the current position of the playback.
|
|
*
|
|
* @return The current playback position, in nanoseconds.
|
|
*/
|
|
virtual int64_t position() = 0;
|
|
|
|
/**
|
|
* Return the duration of the currently loaded track.
|
|
*
|
|
* @return The duration of the current track, in nanoseconds.
|
|
*/
|
|
virtual int64_t duration() = 0;
|
|
|
|
/**
|
|
* Called to handle reaching the end-of-stream.
|
|
*/
|
|
void eos();
|
|
};
|
|
|
|
|
|
/**
|
|
* Namespace for higher-level audio controls.
|
|
*/
|
|
namespace audio
|
|
{
|
|
|
|
/**
|
|
* Seek to a specific point in the track.
|
|
*
|
|
* @param pos Offset (in nanoseconds) from the beginning of the track.
|
|
*/
|
|
void seek_to(int64_t);
|
|
|
|
/**
|
|
* Stop playback and seek to the beginning of the track.
|
|
*/
|
|
void stop();
|
|
|
|
/**
|
|
* @return The current position of the audio playback (in nanoseconds).
|
|
*/
|
|
int64_t position();
|
|
|
|
/**
|
|
* @return The duration of the currently loaded track (in nanoseconds).
|
|
*/
|
|
int64_t duration();
|
|
|
|
void next(); /**< Find and load the next track that should be played. */
|
|
void prev(); /**< Call the deck :: previous() function and load the result. */
|
|
|
|
/**
|
|
* @return A pointer to the currently playing track object.
|
|
*/
|
|
struct track *current_track();
|
|
|
|
/**
|
|
* Configure the automatic pausing feature.
|
|
*
|
|
* @param enabled Set to true to enable pausing, false to disable.
|
|
* @param n Number of tracks to play before pausing.
|
|
*/
|
|
void pause_after(bool, unsigned int);
|
|
|
|
/**
|
|
* Call to find the current automatic pausing state.
|
|
*
|
|
* @return True if automatic pausing is enabled, false otherwise.
|
|
*/
|
|
bool pause_enabled();
|
|
|
|
/**
|
|
* Call to find the number of tracks remaining before pausing.
|
|
*
|
|
* @return The number of tracks before pausing.
|
|
*/
|
|
unsigned int pause_count();
|
|
|
|
/**
|
|
* Called to access an audio driver.
|
|
*
|
|
* @return The current driver used by the application.
|
|
*/
|
|
AudioDriver *get_driver();
|
|
};
|
|
|
|
|
|
/* Called to initialize the audio manager. */
|
|
void audio_init(int *, char ***, struct audio_ops *);
|
|
|
|
/* Called to deinitialize the audio manager. */
|
|
void audio_deinit();
|
|
|
|
|
|
/* Called to load a track for playback. */
|
|
bool audio_load(struct track *);
|
|
|
|
/* Called to begin playback. */
|
|
bool audio_play();
|
|
|
|
/* Called to pause playback. */
|
|
bool audio_pause();
|
|
|
|
GstElement *audio_get_player();
|
|
#endif /* OCARINA_CORE_AUDIO_H */
|