crtmpserver 运行过程简明分析

crtmpserver 安装 cmake . [root@crtmpserver cmake]# cmake . -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C 阅读详情
crtmpserver.cpp main()函数下的执行过程:

1. SRAND(); //随机数产生过程
2. InitNetworking(); //初始化异步socket资源,调用接口WSAStartup()
3. Variant::DeserializeFromCmdLineArgs(argc, argv, gRs.commandLine) //把命令行带入的参数,序列化到Variant gRs.commandLine
4. NormalizeCommandLine(configFile) //把序列化的参数检查一遍,并把按string类型存储的转化为实际类型存储string configFile
5. Initialize() //主要用于初始化运行前的环境、状态及完善配置信息
6. Run() //循环监听运行socket的状态,并及时进行服务处理
7. Cleanup() //系统退出时,需要做的一些清理工作

crtmpserver.cpp Initialize()函数下的执行过程:

1. Logger::Init(); //用于实例化一个Logger对象
2. Logger::AddLogLocation(pLogLocation); //根据命令行有无”–use-implicit-console-appender”,去添加一个ConsoleLogLocation * pLogLocation 对象。
3. gRs.pConfigFile = new ConfigFile(NULL, NULL); //实例化一个空的配置文件对象
4. splitFileName(configFilePath, fileName, extension); //分割文件名和文件类型
5. gRs.pConfigFile->LoadLuaFile(configFilePath, (bool)gRs.commandLine[“arguments”][“–daemon”]) //load一个lua配置文件,并把所有配置信息放入到pConfigFile指向的对象的Variant _configuration中,并检查配置参数的合理性。
6. gRs.pConfigFile->ConfigLogAppenders()
遍历FOR_MAP(_logAppenders, string, Variant, i)变量,并根据配置信息创建的实例对象(eg. ConsoleLogLocation, FileLogLocation)。
7. IOHandlerManager::Initialize()
主要是把FdStats IOHandlerManager::_fdStats、fd_set IOHandlerManager::_readFds、
fd_set IOHandlerManager::_writeFds三个对象初始化,
并_pTimersManager = new TimersManager(IOHandlerManager::ProcessTimer)、_isShuttingDown = false,其中_fdStats为fd的统计信息对象,_readFds为读取的socket集,_writeFds为写出的socket集。
8. gRs.pConfigFile->ConfigModules()
遍历FOR_MAP(_applications, string, Variant, i)变量,把map<string, Module> _modules填充满,并调用Module.Load()函数,把每个应用模块对应的dll加载进来,并根据加载的dll句柄,获取相应的接口函数指针去初始化getApplication、getFactory两个函数指针。
9. gRs.pProtocolFactory = new DefaultProtocolFactory()
实例化一个DefaultProtocolFactory对象,DefaultProtocolFactory—>BaseProtocolFactory(构造函数中只产生一个uint32_t _id)。
10. ProtocolFactoryManager::RegisterProtocolFactory(gRs.pProtocolFactory)
把第9步创建的默认协议工厂对象注册到协议工厂管理器中,注册过程中,首先检查协议工厂_id是否已经存在于_factoriesById中,如 果没有就继续注册下去,协议工厂调用HandledProtocolChains()接口,返回支持的协议链名的向量,并检查每个协议链名是否存在于_factoriesByChainName中,如果没有就继续注册下去,然后协议工厂调用HandledProtocols()接口去返回支持的协议id的向量,并检查每个协议id是否存在于_factoriesByProtocolId变量中,如果没有就注册成功。

map<uint32_t, BaseProtocolFactory *> ProtocolFactoryManager::_factoriesById;
map<uint64_t, BaseProtocolFactory *> ProtocolFactoryManager::_factoriesByProtocolId;
map<string, BaseProtocolFactory *> ProtocolFactoryManager::_factoriesByChainName;

