Skip to content

Commit

Permalink
fftools/ffmpeg: prepare FrameData for having allocated fields
Browse files Browse the repository at this point in the history
Will be useful in following commits.
  • Loading branch information
elenril committed Mar 13, 2024
1 parent efab83c commit b98af44
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions fftools/ffmpeg.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit b98af44

Please sign in to comment.