221 lines
4.8 KiB
C++
221 lines
4.8 KiB
C++
/**
|
|
* @file
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_CORE_DRIVER_H
|
|
#define OCARINA_CORE_DRIVER_H
|
|
|
|
#include <string>
|
|
|
|
/** Use to convert nanoseconds to seconds */
|
|
static const unsigned long O_SECOND = 1000000000;
|
|
|
|
|
|
/**
|
|
* The audio driver class gives us an interface for using multiple
|
|
* audio frameworks for audio playback.
|
|
*/
|
|
class Driver {
|
|
protected:
|
|
void (*on_eos) (); /**< End-of-stream callback function. */
|
|
void (*on_error) (); /**< Error handling callback function. */
|
|
|
|
public:
|
|
Driver(); /**< Default Driver constructor. */
|
|
virtual ~Driver(); /**< Driver destructor. */
|
|
|
|
/**
|
|
* Initialize an audio driver.
|
|
*
|
|
* @param argc Argc passed to the application's main() function.
|
|
* @param argv Argv passed to the applicaiton's main() function.
|
|
* @param eos_cb End-of-stream callback function.
|
|
* @param error_cb Callback function used when the audio library encounters an error.
|
|
*/
|
|
virtual void init(int *argc, char ***argv, void (*eos_cb)(), void (*error_cb)()) = 0;
|
|
|
|
|
|
/**
|
|
* Loads an audio file for playback.
|
|
*
|
|
* @param file Filepath of the track to load.
|
|
*/
|
|
virtual void load(const std::string &file) = 0;
|
|
|
|
/**
|
|
* Called to begin playback on the currently loaded track.
|
|
*
|
|
* @return True if playback state was changed successfully, false otherwise.
|
|
*/
|
|
virtual bool play() = 0;
|
|
|
|
/**
|
|
* Called to pause playback on the currently loaded track.
|
|
*
|
|
* @return True if playback state was changed successfully, false otherwise.
|
|
*/
|
|
virtual bool pause() = 0;
|
|
|
|
/**
|
|
* 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(long offset) = 0;
|
|
|
|
/**
|
|
* Return the current position of the playback.
|
|
*
|
|
* @return The current playback position, in nanoseconds.
|
|
*/
|
|
virtual long position() = 0;
|
|
|
|
/**
|
|
* Return the duration of the currently loaded track.
|
|
*
|
|
* @return The duration of the current track, in nanoseconds.
|
|
*/
|
|
virtual long duration() = 0;
|
|
};
|
|
|
|
|
|
#ifdef CONFIG_TEST
|
|
class TestDriver : public Driver
|
|
{
|
|
public:
|
|
bool playing;
|
|
long cur_pos;
|
|
long cur_duration;
|
|
std::string cur_file;
|
|
|
|
TestDriver();
|
|
~TestDriver();
|
|
void init(int *, char ***, void (*)(), void (*)());
|
|
|
|
void load(const std::string &);
|
|
bool play();
|
|
bool pause();
|
|
bool is_playing();
|
|
|
|
void seek_to(long);
|
|
long position();
|
|
long duration();
|
|
|
|
void eos();
|
|
void error();
|
|
};
|
|
#else /* !CONFIG_TEST */
|
|
|
|
#include <gst/gst.h>
|
|
|
|
/**
|
|
* Driver for the GStreamer audio library.
|
|
*
|
|
* The shell command `gst-inspect-1.0 --help-gst` details the command line
|
|
* options that can be passed to Ocarina.
|
|
*/
|
|
class GSTDriver : public Driver
|
|
{
|
|
private:
|
|
GstElement *player;
|
|
std::string cur_file;
|
|
bool change_state(GstState state);
|
|
|
|
public:
|
|
/**
|
|
* GStreamer audio driver constructor.
|
|
*/
|
|
GSTDriver();
|
|
|
|
/**
|
|
* GStreamer audio driver destructor.
|
|
*/
|
|
~GSTDriver();
|
|
|
|
/**
|
|
* Called to initialize the GStreamer audio driver.
|
|
* @param argc Argc passed to the application's main() function.
|
|
* @param argv Argv passed to the applicaiton's main() function.
|
|
* @param eos_cb End-of-stream callback function.
|
|
* @param error_cb Callback function used when the audio library encounters an error.
|
|
*/
|
|
void init(int *, char ***, void (*)(), void (*)());
|
|
|
|
/**
|
|
* Load a track into the gstreamer pipeline.
|
|
* @param filepath The file to be loaded.
|
|
*/
|
|
void load(const std::string &);
|
|
|
|
/**
|
|
* Begin playback on the GStreamer pipeline.
|
|
* @return True if the state change was successful.
|
|
*/
|
|
bool play();
|
|
|
|
/**
|
|
* Pause the GStreamer pipeline.
|
|
* @return True if the state change was successful.
|
|
*/
|
|
bool pause();
|
|
|
|
/**
|
|
* Check if the GStreamer pipeline is playing.
|
|
* @return True if the pipeline is playing.
|
|
*/
|
|
bool is_playing();
|
|
|
|
|
|
/**
|
|
* Seek to a specific position in the pipeline.
|
|
* @param offset Offset from the beginning of the pipeline, in nanoseconds.
|
|
*/
|
|
void seek_to(long);
|
|
|
|
/**
|
|
* Find the current playback position of the pipeline.
|
|
* @return The current position of the pipeline, in nanoseconds.
|
|
*/
|
|
long position();
|
|
|
|
/**
|
|
* Find the duration of the pipeline.
|
|
* @return The duration of the pipeline, in nanoseconds.
|
|
*/
|
|
long duration();
|
|
|
|
|
|
/**
|
|
* Called to handle messages from the GStreamer bus.
|
|
* @param message The message to be handled.
|
|
*/
|
|
void on_message(GstMessage *);
|
|
};
|
|
#endif /* CONFIG_TEST */
|
|
|
|
|
|
/**
|
|
* Namespace for audio driver access.
|
|
*/
|
|
namespace driver
|
|
{
|
|
|
|
/**
|
|
* Called to access an audio driver.
|
|
*
|
|
* @return The current driver used by the application.
|
|
*/
|
|
Driver *get_driver();
|
|
|
|
}
|
|
|
|
#endif /* OCARINA_CORE_DRIVER_H */
|