Kurento Java Tutorial - RTP Receiver¶
This web application consists of a simple RTP stream pipeline: an RtpEndpoint is configured in KMS to listen for one incoming video stream. This stream must be generated by an external program. Visual feedback is provided in this page, by connecting the RtpEndpoint to a WebRtcEndpoint in receive-only mode.
The Java Application Server connects to all events emitted from KMS and prints log messages for each one, so this application is also a good reference to understand what are those events and their relationship with how KMS works. Check Endpoint Events for more information about events that can be emitted by KMS.
This application uses
HTTPS. It will work fine is you run it in
localhost and accept a security exception in the browser, but you should secure your application if running remotely.
For more info, check Configure a Java server to use HTTPS.
Follow these steps to run this demo application:
Install and run Kurento Media Server: Installation Guide.
Install Java JDK and Maven:
sudo apt-get update sudo apt-get install default-jdk maven
Run these commands:
git clone https://github.com/Kurento/kurento-tutorial-java.git cd kurento-tutorial-java/kurento-rtp-receiver/ git checkout 6.10.0 mvn -U clean spring-boot:run -Dkms.url=ws://localhost:8888/kurento
Open the demo page with a WebRTC-compliant browser (Chrome, Firefox): https://localhost:8443/
Click on Start to begin the demo.
Copy the KMS IP and Port values to the external streaming program.
As soon as the external streaming program starts sending RTP packets to the IP and Port where KMS is listening for incoming data, the video should appear in the page.
Click on Stop to finish the demo.
Understanding this example¶
To implement this behavior we have to create a Media Pipeline, composed of an RtpEndpoint and a WebRtcEndpoint. The former acts as an RTP receiver, and the later is used to show the video in the demo page.
To communicate these entities, two WebSockets channels are used:
- A WebSocket is created between the Application Server and the browser client, to implement a custom signaling protocol.
- Another WebSocket is used to perform the communication between the Application Server and the Kurento Media Server. For this, the Application Server uses the Kurento Java Client library. This communication takes place using the Kurento Protocol (see Kurento Protocol).
The complete source code for this tutorial can be found in GitHub.
Application Server Logic¶
This demo has been developed using Java in the server side, based on the Spring Boot framework, which embeds a Tomcat web server within the resulting program, and thus simplifies the development and deployment process.
You can use whatever Java server side technology you prefer to build web applications with Kurento. For example, a pure Java EE application, SIP Servlets, Play, Vert.x, etc. Here we chose Spring Boot for convenience.
This graph shows the class diagram of the Application Server:
These libraries are linked in the index.html page, and are used in the index.js file.