diff options
author | Anton Khirnov <anton@khirnov.net> | 2024-02-15 08:57:07 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-03-13 08:01:15 +0100 |
commit | b98af440c575c1f9a706bd57ee5f1dd8b9ff82cc (patch) | |
tree | 54656654a4ef2b26f2446b218471cae321df4b8a /fftools/ffmpeg.c | |
parent | efab83c1561c5c095a976971b947489a2d9abfa9 (diff) | |
download | ffmpeg-b98af440c575c1f9a706bd57ee5f1dd8b9ff82cc.tar.gz |
fftools/ffmpeg: prepare FrameData for having allocated fields
Will be useful in following commits.
Diffstat (limited to 'fftools/ffmpeg.c')
-rw-r--r-- | fftools/ffmpeg.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2f01a01e2d..ffd25f4c5b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -402,23 +402,44 @@ InputStream *ist_iter(InputStream *prev) return NULL; } +static void frame_data_free(void *opaque, uint8_t *data) +{ + av_free(data); +} + static int frame_data_ensure(AVBufferRef **dst, int writable) { - if (!*dst) { + AVBufferRef *src = *dst; + + if (!src || (writable && !av_buffer_is_writable(src))) { FrameData *fd; - *dst = av_buffer_allocz(sizeof(*fd)); - if (!*dst) + fd = av_mallocz(sizeof(*fd)); + if (!fd) + return AVERROR(ENOMEM); + + *dst = av_buffer_create((uint8_t *)fd, sizeof(*fd), + frame_data_free, NULL, 0); + if (!*dst) { + av_buffer_unref(&src); + av_freep(&fd); return AVERROR(ENOMEM); - fd = (FrameData*)((*dst)->data); + } + + if (src) { + const FrameData *fd_src = (const FrameData *)src->data; + + memcpy(fd, fd_src, sizeof(*fd)); - fd->dec.frame_num = UINT64_MAX; - fd->dec.pts = AV_NOPTS_VALUE; + av_buffer_unref(&src); + } else { + fd->dec.frame_num = UINT64_MAX; + fd->dec.pts = AV_NOPTS_VALUE; - for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i++) - fd->wallclock[i] = INT64_MIN; - } else if (writable) - return av_buffer_make_writable(dst); + for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i++) + fd->wallclock[i] = INT64_MIN; + } + } return 0; } |