/***************************************************************************
 *
 * Copyright (c) 2019 Baidu.com, Inc. All Rights Reserved
 *
 * @author: sunjian
 *
 ***************************************************************************/

#pragma once
#ifndef BAIDU_RTC_EXPORT
#define BAIDU_RTC_EXPORT_API __declspec(dllimport)
#else
#define BAIDU_RTC_EXPORT_API __declspec(dllexport)
#endif

#define BAIDU_RTC_MAX_COMMON_ARRAY_LEN 512
#define BAIDU_RTC_ADM_MAX_DEVICE_NAME_SIZE 128
#define BAIDU_RTC_ADM_MAX_GUID_SIZE 128

 /*
  *
  *  RTC媒体类型定义
  *
  **/
typedef enum BAIDU_RTC_EXPORT_API RtcMediaType {
	RTC_MEDIA_TYPE_VIDEO,
	RTC_MEDIA_TYPE_AUDIO,
	RTC_MEDIA_TYPE_DATA,
	RTC_MEDIA_TYPE_UNKNOW,
}RtcMediaType;

/*
 *
 *  连接类型定义
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API ConnectionType {
	RTC_SIGNAL_CHANNEL_CONNECTION,
	RTC_MEDIA_CHANNEL_CONNECTION,
}ConnectionType;

/*
 *
 *  网络连接状态
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API ConnectionStats {
	RTC_CONNECTION_STATS_UNKNOW = 400,
	RTC_CONNECTION_STATS_DISCONNECTED,
	RTC_CONNECTION_STATS_CONNECTING,
	RTC_CONNECTION_STATS_CONNECTED,
	RTC_CONNECTION_STATS_RECONNECTING,
	RTC_CONNECTION_STATS_FAILED,
}ConnectionStats;

/*
 *
 * 网络类型定义
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API NetworkType {
	NETWORK_TYPE_UNKNOWN,
	NETWORK_TYPE_UNARRIVAL,
	NETWORK_TYPE_LAN,
	NETWORK_TYPE_WIFI,
}NetworkType;

/*
 * 视频颜色空间类型,RTC SDK 支持下面两种颜色空间的转换
 *
 *VIDEO_COLOR_FORMAT_ARGB 表示RGB颜色空间
 *VIDEO_COLOR_FORMAT_I420 标识YUV420颜色空间
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API VideoColorFormat {
	VIDEO_COLOR_FORMAT_ARGB = 100,
	VIDEO_COLOR_FORMAT_I420,
}VideoColorFormat;



/*
 *
 * 消息类型定义
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API RtcMessageType {
	//正在建立信令通道
	RTC_MESSAGE_ESTABLISHING_SIGNAL_CHENNAL = 200,

	//建立信令通道成功
	RTC_MESSAGE_ESTABLISH_SIGNAL_CHENNAL_SUCCESS,

	//建立信令通道失败
	RTC_MESSAGE_ESTABLISH_SIGNAL_CHENNAL_FAIL,

	//信令通道链接断开
	RTC_MESSAGE_SIGNAL_CHENNAL_DISCONNECTED,

	//信令通道信令超时
	RTC_MESSAGE_SIGNAL_CHENNAL_SERVER_TIMEOUT,

	//信令通道信令超时
	RTC_MESSAGE_SIGNAL_CHENNAL_CLIENT_TIMEOUT,

	//信令通道收到hangup
	RTC_MESSAGE_SIGNAL_CHENNAL_RECEIVED_HANGUP,

	//登录房间成功
	RTC_MESSAGE_LOGIN_ROOM_SUCCESS,

	//登录房间失败
	RTC_MESSAGE_LOGIN_ROOM_FAILED,

	//用户离开房间
	RTC_MESSAGE_USER_LEAVING_ROOM,

	//用户加入房间
	RTC_MESSAGE_USER_JOINED_ROOM,

    //Lss直播转推成功
    RTC_MESSAGE_LIVE_PUBLISH_SUCCESS,

    //Lss直播转推失败
    RTC_MESSAGE_LIVE_PUBLISH_FAIL,

    //Lss直播转推中断
    RTC_MESSAGE_LIVE_PUBLISH_INTERRUPT,

	//正在建立媒体通道
	RTC_MESSAGE_ESTABLISHING_MEDIA_CHANNEL = 300,

	//建立媒体通道成功
	RTC_MESSAGE_ESTABLISH_MEDIA_CHANNEL_SUCCESS,

	//建立媒体通道失败
	RTC_MESSAGE_ESTABLISH_MEDIA_CHANNEL_FAILED,

	//媒体通道链接断开
	RTC_MESSAGE_ESTABLISH_MEDIA_CHANNEL_DISCONNECTED,

	//媒体通道建连超时
	RTC_MESSAGE_ESTABLISH_MEDIA_CHANNEL_TIMEOUT,

	//媒体通道关闭
	RTC_MESSAGE_MEDIA_CHANNEL_CLOSED,

	//开始订阅流
	RTC_MESSAGE_MEDIA_SUBSCRIBING_STREAMING = 500,

	//媒体流到达
	RTC_MESSAGE_MEDIA_STREAMING_ARRIVAL,

	//数据流到达
	RTC_MESSAGE_DATA_STREAMING_ARRIVAL,

	//媒体链路不稳定
	RTC_MESSAGE_NETWORK_LINK_INSTABILITY,

	//网络不可达
	RTC_MESSAGE_BE_UNABLE_TO_NETWORK,

	//网络上行带宽统计
	RTC_MESSAGE_NET_UP_BIND_WIDTH_STATISTICS,

	//网络下行带宽统计
	RTC_MESSAGE_NET_DOWN_BIND_WIDTH_STATISTICS,

	/********************************************/
	//本地视频采集设备初始化状态
	RTC_MESSAGE_LOCAL_VIDEO_STREAM_STATS_STOPPED = 600,

	//本地视频采集设备启动成功
	RTC_MESSAGE_LOCAL_VIDEO_STREAM_STATS_CAPTURING,

	//本地失败首帧编码成功
	RTC_MESSAGE_LOCAL_VIDEO_STREAM_STATS_ENCODED,

	//本地视频首帧发放成功
	RTC_MESSAGE_LOCAL_VIDEO_STREAM_STATS_SENT,

	/********************************************/
	//远端视频启动失败
	RTC_MESSAGE_LOCAL_VIDEO_STREAM_STATS_FAILED,

	//远端视频采集设备初始化状态
	RTC_MESSAGE_REMOTE_VIDEO_STREAM_STATS_STOPPED,

	//远端视频首帧已经到达
	RTC_MESSAGE_REMOTE_VIDEO_STREAM_STATS_ARRIVED,

	//远端视频流解码播放正常
	RTC_MESSAGE_REMOTE_VIDEO_STREAM_STATS_DECODED,

	//远端视频流卡顿
	RTC_MESSAGE_REMOTE_VIDEO_STREAM_STATS_FROZEN,

	//远端视频流播放失败
	RTC_MESSAGE_REMOTE_VIDEO_STREAM_STATS_FAILED,

	/********************************************/
	//本地音频默认初始化状态
	RTC_MESSAGE_LOCAL_AUDIO_STREAM_STATS_STOPPED = 700,

	//本地音频采集启动成功
	RTC_MESSAGE_LOCAL_AUDIO_STREAM_STATS_RECORDING,

	//本地音频首帧编码成功
	RTC_MESSAGE_LOCAL_AUDIO_STREAM_STATS_ENCODING,

    //本地音频首帧发送成功
    RTC_MESSAGE_LOCAL_AUDIO_STREAM_STATS_SENT,

	//本地音频设备启动失败
	RTC_MESSAGE_LOCAL_AUDIO_STREAM_STATS_FAILED,

	/********************************************/
	//远端音频流默认初始状态
	RTC_MESSAGE_REMOTE_AUDIO_STREAM_STATS_STOPPED,

	//远端音频首包到达
	RTC_MESSAGE_REMOTE_AUDIO_STREAM_STATS_ARRIVED,

	//远端音频解码播放正常
	RTC_MESSAGE_REMOTE_AUDIO_STREAM_STATS_DECODING,

	//远端音频解码播放卡顿
	RTC_MESSAGE_REMOTE_AUDIO_STREAM_STATS_FROZEN,

	//远端音频播放失败
	RTC_MESSAGE_REMOTE_AUDIO_STREAM_STATS_FAILED,

	/********************************************/
	/*网络类型改变通知*/
    RTC_MESSAGE_NETWORK_TYPE_CHANGE_AS_LAN = 800,
	RTC_MESSAGE_NETWORK_TYPE_CHANGE_AS_WIFI,
	RTC_MESSAGE_NETWORK_TYPE_CHANGE_AS_UNKOWN,
}RtcMessageType;


