Netease interactive live broadcast 2.0 development II main process of interactive wheat connection

 

I. General Process

 

RTC          real time communication 

Netease realtime communication

 

 

The most important thing is the creation and use of NERTC engine

createNERtcEngine()

nertc::IRtcEngine::initialize "initialize"

nertc::IRtcEngine::joinChannel "joinChannel"

nertc::IRtcEngine::leaveChannel "leaveChannel"

nertc::IRtcEngine::release "release"

 

II. Basic interface class: IRtcEngine

IRtcEngine provides the basic functions of SDK

Class is defined as follows:

 /**
 * @namespace nertc
 * @brief namespace nertc
 */
namespace nertc
{
/** RtcEngineContext definition
*/
struct NERtcEngineContext
{
    const char *app_key;		/**< The user registers the APP Key of Yunxin. If there is no APP Key in your development kit, please apply for registration of a new APP Key.*/
    IRtcEngineEventHandlerEx *event_handler;	/**< Used to send callback event notification from SDK to App.*/
    const char *log_dir_path;	/**< The full path of the log directory is encoded in UTF-8.*/
    NERtcLogLevel log_level;	/**< Log level. The default level is kNERtcLogLevelInfo.*/
    uint32_t log_file_max_size_KBytes;	/**< Specifies the maximum size of the SDK output log file, in KB. If set to 0, the default is 20 M.*/
    bool video_prefer_hw_encoder; /**< Video hardware coding is accelerated, and hardware coding video data is preferred. Valid only under mac*/
    bool video_prefer_hw_decoder; /**< Video hardware decoding is accelerated, and hardware decoding is preferred. Valid only under mac*/
    bool video_use_exnternal_render; /**< Whether to use external rendering. The default is false. Valid only under mac*/
};

/** RtcEngine Class provides the main interface methods for App to call.

 IRtcEngine It is the basic interface class of the NERTC SDK. Creating an IRtcEngine object and calling the method of this object can activate the communication function of the NERTC SDK.
 */
class IRtcEngine
{
public:
    virtual ~IRtcEngine() {}

    /** Initialize the NERTC SDK service.

     This method is used to initialize the NERTC service. Pass in Yunxin to initialize the manufacturer's secret key issued by the developer. Create IRtcEngine after calling the createNERtcEngine() method 
	 Object, this method must be called for initialization before other methods can be used. After successful initialization, it is in audio and video call mode by default.

     @warning
     - You must use the same App Key to make a call.
     - An IRtcEngine instance object can only use one App Key. To replace the App Key, you must first call the \ ref IRtcEngine::release "release" method to destroy the current instance, and then call this method to recreate the instance.

     @param[in] context RTC engine context object passed in: NERtcEngineContext
     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int initialize(const NERtcEngineContext& context) = 0;

    /** Destroy the IRtcEngine object.

     @param[in] sync

     - true: Synchronous call. Wait for the IRtcEngine object resource to be released before returning. The App should not call this interface in the callback generated by the SDK. Otherwise, the SDK will wait for the callback to return before recycling the relevant object resources, which will cause a deadlock. The SDK will automatically detect this deadlock and turn it into an asynchronous call, but the detection itself will consume additional time.
     - false: Asynchronous call. Return immediately without waiting for the IRtcEngine object resource to be released. The SDK will release all resources by itself. When using asynchronous calls, be careful not to uninstall the SDK dynamic library immediately after the call, otherwise it may crash because the SDK cleaning thread has not exited.
     */
    virtual void release(bool sync = false) = 0;


    /** Set call mode

     @note It must be set before joining the call. The setting after starting the call is invalid, and the previous setting is retained after ending the call.

     @param[in] profile Scene mode nertchannelprofiletype
     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int setChannelProfile(NERtcChannelProfileType profile) = 0;

    /** Join the channel. If the channel has not been created, it will automatically try to create the channel.

     This method allows users to join the call channel, users in the same channel can talk to each other, and multiple users can join the same channel to group chat. Apps using different App keys cannot be interconnected. If you are already in a call, the user must call \ ref IRtcEngine::leaveChannel "leaveChannel" to exit the current call before entering the next channel.

     @note The user ID of each user in the channel must be unique.
     
     @param[in] token Dynamic key. Low security requirements: set the value to an empty string. High security requirements: set the value to Token. Be sure to use Token if you have enabled it.
     @param[in] channel_name Identify the channel name of the call, a string with a length of less than 64 bytes. The following is the supported character set range (89 characters in total): A-Z, A-Z, 0-9, space,! #$%& ()+-:;& le;.,>? @ []^_ {|}~”
     @param[in] uid User ID.

     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int joinChannel(const char* token, const char* channel_name, uid_t uid) = 0;

    /** Leave the channel.

     Leave the channel, i.e. hang up or exit the call.

     After calling the \ ref IRtcEngine::joinChannel "joinChannel" method, you must call \ ref IRtcEngine::leaveChannel "leaveChannel" to end the call, otherwise you cannot start the next call. No matter whether the call is in progress or not, you can call leaveChannel without side effects. This method will release all resources related to the session.

     This method is an asynchronous operation and does not really exit the channel when the call returns. After exiting the channel, the SDK will trigger the \ ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.

     @note
     - If you call \ ref irtcengine:: release "release" immediately after calling \ ref IRtcEngine::leaveChannel "leaveChannel", the SDK will not be able to trigger the \ ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.

     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int leaveChannel() = 0;

    /** Retrieves the pointer to the device manager object.

     @param iid ID of the interface.
     @param inter Pointer to the *DeviceManager* object.
     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int queryInterface(NERtcInterfaceIdType iid, void** inter) = 0;

    /** Turn on or off local voice acquisition or processing

    This method can restart the local voice function and restart the local audio acquisition and processing.

    This method does not affect receiving or playing remote audio stream.

    @note
    - This method differs from \ ref irtcengineex:: muteloocalaudiostream "muteloocalaudiostream" in that:
    - \ref IRtcEngine::enableLocalAudio "enableLocalAudio": Enable local voice acquisition and processing
    - \ref IRtcEngineEx::muteLocalAudioStream "muteLocalAudioStream": Stop or continue sending local audio streams

    @note This method sets the internal engine to the enabled state and is still valid after \ ref IRtcEngine::leaveChannel "leaveChannel".

    @param[in] enabled
    - true: Turn on the local voice function again, that is, turn on the local voice acquisition or processing (default)
    - false: Turn off the local voice function, that is, stop the local voice acquisition or processing

    @return
    - 0: Method call succeeded;
    - Other: method call failed.
    */
    virtual int enableLocalAudio(bool enabled) = 0;

    /** Set the local view.

     This method sets the local video display information. App binds the display view of the local video stream by calling this interface. In app development, this method is usually called after initialization to set the local video, and then add the channel.

     @param[in] canvas Video canvas information
     @return
	 - 0: Method call succeeded;
	 - Other: method call failed.
     */
    virtual int setupLocalVideoCanvas(NERtcVideoCanvas* canvas) = 0;

    /** Set the remote user view.

     This method binds the remote user and the display view, that is, it sets which view the user specified by uid displays. When calling this interface, you need to specify the uid of the remote video, which can be set in advance before entering the channel.

     If the app cannot know the uid of the other party in advance, it can be set when the app receives the \ ref irtcengineeeventhandler:: onuserjoined "onuserjoined" event.
     After exiting the channel, the SDK will clear the binding relationship of the remote user.

     @param[in] uid Remote user ID.
     @param[in] canvas Video canvas information
     @return
	 - 0: Method call succeeded;
	 - Other: method call failed.
     */
    virtual int setupRemoteVideoCanvas(uid_t uid, NERtcVideoCanvas* canvas) = 0;

    /** Turn on or off local video capture and rendering

    This method enables the local video capture function.

    @note This method sets the internal engine to the enabled state and is still valid after \ ref IRtcEngine::leaveChannel "leaveChannel".

    @param[in] enabled Enable local video:
    - true: Enable local video capture and rendering (default);
    - false: Turn off the use of local camera devices. After closing, the remote user will not receive the video stream of the local user; However, local users can still receive video streams from remote users. When set to false, this method does not require a local camera.

    @return
    - 0: Method call succeeded;
    - Other: method call failed.
    */
    virtual int enableLocalVideo(bool enabled) = 0;

    /** Subscribe / unsubscribe from the video stream of the specified remote user. The other party needs to actively subscribe after opening the video

    @param[in] uid Specifies the user ID of the user.
    @param[in] type Flow type# NERtcRemoteVideoStreamType
    @param[in] subscribe
    - true: Subscribe to the video stream of the specified remote user;
    - false: Unsubscribe from the video stream of the specified remote user.

    @return
    - 0: Method call succeeded;
    - Other: method call failed.
    */
    virtual int subscribeRemoteVideoStream(uid_t uid, NERtcRemoteVideoStreamType type, bool subscribe) = 0;
};

} //namespace nertc

Important are:

1) Initialize

    /** Initialize the NERTC SDK service.

     This method is used to initialize the NERTC service. Pass in Yunxin to initialize the manufacturer's secret key issued by the developer. Create IRtcEngine after calling the createNERtcEngine() method 
	 Object, this method must be called for initialization before other methods can be used. After successful initialization, it is in audio and video call mode by default.

     @warning
     - You must use the same App Key to make a call.
     - An IRtcEngine instance object can only use one App Key. To replace the App Key, you must first call the \ ref IRtcEngine::release "release" method to destroy the current instance, and then call this method to recreate the instance.

     @param[in] context RTC engine context object passed in: NERtcEngineContext
     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int initialize(const NERtcEngineContext& context) = 0;

 

2) Set call mode

    /** Scene mode */
    typedef enum 
    {
        kNERtcChannelProfileCommunication       = 0,    /**< Call scenario */
        kNERtcChannelProfileLiveBroadcasting    = 1,    /**< Live streaming scene */
    } NERtcChannelProfileType;



    /** Set call mode

     @note It must be set before joining the call. The setting after starting the call is invalid, and the previous setting is retained after ending the call.

     @param[in] profile Scene mode nertchannelprofiletype
     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int setChannelProfile(NERtcChannelProfileType profile) = 0;

 

3) Join channel

    /** Join the channel. If the channel has not been created, it will automatically try to create the channel.

     This method allows users to join the call channel, users in the same channel can talk to each other, and multiple users can join the same channel to group chat. Apps using different App keys cannot be interconnected. If you are already in a call, the user must call \ ref IRtcEngine::leaveChannel "leaveChannel" to exit the current call before entering the next channel.

     @note The user ID of each user in the channel must be unique.
     
     @param[in] token Dynamic key. Low security requirements: set the value to an empty string. High security requirements: set the value to Token. Be sure to use Token if you have enabled it.
     @param[in] channel_name Identify the channel name of the call, a string with a length of less than 64 bytes. The following is the supported character set range (89 characters in total): A-Z, A-Z, 0-9, space,! #$%& ()+-:;& le;.,>? @ []^_ {|}~”
     @param[in] uid User ID.

     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int joinChannel(const char* token, const char* channel_name, uid_t uid) = 0;

 

4) Leave channel

    /** Leave the channel.

     Leave the channel, i.e. hang up or exit the call.

     After calling the \ ref IRtcEngine::joinChannel "joinChannel" method, you must call \ ref IRtcEngine::leaveChannel "leaveChannel" to end the call, otherwise you cannot start the next call. No matter whether the call is in progress or not, you can call leaveChannel without side effects. This method will release all resources related to the session.

     This method is an asynchronous operation and does not really exit the channel when the call returns. After exiting the channel, the SDK will trigger the \ ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.

     @note
     - If you call \ ref irtcengine:: release "release" immediately after calling \ ref IRtcEngine::leaveChannel "leaveChannel", the SDK will not be able to trigger the \ ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.

     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int leaveChannel() = 0;

 

5) Turn on or off local voice acquisition or processing

    /** Turn on or off local voice acquisition or processing

    This method can restart the local voice function and restart the local audio acquisition and processing.

    This method does not affect receiving or playing remote audio stream.

    @note
    - This method differs from \ ref irtcengineex:: muteloocalaudiostream "muteloocalaudiostream" in that:
    - \ref IRtcEngine::enableLocalAudio "enableLocalAudio": Enable local voice acquisition and processing
    - \ref IRtcEngineEx::muteLocalAudioStream "muteLocalAudioStream": Stop or continue sending local audio streams

    @note This method sets the internal engine to the enabled state and is still valid after \ ref IRtcEngine::leaveChannel "leaveChannel".

    @param[in] enabled
    - true: Turn on the local voice function again, that is, turn on the local voice acquisition or processing (default)
    - false: Turn off the local voice function, that is, stop the local voice acquisition or processing

    @return
    - 0: Method call succeeded;
    - Other: method call failed.
    */
    virtual int enableLocalAudio(bool enabled) = 0;

 

6) Turn on or off local video capture and rendering

 

    /** Turn on or off local video capture and rendering

    This method enables the local video capture function.

    @note This method sets the internal engine to the enabled state and is still valid after \ ref IRtcEngine::leaveChannel "leaveChannel".

    @param[in] enabled Enable local video:
    - true: Enable local video capture and rendering (default);
    - false: Turn off the use of local camera devices. After closing, the remote user will not receive the video stream of the local user; However, local users can still receive video streams from remote users. When set to false, this method does not require a local camera.

    @return
    - 0: Method call succeeded;
    - Other: method call failed.
    */
    virtual int enableLocalVideo(bool enabled) = 0;

 

