[FFmpeg-devel] [PATCH 2/4] ffserver: Implement publisher

Michael Niedermayer michael at niedermayer.cc
Fri Apr 13 18:17:00 EEST 2018


On Thu, Apr 12, 2018 at 03:35:47PM +0200, Stephan Holljes wrote:
> ---
>  publisher.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  publisher.h | 134 +++++++++++++++++++++++++++++
>  2 files changed, 412 insertions(+)
>  create mode 100644 publisher.c
>  create mode 100644 publisher.h
> 
> diff --git a/publisher.c b/publisher.c
> new file mode 100644
> index 0000000..d1ccb95
> --- /dev/null
> +++ b/publisher.c
> @@ -0,0 +1,278 @@
> +#include "publisher.h"
> +#include "segment.h"
> +#include <libavutil/log.h>
> +
> +void client_log(struct Client *c)
> +{
> +    char state[64];
> +    sprintf("State: ", state);
> +    switch(c->state) {
> +    case FREE:
> +        sprintf(state, "FREE");
> +        break;
> +    case RESERVED:
> +        sprintf(state, "RESERVED");
> +        break;
> +    case WAIT:
> +        sprintf(state, "WAIT");
> +        break;
> +    case WRITABLE:
> +        sprintf(state, "WRITABLE");
> +        break;
> +    case BUSY:
> +        sprintf(state, "BUSY");
> +        break;
> +    case BUFFER_FULL:
> +        sprintf(state, "BUFFER_FULL");
> +        break;
> +    default:
> +        sprintf(state, "UNDEFINED");
> +        break;
> +    }
> +    av_log(NULL, AV_LOG_INFO, "%s\n", state);

const char *state = "UNDEFINED";
...
case WAIT:
    state = "WAIT"
...

av_log(..., "State: %s", state);

simpler, no buffer, no copy (which lacks buffer size checks)


[...]
> +void publisher_gen_status_json(struct PublisherContext *pub, char *status)
> +{
> +    int nb_free = 0, nb_reserved = 0, nb_wait = 0, nb_writable = 0, nb_busy = 0, nb_buffer_full = 0, current_read = 0, newest_write = 0, oldest_write = 0;
> +    int i;
> +    struct Client *c;
> +
> +    current_read = pub->current_segment_id;
> +    oldest_write = current_read;
> +
> +    for (i = 0; i < MAX_CLIENTS; i++) {
> +        c = &pub->clients[i];
> +        if (c->current_segment_id > 0 && c->current_segment_id < oldest_write) {
> +            oldest_write = c->current_segment_id;
> +        }
> +        if (c->current_segment_id > newest_write) {
> +            newest_write = c->current_segment_id;
> +        }
> +
> +        switch(c->state) {
> +        case FREE:
> +            nb_free++;
> +            continue;
> +        case RESERVED:
> +            nb_reserved++;
> +            continue;
> +        case WAIT:
> +            nb_wait++;
> +            continue;
> +        case WRITABLE:
> +            nb_writable++;
> +            continue;
> +        case BUSY:
> +            nb_busy++;
> +            continue;
> +        case BUFFER_FULL:
> +            nb_buffer_full++;
> +            continue;
> +        default:
> +            continue;
> +        }
> +    }

you can simplify this substantially:

int nb_table[STATE_NB] = {0};

...
for()
    nb_table[c->state]++;

[..]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180413/f8bdce10/attachment.sig>


More information about the ffmpeg-devel mailing list