[vlc-devel] Audio stutters on embedded ARM device

Marco Lang marco.lang at gmx.net
Tue Jan 17 08:47:23 CET 2006


Hello all,
I am trying to bring up the VLC as pure audio player on an embedded device
with TI ARM OMAP 200 MHz processor. Its audio interface is proprietary with
currently only 8 kHz bandwidth. I wrote an audio output plug-in based on
OSS. But it does not work correctly. Mesaurements showed that aprox. only
the half of the necessary buffers are delivered to the audio out. So I tried
to run vlc with the rt-priority option. This ends with a system chrash when
vlc creates some pthreads with higher than 0 priority. I would be very
greatful for some helpfull hints because I do not have any further idea to
solve this problems.

Thank you very much for your support!
:-) Marco

Here are the detailed information for investigations:

The audio play function needs a fixed buffer size of 480 bytes (2
bytes/sample). During playing this buffer it blocks up to 30ms.

The audio-output plug-in
source:

/*****************************************************************************
 * Local prototypes

*****************************************************************************/
static int  Open         ( vlc_object_t * );
static void Close        ( vlc_object_t * );
static void Play         ( aout_instance_t * );
static int  WLSSThread   ( aout_instance_t *
);


/*****************************************************************************
 * Module descriptor

*****************************************************************************/
vlc_module_begin();
   set_shortname( "beatnik" );
   set_description( _("wlanhs audio output") );
   set_capability( "audio output", 50 );
   set_category( CAT_AUDIO );
   set_subcategory( SUBCAT_AUDIO_AOUT );
   set_callbacks( Open, Close
);
vlc_module_end();




/*****************************************************************************
 * Open: open an aRts socket

*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    aout_instance_t *p_aout = (aout_instance_t *)p_this;
    struct aout_sys_t * p_sys;
    int i_err;
    int i_nb_channels;


    // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: Open +\n");

    /* Allocate structure */
    p_sys = malloc( sizeof( aout_sys_t ) );
    if( p_sys == NULL )
    {
        msg_Err( p_aout, "out of memory" );
        return VLC_ENOMEM;
    }
    p_aout->output.p_sys = p_sys;

    p_aout->output.pf_play = Play;
    aout_VolumeSoftInit( p_aout );

    p_aout->output.output.i_format = AOUT_FMT_S16_NE;
    i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
    if ( i_nb_channels > 1 )
    {
        i_nb_channels = 1;
        p_aout->output.output.i_physical_channels =
            AOUT_CHAN_CENTER;
    }
	

        /* open audio socket */
	i_err=audio_play_open(PCM16_NB);
	if( i_err != 0 )
        {
           msg_Err( p_aout, "Open audio failed");
           free( p_sys );
           return VLC_EGENERIC;
        }

	p_sys->i_size=480;

       p_aout->output.i_nb_samples = p_sys->i_size / sizeof(uint16_t) /
