av_packet_unref
该接口使用了如下调用,该接口主要作用是清理AVPacket中的所有空间数据,清理完毕后进行初始化操作,并且将 data 与 size 置为0,方便下次调用。
void av_packet_unref(AVPacket *pkt)
{av_packet_free_side_data(pkt);av_buffer_unref(&pkt->buf);av_init_packet(pkt);pkt->data = NULL;pkt->size = 0;
}
void av_packet_free_side_data(AVPacket *pkt)
接口解析:根据AVPacket中side_data_elems来使用for循环逐个清理其中的数据,最后将side_data_elems置为0
void av_packet_free_side_data(AVPacket *pkt)
{int i;for (i = 0; i < pkt->side_data_elems; i++)av_freep(&pkt->side_data[i].data);av_freep(&pkt->side_data);pkt->side_data_elems = 0;
}
av_freep
void av_freep(void *arg)
{void *val;memcpy(&val, arg, sizeof(val));memcpy(arg, &(void *){ NULL }, sizeof(val));av_free(val);
}
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
{if (!buf || !*buf)return;buffer_replace(buf, NULL);
}
buffer_replace
static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
{AVBuffer *b;b = (*dst)->buffer;if (src) {**dst = **src;av_freep(src);} elseav_freep(dst);if (atomic_fetch_sub_explicit(&b->refcount, 1, memory_order_acq_rel) == 1) {b->free(b->opaque, b->data);av_freep(&b);}
}
av_free参考av_free