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.


>    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 hope I did not forget anything ...
_______________________________________________
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

Reply via email to