[vlc-commits] amem: add support for pause/resume and flush/drain

Rémi Denis-Courmont git at videolan.org
Thu Aug 4 17:16:42 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Aug  4 16:42:31 2011 +0300| [4cc939684b71ec56a35048c9061915954fbc8076] | committer: Rémi Denis-Courmont

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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4cc939684b71ec56a35048c9061915954fbc8076
---

 include/vlc/libvlc_media_player.h |   58 ++++++++++++++++++++++++++++++++++--
 modules/audio_output/amem.c       |   30 ++++++++++++++++++-
 src/control/media_player.c        |   16 +++++++++-
 src/libvlc.sym                    |    1 +
 4 files changed, 97 insertions(+), 8 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 0f24e37..5233ecb 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -476,9 +476,39 @@ typedef void (*libvlc_audio_play_cb)(void *data, const void *samples,
                                      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.
  * \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
  */
 typedef void (*libvlc_audio_set_volume_cb)(void *data,
@@ -491,17 +521,37 @@ typedef void (*libvlc_audio_set_volume_cb)(void *data,
  *
  * \param mp the media player
  * \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 opaque private pointer for the two callbacks (as first parameter)
+ * \param pause callback to pause playback (or NULL to ignore)
+ * \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
  */
 LIBVLC_API
 void libvlc_audio_set_callbacks( libvlc_media_player_t *mp,
                                  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 );
 
 /**
+ * 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.
  * This is called when the media player needs to create a new audio output.
  * \param opaque pointer to the data pointer passed to
diff --git a/modules/audio_output/amem.c b/modules/audio_output/amem.c
index ac4a11e..02dc44d 100644
--- a/modules/audio_output/amem.c
+++ b/modules/audio_output/amem.c
@@ -55,6 +55,10 @@ struct aout_sys_t
 {
     void *opaque;
     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);
     void (*cleanup) (void *opaque);
 };
@@ -68,6 +72,24 @@ static void Play (audio_output_t *aout, block_t *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)
 {
     aout_sys_t *sys = aout->sys;
@@ -87,6 +109,10 @@ static int Open (vlc_object_t *obj)
     aout->sys = sys;
     sys->opaque = var_InheritAddress (obj, "amem-data");
     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->cleanup = NULL; /* defer */
     if (sys->play == NULL)
@@ -127,8 +153,8 @@ static int Open (vlc_object_t *obj)
     aout->format.i_rate = rate;
 
     aout->pf_play = Play;
-    aout->pf_pause = NULL;
-    aout->pf_flush = NULL;
+    aout->pf_pause = Pause;
+    aout->pf_flush = Flush;
     if (sys->set_volume != NULL)
         aout->pf_volume_set = VolumeSet;
     else
diff --git a/src/control/media_player.c b/src/control/media_player.c
index 3521c33..b0942a4 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -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,
                                  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 )
 {
     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_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,
                                         libvlc_audio_setup_cb setup,
                                         libvlc_audio_cleanup_cb cleanup )
diff --git a/src/libvlc.sym b/src/libvlc.sym
index 8e3d835..2c09776 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -28,6 +28,7 @@ libvlc_audio_toggle_mute
 libvlc_audio_set_format
 libvlc_audio_set_format_callbacks
 libvlc_audio_set_callbacks
+libvlc_audio_set_volume_callback
 libvlc_clock
 libvlc_event_attach
 libvlc_event_detach



More information about the vlc-commits mailing list