Create your own media streaming platform [Using Open source technologies] (Part- 1)

This article is for developers who wants to build their own live streaming platform, including media server and web or mobile application with open source technologies.

We will cover this road to audio streaming platform by breaking this series in three parts in first part we will be covering the overview of the application/platform and setting up our own media server on aws platform. In the second part we will cover whole back-end including media manager application and metadata manager. In the third part of the series, we will cover the front-end part.
Part 1: Application introduction and setting up your own media server
So lets start with listing down the high level components that are required to make this project live.
- Middle-ware component [Media server]: So there a few open source media server options even full streaming platforms like Jitsi and OpenVidu, Here we are gonna go with Kurento media server
- Front-end component: Any framework (supporting web-socket connections) would work but here we will go with Ionic 5, Angular with Capacitor.
- Back-end component [Media manager]: After choosing Kurento we have two option for our back-end application language, Java and Node.js. Here we will go with Java [Spring boot- Web socket].
- Back-end component [Metadata service]: This is an optional component, Its mainly for providing metadata or loading metadata in our system. Lets go with Java [Spring boot- Rest api].
Now we can use our local machines to setup the above mentioned components and serve our listeners but we also want to provide 99.9% up-time, So here we are gonna use amazon web services for our infrastructure needs.
Introduction to Kurento
Kurento Media Server (KMS) is a multimedia server package that can be used to develop advanced video applications for WebRTC platforms. It is an Open Source project, with source code released under the terms of Apache License Version 2.0

WebRTC is a set of protocols and APIs that provide web browsers and mobile applications with Real-Time Communications (RTC) capabilities over peer-to-peer connections. It was conceived to allow connecting browsers without intermediate helpers or services, but in practice this P2P model falls short when trying to create more complex applications. For this reason, in most cases a central media server is required.
Some of the Kurento Media Server capabilities

Lets start setting up Kurento media server on our aws account (Create an aws account )
There are various options provided by kurento team for setting up the media server, Like if you already have a instance (any server/ec2 instance) in place then you can use The Kurento Docker image (docker), Now if you do not have any instance ready then there is even a hassle free way using aws cloudformation (Infrastructure as a code).
Kurento team has provided this cloud-formation template which can be used to create an ec2 instance with pre-installed kurento media server: https://s3-eu-west-1.amazonaws.com/aws.kurento.org/KMS-Coturn-cfn-6.15.0.yaml
If you do not want to use any previous ssh key pairs, then you need to create a new one from the aws ec2 console (Key pairs option in Network & Security menu item)

Once the installation is complete you can ssh into your newly created instance with ubuntu as username and our key pair.

To verify that the Kurento process is up and running you need to run ps -fC kurento-media-server command and see your running process.

To check whether KMS is up and listening for connections, use the following command and do not worry here 500 Error is fine :):
curl \
--include \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: 127.0.0.1:8888" \
--header "Origin: 127.0.0.1" \
http://127.0.0.1:8888/kurento
Now media server setup is complete but what happens to the public ip of your ec2 instance if the you stop and start the ec2 instance ? Yes it will change. So what we can do is we can attach an Elastic IP(An Elastic IP address is a reserved public IP address that you can assign to any EC2 instance) to our ec2 instance.

Copy the newly created elastic ip and in the terminal go to this config file and replace the ip with your elastic ip /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
To apply the changes you need to stop and then start the kurento media server, To do that use these commands:
sudo service kurento-media-server stopsudo service kurento-media-server start
Perform same health check steps to insure that the media server is running properly.
Great Now your own media server is up and running.
Ready to stream any kind of media, in any type of way like
One-To-One video call, One-To-One video call with recording and filtering, Many-To-Many video call (Group Call) or One-To-Many broadcast that we will be doing in this series.
That’s all folks
for this part of the series, In the next part we will be going little more deep with the concepts of media server and its interfaces, Also creating our back-end component using Media pipeline and Kurento Endpoints step by step with code snippets.