]> git.sesse.net Git - vlc/blobdiff - plugins/beos/aout_beos.cpp
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / beos / aout_beos.cpp
index 3f16f91f503e535ef292e03cb04279d22698ac13..2f4ed344e65661056aa8c43c990b40f230d03df0 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
- * aout_beos.cpp: beos interface
+ * aout_beos.cpp: BeOS audio output
  *****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
+ * Copyright (C) 1999, 2000, 2001 VideoLAN
+ * $Id: aout_beos.cpp,v 1.13 2001/02/20 07:49:12 sam Exp $
  *
- * Authors:
- * Samuel Hocevar <sam@via.ecp.fr>
+ * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
+ *          Samuel Hocevar <sam@zoy.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME beos
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
@@ -28,8 +32,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>                                      /* malloc(), free() */
-#include <sys/types.h>                        /* on BSD, uio.h needs types.h */
-#include <sys/uio.h>                                            /* "input.h" */
 #include <kernel/OS.h>
 #include <View.h>
 #include <Application.h>
@@ -46,20 +48,20 @@ extern "C"
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
 
 #include "audio_output.h"
 
 #include "intf_msg.h"
-
 #include "main.h"
+
+#include "modules.h"
 }
 
 /*****************************************************************************
- * aout_sys_t: esd audio output method descriptor
+ * aout_sys_t: BeOS audio output method descriptor
  *****************************************************************************
  * This structure is part of the audio output thread descriptor.
- * It describes some esd specific variables.
+ * It describes some BeOS specific variables.
  *****************************************************************************/
 typedef struct aout_sys_s
 {
@@ -75,15 +77,50 @@ extern "C"
 {
 
 /*****************************************************************************
- * aout_BeOpen: opens a BPushGameSound
+ * Local prototypes.
+ *****************************************************************************/
+static int     aout_Probe       ( probedata_t *p_data );
+static int     aout_Open        ( aout_thread_t *p_aout );
+static int     aout_SetFormat   ( aout_thread_t *p_aout );
+static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static void    aout_Play        ( aout_thread_t *p_aout,
+                                  byte_t *buffer, int i_size );
+static void    aout_Close       ( aout_thread_t *p_aout );
+
+/*****************************************************************************
+ * Functions exported as capabilities. They are declared as static so that
+ * we don't pollute the namespace too much.
+ *****************************************************************************/
+void _M( aout_getfunctions )( function_list_t * p_function_list )
+{
+    p_function_list->pf_probe = aout_Probe;
+    p_function_list->functions.aout.pf_open = aout_Open;
+    p_function_list->functions.aout.pf_setformat = aout_SetFormat;
+    p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
+    p_function_list->functions.aout.pf_play = aout_Play;
+    p_function_list->functions.aout.pf_close = aout_Close;
+}
+
+/*****************************************************************************
+ * aout_Probe: probe the audio device and return a score
  *****************************************************************************/
-int aout_BeOpen( aout_thread_t *p_aout )
+static int aout_Probe( probedata_t *p_data )
+{
+    /* We don't test anything since I don't know what to test. However
+     * if the module could be loaded it is quite likely to work. */
+    return( 100 );
+}
+
+/*****************************************************************************
+ * aout_Open: opens a BPushGameSound
+ *****************************************************************************/
+static int aout_Open( aout_thread_t *p_aout )
 {
     /* Allocate structure */
     p_aout->p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
     if( p_aout->p_sys == NULL )
     {
-        intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
+        intf_ErrMsg("error: %s", strerror(ENOMEM) );
         return( 1 );
     }
 
@@ -92,12 +129,12 @@ int aout_BeOpen( aout_thread_t *p_aout )
     if( p_aout->p_sys->p_format == NULL )
     {
         free( p_aout->p_sys );
-        intf_ErrMsg("error: cannot allocate memory for gs_audio_format\n" );
+        intf_ErrMsg("error: cannot allocate memory for gs_audio_format" );
         return( 1 );
     }
 
     /* Initialize some variables */
-    p_aout->i_format = AOUT_DEFAULT_FORMAT;
+    p_aout->i_format = AOUT_FORMAT_DEFAULT;
     p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
                                                   AOUT_STEREO_DEFAULT );
     p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
@@ -106,7 +143,8 @@ int aout_BeOpen( aout_thread_t *p_aout )
     p_aout->p_sys->p_format->channel_count = p_aout->i_channels;
     p_aout->p_sys->p_format->format = gs_audio_format::B_GS_S16;
     p_aout->p_sys->p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
-    p_aout->p_sys->p_format->buffer_size = 8192;
+    p_aout->p_sys->p_format->buffer_size = 4*8192;
+    p_aout->p_sys->i_buffer_pos = 0;
 
     /* Allocate BPushGameSound */
     p_aout->p_sys->p_sound = new BPushGameSound( 8192,
@@ -116,7 +154,7 @@ int aout_BeOpen( aout_thread_t *p_aout )
     {
         free( p_aout->p_sys->p_format );
         free( p_aout->p_sys );
-        intf_ErrMsg("error: cannot allocate memory for BPushGameSound\n" );
+        intf_ErrMsg("error: cannot allocate memory for BPushGameSound" );
         return( 1 );
     }
 
@@ -124,7 +162,7 @@ int aout_BeOpen( aout_thread_t *p_aout )
     {
         free( p_aout->p_sys->p_format );
         free( p_aout->p_sys );
-        intf_ErrMsg("error: cannot allocate memory for BPushGameSound\n" );
+        intf_ErrMsg("error: cannot allocate memory for BPushGameSound" );
         return( 1 );
     }
 
@@ -135,70 +173,41 @@ int aout_BeOpen( aout_thread_t *p_aout )
 
     return( 0 );
 }
-/*****************************************************************************
- * aout_BeReset: resets the dsp
- *****************************************************************************/
-int aout_BeReset( aout_thread_t *p_aout )
-{
-    return( 0 );
-}
 
 /*****************************************************************************
- * aout_BeSetFormat: sets the dsp output format
+ * aout_SetFormat: sets the dsp output format
  *****************************************************************************/
-int aout_BeSetFormat( aout_thread_t *p_aout )
+static int aout_SetFormat( aout_thread_t *p_aout )
 {
     return( 0 );
 }
 
 /*****************************************************************************
- * aout_BeSetChannels: sets the dsp's stereo or mono mode
+ * aout_GetBufInfo: buffer status query
  *****************************************************************************/
-int aout_BeSetChannels( aout_thread_t *p_aout )
+static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
 {
-    return( 0 );
-}
-
-/*****************************************************************************
- * aout_BeSetRate: sets the dsp's audio output rate
- *****************************************************************************/
-int aout_BeSetRate( aout_thread_t *p_aout )
-{
-    return( 0 );
-}
-
-/*****************************************************************************
- * aout_BeGetBufInfo: buffer status query
- *****************************************************************************/
-long aout_BeGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
-{
-
+    /* Each value is 4 bytes long (stereo signed 16 bits) */
     long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
 
-    /*fprintf( stderr, "read 0x%.6lx - write 0x%.6lx = ",
-             i_hard_pos, p_aout->p_sys->i_buffer_pos );*/
-
-    if( i_hard_pos < p_aout->p_sys->i_buffer_pos )
+    i_hard_pos = p_aout->p_sys->i_buffer_pos - i_hard_pos;
+    if( i_hard_pos < 0 )
     {
-        i_hard_pos += p_aout->p_sys->i_buffer_size;
+         i_hard_pos += p_aout->p_sys->i_buffer_size;
     }
 
-    /*fprintf( stderr, "0x%.6lx\n", i_hard_pos - p_aout->p_sys->i_buffer_pos ); */
-
-    return( (p_aout->p_sys->i_buffer_size - (i_hard_pos - p_aout->p_sys->i_buffer_pos)) );
+    return( i_hard_pos );
 }
 
 /*****************************************************************************
- * aout_BePlaySamples: plays a sound samples buffer
+ * aout_Play: plays a sound samples buffer
  *****************************************************************************
  * This function writes a buffer of i_length bytes in the dsp
  *****************************************************************************/
-void aout_BePlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
+static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
 {
     long i_newbuf_pos;
 
-    //fprintf( stderr, "writing %i\n", i_size );
-
     if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
               > p_aout->p_sys->i_buffer_size )
     {
@@ -208,24 +217,26 @@ void aout_BePlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
                 p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos );
 
         memcpy( (void *)((int)p_aout->p_sys->p_buffer),
-                buffer,
+                buffer + p_aout->p_sys->i_buffer_size - p_aout->p_sys->i_buffer_pos,
                 i_size - ( p_aout->p_sys->i_buffer_size
                              - p_aout->p_sys->i_buffer_pos ) );
-
+        
         p_aout->p_sys->i_buffer_pos = i_newbuf_pos - p_aout->p_sys->i_buffer_size;
+
     }
     else
     {
         memcpy( (void *)((int)p_aout->p_sys->p_buffer + p_aout->p_sys->i_buffer_pos),
                 buffer, i_size );
+
         p_aout->p_sys->i_buffer_pos = i_newbuf_pos;
     }
 }
 
 /*****************************************************************************
- * aout_BeClose: closes the dsp audio device
+ * aout_Close: closes the dsp audio device
  *****************************************************************************/
-void aout_BeClose( aout_thread_t *p_aout )
+static void aout_Close( aout_thread_t *p_aout )
 {
     p_aout->p_sys->p_sound->UnlockCyclic();
     p_aout->p_sys->p_sound->StopPlaying( );