7) Set local view

    /** Video display settings */
struct NERtcVideoCanvas
{
    onFrameDataCallback cb; /**< If the data callback is macosx, you need to set the video of NERtcEngineContext_ use_ exnternal_ Render is valid only when it is true*/
    void *user_data;        /**< If the user of data callback transparently transmits data to macosx, the video of NERtcEngineContext needs to be set_ use_ exnternal_ Render is valid only when it is true */
    void *window;           /**< If the rendering window handle is macosx, you need to set the video of NERtcEngineContext_ use_ exnternal_ Render is valid only if it is false*/
    NERtcVideoScalingMode scaling_mode; /**< Video zoom mode */
};





/** Set the local view.

     This method sets the local video display information. App binds the display view of the local video stream by calling this interface. In app development, this method is usually called after initialization to set the local video, and then add the channel.

     @param[in] canvas Video canvas information
     @return
	 - 0: Method call succeeded;
	 - Other: method call failed.
     */
    virtual int setupLocalVideoCanvas(NERtcVideoCanvas* canvas) = 0;

 

8) Set remote user view

 


    /** Set the remote user view.

     This method binds the remote user and the display view, that is, it sets which view the user specified by uid displays. When calling this interface, you need to specify the uid of the remote video, which can be set in advance before entering the channel.

     If the app cannot know the uid of the other party in advance, it can be set when the app receives the \ ref irtcengineeeventhandler:: onuserjoined "onuserjoined" event.
     After exiting the channel, the SDK will clear the binding relationship of the remote user.

     @param[in] uid Remote user ID.
     @param[in] canvas Video canvas information
     @return
	 - 0: Method call succeeded;
	 - Other: method call failed.
     */
    virtual int setupRemoteVideoCanvas(uid_t uid, NERtcVideoCanvas* canvas) = 0;

 

9) Destroy IRtcEngine object

 

    /** Destroy the IRtcEngine object.

     @param[in] sync

     - true: Synchronous call. Wait for the IRtcEngine object resource to be released before returning. The App should not call this interface in the callback generated by the SDK. Otherwise, the SDK will wait for the callback to return before recycling the relevant object resources, which will cause a deadlock. The SDK will automatically detect this deadlock and turn it into an asynchronous call, but the detection itself will consume additional time.
     - false: Asynchronous call. Return immediately without waiting for the IRtcEngine object resource to be released. The SDK will release all resources by itself. When using asynchronous calls, be careful not to uninstall the SDK dynamic library immediately after the call, otherwise it may crash because the SDK cleaning thread has not exited.
     */
    virtual void release(bool sync = false) = 0;


 

 

III. creation and initialization of Netease real-time communication engine

 

3.1 # creation and initialization process

       

    // Netease cloud communication SDK engine
    nertc::IRtcEngineEx* rtc_engine_;

 

    rtc_engine_ = static_cast<IRtcEngineEx *>(createNERtcEngine());

 

bool NRTCEngine::Init(const char *app_key, const char *log_dir_path, uint32_t log_file_max_size_KBytes){

    //Init NERTC engine
    if (kNERtcNoError != rtc_engine_->initialize(rtc_engine_context_)){
        qDebug("ERROR: Failed to initialize NERtc Engine\n");
        return false;
    }


    return true;
}

 

void NRTCEngine::Uninit(){
    if (rtc_engine_){
        //Sleep(500);// Wait for the underlying asynchronous shutdown
        //Synchronous exit
        rtc_engine_->release(true);
        destroyNERtcEngine((void *&)rtc_engine_);
        rtc_engine_ = nullptr;
    }
}


NRTCEngine::~NRTCEngine(){
    Uninit();
}

 

3.2 # specific initialization of NERTC

3.2.1} setting initialization parameters

struct NERtcEngineContext
{
    const char *app_key;		/**< The user registers the APP Key of Yunxin. If there is no APP Key in your development kit, please apply for registration of a new APP Key.*/
    IRtcEngineEventHandlerEx *event_handler;	/**< Used to send callback event notification from SDK to App.*/
    const char *log_dir_path;	/**< The full path of the log directory is encoded in UTF-8.*/
    NERtcLogLevel log_level;	/**< Log level. The default level is kNERtcLogLevelInfo.*/
    uint32_t log_file_max_size_KBytes;	/**< Specifies the maximum size of the SDK output log file, in KB. If set to 0, the default is 20 M.*/
    bool video_prefer_hw_encoder; /**< Video hardware coding is accelerated, and hardware coding video data is preferred. Valid only under mac*/
    bool video_prefer_hw_decoder; /**< Video hardware decoding is accelerated, and hardware decoding is preferred. Valid only under mac*/
    bool video_use_exnternal_render; /**< Whether to use external rendering. The default is false. Valid only under mac*/
};

