CloudHub 文档中心
下载中心 文档中心

本地服务端录制


集成 RecordingSDK

本页介绍如何设置环境以及集成 CloudHub RecordingSDK。

你需要将 CloudHub RecordingSDK 集成在你的 Linux 服务器上而不是你的 App 上。如果你不想自行部署 Linux 服务器,可尝试 CloudHub 云端录制

录制某频道内的音视频信息相当于将一个特殊的观众加入该频道,之后该观众将获取频道内的音视频信息。 因此,你必须:

准备环境

  1. 下载最新的 RecordingSDK 软件包。软件包内容如下:

    文件描述
    recording_define.h基础结构体和枚举值
    recording_engine.h录制引擎的接口类
    libcloudhub_recording.so录制引擎库
  2. 安装编译器 GCC 4.8+。

  3. 为调试方便,建议你打开系统的 core dump 功能以记录可能产生的程序崩溃信息。

集成步骤

1. 初始化 RecordingEngine

在调用其他 API 前,需要创建并初始化 RecordingEngine 对象。

在此之前,需要申请 APPID ,请参考 创建 CloudHub 账号并获取 AppId

初始化 RecordingEngine 时需要提供一个回调事件处理器,关于事件的具体信息,请参考 概览

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. 设置视频相关配置

engine->enableRgbVideoFrame(false);
or
engine->enableRgbVideoFrame(true);

3. 加入频道

const ERROR_CODE ret = engine->joinChannel(channelId, token, "");
if (ret != ERR_OK)
{
    printf(" Error! joinChannel() failed. ret = %d \n", ret);

    return (-1);
}

4. 处理事件

根据业务需求,在相关的回调函数内处理。请参考 Recording Engine Event Handler

5. 离开频道

根据业务需求,调用 leaveChannel 离开当前频道。

engine->leaveChannel();