Crtmpserver Basic Process Analysis

Source: Internet
Author: User

Recently, we are studying crtmpserver. Here we record the learning process. First, we will analyze the basic process.

1. Initialization Process

Initnetworking --- initialize the network
Initialize
Logger: Init () --- initialize log
Lowercase (Extension) = "Lua" --- load the. Lua suffix configuration file
Loadluafile
Normalize
Normalizelogappenders initialize log Configuration
Normalizeapplications initialize Listener Configuration


GRS. pconfigfile-> configlogappenders () is initialized Based on the configuration
Iohandlermanager: Initialize () initializes Io and clears read/write queues.
GRS. pconfigfile-> configmodules () load the dynamic library worker elector. dll
Protocolfactorymanager: registerprotocolfactory (GRs. pprotocolfactory) load the set of protocols supported by default
GRS. pconfigfile-> configacceptors () Enable listener Based on IP address and port
GRS. pconfigfile-> configinstances () Multi-instance configuration, not supported in win
GRS. pconfigfile-> configapplications () bind the listener to the instance
Installquitsignal: Set the program exit mechanism


Run
Iohandlermanager: pulse () polls socket resources to check whether there are socket operations that require reading and writing.






2. Connect to receive client connection requests
Pulse ()
Fd_isset (map_val (I)-> getinboundfd (), & _ readfdscopy)
Map_val (I)-> onevent (_ currentevent)
Tcpacceptor: accept () Enter accept to create a connection
Baseprotocol * pProtocol = protocolfactorymanager: createprotocolchain creates the Protocol configured for the connection, such as TCP & rtmp, or UDP & RTCP =


Tcpcarrier * ptcpcarrier = new tcpcarrier (FD) creates a TCP interaction object for the connection and binds it to the created protocol object. When the constructor is created, the Read Request is aborted.


Fd_isset (map_val (I)-> getinboundfd (), & _ readfdscopy)
Map_val (I)-> onevent (_ currentevent)
Tcpcarrier: onevent (select_event & event) enters the read branch to read data, analyzes the data read based on the corresponding protocol, fills the _ outputbuffer sending buffer according to the result, and sets the sending signal tcpcarrier :: signaloutputdata () ---> enable_write_data, notifies the pulse to poll the socket status, and then enters the tcpcarrier: onevent (select_event & event) Write branch again to send real data


Rtmp Message Type: rm_invoke_function_connect


3. Publish
This section is part of rtmp protocol interaction.


Rm_invoke_function_releasestream the stream name is not obtained here, and a name request is sent.
Rm_invoke_function_fcpublish the stream name is obtained here.
Rm_invoke_function_createstream
Processinvokecreatestream
Pfrom-> createneutralstream (ID) = NULL
Rtmpstream * pstream = new rtmpstream create an rtmpstream stream control object rtmpstream ---> basestream
Rm_invoke_function_publish
Processinvokepublish
Getapplication ()-> getallowduplicateinboundnetworkstreams () whether the same name exists here
Innetrtmpstream * pinnetrtmpstream = pfrom-> createins (vh_ci (request) Create Network inbound stream
Getapplication ()-> getstreamsmanager ()-> getwaitingsubscribers query whether a connection to this stream is requested and bind pbaseoutstream-> Link (pinnetrtmpstream );
Pinnetrtmpstream-> sendonstatusstreampublished () sends to prepare to receive stream requests
Baseoutfilestream * poutfilestream = createoutfilestream (pfrom, Meta, appending); in addition, if video recording is required, create a file stream connection here.


4. Receive client requests for real-time streams
This section is part of rtmp protocol interaction.


Rm_invoke_function_play
Processinvokeplay
Pfrom-> closestream (vh_si (request), true) closes the stream requested before the connection
Trylinktolivestream (pfrom, vh_si (request), streamname, linked) binds the connection
For_map (inboundstreams, uint32_t, basestream *, I) finds stream input through streamname Query
Baseoutnetrtmpstream * pbaseoutnetrtmpstream = pfrom-> createons (streamid, first create stream output
Pbaseinnetstream-> Link (pbaseoutnetrtmpstream) then binds the stream output to the stream input.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.