Commit 1c13a987 authored by Christophe Massiot's avatar Christophe Massiot

Big round of fixes in the aout3.

* Audio and video should now _always_ be perfectly in sync.
* Changes in a52.c (end_date management) must be ported to other codecs,
  otherwise mixer errors will appear.
* Audio output plug-in can now tell whether they can handle a little
  clock drift (for instance, inserting zeroes after a pause).
parent 692795dc
This diff is collapsed.
......@@ -449,6 +449,7 @@ PLUGINS="${PLUGINS} codec/a52old/imdct/imdct codec/a52old/downmix/downmix codec/
PLUGINS="${PLUGINS} video_filter/deinterlace/deinterlace video_filter/invert video_filter/wall video_filter/transform video_filter/distort video_filter/clone video_filter/crop"
PLUGINS="${PLUGINS} audio_filter/converter/float32tos16 audio_filter/converter/float32tos8 audio_filter/converter/float32tou16 audio_filter/converter/float32tou8 audio_filter/converter/a52tospdif audio_filter/converter/fixed32tofloat32 audio_filter/converter/fixed32tos16 audio_filter/converter/s16tofloat32"
PLUGINS="${PLUGINS} audio_filter/resampler/trivial"
PLUGINS="${PLUGINS} audio_filter/channel_mixer/trivial"
PLUGINS="${PLUGINS} audio_mixer/trivial audio_mixer/spdif"
PLUGINS="${PLUGINS} audio_output/file"
#PLUGINS="${PLUGINS} visualization/scope/scope"
......
......@@ -2,7 +2,7 @@
* aout_internal.h : internal defines for audio output
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: aout_internal.h,v 1.7 2002/08/19 23:12:57 massiot Exp $
* $Id: aout_internal.h,v 1.8 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -82,95 +82,11 @@ typedef struct aout_alloc_t
*****************************************************************************/
typedef struct aout_fifo_t
{
struct aout_buffer_t * p_first;
struct aout_buffer_t ** pp_last;
mtime_t end_date;
aout_buffer_t * p_first;
aout_buffer_t ** pp_last;
audio_date_t end_date;
} aout_fifo_t;
static inline void aout_FifoInit( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo )
{
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
p_fifo->end_date = 0;
}
static inline void aout_FifoPush( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo,
aout_buffer_t * p_buffer )
{
*p_fifo->pp_last = p_buffer;
p_fifo->pp_last = &p_buffer->p_next;
*p_fifo->pp_last = NULL;
/* Enforce continuity of the stream. */
if ( p_fifo->end_date )
{
mtime_t duration = p_buffer->end_date - p_buffer->start_date;
p_buffer->start_date = p_fifo->end_date;
p_buffer->end_date = p_fifo->end_date =
p_buffer->start_date + duration;
}
else
{
p_fifo->end_date = p_buffer->end_date;
}
}
static inline mtime_t aout_FifoNextStart( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo )
{
return p_fifo->end_date;
}
/* Reinit the end_date (for instance after a pause). */
static inline void aout_FifoSet( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo, mtime_t date )
{
aout_buffer_t * p_buffer;
p_fifo->end_date = date;
/* Remove all buffers. */
p_buffer = p_fifo->p_first;
while ( p_buffer != NULL )
{
aout_buffer_t * p_next = p_buffer->p_next;
aout_BufferFree( p_buffer );
p_buffer = p_next;
}
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
}
/* This function supposes there is at least one buffer in p_fifo. */
static inline aout_buffer_t * aout_FifoPop( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo )
{
aout_buffer_t * p_buffer;
p_buffer = p_fifo->p_first;
p_fifo->p_first = p_buffer->p_next;
if ( p_fifo->p_first == NULL )
{
p_fifo->pp_last = &p_fifo->p_first;
}
return p_buffer;
}
static inline void aout_FifoDestroy( struct aout_instance_t * p_aout,
aout_fifo_t * p_fifo )
{
aout_buffer_t * p_buffer;
p_buffer = p_fifo->p_first;
while ( p_buffer != NULL )
{
aout_buffer_t * p_next = p_buffer->p_next;
aout_BufferFree( p_buffer );
p_buffer = p_next;
}
}
/*****************************************************************************
* aout_filter_t : audio output filter
*****************************************************************************/
......@@ -297,3 +213,12 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
void aout_OutputDelete( aout_instance_t * p_aout );
VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, vlc_bool_t ) );
void aout_FormatPrepare( audio_sample_format_t * p_format );
void aout_FifoInit( aout_instance_t *, aout_fifo_t *, u32 );
mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
aout_buffer_t * aout_FifoPop( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
......@@ -2,7 +2,7 @@
* audio_output.h : audio output interface
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: audio_output.h,v 1.60 2002/08/19 21:31:11 massiot Exp $
* $Id: audio_output.h,v 1.61 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -126,6 +126,16 @@ struct aout_buffer_t
/* Size of a frame for S/PDIF output. */
#define AOUT_SPDIF_SIZE 6144
/*****************************************************************************
* audio_date_t : date incrementation without long-term rounding errors
*****************************************************************************/
struct audio_date_t
{
mtime_t date;
u32 i_divider;
u32 i_remainder;
};
/*****************************************************************************
* Prototypes
*****************************************************************************/
......@@ -136,7 +146,11 @@ VLC_EXPORT( void, aout_DeleteInstance, ( aout_instance_t * ) );
VLC_EXPORT( aout_buffer_t *, aout_BufferNew, ( aout_instance_t *, aout_input_t *, size_t ) );
VLC_EXPORT( void, aout_BufferDelete, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
VLC_EXPORT( void, aout_BufferPlay, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
VLC_EXPORT( void, aout_DateInit, ( audio_date_t *, u32 ) );
VLC_EXPORT( void, aout_DateSet, ( audio_date_t *, mtime_t ) );
VLC_EXPORT( void, aout_DateMove, ( audio_date_t *, mtime_t ) );
VLC_EXPORT( mtime_t, aout_DateGet, ( const audio_date_t * ) );
VLC_EXPORT( mtime_t, aout_DateIncrement, ( audio_date_t *, u32 ) );
/* From input.c : */
#define aout_InputNew(a,b,c) __aout_InputNew(VLC_OBJECT(a),b,c)
......
......@@ -105,15 +105,15 @@
/* Duration between the time we receive the data packet, and the time we will
* mark it to be presented */
#define DEFAULT_PTS_DELAY (mtime_t)(.45*CLOCK_FREQ)
#define DEFAULT_PTS_DELAY (mtime_t)(.2*CLOCK_FREQ)
/* DVD and VCD devices */
#ifndef WIN32
# define DVD_DEVICE "/dev/dvd"
# define VCD_DEVICE "/dev/cdrom"
# define DVD_DEVICE "/dev/dvd"
# define VCD_DEVICE "/dev/cdrom"
#else
# define DVD_DEVICE "D"
# define VCD_DEVICE "D"
# define DVD_DEVICE "D"
# define VCD_DEVICE "D"
#endif
/*****************************************************************************
......@@ -139,9 +139,13 @@
* will cause the calling thread to sleep */
#define AOUT_MAX_PREPARE_TIME (mtime_t)(.5*CLOCK_FREQ)
/* Buffers which arrive after pts - AOUT_MIN_PREPARE_TIME will be trashed
* to avoid too heavy resampling */
#define AOUT_MIN_PREPARE_TIME (mtime_t)(.04*CLOCK_FREQ)
/* Max acceptable delay between the coded PTS and the actual presentation
* time, without resampling */
#define AOUT_PTS_TOLERANCE (mtime_t)(.03*CLOCK_FREQ)
#define AOUT_PTS_TOLERANCE (mtime_t)(.02*CLOCK_FREQ)
/*****************************************************************************
* Video configuration
......
......@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc_common.h,v 1.21 2002/08/21 15:53:06 sam Exp $
* $Id: vlc_common.h,v 1.22 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
......@@ -178,6 +178,7 @@ typedef struct aout_sys_t aout_sys_t;
typedef struct aout_input_t aout_input_t;
typedef struct aout_buffer_t aout_buffer_t;
typedef struct audio_sample_format_t audio_sample_format_t;
typedef struct audio_date_t audio_date_t;
/* Video */
typedef struct vout_thread_t vout_thread_t;
......
......@@ -53,6 +53,8 @@ struct module_symbols_t
module_config_t * (* config_FindConfig_inner) ( vlc_object_t *, const char *psz_name ) ;
module_t * (* __module_Need_inner) ( vlc_object_t *, const char *, const char * ) ;
msg_subscription_t* (* __msg_Subscribe_inner) ( vlc_object_t * ) ;
mtime_t (* aout_DateGet_inner) ( const audio_date_t * ) ;
mtime_t (* aout_DateIncrement_inner) ( audio_date_t *, u32 ) ;
mtime_t (* input_ClockGetTS_inner) ( input_thread_t *, pgrm_descriptor_t *, mtime_t ) ;
mtime_t (* mdate_inner) ( void ) ;
pes_packet_t * (* input_NewPES_inner) ( input_buffers_t * ) ;
......@@ -102,8 +104,10 @@ struct module_symbols_t
void (* __vlc_thread_ready_inner) ( vlc_object_t * ) ;
void (* aout_BufferDelete_inner) ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) ;
void (* aout_BufferPlay_inner) ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) ;
void (* aout_DateInit_inner) ( audio_date_t *, u32 ) ;
void (* aout_DateMove_inner) ( audio_date_t *, mtime_t ) ;
void (* aout_DateSet_inner) ( audio_date_t *, mtime_t ) ;
void (* aout_DeleteInstance_inner) ( aout_instance_t * ) ;
void (* aout_FormatPrepare_inner) ( audio_sample_format_t * p_format ) ;
void (* aout_InputDelete_inner) ( aout_instance_t *, aout_input_t * ) ;
void (* config_Duplicate_inner) ( module_t *, module_config_t * ) ;
void (* config_SetCallbacks_inner) ( module_config_t *, module_config_t * ) ;
......@@ -210,8 +214,12 @@ struct module_symbols_t
# define aout_BufferDelete p_symbols->aout_BufferDelete_inner
# define aout_BufferNew p_symbols->aout_BufferNew_inner
# define aout_BufferPlay p_symbols->aout_BufferPlay_inner
# define aout_DateGet p_symbols->aout_DateGet_inner
# define aout_DateIncrement p_symbols->aout_DateIncrement_inner
# define aout_DateInit p_symbols->aout_DateInit_inner
# define aout_DateMove p_symbols->aout_DateMove_inner
# define aout_DateSet p_symbols->aout_DateSet_inner
# define aout_DeleteInstance p_symbols->aout_DeleteInstance_inner
# define aout_FormatPrepare p_symbols->aout_FormatPrepare_inner
# define aout_InputDelete p_symbols->aout_InputDelete_inner
# define aout_OutputNextBuffer p_symbols->aout_OutputNextBuffer_inner
# define config_Duplicate p_symbols->config_Duplicate_inner
......
/*****************************************************************************
* trivial.c : trivial channel mixer plug-in (drops unwanted channels)
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: trivial.c,v 1.1 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* 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
* (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.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <errno.h>
#include <stdlib.h> /* malloc(), free() */
#include <string.h>
#include <vlc/vlc.h>
#include "audio_output.h"
#include "aout_internal.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Create ( vlc_object_t * );
static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
aout_buffer_t * );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("audio filter for trivial channel mixing") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
/*****************************************************************************
* Create: allocate trivial channel mixer
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
aout_filter_t * p_filter = (aout_filter_t *)p_this;
if ( p_filter->input.i_channels == p_filter->output.i_channels
|| p_filter->input.i_format != p_filter->output.i_format
|| p_filter->input.i_rate != p_filter->output.i_rate
|| (p_filter->input.i_format != AOUT_FMT_FLOAT32
&& p_filter->input.i_format != AOUT_FMT_FIXED32) )
{
return -1;
}
p_filter->pf_do_work = DoWork;
if ( p_filter->input.i_channels > p_filter->output.i_channels )
{
/* Downmixing */
p_filter->b_in_place = 1;
}
else
{
/* Upmixing */
p_filter->b_in_place = 0;
}
return 0;
}
/*****************************************************************************
* SparseCopy: trivially downmix or upmix a buffer
*****************************************************************************/
static void SparseCopy( s32 * p_dest, const s32 * p_src, size_t i_len,
int i_output_stride, int i_input_stride )
{
int i;
for ( i = 0; i < i_len; i++ )
{
int j;
for ( j = 0; j < i_output_stride; j++ )
{
p_dest[j] = p_src[j];
}
p_src += i_input_stride;
p_dest += i_output_stride;
}
}
/*****************************************************************************
* DoWork: convert a buffer
*****************************************************************************/
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
SparseCopy( (s32 *)p_out_buf->p_buffer, (s32 *)p_in_buf->p_buffer,
p_in_buf->i_nb_samples, p_filter->output.i_channels,
p_filter->input.i_channels );
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * p_filter->output.i_channels
/ p_filter->input.i_channels;
}
......@@ -2,7 +2,7 @@
* a52tospdif.c : encapsulates A/52 frames into S/PDIF packets
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: a52tospdif.c,v 1.8 2002/08/17 13:26:57 tcastley Exp $
* $Id: a52tospdif.c,v 1.9 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Stphane Borel <stef@via.ecp.fr>
......@@ -50,7 +50,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for A/52->S/PDIF encapsulation") );
set_description( _("audio filter for A/52->S/PDIF encapsulation") );
set_capability( "audio filter", 10 );
set_callbacks( Create, NULL );
vlc_module_end();
......@@ -82,11 +82,13 @@ static int Create( vlc_object_t *p_this )
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
u16 i;
#ifdef WORDS_BIGENDIAN
static const u8 p_sync[6] = { 0xF8, 0x72, 0x4E, 0x1F, 0x00, 0x01 };
#else
static const u8 p_sync[6] = { 0x72, 0xF8, 0x1F, 0x4E, 0x01, 0x00 };
# ifndef HAVE_SWAB
u16 i;
# endif
#endif
u16 i_length = p_in_buf->i_nb_samples;
u16 * pi_length;
......
......@@ -2,7 +2,7 @@
* fixed32float32.c : converter from fixed32 to float32 bits integer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: fixed32tofloat32.c,v 1.5 2002/08/19 21:31:11 massiot Exp $
* $Id: fixed32tofloat32.c,v 1.6 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Jean-Paul Saman <jpsaman@wxs.nl>
*
......@@ -44,7 +44,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for fixed32->float32 conversion") );
set_description( _("audio filter for fixed32->float32 conversion") );
set_capability( "audio filter", 10 );
set_callbacks( Create, NULL );
vlc_module_end();
......@@ -105,6 +105,8 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
#endif
/* combined conversion */
/* This has absolutely no chance of working. *p_in is s32, gcc
* doesn't know anything of vlc_fixed_t... --Meuuh */
if ( *p_in >= 8 ) *p_out = (float) 1.0;
else if ( *p_in < -8 ) *p_out = (float) -1.0;
else *p_out =(float) (*p_in/8.0);
......@@ -113,5 +115,6 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
}
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;
}
......@@ -2,7 +2,7 @@
* fixed32tos16.c : converter from fixed32 to signed 16 bits integer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: fixed32tos16.c,v 1.4 2002/08/19 21:31:11 massiot Exp $
* $Id: fixed32tos16.c,v 1.5 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Jean-Paul Saman <jpsaman@wxs.nl>
*
......@@ -44,7 +44,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for fixed32->s16 conversion") );
set_description( _("audio filter for fixed32->s16 conversion") );
set_capability( "audio filter", 10 );
set_callbacks( Create, NULL );
vlc_module_end();
......@@ -216,4 +216,5 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
// p_in++; p_out++;
}
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes / 2;
}
......@@ -2,7 +2,7 @@
* float32tos16.c : converter from float32 to signed 16 bits integer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: float32tos16.c,v 1.8 2002/08/19 21:31:11 massiot Exp $
* $Id: float32tos16.c,v 1.9 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -44,15 +44,13 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for float32->s16 conversion") );
set_description( _("audio filter for float32->s16 conversion") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
/*****************************************************************************
* Create: allocate trivial mixer
*****************************************************************************
* This function allocates and initializes a Crop vout method.
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
......@@ -88,7 +86,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
for ( i = p_in_buf->i_nb_samples * p_filter->input.i_channels ; i-- ; )
{
#if 0
/* Slow version */
/* Slow version. */
if ( *p_in >= 1.0 ) *p_out = 32767;
else if ( *p_in < -1.0 ) *p_out = -32768;
else *p_out = *p_in * 32768.0;
......
......@@ -2,7 +2,7 @@
* float32tos8.c : converter from float32 to signed 8 bits integer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: float32tos8.c,v 1.3 2002/08/19 21:31:11 massiot Exp $
* $Id: float32tos8.c,v 1.4 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Xavier Maillard <zedek@fxgsproject.org>
*
......@@ -44,7 +44,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for float32->s8 conversion") );
set_description( _("audio filter for float32->s8 conversion") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
......
......@@ -2,7 +2,7 @@
* float32tou16.c : converter from float32 to unsigned 16 bits integer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: float32tou16.c,v 1.3 2002/08/19 21:31:11 massiot Exp $
* $Id: float32tou16.c,v 1.4 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Xavier Maillard <zedek@fxgsproject.org>
*
......@@ -44,7 +44,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for float32->u16 conversion") );
set_description( _("audio filter for float32->u16 conversion") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
......
......@@ -2,7 +2,7 @@
* float32tou8.c : converter from float32 to unsigned 8 bits integer
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: float32tou8.c,v 1.3 2002/08/19 21:31:11 massiot Exp $
* $Id: float32tou8.c,v 1.4 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Xavier Maillard <zedek@fxgsproject.org>
*
......@@ -44,7 +44,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for float32->u8 conversion") );
set_description( _("audio filter for float32->u8 conversion") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
......
......@@ -2,7 +2,7 @@
* s16tofloat32.c : converter from signed 16 bits integer to float32
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: s16tofloat32.c,v 1.1 2002/08/21 09:27:40 sam Exp $
* $Id: s16tofloat32.c,v 1.2 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -44,7 +44,7 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for s16->float32 conversion") );
set_description( _("audio filter for s16->float32 conversion") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
......
......@@ -2,7 +2,7 @@
* trivial.c : trivial resampler (skips samples or pads with zeroes)
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: trivial.c,v 1.3 2002/08/12 22:12:50 massiot Exp $
* $Id: trivial.c,v 1.4 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -44,22 +44,23 @@ static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("aout filter for trivial resampling") );
set_description( _("audio filter for trivial resampling") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
/*****************************************************************************
* Create: allocate trivial resampler
*****************************************************************************
* This function allocates and initializes a Crop vout method.
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
aout_filter_t * p_filter = (aout_filter_t *)p_this;
if ( p_filter->input.i_rate == p_filter->output.i_rate
|| p_filter->input.i_format != p_filter->output.i_format )
|| p_filter->input.i_format != p_filter->output.i_format
|| p_filter->input.i_channels != p_filter->output.i_channels
|| (p_filter->input.i_format != AOUT_FMT_FLOAT32
&& p_filter->input.i_format != AOUT_FMT_FIXED32) )
{
return -1;
}
......@@ -83,7 +84,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
if ( p_out_buf != p_in_buf )
{
/* For whatever reason the buffer allocator decided to allocate
* a new buffer. */
* a new buffer. Currently, this never happens. */
p_aout->p_vlc->pf_memcpy( p_out_buf->p_buffer, p_in_buf->p_buffer,
__MIN(i_out_nb, i_in_nb) );
}
......@@ -95,5 +96,6 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
}
p_out_buf->i_nb_samples = i_out_nb;
p_out_buf->i_nb_bytes = i_out_nb * sizeof(s32);
}
......@@ -2,7 +2,7 @@
* spdif.c : dummy mixer for S/PDIF output (1 input only)
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: spdif.c,v 1.4 2002/08/19 21:31:11 massiot Exp $
* $Id: spdif.c,v 1.5 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -45,7 +45,6 @@ static void DoWork ( aout_instance_t *, aout_buffer_t * );
vlc_module_begin();
set_description( _("dummy spdif audio mixer module") );
set_capability( "audio mixer", 1 );
add_shortcut( "spdif" );
set_callbacks( Create, NULL );
vlc_module_end();
......
......@@ -2,7 +2,7 @@
* trivial.c : trivial mixer plug-in (1 input, no downmixing)
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: trivial.c,v 1.5 2002/08/19 21:31:11 massiot Exp $
* $Id: trivial.c,v 1.6 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -43,9 +43,8 @@ static void DoWork ( aout_instance_t *, aout_buffer_t * );
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("trivial aout mixer module") );
set_description( _("trivial audio mixer module") );
set_capability( "audio mixer", 1 );
add_shortcut( "trivial" );
set_callbacks( Create, NULL );
vlc_module_end();
......@@ -67,34 +66,13 @@ static int Create( vlc_object_t *p_this )
return 0;
}
#if 0
/*****************************************************************************
* SparseCopy: trivially downmix or upmix a buffer
*****************************************************************************/
static void SparseCopy( u32 * p_dest, const u32 * p_src, size_t i_len,
int i_output_stride, int i_input_stride )
{
int i;
for ( i = 0; i < i_len; i++ )
{
int j;
for ( j = 0; j < i_output_stride; j++ )
{
p_dest[j] = p_src[j];
}
p_src += i_input_stride;
p_dest += i_output_stride;
}
}
#endif
/*****************************************************************************
* DoWork: mix a new output buffer
*****************************************************************************/
static void DoWork( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
{
aout_input_t * p_input = p_aout->pp_inputs[0];
int i_nb_bytes = p_buffer->i_nb_samples * sizeof(u32)
int i_nb_bytes = p_buffer->i_nb_samples * sizeof(s32)
* p_aout->mixer.mixer.i_channels;
byte_t * p_in = p_input->p_first_byte_to_mix;
byte_t * p_out = p_buffer->p_buffer;
......@@ -104,7 +82,7 @@ static void DoWork( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
ptrdiff_t i_available_bytes = (p_input->fifo.p_first->p_buffer
- p_in)
+ p_input->fifo.p_first->i_nb_samples
* sizeof(u32)
* sizeof(s32)
* p_aout->mixer.mixer.i_channels;
if ( i_available_bytes < i_nb_bytes )
......
......@@ -2,7 +2,7 @@
* sdl.c : SDL audio output plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2002 VideoLAN
* $Id: sdl.c,v 1.3 2002/08/19 21:31:11 massiot Exp $
* $Id: sdl.c,v 1.4 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -150,7 +150,7 @@ static void SDLCallback( void * _p_aout, byte_t * p_stream, int i_len )
{
aout_instance_t * p_aout = (aout_instance_t *)_p_aout;
/* FIXME : take into account SDL latency instead of mdate() */
aout_buffer_t * p_buffer = aout_OutputNextBuffer( p_aout, mdate(), 0 );
aout_buffer_t * p_buffer = aout_OutputNextBuffer( p_aout, mdate(), 1 );
if ( i_len != FRAME_SIZE * sizeof(s16)
* p_aout->output.output.i_channels )
......
......@@ -4,7 +4,7 @@
* (http://liba52.sf.net/).
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: a52.c,v 1.5 2002/08/19 21:31:11 massiot Exp $
* $Id: a52.c,v 1.6 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Christophe Massiot <massiot@via.ecp.fr>
......@@ -77,7 +77,7 @@ typedef struct a52_thread_s
aout_instance_t * p_aout; /* opaque */
aout_input_t * p_aout_input; /* opaque */
audio_sample_format_t output_format;
mtime_t last_date;
audio_date_t end_date;
} a52_thread_t;
/*****************************************************************************
......@@ -195,6 +195,7 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
{
p_dec->output_format.i_rate = i_rate;
/* p_dec->output_format.i_channels = i_channels; */
aout_DateInit( &p_dec->end_date, i_rate );
p_dec->p_aout_input = aout_InputNew( p_dec->p_fifo,
&p_dec->p_aout,
&p_dec->output_format );
......@@ -208,9 +209,9 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
/* Set the Presentation Time Stamp */
CurrentPTS( &p_dec->bit_stream, &pts, NULL );
if ( pts != 0 )
if ( pts != 0 && pts != aout_DateGet( &p_dec->end_date ) )
{
p_dec->last_date = pts;
aout_DateSet( &p_dec->end_date, pts );
}
/* Get the complete frame */
......@@ -248,7 +249,6 @@ static int InitThread( a52_thread_t * p_dec, decoder_fifo_t * p_fifo )
p_dec->p_fifo = p_fifo;
p_dec->output_format.i_format = AOUT_FMT_FLOAT32;
p_dec->output_format.i_channels = 2; /* FIXME ! */
p_dec->last_date = 0;
/* Initialize liba52 */
p_dec->p_a52_state = a52_init( 0 );
......@@ -294,7 +294,7 @@ static int DecodeFrame( a52_thread_t * p_dec, byte_t * p_frame_buffer )
int i_bytes_per_block = 256 * p_dec->output_format.i_channels
* sizeof(float);
if( !p_dec->last_date )
if( !aout_DateGet( &p_dec->end_date ) )
{
/* We've just started the stream, wait for the first PTS. */
return 0;
......@@ -303,10 +303,9 @@ static int DecodeFrame( a52_thread_t * p_dec, byte_t * p_frame_buffer )
p_buffer = aout_BufferNew( p_dec->p_aout, p_dec->p_aout_input,
A52_FRAME_NB );
if ( p_buffer == NULL ) return -1;
p_buffer->start_date = p_dec->last_date;
p_dec->last_date += (mtime_t)A52_FRAME_NB * 1000000
/ p_dec->output_format.i_rate;
p_buffer->end_date = p_dec->last_date;
p_buffer->start_date = aout_DateGet( &p_dec->end_date );
p_buffer->end_date = aout_DateIncrement( &p_dec->end_date,
A52_FRAME_NB );
/* FIXME */
i_flags = A52_STEREO | A52_ADJUST_LEVEL;
......
/*****************************************************************************
* audio_output.c : audio output instance
* audio_output.c : audio output instance miscellaneous functions
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: audio_output.c,v 1.98 2002/08/19 23:12:57 massiot Exp $
* $Id: audio_output.c,v 1.99 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -36,6 +36,10 @@
#include "audio_output.h"
#include "aout_internal.h"
/*
* Instances management (see also input.c:aout_InputNew())
*/
/*****************************************************************************
* aout_NewInstance: initialize aout structure
*****************************************************************************/
......@@ -77,6 +81,11 @@ void aout_DeleteInstance( aout_instance_t * p_aout )
vlc_object_destroy( p_aout );
}
/*
* Buffer management (interface to the decoders)
*/
/*****************************************************************************
* aout_BufferNew : ask for a new empty buffer
*****************************************************************************/
......@@ -142,6 +151,11 @@ void aout_BufferPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_MixerRun( p_aout );
}
/*
* Formats management (internal)
*/
/*****************************************************************************
* aout_FormatPrepare : compute the number of bytes per frame & frame length
*****************************************************************************/
......@@ -183,3 +197,181 @@ void aout_FormatPrepare( audio_sample_format_t * p_format )
p_format->i_frame_length = 1;
}
/*
* FIFO management (internal) - please understand that solving race conditions
* is _your_ job, ie. in the audio output you should own the mixer lock
* before calling any of these functions.
*/
/*****************************************************************************
* aout_FifoInit : initialize the members of a FIFO
*****************************************************************************/
void aout_FifoInit( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
u32 i_rate )
{
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
aout_DateInit( &p_fifo->end_date, i_rate );
}
/*****************************************************************************
* aout_FifoPush : push a packet into the FIFO
*****************************************************************************/
void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
aout_buffer_t * p_buffer )
{
*p_fifo->pp_last = p_buffer;
p_fifo->pp_last = &p_buffer->p_next;
*p_fifo->pp_last = NULL;
/* Enforce the continuity of the stream. */
if ( aout_DateGet( &p_fifo->end_date ) )
{
p_buffer->start_date = aout_DateGet( &p_fifo->end_date );
p_buffer->end_date = aout_DateIncrement( &p_fifo->end_date,
p_buffer->i_nb_samples );
}
else
{
aout_DateSet( &p_fifo->end_date, p_buffer->end_date );
}
}
/*****************************************************************************
* aout_FifoSet : set end_date and trash all buffers (because they aren't
* properly dated)
*****************************************************************************/
void aout_FifoSet( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
mtime_t date )
{
aout_buffer_t * p_buffer;
aout_DateSet( &p_fifo->end_date, date );
p_buffer = p_fifo->p_first;
while ( p_buffer != NULL )
{
aout_buffer_t * p_next = p_buffer->p_next;
aout_BufferFree( p_buffer );
p_buffer = p_next;
}
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
}
/*****************************************************************************
* aout_FifoMoveDates : Move forwards or backwards all dates in the FIFO
*****************************************************************************/
void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
mtime_t difference )
{
aout_buffer_t * p_buffer;
aout_DateMove( &p_fifo->end_date, difference );
p_buffer = p_fifo->p_first;
while ( p_buffer != NULL )
{
p_buffer->start_date += difference;
p_buffer->end_date += difference;
p_buffer = p_buffer->p_next;
}
}
/*****************************************************************************
* aout_FifoNextStart : return the current end_date
*****************************************************************************/
mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
{
return aout_DateGet( &p_fifo->end_date );
}
/*****************************************************************************
* aout_FifoPop : get the next buffer out of the FIFO
*****************************************************************************/
aout_buffer_t * aout_FifoPop( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
{
aout_buffer_t * p_buffer;
p_buffer = p_fifo->p_first;
if ( p_buffer == NULL ) return NULL;
p_fifo->p_first = p_buffer->p_next;
if ( p_fifo->p_first == NULL )
{
p_fifo->pp_last = &p_fifo->p_first;
}
return p_buffer;
}
/*****************************************************************************
* aout_FifoDestroy : destroy a FIFO and its buffers
*****************************************************************************/
void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
{
aout_buffer_t * p_buffer;
p_buffer = p_fifo->p_first;
while ( p_buffer != NULL )
{
aout_buffer_t * p_next = p_buffer->p_next;
aout_BufferFree( p_buffer );
p_buffer = p_next;
}
}
/*
* Date management (internal and external)
*/
/*****************************************************************************
* aout_DateInit : set the divider of an audio_date_t
*****************************************************************************/
void aout_DateInit( audio_date_t * p_date, u32 i_divider )
{
p_date->date = 0;
p_date->i_divider = i_divider;
p_date->i_remainder = 0;
}
/*****************************************************************************
* aout_DateSet : set the date of an audio_date_t
*****************************************************************************/
void aout_DateSet( audio_date_t * p_date, mtime_t new_date )
{
p_date->date = new_date;
p_date->i_remainder = 0;
}
/*****************************************************************************
* aout_DateMove : move forwards or backwards the date of an audio_date_t
*****************************************************************************/
void aout_DateMove( audio_date_t * p_date, mtime_t difference )
{
p_date->date += difference;
}
/*****************************************************************************
* aout_DateGet : get the date of an audio_date_t
*****************************************************************************/
mtime_t aout_DateGet( const audio_date_t * p_date )
{
return p_date->date;
}
/*****************************************************************************
* aout_DateIncrement : increment the date and return the result, taking
* into account rounding errors
*****************************************************************************/
mtime_t aout_DateIncrement( audio_date_t * p_date, u32 i_nb_samples )
{
mtime_t i_dividend = (mtime_t)i_nb_samples * 1000000;
p_date->date += i_dividend / p_date->i_divider;
p_date->i_remainder += i_dividend % p_date->i_divider;
if ( p_date->i_remainder >= p_date->i_divider )
{
/* This is Bresenham algorithm. */
p_date->date++;
p_date->i_remainder -= p_date->i_divider;
}
return p_date->date;
}
......@@ -2,7 +2,7 @@
* input.c : internal management of input streams for the audio output
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: input.c,v 1.6 2002/08/19 23:12:57 massiot Exp $
* $Id: input.c,v 1.7 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -63,7 +63,7 @@ static aout_input_t * InputNew( aout_instance_t * p_aout,
aout_FormatPrepare( &p_input->input );
/* Prepare FIFO. */
aout_FifoInit( p_aout, &p_input->fifo );
aout_FifoInit( p_aout, &p_input->fifo, p_aout->mixer.mixer.i_rate );
p_input->p_first_byte_to_mix = NULL;
/* Create filters. */
......@@ -220,8 +220,8 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
vlc_mutex_unlock( &p_aout->input_lock );
/* We don't care if someone changes the start date behind our back after
* aout_FifoNextStart. aout_FifoPush will deal with that, and we will
* compensate with the next incoming buffer. */
* this. We'll deal with that when pushing the buffer, and compensate
* with the next incoming buffer. */
start_date = aout_FifoNextStart( p_aout, &p_input->fifo );
if ( start_date != 0 && start_date < mdate() )
......@@ -237,7 +237,7 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
start_date = 0;
}
if ( p_buffer->start_date < mdate() )
if ( p_buffer->start_date < mdate() - AOUT_MIN_PREPARE_TIME )
{
/* The decoder gives us f*cked up PTS. It's its business, but we
* can't present it anyway, so drop the buffer. */
......@@ -268,6 +268,7 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
int i_ratio, i_nb_filters;
mtime_t old_duration;
aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
aout_buffer_t * p_new_buffer;
aout_alloc_t dummy_alloc;
mtime_t drift = p_buffer->start_date - start_date;
......@@ -280,15 +281,15 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
duration = p_buffer->end_date - start_date;
i_ratio = duration * 100 / old_duration;
/* If the ratio is too != 100, the sound quality will be awful. */
if ( i_ratio < 90 /* % */ )
if ( i_ratio < 66 /* % */ )
{
duration = old_duration * 90 / 100;
duration = old_duration * 66 / 100;
}
if ( i_ratio > 110 /* % */ )
if ( i_ratio > 150 /* % */ )
{
duration = old_duration * 110 / 100;
duration = old_duration * 150 / 100;
}
new_output.i_rate = new_output.i_rate * old_duration / duration;
new_output.i_rate = new_output.i_rate * duration / old_duration;
if ( aout_FiltersCreatePipeline( p_aout, pp_filters,
&i_nb_filters, &p_input->input,
......@@ -311,6 +312,20 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
dummy_alloc.i_bytes_per_sec = -1;
aout_FiltersHintBuffers( p_aout, pp_filters, i_nb_filters,
&dummy_alloc );
dummy_alloc.i_bytes_per_sec = __MAX(
dummy_alloc.i_bytes_per_sec,
p_input->input.i_bytes_per_frame
* p_input->input.i_rate
/ p_input->input.i_frame_length );
dummy_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
aout_BufferAlloc( &dummy_alloc, old_duration, NULL, p_new_buffer );
memcpy( p_new_buffer->p_buffer, p_buffer->p_buffer,
p_buffer->i_nb_bytes );
p_new_buffer->i_nb_samples = p_buffer->i_nb_samples;
p_new_buffer->i_nb_bytes = p_buffer->i_nb_bytes;
aout_BufferFree( p_buffer );
p_buffer = p_new_buffer;
aout_FiltersPlay( p_aout, pp_filters, i_nb_filters,
&p_buffer );
......@@ -327,10 +342,10 @@ void aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
&p_buffer );
}
vlc_mutex_lock( &p_aout->mixer_lock );
/* Adding the start date will be managed by aout_FifoPush(). */
p_buffer->start_date = start_date;
p_buffer->end_date = start_date + duration;
vlc_mutex_lock( &p_aout->mixer_lock );
aout_FifoPush( p_aout, &p_input->fifo, p_buffer );
vlc_mutex_unlock( &p_aout->mixer_lock );
......
......@@ -2,7 +2,7 @@
* mixer.c : audio output mixing operations
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: mixer.c,v 1.8 2002/08/19 23:12:57 massiot Exp $
* $Id: mixer.c,v 1.9 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -66,10 +66,15 @@ static int MixBuffer( aout_instance_t * p_aout )
int i;
aout_buffer_t * p_output_buffer;
mtime_t start_date, end_date;
audio_date_t exact_start_date;
/* Retrieve the date of the next buffer. */
vlc_mutex_lock( &p_aout->mixer_lock );
start_date = aout_FifoNextStart( p_aout, &p_aout->output.fifo );
/* Retrieve the date of the next buffer. */
memcpy( &exact_start_date, &p_aout->output.fifo.end_date,
sizeof(audio_date_t) );
start_date = aout_DateGet( &exact_start_date );
if ( start_date != 0 && start_date < mdate() )
{
/* The output is _very_ late. This can only happen if the user
......@@ -77,7 +82,9 @@ static int MixBuffer( aout_instance_t * p_aout )
* happen :). */
msg_Warn( p_aout, "Output PTS is out of range (%lld), clearing out",
start_date );
start_date = p_aout->output.fifo.end_date = 0;
aout_FifoSet( p_aout, &p_aout->output.fifo, 0 );
aout_DateSet( &exact_start_date, 0 );
start_date = 0;
}
/* See if we have enough data to prepare a new buffer for the audio
......@@ -99,6 +106,7 @@ static int MixBuffer( aout_instance_t * p_aout )
if ( !start_date || start_date < p_buffer->start_date )
{
aout_DateSet( &exact_start_date, p_buffer->start_date );
start_date = p_buffer->start_date;
}
}
......@@ -110,8 +118,8 @@ static int MixBuffer( aout_instance_t * p_aout )
return -1;
}
}
end_date = start_date + (mtime_t)p_aout->output.i_nb_samples * 1000000
/ p_aout->output.output.i_rate;
aout_DateIncrement( &exact_start_date, p_aout->output.i_nb_samples );
end_date = aout_DateGet( &exact_start_date );
/* Check that start_date and end_date are available for all input
* streams. */
......@@ -163,13 +171,13 @@ static int MixBuffer( aout_instance_t * p_aout )
mixer_nb_bytes = p_input->p_first_byte_to_mix
- p_buffer->p_buffer;
if ( i_nb_bytes + p_aout->mixer.mixer.i_bytes_per_frame
< mixer_nb_bytes ||
i_nb_bytes - p_aout->mixer.mixer.i_bytes_per_frame
> mixer_nb_bytes )
if ( !((i_nb_bytes + p_aout->mixer.mixer.i_bytes_per_frame
> mixer_nb_bytes) &&
(i_nb_bytes < p_aout->mixer.mixer.i_bytes_per_frame
+ mixer_nb_bytes)) )
{
msg_Warn( p_aout,
"mixer start isn't output start (%ld)",
"mixer start isn't output start (%d)",
i_nb_bytes - mixer_nb_bytes );
/* Round to the nearest multiple */
......
......@@ -2,7 +2,7 @@
* output.c : internal management of output streams for the audio output
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: output.c,v 1.8 2002/08/19 23:12:57 massiot Exp $
* $Id: output.c,v 1.9 2002/08/21 22:41:59 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -42,9 +42,6 @@ int aout_OutputNew( aout_instance_t * p_aout,
int i_rate = config_GetInt( p_aout, "aout-rate" );
int i_channels = config_GetInt( p_aout, "aout-channels" );
/* Prepare FIFO. */
aout_FifoInit( p_aout, &p_aout->output.fifo );
p_aout->output.p_module = module_Need( p_aout, "audio output",
psz_name );
if ( psz_name != NULL ) free( psz_name );
......@@ -79,6 +76,9 @@ int aout_OutputNew( aout_instance_t * p_aout,
}
aout_FormatPrepare( &p_aout->output.output );
/* Prepare FIFO. */
aout_FifoInit( p_aout, &p_aout->output.fifo, p_aout->output.output.i_rate );
msg_Dbg( p_aout, "output format=%d rate=%d channels=%d",
p_aout->output.output.i_format, p_aout->output.output.i_rate,
p_aout->output.output.i_channels );
......@@ -149,10 +149,10 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
p_aout->output.i_nb_filters,
&p_buffer );
/* Please remember that we have the mixer_lock in this function. */
vlc_mutex_lock( &p_aout->mixer_lock );
aout_FifoPush( p_aout, &p_aout->output.fifo, p_buffer );
p_aout->output.pf_play( p_aout );
vlc_mutex_unlock( &p_aout->mixer_lock );
}
/*****************************************************************************
......@@ -160,7 +160,7 @@ void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
*****************************************************************************
* If b_can_sleek is 1, the aout core functions won't try to resample
* new buffers to catch up - that is we suppose that the output plug-in can
* do it by itself. S/PDIF outputs should always set b_can_sleek = 1.
* compensate it by itself. S/PDIF outputs should always set b_can_sleek = 1.
*****************************************************************************/
aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
mtime_t start_date ,
......@@ -171,10 +171,10 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
vlc_mutex_lock( &p_aout->mixer_lock );
p_buffer = p_aout->output.fifo.p_first;
while ( p_buffer != NULL && p_buffer->end_date < start_date )
while ( p_buffer != NULL && p_buffer->start_date < start_date )
{
msg_Dbg( p_aout, "audio output is too slow (%lld)",
start_date - p_buffer->end_date );
start_date - p_buffer->start_date );
p_buffer = p_buffer->p_next;
}
......@@ -183,7 +183,7 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
{
p_aout->output.fifo.pp_last = &p_aout->output.fifo.p_first;
/* Set date to 0, to allow the mixer to send a new buffer ASAP */
p_aout->output.fifo.end_date = 0;
aout_FifoSet( p_aout, &p_aout->output.fifo, 0 );
vlc_mutex_unlock( &p_aout->mixer_lock );
msg_Dbg( p_aout, "audio output is starving" );
return NULL;
......@@ -200,22 +200,26 @@ aout_buffer_t * aout_OutputNextBuffer( aout_instance_t * p_aout,
return NULL;
}
#if 0
if ( !b_can_sleek )
if ( !b_can_sleek &&
( (p_buffer->start_date - start_date > AOUT_PTS_TOLERANCE)
|| (start_date - p_buffer->start_date > AOUT_PTS_TOLERANCE) ) )
{
/* Try to compensate the drift by doing some resampling. */
int i;
mtime_t difference = p_buffer->start_date - start_date;
msg_Warn( p_aout, "output date isn't PTS date, resampling (%lld)",
difference );
/* Take the mixer lock because no input can be removed when the
* the mixer lock is taken. */
vlc_mutex_lock( &p_aout->output.fifo.lock );
for ( i = 0; i < p_input->i_nb_inputs; i++ )
/* Remember that we still own the mixer lock. */
for ( i = 0; i < p_aout->i_nb_inputs; i++ )
{
aout_input_t * p_input = p_aout->pp_inputs[i];
aout_fifo_t * p_fifo = &p_aout->pp_inputs[i]->fifo;
aout_FifoMoveDates( p_aout, p_fifo, difference );
}
vlc_mutex_lock( &p_aout->output.fifo.lock );
aout_FifoMoveDates( p_aout, &p_aout->output.fifo, difference );
}
#endif
p_aout->output.fifo.p_first = p_buffer->p_next;
if ( p_buffer->p_next == NULL )
......
......@@ -185,7 +185,11 @@ static const char * module_error( char *psz_buffer )
(p_symbols)->aout_BufferNew_inner = aout_BufferNew; \
(p_symbols)->aout_BufferDelete_inner = aout_BufferDelete; \
(p_symbols)->aout_BufferPlay_inner = aout_BufferPlay; \
(p_symbols)->aout_FormatPrepare_inner = aout_FormatPrepare; \
(p_symbols)->aout_DateInit_inner = aout_DateInit; \
(p_symbols)->aout_DateSet_inner = aout_DateSet; \
(p_symbols)->aout_DateMove_inner = aout_DateMove; \
(p_symbols)->aout_DateGet_inner = aout_DateGet; \
(p_symbols)->aout_DateIncrement_inner = aout_DateIncrement; \
(p_symbols)->__aout_InputNew_inner = __aout_InputNew; \
(p_symbols)->aout_InputDelete_inner = aout_InputDelete; \
(p_symbols)->__config_GetInt_inner = __config_GetInt; \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment