From 1714fe2990d5404b528822b324ca35cbd607a8c0 Mon Sep 17 00:00:00 2001 From: "Reynaldo H. Verdejo Pinochet" Date: Wed, 24 Jun 2015 17:41:06 -0300 Subject: ffserver: factor out stream params printing Signed-off-by: Reynaldo H. Verdejo Pinochet --- ffserver.c | 84 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 36 deletions(-) (limited to 'ffserver.c') diff --git a/ffserver.c b/ffserver.c index af1a445330..6b537b3304 100644 --- a/ffserver.c +++ b/ffserver.c @@ -209,6 +209,7 @@ static void close_connection(HTTPContext *c); /* HTTP handling */ static int handle_connection(HTTPContext *c); +static inline void print_stream_params(AVIOContext *pb, FFServerStream *stream); static void compute_status(HTTPContext *c); static int open_input_stream(HTTPContext *c, const char *info); static int http_parse_request(HTTPContext *c); @@ -1750,6 +1751,52 @@ static void fmt_bytecount(AVIOContext *pb, int64_t count) avio_printf(pb, "%"PRId64"%c", count, *s); } +static inline void print_stream_params(AVIOContext *pb, FFServerStream *stream) +{ + int i, stream_no; + const char *type = "unknown"; + char parameters[64]; + AVStream *st; + AVCodec *codec; + + stream_no = stream->nb_streams; + + avio_printf(pb, "
Stream" + "typekbits/scodec" + "Parameters\n"); + + for (i = 0; i < stream_no; i++) { + st = stream->streams[i]; + codec = avcodec_find_encoder(st->codec->codec_id); + + parameters[0] = 0; + + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: + type = "audio"; + snprintf(parameters, sizeof(parameters), "%d channel(s), %d Hz", + st->codec->channels, st->codec->sample_rate); + break; + case AVMEDIA_TYPE_VIDEO: + type = "video"; + snprintf(parameters, sizeof(parameters), + "%dx%d, q=%d-%d, fps=%d", st->codec->width, + st->codec->height, st->codec->qmin, st->codec->qmax, + st->codec->time_base.den / st->codec->time_base.num); + break; + default: + abort(); + } + + avio_printf(pb, "
%d%s%d" + "%s%s\n", + i, type, st->codec->bit_rate/1000, + codec ? codec->name : "", parameters); + } + + avio_printf(pb, "
\n"); +} + static void compute_status(HTTPContext *c) { HTTPContext *c1; @@ -1920,42 +1967,7 @@ static void compute_status(HTTPContext *c) avio_printf(pb, "

"); } - avio_printf(pb, "
Stream" - "typekbits/scodec" - "Parameters\n"); - - for (i = 0; i < stream->nb_streams; i++) { - AVStream *st = stream->streams[i]; - AVCodec *codec = avcodec_find_encoder(st->codec->codec_id); - const char *type = "unknown"; - char parameters[64]; - - parameters[0] = 0; - - switch(st->codec->codec_type) { - case AVMEDIA_TYPE_AUDIO: - type = "audio"; - snprintf(parameters, sizeof(parameters), "%d channel(s), %d Hz", - st->codec->channels, st->codec->sample_rate); - break; - case AVMEDIA_TYPE_VIDEO: - type = "video"; - snprintf(parameters, sizeof(parameters), - "%dx%d, q=%d-%d, fps=%d", st->codec->width, - st->codec->height, st->codec->qmin, st->codec->qmax, - st->codec->time_base.den / st->codec->time_base.num); - break; - default: - abort(); - } - - avio_printf(pb, "
%d%s%d" - "%s%s\n", - i, type, st->codec->bit_rate/1000, - codec ? codec->name : "", parameters); - } - - avio_printf(pb, "
\n"); + print_stream_params(pb, stream); stream = stream->next; } -- cgit v1.2.3