/*
 *
 * 消息结构体
 *
 * @discuss 当注册了消息监听接口给sdk后，sdk会抛消息上来，消息的结构如下；
 *
 *
 **/
typedef struct BAIDU_RTC_EXPORT_API RtcMessage {
	RtcMessageType msgType;
	union {
		int64_t userId;
		int64_t streamId;
		int64_t erroCodes;
		const char* message;
		const char* reason;
	}data;

	//带宽信息统计
	struct {
		//上行网络可用带宽
		int upNetAvailableBW;

		//上行网络已占用带宽
		int upNetUsedBW;

		//下行网络可用带宽
		int downNetAvailableBW;

		//下行网络已占用带宽
		int downUsedBW;
	}bw;

	int frameObserverIndex;
	void* obj;
}RtcMessage;


/*
 *
 * 消息监听接口定义
 *
 * @discuss 需要开发者实现，并注册给rtc sdk;
 *
 *
 **/
class BAIDU_RTC_EXPORT_API IRtcMessageListener {
public:
	virtual void OnRtcMessage(RtcMessage msg) = 0;
};

/*
 *
 * 视频设备信息结构体
 *
 * @discuss 管理视频设备;
 *
 *
 **/
typedef struct BAIDU_RTC_EXPORT_API RtcVideoDeviceInfo {
	char deviceId[BAIDU_RTC_MAX_COMMON_ARRAY_LEN];
	char deviceName[BAIDU_RTC_MAX_COMMON_ARRAY_LEN];
}RtcVideoDeviceInfo;

