/*****************************************************************************
* oss.c : OSS input module for vlc
*****************************************************************************
- * Copyright (C) 2002-2009 the VideoLAN team
+ * Copyright (C) 2002-2009 VLC authors and VideoLAN
* $Id$
*
* Authors: Benjamin Pracht <bigben at videolan dot org>
* Antoine Cellerier <dionoea at videolan d.t org>
* Dennis Lou <dlou99 at yahoo dot com>
*
- * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU 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.
+ * 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.
*****************************************************************************/
/*****************************************************************************
#include <vlc_plugin.h>
#include <vlc_access.h>
#include <vlc_demux.h>
-#include <vlc_input.h>
-#include <vlc_vout.h>
+#include <vlc_fs.h>
-#include <ctype.h>
+#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
-#include <sys/soundcard.h>
+#ifdef HAVE_SYS_SOUNDCARD_H
+# include <sys/soundcard.h>
+#endif
+#ifdef HAVE_SOUNDCARD_H
+# include <soundcard.h>
+#endif
#include <poll.h>
#define SAMPLERATE_LONGTEXT N_( \
"Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100, 48000)" )
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
- "Caching value for OSS captures. This " \
- "value should be set in milliseconds." )
-
#define OSS_DEFAULT "/dev/dsp"
#define CFG_PREFIX "oss-"
set_capability( "access_demux", 10 )
set_callbacks( DemuxOpen, DemuxClose )
- add_bool( CFG_PREFIX "stereo", true, NULL, STEREO_TEXT, STEREO_LONGTEXT,
- true );
- add_integer( CFG_PREFIX "samplerate", 48000, NULL, SAMPLERATE_TEXT,
- SAMPLERATE_LONGTEXT, true );
- add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL,
- CACHING_TEXT, CACHING_LONGTEXT, true );
+ add_bool( CFG_PREFIX "stereo", true, STEREO_TEXT, STEREO_LONGTEXT,
+ true )
+ add_integer( CFG_PREFIX "samplerate", 48000, SAMPLERATE_TEXT,
+ SAMPLERATE_LONGTEXT, true )
vlc_module_end ()
/*****************************************************************************
int i_fd;
/* Audio */
- int i_pts;
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 )
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_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 )
{
/* 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;
case DEMUX_GET_PTS_DELAY:
pi64 = (int64_t*)va_arg( args, int64_t * );
- *pi64 = (int64_t)p_sys->i_pts * 1000;
+ *pi64 = INT64_C(1000)
+ * var_InheritInteger( p_demux, "live-caching" );
return VLC_SUCCESS;
case DEMUX_GET_TIME:
*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;
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( errno == EINTR )
+ continue;
+ 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;
}
block_t *p_block;
if( p_sys->p_block ) p_block = p_sys->p_block;
- else p_block = block_New( p_demux, p_sys->i_max_frame_size );
+ else p_block = block_Alloc( p_sys->i_max_frame_size );
if( !p_block )
{
msg_Warn( p_demux, "cannot get block" );
- return 0;
+ return NULL;
}
p_sys->p_block = p_block;
i_read = read( p_sys->i_fd, p_block->p_buffer,
p_sys->i_max_frame_size );
- if( i_read <= 0 ) return 0;
+ if( i_read <= 0 ) return NULL;
p_block->i_buffer = i_read;
- p_sys->p_block = 0;
+ p_sys->p_block = NULL;
/* Correct the date because of kernel buffering */
i_correct = i_read;
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 )
{
- msg_Err( p_demux, "cannot open OSS audio device (%m)" );
+ msg_Err( p_demux, "cannot open OSS audio device (%s)",
+ vlc_strerror_c(errno) );
goto adev_fail;
}
|| i_format != AFMT_S16_LE )
{
msg_Err( p_demux,
- "cannot set audio format (16b little endian) (%m)" );
+ "cannot set audio format (16b little endian) (%s)",
+ vlc_strerror_c(errno) );
goto adev_fail;
}
if( ioctl( i_fd, SNDCTL_DSP_STEREO,
&p_demux->p_sys->b_stereo ) < 0 )
{
- msg_Err( p_demux, "cannot set audio channels count (%m)" );
+ msg_Err( p_demux, "cannot set audio channels count (%s)",
+ vlc_strerror_c(errno) );
goto adev_fail;
}
if( ioctl( i_fd, SNDCTL_DSP_SPEED,
&p_demux->p_sys->i_sample_rate ) < 0 )
{
- msg_Err( p_demux, "cannot set audio sample rate (%m)" );
+ msg_Err( p_demux, "cannot set audio sample rate (%s)",
+ vlc_strerror_c(errno) );
goto adev_fail;
}
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;
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 )
{
- msg_Err( p_demux, "cannot open device %s for OSS audio (%m)", psz_device );
+ msg_Err( p_demux, "cannot open device %s for OSS audio (%s)",
+ psz_device, vlc_strerror_c(errno) );
goto open_failed;
}
/* this will fail if the device is video */
if( ioctl( i_fd, SNDCTL_DSP_GETCAPS, &i_caps ) < 0 )
{
- msg_Err( p_demux, "cannot get audio caps (%m)" );
+ msg_Err( p_demux, "cannot get audio caps (%s)",
+ vlc_strerror_c(errno) );
goto open_failed;
}