[pulseaudio-discuss] [PATCH v6 1/2] pipe-source: generate silence when no writers connected
Raman Shishniou
rommer at ibuffed.com
Fri Feb 16 16:37:47 UTC 2018
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
> }
>
> 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 ...
The incoming data can has a sample rate that differs from the system clock.
For example, due to imperfect hardware oscillator. It's a bad idea to expect
a data at the system clock rate. When the source is receiving a real data from
pipe the timer should be disabled and u->timestamp and u->starting doesn't make sense.
More information about the pulseaudio-discuss
mailing list