/*
 *
 * 房间用户角色
 *
 * @param RTC_ROOM_USER_ROLE_PUBLISHER, 角色为流发布者
 * @param RTC_ROOM_USER_ROLE_LISTENER, 角色为流监听者
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API RtcRoomUserRole {
	RTC_ROOM_USER_ROLE_PUBLISHER,
	RTC_ROOM_USER_ROLE_LISTENER,
}RtcRoomUserRole;


/*
 *
 * 房间用户信息
 *
 * @param userRole, 用户角色
 * @param userId, 用户id
 * @param roomId, 房间id
 *
 **/
typedef struct BAIDU_RTC_EXPORT_API RtcRoomUserInfo {
	RtcRoomUserRole userRole;
	int64_t userId;
	int64_t roomId;
}RtcRoomUserInfo;

/*
 *
 * 房间用户信息
 *
 * @param userRole, 用户角色
 * @param userId, 用户id
 * @param roomId, 房间id
 *
 **/
enum BAIDU_RTC_EXPORT_API RtcLiveTransferMode {
    RTC_LIVE_TRANSFER_MODE_ROOM_TRANSMISSION = 0,
    RTC_LIVE_TRANSFER_MODE_ANCHOR_TRANSMISSION = 1
};

enum BAIDU_RTC_EXPORT_API CaptureType {
    kScreen = 0,
    kWindow = 1,
};

typedef struct BAIDU_RTC_EXPORT_API WindowFrame {
    int width;
    int height;
    uint8_t* data;
}WindowFrame;


