pcm_meter.c issue at s16_update
Pavel Hofman
pavel.hofman at ivitera.com
Tue Jul 28 20:54:26 CEST 2020
Dne 28. 07. 20 v 20:04 Pavel Hofman napsal(a):
> Dne 28. 07. 20 v 19:04 Takashi Iwai napsal(a):
>> On Tue, 28 Jul 2020 18:46:00 +0200,
>> Pavel Hofman wrote:
>>>
>>>
>>>>
>>>> The debug around the event looks like this, suddenly meter->now drops down:
>>>>
>>>> s16_update 1: meter->now 2567498, s16->old 2566593, size 905
>>>> s16_update 1: meter->now 2568401, s16->old 2567498, size 903
>>>> s16_update 1: meter->now 20786, s16->old 20786, size 0
>>>> s16_update 1: meter->now 1065, s16->old 20786, size -19721
>>>> s16_update 1: meter->now 24839, s16->old 24838, size 1
>>>> s16_update 1: meter->now 701, s16->old 24839, size -24138
>>>> s16_update 1: meter->now 1253162, s16->old 701, size 1252461
>>>> s16_update 1: meter->now 1255148, s16->old 1253162, size 1986
>>>>
>>>> ..........
>>>>
>>>> s16_update 1: meter->now 11136, s16->old 10261, size 875
>>>> s16_update 1: meter->now 22525, s16->old 22524, size 1
>>>> s16_update 1: meter->now 963, s16->old 22525, size -21562
>>>> s16_update 1: meter->now 1270914, s16->old 963, size 1269951
>>>> s16_update 1: meter->now 1272917, s16->old 1270914, size 2003
>>>>
>>>
>>> I think the problem is that s16->old is not reset when status.appl_ptr
>>> is zeroed and starts running again. There is a call
>>>
>>> static void s16_reset(snd_pcm_scope_t *scope)
>>> {
>>> snd_pcm_scope_s16_t *s16 = scope->private_data;
>>> snd_pcm_meter_t *meter = s16->pcm->private_data;
>>> s16->old = meter->now;
>>> }
>>>
>>> but I do not know when this method is called and whether the meter->now
>>> is already assigned to the newly zeroed status.appl_ptr.
>>
>> Would adding atomic_add(&meter->reset, 1) in snd_pcm_meter_reset()
>> help?
>>
> Unfortunately not.
>
> s16_reset is called correctly, setting s16->old = meter->now; But at
> that time meter->now is still 22751, setting s16->old to the same value.
>
> s16_update 1: meter->now 22751, s16->old 22751, size 0
>
> However, in the next update call meter->now comes from the freshly
> started application pointer:
>
> s16_update 1: meter->now 839, s16->old 22751, size -21912
>
>
> Of course this helps:
>
> - if (size < 0)
> - size += spcm->boundary;
> + if (size < 0) {
> + size = meter->now;
> + s16->old = 0;
> + }
>
> But I understand this is not a solution because:
>
> * it will not work at reaching spcm->boundary (after thousands of hours?)
> * it will cause the same problem when the stream is rewound (which is
> the problem now too) - size will equal to large meter->now (length from
> the beginning of the stream minus the rewound = large number).
>
IMHO there are two cases of the [application pointer + delay] drop
compared to the previous run:
* stream start, rewinding => s16->old = meter->now; size =0, i.e.
skipping the samples to show
* wrapping at spcm->boundary => size += spcm->boundary, i.e. showing the
wrapped samples
Optionally the second case could be handled just like the first case by
resetting s16->old, assuming the boundary wrap occurs very infrequently.
Pavel.
More information about the Alsa-devel
mailing list