Commit 4cc93968 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

amem: add support for pause/resume and flush/drain

parent 4f6fae71
...@@ -475,10 +475,40 @@ LIBVLC_API void *libvlc_media_player_get_hwnd ( libvlc_media_player_t *p_mi ); ...@@ -475,10 +475,40 @@ LIBVLC_API void *libvlc_media_player_get_hwnd ( libvlc_media_player_t *p_mi );
typedef void (*libvlc_audio_play_cb)(void *data, const void *samples, typedef void (*libvlc_audio_play_cb)(void *data, const void *samples,
unsigned count, int64_t pts); unsigned count, int64_t pts);
/**
* Callback prototype for audio pause.
* \note The pause callback is never called if the audio is already paused.
* \param data data pointer as passed to libvlc_audio_set_callbacks() [IN]
* \param pts time stamp of the pause request (should be elapsed already)
*/
typedef void (*libvlc_audio_pause_cb)(void *data, int64_t pts);
/**
* Callback prototype for audio resumption (i.e. restart from pause).
* \note The resume callback is never called if the audio is not paused.
* \param data data pointer as passed to libvlc_audio_set_callbacks() [IN]
* \param pts time stamp of the resumption request (should be elapsed already)
*/
typedef void (*libvlc_audio_resume_cb)(void *data, int64_t pts);
/**
* Callback prototype for audio buffer flush
* (i.e. discard all pending buffers and stop playback as soon as possible).
* \param data data pointer as passed to libvlc_audio_set_callbacks() [IN]
*/
typedef void (*libvlc_audio_flush_cb)(void *data, int64_t pts);
/**
* Callback prototype for audio buffer drain
* (i.e. wait for pending buffers to be played).
* \param data data pointer as passed to libvlc_audio_set_callbacks() [IN]
*/
typedef void (*libvlc_audio_drain_cb)(void *data);
/** /**
* Callback prototype for audio volume change. * Callback prototype for audio volume change.
* \param data data pointer as passed to libvlc_audio_set_callbacks() [IN] * \param data data pointer as passed to libvlc_audio_set_callbacks() [IN]
* \param volume linear volume (1. = nominal, 0. = mute) * \param volume software volume (1. = nominal, 0. = mute)
* \param mute muted flag * \param mute muted flag
*/ */
typedef void (*libvlc_audio_set_volume_cb)(void *data, typedef void (*libvlc_audio_set_volume_cb)(void *data,
...@@ -491,16 +521,36 @@ typedef void (*libvlc_audio_set_volume_cb)(void *data, ...@@ -491,16 +521,36 @@ typedef void (*libvlc_audio_set_volume_cb)(void *data,
* *
* \param mp the media player * \param mp the media player
* \param play callback to play audio samples (must not be NULL) * \param play callback to play audio samples (must not be NULL)
* \param set_volume callback to set audio volume, or NULL for software volume * \param pause callback to pause playback (or NULL to ignore)
* \param opaque private pointer for the two callbacks (as first parameter) * \param resume callback to resume playback (or NULL to ignore)
* \param flush callback to flush audio buffers (or NULL to ignore)
* \param drain callback to drain audio buffers (or NULL to ignore)
* \param opaque private pointer for the audio callbacks (as first parameter)
* \version LibVLC 1.2.0 or later * \version LibVLC 1.2.0 or later
*/ */
LIBVLC_API LIBVLC_API
void libvlc_audio_set_callbacks( libvlc_media_player_t *mp, void libvlc_audio_set_callbacks( libvlc_media_player_t *mp,
libvlc_audio_play_cb play, libvlc_audio_play_cb play,
libvlc_audio_set_volume_cb set_volume, libvlc_audio_pause_cb pause,
libvlc_audio_resume_cb resume,
libvlc_audio_flush_cb flush,
libvlc_audio_drain_cb drain,
void *opaque ); void *opaque );
/**
* Set callbacks and private data for decoded audio.
* Use libvlc_audio_set_format() or libvlc_audio_set_format_callbacks()
* to configure the decoded audio format.
*
* \param mp the media player
* \param set_volume callback to apply audio volume,
* or NULL to apply volume in software
* \version LibVLC 1.2.0 or later
*/
LIBVLC_API
void libvlc_audio_set_volume_callback( libvlc_media_player_t *mp,
libvlc_audio_set_volume_cb set_volume );
/** /**
* Callback prototype to setup the audio playback. * Callback prototype to setup the audio playback.
* This is called when the media player needs to create a new audio output. * This is called when the media player needs to create a new audio output.
......
...@@ -55,6 +55,10 @@ struct aout_sys_t ...@@ -55,6 +55,10 @@ struct aout_sys_t
{ {
void *opaque; void *opaque;
void (*play) (void *opaque, const void *data, unsigned count, int64_t pts); void (*play) (void *opaque, const void *data, unsigned count, int64_t pts);
void (*pause) (void *opaque, int64_t pts);
void (*resume) (void *opaque, int64_t pts);
void (*flush) (void *opaque);
void (*drain) (void *opaque);
int (*set_volume) (void *opaque, float vol, bool mute); int (*set_volume) (void *opaque, float vol, bool mute);
void (*cleanup) (void *opaque); void (*cleanup) (void *opaque);
}; };
...@@ -68,6 +72,24 @@ static void Play (audio_output_t *aout, block_t *block) ...@@ -68,6 +72,24 @@ static void Play (audio_output_t *aout, block_t *block)
block_Release (block); block_Release (block);
} }
static void Pause (audio_output_t *aout, bool paused, mtime_t date)
{
aout_sys_t *sys = aout->sys;
void (*cb) (void *, int64_t) = paused ? sys->pause : sys->resume;
if (cb != NULL)
cb (sys->opaque, date);
}
static void Flush (audio_output_t *aout, bool wait)
{
aout_sys_t *sys = aout->sys;
void (*cb) (void *) = wait ? sys->drain : sys->flush;
if (cb != NULL)
cb (sys->opaque);
}
static int VolumeSet (audio_output_t *aout, float vol, bool mute) static int VolumeSet (audio_output_t *aout, float vol, bool mute)
{ {
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
...@@ -87,6 +109,10 @@ static int Open (vlc_object_t *obj) ...@@ -87,6 +109,10 @@ static int Open (vlc_object_t *obj)
aout->sys = sys; aout->sys = sys;
sys->opaque = var_InheritAddress (obj, "amem-data"); sys->opaque = var_InheritAddress (obj, "amem-data");
sys->play = var_InheritAddress (obj, "amem-play"); sys->play = var_InheritAddress (obj, "amem-play");
sys->pause = var_InheritAddress (obj, "amem-pause");
sys->resume = var_InheritAddress (obj, "amem-resume");
sys->flush = var_InheritAddress (obj, "amem-flush");
sys->drain = var_InheritAddress (obj, "amem-drain");
sys->set_volume = var_InheritAddress (obj, "amem-set-volume"); sys->set_volume = var_InheritAddress (obj, "amem-set-volume");
sys->cleanup = NULL; /* defer */ sys->cleanup = NULL; /* defer */
if (sys->play == NULL) if (sys->play == NULL)
...@@ -127,8 +153,8 @@ static int Open (vlc_object_t *obj) ...@@ -127,8 +153,8 @@ static int Open (vlc_object_t *obj)
aout->format.i_rate = rate; aout->format.i_rate = rate;
aout->pf_play = Play; aout->pf_play = Play;
aout->pf_pause = NULL; aout->pf_pause = Pause;
aout->pf_flush = NULL; aout->pf_flush = Flush;
if (sys->set_volume != NULL) if (sys->set_volume != NULL)
aout->pf_volume_set = VolumeSet; aout->pf_volume_set = VolumeSet;
else else
......
...@@ -937,15 +937,27 @@ void *libvlc_media_player_get_hwnd( libvlc_media_player_t *p_mi ) ...@@ -937,15 +937,27 @@ void *libvlc_media_player_get_hwnd( libvlc_media_player_t *p_mi )
void libvlc_audio_set_callbacks( libvlc_media_player_t *mp, void libvlc_audio_set_callbacks( libvlc_media_player_t *mp,
libvlc_audio_play_cb play_cb, libvlc_audio_play_cb play_cb,
libvlc_audio_set_volume_cb set_volume_cb, libvlc_audio_pause_cb pause_cb,
libvlc_audio_resume_cb resume_cb,
libvlc_audio_flush_cb flush_cb,
libvlc_audio_drain_cb drain_cb,
void *opaque ) void *opaque )
{ {
var_SetAddress( mp, "amem-play", play_cb ); var_SetAddress( mp, "amem-play", play_cb );
var_SetAddress( mp, "amem-set-volume", set_volume_cb ); var_SetAddress( mp, "amem-pause", pause_cb );
var_SetAddress( mp, "amem-resume", resume_cb );
var_SetAddress( mp, "amem-flush", flush_cb );
var_SetAddress( mp, "amem-drain", drain_cb );
var_SetAddress( mp, "amem-data", opaque ); var_SetAddress( mp, "amem-data", opaque );
var_SetString( mp, "aout", "amem" ); var_SetString( mp, "aout", "amem" );
} }
void libvlc_audio_set_volume_callback( libvlc_media_player_t *mp,
libvlc_audio_set_volume_cb cb )
{
var_SetAddress( mp, "amem-set-volume", cb );
}
void libvlc_audio_set_format_callbacks( libvlc_media_player_t *mp, void libvlc_audio_set_format_callbacks( libvlc_media_player_t *mp,
libvlc_audio_setup_cb setup, libvlc_audio_setup_cb setup,
libvlc_audio_cleanup_cb cleanup ) libvlc_audio_cleanup_cb cleanup )
......
...@@ -28,6 +28,7 @@ libvlc_audio_toggle_mute ...@@ -28,6 +28,7 @@ libvlc_audio_toggle_mute
libvlc_audio_set_format libvlc_audio_set_format
libvlc_audio_set_format_callbacks libvlc_audio_set_format_callbacks
libvlc_audio_set_callbacks libvlc_audio_set_callbacks
libvlc_audio_set_volume_callback
libvlc_clock libvlc_clock
libvlc_event_attach libvlc_event_attach
libvlc_event_detach libvlc_event_detach
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment