export.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #ifndef RECORDER_EXPORT
  2. #define RECORDER_EXPORT
  3. #include <stdint.h>
  4. // #ifdef AMRECORDER_IMPORT
  5. // #define AMRECORDER_API extern "C" __declspec(dllimport)
  6. // #else
  7. // #define AMRECORDER_API extern "C" __declspec(dllexport)
  8. // #endif
  9. #define AMRECORDER_API
  10. /**
  11. * AMRECORDER_DEVICE
  12. */
  13. #pragma pack(push,1)
  14. typedef struct {
  15. /**
  16. * Device id in utf8
  17. */
  18. char id[260];
  19. /**
  20. * Device name in utf8
  21. */
  22. char name[260];
  23. /**
  24. * Is default device
  25. */
  26. uint8_t is_default;
  27. }AMRECORDER_DEVICE;
  28. #pragma pack(pop)
  29. /**
  30. * AMRECORDER_SETTING
  31. */
  32. #pragma pack(push,1)
  33. typedef struct {
  34. /**
  35. * Left of desktop area
  36. */
  37. int v_left;
  38. /**
  39. * Top of desktop area
  40. */
  41. int v_top;
  42. /**
  43. * Width of desktop area
  44. */
  45. int v_width;
  46. /**
  47. * Height of desktop area
  48. */
  49. int v_height;
  50. /**
  51. * Output video quality, value must be between 0 and 100, 0 is least, 100 is best
  52. */
  53. int v_qb;
  54. /**
  55. * Output video bitrate, the larger value you set,
  56. * the better video quality you get, but the file size is also larger.
  57. * Suggestion: 960|1280|2500 *1000
  58. */
  59. int v_bit_rate;
  60. /**
  61. * FPS(frame per second)
  62. */
  63. int v_frame_rate;
  64. /**
  65. * Video encoder id
  66. * Must get by recorder_get_vencoders
  67. */
  68. int v_enc_id;
  69. /**
  70. * Output file path,the output file format is depended on the ext name.
  71. * Support .mp4|.mkv for now.
  72. */
  73. char output[260];
  74. /**
  75. * Desktop device
  76. * Unused
  77. */
  78. AMRECORDER_DEVICE v_device;
  79. /**
  80. * Microphone device info
  81. */
  82. AMRECORDER_DEVICE a_mic;
  83. /**
  84. * Speaker device info
  85. */
  86. AMRECORDER_DEVICE a_speaker;
  87. }AMRECORDER_SETTING;
  88. #pragma pack(pop)
  89. /**
  90. * AMRECORDER_ENCODERS
  91. */
  92. #pragma pack(push,1)
  93. typedef struct {
  94. /**
  95. * Encoder id
  96. */
  97. int id;
  98. /**
  99. * Encoder name
  100. */
  101. char name[260];
  102. }AMRECORDER_ENCODERS;
  103. #pragma pack(pop)
  104. /**
  105. * Recording duration callback function
  106. * @param[in] duration time in millisecond
  107. */
  108. typedef void(*AMRECORDER_FUNC_DURATION)(uint64_t duration);
  109. /**
  110. * Recording error callback function
  111. * Should call recorder_err2str to get stringify error info
  112. * @param[in] error
  113. */
  114. typedef void(*AMRECORDER_FUNC_ERROR)(int error);
  115. /**
  116. * Device changed callback function
  117. * Should refresh devices
  118. * @param[in] type 0 for video, 1 for speaker, 2 for microphone
  119. */
  120. typedef void(*AMRECORDER_FUNC_DEVICE_CHANGE)(int type);
  121. /**
  122. * YUV data callback function
  123. * Should refresh devices
  124. * @param[in] data yuv buffer
  125. * @param[in] size yuv buffer size
  126. * @param[in] width picture with
  127. * @param[in] height picture height
  128. * @param[in] type yuv type, 0 for 420, 1 fro 444
  129. */
  130. typedef void(*AMRECORDER_FUNC_PREVIEW_YUV)(
  131. const unsigned char *data,
  132. unsigned int size,
  133. int width,
  134. int height,
  135. int type
  136. );
  137. /**
  138. * Unused callback function
  139. */
  140. typedef void(*AMRECORDER_FUNC_PREVIEW_AUDIO)();
  141. /**
  142. * Remux progress callback function
  143. * @param[in] path source file path
  144. * @param[in] progress remuxing progress in total
  145. * @param[in] total always will be 100
  146. */
  147. typedef void(*AMRECORDER_FUNC_REMUX_PROGRESS)(const char *path, int progress, int total);
  148. /**
  149. * Remux state callback function
  150. * @param[in] path source file path
  151. * @param[in] state 0 for unremuxing,1 for remuxing
  152. * @param[in] error 0 for succed,otherwhise error code
  153. */
  154. typedef void(*AMRECORDER_FUNC_REMUX_STATE)(const char *path, int state, int error);
  155. /**
  156. * Callback functions structure
  157. */
  158. #pragma pack(push,1)
  159. typedef struct {
  160. AMRECORDER_FUNC_DURATION func_duration;
  161. AMRECORDER_FUNC_ERROR func_error;
  162. AMRECORDER_FUNC_DEVICE_CHANGE func_device_change;
  163. AMRECORDER_FUNC_PREVIEW_YUV func_preview_yuv;
  164. AMRECORDER_FUNC_PREVIEW_AUDIO func_preview_audio;
  165. }AMRECORDER_CALLBACK;
  166. #pragma pack(pop)
  167. /**
  168. * Get error string by specified error code
  169. * @return error string
  170. */
  171. AMRECORDER_API const char * recorder_err2str(int error);
  172. /**
  173. * Initialize recorder with specified seetings��speaker��mic��encoder...
  174. * @return 0 if succeed,error code otherwise
  175. */
  176. AMRECORDER_API int recorder_init(const AMRECORDER_SETTING &setting, const AMRECORDER_CALLBACK &callbacks);
  177. /**
  178. * Release all recorder resources
  179. */
  180. AMRECORDER_API void recorder_release();
  181. /**
  182. * Start recording
  183. * @return 0 if succeed,error code otherwise
  184. */
  185. AMRECORDER_API int recorder_start();
  186. /**
  187. * Stop recording
  188. */
  189. AMRECORDER_API void recorder_stop();
  190. /**
  191. * Pause recording
  192. * @return 0 if succeed,error code otherwise
  193. */
  194. AMRECORDER_API int recorder_pause();
  195. /**
  196. * Resume recording
  197. * @return 0 if succeed,error code otherwise
  198. */
  199. AMRECORDER_API int recorder_resume();
  200. /**
  201. * Get valid speaker devices
  202. * @param[in] devices a pointer to a device array,should call recorder_free_array to free memory
  203. * @return count of speakers
  204. */
  205. AMRECORDER_API int recorder_get_speakers(AMRECORDER_DEVICE **devices);
  206. /**
  207. * Get valid mic devices
  208. * @param[in] devices a pointer to a device array,should call recorder_free_array to free memory
  209. * @return count of mics
  210. */
  211. AMRECORDER_API int recorder_get_mics(AMRECORDER_DEVICE **devices);
  212. /**
  213. * Get valid camera devices
  214. * @param[in] devices a pointer to a device array,should call recorder_free_array to free memory
  215. * @return count of cameras
  216. */
  217. AMRECORDER_API int recorder_get_cameras(AMRECORDER_DEVICE **devices);
  218. /**
  219. * Get valid encoders
  220. */
  221. AMRECORDER_API int recorder_get_vencoders(AMRECORDER_ENCODERS **encoders);
  222. /**
  223. * Free array memory allocated by recorder APIs
  224. */
  225. AMRECORDER_API void recorder_free_array(void *array_address);
  226. /**
  227. * Remux a file
  228. */
  229. AMRECORDER_API int recorder_remux(
  230. const char *src, const char *dst,
  231. AMRECORDER_FUNC_REMUX_PROGRESS func_progress,
  232. AMRECORDER_FUNC_REMUX_STATE func_state);
  233. /**
  234. * Enable/Disable preview callback
  235. */
  236. AMRECORDER_API void recorder_set_preview_enabled(int enable);
  237. /**
  238. * Set log file path
  239. */
  240. AMRECORDER_API void recorder_set_logpath(const char* path);
  241. /**
  242. * Ring buffer diagnostics (video)
  243. */
  244. AMRECORDER_API uint64_t recorder_get_video_rb_dropped();
  245. AMRECORDER_API int recorder_get_video_rb_pending();
  246. AMRECORDER_API int recorder_get_video_rb_max();
  247. AMRECORDER_API void recorder_set_video_rb_max(int max_frames);
  248. AMRECORDER_API void recorder_reset_video_rb_dropped();
  249. /**
  250. * Ring buffer diagnostics (audio)
  251. */
  252. AMRECORDER_API uint64_t recorder_get_audio_rb_dropped();
  253. AMRECORDER_API int recorder_get_audio_rb_pending();
  254. AMRECORDER_API int recorder_get_audio_rb_max();
  255. AMRECORDER_API void recorder_set_audio_rb_max(int max_frames);
  256. AMRECORDER_API void recorder_reset_audio_rb_dropped();
  257. #endif