[Reproduced please indicate the source] :Juejin. Cn/post / 684490…

1. Kurento

The main component of Kurento is the Kurento Media Server (KMS), which is responsible for media transfer, processing, recording and playback. KMS is built on top of the excellent GStreamer multimedia library and provides the following features:

  • Network traffic protocols, including HTTP, RTP and WebRTC.
  • Support media mixing and media routing/scheduling group communication (MCU and SFU functions).
  • General support for filters that implement computer vision and augmented reality algorithms.
  • Media storage supportWebMandMP4Write operations andGStreamerSupports playback of all formats.
  • GStreamer supports automatic media transcoding between any codec, including VP8, H.264, H.263, AMR, OPUS, Speex, G.711, etc.

Kurento design principles

Kurento’s design is based on the following main principles:

  • Separate media and signaling planes Signals and media are two separate planes so that applications can handle those aspects of multimedia processing separately.
  • Distribution of Media and application services Kurento Media Server and applications can be juxtaposed, upgraded or distributed across different machines. One application can call multiple Kurento Media Server services. The opposite is also true, where Kurento Media Server can accommodate requests from multiple applications.
  • Kurento is suitable for integration into a cloud environment to act as a PaaS (platform as a Service) component.
  • Linking media elements through media pipes is an intuitive way to challenge the complexity of multimedia processing.
  • Application development Developers do not need to understand the complexities of the internal Kurento Media Server: all applications can be deployed in whatever technology or framework the developer prefers, from client to Server. From browsers to cloud services.
  • End-to-end communication capabilities Kurento provides end-to-end communication capabilities so developers don’t have to deal with the complexities of transferring, encoding/decoding and rendering media on client devices.
  • Fully processable media streaming Kurento supports not only interactive human communication (e.g. Skype with push/receive conversational call capabilities), but also human-machine communication (e.g. Video-on-demand via live streaming) and human-machine communication (e.g. Remote video recording), multi-sensor data exchange.
  • Modularization of media processing Modularization through media elements and pipes allows the definition of an application’s media processing capabilities through a “graphic-oriented” language, where application developers can create the required logic by linking the appropriate functionality.
  • Auditable processing Kurento is capable of generating rich and detailed information for QoS monitoring, billing, and auditing.
  • Seamless IMS Integration Kurento is designed to support seamless integration into the IMS infrastructure of telephone carriers.
  • Transparent Media Adapter Kurento provides a transparent media adapter to enable convergence between different devices with different requirements in terms of screen size, power consumption, transmission rate and so on.

Kurento modular system

Kurento is designed as a pluggable framework, and each plug-in in Kurento is called a module that can be extended with new custom modules. For more information, read the Kurento module section.

Kurento modules fall into three categories:

  • Main modules merged with Kurento Media Server out of the box:

    • KMS – Core: The main component of Kurento Media Server.
    • KMS Elements: Implementation of Kurento Media Elements (WebRtcEndpoint, PlayerEndpoint, etc.)
    • Kms-filters: Implementation of Kurento filters (FaceOverlayFilter, ZBarFilter, etc.)
  • Built-in modules Additional modules developed by the Kurento team to enhance the basic functionality of Kurento Media Server. So far there are four built-in modules, which are:

    • Kms-pointerdetector: Filters that detect Pointers in video streams based on color tracking.
    • Kms-chroma: Filter that uses the color range on the top layer and makes it transparent to display another image behind it.
    • Kms-crowddetector: Filter used to detect human clustering in video streams.
    • Kms-platedetector: Filter used to detect license plates in video streams.
  • An extension of the custom module Kurento Media Server that provides new Media functionality.

2. Install the EPEL mirroring source

yum update
# RHEL/CentOS 7:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
# RHEL/CentOS 8:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm 
Copy the code

3. Install the docker

# Uninstall the old version (if any)
yum remove docker  docker-common docker-selinux docker-engine
Install the required software package
yum install -y yum-utils device-mapper-persistent-data lvm2
Set the docker source
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Can use Aliyun Docker source
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# installation docker
yum install docker-ce docker-ce-cli containerd.io
# start docker
systemctl start docker
# Boot automatically
systemctl enable docker

# View KMS logs
docker logs kms
# Real-time view:
docker logs -f kms
Copy the code

4. Install kurento

Install the latest version of Kurento
docker pull kurento/kurento-media-server:latest
# start mirror
docker run --name kms -d -p 8888:8888  kurento/kurento-media-server:latest
Copy the code

The Kurento Media server port (KMS) procedure listens for 8888 client WebSocket connections by default.

Docker logs –follow KMS >” KMS -$(date ‘+%Y%m%dT%H% m% S’).log” 2>&1