/*
 *
 * 窗口信息
 *
 * @param id, 窗口ID
 * @param title, 窗口标题
 *
 **/
typedef struct BAIDU_RTC_EXPORT_API WindowSource {
    // The unique id to represent a Source of current DesktopCapturer.
    long long id;
    // Title of the window or screen in UTF-8 encoding, maybe empty. This field
    // should not be used to identify a source.
    wchar_t* title;
}WindowSource;


/*
 *
 *  本地音频状态出错原因
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API RtcLocalAudioStreamError {
	//本地音频错误原因未知
	RTC_LOCAL_AUDIO_STREAM_ERROR_UNKNOW,

	//没有权限启动本地音频设备
	RTC_LOCAL_AUDIO_STREAM_ERROR_DEVICE_NO_PERMISSION,

	//本地音频设备已经在使用中
	RTC_LOCAL_AUDIO_STREAM_ERROR_DEVICE_BUSY,

	//本地音频录制失败
	RTC_LOCAL_AUDIO_STREAM_ERROR_RECORD_FAIL,

	//本地音频编码失败
	RTC_LOCAL_AUDIO_STREAM_ERROR_ENCODE_FAIL,
}RtcLocalAudioStreamError;

/*
 *
 *  本地视频状态出错原因
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API RtcLocalVideoStreamError {
	//本地视频错误原因未知
	RTC_LOCAL_VIDEO_STREAM_ERROR_UNKNOW,

	//没有权限启动本地音频设备
	RTC_LOCAL_VIDEO_STREAM_ERROR_DEVICE_NO_PERMISSION,

	//本地视频设备已经在使用中
	RTC_LOCAL_VIDEO_STREAM_ERROR_DEVICE_BUSY,

	//本地视频录制失败
	RTC_LOCAL_VIDEO_STREAM_ERROR_RECORD_FAIL,

	//本地视频编码失败
	RTC_LOCAL_VIDEO_STREAM_ERROR_ENCODE_FAIL,
}RtcLocalVideoStreamError;

/*
 *
 *  远端视频状态变化原因
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API RtcRemoteVideoStreamStatsChangeReason {
	//内部原因
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_INTERNAL,

	//网络阻塞
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_NETWORK_CONGESTION,

	//网络恢复正常
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_NETWORK_RECOVERY,

	//停止接收远端视频流或本地用户禁用视频模块
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_LOCAL_MUTED,

	//恢复接收远端视频流或本地用户启动视频模块
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_LOCAL_UNMUTED,

	//远端用户停止发送视频流或禁用视频模块
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_REMOTE_MUTED,

	//远端用户恢复发送视频流或启用视频模块
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_REMOTE_UNMUTED,

	//远端视频流已回退为音频流
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_AUDIO_FALLBACK,

	//回退的远端音频流恢复为视频流
	RTC_REMOTE_VIDEO_STREAM_STATS_CHANGE_REASON_AUDIO_FALLBACK_RECOVERY,
}RtcRemoteVideoStreamStatsChangeReason;


/*
 *
 *  远端音频状态变化原因
 *
 **/
typedef enum BAIDU_RTC_EXPORT_API RtcRemoteAudioStreamStatsChangeReason {
	//内部原因
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_INTERNAL,

	//网络阻塞
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_NETWORK_CONGESTION,

	//网络恢复正常
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_NETWORK_RECOVERY,

	//停止接收远端音频流或本地用户禁用音频模块
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_LOCAL_MUTED,

	//恢复接收远端音频流或本地用户启用音频模块
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_LOCAL_UNMUTED,

	//远端用户停止发送音频流或禁用音频模块
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_REMOTE_MUTED,

	//远端用户恢复发送音频流或启用音频模块
	RTC_REMOTE_AUDIO_STREAM_STATS_CHANGE_REASON_REMOTE_UNMUTED,
}RtcRemoteAudioStreamStatsChangeReason;