* commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e': movenc: Keep track of the allocated size for the cluster array mem: Add av_realloc_array and av_reallocp_array Conflicts: doc/APIchanges libavformat/movenc.c libavutil/mem.c libavutil/mem.h libavutil/version.h
Unified · Split
| @@ -16,6 +16,9 @@ libavutil: 2012-10-22 · 15 unmodified lines | |||
| 16 | API changes, most recent first: | 16 | API changes, most recent first: |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 2013-06-05 - fc962d4 - lavu 52.13.0 - mem.h | ||
| 20 | Add av_realloc_array and av_reallocp_array | ||
| 21 | |||
| 19 | 2013-05-24 - xxxxxxx - lavfi 3.70.100 - avfilter.h | 22 | 2013-05-24 - xxxxxxx - lavfi 3.70.100 - avfilter.h |
| 20 | Add support for slice multithreading to lavfi. Filters supporting threading | 23 | Add support for slice multithreading to lavfi. Filters supporting threading |
| 21 | are marked with AVFILTER_FLAG_SLICE_THREADS. | 24 | are marked with AVFILTER_FLAG_SLICE_THREADS. |
| @@ -3208,10 +3208,12 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 3207 unmodified lines | |||
| 3208 | memcpy(trk->vos_data, pkt->data, size); | 3208 | memcpy(trk->vos_data, pkt->data, size); |
| 3209 | } | 3209 | } |
| 3210 | 3210 | ||
| 3211 | if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) { | 3211 | if (trk->entry >= trk->cluster_capacity) { |
| 3212 | trk->cluster = av_realloc_f(trk->cluster, sizeof(*trk->cluster), (trk->entry + MOV_INDEX_CLUSTER_SIZE)); | 3212 | unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE; |
| 3213 | if (!trk->cluster) | 3213 | if (av_reallocp_array(&trk->cluster, new_capacity, |
| 3214 | return -1; | 3214 | sizeof(*trk->cluster))) |
| 3215 | return AVERROR(ENOMEM); | ||
| 3216 | trk->cluster_capacity = new_capacity; | ||
| 3215 | } | 3217 | } |
| 3216 | 3218 | ||
| 3217 | trk->cluster[trk->entry].pos = avio_tell(pb) - size; | 3219 | trk->cluster[trk->entry].pos = avio_tell(pb) - size; |
| @@ -102,6 +102,7 @@ typedef struct MOVTrack { · 101 unmodified lines | |||
| 102 | int vos_len; | 102 | int vos_len; |
| 103 | uint8_t *vos_data; | 103 | uint8_t *vos_data; |
| 104 | MOVIentry *cluster; | 104 | MOVIentry *cluster; |
| 105 | unsigned cluster_capacity; | ||
| 105 | int audio_vbr; | 106 | int audio_vbr; |
| 106 | int height; ///< active picture (w/o VBI) height for D-10/IMX | 107 | int height; ///< active picture (w/o VBI) height for D-10/IMX |
| 107 | uint32_t tref_tag; | 108 | uint32_t tref_tag; |
| @@ -180,6 +180,32 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize) · 179 unmodified lines | |||
| 180 | return r; | 180 | return r; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | void *av_realloc_array(void *ptr, size_t nmemb, size_t size) | ||
| 184 | { | ||
| 185 | if (size <= 0 || nmemb >= INT_MAX / size) | ||
| 186 | return NULL; | ||
| 187 | return av_realloc(ptr, nmemb * size); | ||
| 188 | } | ||
| 189 | |||
| 190 | int av_reallocp_array(void *ptr, size_t nmemb, size_t size) | ||
| 191 | { | ||
| 192 | void **ptrptr = ptr; | ||
| 193 | void *ret; | ||
| 194 | if (size <= 0 || nmemb >= INT_MAX / size) | ||
| 195 | return AVERROR(ENOMEM); | ||
| 196 | if (nmemb <= 0) { | ||
| 197 | av_freep(ptr); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | ret = av_realloc(*ptrptr, nmemb * size); | ||
| 201 | if (!ret) { | ||
| 202 | av_freep(ptr); | ||
| 203 | return AVERROR(ENOMEM); | ||
| 204 | } | ||
| 205 | *ptrptr = ret; | ||
| 206 | return 0; | ||
| 207 | } | ||
| 208 | |||
| 183 | void av_free(void *ptr) | 209 | void av_free(void *ptr) |
| 184 | { | 210 | { |
| 185 | #if CONFIG_MEMALIGN_HACK | 211 | #if CONFIG_MEMALIGN_HACK |
| @@ -122,6 +122,32 @@ void *av_realloc(void *ptr, size_t size) av_alloc_size(2); · 121 unmodified lines | |||
| 122 | */ | 122 | */ |
| 123 | void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); | 123 | void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); |
| 124 | 124 | ||
| 125 | /** | ||
| 126 | * Allocate or reallocate an array. | ||
| 127 | * If ptr is NULL and nmemb > 0, allocate a new block. If | ||
| 128 | * nmemb is zero, free the memory block pointed to by ptr. | ||
| 129 | * @param ptr Pointer to a memory block already allocated with | ||
| 130 | * av_malloc(z)() or av_realloc() or NULL. | ||
| 131 | * @param nmemb Number of elements | ||
| 132 | * @param size Size of the single element | ||
| 133 | * @return Pointer to a newly reallocated block or NULL if the block | ||
| 134 | * cannot be reallocated or the function is used to free the memory block. | ||
| 135 | */ | ||
| 136 | av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size); | ||
| 137 | |||
| 138 | /** | ||
| 139 | * Allocate or reallocate an array. | ||
| 140 | * If *ptr is NULL and nmemb > 0, allocate a new block. If | ||
| 141 | * nmemb is zero, free the memory block pointed to by ptr. | ||
| 142 | * @param ptr Pointer to a pointer to a memory block already allocated | ||
| 143 | * with av_malloc(z)() or av_realloc(), or pointer to a pointer to NULL. | ||
| 144 | * The pointer is updated on success, or freed on failure. | ||
| 145 | * @param nmemb Number of elements | ||
| 146 | * @param size Size of the single element | ||
| 147 | * @return Zero on success, an AVERROR error code on failure. | ||
| 148 | */ | ||
| 149 | av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); | ||
| 150 | |||
| 125 | /** | 151 | /** |
| 126 | * Free a memory block which has been allocated with av_malloc(z)() or | 152 | * Free a memory block which has been allocated with av_malloc(z)() or |
| 127 | * av_realloc(). | 153 | * av_realloc(). |
| @@ -75,7 +75,7 @@ · 74 unmodified lines | |||
| 75 | */ | 75 | */ |
| 76 | 76 | ||
| 77 | #define LIBAVUTIL_VERSION_MAJOR 52 | 77 | #define LIBAVUTIL_VERSION_MAJOR 52 |
| 78 | #define LIBAVUTIL_VERSION_MINOR 34 | 78 | #define LIBAVUTIL_VERSION_MINOR 35 |
| 79 | #define LIBAVUTIL_VERSION_MICRO 100 | 79 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 80 | 80 | ||
| 81 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | 81 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |