[pulseaudio-discuss] [PATCH v6 1/2] pipe-source: generate silence when no writers connected

Georg Chini georg at chini.tk
Fri Feb 16 12:20:48 UTC 2018


On 16.02.2018 12:35, Raman Shishniou wrote:
> On 02/16/2018 12:00 PM, Georg Chini wrote:
>> On 14.02.2018 23:16, Raman Shyshniou wrote:
>>> Currently the pipe-source does not produce any data if no
>>> writer is connected. This patch enable silence generator
>>> when last writer closed pipe. It will stop automatically
>>> when any data appears.
>>> ---
>> After my fixes to module-null-source, I think your logic is not yet
>> completely correct. I would propose to do it like that:
>>
>> In source_process_msg():
>>
>>            case PA_SOURCE_MESSAGE_GET_LATENCY:
>>                 current_latency = now - time stamp
>>                 if (u->corkfd < 0)
>>                     current_latency += data in pipe
>>
>>            case PA_SOURCE_MESSAGE_SET_STATE:
>>                 if (SUSPENDED or INIT -> IDLE || SUSPENDED or INIT -> RUNNING) {
>>                     get time stamp
>>                     u->starting = true
>>                 }
>>
>> In thread_func():
>>
>> close u->corkfd
>> u->corkfd = -1
>> u->starting = true
>>
>> timer_elapsed = false
>> revents = 0
>> get time stamp
>>
>> for (;;) {
>>      if (source is open) {
>>
>>          /* We have to wait at least one configured source latency before starting
>>           * to read data */
>>          if (revents & POLLIN && !u->starting) {
>>              read data from pipe
>>              if (u->corkfd >=0) {
>>                  close corkfd
>>                  u->corkfd = -1
>>             }
>>
>>          } else if (timer_elapsed && u->corkfd > 0)
>>              generate silence
>>
>>         if (data was read/generated) {
>>              post data
>>              time stamp += data written
>>         }
>>
>>         set timer absolute time stamp + configured (or fixed) source latency
>>     } else
>>         set timer disabled
>>
>>     run rtpoll
>>     get timer_elapsed
>>
>>      if (u->starting && timer_elapsed)
>>          u->starting = false
>>
>>     if (revents & POLLHUP) {
>>         open pipe for writing
>>         u->corkfd = write file descriptor
>>         revents = revents & ~POLLHUP
>>     }
>>
> Unfortunately not all platforms generate POLLHUP when writer closed a pipe:
> Moreover, some platforms generate POLLIN with or without POLLHUP
> https://www.greenend.org.uk/rjk/tech/poll.html
>
> So, the only correct way is try to read EOF (0) from pipe when POLLIN or POLLHUP in revents.

To me it looks like all relevant platforms set POLLHUP
(and maybe additionally POLLIN). So I would be fine with
a POLLHUP check, but if you think you have to take the
other platforms into account, I don't mind.

>
>
>>     error check
>> }
>>
>> You can also add a source_update_requested_latency_cb() like
>> in module-null-source and pass  PA_SOURCE_DYNAMIC_LATENCY
>> to pa_source_new() to make the latency configurable.
> The pipe-source can change latency only when it generating a silence.

I don't think so. Basically, what is done by the pseudo-code above
is to wait one latency and only then start reading. So you can specify
whatever latency you like, as long as the writer (not the pipe itself) is
able to buffer the data.




More information about the pulseaudio-discuss mailing list