From 403ee835e7913eb9536b22c2b22edfdd700166a9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 17 Mar 2011 08:19:54 +0100 Subject: [PATCH] avio: make url_open_dyn_packet_buf internal. It doesn't look fit to be a part of the public API. Adding a temporary hack to ffserver to be able to use it, should be cleaned up when somebody is up for it. --- ffserver.c | 6 ++++-- libavformat/avio.h | 17 +++-------------- libavformat/avio_internal.h | 11 +++++++++++ libavformat/aviobuf.c | 6 +++++- libavformat/movenchint.c | 3 ++- libavformat/rtpdec.c | 2 +- libavformat/rtpenc_chain.c | 3 ++- libavformat/rtspenc.c | 5 +++-- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/ffserver.c b/ffserver.c index 0ee61e2e50..3ad40e9bfb 100644 --- a/ffserver.c +++ b/ffserver.c @@ -33,6 +33,8 @@ #include "libavformat/os_support.h" #include "libavformat/rtpdec.h" #include "libavformat/rtsp.h" +// XXX for ffio_open_dyn_packet_buffer, to be removed +#include "libavformat/avio_internal.h" #include "libavutil/avstring.h" #include "libavutil/lfg.h" #include "libavutil/random_seed.h" @@ -2389,7 +2391,7 @@ static int http_prepare_data(HTTPContext *c) max_packet_size = RTSP_TCP_MAX_PACKET_SIZE; else max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]); - ret = url_open_dyn_packet_buf(&ctx->pb, max_packet_size); + ret = ffio_open_dyn_packet_buf(&ctx->pb, max_packet_size); } else { ret = avio_open_dyn_buf(&ctx->pb); } @@ -3444,7 +3446,7 @@ static int rtp_new_av_stream(HTTPContext *c, c->stream->filename, stream_index, c->protocol); /* normally, no packets should be output here, but the packet size may be checked */ - if (url_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) { + if (ffio_open_dyn_packet_buf(&ctx->pb, max_packet_size) < 0) { /* XXX: close stream */ goto fail; } diff --git a/libavformat/avio.h b/libavformat/avio.h index 5bc85827d1..69896d1404 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -448,6 +448,7 @@ attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...); #endif attribute_deprecated void put_flush_packet(AVIOContext *s); attribute_deprecated int url_open_dyn_buf(AVIOContext **s); +attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); /** * @} @@ -684,22 +685,10 @@ attribute_deprecated int url_close_buf(AVIOContext *s); */ int avio_open_dyn_buf(AVIOContext **s); -/** - * Open a write only packetized memory stream with a maximum packet - * size of 'max_packet_size'. The stream is stored in a memory buffer - * with a big endian 4 byte header giving the packet size in bytes. - * - * @param s new IO context - * @param max_packet_size maximum packet size (must be > 0) - * @return zero if no error. - */ -int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); - /** * Return the written size and a pointer to the buffer. The buffer - * must be freed with av_free(). If the buffer is opened with - * avio_open_dyn_buf, then padding of FF_INPUT_BUFFER_PADDING_SIZE is - * added; if opened with url_open_dyn_packet_buf, no padding is added. + * must be freed with av_free(). + * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer. * * @param s IO context * @param pbuffer pointer to a byte buffer diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index 916de8fcc7..29553ed614 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -81,4 +81,15 @@ unsigned long ffio_get_checksum(AVIOContext *s); unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len); +/** + * Open a write only packetized memory stream with a maximum packet + * size of 'max_packet_size'. The stream is stored in a memory buffer + * with a big endian 4 byte header giving the packet size in bytes. + * + * @param s new IO context + * @param max_packet_size maximum packet size (must be > 0) + * @return zero if no error. + */ +int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); + #endif // AVFORMAT_AVIO_INTERNAL_H diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index cb5f2790f7..73045e6599 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -423,6 +423,10 @@ int url_open_dyn_buf(AVIOContext **s) { return avio_open_dyn_buf(s); } +int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size) +{ + return ffio_open_dyn_packet_buf(s, max_packet_size); +} int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) { return avio_close_dyn_buf(s, pbuffer); @@ -1160,7 +1164,7 @@ int avio_open_dyn_buf(AVIOContext **s) return url_open_dyn_buf_internal(s, 0); } -int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size) +int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size) { if (max_packet_size <= 0) return -1; diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index eb93ef8d7e..615714627c 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -23,6 +23,7 @@ #include "libavutil/intreadwrite.h" #include "internal.h" #include "rtpenc_chain.h" +#include "avio_internal.h" int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) { @@ -409,7 +410,7 @@ int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, /* Fetch the output from the RTP muxer, open a new output buffer * for next time. */ size = avio_close_dyn_buf(rtp_ctx->pb, &buf); - if ((ret = url_open_dyn_packet_buf(&rtp_ctx->pb, + if ((ret = ffio_open_dyn_packet_buf(&rtp_ctx->pb, RTP_MAX_PACKET_SIZE)) < 0) goto done; diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index bbd5f338ed..281f51c443 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -41,7 +41,7 @@ buffer to 'rtp_write_packet' contains all the packets for ONE frame. Each packet should have a four byte header containing the length in big endian format (same trick as - 'url_open_dyn_packet_buf') + 'ffio_open_dyn_packet_buf') */ static RTPDynamicProtocolHandler ff_realmedia_mp3_dynamic_handler = { diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c index 77633ed53e..a923b2deb6 100644 --- a/libavformat/rtpenc_chain.c +++ b/libavformat/rtpenc_chain.c @@ -21,6 +21,7 @@ #include "avformat.h" #include "rtpenc_chain.h" +#include "avio_internal.h" AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, URLContext *handle, int packet_size) @@ -55,7 +56,7 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, if (handle) { url_fdopen(&rtpctx->pb, handle); } else - url_open_dyn_packet_buf(&rtpctx->pb, packet_size); + ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size); ret = av_write_header(rtpctx); if (ret) { diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c index e3631c4290..7f52b1fdb1 100644 --- a/libavformat/rtspenc.c +++ b/libavformat/rtspenc.c @@ -29,6 +29,7 @@ #include "os_support.h" #include "rtsp.h" #include "internal.h" +#include "avio_internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" @@ -142,7 +143,7 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st) int id; /* The interleaving header is exactly 4 bytes, which happens to be * the same size as the packet length header from - * url_open_dyn_packet_buf. So by writing the interleaving header + * ffio_open_dyn_packet_buf. So by writing the interleaving header * over these bytes, we get a consecutive interleaved packet * that can be written in one call. */ interleaved_packet = interleave_header = ptr; @@ -162,7 +163,7 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st) size -= packet_len; } av_free(buf); - url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); + ffio_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); return 0; }