Re: [Bluez-devel] a2dpd and mplayer - any chance to get it working?

Robert Huitl
2007-01-17T18:05:53Z

On Wednesday 17 January 2007 08:03, Frederic Dalleau wrote:
> Robert,
> The sound is ok in mplayer! But the movie is a bit slow :D ...

Yes exactly :)
And then it prints that message about slow CPU, buggy sound drivers, etc.

> If you plugin is the pcm.!default, then you can workaround the problem by
> outputting audio to esound instead of alsa (see mplayer preferences). Not
> the best, but worked for me. +/- helped having perfect synchronisation with
> movie.

Nice. I will try this, but actually I'd rather not have another sound daemon
(artsd is causing enough problems...)

> Brad,
> I was wondering about alsa plugins :
> xmms relies on alsa timing to play, so in the plugin, there is a sleep()
> call, this will wait a little bit until it is time to retievre new data.
> But it seems some players (like mplayer) wants to do their own timing or at
> least don't want to sleep. They need to use that time to do some decoding
> instead. If you sleep too long, the decoding will be defered and the sound
> or movie will be broken.

You are talking about this code, aren't you?

static snd_pcm_sframes_t a2dp_transfer2(snd_pcm_ioplug_t * io, char *buf,
int32_t datatoread)
[...]
// The data are sent to the daemon that act as a proxy thus we double
transfer delay to compensate latency
a2dp_timer_notifyframe(&a2dp->TimerInfos);
delay = a2dp_timer_sleep(&a2dp->TimerInfos, 4*A2DPTIMERPREDELAY);

Without really knowing what I was doing, I removed the a2dp_timer_sleep call.
The result: mplayer plays the video as fast as possible (sound was broken, of
course).

So maybe this delay is too long (however decreasing the delay did not improve
things) or should not be there at all.

> Is there a rule to distinguish? Or some magic value to sleep?

I had a look at the io->nonblock variable and compared its value while playing
with mplayer and play (part of sox), but it's 0 for both.

However, mplayer audio output devices implement a function
/* delay in seconds between first and last sample in buffer */
static float get_delay(void)

This function basically calls snd_pcm_delay(), which can be implemented in the
a2dp io plugin. Mplayer calls this function quite frequently, maybe this is
how it knows when to write new audio samples.

Robert