Commit ac08ae30 authored by Jean-Marc Dressler's avatar Jean-Marc Dressler

D�but du portage BeOS. Beaucoup de fuchiers ont �t� modifi� car il a fallu

r�organiser les headers pour que ce soient les headers les plus proches
du syst�me qui se retrouvent en premier (threads.h devrait toujours �tre
le premier des headers non syst�mes). J'ai du aussi rajouter un type
plugin_id_t et par la m�me occasion inclure plugins.h dans la plupart
des fichiers. Voici en vrac les modifs les plus importantes que j'ai op�r�:

o L�g�re r�organisation pour les raisons �voqu�es ci-dessus (certaines
  macros comme MIN et MAX peuvent �tre d�j� d�finies par le syst�me et
  interf�rer avec celles d�finies dans common.h ou autre)

o Dans intf_msg j'ai du remplacer les vasprintf par des vsprintf
  dans le cas o� ARCH=BEOS.

o la commande hostname du Makefile n'�tait pas compatible et je
  l'ai donc enlev�, en avons-nous besoin ? Auquel cas il suffit de
  rajouter un ifeq.

o J'ai aussi remplac�  les bzero et bcopy par memset et memmove.

o plugin.c, mtime.c et threads.h et quelques fichiers de l'input
  ont �t� adapt�s � BeOS � grand coup de #ifdef SYS_*.

TODO:

o Ecrire intf_beos.cpp, vout_beos.cpp et aout_beos.cpp

