X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Foss.c;h=dbcd94943711e903379d009254311b40d5ef318b;hb=295b0e07523b7e9daf6c7ed76eec02d2dcfd80f0;hp=913a351093433033f32037cb4d30fef7bf6c77d5;hpb=238545c8e2920d653f7dd8b23c71cd74f3872d5d;p=vlc diff --git a/modules/access/oss.c b/modules/access/oss.c index 913a351093..dbcd949437 100644 --- a/modules/access/oss.c +++ b/modules/access/oss.c @@ -36,16 +36,19 @@ #include #include #include -#include -#include +#include -#include #include #include #include #include -#include +#ifdef HAVE_SYS_SOUNDCARD_H +# include +#endif +#ifdef HAVE_SOUNDCARD_H +# include +#endif #include @@ -84,11 +87,11 @@ vlc_module_begin () set_callbacks( DemuxOpen, DemuxClose ) add_bool( CFG_PREFIX "stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT, - true ); + true ) add_integer( CFG_PREFIX "samplerate", 48000, NULL, SAMPLERATE_TEXT, - SAMPLERATE_LONGTEXT, true ); + SAMPLERATE_LONGTEXT, true ) add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL, - CACHING_TEXT, CACHING_LONGTEXT, true ); + CACHING_TEXT, CACHING_LONGTEXT, true ) vlc_module_end () /***************************************************************************** @@ -118,12 +121,14 @@ struct demux_sys_t int i_fd; /* Audio */ - int i_pts; + int i_cache; unsigned int i_sample_rate; bool b_stereo; size_t i_max_frame_size; block_t *p_block; es_out_id_t *p_es; + + int64_t i_next_demux_date; /* Used to handle oss:// as input-slave properly */ }; static int FindMainDevice( demux_t *p_demux ) @@ -165,18 +170,18 @@ static int DemuxOpen( vlc_object_t *p_this ) p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; - p_sys->i_sample_rate = var_CreateGetInteger( p_demux, CFG_PREFIX "samplerate" ); - p_sys->b_stereo = var_CreateGetBool( p_demux, CFG_PREFIX "stereo" ); - p_sys->i_pts = var_CreateGetInteger( p_demux, CFG_PREFIX "caching" ); + p_sys->i_sample_rate = var_InheritInteger( p_demux, CFG_PREFIX "samplerate" ); + p_sys->b_stereo = var_InheritBool( p_demux, CFG_PREFIX "stereo" ); + p_sys->i_cache = var_InheritInteger( p_demux, CFG_PREFIX "caching" ); p_sys->i_fd = -1; p_sys->p_es = NULL; p_sys->p_block = NULL; + p_sys->i_next_demux_date = -1; - if( p_demux->psz_path && *p_demux->psz_path ) - p_sys->psz_device = p_demux->psz_path; + if( p_demux->psz_location && *p_demux->psz_location ) + p_sys->psz_device = p_demux->psz_location; else p_sys->psz_device = OSS_DEFAULT; - msg_Err( p_this, "Device is %s", p_sys->psz_device ); if( FindMainDevice( p_demux ) != VLC_SUCCESS ) { @@ -215,7 +220,6 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) /* Special for access_demux */ case DEMUX_CAN_PAUSE: case DEMUX_CAN_SEEK: - case DEMUX_SET_PAUSE_STATE: case DEMUX_CAN_CONTROL_PACE: pb = (bool*)va_arg( args, bool * ); *pb = false; @@ -223,7 +227,7 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) case DEMUX_GET_PTS_DELAY: pi64 = (int64_t*)va_arg( args, int64_t * ); - *pi64 = (int64_t)p_sys->i_pts * 1000; + *pi64 = (int64_t)p_sys->i_cache * 1000; return VLC_SUCCESS; case DEMUX_GET_TIME: @@ -231,6 +235,10 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) *pi64 = mdate(); return VLC_SUCCESS; + case DEMUX_SET_NEXT_DEMUX_TIME: + p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t ); + return VLC_SUCCESS; + /* TODO implement others */ default: return VLC_EGENERIC; @@ -251,19 +259,31 @@ static int Demux( demux_t *p_demux ) fd.events = POLLIN|POLLPRI; fd.revents = 0; - /* Wait for data */ - if( poll( &fd, 1, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */ + block_t *p_block = NULL; + + do { - if( fd.revents & (POLLIN|POLLPRI) ) + if( p_block ) { - block_t *p_block = GrabAudio( p_demux ); - if( p_block ) + es_out_Send( p_demux->out, p_sys->p_es, p_block ); + p_block = NULL; + } + + /* Wait for data */ + if( poll( &fd, 1, 10 ) ) /* Timeout after 0.01 seconds. Bigger delays are an issue when used with/as an input-slave since all the inputs run in the same thread. */ + { + if( fd.revents & (POLLIN|POLLPRI) ) { - es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts ); - es_out_Send( p_demux->out, p_sys->p_es, p_block ); + p_block = GrabAudio( p_demux ); + if( p_block ) + es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts ); } } - } + } while( p_block && p_sys->i_next_demux_date > 0 && + p_block->i_pts < p_sys->i_next_demux_date ); + + if( p_block ) + es_out_Send( p_demux->out, p_sys->p_es, p_block ); return 1; } @@ -320,7 +340,7 @@ static int OpenAudioDevOss( demux_t *p_demux ) int i_fd; int i_format; - i_fd = open( p_demux->p_sys->psz_device, O_RDONLY | O_NONBLOCK ); + i_fd = vlc_open( p_demux->p_sys->psz_device, O_RDONLY | O_NONBLOCK ); if( i_fd < 0 ) { @@ -374,7 +394,7 @@ static int OpenAudioDev( demux_t *p_demux ) p_sys->i_sample_rate ); es_format_t fmt; - es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('a','r','a','w') ); + es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_S16L ); fmt.audio.i_channels = p_sys->b_stereo ? 2 : 1; fmt.audio.i_rate = p_sys->i_sample_rate; @@ -396,7 +416,7 @@ static int OpenAudioDev( demux_t *p_demux ) static bool ProbeAudioDevOss( demux_t *p_demux, const char *psz_device ) { int i_caps; - int i_fd = open( psz_device, O_RDONLY | O_NONBLOCK ); + int i_fd = vlc_open( psz_device, O_RDONLY | O_NONBLOCK ); if( i_fd < 0 ) {