11. gRs.pConfigFile->ConfigFactories()
遍历FOR_MAP(_modules, string, Module, i)变量,根据第8步获得的getFactory函数指针去生成一个协议工厂赋值给Module中的协议工厂变量BaseProtocolFactory *pFactory,并把此协议工厂变量注册到协议工厂管理器当中。
12. gRs.pConfigFile->ConfigAcceptors()
遍历FOR_MAP(_modules, string, Module, i)中的变量,再遍历FOR_MAP(config["acceptors"], string, Variant, i)中的变量,根据
acceptors对应的每一个形如

{
    ip="0.0.0.0",
    port=1935,
    protocol="inboundRtmp"
}

的变量执行BindAcceptor()接口,过程如下:
1. 首先根据协议链名调用
vector<uint64_t> chain = ProtocolFactoryManager::ResolveProtocolChain(node[CONF_PROTOCOL]);生成
协议链名对应的协议id所构成的向量,然后判断向量的第一个元素是TCP还是UDP协议去生成相应的TCPAccpetor对象。
2. TCPAcceptor *pAcceptor = new TCPAcceptor(node[CONF_IP], node[CONF_PORT], node, chain);
初始化IOHandler的_id、_type = IOHT_ACCEPTOR,并记录端口、IP地址、协议id向量、acceptor子节点参数;并把此IOHandler注册到IOHandlerManager中,注册过程就是:
首先,根据IOHandler的_id注册到map<uint32_t, IOHandler *> IOHandlerManager::_activeIOHandlers;
然后,根据IOHandler的_type调用_fdStats.RegisterManaged(pIOHandler->GetType());注册到_fdStats中,更新其统计。
3. 调用pAcceptor->Bind()接口,
首先,完成socket创建,并赋值给_inboundFd、_outboundFd变量;
然后,setFdOptions(_inboundFd, false),
然后,绑定bind(_inboundFd, (sockaddr *) & _address, sizeof (sockaddr)
最后,监听listen(_inboundFd, 100)
13. gRs.pConfigFile->ConfigInstances()
do nothing, windows server don’t support multiple instance.
14. IOHandlerManager::Start()
do nothing.
15. gRs.pConfigFile->ConfigApplications()

1. pApplication = getApplication(config); // 应用对象的创建

遍历FOR_MAP(_modules, string, Module, i)中的_modules,调用每个Module的接口函数ConfigApplication(),在其内部调用第8步配置的函数指针getApplication去生成应用程序对象(eg. AdminApplication),应用程序对象都是继承自BaseClientApplication类。
在此对象创建过程中,AdminApplication只是把_pRTMPHandler = NULL (类型为RTMPAppProtocolHandler *),
然后其基类对象BaseClientApplication完成的事情就比较多:_id(应用id编号)、_configuration(此应用的配置)、_name(应用名)、_aliases(应用程序别名)、_isDefault(是不是默认应用)、
_allowDuplicateInboundNetworkStreams(是否允许复制入站网络流)、_hasStreamAliases(流别名)
基类对象有一个类型为StreamsManager类的变量_streamsManager(this = 实例对象AdminApplication) ,其构造函数也仅仅是记录实际的应用_uniqueIdGenerator = 1、_pApplication = AdminApplication;

2. ClientApplicationManager::RegisterApplication(pApplication) //应用对象添加到ClientApplicationManager

a. 检查应用的id是否在_applicationsById; b. 检查应用的name、aliases是否在_applicationsByName c. 检查是否是默认应用

3. pApplication->Initialize()

a. BaseClientApplication::Initialize() //do nothing
b. _pRTMPHandler = new RTMPAppProtocolHandler(_configuration) (BaseAppProtocolHandler*)
RTMPAppProtocolHandler()构造函数do nothing
BaseRTMPAppProtocolHandler()构造函数记录以下变量值:
_keyframeSeek、_clientSideBuffer、_seekGranularity、_mediaFolder、_renameBadFiles、_externSeekGenerator、
_enableCheckBandwidth、_lastUsersFileUpdate等变量
BaseAppProtocolHandler()构造函数记录_configuration = configuration
c. RegisterAppProtocolHandler(PT_INBOUND_RTMP, _pRTMPHandler)
往应用程序的map<uint64_t, BaseAppProtocolHandler *> _protocolsHandlers添加Handler,并设置此Handler的应用为应用对象本身。
d. RegisterAppProtocolHandler(PT_OUTBOUND_RTMP, _pRTMPHandler)

4. pApplication->ParseAuthentication()

认证暂时不做分析,等以后有时间再做处理。

5. pApplication->ActivateAcceptors(acceptors)

把应用中acceptors的每一个acceptor都激活,根据acceptor的类型去做相应的处理,以IOHandler的类型为IOHT_ACCEPTOR做讲解:
a. 首先设置此IOHandler的应用为本应用对象(this)
b. 调用此IOHandler的StartAccept()接口,主要是设置好map<int32_t, map<uint32_t, uint8_t> > _fdState关于此Handler,然后更新FdSets. <Handler关联的socket, <Handler的id, Handler对应的状态>>

16. installQuitSignal(QuitSignalHandler) //注册好退出处理函数

crtmpserver.cpp Run()函数执行过程
1. IOHandlerManager::Pulse() //根据此函数的执行结果决定循环是否继续

a. 清空_readFdsCopy、_writeFdsCopy,
b. 把_readFds、_writeFds赋值给_readFdsCopy、_writeFdsCopy
c. 再调用select(MAP_KEY(--_fdState.end()) + 1, &_readFdsCopy, &_writeFdsCopy, NULL, &_timeout)进行socket轮询
d. 遍历FOR_MAP(_activeIOHandlers, uint32_t, IOHandler *, i),检查IOHandler所对应的socket是否在其中,
FD_ISSET(MAP_VAL(i)->GetInboundFd(), &_readFdsCopy) 或者 FD_ISSET(MAP_VAL(i)->GetOutboundFd(), &_writeFdsCopy)
e. 如果存在fdSets中,就调用相应IOHandler的OnEvent
e.1. accept(_inboundFd, &address, &len)
e.2. setFdOptions(fd, false)
e.3. BaseProtocol *pProtocol = ProtocolFactoryManager::CreateProtocolChain(_protocolChain, _parameters)
e.4. 根据accept返回的fd创建TCPCarrier()实例对象,构造函数里面就把设置为可读数据状态、注册到IOHandlerManager中
e.5. pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint());设置pTCPCarrier的协议为远点协议TCPProtocol
e.6. pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 设置远点协议的IOHandler为TCPCarrier
e.7. pProtocol->GetNearEndpoint()->SetApplication(_pApplication); 设置近点协议的应用为本身应用对象(AdminApplication)
e.8. pProtocol->GetNearEndpoint()->GetOutputBuffer()不为NULL,则pProtocol->GetNearEndpoint()->EnqueueForOutbound();
举例:GetNearEndpoint返回InboundRTMPProtocol对象,GetOutputBuffer()实际是调用BaseRTMPProtocol对象中的IOBuffer _outputBuffer;EnqueueForOutbound()实际调用_pFarProtocol->EnqueueForOutbound(),_pFarProtocol为TCPProtocol(),调用TCPProtocol::EnqueueForOutbound(),即是_pCarrier->SignalOutputData(),此函数只是ENABLE_WRITE_DATA
f. 如果在OnEvent()中处理失败就调用EnqueueForDelete()进入状态清理工作,主要是清理_fdState中关于此socket的状态(相应的去设置_readFds、_writeFds的状态),并把IOHandler加入到_deadIOHandlers MAP中

然后在TCPCarrier中做数据的收发动作!根据读写进行相应的操作:
读:

TCPCarrier的_pProtocol为TCPProtocol
a. IOBuffer *pInputBuffer = _pProtocol->GetInputBuffer(); //近点协议带有关于输入的IOBuffer _inputBuffer
以上实际调用TCPProtocol::GetInputBuffer()接口,然后返回TCPProtocol对象的成员 _inputBuffer
b. if (!pInputBuffer->ReadFromTCPFd(_inboundFd, _recvBufferSize, _ioAmount))
c. _pProtocol->SignalInputData(_ioAmount)
在函数内会调用_pNearProtocol->SignalInputData(_inputBuffer),对应调用BaseRTMPProtocol::SignalInputData()接口,在此函数内部进行输入数据的解析。

写:

a. pOutputBuffer = _pProtocol->GetOutputBuffer()
在函数内部调用_pNearProtocol->GetOutputBuffer(),实际调用BaseRTMPProtocol::GetOutputBuffer(),返回
BaseRTMPProtocol的成员IOBuffer _outputBuffer
b. pOutputBuffer->WriteToTCPFd(_outboundFd, _sendBufferSize, _ioAmount)

2. IOHandlerManager::DeleteDeadHandlers(); //
3. ProtocolManager::CleanupDeadProtocols(); //
不藏了!Wireshark 命令、捕获、过滤器大全分享给你 Wireshark,这款广受欢迎的开源网络协议分析工具,堪称网络管理员、网络安全专家和网络爱好者的“显微镜”!它可以帮助我们捕获网络中的数据包,并提供详细的解码和分析能力。本文将为您全面剖析 Wireshark 的强大功能,从基础到高级,让你快速掌握这个神器!💡Wireshark 是一款功能强大的网络协议分析器,最早由 Gerald Combs 于 1998 年开发,经过多年发展,已成为网络诊断和分析的首选工具。 阅读详情

