抓娃娃版1127

IAgoraRtcEngine.h 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112
  1. //
  2. // Agora Rtc Engine SDK
  3. //
  4. // Created by Sting Feng in 2015-02.
  5. // Copyright (c) 2015 Agora IO. All rights reserved.
  6. //
  7. #ifndef AGORA_RTC_ENGINE_H
  8. #define AGORA_RTC_ENGINE_H
  9. #include <stddef.h>
  10. #include <stdio.h>
  11. #include <stdarg.h>
  12. #if defined(_WIN32)
  13. #define WIN32_LEAN_AND_MEAN
  14. #include <windows.h>
  15. #define AGORA_CALL __cdecl
  16. #if defined(AGORARTC_EXPORT)
  17. #define AGORA_API extern "C" __declspec(dllexport)
  18. #else
  19. #define AGORA_API extern "C" __declspec(dllimport)
  20. #endif
  21. #elif defined(__APPLE__)
  22. #define AGORA_API __attribute__((visibility("default"))) extern "C"
  23. #define AGORA_CALL
  24. #elif defined(__ANDROID__) || defined(__linux__)
  25. #define AGORA_API extern "C" __attribute__((visibility("default")))
  26. #define AGORA_CALL
  27. #else
  28. #define AGORA_API extern "C"
  29. #define AGORA_CALL
  30. #endif
  31. namespace agora {
  32. namespace util {
  33. template<class T>
  34. class AutoPtr {
  35. typedef T value_type;
  36. typedef T* pointer_type;
  37. public:
  38. AutoPtr(pointer_type p=0)
  39. :ptr_(p)
  40. {}
  41. ~AutoPtr() {
  42. if (ptr_)
  43. ptr_->release();
  44. }
  45. operator bool() const { return ptr_ != (pointer_type)0; }
  46. value_type& operator*() const {
  47. return *get();
  48. }
  49. pointer_type operator->() const {
  50. return get();
  51. }
  52. pointer_type get() const {
  53. return ptr_;
  54. }
  55. pointer_type release() {
  56. pointer_type tmp = ptr_;
  57. ptr_ = 0;
  58. return tmp;
  59. }
  60. void reset(pointer_type ptr = 0) {
  61. if (ptr != ptr_ && ptr_)
  62. ptr_->release();
  63. ptr_ = ptr;
  64. }
  65. template<class C1, class C2>
  66. bool queryInterface(C1* c, C2 iid) {
  67. pointer_type p = NULL;
  68. if (c && !c->queryInterface(iid, (void**)&p))
  69. {
  70. reset(p);
  71. }
  72. return p != NULL;;
  73. }
  74. private:
  75. AutoPtr(const AutoPtr&);
  76. AutoPtr& operator=(const AutoPtr&);
  77. private:
  78. pointer_type ptr_;
  79. };
  80. class IString {
  81. public:
  82. virtual bool empty() const = 0;
  83. virtual const char* c_str() = 0;
  84. virtual const char* data() = 0;
  85. virtual size_t length() = 0;
  86. virtual void release() = 0;
  87. };
  88. typedef AutoPtr<IString> AString;
  89. }//namespace util
  90. namespace rtc {
  91. typedef unsigned int uid_t;
  92. typedef void* view_t;
  93. enum INTERFACE_ID_TYPE
  94. {
  95. AGORA_IID_AUDIO_DEVICE_MANAGER = 1,
  96. AGORA_IID_VIDEO_DEVICE_MANAGER = 2,
  97. AGORA_IID_RTC_ENGINE_PARAMETER = 3,
  98. AGORA_IID_MEDIA_ENGINE = 4,
  99. };
  100. enum WARN_CODE_TYPE
  101. {
  102. WARN_INVALID_VIEW = 8,
  103. WARN_INIT_VIDEO = 16,
  104. WARN_PENDING = 20,
  105. WARN_NO_AVAILABLE_CHANNEL = 103,
  106. WARN_LOOKUP_CHANNEL_TIMEOUT = 104,
  107. WARN_LOOKUP_CHANNEL_REJECTED = 105,
  108. WARN_OPEN_CHANNEL_TIMEOUT = 106,
  109. WARN_OPEN_CHANNEL_REJECTED = 107,
  110. WARN_AUDIO_MIXING_OPEN_ERROR = 701,
  111. WARN_ADM_RUNTIME_PLAYOUT_WARNING = 1014,
  112. WARN_ADM_RUNTIME_RECORDING_WARNING = 1016,
  113. WARN_ADM_RECORD_AUDIO_SILENCE = 1019,
  114. WARN_ADM_PLAYOUT_MALFUNCTION = 1020,
  115. WARN_ADM_RECORD_MALFUNCTION = 1021,
  116. WARN_ADM_RECORD_AUDIO_LOWLEVEL = 1031,
  117. WARN_APM_HOWLING = 1051,
  118. // sdk: 100~1000
  119. WARN_SWITCH_LIVE_VIDEO_TIMEOUT = 111,
  120. WARN_SET_CLIENT_ROLE_TIMEOUT = 118,
  121. };
  122. enum ERROR_CODE_TYPE
  123. {
  124. ERR_OK = 0,
  125. //1~1000
  126. ERR_FAILED = 1,
  127. ERR_INVALID_ARGUMENT = 2,
  128. ERR_NOT_READY = 3,
  129. ERR_NOT_SUPPORTED = 4,
  130. ERR_REFUSED = 5,
  131. ERR_BUFFER_TOO_SMALL = 6,
  132. ERR_NOT_INITIALIZED = 7,
  133. ERR_NO_PERMISSION = 9,
  134. ERR_TIMEDOUT = 10,
  135. ERR_CANCELED = 11,
  136. ERR_TOO_OFTEN = 12,
  137. ERR_BIND_SOCKET = 13,
  138. ERR_NET_DOWN = 14,
  139. ERR_NET_NOBUFS = 15,
  140. ERR_JOIN_CHANNEL_REJECTED = 17,
  141. ERR_LEAVE_CHANNEL_REJECTED = 18,
  142. ERR_ALREADY_IN_USE = 19,
  143. ERR_ABORTED = 20,
  144. ERR_INIT_NET_ENGINE = 21,
  145. ERR_INVALID_APP_ID = 101,
  146. ERR_INVALID_CHANNEL_NAME = 102,
  147. ERR_CHANNEL_KEY_EXPIRED = 109,
  148. ERR_INVALID_CHANNEL_KEY = 110,
  149. ERR_CONNECTION_INTERRUPTED = 111, // only used in web sdk
  150. ERR_CONNECTION_LOST = 112, // only used in web sdk
  151. ERR_DECRYPTION_FAILED = 120,
  152. ERR_NOT_IN_CHANNEL = 113,
  153. ERR_SIZE_TOO_LARGE = 114,
  154. ERR_BITRATE_LIMIT = 115,
  155. ERR_TOO_MANY_DATA_STREAMS = 116,
  156. ERR_STREAM_MESSAGE_TIMEOUT = 117,
  157. ERR_SET_CLIENT_ROLE_NOT_AUTHORIZED = 119,
  158. //1001~2000
  159. ERR_LOAD_MEDIA_ENGINE = 1001,
  160. ERR_START_CALL = 1002,
  161. ERR_START_CAMERA = 1003,
  162. ERR_START_VIDEO_RENDER = 1004,
  163. ERR_ADM_GENERAL_ERROR = 1005,
  164. ERR_ADM_JAVA_RESOURCE = 1006,
  165. ERR_ADM_SAMPLE_RATE = 1007,
  166. ERR_ADM_INIT_PLAYOUT = 1008,
  167. ERR_ADM_START_PLAYOUT = 1009,
  168. ERR_ADM_STOP_PLAYOUT = 1010,
  169. ERR_ADM_INIT_RECORDING = 1011,
  170. ERR_ADM_START_RECORDING = 1012,
  171. ERR_ADM_STOP_RECORDING = 1013,
  172. ERR_ADM_RUNTIME_PLAYOUT_ERROR = 1015,
  173. ERR_ADM_RUNTIME_RECORDING_ERROR = 1017,
  174. ERR_ADM_RECORD_AUDIO_FAILED = 1018,
  175. ERR_ADM_INIT_LOOPBACK = 1022,
  176. ERR_ADM_START_LOOPBACK = 1023,
  177. ERR_ADM_NO_PERMISSION = 1027,
  178. // 1025, as warning for interruption of adm on ios
  179. // 1026, as warning for route change of adm on ios
  180. // VDM error code starts from 1500
  181. ERR_VDM_CAMERA_NOT_AUTHORIZED = 1501,
  182. // VCM error code starts from 1600
  183. ERR_VCM_UNKNOWN_ERROR = 1600,
  184. ERR_VCM_ENCODER_INIT_ERROR = 1601,
  185. ERR_VCM_ENCODER_ENCODE_ERROR = 1602,
  186. ERR_VCM_ENCODER_SET_ERROR = 1603,
  187. };
  188. enum LOG_FILTER_TYPE
  189. {
  190. LOG_FILTER_OFF = 0,
  191. LOG_FILTER_DEBUG = 0x080f,
  192. LOG_FILTER_INFO = 0x000f,
  193. LOG_FILTER_WARN = 0x000e,
  194. LOG_FILTER_ERROR = 0x000c,
  195. LOG_FILTER_CRITICAL = 0x0008,
  196. LOG_FILTER_MASK = 0x80f,
  197. };
  198. enum MAX_DEVICE_ID_LENGTH_TYPE
  199. {
  200. MAX_DEVICE_ID_LENGTH = 512
  201. };
  202. enum QUALITY_REPORT_FORMAT_TYPE
  203. {
  204. QUALITY_REPORT_JSON = 0,
  205. QUALITY_REPORT_HTML = 1,
  206. };
  207. enum MEDIA_ENGINE_EVENT_CODE_TYPE
  208. {
  209. MEDIA_ENGINE_RECORDING_ERROR = 0,
  210. MEDIA_ENGINE_PLAYOUT_ERROR = 1,
  211. MEDIA_ENGINE_RECORDING_WARNING = 2,
  212. MEDIA_ENGINE_PLAYOUT_WARNING = 3,
  213. MEDIA_ENGINE_AUDIO_FILE_MIX_FINISH = 10,
  214. // media engine role changed
  215. MEDIA_ENGINE_ROLE_BROADCASTER_SOLO = 20,
  216. MEDIA_ENGINE_ROLE_BROADCASTER_INTERACTIVE = 21,
  217. MEDIA_ENGINE_ROLE_AUDIENCE = 22,
  218. MEDIA_ENGINE_ROLE_COMM_PEER = 23,
  219. MEDIA_ENGINE_ROLE_GAME_PEER = 24,
  220. // iOS adm sample rate changed
  221. MEDIA_ENGINE_AUDIO_ADM_REQUIRE_RESTART = 110
  222. };
  223. enum MEDIA_DEVICE_STATE_TYPE
  224. {
  225. MEDIA_DEVICE_STATE_ACTIVE = 1,
  226. MEDIA_DEVICE_STATE_DISABLED = 2,
  227. MEDIA_DEVICE_STATE_NOT_PRESENT = 4,
  228. MEDIA_DEVICE_STATE_UNPLUGGED = 8
  229. };
  230. enum MEDIA_DEVICE_TYPE
  231. {
  232. UNKNOWN_AUDIO_DEVICE = -1,
  233. AUDIO_PLAYOUT_DEVICE = 0,
  234. AUDIO_RECORDING_DEVICE = 1,
  235. VIDEO_RENDER_DEVICE = 2,
  236. VIDEO_CAPTURE_DEVICE = 3,
  237. };
  238. enum AUDIO_RECORDING_QUALITY_TYPE
  239. {
  240. AUDIO_RECORDING_QUALITY_LOW = 0,
  241. AUDIO_RECORDING_QUALITY_MEDIUM = 1,
  242. AUDIO_RECORDING_QUALITY_HIGH = 2,
  243. };
  244. enum QUALITY_TYPE
  245. {
  246. QUALITY_UNKNOWN = 0,
  247. QUALITY_EXCELLENT = 1,
  248. QUALITY_GOOD = 2,
  249. QUALITY_POOR = 3,
  250. QUALITY_BAD = 4,
  251. QUALITY_VBAD = 5,
  252. QUALITY_DOWN = 6,
  253. };
  254. enum RENDER_MODE_TYPE
  255. {
  256. RENDER_MODE_HIDDEN = 1,
  257. RENDER_MODE_FIT = 2,
  258. RENDER_MODE_ADAPTIVE = 3,
  259. };
  260. enum VIDEO_MIRROR_MODE_TYPE
  261. {
  262. VIDEO_MIRROR_MODE_AUTO = 0,//determined by SDK
  263. VIDEO_MIRROR_MODE_ENABLED = 1,//enabled mirror
  264. VIDEO_MIRROR_MODE_DISABLED = 2,//disable mirror
  265. };
  266. enum VIDEO_PROFILE_TYPE
  267. { // res fps kbps
  268. VIDEO_PROFILE_120P = 0, // 160x120 15 65
  269. VIDEO_PROFILE_120P_3 = 2, // 120x120 15 50
  270. VIDEO_PROFILE_180P = 10, // 320x180 15 140
  271. VIDEO_PROFILE_180P_3 = 12, // 180x180 15 100
  272. VIDEO_PROFILE_180P_4 = 13, // 240x180 15 120
  273. VIDEO_PROFILE_240P = 20, // 320x240 15 200
  274. VIDEO_PROFILE_240P_3 = 22, // 240x240 15 140
  275. VIDEO_PROFILE_240P_4 = 23, // 424x240 15 220
  276. VIDEO_PROFILE_360P = 30, // 640x360 15 400
  277. VIDEO_PROFILE_360P_3 = 32, // 360x360 15 260
  278. VIDEO_PROFILE_360P_4 = 33, // 640x360 30 600
  279. VIDEO_PROFILE_360P_6 = 35, // 360x360 30 400
  280. VIDEO_PROFILE_360P_7 = 36, // 480x360 15 320
  281. VIDEO_PROFILE_360P_8 = 37, // 480x360 30 490
  282. VIDEO_PROFILE_360P_9 = 38, // 640x360 15 800
  283. VIDEO_PROFILE_360P_10 = 39, // 640x360 24 800
  284. VIDEO_PROFILE_360P_11 = 100, // 640x360 24 1000
  285. VIDEO_PROFILE_480P = 40, // 640x480 15 500
  286. VIDEO_PROFILE_480P_3 = 42, // 480x480 15 400
  287. VIDEO_PROFILE_480P_4 = 43, // 640x480 30 750
  288. VIDEO_PROFILE_480P_6 = 45, // 480x480 30 600
  289. VIDEO_PROFILE_480P_8 = 47, // 848x480 15 610
  290. VIDEO_PROFILE_480P_9 = 48, // 848x480 30 930
  291. VIDEO_PROFILE_480P_10 = 49, // 640x480 10 400
  292. VIDEO_PROFILE_720P = 50, // 1280x720 15 1130
  293. VIDEO_PROFILE_720P_3 = 52, // 1280x720 30 1710
  294. VIDEO_PROFILE_720P_5 = 54, // 960x720 15 910
  295. VIDEO_PROFILE_720P_6 = 55, // 960x720 30 1380
  296. VIDEO_PROFILE_1080P = 60, // 1920x1080 15 2080
  297. VIDEO_PROFILE_1080P_3 = 62, // 1920x1080 30 3150
  298. VIDEO_PROFILE_1080P_5 = 64, // 1920x1080 60 4780
  299. VIDEO_PROFILE_1440P = 66, // 2560x1440 30 4850
  300. VIDEO_PROFILE_1440P_2 = 67, // 2560x1440 60 7350
  301. VIDEO_PROFILE_4K = 70, // 3840x2160 30 8910
  302. VIDEO_PROFILE_4K_3 = 72, // 3840x2160 60 13500
  303. VIDEO_PROFILE_DEFAULT = VIDEO_PROFILE_360P,
  304. };
  305. enum CHANNEL_PROFILE_TYPE
  306. {
  307. CHANNEL_PROFILE_COMMUNICATION = 0,
  308. CHANNEL_PROFILE_LIVE_BROADCASTING = 1,
  309. CHANNEL_PROFILE_GAME = 2,
  310. };
  311. enum CLIENT_ROLE_TYPE
  312. {
  313. CLIENT_ROLE_BROADCASTER = 1,
  314. CLIENT_ROLE_AUDIENCE = 2,
  315. };
  316. enum USER_OFFLINE_REASON_TYPE
  317. {
  318. USER_OFFLINE_QUIT = 0,
  319. USER_OFFLINE_DROPPED = 1,
  320. USER_OFFLINE_BECOME_AUDIENCE = 2,
  321. };
  322. enum REMOTE_VIDEO_STREAM_TYPE
  323. {
  324. REMOTE_VIDEO_STREAM_HIGH = 0,
  325. REMOTE_VIDEO_STREAM_LOW = 1,
  326. };
  327. enum RAW_AUDIO_FRAME_OP_MODE_TYPE
  328. {
  329. RAW_AUDIO_FRAME_OP_MODE_READ_ONLY = 0,
  330. RAW_AUDIO_FRAME_OP_MODE_WRITE_ONLY = 1,
  331. RAW_AUDIO_FRAME_OP_MODE_READ_WRITE = 2,
  332. };
  333. struct AudioVolumeInfo
  334. {
  335. uid_t uid;
  336. unsigned int volume; // [0,255]
  337. };
  338. struct RtcStats
  339. {
  340. unsigned int duration;
  341. unsigned int txBytes;
  342. unsigned int rxBytes;
  343. unsigned short txKBitRate;
  344. unsigned short rxKBitRate;
  345. unsigned short rxAudioKBitRate;
  346. unsigned short txAudioKBitRate;
  347. unsigned short rxVideoKBitRate;
  348. unsigned short txVideoKBitRate;
  349. unsigned int users;
  350. double cpuAppUsage;
  351. double cpuTotalUsage;
  352. };
  353. struct LocalVideoStats
  354. {
  355. int sentBitrate;
  356. int sentFrameRate;
  357. };
  358. struct RemoteVideoStats
  359. {
  360. uid_t uid;
  361. int delay;
  362. int width;
  363. int height;
  364. int receivedBitrate;
  365. int receivedFrameRate;
  366. REMOTE_VIDEO_STREAM_TYPE rxStreamType;
  367. };
  368. struct VideoCompositingLayout
  369. {
  370. struct Region {
  371. uid_t uid;
  372. double x;//[0,1]
  373. double y;//[0,1]
  374. double width;//[0,1]
  375. double height;//[0,1]
  376. int zOrder; //optional, [0, 100] //0 (default): bottom most, 100: top most
  377. // Optional
  378. // [0, 1.0] where 0 denotes throughly transparent, 1.0 opaque
  379. double alpha;
  380. RENDER_MODE_TYPE renderMode;//RENDER_MODE_HIDDEN: Crop, RENDER_MODE_FIT: Zoom to fit
  381. Region()
  382. :uid(0)
  383. , x(0)
  384. , y(0)
  385. , width(0)
  386. , height(0)
  387. , zOrder(0)
  388. , alpha(1.0)
  389. , renderMode(RENDER_MODE_HIDDEN)
  390. {}
  391. };
  392. int canvasWidth;
  393. int canvasHeight;
  394. const char* backgroundColor;//e.g. "#C0C0C0" in RGB
  395. const Region* regions;
  396. int regionCount;
  397. const char* appData;
  398. int appDataLength;
  399. VideoCompositingLayout()
  400. :canvasWidth(0)
  401. ,canvasHeight(0)
  402. ,backgroundColor(NULL)
  403. ,regions(NULL)
  404. , regionCount(0)
  405. , appData(NULL)
  406. , appDataLength(0)
  407. {}
  408. };
  409. typedef struct Rect {
  410. int top;
  411. int left;
  412. int bottom;
  413. int right;
  414. Rect(): top(0), left(0), bottom(0), right(0) {}
  415. Rect(int t, int l, int b, int r): top(t), left(l), bottom(b), right(r) {}
  416. } Rect;
  417. #if defined(_WIN32)
  418. enum RTMP_STREAM_LIFE_CYCLE_TYPE
  419. {
  420. RTMP_STREAM_LIFE_CYCLE_BIND2CHANNEL = 1,
  421. RTMP_STREAM_LIFE_CYCLE_BIND2OWNER = 2,
  422. };
  423. struct PublisherConfiguration {
  424. int width;
  425. int height;
  426. int framerate;
  427. int bitrate;
  428. int defaultLayout;
  429. int lifecycle;
  430. bool owner;
  431. int injectStreamWidth;
  432. int injectStreamHeight;
  433. const char* injectStreamUrl;
  434. const char* publishUrl;
  435. const char* rawStreamUrl;
  436. const char* extraInfo;
  437. PublisherConfiguration()
  438. : width(640)
  439. , height(360)
  440. , framerate(15)
  441. , bitrate(500)
  442. , defaultLayout(1)
  443. , lifecycle(RTMP_STREAM_LIFE_CYCLE_BIND2CHANNEL)
  444. , owner(true)
  445. , injectStreamWidth(0)
  446. , injectStreamHeight(0)
  447. , injectStreamUrl(NULL)
  448. , publishUrl(NULL)
  449. , rawStreamUrl(NULL)
  450. , extraInfo(NULL)
  451. {}
  452. };
  453. #endif
  454. #if !defined(__ANDROID__)
  455. struct VideoCanvas
  456. {
  457. view_t view;
  458. int renderMode;
  459. uid_t uid;
  460. void *priv; // private data (underlying video engine denotes it)
  461. VideoCanvas()
  462. : view(NULL)
  463. , renderMode(RENDER_MODE_HIDDEN)
  464. , uid(0)
  465. , priv(NULL)
  466. {}
  467. VideoCanvas(view_t v, int m, uid_t u)
  468. : view(v)
  469. , renderMode(m)
  470. , uid(u)
  471. , priv(NULL)
  472. {}
  473. };
  474. #else
  475. struct VideoCanvas;
  476. #endif
  477. class IPacketObserver
  478. {
  479. public:
  480. struct Packet
  481. {
  482. const unsigned char* buffer;
  483. unsigned int size;
  484. };
  485. /**
  486. * called by sdk before the audio packet is sent to other participants
  487. * @param [in,out] packet
  488. * buffer *buffer points the data to be sent
  489. * size of buffer data to be sent
  490. * @return returns true to send out the packet, returns false to discard the packet
  491. */
  492. virtual bool onSendAudioPacket(Packet& packet) = 0;
  493. /**
  494. * called by sdk before the video packet is sent to other participants
  495. * @param [in,out] packet
  496. * buffer *buffer points the data to be sent
  497. * size of buffer data to be sent
  498. * @return returns true to send out the packet, returns false to discard the packet
  499. */
  500. virtual bool onSendVideoPacket(Packet& packet) = 0;
  501. /**
  502. * called by sdk when the audio packet is received from other participants
  503. * @param [in,out] packet
  504. * buffer *buffer points the data to be sent
  505. * size of buffer data to be sent
  506. * @return returns true to process the packet, returns false to discard the packet
  507. */
  508. virtual bool onReceiveAudioPacket(Packet& packet) = 0;
  509. /**
  510. * called by sdk when the video packet is received from other participants
  511. * @param [in,out] packet
  512. * buffer *buffer points the data to be sent
  513. * size of buffer data to be sent
  514. * @return returns true to process the packet, returns false to discard the packet
  515. */
  516. virtual bool onReceiveVideoPacket(Packet& packet) = 0;
  517. };
  518. /**
  519. * the event call back interface
  520. */
  521. class IRtcEngineEventHandler
  522. {
  523. public:
  524. virtual ~IRtcEngineEventHandler() {}
  525. /**
  526. * when join channel success, the function will be called
  527. * @param [in] channel
  528. * the channel name you have joined
  529. * @param [in] uid
  530. * the UID of you in this channel
  531. * @param [in] elapsed
  532. * the time elapsed in ms from the joinChannel been called to joining completed
  533. */
  534. virtual void onJoinChannelSuccess(const char* channel, uid_t uid, int elapsed) {
  535. (void)channel;
  536. (void)uid;
  537. (void)elapsed;
  538. }
  539. /**
  540. * when join channel success, the function will be called
  541. * @param [in] channel
  542. * the channel name you have joined
  543. * @param [in] uid
  544. * the UID of you in this channel
  545. * @param [in] elapsed
  546. * the time elapsed in ms elapsed
  547. */
  548. virtual void onRejoinChannelSuccess(const char* channel, uid_t uid, int elapsed) {
  549. (void)channel;
  550. (void)uid;
  551. (void)elapsed;
  552. }
  553. /**
  554. * when warning message coming, the function will be called
  555. * @param [in] warn
  556. * warning code
  557. * @param [in] msg
  558. * the warning message
  559. */
  560. virtual void onWarning(int warn, const char* msg) {
  561. (void)warn;
  562. (void)msg;
  563. }
  564. /**
  565. * when error message come, the function will be called
  566. * @param [in] err
  567. * error code
  568. * @param [in] msg
  569. * the error message
  570. */
  571. virtual void onError(int err, const char* msg) {
  572. (void)err;
  573. (void)msg;
  574. }
  575. /**
  576. * when audio quality message come, the function will be called
  577. * @param [in] uid
  578. * the uid of the peer
  579. * @param [in] quality
  580. * the quality of the user, see QUALITY_TYPE for value definition
  581. * @param [in] delay
  582. * the average time of the audio packages delayed
  583. * @param [in] lost
  584. * the rate of the audio packages lost
  585. */
  586. virtual void onAudioQuality(uid_t uid, int quality, unsigned short delay, unsigned short lost) {
  587. (void)uid;
  588. (void)quality;
  589. (void)delay;
  590. (void)lost;
  591. }
  592. /**
  593. * when the audio volume information come, the function will be called
  594. * @param [in] speakers
  595. * the array of the speakers' audio volume information
  596. * @param [in] speakerNumber
  597. * the count of speakers in this array
  598. * @param [in] totalVolume
  599. * the total volume of all users
  600. */
  601. virtual void onAudioVolumeIndication(const AudioVolumeInfo* speakers, unsigned int speakerNumber, int totalVolume) {
  602. (void)speakers;
  603. (void)speakerNumber;
  604. (void)totalVolume;
  605. }
  606. /**
  607. * when the audio volume information come, the function will be called
  608. * @param [in] stats
  609. * the statistics of the call
  610. */
  611. virtual void onLeaveChannel(const RtcStats& stats) {
  612. (void)stats;
  613. }
  614. /**
  615. * when the information of the RTC engine stats come, the function will be called
  616. * @param [in] stats
  617. * the RTC engine stats
  618. */
  619. virtual void onRtcStats(const RtcStats& stats) {
  620. (void)stats;
  621. }
  622. /**
  623. * when the audio device state changed(plugged or removed), the function will be called
  624. * @param [in] deviceId
  625. * the ID of the state changed audio device
  626. * @param [in] deviceType
  627. * the type of the audio device(playout device or record device)
  628. * @param [in] deviceState
  629. * the device is been removed or added
  630. */
  631. virtual void onAudioDeviceStateChanged(const char* deviceId, int deviceType, int deviceState) {
  632. (void)deviceId;
  633. (void)deviceType;
  634. (void)deviceState;
  635. }
  636. /**
  637. * When audio mixing file playback finished, this function will be called
  638. */
  639. virtual void onAudioMixingFinished() {
  640. }
  641. /**
  642. * When audio effect playback finished, this function will be called
  643. */
  644. virtual void onAudioEffectFinished(int soundId) {
  645. }
  646. /**
  647. * when the video device state changed(plugged or removed), the function will be called
  648. * @param [in] deviceId
  649. * the ID of the state changed video device
  650. * @param [in] deviceType
  651. * not used
  652. * @param [in] deviceState
  653. * the device is been removed or added
  654. */
  655. virtual void onVideoDeviceStateChanged(const char* deviceId, int deviceType, int deviceState) {
  656. (void)deviceId;
  657. (void)deviceType;
  658. (void)deviceState;
  659. }
  660. /**
  661. * report the network quality
  662. * @param [in] uid
  663. * the UID of the remote user
  664. * @param [in] txQuality
  665. * the score of the send network quality 0~5 the higher the better
  666. * @param [in] rxQuality
  667. * the score of the recv network quality 0~5 the higher the better
  668. */
  669. virtual void onNetworkQuality(uid_t uid, int txQuality, int rxQuality) {
  670. (void)uid;
  671. (void)txQuality;
  672. (void)rxQuality;
  673. }
  674. /**
  675. * report the last-mile test network quality
  676. * @param [in] quality
  677. * the score of the network quality 0~5 the higher the better
  678. */
  679. virtual void onLastmileQuality(int quality) {
  680. (void)quality;
  681. }
  682. /**
  683. * when the first local video frame displayed, the function will be called
  684. * @param [in] width
  685. * the width of the video frame
  686. * @param [in] height
  687. * the height of the video frame
  688. * @param [in] elapsed
  689. * the time elapsed from channel joined in ms
  690. */
  691. virtual void onFirstLocalVideoFrame(int width, int height, int elapsed) {
  692. (void)width;
  693. (void)height;
  694. (void)elapsed;
  695. }
  696. /**
  697. * when the first remote video frame decoded, the function will be called
  698. * @param [in] uid
  699. * the UID of the remote user
  700. * @param [in] width
  701. * the width of the video frame
  702. * @param [in] height
  703. * the height of the video frame
  704. * @param [in] elapsed
  705. * the time elapsed from channel joined in ms
  706. */
  707. virtual void onFirstRemoteVideoDecoded(uid_t uid, int width, int height, int elapsed) {
  708. (void)uid;
  709. (void)width;
  710. (void)height;
  711. (void)elapsed;
  712. }
  713. /**
  714. * when video size changed or rotation changed, the function will be called
  715. * @param [in] uid
  716. * the UID of the remote user or local user (0)
  717. * @param [in] width
  718. * the new width of the video
  719. * @param [in] height
  720. * the new height of the video
  721. * @param [in] rotation
  722. * the rotation of the video
  723. */
  724. virtual void onVideoSizeChanged(uid_t uid, int width, int height, int rotation) {
  725. (void)uid;
  726. (void)width;
  727. (void)height;
  728. (void)rotation;
  729. }
  730. /**
  731. * when the first remote video frame displayed, the function will be called
  732. * @param [in] uid
  733. * the UID of the remote user
  734. * @param [in] width
  735. * the width of the video frame
  736. * @param [in] height
  737. * the height of the video frame
  738. * @param [in] elapsed
  739. * the time elapsed from remote user called joinChannel in ms
  740. */
  741. virtual void onFirstRemoteVideoFrame(uid_t uid, int width, int height, int elapsed) {
  742. (void)uid;
  743. (void)width;
  744. (void)height;
  745. (void)elapsed;
  746. }
  747. /**
  748. * when any other user joined in the same channel, the function will be called
  749. * @param [in] uid
  750. * the UID of the remote user
  751. * @param [in] elapsed
  752. * the time elapsed from remote used called joinChannel to joining completed in ms
  753. */
  754. virtual void onUserJoined(uid_t uid, int elapsed) {
  755. (void)uid;
  756. (void)elapsed;
  757. }
  758. /**
  759. * when user offline(exit channel or offline by accident), the function will be called
  760. * @param [in] uid
  761. * the UID of the remote user
  762. */
  763. virtual void onUserOffline(uid_t uid, USER_OFFLINE_REASON_TYPE reason) {
  764. (void)uid;
  765. (void)reason;
  766. }
  767. /**
  768. * when remote user muted the audio stream, the function will be called
  769. * @param [in] uid
  770. * the UID of the remote user
  771. * @param [in] muted
  772. * true: the remote user muted the audio stream, false: the remote user unmuted the audio stream
  773. */
  774. virtual void onUserMuteAudio(uid_t uid, bool muted) {
  775. (void)uid;
  776. (void)muted;
  777. }
  778. /**
  779. * when remote user muted the video stream, the function will be called
  780. * @param [in] uid
  781. * the UID of the remote user
  782. * @param [in] muted
  783. * true: the remote user muted the video stream, false: the remote user unmuted the video stream
  784. */
  785. virtual void onUserMuteVideo(uid_t uid, bool muted) {
  786. (void)uid;
  787. (void)muted;
  788. }
  789. /**
  790. * when remote user enable video function, the function will be called
  791. * @param [in] uid
  792. * the UID of the remote user
  793. * @param [in] enabled
  794. * true: the remote user has enabled video function, false: the remote user has disabled video function
  795. */
  796. virtual void onUserEnableVideo(uid_t uid, bool enabled) {
  797. (void)uid;
  798. (void)enabled;
  799. }
  800. /**
  801. * when api call executed completely, the function will be called
  802. * @param [in] api
  803. * the api name
  804. * @param [in] error
  805. * error code while 0 means OK
  806. */
  807. virtual void onApiCallExecuted(const char* api, int error) {
  808. (void)api;
  809. (void)error;
  810. }
  811. /**
  812. * reported local video stats
  813. * @param [in] stats
  814. * the latest local video stats
  815. */
  816. virtual void onLocalVideoStats(const LocalVideoStats& stats) {
  817. (void)stats;
  818. }
  819. /**
  820. * reported remote video stats
  821. * @param [in] stats
  822. * the latest remote video stats
  823. */
  824. virtual void onRemoteVideoStats(const RemoteVideoStats& stats) {
  825. (void)stats;
  826. }
  827. /**
  828. * when the camera is ready to work, the function will be called
  829. */
  830. virtual void onCameraReady() {}
  831. /**
  832. * when all video stopped, the function will be called then you can repaint the video windows
  833. */
  834. virtual void onVideoStopped() {}
  835. /**
  836. * when the network can not worked well, the function will be called
  837. */
  838. virtual void onConnectionLost() {}
  839. /**
  840. * when local user disconnected by accident, the function will be called(then SDK will try to reconnect itself)
  841. */
  842. virtual void onConnectionInterrupted() {}
  843. virtual void onRefreshRecordingServiceStatus(int status) {
  844. (void)status;
  845. }
  846. // virtual void onStreamError(int streamId, int code, int parameter, const char* message, size_t length) {}
  847. /**
  848. * when stream message received, the function will be called
  849. * @param [in] uid
  850. * UID of the peer who sends the message
  851. * @param [in] streamId
  852. * APP can create multiple streams for sending messages of different purposes
  853. * @param [in] data
  854. * the message data
  855. * @param [in] length
  856. * the message length, in bytes
  857. * frame rate
  858. */
  859. virtual void onStreamMessage(uid_t uid, int streamId, const char* data, size_t length) {
  860. (void)uid;
  861. (void)streamId;
  862. (void)data;
  863. (void)length;
  864. }
  865. /**
  866. *
  867. */
  868. virtual void onStreamMessageError(uid_t uid, int streamId, int code, int missed, int cached) {
  869. (void)uid;
  870. (void)streamId;
  871. (void)code;
  872. (void)missed;
  873. (void)cached;
  874. }
  875. virtual void onMediaEngineLoadSuccess() {
  876. }
  877. virtual void onMediaEngineStartCallSuccess() {
  878. }
  879. /**
  880. * when channel key is enabled, and specified channel key is invalid or expired, this function will be called.
  881. * APP should generate a new channel key and call renewChannelKey() to refresh the key.
  882. * NOTE: to be compatible with previous version, ERR_CHANNEL_KEY_EXPIRED and ERR_INVALID_CHANNEL_KEY are also reported via onError() callback.
  883. * You should move renew of channel key logic into this callback.
  884. */
  885. virtual void onRequestChannelKey() {
  886. }
  887. /**
  888. * when the first local audio frame generated, the function will be called
  889. * @param [in] elapsed
  890. * the time elapsed from remote user called joinChannel in ms
  891. */
  892. virtual void onFirstLocalAudioFrame(int elapsed) {
  893. (void)elapsed;
  894. }
  895. /**
  896. * when the first remote audio frame arrived, the function will be called
  897. * @param [in] uid
  898. * the UID of the remote user
  899. * @param [in] elapsed
  900. * the time elapsed from remote user called joinChannel in ms
  901. */
  902. virtual void onFirstRemoteAudioFrame(uid_t uid, int elapsed) {
  903. (void)uid;
  904. (void)elapsed;
  905. }
  906. /** @param [in] uid
  907. * the speaker uid who is talking in the channel
  908. */
  909. virtual void onActiveSpeaker(uid_t uid) {
  910. (void)uid;
  911. }
  912. /**
  913. * when client role is successfully changed, the function will be called
  914. */
  915. virtual void onClientRoleChanged(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) {
  916. }
  917. };
  918. /**
  919. * the video device collection interface
  920. */
  921. class IVideoDeviceCollection
  922. {
  923. public:
  924. /**
  925. * get the audio device count
  926. * @return returns the audio device count
  927. */
  928. virtual int getCount() = 0;
  929. /**
  930. * get audio device information
  931. * @param [in] index
  932. * the index of the device in the device list
  933. * @param [in, out] deviceName
  934. * the device name, UTF8 format
  935. * @param [in, out] deviceId
  936. * the device ID, UTF8 format
  937. * @return return 0 if success or an error code
  938. */
  939. virtual int getDevice(int index, char deviceName[MAX_DEVICE_ID_LENGTH], char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  940. /**
  941. * set current active audio device
  942. * @param [in] deviceId
  943. * the deviceId of the device you want to active currently
  944. * @return return 0 if success or an error code
  945. */
  946. virtual int setDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  947. /**
  948. * release the resource
  949. */
  950. virtual void release() = 0;
  951. };
  952. class IVideoDeviceManager
  953. {
  954. public:
  955. /**
  956. * create the IVideoDeviceCollection interface pointer
  957. * @return return the IVideoDeviceCollection interface or nullptr if failed
  958. */
  959. virtual IVideoDeviceCollection* enumerateVideoDevices() = 0;
  960. /**
  961. * active the video device for current using
  962. * @param [in] deviceId
  963. * the deviceId of the device you want to active currently
  964. * @return return 0 if success or the error code.
  965. */
  966. virtual int setDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  967. /**
  968. * get the current active video device
  969. * @param [in, out] deviceId
  970. * the device id of the current active video device
  971. * @return return 0 if success or an error code
  972. */
  973. virtual int getDevice(char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  974. /**
  975. * test the video capture device to know whether it can worked well
  976. * @param [in] hwnd
  977. * the HWND of the video-display window
  978. * @return return 0 if success or an error code
  979. */
  980. virtual int startDeviceTest(view_t hwnd) = 0;
  981. /**
  982. * stop the video device testing
  983. * @return return 0 if success or an error code
  984. */
  985. virtual int stopDeviceTest() = 0;
  986. /**
  987. * release the resource
  988. */
  989. virtual void release() = 0;
  990. };
  991. class IAudioDeviceCollection
  992. {
  993. public:
  994. /**
  995. * get the available devices count
  996. * @return return the device count
  997. */
  998. virtual int getCount() = 0;
  999. /**
  1000. * get video device information
  1001. * @param [in] index
  1002. * the index of the device in the device list
  1003. * @param [in, out] deviceName
  1004. * the device name, UTF8 format
  1005. * @param [in, out] deviceId
  1006. * the device ID, UTF8 format
  1007. * @return return 0 if success or an error code
  1008. */
  1009. virtual int getDevice(int index, char deviceName[MAX_DEVICE_ID_LENGTH], char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  1010. /**
  1011. * active the device for current using
  1012. * @param [in] deviceId
  1013. * the deviceId of the device you want to active currently
  1014. * @return return 0 if success or the error code.
  1015. */
  1016. virtual int setDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  1017. /**
  1018. * release the resource
  1019. */
  1020. virtual void release() = 0;
  1021. };
  1022. class IAudioDeviceManager
  1023. {
  1024. public:
  1025. /**
  1026. * create the IAudioDeviceCollection interface pointer of the playback devices
  1027. * @return return the IVideoDeviceCollection interface or nullptr if failed
  1028. */
  1029. virtual IAudioDeviceCollection* enumeratePlaybackDevices() = 0;
  1030. /**
  1031. * create the IAudioDeviceCollection interface pointer of the Recording devices
  1032. * @return return the IVideoDeviceCollection interface or nullptr if failed
  1033. */
  1034. virtual IAudioDeviceCollection* enumerateRecordingDevices() = 0;
  1035. /**
  1036. * active the playback device for current using
  1037. * @param [in] deviceId
  1038. * the deviceId of the playback device you want to active currently
  1039. * @return return 0 if success or the error code.
  1040. */
  1041. virtual int setPlaybackDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  1042. /**
  1043. * get the current active playback device
  1044. * @param [in, out] deviceId
  1045. * the device id of the current active video device
  1046. * @return return 0 if success or an error code
  1047. */
  1048. virtual int getPlaybackDevice(char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  1049. /**
  1050. * set current playback device volume
  1051. * @param [in] volume
  1052. * the volume you want to set 0-255
  1053. * @return return 0 if success or an error code
  1054. */
  1055. virtual int setPlaybackDeviceVolume(int volume) = 0;
  1056. /**
  1057. * get current playback device volume
  1058. * @param [in, out] volume
  1059. * the current playback device volume 0-255
  1060. * @return return 0 if success or an error code
  1061. */
  1062. virtual int getPlaybackDeviceVolume(int *volume) = 0;
  1063. /**
  1064. * active the recording audio device for current using
  1065. * @param [in] deviceId
  1066. * the deviceId of the recording audio device you want to active currently
  1067. * @return return 0 if success or the error code.
  1068. */
  1069. virtual int setRecordingDevice(const char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  1070. /**
  1071. * get the current active recording device
  1072. * @param [in, out] deviceId
  1073. * the device id of the current active recording audio device
  1074. * @return return 0 if success or an error code
  1075. */
  1076. virtual int getRecordingDevice(char deviceId[MAX_DEVICE_ID_LENGTH]) = 0;
  1077. /**
  1078. * set current recording device volume
  1079. * @param [in] volume
  1080. * the volume you want to set 0-255
  1081. * @return return 0 if success or an error code
  1082. */
  1083. virtual int setRecordingDeviceVolume(int volume) = 0;
  1084. /**
  1085. * get current recording device volume
  1086. * @param [in, out] volume
  1087. * the current recording device volume 0-255
  1088. * @return return 0 if success or an error code
  1089. */
  1090. virtual int getRecordingDeviceVolume(int *volume) = 0;
  1091. /**
  1092. * test the playback audio device to know whether it can worked well
  1093. * @param [in] testAudioFilePath
  1094. * the path of the .wav file
  1095. * @return return 0 if success and you can hear the sound of the .wav file or an error code.
  1096. */
  1097. virtual int startPlaybackDeviceTest(const char* testAudioFilePath) = 0;
  1098. /**
  1099. * stop the playback audio device testing
  1100. * @return return 0 if success or an error code
  1101. */
  1102. virtual int stopPlaybackDeviceTest() = 0;
  1103. /**
  1104. * test the recording audio device to know whether it can worked well
  1105. * @param [in] indicationInterval
  1106. * the period in ms of the call back cycle
  1107. * @return return 0 if success or an error code
  1108. */
  1109. virtual int startRecordingDeviceTest(int indicationInterval) = 0;
  1110. /**
  1111. * stop the recording audio device testing
  1112. * @return return 0 if success or an error code
  1113. */
  1114. virtual int stopRecordingDeviceTest() = 0;
  1115. /**
  1116. * release the resource
  1117. */
  1118. virtual void release() = 0;
  1119. };
  1120. struct RtcEngineContext
  1121. {
  1122. IRtcEngineEventHandler* eventHandler;
  1123. const char* appId;
  1124. RtcEngineContext()
  1125. :eventHandler(NULL)
  1126. ,appId(NULL)
  1127. {}
  1128. };
  1129. class IRtcEngine
  1130. {
  1131. public:
  1132. /**
  1133. * release the engine resource
  1134. * @param [in] sync
  1135. * true: release the engine resources and return after all resources have been destroyed.
  1136. * APP should try not to call release(true) in the engine's callbacks, call it this way in a separate thread instead.
  1137. * false: notify engine to release its resources and returns without waiting for resources are really destroyed
  1138. */
  1139. virtual void release(bool sync=false) = 0;
  1140. /**
  1141. * initialize the engine
  1142. * @param [in] context
  1143. * the RTC engine context
  1144. * @return return 0 if success or an error code
  1145. */
  1146. virtual int initialize(const RtcEngineContext& context) = 0;
  1147. /**
  1148. * get the pointer of the device manager object.
  1149. * @param [in] iid
  1150. * the iid of the interface you want to get
  1151. * @param [in, out] inter
  1152. * the pointer of the pointer you want to point to DeviceManager object
  1153. * @return return 0 if success or an error code
  1154. */
  1155. virtual int queryInterface(INTERFACE_ID_TYPE iid, void** inter) = 0;
  1156. /**
  1157. * get the version information of the SDK
  1158. * @param [in, out] build
  1159. * the build number
  1160. * @return return the version number string in char format
  1161. */
  1162. virtual const char* getVersion(int* build) = 0;
  1163. /**
  1164. * get the version information of the SDK
  1165. * @param [in, out] code
  1166. * the build number
  1167. * @return return the version number string in char format
  1168. */
  1169. virtual const char* getErrorDescription(int code) = 0;
  1170. /**
  1171. * join the channel, if the channel have not been created, it will been created automatically
  1172. * @param [in] channelKey
  1173. * the channel key, if you have initialized the engine with an available APP ID, it can be null here. If you enable channel key on the dashboard, specify channel key here
  1174. * @param [in] channelName
  1175. * the channel name
  1176. * @param [in] info
  1177. * the additional information, it can be null here
  1178. * @param [in] uid
  1179. * the uid of you, if 0 the system will automatically allocate one for you
  1180. * @return return 0 if success or an error code
  1181. */
  1182. virtual int joinChannel(const char* channelKey, const char* channelName, const char* info, uid_t uid) = 0;
  1183. /**
  1184. * leave the current channel
  1185. * @return return 0 if success or an error code
  1186. */
  1187. virtual int leaveChannel() = 0;
  1188. /**
  1189. * renew the channel key for the current channel
  1190. * @param [in] channelKey the renewed channel key, if old channel key expired.
  1191. * @return return 0 if success or an error code
  1192. */
  1193. virtual int renewChannelKey(const char* channelKey) = 0;
  1194. virtual int setChannelProfile(CHANNEL_PROFILE_TYPE profile) = 0;
  1195. virtual int setClientRole(CLIENT_ROLE_TYPE role, const char* permissionKey) = 0;
  1196. /**
  1197. * start the echo testing, if every thing goes well you can hear your echo from the server
  1198. * @return return 0 if success or an error code
  1199. */
  1200. virtual int startEchoTest() = 0;
  1201. /**
  1202. * stop the echo testing
  1203. * @return return 0 if success or an error code
  1204. */
  1205. virtual int stopEchoTest() = 0;
  1206. /**
  1207. * start the network testing
  1208. * @return return 0 if success or an error code
  1209. */
  1210. virtual int enableLastmileTest() = 0;
  1211. /**
  1212. * stop the network testing
  1213. * @return return 0 if success or an error code
  1214. */
  1215. virtual int disableLastmileTest() = 0;
  1216. /**
  1217. * enable video function
  1218. * @return return 0 if success or an error code
  1219. */
  1220. virtual int enableVideo() = 0;
  1221. /**
  1222. * disable video function
  1223. * @return return 0 if success or an error code
  1224. */
  1225. virtual int disableVideo() = 0;
  1226. /**
  1227. * start the local video previewing
  1228. * @return return 0 if success or an error code
  1229. */
  1230. virtual int startPreview() = 0;
  1231. /**
  1232. * stop the local video previewing
  1233. * @return return 0 if success or an error code
  1234. */
  1235. virtual int stopPreview() = 0;
  1236. virtual int setVideoProfile(VIDEO_PROFILE_TYPE profile, bool swapWidthAndHeight) = 0;
  1237. /**
  1238. * set the remote video canvas
  1239. * @param [in] canvas
  1240. * the canvas information
  1241. * @return return 0 if success or an error code
  1242. */
  1243. virtual int setupRemoteVideo(const VideoCanvas& canvas) = 0;
  1244. /**
  1245. * set the local video canvas
  1246. * @param [in] canvas
  1247. * the canvas information
  1248. * @return return 0 if success or an error code
  1249. */
  1250. virtual int setupLocalVideo(const VideoCanvas& canvas) = 0;
  1251. /**
  1252. * enable audio function, which is enabled by deault.
  1253. * @return return 0 if success or an error code
  1254. */
  1255. virtual int enableAudio() = 0;
  1256. /**
  1257. * disable audio function
  1258. * @return return 0 if success or an error code
  1259. */
  1260. virtual int disableAudio() = 0;
  1261. /**
  1262. * get self call id in the current channel
  1263. * @param [in, out] callId
  1264. * the self call Id
  1265. * @return return 0 if success or an error code
  1266. */
  1267. virtual int getCallId(agora::util::AString& callId) = 0;
  1268. virtual int rate(const char* callId, int rating, const char* description) = 0; // 0~10
  1269. virtual int complain(const char* callId, const char* description) = 0;
  1270. /**
  1271. * register a packet observer while the packet arrived or ready to be sent, the observer can touch the packet data
  1272. * @param [in] observer
  1273. * the pointer of the observer object
  1274. * @return return 0 if success or an error code
  1275. */
  1276. virtual int registerPacketObserver(IPacketObserver* observer) = 0;
  1277. /**
  1278. * Specify encryption mode of AES encryption algorithm.
  1279. * @param [in] encryptionMode
  1280. * encryption mode of AES algorithm, could be one of the following:
  1281. * "aes-128-xts", "aes-256-xts".
  1282. * The default value is "aes-128-xts". specify NULL value will use default encryption mode.
  1283. * @return return 0 if success or an error code
  1284. */
  1285. virtual int setEncryptionMode(const char* encryptionMode) = 0;
  1286. /**
  1287. * Specify encryption secret enables built-in encryption function. Leaving channel will clear the secret specified in last channel
  1288. * @param [in] secret
  1289. * secret to enable encryption
  1290. * @return return 0 if success or an error code
  1291. */
  1292. virtual int setEncryptionSecret(const char* secret) = 0;
  1293. virtual int createDataStream(int* streamId, bool reliable, bool ordered) = 0;
  1294. virtual int sendStreamMessage(int streamId, const char* data, size_t length) = 0;
  1295. virtual int setVideoCompositingLayout(const VideoCompositingLayout& sei) = 0;
  1296. virtual int clearVideoCompositingLayout() = 0;
  1297. #if defined(_WIN32)
  1298. virtual int configPublisher(const PublisherConfiguration& config) = 0;
  1299. #endif
  1300. };
  1301. class IRtcEngineParameter
  1302. {
  1303. public:
  1304. /**
  1305. * release the resource
  1306. */
  1307. virtual void release() = 0;
  1308. /**
  1309. * set bool value of the json
  1310. * @param [in] key
  1311. * the key name
  1312. * @param [in] value
  1313. * the value
  1314. * @return return 0 if success or an error code
  1315. */
  1316. virtual int setBool(const char* key, bool value) = 0;
  1317. /**
  1318. * set int value of the json
  1319. * @param [in] key
  1320. * the key name
  1321. * @param [in] value
  1322. * the value
  1323. * @return return 0 if success or an error code
  1324. */
  1325. virtual int setInt(const char* key, int value) = 0;
  1326. /**
  1327. * set unsigned int value of the json
  1328. * @param [in] key
  1329. * the key name
  1330. * @param [in] value
  1331. * the value
  1332. * @return return 0 if success or an error code
  1333. */
  1334. virtual int setUInt(const char* key, unsigned int value) = 0;
  1335. /**
  1336. * set double value of the json
  1337. * @param [in] key
  1338. * the key name
  1339. * @param [in] value
  1340. * the value
  1341. * @return return 0 if success or an error code
  1342. */
  1343. virtual int setNumber(const char* key, double value) = 0;
  1344. /**
  1345. * set string value of the json
  1346. * @param [in] key
  1347. * the key name
  1348. * @param [in] value
  1349. * the value
  1350. * @return return 0 if success or an error code
  1351. */
  1352. virtual int setString(const char* key, const char* value) = 0;
  1353. /**
  1354. * set object value of the json
  1355. * @param [in] key
  1356. * the key name
  1357. * @param [in] value
  1358. * the value
  1359. * @return return 0 if success or an error code
  1360. */
  1361. virtual int setObject(const char* key, const char* value) = 0;
  1362. /**
  1363. * get bool value of the json
  1364. * @param [in] key
  1365. * the key name
  1366. * @param [in, out] value
  1367. * the value
  1368. * @return return 0 if success or an error code
  1369. */
  1370. virtual int getBool(const char* key, bool& value) = 0;
  1371. /**
  1372. * get int value of the json
  1373. * @param [in] key
  1374. * the key name
  1375. * @param [in, out] value
  1376. * the value
  1377. * @return return 0 if success or an error code
  1378. */
  1379. virtual int getInt(const char* key, int& value) = 0;
  1380. /**
  1381. * get unsigned int value of the json
  1382. * @param [in] key
  1383. * the key name
  1384. * @param [in, out] value
  1385. * the value
  1386. * @return return 0 if success or an error code
  1387. */
  1388. virtual int getUInt(const char* key, unsigned int& value) = 0;
  1389. /**
  1390. * get double value of the json
  1391. * @param [in] key
  1392. * the key name
  1393. * @param [in, out] value
  1394. * the value
  1395. * @return return 0 if success or an error code
  1396. */
  1397. virtual int getNumber(const char* key, double& value) = 0;
  1398. /**
  1399. * get string value of the json
  1400. * @param [in] key
  1401. * the key name
  1402. * @param [in, out] value
  1403. * the value
  1404. * @return return 0 if success or an error code
  1405. */
  1406. virtual int getString(const char* key, agora::util::AString& value) = 0;
  1407. /**
  1408. * get a child object value of the json
  1409. * @param [in] key
  1410. * the key name
  1411. * @param [in, out] value
  1412. * the value
  1413. * @return return 0 if success or an error code
  1414. */
  1415. virtual int getObject(const char* key, agora::util::AString& value) = 0;
  1416. /**
  1417. * get array value of the json
  1418. * @param [in] key
  1419. * the key name
  1420. * @param [in, out] value
  1421. * the value
  1422. * @return return 0 if success or an error code
  1423. */
  1424. virtual int getArray(const char* key, agora::util::AString& value) = 0;
  1425. /**
  1426. * set parameters of the sdk or engine
  1427. * @param [in] parameters
  1428. * the parameters
  1429. * @return return 0 if success or an error code
  1430. */
  1431. virtual int setParameters(const char* parameters) = 0;
  1432. /**
  1433. * set profile to control the RTC engine
  1434. * @param [in] profile
  1435. * the profile
  1436. * @param [in] merge
  1437. * if merge with the original value
  1438. * @return return 0 if success or an error code
  1439. */
  1440. virtual int setProfile(const char* profile, bool merge) = 0;
  1441. virtual int convertPath(const char* filePath, agora::util::AString& value) = 0;
  1442. };
  1443. class AAudioDeviceManager : public agora::util::AutoPtr<IAudioDeviceManager>
  1444. {
  1445. public:
  1446. AAudioDeviceManager(IRtcEngine* engine)
  1447. {
  1448. queryInterface(engine, AGORA_IID_AUDIO_DEVICE_MANAGER);
  1449. }
  1450. };
  1451. class AVideoDeviceManager : public agora::util::AutoPtr<IVideoDeviceManager>
  1452. {
  1453. public:
  1454. AVideoDeviceManager(IRtcEngine* engine)
  1455. {
  1456. queryInterface(engine, AGORA_IID_VIDEO_DEVICE_MANAGER);
  1457. }
  1458. };
  1459. class AParameter : public agora::util::AutoPtr<IRtcEngineParameter>
  1460. {
  1461. public:
  1462. AParameter(IRtcEngine& engine) { initialize(&engine); }
  1463. AParameter(IRtcEngine* engine) { initialize(engine); }
  1464. AParameter(IRtcEngineParameter* p) :agora::util::AutoPtr<IRtcEngineParameter>(p) {}
  1465. private:
  1466. bool initialize(IRtcEngine* engine)
  1467. {
  1468. IRtcEngineParameter* p = NULL;
  1469. if (engine && !engine->queryInterface(AGORA_IID_RTC_ENGINE_PARAMETER, (void**)&p))
  1470. reset(p);
  1471. return p != NULL;
  1472. }
  1473. };
  1474. class RtcEngineParameters
  1475. {
  1476. public:
  1477. RtcEngineParameters(IRtcEngine& engine)
  1478. :m_parameter(&engine){}
  1479. RtcEngineParameters(IRtcEngine* engine)
  1480. :m_parameter(engine){}
  1481. /**
  1482. * mute/unmute the local stream capturing
  1483. * @param [in] mute
  1484. * true: mute
  1485. * false: unmute
  1486. * @return return 0 if success or an error code
  1487. */
  1488. int muteLocalAudioStream(bool mute) {
  1489. return setParameters("{\"rtc.audio.mute_me\":%s,\"che.audio.mute_me\":%s}", mute ? "true" : "false", mute ? "true" : "false");
  1490. }
  1491. // mute/unmute all peers. unmute will clear all muted peers specified mutePeer() interface
  1492. /**
  1493. * mute/unmute all the remote audio stream receiving
  1494. * @param [in] mute
  1495. * true: mute
  1496. * false: unmute
  1497. * @return return 0 if success or an error code
  1498. */
  1499. int muteAllRemoteAudioStreams(bool mute) {
  1500. return m_parameter ? m_parameter->setBool("rtc.audio.mute_peers", mute) : -ERR_NOT_INITIALIZED;
  1501. }
  1502. /**
  1503. * mute/unmute one remote audio stream receiving
  1504. * @param [in] uid
  1505. * the uid of the remote user you want to mute/unmute
  1506. * @param [in] mute
  1507. * true: mute
  1508. * false: unmute
  1509. * @return return 0 if success or an error code
  1510. */
  1511. int muteRemoteAudioStream(uid_t uid, bool mute) {
  1512. return setObject("rtc.audio.mute_peer", "{\"uid\":%u,\"mute\":%s}", uid, mute?"true":"false");
  1513. }
  1514. /**
  1515. * mute/unmute local video stream sending
  1516. * @param [in] mute
  1517. * true: mute
  1518. * false: unmute
  1519. * @return return 0 if success or an error code
  1520. */
  1521. int muteLocalVideoStream(bool mute) {
  1522. return setParameters("{\"rtc.video.mute_me\":%s,\"che.video.local.send\":%s}", mute ? "true" : "false", mute ? "false" : "true");
  1523. }
  1524. int enableLocalVideo(bool enabled) {
  1525. return setParameters("{\"rtc.video.capture\":%s,\"che.video.local.capture\":%s,\"che.video.local.render\":%s,\"che.video.local.send\":%s}", enabled ? "true" : "false", enabled ? "true" : "false", enabled ? "true" : "false", enabled ? "true" : "false");
  1526. }
  1527. /**
  1528. * mute/unmute all the remote video stream receiving
  1529. * @param [in] mute
  1530. * true: mute
  1531. * false: unmute
  1532. * @return return 0 if success or an error code
  1533. */
  1534. int muteAllRemoteVideoStreams(bool mute) {
  1535. return m_parameter ? m_parameter->setBool("rtc.video.mute_peers", mute) : -ERR_NOT_INITIALIZED;
  1536. }
  1537. /**
  1538. * mute/unmute one remote video stream receiving
  1539. * @param [in] uid
  1540. * the uid of the remote user you want to mute/unmute
  1541. * @param [in] mute
  1542. * true: mute
  1543. * false: unmute
  1544. * @return return 0 if success or an error code
  1545. */
  1546. int muteRemoteVideoStream(uid_t uid, bool mute) {
  1547. return setObject("rtc.video.mute_peer", "{\"uid\":%u,\"mute\":%s}", uid, mute ? "true" : "false");
  1548. }
  1549. int setRemoteVideoStreamType(uid_t uid, REMOTE_VIDEO_STREAM_TYPE streamType) {
  1550. return setObject("rtc.video.set_remote_video_stream", "{\"uid\":%u,\"stream\":%d}", uid, streamType);
  1551. }
  1552. /**
  1553. * set play sound volume
  1554. * @param [in] volume
  1555. * the volume 0~255
  1556. * @return return 0 if success or an error code
  1557. */
  1558. int setPlaybackDeviceVolume(int volume) {// [0,255]
  1559. return m_parameter ? m_parameter->setInt("che.audio.output.volume", volume) : -ERR_NOT_INITIALIZED;
  1560. }
  1561. /**
  1562. * enable or disable the audio volume indication
  1563. * @param [in] interval
  1564. * the period of the call back cycle, in ms
  1565. * interval <= 0: disable
  1566. * interval > 0: enable
  1567. * @param [in] smooth
  1568. * the smooth parameter
  1569. * @return return 0 if success or an error code
  1570. */
  1571. int enableAudioVolumeIndication(int interval, int smooth) { // in ms: <= 0: disable, > 0: enable, interval in ms
  1572. if (interval < 0)
  1573. interval = 0;
  1574. return setObject("che.audio.volume_indication", "{\"interval\":%d,\"smooth\":%d}", interval, smooth);
  1575. }
  1576. /**
  1577. * start recording the audio stream
  1578. * @param [in] filePath
  1579. * the .wav file path you want to saved
  1580. * @return return 0 if success or an error code
  1581. */
  1582. int startAudioRecording(const char* filePath, AUDIO_RECORDING_QUALITY_TYPE quality) {
  1583. if (!m_parameter) return -ERR_NOT_INITIALIZED;
  1584. #if defined(_WIN32)
  1585. util::AString path;
  1586. if (!m_parameter->convertPath(filePath, path))
  1587. filePath = path->c_str();
  1588. else
  1589. return -ERR_INVALID_ARGUMENT;
  1590. #endif
  1591. return setObject("che.audio.start_recording", "{\"filePath\":\"%s\",\"quality\":%d}", filePath, quality);
  1592. }
  1593. /**
  1594. * stop recording the audio stream
  1595. * @return return 0 if success or an error code
  1596. */
  1597. int stopAudioRecording() {
  1598. return m_parameter ? m_parameter->setBool("che.audio.stop_recording", true) : -ERR_NOT_INITIALIZED;
  1599. }
  1600. /**
  1601. * mix microphone and local audio file into the audio stream
  1602. * @param [in] filePath
  1603. * specify the path and file name of the audio file to be played
  1604. * @param [in] loopback
  1605. * specify if local and remote participant can hear the audio file.
  1606. * false (default): both local and remote party can hear the the audio file
  1607. * true: only the local party can hear the audio file
  1608. * @param [in] replace
  1609. * false (default): mix the local microphone captured voice with the audio file
  1610. * true: replace the microphone captured voice with the audio file
  1611. * @param [in] cycle
  1612. * specify the number of cycles to play
  1613. * -1, infinite loop playback
  1614. * @return return 0 if success or an error code
  1615. */
  1616. int startAudioMixing(const char* filePath, bool loopback, bool replace, int cycle) {
  1617. if (!m_parameter) return -ERR_NOT_INITIALIZED;
  1618. #if defined(_WIN32)
  1619. util::AString path;
  1620. if (!m_parameter->convertPath(filePath, path))
  1621. filePath = path->c_str();
  1622. else
  1623. return -ERR_INVALID_ARGUMENT;
  1624. #endif
  1625. return setObject("che.audio.start_file_as_playout", "{\"filePath\":\"%s\",\"loopback\":%s,\"replace\":%s,\"cycle\":%d}",
  1626. filePath,
  1627. loopback?"true":"false",
  1628. replace?"true":"false",
  1629. cycle);
  1630. }
  1631. /**
  1632. * stop mixing the local audio stream
  1633. * @return return 0 if success or an error code
  1634. */
  1635. int stopAudioMixing() {
  1636. return m_parameter ? m_parameter->setBool("che.audio.stop_file_as_playout", true) : -ERR_NOT_INITIALIZED;
  1637. }
  1638. int pauseAudioMixing() {
  1639. return m_parameter ? m_parameter->setBool("che.audio.pause_file_as_playout", true) : -ERR_NOT_INITIALIZED;
  1640. }
  1641. int resumeAudioMixing() {
  1642. return m_parameter ? m_parameter->setBool("che.audio.pause_file_as_playout", false) : -ERR_NOT_INITIALIZED;
  1643. }
  1644. int adjustAudioMixingVolume(int volume) {
  1645. return m_parameter ? m_parameter->setInt("che.audio.set_file_as_playout_volume", volume) : -ERR_NOT_INITIALIZED;
  1646. }
  1647. int getAudioMixingDuration() {
  1648. int duration = 0;
  1649. int r = m_parameter ? m_parameter->getInt("che.audio.get_mixing_file_length_ms", duration) : -ERR_NOT_INITIALIZED;
  1650. if (r == 0)
  1651. r = duration;
  1652. return r;
  1653. }
  1654. int getAudioMixingCurrentPosition() {
  1655. if (!m_parameter) return -ERR_NOT_INITIALIZED;
  1656. int pos = 0;
  1657. int r = m_parameter->getInt("che.audio.get_mixing_file_played_ms", pos);
  1658. if (r == 0)
  1659. r = pos;
  1660. return r;
  1661. }
  1662. int setAudioMixingPosition(int pos /*in ms*/) {
  1663. return m_parameter ? m_parameter->setInt("che.audio.mixing.file.position", pos) : -ERR_NOT_INITIALIZED;
  1664. }
  1665. #if defined(__APPLE__)
  1666. /**
  1667. * start screen/windows capture
  1668. *
  1669. * @param windowId screen capture, if windowId is 0; windows capture if windowsId isn't 0;
  1670. * @param rect valid when windowId is 0; whole screen if rect is NULL.
  1671. *
  1672. * @return return 0 if success or an error code
  1673. */
  1674. int startScreenCapture(unsigned int windowId, int captureFreq, const Rect *rect) {
  1675. if (!rect)
  1676. return setObject("che.video.start_screen_capture", "{\"id\":%u,\"captureFreq\":%d}", windowId, captureFreq);
  1677. else
  1678. return setObject("che.video.start_screen_capture", "{\"id\":%u,\"captureFreq\":%d,\"top\":%d,\"left\":%d,\"bottom\":%d,\"right\":%d}", windowId, captureFreq, rect->top, rect->left, rect->bottom, rect->right);
  1679. }
  1680. /**
  1681. * stop screen capture
  1682. * @return return 0 if success or an error code
  1683. */
  1684. int stopScreenCapture() {
  1685. return m_parameter ? m_parameter->setBool("che.video.stop_screen_capture", true) : -ERR_NOT_INITIALIZED;
  1686. }
  1687. /**
  1688. * update screen capture region
  1689. *
  1690. * @param rect valid when windowId is 0; whole screen if rect is NULL.
  1691. *
  1692. * @return return 0 if success or an error code
  1693. */
  1694. int updateScreenCaptureRegion(const Rect *rect) {
  1695. if (!rect)
  1696. return setObject("che.video.update_screen_capture_region", "{}");
  1697. else
  1698. return setObject("che.video.update_screen_capture_region", "{\"top\":%d,\"left\":%d,\"bottom\":%d,\"right\":%d}", rect->top, rect->left, rect->bottom, rect->right);
  1699. }
  1700. #elif defined(_WIN32)
  1701. /**
  1702. * start screen/windows capture
  1703. *
  1704. * @param windowId screen capture, if windowId is 0; windows capture if windowsId isn't 0;
  1705. * @param rect valid when windowId is 0; whole screen if rect is NULL.
  1706. *
  1707. * @return return 0 if success or an error code
  1708. */
  1709. int startScreenCapture(HWND windowId, int captureFreq, const Rect *rect) {
  1710. if (!rect)
  1711. return setObject("che.video.start_screen_capture", "{\"id\":%u,\"captureFreq\":%d}", (unsigned int)windowId, captureFreq);
  1712. else
  1713. return setObject("che.video.start_screen_capture", "{\"id\":%u,\"captureFreq\":%d,\"top\":%d,\"left\":%d,\"bottom\":%d,\"right\":%d}", (unsigned int)windowId, captureFreq, rect->top, rect->left, rect->bottom, rect->right);
  1714. }
  1715. /**
  1716. * stop screen capture
  1717. * @return return 0 if success or an error code
  1718. */
  1719. int stopScreenCapture() {
  1720. return m_parameter ? m_parameter->setBool("che.video.stop_screen_capture", true) : -ERR_NOT_INITIALIZED;
  1721. }
  1722. /**
  1723. * update screen capture region
  1724. *
  1725. * @param rect valid when windowId is 0; whole screen if rect is NULL.
  1726. *
  1727. * @return return 0 if success or an error code
  1728. */
  1729. int updateScreenCaptureRegion(const Rect *rect) {
  1730. if (!rect)
  1731. return setObject("che.video.update_screen_capture_region", "{}");
  1732. else
  1733. return setObject("che.video.update_screen_capture_region", "{\"top\":%d,\"left\":%d,\"bottom\":%d,\"right\":%d}", rect->top, rect->left, rect->bottom, rect->right);
  1734. }
  1735. #endif
  1736. /**
  1737. * set path to save the log file
  1738. * @param [in] filePath
  1739. * the .log file path you want to saved
  1740. * @return return 0 if success or an error code
  1741. */
  1742. int setLogFile(const char* filePath) {
  1743. if (!m_parameter) return -ERR_NOT_INITIALIZED;
  1744. #if defined(_WIN32)
  1745. util::AString path;
  1746. if (!m_parameter->convertPath(filePath, path))
  1747. filePath = path->c_str();
  1748. else if (!filePath)
  1749. filePath = "";
  1750. #endif
  1751. return m_parameter->setString("rtc.log_file", filePath);
  1752. }
  1753. /**
  1754. * set the log information filter level
  1755. * @param [in] filter
  1756. * the filter level
  1757. * @return return 0 if success or an error code
  1758. */
  1759. int setLogFilter(unsigned int filter) {
  1760. return m_parameter ? m_parameter->setUInt("rtc.log_filter", filter&LOG_FILTER_MASK) : -ERR_NOT_INITIALIZED;
  1761. }
  1762. /**
  1763. * set local video render mode
  1764. * @param [in] renderMode
  1765. * the render mode
  1766. * @return return 0 if success or an error code
  1767. */
  1768. int setLocalRenderMode(RENDER_MODE_TYPE renderMode) {
  1769. return setRemoteRenderMode(0, renderMode);
  1770. }
  1771. /**
  1772. * set remote video render mode
  1773. * @param [in] renderMode
  1774. * the render mode
  1775. * @return return 0 if success or an error code
  1776. */
  1777. int setRemoteRenderMode(uid_t uid, RENDER_MODE_TYPE renderMode) {
  1778. return setObject("che.video.render_mode", "{\"uid\":%u,\"mode\":%d}", uid, renderMode);
  1779. }
  1780. int setLocalVideoMirrorMode(VIDEO_MIRROR_MODE_TYPE mirrorMode) {
  1781. if (!m_parameter) return -ERR_NOT_INITIALIZED;
  1782. const char *value;
  1783. switch (mirrorMode) {
  1784. case VIDEO_MIRROR_MODE_AUTO:
  1785. value = "default";
  1786. break;
  1787. case VIDEO_MIRROR_MODE_ENABLED:
  1788. value = "forceMirror";
  1789. break;
  1790. case VIDEO_MIRROR_MODE_DISABLED:
  1791. value = "disableMirror";
  1792. break;
  1793. default:
  1794. return -ERR_INVALID_ARGUMENT;
  1795. }
  1796. return m_parameter->setString("che.video.localViewMirrorSetting", value);
  1797. }
  1798. int startRecordingService(const char* recordingKey) {
  1799. return m_parameter ? m_parameter->setString("rtc.api.start_recording_service", recordingKey) : -ERR_NOT_INITIALIZED;
  1800. }
  1801. int stopRecordingService(const char* recordingKey) {
  1802. return m_parameter ? m_parameter->setString("rtc.api.stop_recording_service", recordingKey) : -ERR_NOT_INITIALIZED;
  1803. }
  1804. int refreshRecordingServiceStatus() {
  1805. return m_parameter ? m_parameter->setBool("rtc.api.query_recording_service_status", true) : -ERR_NOT_INITIALIZED;
  1806. }
  1807. int enableDualStreamMode(bool enabled) {
  1808. return setParameters("{\"rtc.dual_stream_mode\":%s,\"che.video.enableLowBitRateStream\":%s}", enabled ? "true" : "false", enabled ? "true" : "false");
  1809. }
  1810. int setRecordingAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) {
  1811. return setObject("che.audio.set_capture_raw_audio_format", "{\"sampleRate\":%d,\"channelCnt\":%d,\"mode\":%d,\"samplesPerCall\":%d}", sampleRate, channel, mode, samplesPerCall);
  1812. }
  1813. int setPlaybackAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) {
  1814. return setObject("che.audio.set_render_raw_audio_format", "{\"sampleRate\":%d,\"channelCnt\":%d,\"mode\":%d,\"samplesPerCall\":%d}", sampleRate, channel, mode, samplesPerCall);
  1815. }
  1816. int setMixedAudioFrameParameters(int sampleRate, int samplesPerCall) {
  1817. return setObject("che.audio.set_mixed_raw_audio_format", "{\"sampleRate\":%d,\"samplesPerCall\":%d}", sampleRate, samplesPerCall);
  1818. }
  1819. int adjustRecordingSignalVolume(int volume) {//[0, 400]: e.g. 50~0.5x 100~1x 400~4x
  1820. if (volume < 0)
  1821. volume = 0;
  1822. else if (volume > 400)
  1823. volume = 400;
  1824. return m_parameter ? m_parameter->setInt("che.audio.record.signal.volume", volume) : -ERR_NOT_INITIALIZED;
  1825. }
  1826. int adjustPlaybackSignalVolume(int volume) {//[0, 400]
  1827. if (volume < 0)
  1828. volume = 0;
  1829. else if (volume > 400)
  1830. volume = 400;
  1831. return m_parameter ? m_parameter->setInt("che.audio.playout.signal.volume", volume) : -ERR_NOT_INITIALIZED;
  1832. }
  1833. int setHighQualityAudioParameters(bool fullband, bool stereo, bool fullBitrate) {
  1834. return setObject("che.audio.codec.hq", "{\"fullband\":%s,\"stereo\":%s,\"fullBitrate\":%s}", fullband ? "true" : "false", stereo ? "true" : "false", fullBitrate ? "true" : "false");
  1835. }
  1836. int enableWebSdkInteroperability(bool enabled) {//enable interoperability with zero-plugin web sdk
  1837. return setParameters("{\"rtc.video.web_h264_interop_enable\":%s,\"che.video.web_h264_interop_enable\":%s}", enabled ? "true" : "false", enabled ? "true" : "false");
  1838. }
  1839. //only for live broadcasting
  1840. int setVideoQualityParameters(bool preferFrameRateOverImageQuality) {
  1841. return setParameters("{\"rtc.video.prefer_frame_rate\":%s,\"che.video.prefer_frame_rate\":%s}", preferFrameRateOverImageQuality ? "true" : "false", preferFrameRateOverImageQuality ? "true" : "false");
  1842. }
  1843. protected:
  1844. AParameter& parameter() {
  1845. return m_parameter;
  1846. }
  1847. int setParameters(const char* format, ...) {
  1848. char buf[512];
  1849. va_list args;
  1850. va_start(args, format);
  1851. vsnprintf(buf, sizeof(buf)-1, format, args);
  1852. va_end(args);
  1853. return m_parameter ? m_parameter->setParameters(buf) : -ERR_NOT_INITIALIZED;
  1854. }
  1855. int setObject(const char* key, const char* format, ...) {
  1856. char buf[512];
  1857. va_list args;
  1858. va_start(args, format);
  1859. vsnprintf(buf, sizeof(buf)-1, format, args);
  1860. va_end(args);
  1861. return m_parameter ? m_parameter->setObject(key, buf) : -ERR_NOT_INITIALIZED;
  1862. }
  1863. int enableLocalVideoCapture(bool enabled) {
  1864. return m_parameter ? m_parameter->setBool("che.video.local.capture", enabled) : -ERR_NOT_INITIALIZED;
  1865. }
  1866. int enableLocalVideoRender(bool enabled) {
  1867. return m_parameter ? m_parameter->setBool("che.video.local.render", enabled) : -ERR_NOT_INITIALIZED;
  1868. }
  1869. int enableLocalVideoSend(bool enabled) {
  1870. return muteLocalVideoStream(!enabled);
  1871. }
  1872. int stopAllRemoteVideo() {
  1873. return m_parameter ? m_parameter->setBool("che.video.peer.stop_render", true) : -ERR_NOT_INITIALIZED;
  1874. }
  1875. private:
  1876. AParameter m_parameter;
  1877. };
  1878. } //namespace rtc
  1879. } // namespace agora
  1880. /**
  1881. * to get the version number of the SDK
  1882. * @param [in, out] build
  1883. * the build number of Agora SDK
  1884. * @return returns the string of the version of the SDK
  1885. */
  1886. AGORA_API const char* AGORA_CALL getAgoraRtcEngineVersion(int* build);
  1887. /**
  1888. * create the RTC engine object and return the pointer
  1889. * @return returns the pointer of the RTC engine object
  1890. */
  1891. AGORA_API agora::rtc::IRtcEngine* AGORA_CALL createAgoraRtcEngine();
  1892. /**
  1893. * create the RTC engine object and return the pointer
  1894. * @param [in] err
  1895. * the error code
  1896. * @return returns the description of the error code
  1897. */
  1898. AGORA_API const char* AGORA_CALL getAgoraRtcEngineErrorDescription(int err);
  1899. AGORA_API int AGORA_CALL setAgoraRtcEngineExternalSymbolLoader(void* (*func)(const char* symname));
  1900. #endif