diff options
author | Martin Storsjö <martin@martin.st> | 2015-02-24 14:37:03 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2015-02-25 00:07:44 +0300 |
commit | 199fb40278146c5bb162990c66ad3cd561abc780 (patch) | |
tree | 0411eef55863c799202a17254b8cc30e9601d28f | |
parent | 8a273a746061a112e5e35066a8fd8e146d821a62 (diff) |
rtpdec: Use ffio_free_dyn_buf
Signed-off-by: Martin Storsjö <martin@martin.st>
-rw-r--r-- | libavformat/rtpdec_ac3.c | 19 | ||||
-rw-r--r-- | libavformat/rtpdec_asf.c | 12 | ||||
-rw-r--r-- | libavformat/rtpdec_dv.c | 13 | ||||
-rw-r--r-- | libavformat/rtpdec_h261.c | 15 | ||||
-rw-r--r-- | libavformat/rtpdec_h263_rfc2190.c | 12 | ||||
-rw-r--r-- | libavformat/rtpdec_jpeg.c | 17 | ||||
-rw-r--r-- | libavformat/rtpdec_latm.c | 12 | ||||
-rw-r--r-- | libavformat/rtpdec_mpa_robust.c | 17 | ||||
-rw-r--r-- | libavformat/rtpdec_svq3.c | 13 | ||||
-rw-r--r-- | libavformat/rtpdec_vp8.c | 19 | ||||
-rw-r--r-- | libavformat/rtpdec_xiph.c | 17 |
11 files changed, 39 insertions, 127 deletions
diff --git a/libavformat/rtpdec_ac3.c b/libavformat/rtpdec_ac3.c index 480fdd0cd5..a2ff961721 100644 --- a/libavformat/rtpdec_ac3.c +++ b/libavformat/rtpdec_ac3.c @@ -20,6 +20,7 @@ */ #include "avformat.h" +#include "avio_internal.h" #include "rtpdec_formats.h" #define RTP_AC3_PAYLOAD_HEADER_SIZE 2 @@ -31,19 +32,9 @@ struct PayloadContext { AVIOContext *fragment; }; -static void free_fragment(PayloadContext *data) -{ - if (data->fragment) { - uint8_t *p; - avio_close_dyn_buf(data->fragment, &p); - av_free(p); - data->fragment = NULL; - } -} - static void ac3_free_context(PayloadContext *data) { - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); } static int ac3_handle_packet(AVFormatContext *ctx, PayloadContext *data, @@ -82,7 +73,7 @@ static int ac3_handle_packet(AVFormatContext *ctx, PayloadContext *data, case 1: case 2: /* First fragment */ - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); data->last_frame = 1; data->nr_frames = nr_frames; @@ -102,7 +93,7 @@ static int ac3_handle_packet(AVFormatContext *ctx, PayloadContext *data, } if (nr_frames != data->nr_frames || data->timestamp != *timestamp) { - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); av_log(ctx, AV_LOG_ERROR, "Invalid packet received\n"); return AVERROR_INVALIDDATA; } @@ -115,7 +106,7 @@ static int ac3_handle_packet(AVFormatContext *ctx, PayloadContext *data, return AVERROR(EAGAIN); if (data->last_frame != data->nr_frames) { - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); av_log(ctx, AV_LOG_ERROR, "Missed %d packets\n", data->nr_frames - data->last_frame); return AVERROR_INVALIDDATA; diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index b0a50353fd..7eb720b3c4 100644 --- a/libavformat/rtpdec_asf.c +++ b/libavformat/rtpdec_asf.c @@ -213,10 +213,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, * multiple RTP packets. */ if (asf->pktbuf && len_off != avio_tell(asf->pktbuf)) { - uint8_t *p; - avio_close_dyn_buf(asf->pktbuf, &p); - asf->pktbuf = NULL; - av_free(p); + ffio_free_dyn_buf(&asf->pktbuf); } if (!len_off && !asf->pktbuf && (res = avio_open_dyn_buf(&asf->pktbuf)) < 0) @@ -279,12 +276,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, static void asfrtp_free_context(PayloadContext *asf) { - if (asf->pktbuf) { - uint8_t *p = NULL; - avio_close_dyn_buf(asf->pktbuf, &p); - asf->pktbuf = NULL; - av_free(p); - } + ffio_free_dyn_buf(&asf->pktbuf); av_freep(&asf->buf); av_free(asf); } diff --git a/libavformat/rtpdec_dv.c b/libavformat/rtpdec_dv.c index c428322097..72d06f75f8 100644 --- a/libavformat/rtpdec_dv.c +++ b/libavformat/rtpdec_dv.c @@ -23,6 +23,7 @@ #include "libavcodec/bytestream.h" +#include "avio_internal.h" #include "rtpdec_formats.h" struct PayloadContext { @@ -31,17 +32,9 @@ struct PayloadContext { int bundled_audio; }; -static void dv_free_dyn_buffer(AVIOContext **dyn_buf) -{ - uint8_t *ptr_dyn_buffer; - avio_close_dyn_buf(*dyn_buf, &ptr_dyn_buffer); - av_free(ptr_dyn_buffer); - *dyn_buf = NULL; -} - static av_cold void dv_free_context(PayloadContext *data) { - dv_free_dyn_buffer(&data->buf); + ffio_free_dyn_buf(&data->buf); } static av_cold int dv_sdp_parse_fmtp_config(AVFormatContext *s, @@ -104,7 +97,7 @@ static int dv_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_dv_ctx, /* drop data of previous packets in case of non-continuous (lossy) packet stream */ if (rtp_dv_ctx->buf && rtp_dv_ctx->timestamp != *timestamp) { - dv_free_dyn_buffer(&rtp_dv_ctx->buf); + ffio_free_dyn_buf(&rtp_dv_ctx->buf); } /* sanity check for size of input packet: 1 byte payload at least */ diff --git a/libavformat/rtpdec_h261.c b/libavformat/rtpdec_h261.c index b2d2a53f1c..6ca385fd80 100644 --- a/libavformat/rtpdec_h261.c +++ b/libavformat/rtpdec_h261.c @@ -21,6 +21,7 @@ #include "libavcodec/get_bits.h" #include "avformat.h" +#include "avio_internal.h" #include "rtpdec_formats.h" #define RTP_H261_PAYLOAD_HEADER_SIZE 4 @@ -32,14 +33,6 @@ struct PayloadContext { uint32_t timestamp; }; -static void h261_free_dyn_buffer(AVIOContext **dyn_buf) -{ - uint8_t *ptr_dyn_buffer; - avio_close_dyn_buf(*dyn_buf, &ptr_dyn_buffer); - av_free(ptr_dyn_buffer); - *dyn_buf = NULL; -} - static av_cold void h261_free_context(PayloadContext *pl_ctx) { /* return if context is invalid */ @@ -47,9 +40,7 @@ static av_cold void h261_free_context(PayloadContext *pl_ctx) return; /* free buffer if it is valid */ - if (pl_ctx->buf) { - h261_free_dyn_buffer(&pl_ctx->buf); - } + ffio_free_dyn_buf(&pl_ctx->buf); } static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx, @@ -62,7 +53,7 @@ static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx /* drop data of previous packets in case of non-continuous (lossy) packet stream */ if (rtp_h261_ctx->buf && rtp_h261_ctx->timestamp != *timestamp) { - h261_free_dyn_buffer(&rtp_h261_ctx->buf); + ffio_free_dyn_buf(&rtp_h261_ctx->buf); rtp_h261_ctx->endbyte_bits = 0; } diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c index e45778108b..f0794c7c94 100644 --- a/libavformat/rtpdec_h263_rfc2190.c +++ b/libavformat/rtpdec_h263_rfc2190.c @@ -26,6 +26,7 @@ */ #include "avformat.h" +#include "avio_internal.h" #include "rtpdec_formats.h" #include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" @@ -41,11 +42,7 @@ struct PayloadContext { static void h263_free_context(PayloadContext *data) { - if (data->buf) { - uint8_t *p; - avio_close_dyn_buf(data->buf, &p); - av_free(p); - } + ffio_free_dyn_buf(&data->buf); } static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, @@ -63,10 +60,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, if (data->buf && data->timestamp != *timestamp) { /* Dropping old buffered, unfinished data */ - uint8_t *p; - avio_close_dyn_buf(data->buf, &p); - av_free(p); - data->buf = NULL; + ffio_free_dyn_buf(&data->buf); data->endbyte_bits = 0; } diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c index 0bc9eea13c..d2ca6ab007 100644 --- a/libavformat/rtpdec_jpeg.c +++ b/libavformat/rtpdec_jpeg.c @@ -20,6 +20,7 @@ */ #include "avformat.h" +#include "avio_internal.h" #include "rtpdec.h" #include "rtpdec_formats.h" #include "libavutil/intreadwrite.h" @@ -59,19 +60,9 @@ static const uint8_t default_quantizers[128] = { 99, 99, 99, 99, 99, 99, 99, 99 }; -static void free_frame(PayloadContext *jpeg) -{ - if (jpeg->frame) { - uint8_t *p; - avio_close_dyn_buf(jpeg->frame, &p); - av_free(p); - jpeg->frame = NULL; - } -} - static void jpeg_free_context(PayloadContext *jpeg) { - free_frame(jpeg); + ffio_free_dyn_buf(&jpeg->frame); } static int jpeg_create_huffman_table(PutByteContext *p, int table_class, @@ -315,7 +306,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg, /* Skip the current frame in case of the end packet * has been lost somewhere. */ - free_frame(jpeg); + ffio_free_dyn_buf(&jpeg->frame); if ((ret = avio_open_dyn_buf(&jpeg->frame)) < 0) return ret; @@ -341,7 +332,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg, if (jpeg->timestamp != *timestamp) { /* Skip the current frame if timestamp is incorrect. * A start packet has been lost somewhere. */ - free_frame(jpeg); + ffio_free_dyn_buf(&jpeg->frame); av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match.\n"); return AVERROR_INVALIDDATA; } diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c index 3ee552e414..81f3ae4c4f 100644 --- a/libavformat/rtpdec_latm.c +++ b/libavformat/rtpdec_latm.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "avio_internal.h" #include "rtpdec_formats.h" #include "internal.h" #include "libavutil/avstring.h" @@ -33,11 +34,7 @@ struct PayloadContext { static void latm_free_context(PayloadContext *data) { - if (data->dyn_buf) { - uint8_t *p; - avio_close_dyn_buf(data->dyn_buf, &p); - av_free(p); - } + ffio_free_dyn_buf(&data->dyn_buf); av_free(data->buf); } @@ -51,10 +48,7 @@ static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data, if (buf) { if (!data->dyn_buf || data->timestamp != *timestamp) { av_freep(&data->buf); - if (data->dyn_buf) - avio_close_dyn_buf(data->dyn_buf, &data->buf); - data->dyn_buf = NULL; - av_freep(&data->buf); + ffio_free_dyn_buf(&data->dyn_buf); data->timestamp = *timestamp; if ((ret = avio_open_dyn_buf(&data->dyn_buf)) < 0) diff --git a/libavformat/rtpdec_mpa_robust.c b/libavformat/rtpdec_mpa_robust.c index 46e9f36e8d..36b4691112 100644 --- a/libavformat/rtpdec_mpa_robust.c +++ b/libavformat/rtpdec_mpa_robust.c @@ -22,6 +22,7 @@ #include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" +#include "avio_internal.h" #include "rtpdec_formats.h" struct PayloadContext { @@ -33,19 +34,9 @@ struct PayloadContext { AVIOContext *fragment; }; -static void free_fragment(PayloadContext *data) -{ - if (data->fragment) { - uint8_t *p; - avio_close_dyn_buf(data->fragment, &p); - av_free(p); - data->fragment = NULL; - } -} - static void mpa_robust_free_context(PayloadContext *data) { - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); av_free(data->split_buf); } @@ -154,7 +145,7 @@ static int mpa_robust_parse_packet(AVFormatContext *ctx, PayloadContext *data, return 0; } else if (!continuation) { /* && adu_size > len */ /* First fragment */ - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); data->adu_size = adu_size; data->cur_size = len; @@ -177,7 +168,7 @@ static int mpa_robust_parse_packet(AVFormatContext *ctx, PayloadContext *data, } if (adu_size = data->adu_size || data->timestamp != *timestamp) { - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); av_log(ctx, AV_LOG_ERROR, "Invalid packet received\n"); return AVERROR_INVALIDDATA; } diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c index 4667c75cb8..030b379b72 100644 --- a/libavformat/rtpdec_svq3.c +++ b/libavformat/rtpdec_svq3.c @@ -28,6 +28,7 @@ #include <string.h> #include "libavutil/intreadwrite.h" +#include "avio_internal.h" #include "rtp.h" #include "rtpdec.h" #include "rtpdec_formats.h" @@ -82,11 +83,7 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, if (start_packet) { int res; - if (sv->pktbuf) { - uint8_t *tmp; - avio_close_dyn_buf(sv->pktbuf, &tmp); - av_free(tmp); - } + ffio_free_dyn_buf(&sv->pktbuf); if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0) return res; sv->timestamp = *timestamp; @@ -111,11 +108,7 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, static void svq3_extradata_free(PayloadContext *sv) { - if (sv->pktbuf) { - uint8_t *buf; - avio_close_dyn_buf(sv->pktbuf, &buf); - av_free(buf); - } + ffio_free_dyn_buf(&sv->pktbuf); } RTPDynamicProtocolHandler ff_svq3_dynamic_handler = { diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c index 9fa5afa629..d156cd3f64 100644 --- a/libavformat/rtpdec_vp8.c +++ b/libavformat/rtpdec_vp8.c @@ -29,6 +29,7 @@ #include "libavcodec/bytestream.h" +#include "avio_internal.h" #include "rtpdec_formats.h" struct PayloadContext { @@ -52,22 +53,12 @@ struct PayloadContext { int got_keyframe; }; -static void vp8_free_buffer(PayloadContext *vp8) -{ - uint8_t *tmp; - if (!vp8->data) - return; - avio_close_dyn_buf(vp8->data, &tmp); - av_free(tmp); - vp8->data = NULL; -} - static int vp8_broken_sequence(AVFormatContext *ctx, PayloadContext *vp8, const char *msg) { vp8->sequence_ok = 0; av_log(ctx, AV_LOG_WARNING, "%s", msg); - vp8_free_buffer(vp8); + ffio_free_dyn_buf(&vp8->data); return AVERROR(EAGAIN); } @@ -150,7 +141,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, int res; int non_key = buf[0] & 0x01; if (!non_key) { - vp8_free_buffer(vp8); + ffio_free_dyn_buf(&vp8->data); // Keyframe, decoding ok again vp8->sequence_ok = 1; vp8->sequence_dirty = 0; @@ -205,7 +196,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, old_timestamp = vp8->timestamp; } else { // Shouldn't happen - vp8_free_buffer(vp8); + ffio_free_dyn_buf(&vp8->data); } } } @@ -277,7 +268,7 @@ static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp static void vp8_free_context(PayloadContext *vp8) { - vp8_free_buffer(vp8); + ffio_free_dyn_buf(&vp8->data); } static int vp8_need_keyframe(PayloadContext *vp8) diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c index 5d0dc69dc2..83cccd9094 100644 --- a/libavformat/rtpdec_xiph.c +++ b/libavformat/rtpdec_xiph.c @@ -34,6 +34,7 @@ #include <assert.h> +#include "avio_internal.h" #include "rtpdec.h" #include "rtpdec_formats.h" @@ -49,19 +50,9 @@ struct PayloadContext { int split_pkts; }; -static void free_fragment(PayloadContext * data) -{ - if (data->fragment) { - uint8_t* p; - avio_close_dyn_buf(data->fragment, &p); - av_free(p); - data->fragment = NULL; - } -} - static void xiph_free_context(PayloadContext * data) { - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); av_free(data->split_buf); } @@ -168,7 +159,7 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data, int res; // end packet has been lost somewhere, so drop buffered data - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); if((res = avio_open_dyn_buf(&data->fragment)) < 0) return res; @@ -181,7 +172,7 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data, if (data->timestamp != *timestamp) { // skip if fragmented timestamp is incorrect; // a start packet has been lost somewhere - free_fragment(data); + ffio_free_dyn_buf(&data->fragment); av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match!\n"); return AVERROR_INVALIDDATA; } |