MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_buffer_realloc

Function av_buffer_realloc

libavutil/buffer.c:183–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
184{
185 AVBufferRef *buf = *pbuf;
186 uint8_t *tmp;
187 int ret;
188
189 if (!buf) {
190 /* allocate a new buffer with av_realloc(), so it will be reallocatable
191 * later */
192 uint8_t *data = av_realloc(NULL, size);
193 if (!data)
194 return AVERROR(ENOMEM);
195
196 buf = av_buffer_create(data, size, av_buffer_default_free, NULL, 0);
197 if (!buf) {
198 av_freep(&data);
199 return AVERROR(ENOMEM);
200 }
201
202 buf->buffer->flags_internal |= BUFFER_FLAG_REALLOCATABLE;
203 *pbuf = buf;
204
205 return 0;
206 } else if (buf->size == size)
207 return 0;
208
209 if (!(buf->buffer->flags_internal & BUFFER_FLAG_REALLOCATABLE) ||
210 !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {
211 /* cannot realloc, allocate a new reallocable buffer and copy data */
212 AVBufferRef *new = NULL;
213
214 ret = av_buffer_realloc(&new, size);
215 if (ret < 0)
216 return ret;
217
218 memcpy(new->data, buf->data, FFMIN(size, buf->size));
219
220 buffer_replace(pbuf, &new);
221 return 0;
222 }
223
224 tmp = av_realloc(buf->buffer->data, size);
225 if (!tmp)
226 return AVERROR(ENOMEM);
227
228 buf->buffer->data = buf->data = tmp;
229 buf->buffer->size = buf->size = size;
230 return 0;
231}
232
233int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
234{

Callers 11

ebml_read_binaryFunction · 0.85
get_qt_codecFunction · 0.85
jpegxl_anim_read_headerFunction · 0.85
packet_allocFunction · 0.85
av_grow_packetFunction · 0.85
ff_parse_a53_ccFunction · 0.85
libjxl_receive_frameFunction · 0.85
mpeg_decode_a53_ccFunction · 0.85
av_exif_writeFunction · 0.85
evc_frame_merge_filterFunction · 0.85

Calls 5

av_buffer_createFunction · 0.85
av_freepFunction · 0.85
av_buffer_is_writableFunction · 0.85
buffer_replaceFunction · 0.85
av_reallocFunction · 0.70

Tested by

no test coverage detected