# HG changeset patch # User reimar # Date 1278833700 0 # Node ID cb3eb3a2fc968298a995119fda9737b2d5f15fb7 # Parent 24649290a14f80b864d2cf5e961181898ba1424c Add avsubtitle_free function. diff -r 24649290a14f -r cb3eb3a2fc96 avcodec.h --- a/avcodec.h Sun Jul 11 06:59:21 2010 +0000 +++ b/avcodec.h Sun Jul 11 07:35:00 2010 +0000 @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 81 +#define LIBAVCODEC_VERSION_MINOR 82 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -3548,13 +3548,22 @@ * due to a potentially very different allocation pattern. * * @param avctx the codec context - * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored. + * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be + freed with avsubtitle_free if *got_sub_ptr is set. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero. * @param[in] avpkt The input AVPacket containing the input buffer. */ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt); + +/** + * Frees all allocated data in the given subtitle struct. + * + * @param sub AVSubtitle to free. + */ +void avsubtitle_free(AVSubtitle *sub); + int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, int *data_size_ptr, uint8_t *buf, int buf_size); diff -r 24649290a14f -r cb3eb3a2fc96 utils.c --- a/utils.c Sun Jul 11 06:59:21 2010 +0000 +++ b/utils.c Sun Jul 11 07:35:00 2010 +0000 @@ -689,6 +689,26 @@ return ret; } +void avsubtitle_free(AVSubtitle *sub) +{ + int i; + + for (i = 0; i < sub->num_rects; i++) + { + av_freep(sub->rects[i]->pict.data[0]); + av_freep(sub->rects[i]->pict.data[1]); + av_freep(sub->rects[i]->pict.data[2]); + av_freep(sub->rects[i]->pict.data[3]); + av_freep(sub->rects[i]->text); + av_freep(sub->rects[i]->ass); + av_freep(sub->rects[i]); + } + + av_freep(sub->rects); + + memset(sub, 0, sizeof(AVSubtitle)); +} + av_cold int avcodec_close(AVCodecContext *avctx) { /* If there is a user-supplied mutex locking routine, call it. */