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

devtools/2024/10/15 21:29:01/

目录

  • 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.ppmy.cn/devtools/126354.html

相关文章

ubuntu 安装docker, docker-compose

1. 安装curl apt-get update apt upgradeapt install curl 2.安装&#xff1a; curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 3. 验证&#xff1a; docker -v 4. 安装docker-compose : # 下载 curl -L "https://github.com/docker/compose/rel…

【uniapp】使用uniapp实现一个输入英文单词翻译组件

目录 1、组件代码 2、组件代码 3、调用页面 4、展示 前言&#xff1a;使用uniapp调用一个在线单词翻译功能 1、组件代码 2、组件代码 YouDaoWordTranslator <template><view class"translator"><input class"ipttext" type"te…

2024.10.14 软考学习笔记

刷题网站&#xff1a; 软考中级软件设计师在线试题、软考解析及答案-51CTO题库-软考在线做题备考工具

汇总10个AI免费一键生成PPT的网站

一、前言 PPT幻灯片是现代办公和学习中的重要组成部分。它在工作、研究或培训中扮演着重要角色&#xff0c;并能够让观众更好地理解信息。随着当今人工智能技术的快速发展&#xff0c;现在有很多免费的AI PPT生成器可供选择&#xff0c;帮助用户更加便捷地制作出高效且具有较强…

uniapp 编程体验

全局变量 方法一 改App.vue // App.vue export default {globalData: {userInfo: null,token: },onLaunch: function () {// 初始化全局变量this.globalData.userInfo { name: 张三, age: 30 };} }// 在其他页面或组件中访问 const app getApp(); console.log(app.globalDa…

2024 年 04 月编程语言排行榜,PHP 排名创新低?

编程语言的流行度总是变化莫测&#xff0c;每个月的排行榜都揭示着新的趋势。2024年4月的编程语言排行榜揭示了一个引人关注的现象&#xff1a;PHP的排名再次下滑&#xff0c;创下了历史新低。这种变化对于PHP开发者和整个技术社区来说&#xff0c;意味着什么呢&#xff1f; P…

目标检测——Cascade R-CNN算法解读

论文&#xff1a; Cascade R-CNN: Delving into High Quality Object Detection (2017.12.3) 链接&#xff1a;https://arxiv.org/abs/1712.00726 Cascade R-CNN: High Quality Object Detection and Instance Segmentation (2019.6.24) 链接&#xff1a;https://arxiv.org/abs…

设备树与 Linux 内核设备驱动模型的整合

往期内容 总线&#xff1a; 驱动中的device和device_driver结构体-CSDN博客bus总线的相关结构体和注册逻辑-CSDN博客bus中设备驱动的probe触发逻辑和device、driver的添加逻辑-CSDN博客platform bus平台总线详解-CSDN博客 设备树&#xff1a; 设备树语法规则讲解-CSDN博客基于设…