相关推荐

opencv+nvcodec实现视频硬解码

最近遇到一个新项目,AI推理在上,为了方便和节省成本的考虑决定研究下模块。根据官网的说法显卡具有独立的和模块,所以理论上和是独立互不干涉的。以前的项目都只是把显卡当成推理工具,没有将它的功能利用起来,本身也是一种浪费。事实真的有这么丝滑吗?看到这里,如果你真的觉得是白叫的那就真的是了,事实究竟如何,请听我娓娓道来。NVCODEC全称是 NVIDIA VIDEO CODEC,是NVIDIA为绝大多数显卡配置的硬件编解码单元。不一定是所有显卡都有,一般来讲越新的显卡硬件编解码就越强,支持的格式也就越新。

jiexijihe945的博客 1万+

C++ RTMP Server(crtmpserver)常见问题解决方案

C++ RTMP Server(crtmpserver)常见问题解决方案 C++ RTMP Server(简称crtmpserver)是一个开源的RTMP流媒体服务器,它支持RTMP、HTTP-FLV和WebSocket等多种流媒体协议。该项目主要使用C++编程语言开发。 一、项目基础介绍 crtmpserver是一个功能强大的流媒体服务器,适用于实时视频流传输。它的主要特点包括: 支持RTMP...

gitblog_00108的博客 778

【心得】Back trader避坑指南(一)——关于安装过程的问题

我认为一开始比较容易卡住的地方,主要是安装上面的问题。我给大家整理的这个版本是我能跑通的版本,还有一些好用的神器,手把手教你怎么装!

weixin_38347757的博客 1303

crtmpserver 项目教程

crtmpserver 项目教程 1. 项目的目录结构及介绍 crtmpserver 项目的目录结构如下: crtmpserver/ ├── builders │ ├── cmake │ ├── debian │ └── freebsd ├── cmake ├── doc ├── etc │ └── crtmpserver ├── media ├── scripts ├── sbi...

gitblog_01047的博客 376

EB TRESOS 29.0.0安装教程用于MCAL配置开发

本文介绍的搭建基于NXP官网提供EB软件,进行基于标准AUTOSAR软件底层驱动配置的开发

qq_53260940的博客 1877

PIMPL 模式 以及Q_DECLARE_PUBLIC 与 Q_DECLARE_PRIVATE

在 C++ 中,PIMPL 模式通常通过将类的私有数据和实现放在一个单独的类中,然后在类的公共接口中使用指向该私有实现类的指针来实现。宏可以帮助在 Qt 的 PIMPL 模式中实现类的私有实现和公共接口的分离,提高代码的封装性和可维护性。宏的结合使用,我们可以实现类的私有性和封装,避免暴露私有实现的细节,同时提高类的可维护性和灵活性。:这一行声明了一个友元类,使得类的公共接口可以访问私有实现类的私有成员。:这一行声明了一个友元类,使得类的私有实现可以访问类的私有成员。是两个宏,用于实现 PIMPL 模式。

追赶时代的博客 846

