位置:libavutil/buffer.h

AVBuffer采用引用计数的数据Buffer的API。

有两个核心对象这个API——AVBuffer和AVBufferRef。

AVBuffer代表数据缓冲区本身,它是私有的,不能直接被调用者调用。我们可以通过AVBufferRef,调用者须要检查两个AVBuffer指针是否指向两个不同的引用在同一数据buffer中。AVBufferRef 代表一个单个引用指向AVBuffer,调用者可以直接调它。

有两个功能函数提供创建一个AVBuffer对象在一个单引用中,av_buffer_alloc()分配置一个新buffer空间。av_buffer_create()负责包装已存在数组的AVBuffer对象。从一个已存在引用,其他的引用将创建通过av_buffer_ref()方法。
使用av_buffer_unref(),交释放这个引用(包含数据引用及计数引用)。

在已经存在的AVBuffer引用中,FFmpeg认为AVBuffer是可写入相关数据的。(不会被标识只读),av_buffer_is_writable() 函数提供是否可write的功能,如果不能将自动创建一个新的可写的buffer。

typedef struct AVBuffer AVBuffer;/*** A reference to a data buffer.** The size of this struct is not a part of the public ABI and it is not meant* to be allocated directly.*/
typedef struct AVBufferRef {AVBuffer *buffer;/*** The data buffer. It is considered writable if and only if* this is the only reference to the buffer, in which case* av_buffer_is_writable() returns 1.*/uint8_t *data;/*** Size of data in bytes.*/int      size;
} AVBufferRef;/*** Allocate an AVBuffer of the given size using av_malloc().** @return an AVBufferRef of given size or NULL when out of memory*/
AVBufferRef *av_buffer_alloc(int size);/*** Same as av_buffer_alloc(), except the returned buffer will be initialized* to zero.*/
AVBufferRef *av_buffer_allocz(int size);/*** Always treat the buffer as read-only, even when it has only one* reference.*/
#define AV_BUFFER_FLAG_READONLY (1 << 0)/*** Create an AVBuffer from an existing array.** If this function is successful, data is owned by the AVBuffer. The caller may* only access data through the returned AVBufferRef and references derived from* it.* If this function fails, data is left untouched.* @param data   data array* @param size   size of data in bytes* @param free   a callback for freeing this buffer's data* @param opaque parameter to be got for processing or passed to free* @param flags  a combination of AV_BUFFER_FLAG_*** @return an AVBufferRef referring to data on success, NULL on failure.*/
AVBufferRef *av_buffer_create(uint8_t *data, int size,void (*free)(void *opaque, uint8_t *data),void *opaque, int flags);/*** Default free callback, which calls av_free() on the buffer data.* This function is meant to be passed to av_buffer_create(), not called* directly.*/
void av_buffer_default_free(void *opaque, uint8_t *data);/*** Create a new reference to an AVBuffer.** @return a new AVBufferRef referring to the same AVBuffer as buf or NULL on* failure.*/
AVBufferRef *av_buffer_ref(AVBufferRef *buf);/*** Free a given reference and automatically free the buffer if there are no more* references to it.** @param buf the reference to be freed. The pointer is set to NULL on return.*/
void av_buffer_unref(AVBufferRef **buf);/*** @return 1 if the caller may write to the data referred to by buf (which is* true if and only if buf is the only reference to the underlying AVBuffer).* Return 0 otherwise.* A positive answer is valid until av_buffer_ref() is called on buf.*/
int av_buffer_is_writable(const AVBufferRef *buf);/*** @return the opaque parameter set by av_buffer_create.*/
void *av_buffer_get_opaque(const AVBufferRef *buf);int av_buffer_get_ref_count(const AVBufferRef *buf);/*** Create a writable reference from a given buffer reference, avoiding data copy* if possible.** @param buf buffer reference to make writable. On success, buf is either left*            untouched, or it is unreferenced and a new writable AVBufferRef is*            written in its place. On failure, buf is left untouched.* @return 0 on success, a negative AVERROR on failure.*/
int av_buffer_make_writable(AVBufferRef **buf);/*** Reallocate a given buffer.** @param buf  a buffer reference to reallocate. On success, buf will be*             unreferenced and a new reference with the required size will be*             written in its place. On failure buf will be left untouched. *buf*             may be NULL, then a new buffer is allocated.* @param size required new buffer size.* @return 0 on success, a negative AVERROR on failure.** @note the buffer is actually reallocated with av_realloc() only if it was* initially allocated through av_buffer_realloc(NULL) and there is only one* reference to it (i.e. the one passed to this function). In all other cases* a new buffer is allocated and the data is copied.*/
int av_buffer_realloc(AVBufferRef **buf, int size);/*** @}*/typedef struct AVBufferPool AVBufferPool;/*** Allocate and initialize a buffer pool.** @param size size of each buffer in this pool* @param alloc a function that will be used to allocate new buffers when the* pool is empty. May be NULL, then the default allocator will be used* (av_buffer_alloc()).* @return newly created buffer pool on success, NULL on error.*/
AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));/*** Allocate and initialize a buffer pool with a more complex allocator.** @param size size of each buffer in this pool* @param opaque arbitrary user data used by the allocator* @param alloc a function that will be used to allocate new buffers when the*              pool is empty.* @param pool_free a function that will be called immediately before the pool*                  is freed. I.e. after av_buffer_pool_can_uninit() is called*                  by the pool and all the frames are returned to the pool and*                  freed. It is intended to uninitialize the user opaque data.* @return newly created buffer pool on success, NULL on error.*/
AVBufferPool *av_buffer_pool_init2(int size, void *opaque,AVBufferRef* (*alloc)(void *opaque, int size),void (*pool_free)(void *opaque));/*** Mark the pool as being available for freeing. It will actually be freed only* once all the allocated buffers associated with the pool are released. Thus it* is safe to call this function while some of the allocated buffers are still* in use.** @param pool pointer to the pool to be freed. It will be set to NULL.*/
void av_buffer_pool_uninit(AVBufferPool **pool);/*** Allocate a new AVBuffer, reusing an old buffer from the pool when available.* This function may be called simultaneously from multiple threads.** @return a reference to the new buffer on success, NULL on error.*/
AVBufferRef *av_buffer_pool_get(AVBufferPool *pool);/*** @}*/#endif /* AVUTIL_BUFFER_H */

