2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
=================================================================
Source code analysis related to FFmpeg memory management:
FFmpeg reference count data buffer related structures: AVBuffer, AVBufferRef Introduction
FFmpeg source code: av_buffer_ref, av_buffer_unref function analysis
=================================================================
Many structures in FFmpeg source code, such as AVPacket and AVFrame, use AVBufferRef and AVBuffer to manage buffers. AVBuffer uses the member variable refcount to record the number of times resources are used and control the release of resources. This article introduces the AVBuffer and AVBufferRef structures.
AVBuffer is an application programming interface for reference counted data buffers, which represents the data buffer itself. It is opaque and cannot be directly accessed by users using the FFmpeg API. Users can only access it indirectly through AVBufferRef. However, it is possible to check whether two different references describe the same data buffer by comparing two AVBuffer pointers.
The AVBuffer structure is declared in the header file libavutil/buffer_internal.h of the FFmpeg source code (the FFmpeg source code version used in this article is 5.0.3):
struct AVBuffer {
uint8_t *data; /**