[PATCH v8] pipe-source: implement autosuspend option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/20/2018 07:02 PM, Georg Chini wrote:
> On 20.02.2018 16:38, Raman Shyshniou wrote:
>> Currently the pipe-source will remain running even if no
>> writer is connected and therefore no data is produced.
>> This patch adds the autosuspend=<bool> option to prevent this.
>> Source will stay suspended if no writer is connected.
>> This option is enabled by default.
>> ---
>>   src/modules/module-pipe-source.c | 279 +++++++++++++++++++++++++++++----------
>>   1 file changed, 212 insertions(+), 67 deletions(-)
>>

I think I need post a simple pseudo code of new thread loop because it
was completely rewritten. There are too many changes in one patch.
It can be difficult to see the whole picture of new main loop.

pollfd = NULL;
rtpoll_item = NULL;
chunk.length = 0; // length of pending data in chunk.memblock
chunk.memblock = pa_memblock_new(); // always allocated

for (;;) {

    /**************************************************
     * run rtpoll
     */
    if (chunk.length > 0) {
        /* we have a pending data */
        if (rtpoll_item) {
            /* stop polling pipe
             * the only way to be here:
             * source was just suspended */ 
            ... free rtpoll_item ...
            rtpoll_item = NULL;
        }
    } else {
        /* we have no pending data */
        if (rtpoll_item == NULL) {
            /* start polling pipe
             * the only way to be here:
             * source was just resumed */
            ... allocate rtpoll_item, get pollfd ...
            pollfd->events = POLLIN;
            pollfd->fd = u->fd;
        }
    }

    pa_rtpoll_run()

    ... check errors ...

    if (rtpoll_item) {
        /* we polled pipe */
        ... refresh pollfd ...
    } else
        /* we are waiting for source state changes */
        pollfd = NULL;

    /**************************************************
     * Read data
     */
    if (pollfd && pollfd->revents) {

        ... read data from pipe ...

        if (len > 0) {
            chunk.length = len;

            /* source is autosuspended? */
            if (u->corkfd >= 0) {
                ... send resume message ...
                close(u->corkfd);
                u->corkfd = -1;
            }
        }

        if (len == 0) {
            /* sourece not autosuspended? */
            if (u->corkfd < 0) {
                ... send suspend message ...
                u->corkfd = open(pipe, O_WRONLY);
            }
        }

        if (len < 0) {
            ... check read error ...
        }
    }

    /**************************************************
     * Post data
     */
    if (source is opened) {
        ... post data ...
        unref(chunk.memblock);
        chunk.memblock = pa_memblock_new();
        chunk.length = 0;
    }

    /* chunk.length can be greater than 0 only if we are suspended right now
     * we need to stop polling pipe and wait while state will be changed to RUNNING or IDLE
     * to post pending data */
}

I can convert all changes to patch series if you want.

--
Raman


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux