Integrate Local Recording SDK
This page describes how to set up the environment and integrate CloudHub RecordingSDK.
You need to integrate CloudHub RecordingSDK on your Linux server instead of your App. If you don’t want to deploy a Linux server by yourself, you can try Cloud recording.
Recording the audio and video information in a channel is equivalent to adding a special viewer to the channel, and then the viewer will obtain the audio and video information in the channel. Therefore, you must:
- Integrate RecordingSDK on your Linux server;
- Use the same App ID as the audio and video call SDK in the RecordingSDK.
Prepare Environment
- Download the latest RecordingSDK software package. The package contents are as follows:
File | Description |
---|---|
recording_define.h | Basic structure and enumeration value |
recording_engine.h | The interface class of the recording engine |
libcloudhub_recording.so | Recording Engine Library |
Install the compiler GCC 4.8+.
For debugging convenience, it is recommended that you enable the core dump function of the system to record possible program crash information.
Integration steps
1. Initialize RecordingEngine
Before calling other APIs, a RecordingEngine object needs to be created and initialized.
Before that, you need to apply for an APPID, please refer to Create a CloudHub account and get AppId.
When the RecordingEngine is initialized, a callback event handler needs to be provided. For specific information about the event, please refer to Overview.
class EventHandler : public IRecordingEngineEventHandler
{
public:
virtual void onConnectionStateChanged(CONNECTION_STATE state)
{
printf("\n EventHandler::onConnectionStateChanged(%d) \n", state);
}
virtual void onConnectionLost()
{
printf("\n EventHandler::onConnectionLost() \n");
}
virtual void onJoinChannelSuccess(
const char* channelId,
const char* uid
)
{
printf("\n EventHandler::onJoinChannelSuccess(%s, %s) \n", channelId, uid);
}
virtual void onRejoinChannelSuccess(
const char* channelId,
const char* uid
)
{
printf("\n EventHandler::onRejoinChannelSuccess(%s, %s) \n", channelId, uid);
}
virtual void onLeaveChannel()
{
printf("\n EventHandler::onLeaveChannel() \n");
}
virtual void onChannelForceClosed(
const char* channelId,
SERVER_CLOSE_CHANNEL_REASON reason
)
{
printf("\n EventHandler::onChannelForceClosed(%s, %d) \n", channelId, reason);
}
virtual void onTokenWillExpire(const char* token)
{
printf("\n EventHandler::onTokenWillExpire() \n");
}
virtual void onRequestToken()
{
printf("\n EventHandler::onRequestToken() \n");
}
virtual void onLocalUserEvicted(int reason)
{
printf("\n EventHandler::onLocalUserEvicted(%d) \n", reason);
}
virtual void onUserJoined(
const char* uid,
const char* properties,
const char* fromChannelId
)
{
printf("\n EventHandler::onUserJoined(%s) \n", uid);
}
virtual void onUserLeft(const char* uid)
{
printf("\n EventHandler::onUserLeft(%s) \n", uid);
}
virtual void onRemoteVideoStateChanged(
const char* uid,
MEDIA_TYPE mediaType,
const char* sourceId,
const char* streamId,
REMOTE_VIDEO_STATE state,
REMOTE_VIDEO_STATE_REASON reason
)
{
printf("\n EventHandler::onRemoteVideoStateChanged(%s, %s, %d, %d) \n",
uid, streamId, state, reason);
}
virtual void onFirstRemoteVideoFrame(
const char* uid,
MEDIA_TYPE mediaType,
const char* sourceId,
const char* streamId,
int width,
int height
)
{
printf("\n EventHandler::onFirstRemoteVideoFrame(%s, %s, %d, %d) \n",
uid, streamId, width, height);
}
virtual void onRemoteVideoSizeChanged(
const char* uid,
MEDIA_TYPE mediaType,
const char* sourceId,
const char* streamId,
int width,
int height
)
{
printf("\n EventHandler::onRemoteVideoSizeChanged(%s, %s, %d, %d) \n",
uid, streamId, width, height);
}
virtual void onRemoteVideoFrame(
const char* uid,
MEDIA_TYPE mediaType,
const char* sourceId,
const char* streamId,
const VideoFrameI420& frame
)
{
printf("\n EventHandler::onRemoteVideoFrame-I420(%s, %s) \n", uid, streamId);
}
virtual void onRemoteVideoFrame(
const char* uid,
MEDIA_TYPE mediaType,
const char* sourceId,
const char* streamId,
const VideoFrameRgb24& frame
)
{
printf("\n EventHandler::onRemoteVideoFrame-RGB24(%s, %s) \n", uid, streamId);
}
virtual void onRemoteAudioStateChanged(
const char* uid,
REMOTE_AUDIO_STATE state,
REMOTE_AUDIO_STATE_REASON reason
)
{
printf("\n EventHandler::onRemoteAudioStateChanged(%s, %d, %d) \n",
uid, state, reason);
}
virtual void onFirstRemoteAudioFrame(const char* uid)
{
printf("\n EventHandler::onFirstRemoteAudioFrame(%s) \n", uid);
}
virtual void onRemoteAudioFrame(
const char* uid,
const AudioFrame& frame
)
{
printf("\n EventHandler::onRemoteAudioFrame(%s) \n", uid);
}
virtual void onChatMessageArrival(
const char* fromId,
const char* textMsg,
const char* extraData
)
{
printf("\n EventHandler::onChatMessageArrival(%s, %s) \n", fromId, textMsg);
}
virtual void onError(
ERROR_CODE err,
const char* msg
)
{
printf("\n EventHandler::onError(%d, %s) \n", err, msg);
}
};
const char* const appId = "123456"; /* using your appId */
EventHandler handler;
IRecordingEngine* const engine = createRecordingEngine(&handler, "", appId);
if (engine == NULL)
{
printf(" Error! Create engine failed. \n");
return (-1);
}
2. Set video-related configuration
engine->enableRgbVideoFrame(false);
or
engine->enableRgbVideoFrame(true);
3. Join the channel
const ERROR_CODE ret = engine->joinChannel(channelId, token, "");
if (ret != ERR_OK)
{
printf(" Error! joinChannel() failed. ret = %d \n", ret);
return (-1);
}
4. Dealing with events
According to business requirements, it is processed in the related callback function. Please refer to Recording Engine Event Handler.
5. Leave channel
According to business requirements, call leaveChannel
to leave the current channel.
engine->leaveChannel();