Compile and run the sample project
Updated
Set up, compile, and run the sample Server Gateway project provided by Agora.
Agora provides a runnable sample project with the Server Gateway SDK. This page shows you how to run the sample project to send and receive media streams.
Get the sample project
Download the latest SDK package for your CPU architecture, x86-64 or arm64 (aarch64), from Downloads, and decompress the file. If you need the SDK for another architecture, submit a ticket to technical support.
Compile the sample project
To compile the sample project, take the following steps:
-
In the decompressed package, go to the sample project folder for your CPU architecture:
cd Agora_Native_SDK_for_Linux_SERVER/rtc/examplecd Agora_Native_SDK_for_Linux_SERVER/example -
Run the following commands to build the project and prepare the test data:
# Build the sample project ./build.sh # Sync the video and audio data that the project needs cd out ../sync-data.sh # Add the SDK libraries to LD_LIBRARY_PATH export LD_LIBRARY_PATH=../../sdk:$LD_LIBRARY_PATH
Send media streams from the server
This section shows you how to send media streams from the server with the sample_send_h264_pcm project.
Run the sample
To send H.264 video and PCM audio, run the sample_send_h264_pcm project:
./sample_send_h264_pcm --token YOUR_RTC_TOKEN --channelId demo_channel --videoFile test_data/send_video.h264 --audioFile test_data/send_audio_16k_1ch.pcmReplace YOUR_RTC_TOKEN with your temporary token and demo_channel with your channel name.
Use the same channel name that you used to generate the temporary token.
Use the Web demo to receive streams from the server
To simulate a client that receives the streams in a browser, take the following steps:
-
On a computer or mobile device, open the Agora Web demo and fill in the following fields:
- APP ID: Your App ID. Use the same App ID as the server.
- Channel Name: The channel name that the server uses.
- Token: A valid temporary token.
-
Click Join to receive media streams from the server.
Receive media streams from the client
This section shows you how to receive media streams from a client with the sample_receive_h264_pcm project.
Run the sample
To receive H.264 video and PCM audio, run the sample_receive_h264_pcm project:
./sample_receive_h264_pcm --token YOUR_RTC_TOKEN --channelId demo_channelReplace YOUR_RTC_TOKEN with your temporary token and demo_channel with your channel name.
While the sample runs, the console prints output similar to the following:
[ APP_LOG_INFO ] Subscribe streams from all remote users
[ APP_LOG_INFO ] Start receiving audio & video data ...
[ APP_LOG_INFO ] Created file received_audio.pcm to save received PCM samples
[ APP_LOG_INFO ] onUserAudioTrackStateChanged: userId 4088243221, state 1, reason 0
[ APP_LOG_INFO ] onUserAudioTrackStateChanged: userId 4088243221, state 2, reason 6
[ APP_LOG_INFO ] onUserInfoUpdated: userId 4088243221, msg 0, val 0
[ APP_LOG_INFO ] onUserInfoUpdated: userId 4088243221, msg 4, val 1
[ APP_LOG_INFO ] onUserInfoUpdated: userId 4088243221, msg 8, val 1
[ APP_LOG_INFO ] onUserInfoUpdated: userId 4088243221, msg 1, val 1Use the Web demo to send media streams to the server
To simulate a client that sends streams from a browser, take the following steps:
-
On a computer or mobile device, open the Agora Web demo and fill in the following fields:
- APP ID: Your App ID. Use the same App ID as the server.
- Channel Name: The channel name that the server uses.
- Token: A valid temporary token.
-
Click Join to send media streams to the server.
The server console prints output similar to the following:
[ APP_LOG_INFO ] onUserInfoUpdated: userId 436868190, msg 0, val 1 [ APP_LOG_INFO ] onUserInfoUpdated: userId 436868190, msg 4, val 1 [ APP_LOG_INFO ] onUserInfoUpdated: userId 436868190, msg 8, val 1 [ APP_LOG_INFO ] onUserInfoUpdated: userId 436868190, msg 1, val 1 [ APP_LOG_INFO ] onUserInfoUpdated: userId 436868190, msg 0, val 0 [ APP_LOG_INFO ] onUserInfoUpdated: userId 436868190, msg 1, val 0 [ APP_LOG_INFO ] onUserVideoTrackSubscribed: userId 436868190, codecType 1, encodedFrameOnly 1 [ APP_LOG_INFO ] onUserAudioTrackStateChanged: userId 436868190, state 1, reason 0 [ APP_LOG_INFO ] onUserAudioTrackStateChanged: userId 436868190, state 2, reason 6 [ APP_LOG_INFO ] Created file received_video.h264 to save received H264 frames [ APP_LOG_INFO ] onUserAudioTrackStateChanged: userId 436868190, state 0, reason 7The sample saves the received video to
received_video.h264and the received audio toreceived_audio.pcm.