Je suis sous linux et je viens de tester le client qui marche tr�s
bien, mais il est n�anmoins possible que j'ai introduit quelques
probl�mes de compilations pour certains modules, si c'est le cas
pr�venez moi.
parent ec9bf58a
......@@ -10,7 +10,7 @@
################################################################################
# Environment
CC=egcc
CC=gcc
#CC=gcc295
SHELL=/bin/sh
INSTALL=install
......@@ -30,7 +30,7 @@ VIDEO = x11
#VIDEO += ggi
#VIDEO += glide
# Not yet supported
#VIDEO += beos
#VIDEO = beos
#VIDEO += dga
# Fallback method that should always work
VIDEO += dummy
......@@ -82,7 +82,9 @@ endif
# PROGRAM_BUILD is a complete identification of the build
# ( we can't use fancy options with date since OSes like Solaris
# or FreeBSD have strange date implementations )
PROGRAM_BUILD = `date` $(USER)@`hostname`
PROGRAM_BUILD = `date` $(USER)
# XXX: beos does not support hostname
#PROGRAM_BUILD = `date` $(USER)@`hostname`
# DEFINE will contain some of the constants definitions decided in Makefile,
# including ARCH_xx and SYS_xx. It will be passed to C compiler.
......@@ -124,6 +126,10 @@ ifeq ($(SYS),LINUX)
LIB += -lpthread -ldl
endif
ifeq ($SYS),BEOS)
LIB += -llibroot -llibgame -llibbe
endif
LIB += -lm
#
......
......@@ -184,7 +184,7 @@ typedef struct aout_thread_s
aout_fifo_t fifo[ AOUT_MAX_FIFOS ];
/* Plugins */
void * p_aout_plugin; /* video output plugin */
plugin_id_t aout_plugin; /* video output plugin */
aout_sys_open_t * p_sys_open;
aout_sys_reset_t * p_sys_reset;
aout_sys_setformat_t * p_sys_setformat;
......
......@@ -103,8 +103,12 @@ typedef struct video_parser_s * p_video_parser_t;
#define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
/* MAX and MIN: self explanatory */
#ifndef MAX
#define MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
#endif
#ifndef MIN
#define MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
#endif
/* MSB (big endian)/LSB (little endian) convertions - network order is always
* MSB, and should be used for both network communications and files. Note that
......
......@@ -373,6 +373,10 @@
* Messages and console interfaces configuration
*****************************************************************************/
/* Maximal size of a message to be stored in the mesage queue,
* it is needed when vasprintf is not avalaible */
#define INTF_MAX_MSG_SIZE 512
/* Maximal size of the message queue - in case of overflow, all messages in the
* queue are printed by the calling thread */
#define INTF_MSG_QSIZE 64
......
......@@ -58,7 +58,7 @@ typedef struct intf_thread_s
p_intf_sys_t p_sys; /* system interface */
/* Plugin */
void * p_intf_plugin; /* interface plugin */
plugin_id_t intf_plugin; /* interface plugin */
intf_sys_create_t * p_sys_create; /* create interface thread */
intf_sys_manage_t * p_sys_manage; /* main loop */
intf_sys_destroy_t * p_sys_destroy; /* destroy interface */
......
......@@ -21,7 +21,13 @@
* Boston, MA 02111-1307, USA.
*****************************************************************************/
void * RequestPlugin ( char * psz_mask, char * psz_name );
void TrashPlugin ( void * p_plugin );
void * GetPluginFunction ( void *plugin, char *name );
#ifdef SYS_BEOS
typedef int plugin_id_t;
#else
typedef void* plugin_id_t;
#endif
int RequestPlugin ( plugin_id_t * p_plugin, char * psz_mask, char * psz_name );
void TrashPlugin ( plugin_id_t p_plugin );
void * GetPluginFunction ( plugin_id_t plugin, char *name );
......@@ -24,9 +24,17 @@
* Boston, MA 02111-1307, USA.
*****************************************************************************/
#ifdef SYS_GNU
#include <cthreads.h>
#else
#endif
#ifdef SYS_BEOS
#include <kernel/OS.h>
#include <kernel/scheduler.h>
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
#include <pthread.h>
#endif
......@@ -80,13 +88,38 @@ typedef struct s_condition {
struct cond_imp *implications;
} vlc_cond_t;
#else /* SYS_GNU */
#endif /* SYS_GNU */
#ifdef SYS_BEOS
typedef thread_id vlc_thread_t;
typedef struct
{
int32 init;
sem_id lock;
thread_id owner;
} vlc_mutex_t;
typedef struct
{
int32 init;
sem_id sem;
sem_id handshakeSem;
sem_id signalSem;
volatile int32 nw;
volatile int32 ns;
} vlc_cond_t;
#endif /* SYS_BEOS */
#if defined(SYS_LINUX) || defined(SYS_BSD)
typedef pthread_t vlc_thread_t;
typedef pthread_mutex_t vlc_mutex_t;
typedef pthread_cond_t vlc_cond_t;
#endif /* SYS_GNU */
#endif /* SYS_LINUX || SYS_BSD */
typedef void *(*vlc_thread_func_t)(void *p_data);
......@@ -122,7 +155,14 @@ static __inline__ int vlc_thread_create( vlc_thread_t *p_thread,
#ifdef SYS_GNU
*p_thread = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
return( 0 );
#else
#endif
#ifdef SYS_BEOS
*p_thread = spawn_thread( (thread_func)func, psz_name, B_NORMAL_PRIORITY, p_data );
return resume_thread( *p_thread );
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_create( p_thread, NULL, func, p_data );
#endif
}
......@@ -135,7 +175,13 @@ static __inline__ void vlc_thread_exit( void )
#ifdef SYS_GNU
int result;
cthread_exit( &result );
#else
#endif
#ifdef SYS_BEOS
exit_thread( 0 );
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
pthread_exit( 0 );
#endif
}
......@@ -147,11 +193,34 @@ static __inline__ void vlc_thread_join( vlc_thread_t thread )
{
#ifdef SYS_GNU
cthread_join( thread );
#else
#endif
#ifdef SYS_BEOS
int32 exit_value;
wait_for_thread( thread, &exit_value );
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
pthread_join( thread, NULL );
#endif
}
#ifdef SYS_BEOS
/* lazy_init_mutex */
static __inline__ void lazy_init_mutex(vlc_mutex_t* p_mutex)
{
int32 v = atomic_or( &p_mutex->init, 1 );
if( 2000 == v ) // we're the first, so do the init
{
vlc_mutex_init( p_mutex );
}
else // we're not the first, so wait until the init is finished
{
while( p_mutex->init != 9999 ) snooze( 10000 );
}
}
#endif
/*****************************************************************************
* vlc_mutex_init: initialize a mutex
*****************************************************************************/
......@@ -160,7 +229,20 @@ static __inline__ int vlc_mutex_init( vlc_mutex_t *p_mutex )
#ifdef SYS_GNU
mutex_init( p_mutex );
return( 0 );
#else
#endif
#ifdef SYS_BEOS
// check the arguments and whether it's already been initialized
if( !p_mutex ) return B_BAD_VALUE;
if( p_mutex->init == 9999 ) return EALREADY;
p_mutex->lock = create_sem( 1, "BeMutex" );
p_mutex->owner = -1;
p_mutex->init = 9999;
return B_OK;
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_mutex_init( p_mutex, NULL );
#endif
}
......@@ -173,7 +255,21 @@ static __inline__ int vlc_mutex_lock( vlc_mutex_t *p_mutex )
#ifdef SYS_GNU
mutex_lock( p_mutex );
return( 0 );
#else
#endif
#ifdef SYS_BEOS
status_t err;
if( !p_mutex ) return B_BAD_VALUE;
if( p_mutex->init < 2000 ) return B_NO_INIT;
lazy_init_mutex( p_mutex );
err = acquire_sem( p_mutex->lock );
if( !err ) p_mutex->owner = find_thread( NULL );
return err;
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_mutex_lock( p_mutex );
#endif
}
......@@ -186,11 +282,40 @@ static __inline__ int vlc_mutex_unlock( vlc_mutex_t *p_mutex )
#ifdef SYS_GNU
mutex_unlock( p_mutex );
return( 0 );
#else
#endif
#ifdef SYS_BEOS
if(! p_mutex) return B_BAD_VALUE;
if( p_mutex->init < 2000 ) return B_NO_INIT;
lazy_init_mutex( p_mutex );
if( p_mutex->owner != find_thread(NULL) ) return ENOLCK;
p_mutex->owner = -1;
release_sem( p_mutex->lock );
return B_OK;
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_mutex_unlock( p_mutex );
#endif
}
#ifdef SYS_BEOS
/* lazy_init_cond */
static __inline__ void lazy_init_cond( vlc_cond_t* p_condvar )
{
int32 v = atomic_or( &p_condvar->init, 1 );
if( 2000 == v ) // we're the first, so do the init
{
vlc_cond_init( p_condvar );
}
else // we're not the first, so wait until the init is finished
{
while( p_condvar->init != 9999 ) snooze( 10000 );
}
}
#endif
/*****************************************************************************
* vlc_cond_init: initialize a condition
*****************************************************************************/
......@@ -204,7 +329,21 @@ static __inline__ int vlc_cond_init( vlc_cond_t *p_condvar )
p_condvar->implications = 0;
return( 0 );
#else
#endif
#ifdef SYS_BEOS
if( !p_condvar ) return B_BAD_VALUE;
if( p_condvar->init == 9999 ) return EALREADY;
p_condvar->sem = create_sem( 0, "CVSem" );
p_condvar->handshakeSem = create_sem( 0, "CVHandshake" );
p_condvar->signalSem = create_sem( 1, "CVSignal" );
p_condvar->ns = p_condvar->nw = 0;
p_condvar->init = 9999;
return B_OK;
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_cond_init( p_condvar, NULL );
#endif
}
......@@ -221,7 +360,33 @@ static __inline__ int vlc_cond_signal( vlc_cond_t *p_condvar )
cond_signal( (condition_t)p_condvar );
}
return( 0 );
#else
#endif
#ifdef SYS_BEOS
status_t err = B_OK;
if( !p_condvar ) return B_BAD_VALUE;
if( p_condvar->init < 2000 ) return B_NO_INIT;
lazy_init_cond( p_condvar );
if( acquire_sem(p_condvar->signalSem) == B_INTERRUPTED) return B_INTERRUPTED;
if( p_condvar->nw > p_condvar->ns )
{
p_condvar->ns += 1;
release_sem( p_condvar->sem );
release_sem( p_condvar->signalSem );
while( acquire_sem(p_condvar->handshakeSem) == B_INTERRUPTED )
{ err = B_INTERRUPTED; }
}
else
{
release_sem( p_condvar->signalSem );
}
return err;
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_cond_signal( p_condvar );
#endif
}
......@@ -234,8 +399,39 @@ static __inline__ int vlc_cond_wait( vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex
#ifdef SYS_GNU
condition_wait( (condition_t)p_condvar, (mutex_t)p_mutex );
return( 0 );
#else
#endif
#ifdef SYS_BEOS
status_t err;
if( !p_condvar ) return B_BAD_VALUE;
if( !p_mutex ) return B_BAD_VALUE;
if( p_condvar->init < 2000 ) return B_NO_INIT;
lazy_init_cond( p_condvar );
if( acquire_sem(p_condvar->signalSem) == B_INTERRUPTED ) return B_INTERRUPTED;
p_condvar->nw += 1;
release_sem( p_condvar->signalSem );
vlc_mutex_unlock( p_mutex );
err = acquire_sem( p_condvar->sem );
while( acquire_sem(p_condvar->signalSem) == B_INTERRUPTED)
{ err = B_INTERRUPTED; }
if( p_condvar->ns > 0 )
{
release_sem( p_condvar->handshakeSem );
p_condvar->ns -= 1;
}
p_condvar->nw -= 1;
release_sem( p_condvar->signalSem );
while( vlc_mutex_lock(p_mutex) == B_INTERRUPTED)
{ err = B_INTERRUPTED; }
return err;
#endif
#if defined(SYS_LINUX) || defined(SYS_BSD)
return pthread_cond_wait( p_condvar, p_mutex );
#endif
}
......@@ -152,7 +152,7 @@ typedef struct vout_thread_s
u32 i_blue_pixel; /* blue */
/* Plugins */
void * p_vout_plugin; /* video output plugin */
plugin_id_t vout_plugin; /* video output plugin */
vout_sys_create_t * p_sys_create; /* allocate output method */
vout_sys_init_t * p_sys_init; /* initialize output method */
vout_sys_end_t * p_sys_end; /* terminate output method */
......
......@@ -40,10 +40,11 @@
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "plugins.h"
#include "debug.h" /* "input_netlist.h" */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
......
......@@ -39,10 +39,11 @@
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "plugins.h"
#include "debug.h" /* "input_netlist.h" */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
......
......@@ -29,10 +29,11 @@
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include "threads.h"
#include "config.h"
#include "common.h"
#include "mtime.h" /* mtime_t */
#include "threads.h"
#include "plugins.h"
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
......
......@@ -41,10 +41,10 @@
#include <stdio.h> /* "intf_msg.h" */
#include <stdlib.h> /* calloc(), malloc(), free() */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h" /* mtime_t, mdate(), msleep() */
#include "threads.h"
#include "plugins.h"
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
......@@ -93,9 +93,8 @@ aout_thread_t *aout_CreateThread( int *pi_status )
/* Request an interface plugin */
psz_method = main_GetPszVariable( AOUT_METHOD_VAR, AOUT_DEFAULT_METHOD );
p_aout->p_aout_plugin = RequestPlugin( "aout", psz_method );
if( !p_aout->p_aout_plugin )
if( RequestPlugin( &p_aout->aout_plugin, "aout", psz_method ) )
{
intf_ErrMsg( "error: could not open audio plugin aout_%s.so\n", psz_method );
free( p_aout );
......@@ -103,21 +102,21 @@ aout_thread_t *aout_CreateThread( int *pi_status )
}
/* Get plugins */
p_aout->p_sys_open = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysOpen" );
p_aout->p_sys_reset = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysReset" );
p_aout->p_sys_setformat = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysSetFormat" );
p_aout->p_sys_setchannels = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysSetChannels" );
p_aout->p_sys_setrate = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysSetRate" );
p_aout->p_sys_getbufinfo = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysGetBufInfo" );
p_aout->p_sys_playsamples = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysPlaySamples" );
p_aout->p_sys_close = GetPluginFunction( p_aout->p_aout_plugin, "aout_SysClose" );
p_aout->p_sys_open = GetPluginFunction( p_aout->aout_plugin, "aout_SysOpen" );
p_aout->p_sys_reset = GetPluginFunction( p_aout->aout_plugin, "aout_SysReset" );
p_aout->p_sys_setformat = GetPluginFunction( p_aout->aout_plugin, "aout_SysSetFormat" );
p_aout->p_sys_setchannels = GetPluginFunction( p_aout->aout_plugin, "aout_SysSetChannels" );
p_aout->p_sys_setrate = GetPluginFunction( p_aout->aout_plugin, "aout_SysSetRate" );
p_aout->p_sys_getbufinfo = GetPluginFunction( p_aout->aout_plugin, "aout_SysGetBufInfo" );
p_aout->p_sys_playsamples = GetPluginFunction( p_aout->aout_plugin, "aout_SysPlaySamples" );
p_aout->p_sys_close = GetPluginFunction( p_aout->aout_plugin, "aout_SysClose" );
/*
* Initialize audio device
*/
if ( p_aout->p_sys_open( p_aout ) )
{
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
free( p_aout );
return( NULL );
}
......@@ -128,28 +127,28 @@ aout_thread_t *aout_CreateThread( int *pi_status )
if ( p_aout->p_sys_reset( p_aout ) )
{
p_aout->p_sys_close( p_aout );
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
free( p_aout );
return( NULL );
}
if ( p_aout->p_sys_setformat( p_aout ) )
{
p_aout->p_sys_close( p_aout );
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
free( p_aout );
return( NULL );
}
if ( p_aout->p_sys_setchannels( p_aout ) )
{
p_aout->p_sys_close( p_aout );
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
free( p_aout );
return( NULL );
}
if ( p_aout->p_sys_setrate( p_aout ) )
{
p_aout->p_sys_close( p_aout );
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
free( p_aout );
return( NULL );
}
......@@ -160,7 +159,7 @@ aout_thread_t *aout_CreateThread( int *pi_status )
if( aout_SpawnThread( p_aout ) )
{
p_aout->p_sys_close( p_aout );
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
free( p_aout );
return( NULL );
}
......@@ -327,7 +326,7 @@ void aout_DestroyThread( aout_thread_t * p_aout, int *pi_status )
intf_DbgMsg("aout debug: audio device (%s) closed\n", p_aout->psz_device);
/* Close plugin */
TrashPlugin( p_aout->p_aout_plugin );
TrashPlugin( p_aout->aout_plugin );
/* Free structure */
free( p_aout );
......
......@@ -34,11 +34,12 @@
#include <stdlib.h> /* free() */
#include <netinet/in.h> /* ntohs() */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "intf_msg.h"
#include "plugins.h"
#include "debug.h"
#include "input.h"
......
......@@ -31,11 +31,12 @@
#include <netinet/in.h> /* ntohs */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "intf_msg.h"
#include "plugins.h"
#include "debug.h"
#include "input.h"
......
......@@ -27,10 +27,10 @@
#include <sys/types.h> /* on BSD, uio.h needs types.h */
#include <sys/uio.h> /* "input.h" */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "input.h"
#include "input_file.h"
......
......@@ -32,10 +32,10 @@
#include <string.h> /* strerror() */
#include <errno.h> /* errno */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "intf_msg.h"
#include "debug.h"
#include "input.h"
......
......@@ -32,17 +32,17 @@
#include <errno.h> /* errno */
#include <sys/time.h> /* "input_network.h" */
#ifdef SYS_BSD
#if defined(SYS_BSD) || defined(SYS_BEOS)
#include <sys/socket.h> /* struct sockaddr */
#endif
#include <netdb.h> /* servent, getservbyname(), hostent, gethostbyname() */
#include <netinet/in.h> /* sockaddr_in, htons(), htonl() */
#include "threads.h"
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "threads.h"
#include "netutils.h"
#include "input.h"
......@@ -96,6 +96,7 @@ int input_NetworkOpen( input_thread_t *p_input )
return( 1 );
}
#ifndef SYS_BEOS
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
* packet loss caused by scheduling problems */
i_socket_option = 524288;
......@@ -109,6 +110,7 @@ int input_NetworkOpen( input_thread_t *p_input )
close( p_input->i_handle );
return( 1 );
}
#endif /* SYS_BEOS */