tmedia_common.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file tmedia_common.h
  23. * @brief Common functions and definitions.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYMEDIA_COMMON_H
  29. #define TINYMEDIA_COMMON_H
  30. #include "tinymedia_config.h"
  31. #include "tsk_plugin.h"
  32. #include "tsk_object.h"
  33. TMEDIA_BEGIN_DECLS
  34. struct tsdp_message_s;
  35. struct tsdp_header_M_s;
  36. /** List of all supported media types */
  37. // @tinyWRAP
  38. typedef enum tmedia_type_e {
  39. tmedia_none = 0x00,
  40. tmedia_ghost = (0x01 << 0),
  41. tmedia_audio = (0x01 << 1),
  42. tmedia_video = (0x01 << 2),
  43. tmedia_chat = (0x01 << 3),
  44. tmedia_file = (0x01 << 4),
  45. tmedia_t38 = (0x01 << 5),
  46. tmedia_t140 = (0x01 << 6),
  47. tmedia_bfcp = (0x01 << 7),
  48. tmedia_bfcp_audio = (0x01 << 8)/*must*/ | tmedia_bfcp, /* do not add "| audio". Otherwise it will be impossible to start an "video+bfcp-audio" session. */
  49. tmedia_bfcp_video = (0x01 << 9)/*must*/ | tmedia_bfcp, /* do not add "| video". Otherwise it will be impossible to start an "audio+bfcp-video" session. */
  50. tmedia_msrp = (tmedia_chat | tmedia_file),
  51. tmedia_audiovideo = (tmedia_audio | tmedia_video),
  52. tmedia_all = 0xff
  53. }
  54. tmedia_type_t;
  55. // @tinyWRAP
  56. typedef enum tmedia_mode_e {
  57. tmedia_mode_none,
  58. tmedia_mode_optional,
  59. tmedia_mode_mandatory
  60. }
  61. tmedia_mode_t;
  62. // @tinyWRAP
  63. typedef enum tmedia_srtp_mode_e {
  64. tmedia_srtp_mode_none,
  65. tmedia_srtp_mode_optional,
  66. tmedia_srtp_mode_mandatory
  67. }
  68. tmedia_srtp_mode_t;
  69. // @tinyWRAP
  70. typedef enum tmedia_srtp_type_e {
  71. tmedia_srtp_type_none = 0x00,
  72. tmedia_srtp_type_sdes = 0x01,
  73. tmedia_srtp_type_dtls = 0x02,
  74. tmedia_srtp_type_sdes_dtls = (tmedia_srtp_type_sdes | tmedia_srtp_type_dtls)
  75. }
  76. tmedia_srtp_type_t;
  77. // @tinyWRAP
  78. typedef enum tmedia_t140_data_type_e {
  79. tmedia_t140_data_type_utf8,
  80. tmedia_t140_data_type_zero_width_no_break_space = 0xefbbbf,
  81. tmedia_t140_data_type_backspace = 0x08,
  82. tmedia_t140_data_type_esc = 0x1b,
  83. tmedia_t140_data_type_cr = 0x0d,
  84. tmedia_t140_data_type_lf = 0x0a,
  85. tmedia_t140_data_type_cr_lf = 0x0d0a,
  86. tmedia_t140_data_type_bell = 0x07,
  87. tmedia_t140_data_type_sos = 0x98,
  88. tmedia_t140_data_type_string_term = 0x9c,
  89. tmedia_t140_data_type_graphic_start = 0x9b,
  90. tmedia_t140_data_type_graphic_end = 0x6d,
  91. tmedia_t140_data_type_loss_char_char = 0xfffd,
  92. tmedia_t140_data_type_loss_utf8 = 0xefbfbd,
  93. }
  94. tmedia_t140_data_type_t;
  95. // @tinyWRAP
  96. typedef enum tmedia_rtcp_event_type_e {
  97. tmedia_rtcp_event_type_fir, // Full Intra Refresh
  98. }
  99. tmedia_rtcp_event_type_t;
  100. // @tinyWRAP
  101. typedef enum tmedia_profile_e {
  102. tmedia_profile_default,
  103. // Enable all RTCWeb specifications:
  104. // ICE, DTLS-SRTP, RTP/AVPF, FEC, RED, SDPCapNeg, RTCP-MUX, imageattr...
  105. tmedia_profile_rtcweb
  106. }
  107. tmedia_profile_t;
  108. // @tinyWRAP
  109. typedef enum tmedia_pref_video_size_s {
  110. /* must be sorted like this */
  111. tmedia_pref_video_size_sqcif, // 128 x 98
  112. tmedia_pref_video_size_qcif, // 176 x 144
  113. tmedia_pref_video_size_qvga, // 320 x 240
  114. tmedia_pref_video_size_cif, // 352 x 288
  115. tmedia_pref_video_size_hvga, // 480 x 320
  116. tmedia_pref_video_size_vga, // 640 x 480
  117. tmedia_pref_video_size_4cif, // 704 x 576
  118. tmedia_pref_video_size_wvga, // 800 x 480
  119. tmedia_pref_video_size_svga, // 800 x 600
  120. tmedia_pref_video_size_480p, // 852 x 480
  121. tmedia_pref_video_size_xga, // 1024 x 768
  122. tmedia_pref_video_size_720p, // 1280 x 720
  123. tmedia_pref_video_size_16cif, // 1408 x 1152
  124. tmedia_pref_video_size_1080p, // 1920 x 1080
  125. tmedia_pref_video_size_2160p, // 3840 x 2160
  126. }
  127. tmedia_pref_video_size_t;
  128. typedef enum tmedia_rtcweb_type_e {
  129. tmedia_rtcweb_type_none,
  130. tmedia_rtcweb_type_firefox,
  131. tmedia_rtcweb_type_chrome,
  132. tmedia_rtcweb_type_ie,
  133. tmedia_rtcweb_type_safari,
  134. tmedia_rtcweb_type_opera,
  135. tmedia_rtcweb_type_ericsson,
  136. tmedia_rtcweb_type_doubango
  137. }
  138. tmedia_rtcweb_type_t;
  139. typedef enum tmedia_video_encode_result_type_e {
  140. tmedia_video_encode_result_type_none = 0x00,
  141. tmedia_video_encode_result_type_params = (0x01 << 0), // e.g. SPS or PPS, DCT coeff., Quant params....
  142. tmedia_video_encode_result_type_intra = (0x01 << 1),
  143. tmedia_video_encode_result_type_key = tmedia_video_encode_result_type_intra,
  144. tmedia_video_encode_result_type_gold = tmedia_video_encode_result_type_intra,
  145. tmedia_video_encode_result_type_predicted = (0x01 << 2),
  146. tmedia_video_encode_result_type_bipredicted = (0x01 << 3)
  147. }
  148. tmedia_video_encode_result_type_t;
  149. typedef struct tmedia_video_encode_result_xs {
  150. tmedia_video_encode_result_type_t type;
  151. const void* usr_data;
  152. struct {
  153. const void* ptr;
  154. tsk_size_t size;
  155. } buffer;
  156. uint32_t duration;
  157. tsk_bool_t last_chunck;
  158. const tsk_object_t* proto_hdr;
  159. }
  160. tmedia_video_encode_result_xt;
  161. #define tmedia_video_encode_result_reset(result) \
  162. (result)->type = tmedia_video_encode_result_type_none; \
  163. (result)->usr_data = tsk_null; \
  164. (result)->proto_hdr = tsk_null; \
  165. (result)->buffer.ptr = tsk_null; \
  166. (result)->buffer.size = 0; \
  167. (result)->duration = 0; \
  168. (result)->last_chunck = tsk_false; \
  169. (result)->proto_hdr = tsk_null; \
  170. typedef enum tmedia_video_decode_result_type_e {
  171. tmedia_video_decode_result_type_none,
  172. tmedia_video_decode_result_type_error,
  173. tmedia_video_decode_result_type_idr,
  174. }
  175. tmedia_video_decode_result_type_t;
  176. typedef struct tmedia_video_decode_result_xs {
  177. tmedia_video_decode_result_type_t type;
  178. const void* usr_data;
  179. const tsk_object_t* proto_hdr; // RTP, RTSP....
  180. }
  181. tmedia_video_decode_result_xt;
  182. #define tmedia_video_decode_result_reset(result) \
  183. (result)->type = tmedia_video_decode_result_type_none; \
  184. (result)->usr_data = tsk_null; \
  185. (result)->proto_hdr = tsk_null; \
  186. // @tinyWRAP
  187. typedef enum tmedia_chroma_e {
  188. tmedia_chroma_none=0,
  189. tmedia_chroma_rgb24, // will be stored as bgr24 on x86 (little endians) machines; e.g. WindowsPhone7
  190. tmedia_chroma_bgr24, // used by windows consumer (DirectShow) -
  191. tmedia_chroma_rgb32, // used by iOS4 consumer (iPhone and iPod touch)
  192. tmedia_chroma_rgb565le, // (used by both android and wince consumers)
  193. tmedia_chroma_rgb565be,
  194. tmedia_chroma_nv12, // used by iOS4 producer (iPhone and iPod Touch 3GS and 4)
  195. tmedia_chroma_nv21, // Yuv420 SP (used by android producer)
  196. tmedia_chroma_yuv422p,
  197. tmedia_chroma_uyvy422, // used by iOS4 producer (iPhone and iPod Touch 3G) - Microsoft: MFVideoFormat_YUY2
  198. tmedia_chroma_yuv420p, // Default
  199. tmedia_chroma_mjpeg, // VirtualBox default camera mode (Windows as host and Linux as guest)
  200. tmedia_chroma_yuyv422, // YUYV422 (V4L2 preferred format)
  201. }
  202. tmedia_chroma_t;
  203. // @tinyWRAP
  204. // @deprecated
  205. // keep order (low->unrestricted)
  206. typedef enum tmedia_bandwidth_level_e {
  207. tmedia_bl_low,
  208. tmedia_bl_medium,
  209. tmedia_bl_hight,
  210. tmedia_bl_unrestricted
  211. }
  212. tmedia_bandwidth_level_t;
  213. typedef enum tmedia_ro_type_e {
  214. tmedia_ro_type_none = 0x00,
  215. tmedia_ro_type_offer = (0x01 << 0),
  216. tmedia_ro_type_answer = (0x01 << 1),
  217. tmedia_ro_type_provisional = tmedia_ro_type_answer | (0x01 << 2),
  218. }
  219. tmedia_ro_type_t;
  220. TINYMEDIA_API tsk_size_t tmedia_plugin_register(struct tsk_plugin_s* plugin, enum tsk_plugin_def_type_e type, enum tsk_plugin_def_media_type_e media);
  221. TINYMEDIA_API tsk_size_t tmedia_plugin_unregister(struct tsk_plugin_s* plugin, enum tsk_plugin_def_type_e type, enum tsk_plugin_def_media_type_e media);
  222. TINYMEDIA_API tmedia_type_t tmedia_type_from_sdp(const struct tsdp_message_s* sdp);
  223. TINYMEDIA_API tmedia_type_t tmedia_type_from_sdp_headerM(const struct tsdp_header_M_s* M);
  224. TINYMEDIA_API int tmedia_parse_rtpmap(const char* rtpmap, char** name, int32_t* rate, int32_t* channels);
  225. TINYMEDIA_API int tmedia_video_get_size(tmedia_pref_video_size_t pref_vs, unsigned *width, unsigned *height);
  226. TINYMEDIA_API int tmedia_video_get_closest_cif_size(tmedia_pref_video_size_t pref_vs, tmedia_pref_video_size_t *cif_vs);
  227. TINYMEDIA_API int tmedia_video_get_closest_pref_size(unsigned width, unsigned height, tmedia_pref_video_size_t *pref_vs);
  228. TINYMEDIA_API int tmedia_parse_video_fmtp(const char* fmtp, tmedia_pref_video_size_t pref_vs, unsigned* width, unsigned* height, unsigned* fps);
  229. TINYMEDIA_API int tmedia_parse_video_imageattr(const char* imageattr, tmedia_pref_video_size_t pref_vs, unsigned* in_width, unsigned* in_height, unsigned* out_width, unsigned* out_height);
  230. TINYMEDIA_API char* tmedia_get_video_fmtp(tmedia_pref_video_size_t pref_vs);
  231. TINYMEDIA_API char* tmedia_get_video_imageattr(tmedia_pref_video_size_t pref_vs, unsigned in_width, unsigned in_height, unsigned out_width, unsigned out_height);
  232. TINYMEDIA_API int tmedia_get_video_quality(tmedia_bandwidth_level_t bl);
  233. TINYMEDIA_API int32_t tmedia_get_video_bandwidth_kbps(unsigned width, unsigned height, unsigned fps, unsigned motion_rank);
  234. TINYMEDIA_API int32_t tmedia_get_video_bandwidth_kbps_2(unsigned width, unsigned height, unsigned fps);
  235. TINYMEDIA_API int32_t tmedia_get_video_bandwidth_kbps_3();
  236. TINYMEDIA_API int32_t tmedia_get_video_motion_rank(unsigned width, unsigned height, unsigned fps, int32_t bw_kbps);
  237. #define tmedia_get_video_qscale tmedia_get_video_quality
  238. TMEDIA_END_DECLS
  239. #endif /* TINYMEDIA_COMMON_H */