当前位置: 首页 > news >正文

ffmpeg面向对象——rtsp拉流探索(1)

目录

  • 0.avformat_open_input的rtsp流程程纯净版
  • 1.rtsp拉流流程图
  • 2.rtsp拉流对象图

标准rtsp协议的基石是tcp,本节探索下ffmpeg的rtsp拉流协议tcp的创建及rtsp协商过程。

0.avformat_open_input的rtsp流程程纯净版

ffmpeg拉流,从avformat_open_input接口开始,去除与rtsp拉流无关的代码后,如下:


int avformat_open_input(AVFormatContext **ps, const char *filename,const AVInputFormat *fmt, AVDictionary **options)
{AVFormatContext *s = *ps;FFFormatContext *si;AVDictionary *tmp = NULL;int ret = 0;if (!s && !(s = avformat_alloc_context()))return AVERROR(ENOMEM);si = ffformatcontext(s);if (!s->av_class) {av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n");return AVERROR(EINVAL);}if (options)av_dict_copy(&tmp, *options, 0);if ((ret = av_opt_set_dict(s, &tmp)) < 0)goto fail;if (!(s->url = av_strdup(filename ? filename : ""))) {ret = AVERROR(ENOMEM);goto fail;}if ((ret = init_input(s, filename, &tmp)) < 0)goto fail;s->probe_score = ret;s->duration = s->start_time = AV_NOPTS_VALUE;/* Allocate private data. */if (s->iformat->priv_data_size > 0) {if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) {ret = AVERROR(ENOMEM);goto fail;}if (s->iformat->priv_class) {*(const AVClass **) s->priv_data = s->iformat->priv_class;av_opt_set_defaults(s->priv_data);if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)goto fail;}}if (s->iformat->read_header){if ((ret = s->iformat->read_header(s)) < 0) {if (s->iformat->flags_internal & FF_FMT_INIT_CLEANUP)goto close;goto fail;}}si->raw_packet_buffer_size = 0;update_stream_avctx(s);if (options) {av_dict_free(options);*options = tmp;}*ps = s;return 0;close:if (s->iformat->read_close)s->iformat->read_close(s);
fail:av_dict_free(&tmp);avformat_free_context(s);*ps = NULL;return ret;
}

其中留下了字典参数配置流程,因为基本会有所设置,参数配置参见《ffmpeg面向对象——参数配置机制及其设计模式探索》。

输入格式匹配(看下面流程图会清晰点),参见《ffmpeg面向对象-rtsp拉流相关对象》的第2节。

协议匹配机制(看下面流程图会清晰点),参见《ffmpeg面向对象——拉流协议匹配机制探索》。

输入格式类与协议类什么关系参见《ffmpeg面向对象——AVInputFormat与URLProtocol啥关系》。

这些结合流层图与对象图看会清晰点。

1.rtsp拉流流程图

在这里插入图片描述
rtsp的tcp链接创建在图中最右边。
rtsp协商流程也比较清晰,可以看到ff_rtsp_send_cmd是各个协商方法最终都要调用的中心转发节点。
另外可以看到底层tcp协议读写是如何对接的,结合下面对象图,就能深入理解输入格式类与协议类的关系,它们面向接口编程,各自分层迭代开发,互不影响。

2.rtsp拉流对象图

在这里插入图片描述

可琢磨的比较多,其中,输入格式类与底层协议类型都是“可变的”,因为这两者都是代码运行中匹配出来的,所以它们都被更上一层的进行“托管”。参见《ffmpeg面向对象——priv_data设计原理探索》。


http://www.mrgr.cn/news/50425.html

相关文章:

  • 前沿多模态论文 EI-CLIP 解读
  • tPS+redis限流算法
  • 成交的秘密——高业绩顾问式销售技巧
  • 华为OD机试 - 采样过滤(Java 2024 E卷 100分)
  • ajax地址参数与data参数运用
  • Hutool:国产良心工具包,让你的Java变得更甜
  • 【解决】ORA-12514:无监听程序
  • DOIP协议介绍-1
  • 【Linux】进程控制:从fork到exec
  • Python调用外部脚本后的结果乱码问题解决方案
  • 2020年下半年软件设计师上午真题及答案解析
  • 力扣hot100--二叉树
  • PHP校园帮一键触达便捷无限小程序系统源码
  • 好用的图片翻译软件有哪些?外贸打工人必备的翻译器分享
  • DeepFM模型预测高潜购买用户
  • TPAMI 2024 | HIRI-ViT:具有高分辨率输入的缩放视觉Transformer
  • 分包与粘包
  • 求13张扑克牌的原顺序
  • Windows系统部署redis自启动服务
  • 【头歌平台实验】【使用Matplotlib模块进行数据可视化】【网络机器人相关法律责任】【网页抓取及信息提取】