FFmpeg 协议初步学习
typedef struct URLContext {
const AVClass *av_class; /**< information for av_log(). Set by url_open(). */
struct URLProtocol *prot;
void *priv_data;
char *filename; /**< specified URL */
int flags;
int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
int is_streamed; /**< true if streamed (no seek possible), default = false */
int is_connected;
AVIOInterruptCB interrupt_callback;
int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */
} URLContext;
1、context 当前执行的上下文环境,事实上说白了就是C的全局变量,用来保存当前模块执行时的多个函数须要使用到的共同变量。每个模块里面都会有一个 context 来表示执行上下文,模块里面的详细实现都要使用到和其相应的 context 。file 协议是在 file.c 中实现的,里面有一个 FileContext, 和一个 AVClass file_class
2、URLContext 中的 av_class 是它自身的 AVClass ffurl_context_class
3、URLContext 中的 prot 是指向详细的协议的,URLProtocol 抽象出了一些接口,上层使用这些接口去操作数据,而在不同的协议里面实现了这些接口。打开的是一个文件协议的话,此时的 prot 就是指向 URLProtocol ff_file_protocol
4、URLContext 中的 priv_data,有点比較难理解,先理解一下 URLProtocol 再回来就比較easy理解一点
typedef struct URLProtocol {
const char *name;
int (*url_open)( URLContext *h, const char *url, int flags);
/**
* This callback is to be used by protocols which open further nested
* protocols. options are then to be passed to ffurl_open()/ffurl_connect()
* for those nested protocols.
*/
int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);
/**
* Read data from the protocol.
* If data is immediately available (even less than size), EOF is
* reached or an error occurs (including EINTR), return immediately.
* Otherwise:
* In non-blocking mode, return AVERROR(EAGAIN) immediately.
* In blocking mode, wait for data/EOF/error with a short timeout (0.1s),
* and return AVERROR(EAGAIN) on timeout.
* Checking interrupt_callback, looping on EINTR and EAGAIN and until
* enough data has been read is left to the calling function; see
* retry_transfer_wrapper in avio.c.
*/
int (*url_read)( URLContext *h, unsigned char *buf, int size);
int (*url_write)(URLContext *h, const unsigned char *buf, int size);
int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
int (*url_close)(URLContext *h);
struct URLProtocol *next;
int (*url_read_pause)(URLContext *h, int pause);
int64_t (*url_read_seek)(URLContext *h, int stream_index,
int64_t timestamp, int flags);
int (*url_get_file_handle)(URLContext *h);
int (*url_get_multi_file_handle)(URLContext *h, int **handles,
int *numhandles);
int (*url_shutdown)(URLContext *h, int flags);
int priv_data_size;
const AVClass *priv_data_class;
int flags;
int (*url_check)(URLContext *h, int mask);
} URLProtocol;
5、URLProtocol 中的 priv_data_size 指的是当前详细实现的 context 的大小,在file协议中就是 FileContext 结构的大小
6、URLProtocol 中的 priv_data_class 指的是当前详细实现的 AVClass,在file协议中就是指向 AVClass file_class
URLProtocol ff_file_protocol = {
.name = "file",
.url_open = file_open,
.url_read = file_read,
.url_write = file_write,
.url_seek = file_seek,
.url_close = file_close,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
.priv_data_size = sizeof(FileContext),
.priv_data_class = &file_class,
};
7、file 协议的详细实现,实现了 URLProtocol 中的接口,而且里面的两个 priv 变量是指的是它自身的 FileContext 结构的大小和 AVClass file_class
8、URLContext 中的 priv_data 指向的事实上是详细协议的 context,在file协议中就是分配的一个 FileContext,FileContext 中的 class 指向的自身的 AVClass ,也就是和 ff_file_protocol 中的 priv_data_class 指向的是同一个AVClass
typedef struct FileContext {
const AVClass *class;
int fd;
int trunc;
int blocksize;
} FileContext;
9、AVClass 眼下还没有发现是干嘛用的,在file协议中好像是和一些设置參数有关,通过參数能够更改 FileContext 中成员的值
static const AVClass file_class = {
.class_name = "file",
.item_name = av_default_item_name,
.option = file_options,
.version = LIBAVUTIL_VERSION_INT,
};
10、找到详细的协议是在 url_find_protocol 函数中查找的,查找是依照协议的名字和 URLProtocol.name 匹配的,假设给到的 filename 是没有写协议的路径,会被直接当做 file 协议。查找到了相关的协议后就要分配 context(比方:FileContext),并设置 URLContext 中的成员,实现是在 url_alloc_for_protocol 函数中
11、avio.c 中维护了一个 URLProtocol 列表,通过 ffurl_register_protocol 函数将协议注冊。这个函数是在 av_register_all 里面触发的,在这里会完毕全部的 codecs,muxers,protocol,libraries 等的注冊
FFmpeg 协议初步学习的更多相关文章
- FFmpeg 结构体学习(七): AVIOContext 分析
在上文FFmpeg 结构体学习(六): AVCodecContext 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVIOContext. AVIOContext是FFMPEG管 ...
- Httprunner初步学习
一:简介 一直在技术博客上看到Httprunner测试框架,但始终不太明白这个框架的具体作用,今天就花点时间来初步学习了解一下. HttpRunner 是一款面向 HTTP(S) 协议的通用测试框架, ...
- 以太坊web3开发初步学习
以太坊web3开发初步学习 此文是对https://learnblockchain.cn/2018/04/15/web3-html/的学习再理解. 以太坊智能合约通过使用web3.js前端和智能合约交 ...
- json2.js的初步学习与了解
json2.js的初步学习与了解,想要学习json的朋友可以参考下. json2.js的初步学习与了解 1.)该js的下载地址是:http://www.json.org/json2.js 2.)在页面 ...
- 老周的ABP框架系列教程 -》 一、框架理论初步学习
老周的ABP框架系列教程 -- 一.框架理论初步学习 1. ABP框架的来源与作用简介 1.1 简介 1.1.1 ABP框架全称为"ASP.NET Boilerplate ...
- 初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助
初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助,如果有bug或者更好的优化方案,也请批评与指正,谢谢,代码如下: var fs = require('f ...
- EF Codefirst 初步学习(二)—— 程序管理命令 更新数据库
前提:搭建成功codefirst相关代码,参见EF Codefirst 初步学习(一)--设置codefirst开发模式 具体需要注意点如下: 1.确保实体类库程序生成成功 2.确保实体表类库不缺少 ...
- FFmpeg 结构体学习(二): AVStream 分析
在上文FFmpeg 结构体学习(一): AVFormatContext 分析我们学习了AVFormatContext结构体的相关内容.本文,我们将讲述一下AVStream. AVStream是存储每一 ...
- FFmpeg 结构体学习(三): AVPacket 分析
在上文FFmpeg 结构体学习(二): AVStream 分析我们学习了AVStream结构体的相关内容.本文,我们将讲述一下AVPacket. AVPacket是存储压缩编码数据相关信息的结构体.下 ...
随机推荐
- 重新想象 Windows 8 Store Apps (22) - 文件系统: 访问文件夹和文件, 通过 AQS 搜索本地文件
原文:重新想象 Windows 8 Store Apps (22) - 文件系统: 访问文件夹和文件, 通过 AQS 搜索本地文件 [源码下载] 重新想象 Windows 8 Store Apps ( ...
- 【原创】leetCodeOj --- Majority Element 解题报告(脍炙人口的找n个元素数组中最少重复n/2次的元素)
题目地址: https://oj.leetcode.com/problems/majority-element/ 题目内容: Given an array of size n, find the ma ...
- 超赞的.NET办公软件库
之前做项目无意中搜到这个站点,一開始以为是国外大牛们的杰作,然后看到联系地址中竟然是四川成都,喔...咱们中国人跟老美.印度人比起来也非常厉害啊. 这个站点一次性提供了word.excel.ppt.p ...
- Cocos2d-x学习笔记(六) 定时器Schedule的简单应用
Cocos2d-x中的定时器使用非常easy,共同拥有3种:schedule.scheduleUpdate和scheduleOnce.简介一下三种的差别: schedule,每隔指定时间运行某个 ...
- 十一:Java之GUI图形Awt和Swing
一. AWT和 Swing AWT 和 Swing 是 Java 设计 GUI用户界面的基础.与 AWT 的重量级组件不同,Swing 中大部分是轻量级组件.正是这个原因,Swing 差点儿无所不能, ...
- Java服务器下载速度的限制
没有取之不尽,用之不竭的资源.server有限的带宽.运营商可以限制一点点.近期使用云存储openstack swift待办事项文件存储下载.如果第一个限速code: private Long wri ...
- CentOS7.0 安装JAVA周围环境
CentOS7.0 安装JAVA周围环境 安装JDK 1.配置JDK环境变量 把下载好的JDK(jdk-7u75-linux-x64.gz)文件上传到 Reg: /home/p2pweb/java/ ...
- AndroidAndroid程序提示和消息button响应事件
首先,接口XML加入button响应函数 android:onClick="OnMyClick" <Button android:id="@+id/button1& ...
- MVC简单的认识
学习一个新知识,首先要了解的就是以下几个问题,它是什么?它能干什么?使用它有什么优点?这篇文章就环绕这几个问题来展开讨论. mvc不是一种编程语言,严格来说.它都不算是一门技术.它是开发软件时使用的一 ...
- Cocos2d-X中间应用
(层)Laye:与球员打交道响应事件Node子类. 不同的场景,层通常包括直接在屏幕上呈现的内容.而且能够接受用户的输入事件.包括触摸,加速度计和键盘输入等. 我们须要在层中加入精灵,文本标签或者其它 ...