]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/amem.c
Implement plugin support for OS/2
[vlc] / modules / audio_output / amem.c
index b03d54c0edd7021096b96001c7e062bd67490d5e..15996e3e682ca22f164a80ca01a7291c2d6bffb4 100644 (file)
@@ -3,19 +3,19 @@
  *****************************************************************************
  * Copyright (C) 2011 RĂ©mi Denis-Courmont
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
  * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -25,7 +25,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
-#include <vlc_aout_intf.h>
+#include <assert.h>
 
 static int Open (vlc_object_t *);
 static void Close (vlc_object_t *);
@@ -56,43 +56,64 @@ 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);
 };
 
-static void Play (aout_instance_t *aout)
+static void Play (audio_output_t *aout, block_t *block)
 {
-    aout_sys_t *sys = aout->output.p_sys;
-    block_t *block;
+    aout_sys_t *sys = aout->sys;
 
-    while ((block = aout_FifoPop(&aout->output.fifo)) != NULL)
-    {
-        sys->play (sys->opaque, block->p_buffer, block->i_nb_samples,
-                   block->i_pts);
-        block_Release (block);
-    }
+    sys->play (sys->opaque, block->p_buffer, block->i_nb_samples,
+               block->i_pts);
+    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 (aout_instance_t *aout, audio_volume_t ivol, bool mute)
+static int VolumeSet (audio_output_t *aout, float vol, bool mute)
 {
-    aout_sys_t *sys = aout->output.p_sys;
-    float fvol = ivol / (float)AOUT_VOLUME_DEFAULT;
+    aout_sys_t *sys = aout->sys;
 
-    return sys->set_volume (sys->opaque, fvol, mute) ? -1 : 0;
+    return sys->set_volume (sys->opaque, vol, mute) ? -1 : 0;
 }
 
 typedef int (*vlc_audio_format_cb) (void **, char *, unsigned *, unsigned *);
 
 static int Open (vlc_object_t *obj)
 {
-    aout_instance_t *aout = (aout_instance_t *)obj;
+    audio_output_t *aout = (audio_output_t *)obj;
     aout_sys_t *sys = malloc (sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
-    aout->output.p_sys = sys;
+    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)
@@ -104,12 +125,12 @@ static int Open (vlc_object_t *obj)
 
     if (setup != NULL)
     {
-        rate = aout->output.output.i_rate;
-        channels = aout_FormatNbChannels(&aout->output.output);
+        rate = aout->format.i_rate;
+        channels = aout_FormatNbChannels(&aout->format);
 
         if (setup (&sys->opaque, format, &rate, &channels))
             goto error;
-        /* Only call this callback if setup succeeded */ 
+        /* Only call this callback if setup succeeded */
         sys->cleanup = var_InheritAddress (obj, "amem-cleanup");
     }
     else
@@ -123,19 +144,66 @@ static int Open (vlc_object_t *obj)
         goto error;
 
     /* TODO: amem-format */
-    /* FIXME/TODO channel mapping */
-    if (strcmp(format, "S16N") || aout->output.output.i_channels != channels)
+    if (strcmp(format, "S16N"))
     {
         msg_Err (aout, "format not supported");
         goto error;
     }
-    aout->output.output.i_format = VLC_CODEC_S16N;
-    aout->output.output.i_rate = rate;
 
-    aout->output.pf_play = Play;
-    aout->output.pf_pause = NULL;
+    /* channel mapping */
+    switch (channels)
+    {
+        case 1:
+            aout->format.i_physical_channels = AOUT_CHAN_CENTER;
+            break;
+        case 2:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
+            break;
+        case 3:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_LFE;
+            break;
+        case 4:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
+                AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
+            break;
+        case 5:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
+                AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;
+            break;
+        case 6:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
+                AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE;
+            break;
+        case 7:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
+                AOUT_CHAN_REARCENTER | AOUT_CHAN_MIDDLELEFT |
+                AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE;
+            break;
+        case 8:
+            aout->format.i_physical_channels =
+                AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
+                AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
+                AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | AOUT_CHAN_LFE;
+            break;
+        default:
+            assert(0);
+    }
+
+    aout->format.i_format = VLC_CODEC_S16N;
+    aout->format.i_rate = rate;
+    aout->format.i_original_channels = aout->format.i_physical_channels;
+
+    aout->pf_play = Play;
+    aout->pf_pause = Pause;
+    aout->pf_flush = Flush;
     if (sys->set_volume != NULL)
-        aout->output.pf_volume_set = VolumeSet;
+        aout->pf_volume_set = VolumeSet;
     else
         aout_VolumeSoftInit (aout);
     return VLC_SUCCESS;
@@ -147,8 +215,8 @@ error:
 
 static void Close (vlc_object_t *obj)
 {
-    aout_instance_t *aout = (aout_instance_t *)obj;
-    aout_sys_t *sys = aout->output.p_sys;
+    audio_output_t *aout = (audio_output_t *)obj;
+    aout_sys_t *sys = aout->sys;
 
     if (sys->cleanup != NULL)
         sys->cleanup (sys->opaque);