i_nb_channels;

    // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: Open vlc_thread_create\n");
    fflush(stderr);
   
    /* Create OSS thread and wait for its readiness. */
    if( vlc_thread_create( p_aout, "aout", WLSSThread,
                           VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
    {
        msg_Err( p_aout, "cannot create WLSS thread (%s)", strerror(errno)
);
        free( p_sys );
        return VLC_ETHREAD;
    }

	
    // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: Open -\n");

    return
VLC_SUCCESS;
}

/*****************************************************************************
 * Play: nothing to do

*****************************************************************************/

static void Play( aout_instance_t *p_aout
)
{

}

/*****************************************************************************
 * Close: close the aRts socket

*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    aout_instance_t *p_aout = (aout_instance_t *)p_this;
    struct aout_sys_t * p_sys = p_aout->output.p_sys;

    // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: Close +\n");
  	
    p_aout->b_die = VLC_TRUE;
    vlc_thread_join( p_aout );
    p_aout->b_die = VLC_FALSE;

    audio_play_close();
	
    free( p_sys );

    // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: Close
-\n");
}



/*****************************************************************************
 * WLSSThread: asynchronous thread used to DMA the data to the device

*****************************************************************************/

static int WLSSThread( aout_instance_t * p_aout )
{
    int tst1 = 0;
    int tst2 = 0;
    int tst3 = 0;
    int tst4 = 0;
    int flag = 0;
    int samples = 0;
    int bytes_per_frame = 0;
    int frame_lenth = 0;
    int buffer_duration = 0;

          
    // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: WLSSThread +\n");

   mtime_t next_date = 0;

    while ( !p_aout->b_die )
    {
        aout_buffer_t * p_buffer = NULL;
        int i_tmp, i_size;
        byte_t * p_bytes;

        if( !next_date )
        {
           next_date = mdate();
        }
        else
        {
           mtime_t delay = next_date - mdate();
           if( delay > AOUT_PTS_TOLERANCE )
           {
              tst1++;
		          msleep( delay / 2 );
           }
        }

        while( !p_aout->b_die && ! ( p_buffer =
               aout_OutputNextBuffer( p_aout, next_date, VLC_TRUE ) ) )
       {
          msleep( 10 );
          next_date = mdate();
		      tst2++;
       }


	     if ( p_buffer != NULL )
       {
          p_bytes = p_buffer->p_buffer;
          i_size = p_buffer->i_nb_bytes;
          // This is theoretical ... we'll see next iteration whether
          // we're drifting
	        next_date += p_buffer->end_date - p_buffer->start_date;
	        tst3++;

          if (!flag)
	        {
	           flag++;
	           samples= p_aout->output.i_nb_samples;
	           bytes_per_frame=  p_aout->output.output.i_bytes_per_frame;
	           frame_lenth= p_aout->output.output.i_frame_length;
	           buffer_duration= p_buffer->end_date - p_buffer->start_date;
	        }

	      }
        else
        {
            i_size = 480;
            p_bytes = malloc( i_size );
            memset( p_bytes, 0, i_size );
            next_date = 0;
        }

        if (i_size!=480)
        {
           msg_Err( p_aout, "audio write failed: Wrong Buffersize %d
",i_size);
        }
        else
        {
           i_tmp=audio_play_data((short *)p_bytes, i_size);
           tst4++;
	         if( i_tmp < 0 )
           {
              msg_Err( p_aout, "audio write failed ");
           }
        }
 

        if ( p_buffer != NULL )
        {
            aout_BufferFree( p_buffer );
        }
        else
        {
            free( p_bytes );
        }
    }

        // ONLY TEST
    fprintf(stderr,"VLC: beatnik.c: WLSSThread -\n");
    fprintf(stderr,"tst1: %d,  tst2: %d,  tst3: %d, tst4: %d\n", tst1, tst2,
tst3, tst4);
    fprintf(stderr,"samples: %d,  bytes_per_frame: %d,  frame_lenth: %d,
buffer_duration: %d\n", samples, bytes_per_frame, frame_lenth,
buffer_duration);


    return VLC_SUCCESS;
}


-------------------------------------------------------------------------

Debug ouput (extended in threads.c) without rt-priority option:

vlc -vvv Trumpet1.wav --aout beatnik --aout-rate 8000
MLA orig06 VLC media player 0.8.4a Janu[00000001] main vlc debug: checking
builtin modules
[00000001] main vlc debug: checking plugin modules
[00000001] main vlc debug: loading plugins cache file
/root/.vlc/cache/plugins-04041e.dat
[00000001] main vlc warning: could not open plugins cache file
/root/.vlc/cache/plugins-04041e.dat for reading
[00000001] main vlc debug: recursively browsing `modules'
[00000001] main vlc debug: recursively browsing `/usr/local/lib/vlc'
[00000001] main vlc debug: recursively browsing `plugins'
[00000001] main vlc debug: module bank initialized, found 158 modules
[00000001] main vlc debug: opening config file /root/.vlc/vlcrc
[00000001] main vlc warning: config file /root/.vlc/vlcrc does not exist yet
[00000001] main vlc debug: CPU has capabilities 
[00000001] main vlc debug: looking for memcpy module: 1 candidate
[00000137] main module debug: using memcpy module "memcpy"
[00000194] main playlist debug: MLA:__vlc_thread_create() started,
*psz_file: src/playlist/playlist.c, psz_name: playlist, prio: 1 
[00000194] main playlist debug: MLA: pthread_create()+
[00000194] main playlist debug: MLA: pthread_create()-
[00000194] main playlist debug: MLA:  i_priority = 0
[00000194] main playlist debug: waiting for thread completion
[00000194] main playlist debug: thread 16386 (playlist) created at priority
0 (src/playlist/playlist.c:183)
[00000195] main private debug: MLA:__vlc_thread_create() started, *psz_file:
src/playlist/playlist.c, psz_name: preparser, prio: 1 
[00000195] main private debug: MLA: pthread_create()+
[00000195] main private debug: MLA: pthread_create()-
[00000195] main private debug: MLA:  i_priority = 0
[00000195] main private debug: waiting for thread completion
[00000195] main private debug: thread 32771 (preparser) created at priority
0 (src/playlist/playlist.c:205)
[00000196] main interface debug: looking for interface module: 1 candidate
[00000082] main module debug: using interface module "hotkeys"
[00000196] main interface debug: interface initialized
[00000196] main interface debug: MLA:__vlc_thread_create() started,
*psz_file: src/interface/interface.c, psz_name: interface, prio: 1 
[00000196] main interface debug: MLA: pthread_create()+
[00000196] main interface debug: MLA: pthread_create()-
[00000196] main interface debug: MLA:  i_priority = 0
[00000196] main interface debug: thread 49156 (interface) created at
priority 0 (src/interface/interface.c:211)
[00000194] main playlist debug: adding playlist item `Trumpet1.wav' (
Trumpet1.wav )
[00000197] main interface debug: looking for interface module: 1 candidate
Remote control interface initialized, `h' for help
[00000084] main module debug: using interface module "rc"
[00000197] main interface debug: interface initialized
[00000197] main interface debug: MLA:__vlc_thread_create() started,
*psz_file: src/interface/interface.c, psz_name: manager, prio: 1 
[00000197] main interface debug: MLA: pthread_create()+
[00000197] main interface debug: MLA: pthread_create()-
[00000197] main interface debug: MLA:  i_priority = 0
[00000197] main interface debug: thread 65541 (manager) created at priority
0 (src/interface/interface.c:196)
[00000194] main playlist debug: creating new input thread
[00000198] main input debug: MLA:__vlc_thread_create() started, *psz_file:
src/input/input.c, psz_name: input, prio: 20 
[00000198] main input debug: MLA: pthread_create()+
[00000198] main input debug: MLA: pthread_create()-
status change: ( New input: Trumpet1.wav )
[00000198] main input debug: MLA:  i_priority = 0
[00000198] main input debug: waiting for thread completion
[00000198] main input debug: `Trumpet1.wav' gives access `' demux `' path
`Trumpet1.wav'
[00000198] main input debug: thread 81926 (input) created at priority 0
(src/input/input.c:230)
[00000198] main input debug: creating demux: access='' demux=''
path='Trumpet1.wav'
[00000199] main demuxer debug: looking for access_demux module: 0 candidates
status change: ( audio volume: 256 )
status change: ( play state: 1 )
[00000199] main demuxer warning: no access_demux module matched "any"
[00000198] main input debug: creating access '' path='Trumpet1.wav'
[00000200] main access debug: looking for access2 module: 3 candidates
[00000200] access_file access debug: opening file `Trumpet1.wav'
[00000008] main module debug: using access2 module "access_file"
[00000201] main private debug: pre buffering
[00000201] main private debug: received first data for our buffer
[00000198] main input debug: creating demux: access='' demux=''
path='Trumpet1.wav'
[00000202] main demuxer debug: looking for demux2 module: 33 candidates
[00000202] wav demuxer debug: Chunk: fcc=`fmt ` size=16
[00000202] wav demuxer debug: format: 0x0001, fourcc: araw, channels: 1,
freq: 11025 Hz, bitrate: 10Ko/s, blockalign: 1, bits/samples: 8, extra size:

0
[00000202] wav demuxer debug: found Raw audio audio format
[00000202] wav demuxer debug: Chunk: fcc=`data` size=66068[00000198] main
input debug: selecting program id=0
[00000121] main module debug: using demux2 module "wav"
[00000203] main decoder debug: looking for decoder module: 15 candidates
[00000203] araw decoder debug: samplerate:11025Hz channels:1 bits/sample:8
[00000058] main module debug: using decoder module "araw"
[00000203] main decoder debug: MLA:__vlc_thread_create() started, *psz_file:
src/input/decoder.c, psz_name: decoder, prio: 10 
[00000203] main decoder debug: MLA: pthread_create()+
[00000203] main decoder debug: MLA: pthread_create()-
[00000203] main decoder debug: MLA:  i_priority = 0
[00000203] main decoder debug: thread 98311 (decoder) created at priority 0
(src/input/decoder.c:159)
[00000198] main input debug: `Trumpet1.wav' successfully opened
[00000203] main decoder debug: no aout present, spawning one
[00000204] main audio output debug: looking for audio output module: 3
candidates
VLC: beatnik.c: Open +
VLC: beatnik.c: Open vlc_thread_create
[00000204] main audio output debug: MLA:__vlc_thread_create() started,
*psz_file: beatnik.c, psz_name: aout, prio: 30 
[00000204] main audio output debug: MLA: pthread_create()+
VLC: beatnik.c: WLSSThread +
[00000204] main audio output debug: MLA: pthread_create()-
[00000204] main audio output debug: MLA:  i_priority = 0
[00000204] main audio output debug: thread 114696 (aout) created at priority
0 (beatnik.c:150)
VLC: beatnik.c: Open -
[00000053] main module debug: using audio output module "beatnik"
[00000204] main audio output debug: output 's16l' 8000 Hz Mono frame=1
samples/2 bytes
[00000204] main audio output debug: mixer 's16l' 8000 Hz Mono frame=1
samples/2 bytes
[00000204] main audio output debug: filter(s) 'fi32'->'s16l' 8000 Hz->8000
Hz Mono->Mono
[00000205] main private debug: looking for audio filter module: 22
candidates
[00000028] main module debug: using audio filter module "fixed32tos16"
[00000204] main audio output debug: found a filter for the whole conversion
[00000204] main audio output debug: looking for audio mixer module: 3
candidates
[00000051] main module debug: using audio mixer module "trivial_mixer"
[00000204] main audio output debug: input 'u8  ' 11025 Hz Mono frame=1
samples/1 bytes
[00000204] main audio output debug: filter(s) 'u8  '->'fi32' 11025 Hz->11025
Hz Mono->Mono
[00000206] main private debug: looking for audio filter module: 22
candidates
[00000046] main module debug: using audio filter module "u8tofixed32"
[00000204] main audio output debug: found a filter for the whole conversion
[00000204] main audio output debug: filter(s) 'fi32'->'fi32' 12127 Hz->8000
Hz Mono->Mono
[00000207] main private debug: looking for audio filter module: 22
candidates
[00000048] main module debug: using audio filter module "ugly_resampler"
[00000204] main audio output debug: found a filter for the whole conversion
[00000204] main audio output warning: PTS is out of range (135731), dropping
buffer
[00000204] main audio output warning: PTS is out of range (145411), dropping
buffer
[00000204] main audio output warning: PTS is out of range (102794), dropping
buffer
[00000204] main audio output warning: PTS is out of range (62396), dropping
buffer
[00000204] main audio output warning: PTS is out of range (23021), dropping
buffer
[00000204] main audio output warning: PTS is out of range (-13894), dropping
buffer
First answer timestamp = 708
[00000198] main input debug: EOF reached
[00000198] main input debug: waiting decoder fifos to empty
[00000198] main input debug: closing input
[00000121] main module debug: unlocking module "wav"
[00000008] main module debug: unlocking module "access_file"
[00000058] main module debug: unlocking module "araw"
[00000203] main decoder debug: thread 98311 joined (src/input/decoder.c:191)
[00000203] main decoder debug: killing decoder fourcc `araw', 0 PES in FIFO
[00000046] main module debug: unlocking module "u8tofixed32"
[00000048] main module debug: unlocking module "ugly_resampler"
VLC: beatnik.c: Close +
VLC: beatnik.c: WLSSThread -
tst1: 0,  tst2: 16,  tst3: 90, tst4: 90
samples: 240,  bytes_per_frame: 2,  frame_lenth: 1, buffer_duration: 30000
[00000204] main audio output debug: thread 114696 joined (beatnik.c:207)
VLC: beatnik.c: Close -
[00000053] main module debug: unlocking module "beatnik"
[00000028] main module debug: unlocking module "fixed32tos16"
[00000051] main module debug: unlocking module "trivial_mixer"
status change: ( stop state: 0 )
[00000198] main input debug: thread 81926 joined (src/input/input.c:386)
status change: ( stop state: 0 )
[00000194] main playlist: nothing to play


------------------------------------------------------------------------
Debug ouput (extended in threads.c) with rt-priority option:

vlc -vvv Trumpet1.wav --aout beatnik --aout-rate 8000 --rt-priority
MLA orig06 VLC media player 0.8.4a Janus
[00000001] main vlc debug: checking builtin modules
[00000001] main vlc debug: checking plugin modules
[00000001] main vlc debug: loading plugins cache file
/root/.vlc/cache/plugins-04041e.dat
[00000001] main vlc warning: could not open plugins cache file
/root/.vlc/cache/plugins-04041e.dat for reading
[00000001] main vlc debug: recursively browsing `modules'
[00000001] main vlc debug: recursively browsing `/usr/local/lib/vlc'
[00000001] main vlc debug: recursively browsing `plugins'
[00000001] main vlc debug: module bank initialized, found 158 modules
[00000001] main vlc debug: opening config file /root/.vlc/vlcrc
[00000001] main vlc warning: config file /root/.vlc/vlcrc does not exist yet
[00000001] main vlc debug: CPU has capabilities 
[00000001] main vlc debug: looking for memcpy module: 1 candidate
[00000137] main module debug: using memcpy module "memcpy"
[00000194] main playlist debug: MLA:__vlc_thread_create() started,
*psz_file: src/playlist/playlist.c, psz_name: playlist, prio: 1 
[00000194] main playlist debug: MLA: pthread_create()+
[00000194] main playlist debug: MLA: pthread_create()-
[00000194] main playlist debug: MLA:  prio_max= 99, prio_min= 1  
pthread_setschedparam()+
[00000194] main playlist debug: waiting for thread completion
[00000194] main playlist debug: thread 16386 (playlist) created at priority
1 (src/playlist/playlist.c:183)
[00000195] main private debug: MLA:__vlc_thread_create() started, *psz_file:
src/playlist/playlist.c, psz_name: preparser, prio: 1 
[00000195] main private debug: MLA: pthread_create()+
[00000195] main private debug: MLA: pthread_create()-
[00000195] main private debug: MLA:  prio_max= 99, prio_min= 1  
pthread_setschedparam()+
[00000195] main private debug: waiting for thread completion
[00000195] main private debug: thread 32771 (preparser) created at priority
1 (src/playlist/playlist.c:205)
[00000196] main interface debug: looking for interface module: 1 candidate
[00000082] main module debug: using interface module "hotkeys"
[00000196] main interface debug: interface initialized
[00000196] main interface debug: MLA:__vlc_thread_create() started,
*psz_file: src/interface/interface.c, psz_name: interface, prio: 1 
[00000196] main interface debug: MLA: pthread_create()+
[00000196] main interface debug: MLA: pthread_create()-
[00000196] main interface debug: MLA:  prio_max= 99, prio_min= 1  
pthread_setschedparam()+
[00000196] main interface debug: thread 49156 (interface) created at
priority 1 (src/interface/interface.c:211)
[00000194] main playlist debug: adding playlist item `Trumpet1.wav' (
Trumpet1.wav )
[00000197] main interface debug: looking for interface module: 1 candidate
Remote control interface initialized, `h' for help
[00000084] main module debug: using interface module "rc"
[00000197] main interface debug: interface initialized
[00000197] main interface debug: MLA:__vlc_thread_create() started,
*psz_file: src/interface/interface.c, psz_name: manager, prio: 1 
[00000197] main interface debug: MLA: pthread_create()+
[00000197] main interface debug: MLA: pthread_create()-
[00000197] main interface debug: MLA:  prio_max= 99, prio_min= 1  
pthread_setschedparam()+
[00000197] main interface debug: thread 65541 (manager) created at priority
1 (src/interface/interface.c:196)
[00000194] main playlist debug: creating new input thread
Connection closed by foreign host.
 
 

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner

-- 
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://developers.videolan.org/lists.html



More information about the vlc-devel mailing list