void av_frame_unref(AVFrame *frame)
{
if (!frame)
return;
frame_side_data_wipe(frame);
for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
av_buffer_unref(&frame->buf[i]);
for (int i = 0; i < frame->nb_extended_buf; i++)
av_buffer_unref(&frame->extended_buf[i]);
av_freep(&frame->extended_buf);
av_dict_free(&frame->metadata);
av_buffer_unref(&frame->hw_frames_ctx);
av_buffer_unref(&frame->opaque_ref);
av_buffer_unref(&frame->private_ref);
if (frame->extended_data != frame->data)
av_freep(&frame->extended_data);
av_channel_layout_uninit(&frame->ch_layout);
get_frame_defaults(frame);
}
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
{
av_assert1(dst->width == 0 && dst->height == 0);
av_assert1(dst->ch_layout.nb_channels == 0 &&
dst->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
*dst = *src;
if (src->extended_data == src->data)
dst->extended_data = dst->data;
get_frame_defaults(src);
}
static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
{
AVBuffer *b;
b = (*dst)->buffer;
if (src) {
**dst = **src;
av_freep(src);
} else
av_freep(dst);
if (atomic_fetch_sub_explicit(&b->refcount, 1, memory_order_acq_rel) == 1) {
/* b->free below might already free the structure containing *b,
* so we have to read the flag now to avoid use-after-free. */
int free_avbuffer = !(b->flags_internal & BUFFER_FLAG_NO_FREE);
b->free(b->opaque, b->data);
if (free_avbuffer)
av_free(b);
}
}
void av_buffer_unref(AVBufferRef **buf)
{
if (!buf || !*buf)
return;
buffer_replace(buf, NULL);
}
420

被折叠的 条评论
为什么被折叠?



