[alsa-devel] zero appl_ptr reported
Hi Takashi,
I noticed that 'appl_ptr' is always 0 during playback, whether it be mplayer or aplay, T61 or DG45ID. Is this a bug?
% grep -r . /proc/asound/card0/pcm0p /proc/asound/card0/pcm0p/sub0/prealloc_max:32768 /proc/asound/card0/pcm0p/sub0/prealloc:64 /proc/asound/card0/pcm0p/sub0/status:state: RUNNING /proc/asound/card0/pcm0p/sub0/status:trigger_time: 260.550520867 /proc/asound/card0/pcm0p/sub0/status:tstamp : 264.361429403 /proc/asound/card0/pcm0p/sub0/status:delay : -182952 /proc/asound/card0/pcm0p/sub0/status:avail : 191144 /proc/asound/card0/pcm0p/sub0/status:avail_max : 191144 /proc/asound/card0/pcm0p/sub0/status:----- /proc/asound/card0/pcm0p/sub0/status:hw_ptr : 182952 /proc/asound/card0/pcm0p/sub0/status:appl_ptr : 0 /proc/asound/card0/pcm0p/sub0/sw_params:tstamp_mode: ENABLE /proc/asound/card0/pcm0p/sub0/sw_params:period_step: 1 /proc/asound/card0/pcm0p/sub0/sw_params:avail_min: 1024 /proc/asound/card0/pcm0p/sub0/sw_params:start_threshold: 1 /proc/asound/card0/pcm0p/sub0/sw_params:stop_threshold: 4611686018427387904 /proc/asound/card0/pcm0p/sub0/sw_params:silence_threshold: 0 /proc/asound/card0/pcm0p/sub0/sw_params:silence_size: 4611686018427387904 /proc/asound/card0/pcm0p/sub0/sw_params:boundary: 4611686018427387904 /proc/asound/card0/pcm0p/sub0/hw_params:access: MMAP_INTERLEAVED /proc/asound/card0/pcm0p/sub0/hw_params:format: S32_LE /proc/asound/card0/pcm0p/sub0/hw_params:subformat: STD /proc/asound/card0/pcm0p/sub0/hw_params:channels: 2 /proc/asound/card0/pcm0p/sub0/hw_params:rate: 48000 (48000/1) /proc/asound/card0/pcm0p/sub0/hw_params:period_size: 1024 /proc/asound/card0/pcm0p/sub0/hw_params:buffer_size: 8192 /proc/asound/card0/pcm0p/sub0/info:card: 0 /proc/asound/card0/pcm0p/sub0/info:device: 0 /proc/asound/card0/pcm0p/sub0/info:subdevice: 0 /proc/asound/card0/pcm0p/sub0/info:stream: PLAYBACK /proc/asound/card0/pcm0p/sub0/info:id: STAC92xx Analog /proc/asound/card0/pcm0p/sub0/info:name: STAC92xx Analog /proc/asound/card0/pcm0p/sub0/info:subname: subdevice #0 /proc/asound/card0/pcm0p/sub0/info:class: 0 /proc/asound/card0/pcm0p/sub0/info:subclass: 0 /proc/asound/card0/pcm0p/sub0/info:subdevices_count: 1 /proc/asound/card0/pcm0p/sub0/info:subdevices_avail: 0 /proc/asound/card0/pcm0p/xrun_debug:0 /proc/asound/card0/pcm0p/info:card: 0 /proc/asound/card0/pcm0p/info:device: 0 /proc/asound/card0/pcm0p/info:subdevice: 0 /proc/asound/card0/pcm0p/info:stream: PLAYBACK /proc/asound/card0/pcm0p/info:id: STAC92xx Analog /proc/asound/card0/pcm0p/info:name: STAC92xx Analog /proc/asound/card0/pcm0p/info:subname: subdevice #0 /proc/asound/card0/pcm0p/info:class: 0 /proc/asound/card0/pcm0p/info:subclass: 0 /proc/asound/card0/pcm0p/info:subdevices_count: 1 /proc/asound/card0/pcm0p/info:subdevices_avail: 0
Interestingly DG45ID HDMI audio playback does not have this problem:
/proc/asound/card0/pcm3p/sub0/prealloc_max:32768 /proc/asound/card0/pcm3p/sub0/prealloc:64 /proc/asound/card0/pcm3p/sub0/status:state: RUNNING /proc/asound/card0/pcm3p/sub0/status:trigger_time: 441.375970806 /proc/asound/card0/pcm3p/sub0/status:tstamp : 447.039903859 /proc/asound/card0/pcm3p/sub0/status:delay : 16096 /proc/asound/card0/pcm3p/sub0/status:avail : 288 /proc/asound/card0/pcm3p/sub0/status:avail_max : 288 /proc/asound/card0/pcm3p/sub0/status:----- /proc/asound/card0/pcm3p/sub0/status:hw_ptr : 249824 /proc/asound/card0/pcm3p/sub0/status:appl_ptr : 265920 /proc/asound/card0/pcm3p/sub0/sw_params:tstamp_mode: NONE /proc/asound/card0/pcm3p/sub0/sw_params:period_step: 1 /proc/asound/card0/pcm3p/sub0/sw_params:avail_min: 1024 /proc/asound/card0/pcm3p/sub0/sw_params:start_threshold: 1024 /proc/asound/card0/pcm3p/sub0/sw_params:stop_threshold: 4611686018427387904 /proc/asound/card0/pcm3p/sub0/sw_params:silence_threshold: 0 /proc/asound/card0/pcm3p/sub0/sw_params:silence_size: 4611686018427387904 /proc/asound/card0/pcm3p/sub0/sw_params:boundary: 4611686018427387904 /proc/asound/card0/pcm3p/sub0/hw_params:access: RW_INTERLEAVED /proc/asound/card0/pcm3p/sub0/hw_params:format: S16_LE /proc/asound/card0/pcm3p/sub0/hw_params:subformat: STD /proc/asound/card0/pcm3p/sub0/hw_params:channels: 2 /proc/asound/card0/pcm3p/sub0/hw_params:rate: 44100 (44100/1) /proc/asound/card0/pcm3p/sub0/hw_params:period_size: 1024 /proc/asound/card0/pcm3p/sub0/hw_params:buffer_size: 16384 /proc/asound/card0/pcm3p/sub0/info:card: 0 /proc/asound/card0/pcm3p/sub0/info:device: 3 /proc/asound/card0/pcm3p/sub0/info:subdevice: 0 /proc/asound/card0/pcm3p/sub0/info:stream: PLAYBACK /proc/asound/card0/pcm3p/sub0/info:id: INTEL HDMI /proc/asound/card0/pcm3p/sub0/info:name: INTEL HDMI /proc/asound/card0/pcm3p/sub0/info:subname: subdevice #0 /proc/asound/card0/pcm3p/sub0/info:class: 0 /proc/asound/card0/pcm3p/sub0/info:subclass: 0 /proc/asound/card0/pcm3p/sub0/info:subdevices_count: 1 /proc/asound/card0/pcm3p/sub0/info:subdevices_avail: 0 /proc/asound/card0/pcm3p/xrun_debug:0 /proc/asound/card0/pcm3p/info:card: 0 /proc/asound/card0/pcm3p/info:device: 3 /proc/asound/card0/pcm3p/info:subdevice: 0 /proc/asound/card0/pcm3p/info:stream: PLAYBACK /proc/asound/card0/pcm3p/info:id: INTEL HDMI /proc/asound/card0/pcm3p/info:name: INTEL HDMI /proc/asound/card0/pcm3p/info:subname: subdevice #0 /proc/asound/card0/pcm3p/info:class: 0 /proc/asound/card0/pcm3p/info:subclass: 0 /proc/asound/card0/pcm3p/info:subdevices_count: 1 /proc/asound/card0/pcm3p/info:subdevices_avail: 0
Thanks, Fengguang
At Thu, 19 Feb 2009 13:20:16 +0800, Wu Fengguang wrote:
Hi Takashi,
I noticed that 'appl_ptr' is always 0 during playback, whether it be mplayer or aplay, T61 or DG45ID. Is this a bug?
No, it's a feature. When you use dmix, the appl_ptr isn't updated in the driver side but the driver is running in a "free-wheel" mode. OTOH, if you use pulseaudio or use HDMI out, the device is opened in a normal mode, thus appl_ptr is handled in the driver side.
Takashi
% grep -r . /proc/asound/card0/pcm0p /proc/asound/card0/pcm0p/sub0/prealloc_max:32768 /proc/asound/card0/pcm0p/sub0/prealloc:64 /proc/asound/card0/pcm0p/sub0/status:state: RUNNING /proc/asound/card0/pcm0p/sub0/status:trigger_time: 260.550520867 /proc/asound/card0/pcm0p/sub0/status:tstamp : 264.361429403 /proc/asound/card0/pcm0p/sub0/status:delay : -182952 /proc/asound/card0/pcm0p/sub0/status:avail : 191144 /proc/asound/card0/pcm0p/sub0/status:avail_max : 191144 /proc/asound/card0/pcm0p/sub0/status:----- /proc/asound/card0/pcm0p/sub0/status:hw_ptr : 182952 /proc/asound/card0/pcm0p/sub0/status:appl_ptr : 0 /proc/asound/card0/pcm0p/sub0/sw_params:tstamp_mode: ENABLE /proc/asound/card0/pcm0p/sub0/sw_params:period_step: 1 /proc/asound/card0/pcm0p/sub0/sw_params:avail_min: 1024 /proc/asound/card0/pcm0p/sub0/sw_params:start_threshold: 1 /proc/asound/card0/pcm0p/sub0/sw_params:stop_threshold: 4611686018427387904 /proc/asound/card0/pcm0p/sub0/sw_params:silence_threshold: 0 /proc/asound/card0/pcm0p/sub0/sw_params:silence_size: 4611686018427387904 /proc/asound/card0/pcm0p/sub0/sw_params:boundary: 4611686018427387904 /proc/asound/card0/pcm0p/sub0/hw_params:access: MMAP_INTERLEAVED /proc/asound/card0/pcm0p/sub0/hw_params:format: S32_LE /proc/asound/card0/pcm0p/sub0/hw_params:subformat: STD /proc/asound/card0/pcm0p/sub0/hw_params:channels: 2 /proc/asound/card0/pcm0p/sub0/hw_params:rate: 48000 (48000/1) /proc/asound/card0/pcm0p/sub0/hw_params:period_size: 1024 /proc/asound/card0/pcm0p/sub0/hw_params:buffer_size: 8192 /proc/asound/card0/pcm0p/sub0/info:card: 0 /proc/asound/card0/pcm0p/sub0/info:device: 0 /proc/asound/card0/pcm0p/sub0/info:subdevice: 0 /proc/asound/card0/pcm0p/sub0/info:stream: PLAYBACK /proc/asound/card0/pcm0p/sub0/info:id: STAC92xx Analog /proc/asound/card0/pcm0p/sub0/info:name: STAC92xx Analog /proc/asound/card0/pcm0p/sub0/info:subname: subdevice #0 /proc/asound/card0/pcm0p/sub0/info:class: 0 /proc/asound/card0/pcm0p/sub0/info:subclass: 0 /proc/asound/card0/pcm0p/sub0/info:subdevices_count: 1 /proc/asound/card0/pcm0p/sub0/info:subdevices_avail: 0 /proc/asound/card0/pcm0p/xrun_debug:0 /proc/asound/card0/pcm0p/info:card: 0 /proc/asound/card0/pcm0p/info:device: 0 /proc/asound/card0/pcm0p/info:subdevice: 0 /proc/asound/card0/pcm0p/info:stream: PLAYBACK /proc/asound/card0/pcm0p/info:id: STAC92xx Analog /proc/asound/card0/pcm0p/info:name: STAC92xx Analog /proc/asound/card0/pcm0p/info:subname: subdevice #0 /proc/asound/card0/pcm0p/info:class: 0 /proc/asound/card0/pcm0p/info:subclass: 0 /proc/asound/card0/pcm0p/info:subdevices_count: 1 /proc/asound/card0/pcm0p/info:subdevices_avail: 0
Interestingly DG45ID HDMI audio playback does not have this problem:
/proc/asound/card0/pcm3p/sub0/prealloc_max:32768 /proc/asound/card0/pcm3p/sub0/prealloc:64 /proc/asound/card0/pcm3p/sub0/status:state: RUNNING /proc/asound/card0/pcm3p/sub0/status:trigger_time: 441.375970806 /proc/asound/card0/pcm3p/sub0/status:tstamp : 447.039903859 /proc/asound/card0/pcm3p/sub0/status:delay : 16096 /proc/asound/card0/pcm3p/sub0/status:avail : 288 /proc/asound/card0/pcm3p/sub0/status:avail_max : 288 /proc/asound/card0/pcm3p/sub0/status:----- /proc/asound/card0/pcm3p/sub0/status:hw_ptr : 249824 /proc/asound/card0/pcm3p/sub0/status:appl_ptr : 265920 /proc/asound/card0/pcm3p/sub0/sw_params:tstamp_mode: NONE /proc/asound/card0/pcm3p/sub0/sw_params:period_step: 1 /proc/asound/card0/pcm3p/sub0/sw_params:avail_min: 1024 /proc/asound/card0/pcm3p/sub0/sw_params:start_threshold: 1024 /proc/asound/card0/pcm3p/sub0/sw_params:stop_threshold: 4611686018427387904 /proc/asound/card0/pcm3p/sub0/sw_params:silence_threshold: 0 /proc/asound/card0/pcm3p/sub0/sw_params:silence_size: 4611686018427387904 /proc/asound/card0/pcm3p/sub0/sw_params:boundary: 4611686018427387904 /proc/asound/card0/pcm3p/sub0/hw_params:access: RW_INTERLEAVED /proc/asound/card0/pcm3p/sub0/hw_params:format: S16_LE /proc/asound/card0/pcm3p/sub0/hw_params:subformat: STD /proc/asound/card0/pcm3p/sub0/hw_params:channels: 2 /proc/asound/card0/pcm3p/sub0/hw_params:rate: 44100 (44100/1) /proc/asound/card0/pcm3p/sub0/hw_params:period_size: 1024 /proc/asound/card0/pcm3p/sub0/hw_params:buffer_size: 16384 /proc/asound/card0/pcm3p/sub0/info:card: 0 /proc/asound/card0/pcm3p/sub0/info:device: 3 /proc/asound/card0/pcm3p/sub0/info:subdevice: 0 /proc/asound/card0/pcm3p/sub0/info:stream: PLAYBACK /proc/asound/card0/pcm3p/sub0/info:id: INTEL HDMI /proc/asound/card0/pcm3p/sub0/info:name: INTEL HDMI /proc/asound/card0/pcm3p/sub0/info:subname: subdevice #0 /proc/asound/card0/pcm3p/sub0/info:class: 0 /proc/asound/card0/pcm3p/sub0/info:subclass: 0 /proc/asound/card0/pcm3p/sub0/info:subdevices_count: 1 /proc/asound/card0/pcm3p/sub0/info:subdevices_avail: 0 /proc/asound/card0/pcm3p/xrun_debug:0 /proc/asound/card0/pcm3p/info:card: 0 /proc/asound/card0/pcm3p/info:device: 3 /proc/asound/card0/pcm3p/info:subdevice: 0 /proc/asound/card0/pcm3p/info:stream: PLAYBACK /proc/asound/card0/pcm3p/info:id: INTEL HDMI /proc/asound/card0/pcm3p/info:name: INTEL HDMI /proc/asound/card0/pcm3p/info:subname: subdevice #0 /proc/asound/card0/pcm3p/info:class: 0 /proc/asound/card0/pcm3p/info:subclass: 0 /proc/asound/card0/pcm3p/info:subdevices_count: 1 /proc/asound/card0/pcm3p/info:subdevices_avail: 0
Thanks, Fengguang
On Thu, Feb 19, 2009 at 08:42:15AM +0200, Takashi Iwai wrote:
At Thu, 19 Feb 2009 13:20:16 +0800, Wu Fengguang wrote:
Hi Takashi,
I noticed that 'appl_ptr' is always 0 during playback, whether it be mplayer or aplay, T61 or DG45ID. Is this a bug?
No, it's a feature. When you use dmix, the appl_ptr isn't updated in the driver side but the driver is running in a "free-wheel" mode. OTOH, if you use pulseaudio or use HDMI out, the device is opened in a normal mode, thus appl_ptr is handled in the driver side.
Ah thanks. This dismissed my questions :)
The dmix plugin always returns error code or negative delay:
alsa-lib/src/pcm/pcm_dmix.c 477 static int snd_pcm_dmix_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) 478 { 479 snd_pcm_direct_t *dmix = pcm->private_data; 480 int err; 481 482 switch(dmix->state) { 483 case SNDRV_PCM_STATE_DRAINING: 484 case SNDRV_PCM_STATE_RUNNING: 485 err = snd_pcm_dmix_sync_ptr(pcm); 486 if (err < 0) 487 return err; 488 /* fallthru */ 489 case SNDRV_PCM_STATE_PREPARED: 490 case SNDRV_PCM_STATE_SUSPENDED: 491 case STATE_RUN_PENDING: 492 *delayp = snd_pcm_mmap_playback_hw_avail(pcm); 493 return 0; 494 case SNDRV_PCM_STATE_XRUN: 495 return -EPIPE; 496 case SNDRV_PCM_STATE_DISCONNECTED: 497 return -ENODEV; 498 default: 499 return -EBADFD; 500 } 501 }
That explains why mplayer always do snd_pcm_forward() after snd_pcm_delay():
snd_pcm_delay(0x122edc0, 0x7fff0c2201e0, 0x5f4ca4, 0, 0x11e1588) = 0 snd_pcm_forward(0x122edc0, 1756, 0xc0000000000026dc, 9948, 0x11e1588) = 0 snd_pcm_delay(0x122edc0, 0x7fff0c2201c0, 24000, 0x122da98, 0x11e1588) = 0 snd_pcm_forward(0x122edc0, 8, 0xc000000000002008, 8200, 0x11e1588) = 0x3ffffffffffff924
The mplayer get_delay() code reads:
MPlayer-1.0rc2/libao2/ao_alsa.c 869 /* delay in seconds between first and last sample in buffer */ 870 static float get_delay(void) 871 { 872 if (alsa_handler) { 873 snd_pcm_sframes_t delay; 874 875 if (snd_pcm_delay(alsa_handler, &delay) < 0) 876 return 0; 877 878 if (delay < 0) { 879 /* underrun - move the application pointer forward to catch up */ 880 #if SND_LIB_VERSION >= 0x000901 /* snd_pcm_forward() exists since 0.9.0rc8 */ 881 snd_pcm_forward(alsa_handler, -delay); 882 #endif 883 delay = 0; 884 } 885 return (float)delay / (float)ao_data.samplerate; 886 } else { 887 return(0); 888 } 889 }
Which is called in the following places:
3 mplayer.c playing_audio_pts 1601 audio_out->get_delay(); 4 mplayer.c fill_audio_out_buffers 1823 else if (audio_eof && mpctx->audio_out->get_delay() < .04) { 5 mplayer.c sleep_until_update 1841 float delay = mpctx->audio_out->get_delay(); 6 mplayer.c update_video 2026 float delay = playback_speed*mpctx->audio_out->get_delay();
It happen to not cause trouble because 1) in mplayer, the negative delay will be reset to 0 before being returned 2) in ALSA, snd_pcm_playback_forward() will do nothing if avail is negative
Thanks, Fengguang
participants (2)
-
Takashi Iwai
-
Wu Fengguang