Why should audio and video development learn SRS streaming media server

1 What is SRS

Official definition: SRS is a streaming media cluster that supports RTMP/HLS/HTTP-FLV/RTSP/DASH/WebRTC/SRT/GB28181, which is efficient, stable, easy to use, simple and happy. There are nearly 10k stars (including https://github.com/ossrs/srs link)
URL: https://github.com/winlinvip/srs (currently the main link maintained by the author)

SRS basic information:
Wiki address, there are hundreds of detailed documents, the first starting material: https://github.com/ossrs/srs/wiki
Git branch, you can see the source code: https://github.com/winlinvip/ srs
official website, there is an installation package, the client is for everyone to test and experience: http://www.ossrs.net/srs.release/releases/

2 What problems can SRS solve

2.1 Engineering case
SRS supports a lot of features. Needless to say, traditional RTMP live broadcast applications, let's talk about some new trends here.
Case 1: Traditional video surveillance clients are all Windows pc desktop clients. Now many companies need to view remote video surveillance through the web. At this time, they can push to the SRS streaming media server through RTSP/GB28181. Then use RTMP or HTTP-FLV protocol to pull the stream to view the remote camera.
Case 2: The traditional push end needs to install application software to realize push, but there is also a web-based trend. It is necessary to push the audio and video pictures to the audience through the browser web page, and then it can be pushed to the audience through WebRTC. SRS streaming media server, and then viewers watch the live broadcast through RTMP, HTTP-FLV, etc.
2.2 Technical reserves
As a streamer, you need to be proficient in protocols such as RTMP/HLS/HTTP-FLV/RTSP/DASH/WebRTC. How to be proficient?
• It’s useless to just look at the protocol manual.
• It’s useless to find articles on Baidu. It is
recommended that you analyze the SRS source code in depth:
• The logic of the SRS source code is very clear
• The official website github also provides detailed wiki documentation and a large number of issues
• A large number of Issues are all problems encountered in engineering and how to solve them. It is very helpful for our interviews and job development.
• Supports small-scale clusters in forward mode and large-scale clusters in edge mode
. One point that everyone needs to pay special attention to is that you are learning SRS When it comes to source code, Baidu's search for SRS articles is definitely only an aid, and it cannot actually solve how we learn SRS. I suggest you: (1) Read the official wiki of srs; (2) Use debugging tools such as gdb to track the code.
For specific learning methods, please refer to section 4 How to learn SRS.

3 Does SRS have commercial applications?

Some friends are worried about whether SRS can be applied to commercial projects and whether it is of commercial use. Go to the recruitment website and search to see if a large company needs to master the server when recruiting. For example, if you enter SRS directly in the boss, I Only the recruitment needs of 3 companies are listed here.
Insert picture description here
Insert picture description here
Insert picture description here

It can be seen from the recruitment results that if we are applying for streaming media-related positions, mastering SRS streaming media is a must or a bonus item. This also illustrates the needs of SRS streaming media server in actual development.

4 How to learn SRS

To learn SRS streaming media server, it is recommended to read less Baidu, read more official wiki and practice by yourself:

  1. Watch wiki
  2. Code tracking via gdb
  3. Analyze the srs framework with gdb
  4. Analyze the specific implementation of RTMP/HLS/HTTP-FLV/RTSP/WebRTC in combination with streaming media protocols.
    Take the official RTMP deployment as an example: https://github.com/ossrs/srs/wiki/v1_CN_SampleRTMP

conf/rtmp.conf

listen 1935;
max_connections 1000;
vhost defaultVhost { } here involves port 1935, we can also infer from this, the configuration file is configured with port 1935, then RTMP is to listen on this port. To listen to this port, you must read the listen field. For example, we search for "listen" in source insight



Insert picture description here

From here we can see that the SrsConfig class has to read the "listen" field. In fact, if we click on SrsConfig, we can easily find that all configuration files are read by this class.
Let’s go a step further and focus only on fields like get("listen"), and find
vector SrsConfig::get_listens()
{ std::vector ports;

SrsConfDirective* conf = root->get("listen"); // 从配置文件也可以出来,listen字段是在root
if (!conf) {
    return ports;
}

for (int i = 0; i < (int)conf->args.size(); i++) {
    ports.push_back(conf->args.at(i));
}

return ports;

}
We can use gdb to break at SrsConfig::get_listens

  1. Start with gdb: gdb ./objs/srs

  2. Setting parameters: set args -c ./conf/rtmp.conf

  3. Break point: It is recommended to break the point in the main function first, and then run to the main function and so on after so is loaded, and then break the point in SrsConfig::get_listens, otherwise the following red box will appear.Insert picture description here

  4. After the main breakpoint, run up and stop at the main functionInsert picture description here

  5. Then stop at the main function, you can breakpoint at this timeInsert picture description here

  6. Still report the problem of the red box, then we can breakpoint according to the code position, and breakpoint in srs_app_config.cpp:3983Insert picture description here

Then enter r to restart the program, press c until you enter the rs_app_config.cpp:3983 breakpoint, and then press bt to see that we read the configuration file and monitor the call stack of the rtmp port.Insert picture description here

But at this time, if we look at the call stack and find that it is only checking whether the configuration file is correct, we can continue to enter c, and then enter bt to see the call stack, until we see some listen words in the call.
At this point, you can analyze the framework process of the srs listening port according to the call stackInsert picture description here

You can locate src/app/srs_app_server.cpp:1246 to viewInsert picture description here

At this point, you can find the rtmp monitoring process.
The above is just a small test. For the analysis of the srs framework, I have also recorded some videos here. You can add Junyang 832218493 to get it.

Guess you like

Origin blog.csdn.net/lingshengxueyuan/article/details/108107198