For us, 1) first of all, we should have Netease APP_KEY, otherwise, the SDK cannot be used

2) the most important is IRtcEngineEventHandlerEx *event_handler; / * * < used by SDK to send callback event notification to App*/

Get callback event information

3) analyze the misused LOG directory log_dir_path

  

3.2.2 initialize RTC engine

 

 virtual int initialize(const NERtcEngineContext& context) = 0;
This method is used to initialize the NERTC service. Pass in Yunxin to initialize the manufacturer's secret key issued by the developer.  

After successful initialization, it is in audio and video call mode by default.

Example:

During initialization, the APPKEY LOG path should be passed in

Further encapsulation is as follows:

   bool Init(const char* app_key, const char* log_dir_path, uint32_t log_file_max_size_KBytes);

 

    // Netease cloud communication SDK engine
    nertc::IRtcEngineEx* rtc_engine_;
    // The set of parameters required to initialize the engine
    nertc::NERtcEngineContext rtc_engine_context_;

    std::unique_ptr<nertc::IRtcEngineEventHandlerEx> rtc_engine_handler_;

 

bool NRTCEngine::Init(const char *app_key, const char *log_dir_path, uint32_t log_file_max_size_KBytes){
    rtc_engine_ = static_cast<IRtcEngineEx *>(createNERtcEngine());
    rtc_engine_context_.app_key = app_key;
    rtc_engine_context_.log_dir_path = log_dir_path;
    rtc_engine_context_.log_level = kNERtcLogLevelInfo;
    rtc_engine_context_.log_file_max_size_KBytes = log_file_max_size_KBytes;
    rtc_engine_context_.event_handler = rtc_engine_handler_.get();
    rtc_engine_context_.video_use_exnternal_render = false;

    //Init NERTC engine
    if (kNERtcNoError != rtc_engine_->initialize(rtc_engine_context_)){
        qDebug("ERROR: Failed to initialize NERtc Engine\n");
        return false;
    }

    //Init audio/video device manager
    auto ret = rtc_engine_->queryInterface(kNERtcIIDAudioDeviceManager, (void**)&audio_device_manager);
    ret = rtc_engine_->queryInterface(kNERtcIIDVideoDeviceManager, (void**)&video_device_manager);

    return true;
}

 

4. Join the channel

/ * * join the channel. If the channel has not been created, it will automatically try to create the channel.

This method allows users to join the call channel, users in the same channel can talk to each other, and multiple users can join the same channel to group chat. Apps using different App keys cannot be interconnected. If you are already in a call, the user must call \ ref IRtcEngine::leaveChannel "leaveChannel" to exit the current call before entering the next channel.

The user ID of each user in the @ note channel must be unique.
     
@ param[in] token dynamic secret key. Low security requirements: set the value to an empty string. High security requirements: set the value to Token. Be sure to use Token if you have enabled it.
     @param[in] channel_name identifies the channel name of the call. It is a string with a length of less than 64 bytes. The following is the supported character set range (89 characters in total): A-Z, A-Z, 0-9, space,! #$%& ()+-:;& le;.,>? @ []^_ {|}~”
@ param[in] uid user ID.

     @return
- 0: method call succeeded;
- Other: method call failed.
     */
    virtual int joinChannel(const char* token, const char* channel_name, uid_t uid) = 0;

 

4.1 , parameters necessary for adding rooms

virtual int joinChannel(const char* token, const char* channel_name, uid_t uid) = 0;

token, which is not strict, can be empty

Channel name (that is, the old version of the room name {can be alphanumeric)

User ID} can only be an unsigned integer type

