<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"> Thanks all,<br>
<br>
Finally I`m using this way to get the available frames:<br>
<br>
static int32_t audio_pcm_avail(ni_mediahal_audio_dev_type
type)<br>
{<br>
snd_pcm_sframes_t av1 = snd_pcm_avail(pcm);<br>
snd_pcm_uframes_t av2 = 0;<br>
snd_htimestamp_t ht;<br>
int err = snd_pcm_htimestamp(pcm, &av2, &ht);<br>
struct timespec t;<br>
clock_gettime(CLOCK_MONOTONIC, &t);<br>
int64_t curTime = (int64_t) (t.tv_sec) * 1000000000LL +
t.tv_nsec;<br>
int64_t alsaTime = (int64_t) (ht.tv_sec) * 1000000000LL +
ht.tv_nsec;<br>
//LOG_AUDIOIO("av1=%d, av2=%u, curTime=%lld, alsaTime=%lld
err=%d", av1, av2, curTime, alsaTime, err);<br>
double timeDiff = (double)(curTime - alsaTime) *
0.000000001;<br>
int32_t diffFrames = (int32_t)(timeDiff *
audio_dev_params[type].rate);<br>
//LOG_AUDIOIO("timeDiff=%g, frameDiff=%d, rate=%d",
timeDiff, diffFrames, audio_dev_params[type].rate);<br>
if (diffFrames >=
(int)audio_dev_params[type].period_size) {<br>
diffFrames = 0;<br>
}<br>
return av1 + diffFrames;<br>
}<br>
<br>
get the diff time of current time and alsa timestamp, than
caculate the diff frames with sample rate.<br>
<br>
<br>
在 2015年06月10日 19:42, Raymond Yau 写道:<br>
</div>
<blockquote
cite="mid:CAN8cciZCYOSxLjzNiHryQu3dzFtOmbdX5t_7bbTd1MkZHCFfHQ@mail.gmail.com"
type="cite">
<p><br>
>> ><br>
>> > >><br>
>> > >><br>
>> > >> ><br>
>> > >> > below is what the terminate shows
when running pcm_avail.c<br>
>> > >> ><br>
>> > >> > uid=0 gid=1007@nutshell:/ #
alsactl_test<br>
>> > >> > min_period_size: 8 frames, dir: 0<br>
>> > >> > Playback hwparams: FIFO size is 8<br>
>> > >> > Hardware PCM card 0
'rsnd-dai.0-dirana3.0' device 0 subdevice 0<br>
>> > >> > Its setup is:<br>
>> > >> > stream : PLAYBACK<br>
>> > >> > access : RW_INTERLEAVED<br>
>> > >> > format : S16_LE<br>
>> > >> > subformat : STD<br>
>> > >> > channels : 2<br>
>> > >> > rate : 48000<br>
>> > >> > exact rate : 48000 (48000/1)<br>
>> > >> > msbits : 16<br>
>> > >> > buffer_size : 4096<br>
>> > >> > period_size : 1024<br>
>> > >> > period_time : 21333<br>
>> > >> > tstamp_mode : NONE<br>
>> > >> > period_step : 1<br>
>> > >> > avail_min : 1024<br>
>> > >> > period_event : 0<br>
>> > >> > start_threshold : 1024<br>
>> > >> > stop_threshold : 4096<br>
>> > >> > silence_threshold: 0<br>
>> > >> > silence_size : 0<br>
>> > >> > boundary : 1073741824<br>
>> > >> > appl_ptr : 0<br>
>> > >> > hw_ptr : 0<br>
>> > >> > Playing silence<br>
>> > >> > Available: 0, loop iteration: 0<br>
>> > >> > Available: 1024, loop iteration:
1469<br>
>> > >> > Available: 2048, loop iteration:
5609<br>
>> > >> > Available: 3072, loop iteration:
9667<br>
>> > >> ><br>
>> > >> > All I got is just the 4 lines.<br>
>> > >><br>
>> > >> If your sound card only increment hw_ptr
only at interrupt occur, you<br>
>> > >> need to increase default_rewind_safeguard
from 256 bytes to your<br>
>> > >> selected period size<br>
>> > ><br>
>> > ><br>
>> > > No. PulseAudio, in timer-scheduling mode,
does not use periods at all. You need to change the driver so
that it reports SNDRV_PCM_INFO_BATCH, so that PulseAudio does
not try to use this mode.<br>
>> > ><br>
>> > ><br>
>> > >><br>
>> > >> This mean that your sound card won't
work with timer scheduling or<br>
>> > >> dynamic latency, you can only archieve
low latency by decrease period size<br>
>> > >> Why do pulseaudio enable timer scheduling
when most sound card use IRQ ?<br>
>> > ><br>
>> > ><br>
>> > > Because most broken sound cards driver
authors forget to report SNDRV_PCM_INFO_BATCH?<br>
>> ><br>
>> > Why pulseaudio rely on the flag if your program
can find out the granulatity ?<br>
>><br>
>> AFAIK, there isn't a way to figure out granularity.
Having this would be nice as we could be more intelligent about
our tsched behaviour.<br>
><br>
><br>
> There is not only no way to query granularity, in some
cases it is simply unknown. As for my approach (of measuring it
directly), I currently think (but do not insist) that it is not
suitable for inclusion into PulseAudio, because it is based on
using a silent "test sound", busy-looping and repeatedly
querying the position until it plays out. This would be
unreliable if there is an unrelated CPU usage spike, and I think
that busy-looping in general is not welcome.</p>
<p><a moz-do-not-send="true"
href="https://bugs.freedesktop.org/show_bug.cgi?id=86262#c19">https://bugs.freedesktop.org/show_bug.cgi?id=86262#c19</a></p>
<p>Seem hwptr of snd-usb-audio are not that bad around 240 to 288
frames (less than period size) but not as good as snd-hda-intel
32 frames or oxygen 8 frames <br>
</p>
<p>How accurate do pulseaudio need to use timer base scheduling ?</p>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
pulseaudio-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:pulseaudio-discuss@lists.freedesktop.org">pulseaudio-discuss@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss">http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss</a>
</pre>
</blockquote>
<br>
</body>
</html>