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
   }

   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.

I hope I did not forget anything ...
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

Reply via email to