Among them, channel_name identifies the channel name of the call. User ID {is required

 

typedef uint64_t uid_t;	/**< 64 Bit unsigned integer. Recommended setting range: 1 to 2 < sup > 63 < / sup > - 1, and ensure uniqueness.*/
typedef uint64_t channel_id_t;	/**< 64 Bit unsigned integer. Recommended setting range: 1 to 2 < sup > 63 < / sup > - 1, and ensure uniqueness.*/

 

void VideoWindow::onJoinChannel(QString& roomid, QString& usrId)
{
    this->show();
    
    void* hwnd = ui.video_1->getVideoHwnd();
    ui.video_1->setUsrID(usrId);
    m_engine->setupLocalVideo(hwnd);
    m_engine->joinChannel("", roomid, usrId, true, true, 2);
    //Start camera
    m_engine->enableVideo(true);

}

 

4.2 additional settings when adding a channel room

 

4.2.1 provide technical preview or special customization functions through JSON configuration SDK

 

    /** Provide technical preview or special customization functions through JSON configuration SDK. Expose JSON options in a standardized manner.

    @param[in] parameters JSON Parameters in string form

    @return
    - 0: Method call succeeded;
    - Other: method call failed.
    */
    virtual int setParameters(const char* parameters) = 0;

 

/** Provide technical preview or special customization functions through JSON configuration SDK. Expose JSON options in a standardized manner. See API setParameters for details*/
#define kNERtcKeyRecordHostEnabled          "record_host_enabled"          /**< bool value.  True: recording speaker, false: not recording speaker*/
#Define knertckeyrecordaudioenabled "record_audio_enabled" / * * < bool value to enable server audio recording. The default value is true*/
#Define knertckeyrecordvideoenabled "record_video_enabled" / * * < bool value to enable server video recording. The default value is true*/
#define kNERtcKeyRecordType                 "record_type"                  /**< int value, NERtcRecordType */
#Define knertckeyautosubscribeaudio "auto_subscribe_audio" / * * < bool value. When other users open audio, they will automatically subscribe. The default value is true*/
#Define knertckeypublishselfstreaminenabled "publish_self_stream_enabled" / * * < bool value to enable bypass live broadcast. The default value is false*/
#Define knertckeyloglevel "log_level" / * * < int value, nertcloglevel. The SDK outputs logs less than or equal to this level. The default is kNERtcLogLevelInfo*/
#define kNERtcKeyAudioProcessingAECEnable   "audio_processing_aec_enable"   /**< bool value.  AEC switch, the default value is true*/
#define kNERtcKeyAudioProcessingAGCEnable   "audio_processing_agc_enable"   /**< bool value.  AGC switch, the default value is true*/
#define kNERtcKeyAudioProcessingNSEnable    "audio_processing_ns_enable"   /**< bool value.  NS switch, the default value is true*/
#define kNERtcKeyAudioProcessingExternalAudioMixEnable  "audio_processing_external_audiomix_enable"   /**< bool value.  Input the mixing switch. The default value is false*/
#define kNERtcKeyAudioProcessingEarphone    "audio_processing_earphone"    /**< bool value.  Notify the SDK whether to use headphones. true: use headphones, false: do not use headphones. The default value is false*/
#define kNERtcKeyVideoSendOnPubType         "video_sendonpub_type"      /**< int value.  NERtcSendOnPubType; Set the video sending policy. By default, send the large stream kNERtcSendOnPubHigh; Pre call settings are valid*/

 

Configurable parameters

struct NRTCParameter {
    bool initialized;  // if has been initialized
    // bool p2p_mode_;
    bool audio_aec_enable;
    bool audio_agc_enable;
    bool audio_ns_enable;
    bool audio_external_mix_enable;
    bool audio_earphone;
    bool record_host_enabled;
    bool record_audio_enabled;
    bool record_video_enabled;
    nertc::NERtcRecordType record_type;
    bool auto_start_local_audio;
    bool auto_start_local_video;
    bool auto_subscribe_audio;
    // bool auto_subscribe_video;
    // bool force_auto_subscribe_video;
    bool publish_self_stream_enabled;
    nertc::NERtcLogLevel log_level;
    // bool video_capture_observer_enabled;
    bool video_smooth_enabled;
    bool video_watermark_enabled;
    bool video_filter_enabled;
    bool audio_filter_enabled;
    NRTCParameter() {
        initialized = false;
        // p2p_mode_ = false;
        audio_aec_enable = true;
        audio_agc_enable = true;
        audio_ns_enable = true;
        audio_external_mix_enable = false;
        audio_earphone = false;
        record_host_enabled = true;
        record_audio_enabled = true;
        record_video_enabled = true;
        record_type = nertc::kNERtcRecordTypeAll;
        auto_start_local_audio = true;
        auto_start_local_video = true;
        auto_subscribe_audio = true;
        // auto_subscribe_video = true;
        // force_auto_subscribe_video = true;
        // video_capture_observer_enabled = true;
        publish_self_stream_enabled = false;
        log_level = nertc::kNERtcLogLevelInfo;
        video_smooth_enabled = false;
        video_watermark_enabled = false;
        video_filter_enabled = false;
        audio_filter_enabled = false;
    }
};

 

void NRTCEngine::setParameter(const NRTCParameter &rtc_parameter){
    rtc_parameter_ = rtc_parameter;
    QJsonObject values;
    //values[kNERtcKeySetP2PMode] = rtc_parameter_.p2p_mode_;
    values[kNERtcKeyAudioProcessingAECEnable] = rtc_parameter_.audio_aec_enable;
    values[kNERtcKeyAudioProcessingAGCEnable] = rtc_parameter_.audio_agc_enable;
    values[kNERtcKeyAudioProcessingNSEnable] = rtc_parameter_.audio_ns_enable;
    values[kNERtcKeyAudioProcessingExternalAudioMixEnable] = rtc_parameter_.audio_external_mix_enable;
    values[kNERtcKeyAudioProcessingEarphone] = rtc_parameter_.audio_earphone;
    values[kNERtcKeyRecordHostEnabled] = rtc_parameter_.record_host_enabled;
    values[kNERtcKeyRecordAudioEnabled] = rtc_parameter_.record_audio_enabled;
    values[kNERtcKeyRecordVideoEnabled] = rtc_parameter_.record_video_enabled;
    values[kNERtcKeyRecordType] = rtc_parameter_.record_type;
//     values[kNERtcKeyAutoStartLocalAudio] = rtc_parameter_.auto_start_local_audio;
//     values[kNERtcKeyAutoStartLocalVideo] = rtc_parameter_.auto_start_local_video;
    //rtc_engine_->enableLocalAudio(rtc_parameter_.auto_start_local_audio);
    //rtc_engine_->enableLocalVideo(rtc_parameter_.auto_start_local_video);
    values[kNERtcKeyAutoSubscribeAudio] = rtc_parameter_.auto_subscribe_audio;
    //values[kNERtcKeyAutoSubscribeVideo] = rtc_parameter_.auto_subscribe_video;
    values[kNERtcKeyPublishSelfStreamEnabled] = rtc_parameter_.publish_self_stream_enabled;
    values[kNERtcKeyLogLevel] = rtc_parameter_.log_level;
    //values[kNERtcKeyVideoCaptureObserverEnabled] = rtc_parameter_.video_capture_observer_enabled;
    QString parameters = QString(QJsonDocument(values).toJson());
    int ret = rtc_engine_->setParameters(parameters.toUtf8().data());
    if(ret){
        qDebug("[ERROR] Cannot set parameters ERROR CODE: %d", ret);
    }
}

 

If you only set the bypass live broadcast, you can directly

    m_engine->setParameters("{\"publish_self_stream_enabled\":true}");

 

4.2.2 set local video parameters, such as resolution and other information

 

    /** Set video configuration.

	  This method sets the video configuration. Each attribute corresponds to a set of video parameters, such as resolution, which will take effect after the camera is restarted. All parameters set are the maximum value under ideal conditions. When the video engine cannot reach the set maximum resolution due to network environment and other reasons, it will take the value closest to the maximum.

     @param[in] config Video configuration: NERtcVideoConfig
     @return
	 - 0: Method call succeeded;
	 - Other: method call failed.
     */
    virtual int setVideoConfig(const NERtcVideoConfig& config) = 0;

 

/** Properties of the video configuration.*/
struct NERtcVideoConfig
{
    NERtcVideoProfileType max_profile;	/**< The resolution of video coding, which is used to measure the coding quality.*/
    NERtcVideoCropMode crop_mode_;      /**< Video clipping mode, the default is knertcvideopropmodedefault.*/
    NERtcVideoFramerateType framerate;  /**< Video frame rate */
    NERtcVideoFramerateType min_framerate;  /**< Minimum video frame rate */
    uint32_t bitrate;                   /**< The video coding rate is kbps, and the default value is used when 0 is taken */
    uint32_t min_bitrate;               /**< The lower limit of video coding rate is kbps, and the default value is used when 0 is taken */
    NERtcDegradationPreference degradation_preference;   /**< Coding strategy */
};

Video related parameters

/** @enum NERtcVideoCropMode Video clipping mode.*/
typedef enum
{
    kNERtcVideoCropModeDefault = 0,     /**< Device Defalut */
    kNERtcVideoCropMode16x9    = 1,     /**< 16:9 */
    kNERtcVideoCropMode4x3     = 2,     /**< 4:3 */
    kNERtcVideoCropMode1x1     = 3,     /**< 1:1 */
}NERtcVideoCropMode;

 

/** @enum NERtcVideoFramerateType Video frame rate.*/
typedef enum {
    kNERtcVideoFramerateFpsDefault  = 0,    /**< Default frame rate */
    kNERtcVideoFramerateFps_7       = 7,    /**< 7 Frames per second */
    kNERtcVideoFramerateFps_10      = 10,   /**< 10 Frames per second */
    kNERtcVideoFramerateFps_15      = 15,   /**< 15 Frames per second */
    kNERtcVideoFramerateFps_24      = 24,   /**< 24 Frames per second */
    kNERtcVideoFramerateFps_30      = 30,   /**< 30 Frames per second */
} NERtcVideoFramerateType;

 

/** @enum NERtcDegradationPreference Video coding strategy.*/
typedef enum {
    kNERtcDegradationDefault            = 0,  /**< Use engine recommendations. The balanced mode is used in the call scenario, and the clear mode is preferred in the live streaming scenario */
    kNERtcDegradationMaintainFramerate  = 1,  /**< Frame rate priority */
    kNERtcDegradationMaintainQuality    = 2,  /**< Clarity first */
    kNERtcDegradationBalanced           = 3,  /**< Balance mode */
} NERtcDegradationPreference;

 

Examples

/** Video coding configuration. Used to measure coding quality.*/
typedef enum
{
    kNERtcVideoProfileLowest = 0,       /**< 160x90/120, 15fps */
    kNERtcVideoProfileLow = 1,          /**< 320x180/240, 15fps */
    kNERtcVideoProfileStandard = 2,     /**< 640x360/480, 30fps */
    kNERtcVideoProfileHD720P = 3,       /**< 1280x720, 30fps */
    kNERtcVideoProfileHD1080P = 4,      /**< 1920x1080, 30fps */
    kNERtcVideoProfileNone = 5,
    kNERtcVideoProfileMAX = kNERtcVideoProfileHD1080P,
} NERtcVideoProfileType;



int NRTCEngine::joinChannel(const QString& token, const QString& roomid, const QString& uid,
                            bool autoStartVideo, bool autoStartAudio, int video_resolution){
    int ret = kNERtcNoError;

    //set video/audio auto starting config
    auto_start_audio_ = autoStartAudio;
    auto_start_video_ = autoStartVideo;
    setLocalVideoProfileType((NERtcVideoProfileType)video_resolution);

    NRTCParameter param;
    param.auto_start_local_audio = autoStartAudio;
    param.auto_start_local_video = autoStartVideo;
    setParameter(param);

    //Join channel
    cur_my_uid_ = uid.toULongLong();
    ret = rtc_engine_->joinChannel(token.toUtf8().data(), roomid.toUtf8().data(), cur_my_uid_);

    if(ret == kNERtcNoError){
        emit joiningChannel();
        qDebug() << "[INFO] join channel successfully!";
    }else{
        qDebug("[ERROR] can't join channel, ERROR CODE: %d", ret);
    }
    qDebug("[INFO] current connection state: %d", rtc_engine_->getConnectionState());
    return ret;
}

 

5. Leave the channel

 

    /** Leave the channel.

     Leave the channel, i.e. hang up or exit the call.

     After calling the \ ref IRtcEngine::joinChannel "joinChannel" method, you must call \ ref IRtcEngine::leaveChannel "leaveChannel" to end the call, otherwise you cannot start the next call. No matter whether the call is in progress or not, you can call leaveChannel without side effects. This method will release all resources related to the session.

     This method is an asynchronous operation and does not really exit the channel when the call returns. After exiting the channel, the SDK will trigger the \ ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.

     @note
     - If you call \ ref irtcengine:: release "release" immediately after calling \ ref IRtcEngine::leaveChannel "leaveChannel", the SDK will not be able to trigger the \ ref IRtcEngineEventHandler::onLeaveChannel "onLeaveChannel" callback.

     @return
     - 0: Method call succeeded;
     - Other: method call failed.
     */
    virtual int leaveChannel() = 0;

 

int NRTCEngine::leaveChannel(){
    int ret = kNERtcNoError;
    qDebug("[INFO] current connection state: %d", rtc_engine_->getConnectionState());
    if (rtc_engine_){
        ret = rtc_engine_->enableLocalAudio(false);
        ret = rtc_engine_->enableLocalVideo(false);
        ret = rtc_engine_->leaveChannel();
        if (kNERtcNoError == ret){
            emit leavingChannel();
        }else{
            qDebug("[ERROR] Can't leave channel, ERROR CODE: %d", ret);
        }
    }
    return ret;
}

 

Posted by delfa on Thu, 05 May 2022 06:34:33 +0300