From d9d86e00b2891a2651fd41f0d2d220a67f7968c3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 14 Mar 2011 20:39:02 +0100 Subject: [PATCH] avio: avio_ prefix for url_fprintf Signed-off-by: Ronald S. Bultje --- ffserver.c | 126 ++++++++++++++++++++-------------------- libavformat/avio.h | 9 ++- libavformat/aviobuf.c | 14 ++++- libavformat/ffmetaenc.c | 6 +- 4 files changed, 86 insertions(+), 69 deletions(-) diff --git a/ffserver.c b/ffserver.c index e5c4ac23d8..0dccbd1388 100644 --- a/ffserver.c +++ b/ffserver.c @@ -1861,7 +1861,7 @@ static void fmt_bytecount(AVIOContext *pb, int64_t count) for (s = suffix; count >= 100000 && s[1]; count /= 1000, s++); - url_fprintf(pb, "%"PRId64"%c", count, *s); + avio_printf(pb, "%"PRId64"%c", count, *s); } static void compute_status(HTTPContext *c) @@ -1880,20 +1880,20 @@ static void compute_status(HTTPContext *c) return; } - url_fprintf(pb, "HTTP/1.0 200 OK\r\n"); - url_fprintf(pb, "Content-type: %s\r\n", "text/html"); - url_fprintf(pb, "Pragma: no-cache\r\n"); - url_fprintf(pb, "\r\n"); + avio_printf(pb, "HTTP/1.0 200 OK\r\n"); + avio_printf(pb, "Content-type: %s\r\n", "text/html"); + avio_printf(pb, "Pragma: no-cache\r\n"); + avio_printf(pb, "\r\n"); - url_fprintf(pb, "%s Status\n", program_name); + avio_printf(pb, "%s Status\n", program_name); if (c->stream->feed_filename[0]) - url_fprintf(pb, "\n", c->stream->feed_filename); - url_fprintf(pb, "\n"); - url_fprintf(pb, "

%s Status

\n", program_name); + avio_printf(pb, "\n", c->stream->feed_filename); + avio_printf(pb, "\n"); + avio_printf(pb, "

%s Status

\n", program_name); /* format status */ - url_fprintf(pb, "

Available Streams

\n"); - url_fprintf(pb, "\n"); - url_fprintf(pb, "
PathServed
Conns

bytes
FormatBit rate
kbits/s
Video
kbits/s

Codec
Audio
kbits/s

Codec
Feed\n"); + avio_printf(pb, "

Available Streams

\n"); + avio_printf(pb, "\n"); + avio_printf(pb, "
PathServed
Conns

bytes
FormatBit rate
kbits/s
Video
kbits/s

Codec
Audio
kbits/s

Codec
Feed\n"); stream = first_stream; while (stream != NULL) { char sfilename[1024]; @@ -1921,9 +1921,9 @@ static void compute_status(HTTPContext *c) } } - url_fprintf(pb, "
%s ", + avio_printf(pb, "
%s ", sfilename, stream->filename); - url_fprintf(pb, " %d ", + avio_printf(pb, " %d ", stream->conns_served); fmt_bytecount(pb, stream->bytes_served); switch(stream->stream_type) { @@ -1962,33 +1962,33 @@ static void compute_status(HTTPContext *c) abort(); } } - url_fprintf(pb, " %s %d %d %s %s %d %s %s", + avio_printf(pb, " %s %d %d %s %s %d %s %s", stream->fmt->name, stream->bandwidth, video_bit_rate / 1000, video_codec_name, video_codec_name_extra, audio_bit_rate / 1000, audio_codec_name, audio_codec_name_extra); if (stream->feed) - url_fprintf(pb, "%s", stream->feed->filename); + avio_printf(pb, "%s", stream->feed->filename); else - url_fprintf(pb, "%s", stream->feed_filename); - url_fprintf(pb, "\n"); + avio_printf(pb, "%s", stream->feed_filename); + avio_printf(pb, "\n"); } break; default: - url_fprintf(pb, " - - - - \n"); + avio_printf(pb, " - - - - \n"); break; } } stream = stream->next; } - url_fprintf(pb, "
\n"); + avio_printf(pb, "
\n"); stream = first_stream; while (stream != NULL) { if (stream->feed == stream) { - url_fprintf(pb, "

Feed %s

", stream->filename); + avio_printf(pb, "

Feed %s

", stream->filename); if (stream->pid) { - url_fprintf(pb, "Running as pid %d.\n", stream->pid); + avio_printf(pb, "Running as pid %d.\n", stream->pid); #if defined(linux) && !defined(CONFIG_NOCUTILS) { @@ -2007,7 +2007,7 @@ static void compute_status(HTTPContext *c) if (fscanf(pid_stat, "%10s %64s", cpuperc, cpuused) == 2) { - url_fprintf(pb, "Currently using %s%% of the cpu. Total time used %s.\n", + avio_printf(pb, "Currently using %s%% of the cpu. Total time used %s.\n", cpuperc, cpuused); } fclose(pid_stat); @@ -2015,9 +2015,9 @@ static void compute_status(HTTPContext *c) } #endif - url_fprintf(pb, "

"); + avio_printf(pb, "

"); } - url_fprintf(pb, "
Streamtypekbits/scodecParameters\n"); + avio_printf(pb, "
Streamtypekbits/scodecParameters\n"); for (i = 0; i < stream->nb_streams; i++) { AVStream *st = stream->streams[i]; @@ -2040,26 +2040,26 @@ static void compute_status(HTTPContext *c) default: abort(); } - url_fprintf(pb, "
%d%s%d%s%s\n", + avio_printf(pb, "
%d%s%d%s%s\n", i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters); } - url_fprintf(pb, "
\n"); + avio_printf(pb, "
\n"); } stream = stream->next; } /* connection status */ - url_fprintf(pb, "

Connection Status

\n"); + avio_printf(pb, "

Connection Status

\n"); - url_fprintf(pb, "Number of connections: %d / %d
\n", + avio_printf(pb, "Number of connections: %d / %d
\n", nb_connections, nb_max_connections); - url_fprintf(pb, "Bandwidth in use: %"PRIu64"k / %"PRIu64"k
\n", + avio_printf(pb, "Bandwidth in use: %"PRIu64"k / %"PRIu64"k
\n", current_bandwidth, max_bandwidth); - url_fprintf(pb, "\n"); - url_fprintf(pb, "
#FileIPProtoStateTarget bits/secActual bits/secBytes transferred\n"); + avio_printf(pb, "\n"); + avio_printf(pb, "
#FileIPProtoStateTarget bits/secActual bits/secBytes transferred\n"); c1 = first_http_ctx; i = 0; while (c1 != NULL) { @@ -2078,7 +2078,7 @@ static void compute_status(HTTPContext *c) i++; p = inet_ntoa(c1->from_addr.sin_addr); - url_fprintf(pb, "
%d%s%s%s%s%s", + avio_printf(pb, "
%d%s%s%s%s%s", i, c1->stream ? c1->stream->filename : "", c1->state == HTTPSTATE_RECEIVE_DATA ? "(input)" : "", @@ -2086,20 +2086,20 @@ static void compute_status(HTTPContext *c) c1->protocol, http_state[c1->state]); fmt_bytecount(pb, bitrate); - url_fprintf(pb, ""); + avio_printf(pb, ""); fmt_bytecount(pb, compute_datarate(&c1->datarate, c1->data_count) * 8); - url_fprintf(pb, ""); + avio_printf(pb, ""); fmt_bytecount(pb, c1->data_count); - url_fprintf(pb, "\n"); + avio_printf(pb, "\n"); c1 = c1->next; } - url_fprintf(pb, "
\n"); + avio_printf(pb, "
\n"); /* date */ ti = time(NULL); p = ctime(&ti); - url_fprintf(pb, "
Generated at %s", p); - url_fprintf(pb, "\n\n"); + avio_printf(pb, "
Generated at %s", p); + avio_printf(pb, "\n\n"); len = url_close_dyn_buf(pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; @@ -2812,20 +2812,20 @@ static void rtsp_reply_header(HTTPContext *c, enum RTSPStatusCode error_number) break; } - url_fprintf(c->pb, "RTSP/1.0 %d %s\r\n", error_number, str); - url_fprintf(c->pb, "CSeq: %d\r\n", c->seq); + avio_printf(c->pb, "RTSP/1.0 %d %s\r\n", error_number, str); + avio_printf(c->pb, "CSeq: %d\r\n", c->seq); /* output GMT time */ ti = time(NULL); tm = gmtime(&ti); strftime(buf2, sizeof(buf2), "%a, %d %b %Y %H:%M:%S", tm); - url_fprintf(c->pb, "Date: %s GMT\r\n", buf2); + avio_printf(c->pb, "Date: %s GMT\r\n", buf2); } static void rtsp_reply_error(HTTPContext *c, enum RTSPStatusCode error_number) { rtsp_reply_header(c, error_number); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "\r\n"); } static int rtsp_parse_request(HTTPContext *c) @@ -2970,10 +2970,10 @@ static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer, static void rtsp_cmd_options(HTTPContext *c, const char *url) { // rtsp_reply_header(c, RTSP_STATUS_OK); - url_fprintf(c->pb, "RTSP/1.0 %d %s\r\n", RTSP_STATUS_OK, "OK"); - url_fprintf(c->pb, "CSeq: %d\r\n", c->seq); - url_fprintf(c->pb, "Public: %s\r\n", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE"); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "RTSP/1.0 %d %s\r\n", RTSP_STATUS_OK, "OK"); + avio_printf(c->pb, "CSeq: %d\r\n", c->seq); + avio_printf(c->pb, "Public: %s\r\n", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE"); + avio_printf(c->pb, "\r\n"); } static void rtsp_cmd_describe(HTTPContext *c, const char *url) @@ -3014,10 +3014,10 @@ static void rtsp_cmd_describe(HTTPContext *c, const char *url) return; } rtsp_reply_header(c, RTSP_STATUS_OK); - url_fprintf(c->pb, "Content-Base: %s/\r\n", url); - url_fprintf(c->pb, "Content-Type: application/sdp\r\n"); - url_fprintf(c->pb, "Content-Length: %d\r\n", content_length); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Content-Base: %s/\r\n", url); + avio_printf(c->pb, "Content-Type: application/sdp\r\n"); + avio_printf(c->pb, "Content-Length: %d\r\n", content_length); + avio_printf(c->pb, "\r\n"); avio_write(c->pb, content, content_length); av_free(content); } @@ -3163,30 +3163,30 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); + avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id); switch(rtp_c->rtp_protocol) { case RTSP_LOWER_TRANSPORT_UDP: rtp_port = rtp_get_local_rtp_port(rtp_c->rtp_handles[stream_index]); rtcp_port = rtp_get_local_rtcp_port(rtp_c->rtp_handles[stream_index]); - url_fprintf(c->pb, "Transport: RTP/AVP/UDP;unicast;" + avio_printf(c->pb, "Transport: RTP/AVP/UDP;unicast;" "client_port=%d-%d;server_port=%d-%d", th->client_port_min, th->client_port_max, rtp_port, rtcp_port); break; case RTSP_LOWER_TRANSPORT_TCP: - url_fprintf(c->pb, "Transport: RTP/AVP/TCP;interleaved=%d-%d", + avio_printf(c->pb, "Transport: RTP/AVP/TCP;interleaved=%d-%d", stream_index * 2, stream_index * 2 + 1); break; default: break; } if (setup.transport_option[0] != '\0') - url_fprintf(c->pb, ";%s", setup.transport_option); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, ";%s", setup.transport_option); + avio_printf(c->pb, "\r\n"); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "\r\n"); } @@ -3248,8 +3248,8 @@ static void rtsp_cmd_play(HTTPContext *c, const char *url, RTSPMessageHeader *h) /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id); + avio_printf(c->pb, "\r\n"); } static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPMessageHeader *h) @@ -3273,8 +3273,8 @@ static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPMessageHeader *h /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Session: %s\r\n", rtp_c->session_id); + avio_printf(c->pb, "\r\n"); } static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader *h) @@ -3296,8 +3296,8 @@ static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPMessageHeader /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", session_id); - url_fprintf(c->pb, "\r\n"); + avio_printf(c->pb, "Session: %s\r\n", session_id); + avio_printf(c->pb, "\r\n"); } diff --git a/libavformat/avio.h b/libavformat/avio.h index 9f45a6bd87..5388c39c1e 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -430,6 +430,11 @@ attribute_deprecated int64_t url_fsize(AVIOContext *s); #define URL_EOF (-1) attribute_deprecated int url_fgetc(AVIOContext *s); attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size); +#ifdef __GNUC__ +attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); +#else +attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...); +#endif /** * @} */ @@ -513,9 +518,9 @@ int64_t av_url_read_fseek(AVIOContext *h, int stream_index, /** @warning currently size is limited */ #ifdef __GNUC__ -int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); +int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); #else -int url_fprintf(AVIOContext *s, const char *fmt, ...); +int avio_printf(AVIOContext *s, const char *fmt, ...); #endif #if FF_API_OLD_AVIO diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 7d84b2b293..7fbe4ce76c 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -381,6 +381,18 @@ int url_setbufsize(AVIOContext *s, int buf_size) { return ffio_set_buf_size(s, buf_size); } +int url_fprintf(AVIOContext *s, const char *fmt, ...) +{ + va_list ap; + char buf[4096]; + int ret; + + va_start(ap, fmt); + ret = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + avio_write(s, buf, strlen(buf)); + return ret; +} #endif int avio_put_str(AVIOContext *s, const char *str) @@ -913,7 +925,7 @@ URLContext *url_fileno(AVIOContext *s) } #if CONFIG_MUXERS -int url_fprintf(AVIOContext *s, const char *fmt, ...) +int avio_printf(AVIOContext *s, const char *fmt, ...) { va_list ap; char buf[4096]; diff --git a/libavformat/ffmetaenc.c b/libavformat/ffmetaenc.c index 77db0b9bf8..70940c0e09 100644 --- a/libavformat/ffmetaenc.c +++ b/libavformat/ffmetaenc.c @@ -73,9 +73,9 @@ static int write_trailer(AVFormatContext *s) AVChapter *ch = s->chapters[i]; avio_write(s->pb, ID_CHAPTER, sizeof(ID_CHAPTER) - 1); avio_w8(s->pb, '\n'); - url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); - url_fprintf(s->pb, "START=%"PRId64"\n", ch->start); - url_fprintf(s->pb, "END=%"PRId64"\n", ch->end); + avio_printf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); + avio_printf(s->pb, "START=%"PRId64"\n", ch->start); + avio_printf(s->pb, "END=%"PRId64"\n", ch->end); write_tags(s->pb, ch->metadata); }