Simplest WebRtc Debugging Development Environment For Linux | Latest Branch Head m112
A Step by Step Guide to ** Compile, Build & Debug** WebRTC Library for Linux OS within 10 minutes.
I have been working with WebRtc and its associated technologies since Jan 2018. I got the motivation to plan a series of blogs about WebRtc research in the simplest way such that fresh candidates can easily understand WebRtc firsthand. When I started working with WebRtc, things weren’t straightforward to understand for such a huge C/C++
stack that comprises a lot of the fields on a single platform. It is being said;
WebRtc is a kind of playground for any kind of Developer and Engineer from different fields of research and development such as Digital Signal Processing, Applied Sciences, Networking, and VoIP.
Please Visit: To Develop WebRtc Library For Android
Today, I am going to present a very simple and explanatory example of a WebRtc debugging environment for Linux OS in the following steps;
- WebRtc Compilation for Linux Box/OS
- Testing WebRtc Default Examples
- Create a Simple WebRtc Example with Clion
Example WebRtc Project: Simple WebRtc Cpp Program For Linux
Prerequisites:
This tutorial assumes that you are on a UNIX-based system, I am on Ubuntu and have tested versions *18.04 LTS* and *20.04 LTS*.
Note: I recommend WebRtc Linux development on Ubuntu 18.04 LTS
WebRtc Compilation for Linux Box/OS:
I have made simple and straightforward steps of WebRtc Compilation.
Strictly Recommended: Don’t Open Multiple Terminal Tabs/Windows to install any dependencies related to WebRTC Prerequisites. Do Every of Your Task Related to WebRTC in One and Only One Terminal’s Tab/Window.
First of all, make sure the following things have already been installed, if not then use these commands to do that:
- sudo add-apt-repository ppa:openjdk-r/ppa
- sudo apt-get install openjdk-8-jdk
- sudo apt-get install pkg-config
- sudo apt-get update
OR Simply Inline Command;
sudo add-apt-repository ppa:openjdk-r/ppa && sudo apt-get install openjdk-8-jdk && sudo apt-get install pkg-config && sudo apt-get update
Some additional Libraries;
- sudo apt update
- sudo apt install libboost-all-dev
- sudo apt-get install -y nlohmann-json-dev
- sudo apt install libwebsocketpp-dev
Let’s kick start compiling WebRtc for Linux OS to set up a development environment. Start the following steps one by one. Every step takes its own time based on the *machine specs* and *internet speed*, so make sure every step is completed without interruption.
#!/bin/bash
# Cloning the depot_tools repository, which contains the gclient utility
echo "Cloning the depot_tools repository..."
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# Add depot_tools to the end of your PATH
echo "Setting the PATH environment variable..."
export PATH="$PATH:${HOME}/depot_tools"
# Create a new directory for the WebRTC checkout and enter it
echo "Creating a new directory for the WebRTC checkout..."
mkdir webrtc_linux
cd webrtc_linux
# Fetch the WebRTC codebase without running hooks
echo "Fetching the WebRTC codebase..."
fetch --nohooks webrtc
# Sync the WebRTC dependencies with gclient
echo "Syncing dependencies..."
gclient sync
# Navigate into the src directory
echo "Navigating into the src directory..."
cd src
# Install build dependencies
echo "Installing build dependencies..."
./build/install-build-deps.sh
# Fetch the specific remote branch reference
echo "Fetching the remote branch reference..."
git fetch origin refs/branch-heads/5615
# Checkout the specific branch (branch-heads/m112)
echo "Switching to the branch-heads/m112 branch..."
git checkout -b m112 FETCH_HEAD
# Sync the dependencies again after checking out a new branch
echo "Syncing dependencies again after checking out a new branch..."
gclient sync
# Generate project files using the gn tool with custom arguments
echo "Generating project files..."
gn gen out/Debug --args='is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=true rtc_enable_protobuf=false use_rtti=true use_custom_libcxx=false treat_warnings_as_errors=false use_ozone=true'
# Compile the project using the Ninja build system
echo "Compiling the project..."
ninja -C out/Debug
- Open your favorite text editor. If you’re unsure what to use, `nano` or `vim` in the terminal could be a simple choice. You can start it with the following command:
bash nano build_webrtc_linux.sh
- Copy the bash script content and paste it into the text editor.
- Save the file and close the text editor. If you are using
nano
, you can do this by pressingCTRL + X
, thenY
to confirm the save, and finallyEnter
to confirm the file name. - Now you need to give the script permission to execute. You can do this with the following command in the terminal:
chmod +x build_webrtc_linux.sh
Now, the bash script is ready to run! You can start it with the following command:
./build_webrtc_linux.sh
It turns out that you will end up with the compilation and building of libwebrtc.a
in the /webrtc_linux/src/out/Debug/obj/
directory. Now you can use this WebRtc Static Library in your project to develop and debug WebRtc Native C++ Stack;
Testing WebRtc Default Examples:
Once you have successfully compiled the WebRtc library for Linux, then initially you can test the WebRtc generated small programs to verify that your compilation process is 100%
accurate;
Just go to this directory: /webrtc_linux/src/out/Debug/
Here you will see a list of test programs to observe the basic and simple implementation of the WebRtc native stack;
- Green Colored Files are WebRtc Test Programs
To run any program, simply use the following command for any of the programs; Make sure you are in this directory: /webrtc_linux/src/out/Debug/
Terminal Tab-A
- ./peerconnection_server
Terminal Tab-B
- ./peerconnection_client # Peer-A
Terminal Tab-C
- ./peerconnection_client # Peer-B
The result on Tab-A:
By using the same technique, you can test other compiled programs as well. At this point, we are very confident that our WebRtc compiled libs are 100% accurate.
Create a Simple WebRtc Example with Clion:
Now, we will build a simple CPP program based on **CMake**. You can use an IDE of your own choice, but for this tutorial, I am using CLion IDE for CPP development and debugging.
Create a simple CPP based project or simply clone this project's example from Github; Simple WebRtc Cpp Program For Linux
Program CMakeLists.txt File:
Here is the CMakeLists.txt
file of our program:
Now, we have to implement main.cpp
file that will include the WebRtc program basic logic; Here is the reference file;
The reference to other files that are being used in this sample program is available in this Github repo; Simple WebRtc Cpp Program For Linux.
Now, when you simply build the project, it will successfully compile. The resultant output of the program in debug mode is as follows;
The resultant output of the program in console mode is as follows;
When you run this program, you will come up with the following list of commands to generate SDPs and ICE Candidates
*** Welcome to WebRtc Debugging Development Environment ***
> Please follow these commands to use this program <
1. sdp1 -> To Generate SDPs for Peer-A
2. sdp2 -> To Generate SDPs for Peer-B
3. ice1 -> To Generate Ice Candidates for Peer-A
4. ice2 -> To Generate Ice Candidates for Peer-B
5. ; -> To terminate RTC Thread Session.
Resultant output at the console:
When you type sdp1
command, the result will be like this;
:140071081162560:Main thread has initiated...
> sdp1
:140071081162560:create_offer_sdp
:140071046182656:PeerConnectionObserver::RenegotiationNeeded
> :140071046182656:CreateSessionDescriptionObserver::OnSuccess
:140071046182656:PeerConnectionObserver::SignalingChange(1)
Offer sdp:begin
v=0
o=- 1381929178758113972 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=ice-ufrag:Zw7U
a=ice-pwd:fhNYQwc7IWGYYUR2Mrbsi9Qa
a=ice-options:trickle
a=fingerprint:sha-256 10:0B:68:35:3F:20:65:48:0D:67:7E:DF:3F:2A:4F:ED:A1:CE:79:CF:D8:B1:AE:D0:57:59:BB:C6:4A:DD:91:8C
a=setup:actpass
a=mid:data
a=sctp-port:5000
a=max-message-size:262144
Offer sdp:end
:140071046182656:SetSessionDescriptionObserver::OnSuccess
:140071046182656:PeerConnectionObserver::IceGatheringChange(1)
:140071046182656:PeerConnectionObserver::IceCandidate
:140071046182656:PeerConnectionObserver::IceCandidate
:140071046182656:PeerConnectionObserver::IceCandidate
:140071046182656:PeerConnectionObserver::IceGatheringChange(2)
When you type ice1
command, the output will be like this;
> ice1
[
{
"candidate": "candidate:1021689336 1 udp 2122260223 192.168.1.160 44302 typ host generation 0 ufrag Zw7U network-id 3 network-cost 50",
"sdp_mid": "data",
"sdp_mline_index": 0
},
{
"candidate": "candidate:1919303944 1 tcp 1518280447 192.168.1.160 53703 typ host tcptype passive generation 0 ufrag Zw7U network-id 3 network-cost 50",
"sdp_mid": "data",
"sdp_mline_index": 0
},
{
"candidate": "candidate:3182279500 1 udp 1686052607 110.93.193.154 44302 typ srflx raddr 192.168.1.160 rport 44302 generation 0 ufrag Zw7U network-id 3 network-cost 50",
"sdp_mid": "data",
"sdp_mline_index": 0
}
]
Conclusion:
I have tried my best to cut this tutorial as simple as possible to give newbies a good example to Kick starts the *WebRtc debugging* across core Linux development. Thanks for your support.
Cheers!
Email: mail2ch.usman@gmail.com
LinkedIn: https://www.linkedin.com/in/muhammdusmanbashir786/