AVBufferPool 是用来管理大buffer时的API

调用者必须使用av_buffer_pool_init()创建一个buffer池,无论什么时候需要,通过av_buffer_pool_get(),得到新buffer的引用,和av_buffer_alloc()非常像,当不被引用时,会重新归还给pool,而不用去像AVBuffer那样释放。当调用者不再分配新的buffer时,av_buffer_pool_uninit() 必须调用,表明这个pool将自动释放了(因为这个pool也是一个对象)。分配和释放buffer,是线程安全操作,只要保证没有其他默认alloc的callback在使用。这个结构体是私有的,不能直接被外部使用,外部可以用av_buffer_pool_init(),及av_buffer_pool_uninit()函数。

FFmpeg总结(四)AV系列结构体之AVBuffer、AVBufferRef、AVBufferPool相关推荐

  1. FFmpeg总结(三)AV系列结构体之AVCodecContext

    位置: 描述:主要扩展API的结构体 New fields can be added to the end with minor version bumps. Removal, reordering ...

  2. FFmpeg源代码简单分析:结构体成员管理系统-AVOption

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  3. FFmpeg源代码简单分析:结构体成员管理系统-AVClass

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  4. Linux 字符设备驱动结构(四)—— file_operations 结构体知识解析

    前面在 Linux 字符设备驱动开发基础 (三)-- 字符设备驱动结构(中) ,我们已经介绍了两种重要的数据结构 struct inode{...}与 struct file{...} ,下面来介绍另 ...

  5. FFMPEG中最关键的结构体之间的关系

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrame FFMPEG结构体分析:AVFormatContext FFMPEG结构体分析:AVCodecConte ...

  6. FFMPeg代码分析:AVCodecContext结构体

    在调用avformat_open_input打开文件后,下一步调用av_find_stream_info函数从文件中读取音视频流的信息,而后AVFormatContext的结构体将会将这些信息保存在其 ...

  7. MATLAB基本操作(四):结构体struct元胞数组cell

    一,结构体的使用       1)直接创建法:           [cpp] view plain copy

  8. new 一个结构体数组_每天一个IDA小技巧(四):结构体识别

    之前提到IDA可以将一长串的数组数据声明变成一行数组声明,简化反汇编代码,对于结构体,IDA也同样支持通过各种设置工具来改善结构体代码的可读性. 这篇文章的目标是将[edx+10h]之类的结构体元素访 ...

  9. FFmpeg:浅谈 AVFrame 结构体

    成员变量 struct AVFrame 是一个很基础的类型,顾名思义,主要用来管理解码后的音视频数据: 视频:一个 AVFrame 对象可存储一帧图像. 音频:一个 AVFrame 对象可存储若干个采 ...

  10. 【FFmpeg视频播放器开发】解封装解码流程、常用API和结构体简介(一)

    一.前言 在正式编写 FFmpeg 播放器前,我们需要先简单了解下所要用到的 FFmpeg 库.播放与解码流程.函数和相关结构体. 二.FFmpeg 库简介 库 介绍 avcodec 音视频编解码核心 ...

最新文章

  1. 单列索引和复合索引的使用
  2. linux命令——pwd
  3. LETTers比赛第三场 --1003 大明A+B解题报告
  4. Oracle常用知识
  5. 深度学习网络调试技巧
  6. 关于jquery 1.9以上多次点击checkbox无法选择的
  7. 算法导论的道与术、工程师思维奠定能走多远
  8. Foxmail添加163邮箱账号的方法
  9. Android Sensor感应器简单使用(1)
  10. 关于GIS中Scale和Resolution的那些事儿
  11. Java算法:牛客网哔哩哔哩bilibili笔试真题算法Java版1-14题
  12. 香槟分校计算机专业毕业生去向,2019年伊利诺伊州立大学香槟分校计算机专业排名_托普仕留学...
  13. 【Deodex】Samsung S5/S6/Note4/Note5 Deodex教程
  14. sas 导入csv文件_sas导入txt、csv文件方法
  15. SpringBoot导出word模板并动态渲染数据
  16. python数据分析实战之超市零售分析
  17. Android实现自动点击 - 无障碍服务
  18. JAVA-SE中:集合,IO流,文件与异常
  19. gg 修改器游戏被保护_GG修改器sky光遇脚本下载app_GG修改器光遇脚本2020最新版下载 安卓版 V411.41.41...
  20. 短时间求素数 java

热门文章

  1. Spring IOC(依赖注入的三种方式)
  2. 论文笔记_S2D.73_ICCV2021_单目深度估计的可解释深度网络研究
  3. boost boost::asio::read read_some receive 区别
  4. 什么是端到端的训练或学习?
  5. 论文笔记_S2D.24_2014-ECCV_LSD-SLAM: 基于直接法的大范围单目即时定位和地图构建方法
  6. 根据已有的WSDL文件进行WebService服务开发和部署
  7. HDU-2030-汉字统计
  8. 强推WordPress里的一款代码高亮插件——EnlighterJS
  9. js-权威指南学习笔记21
  10. 1.3 谈谈你对MVC的理解