crtmpserver安装与使用指南

crtmpserver安装与使用指南 项目介绍 crtmpserver是一款基于C++编写的开源RTMP流媒体服务器。该项目提供基础的RTMP服务,允许实时音视频流的传输。尽管它的功能相比Adobe的Flash Media Server(FMS)更为精简,但crtmpserver以其轻量级和高性能的特点,在直播领域占有一席之地。支持多平台部署,包括x86架构的Linux和Windows服务器,乃至...

gitblog_00344的博客 400

飞牛NAS新增虚拟机功能,如果使用虚拟机网卡直通安装ikuai软路由(如何解决OVS网桥绑定失败以及打开ovs后无法访问飞牛nas等问题)

飞牛NAS新增虚拟机功能,如果使用虚拟机网卡直通安装ikuai软路由

XiaoqiangClub的博客 1万+

crtmpserver流媒体服务器搭建及使用指南

crtmpserver流媒体服务器搭建及使用指南 项目介绍 crtmpserver是一个由C++编写的高性能、开源RTMP流媒体服务器。它旨在提供一种轻量级的解决方案,以替代更重型的商业产品如Adobe Flash Media Server。尽管它的特性不如FMS全面,但crtmpserver覆盖了RTMP协议的基本需求,并适用于多种场景,包括x86架构的Linux、Windows服务器,乃至AR...

gitblog_00022的博客 655

【AI面试】 Python 的装饰器

Python装饰器是一种高阶函数,用于在不修改原函数代码的情况下增强其功能。它通过@语法糖接收目标函数作为参数,并返回一个包含额外逻辑(如日志、缓存、权限验证等)的新函数。装饰器的核心价值在于代码复用和解耦,符合开闭原则,典型应用包括性能分析、权限控制等场景。例如,@timer_decorator可自动为函数添加耗时统计功能。本质上,@decorator等价于func = decorator(func),实际调用的是装饰器返回的包装函数。进阶技巧包括使用@functools.wraps保留原函数元信息。装饰

钱多多先森 184

【Java面试题汇总】JVM篇(2026版)

JVM内存模型、双亲委派模型、类加载机制、内存溢出、垃圾回收机制、内存泄漏、垃圾回收流程、垃圾回收器、G1、CMS、JVM调优

种一棵树最好的时间是十年前,其次是现在 3万+

Ubuntu下安装、编译、运行crtmpserver

一、crtmpserver简介 crtmpserver是一个由C++语言编写的开源的RTMP流媒体服务器。与Adobe公司的商业产品FMS相比,从功能上来说crtmpserver只有FMS的部分功能,与flash player的兼容性也比不上FMS。但如果公司没钱用不起商业的FMS,crtmpserver是一个比较好的替代选择。crtmpserver提供了最常见的RTMP实现。作为开源的高性...

崔杰城的博客 1695

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

crtmpserver运行过程详尽分析

crtmpserver是一个基于RTMP协议的流媒体服务器。下面比较详细的分析了它的处理过程: 1. SRAND(); 它其实是一个宏定义,srand((uint32_t)time(NULL)); srand()就是给rand()提供种子seed的,如果srand每次输入的数值是一样的,那么每次运行产生的随机数也是一样的,srand(n),rand()也就是说,以一个固定的数值作为种子是...

yanlinembed的专栏 955

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

crtmpserver 基本流程分析

最近在研究crtmpserver,这里记录下学习过程,首先我们先分析下基本流程。 1、初始化流程 InitNetworking---初始化网络 Initialize Logger::Init()---初始化日志 lowerCase(extension) == "lua"---加载.lua后缀配置文件 LoadLuaFile Normalize NormalizeLogAppende

wcjy07220114的专栏 4303

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

crtmpserver的安装

下载 svn co --username anonymous --password "" https://svn.rtmpd.com/crtmpserver/branches/1.0 crtmpserver 安装: 1. 按照文档sudo apt-get install g++ subversion cmake make libssl-dev,还是出现 -- T

a19860903的专栏 5045

linux下编译与运行crtmpserver