To check that KMS is up and listening for connections, use the following command:

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
Copy the code

You should get a response similar to the following:

HTTP/1.1 500 Internal Server Error
Server: WebSocket++/0.7.0
Copy the code

Ignore the “Server Error” message: This is expected, and it actually proves that KMS has started and is listening for connections.

5. Install coturn

# install dependencies
yum install -y openssl-devel libevent-devel git

# clone source
git clone https://github.com/coturn/coturn.git 
cd coturn 
./configure 
make 
sudo make install

# start turnserverNohup turnserver -l 0.0.0.0-a -u kurento:kurento123pwd -v -f -r zhaolong.org &
Then check whether the process exists on port 3478
sudo lsof -i:3478
Copy the code

In this way, it indicates that the turnserver can be started. Next, let’s stop the turnserver and reconfigure it. Turnserver default. Load the configuration file is/etc/turnserver conf or/usr/local/etc/turnserver. Conf.

cp /usr/local/etc/turnserver.conf.default /usr/local/etc/turnserver.conf
openssl req -x509 -newkey rsa:2048 -keyout /usr/local/etc/turn_server_pkey.pem -out /usr/local/etc/turn_server_cert.pem -days 99999 -nodes
Copy the code

Turnserver default using the SQLite database, if it is need to use the MySQL or PostgreSQL, first need to initialize the database, SQL position in/usr/local/share/turnserver/schema. The SQL.

Changes to turnServer. conf:

# set the forwarding IP (LAN IP), if not, he will choose the default
relay-ip=xx.xx.xx.xx

# Extranet IP address for NAT mapping
external-ip=xx.xx.xx.xx

The number of threads to forward is better not set by default
relay-threads=5

UDP minimum port and maximum port
min-port=40000
max-port=60000

Will be used in the # WebRTC message
fingerprint

# WebRTC certification required
lt-cred-mech

Relay server listener IP addressListening - IP = 0.0.0.0# static account
user=kurento:kurento

# Redis DB for state information
redis-statsdb="ip=xx.xx.xxx.xx dbname=3 password=xxxx port=6379 connect_timeout=30"

# User login domain
realm=zhaolong.org

# certificate
cert=/usr/local/etc/turn_server_cert.pem

Certificate of # key
pkey=/usr/local/etc/turn_server_pkey.pem
 
# the log output
log-file=stdout

mobility
Copy the code

Restart the TurnServer

nohup turnserver >> /var/tmp/turn.log &
Copy the code

Remember to open ports for use:

You can use this url to test the effectiveness of the stun and turn: webrtc. Making. IO/samples/SRC…

To test stun, you do not need to enter the account password. You only need to enter STUn:

To test turn, enter the turn address, beginning with TURN:, and the account password

5. Configure kurento server

Go to kurento’s image and edit kurento’s configuration file:

# enter mirror
docker exec -it kms /bin/bash
# install vim
apt-get update
apt-get install vim
Go to the configuration folder
cd /etc/kurento/modules/kurento/
Edit the configuration file
vim WebRtcEndpoint.conf.ini
Copy the code

Modify stuN and TURN information

stunServerAddress=xx.xx.xx.xx stunServerPort=pp turnURL=username:[email protected]:pp? transport=tcpCopy the code

Restart the Kurento container

View the currently started containerDocker ps docker restart {kurento ID}Copy the code

6. kurento-hello-world

git clone https://github.com/Kurento/kurento-tutorial-java.git
cd kurento-tutorial-java/kurento-hello-world
vim src/main/resources/static/js/index.js
Copy the code

Inside function uiStart(), add a variable called iceservers of the following format:

 var iceservers={
    "iceServers":[
        {
          urls:"stun:xx.xx.xx.xx:3478"
        },
        {
          urls:["turn:xx.xx.xx.xx:3478"]
            username:"xxxx",
            credential: "xxxx"}}]Copy the code

Then modify the options variable below:

 const options = {
    localVideo: uiLocalVideo,
    remoteVideo: uiRemoteVideo,
    mediaConstraints: { audio: true, video: true },
    onicecandidate: (candidate) => sendMessage({
      id: 'ADD_ICE_CANDIDATE', candidate: candidate,}), configuration: iceservers // Add a configuration key};Copy the code

Start the project

mvn -U clean spring-boot:run -Dkms.url=ws://xx.xx.xx.xx:8888/kurento
Copy the code

After launching, open the demo page in Google or Firefox https://localhost:8443/ and click Start

At this point, the simplest HelloWorld is complete.

[Reproduced please indicate the source] :Juejin. Cn/post / 684490…