目录 前言 环境准备及编译 测试 前言 RTMP是Real Time Messaging Protocol(实时消息传输协议)的首字母缩写。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。——摘录自百度。 如果大家想对RTMP有更深的认识,可以参看这篇文章:《带你吃透RTMP》。 本文要处理的是:用c

优快云的博客 580

crtmpserver 配置说明_crtmpserver框架代码详解

一、简介crtmpserver(C++ RTMP Server)是高性能的流媒体服务器,支持以下协议(直播或录制):. 支持Flash(RTMP,RTMPE,RTMPS,RTMPS,RTMPT,RTMPTE). 支持嵌入式设备:iPhone,Android. 支持监控摄像机. 支持IP-TV(MPEG-tS,RTSP/RTCP/RTP)此外,crtmpserver可以作为高性能rendes-vou...

weixin_35914724的博客 319

crtmpserver 配置说明_crtmpserver 流媒体服务器 集群 安装配置

red5单机还是比较不错的,但是官方网站没有文档,不知道集群怎么配置,网查找了半天,只有red5 0.8版本有集群配置。以后的版本看了一下,有集群的插件,但是不知道怎么装插件,就算装好了插件,怎么配置集群,还是不知道啊。没文档坑爹。crtmpserver 流媒体服务器,研究学习,感觉还是不错的,下面说一下,集群配置。一,crtmpserver下载https://github.com/j0sh/cr...

weixin_35436076的博客 365

编译rtmp服务器crtmpserver

参考博客:https://blog.youkuaiyun.com/caoshangpa/article/details/52909991 环境 系统:Windows7 64位 旗舰版 Service Pack1 编译器:Visual Studio 2010 旗舰版 语言:C++ 资源链接 crtmpserver OpenSSL 步骤 一、下载源码,解压得到: 二、用Visual Studio 2010打开源码...

chase_hung的博客 830

crtmpserver分析与组网

简单介绍:crtmpserver是一款不错的开源流媒体server,用c++语言编写,跨平台。官方介绍crtmpserver不仅支持adobe rtmp协议,还支持其他经常使用的协议:. To and from Flash (RTMP,RTMPE, RTMPS, RTMPT...

weixin_30502157的博客 121

crtmpserver框架代码详解

Hank (http://blog.chinaunix.net/uid/26000296.html)版权所有,尊重他人劳动成果, 转载时请注明作者和原始出处及本声明。 一、简介 crtmpserver(C++ RTMP Server)是高性能的流媒体服务器,支持以下协议(直播或录制):  . 支持Flash(RTMP,RTMPE,RTMPS,RTMPS,RTMPT,RTMPTE)  . 支持嵌入式...

zhuquanfu的专栏 445

crtmpserver基本流程分析

1、初始化流程 InitNetworking---初始化网络 Initialize Logger::Init()---初始化日志 lowerCase(extension) == "lua"---加载.lua后缀配置文件 LoadLuaFile Normalize NormalizeLogAppenders 初始化日志配置 NormalizeApplications 初始化监听配

wcjy07220114的专栏 253

关于crtmpserver编译运行及源码修改

1、x86 linux版本编译 X86平台有两种编译方式:使用cmake、直接使用make 一、使用cmake Cd crtmpserver/built/cmake Cmake . Make ./crtmpserver ./crtmpserver.lua   注意:crtmpserver.lua中mediaFolder是用来保存服务器端flv文件的,默认的目录是mediaFolde

weltion的专栏 1663

crtmpserver 配置说明_crtmpserver流媒体服务器的介绍与搭建

前言Adobe的FMS(Flash Media Server)是很好用。但对应着分级授权的是money和有限功能开放。商业的东西既然用不起,也阻碍了我们的技术进步,那就只能求助于开源社区了。而crtmpserver就是FMS的替代者之一1. crtmpserver简介crtmpserver的功能总来说:支持推送给它的rtmp流的接收与播放器请求的分发;rtmp流媒体服务器树状网络集群的构建;支持i...

weixin_39539764的博客 363
上一篇: crtmpserver运行过程详尽分析
下一篇: POCO开源框架-模块加载卸载过程分析
yanlinembed
博客等级 码龄12年 42粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值