vid_port.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJMEDIA_VIDPORT_H__
  19. #define __PJMEDIA_VIDPORT_H__
  20. /**
  21. * @file pjmedia/vid_port.h Video media port
  22. * @brief Video media port
  23. */
  24. #include <pjmedia-videodev/videodev.h>
  25. #include <pjmedia/port.h>
  26. /**
  27. * @defgroup PJMEDIA_VIDEO_PORT Video media port
  28. * @ingroup PJMEDIA_PORT_CLOCK
  29. * @brief Video media port
  30. * @{
  31. */
  32. PJ_BEGIN_DECL
  33. /**
  34. * This structure describes the parameters to create a video port
  35. */
  36. typedef struct pjmedia_vid_port_param
  37. {
  38. /**
  39. * Video stream parameter.
  40. */
  41. pjmedia_vid_dev_param vidparam;
  42. /**
  43. * Specify whether the video port should use active or passive interface.
  44. * If active interface is selected, the video port will perform as
  45. * a media clock, automatically calls pjmedia_port_get_frame() and
  46. * pjmedia_port_put_frame() of its slave port (depending on the direction
  47. * that is specified when opening the video stream). If passive interface
  48. * is selected, application can retrieve the media port of this video
  49. * port by calling pjmedia_vid_port_get_passive_port(), and subsequently
  50. * calls pjmedia_port_put_frame() or pjmedia_port_get_frame() to that
  51. * media port.
  52. *
  53. * Default: PJ_TRUE
  54. */
  55. pj_bool_t active;
  56. } pjmedia_vid_port_param;
  57. /**
  58. * Opaque data type for video port.
  59. */
  60. typedef struct pjmedia_vid_port pjmedia_vid_port;
  61. /**
  62. * Initialize the parameter with the default values. Note that this typically
  63. * would only fill the structure to zeroes unless they have different default
  64. * values.
  65. *
  66. * @param prm The parameter.
  67. */
  68. PJ_DECL(void) pjmedia_vid_port_param_default(pjmedia_vid_port_param *prm);
  69. /**
  70. * Create a video port with the specified parameter. When video port opens
  71. * the video stream with different parameter than the requested values in
  72. * the \a prm.vidparam argument, it will automatically do the necessary
  73. * conversion.
  74. *
  75. * @param pool Pool to allocate memory from.
  76. * @param prm The video port parameter.
  77. * @param p_vp Pointer to receive the result.
  78. *
  79. * @return PJ_SUCCESS if video port has been created
  80. * successfully, or the appropriate error code.
  81. */
  82. PJ_DECL(pj_status_t) pjmedia_vid_port_create(pj_pool_t *pool,
  83. const pjmedia_vid_port_param *prm,
  84. pjmedia_vid_port **p_vp);
  85. /**
  86. * Set the callbacks of the video port's underlying video stream.
  87. *
  88. * @param vid_port The video port.
  89. * @param cb Pointer to structure containing video stream
  90. * callbacks.
  91. * @param user_data Arbitrary user data, which will be given back in the
  92. * callbacks.
  93. */
  94. PJ_DECL(void) pjmedia_vid_port_set_cb(pjmedia_vid_port *vid_port,
  95. const pjmedia_vid_dev_cb *cb,
  96. void *user_data);
  97. /**
  98. * Return the underlying video stream of the video port.
  99. *
  100. * @param vid_port The video port.
  101. *
  102. * @return The video stream.
  103. */
  104. PJ_DECL(pjmedia_vid_dev_stream*)
  105. pjmedia_vid_port_get_stream(pjmedia_vid_port *vid_port);
  106. /**
  107. * Return the (passive) media port of the video port. This operation
  108. * is only valid for video ports created with passive interface selected.
  109. * Retrieving the media port for active video ports may raise an
  110. * assertion.
  111. *
  112. * @param vid_port The video port.
  113. *
  114. * @return The media port instance, or NULL.
  115. */
  116. PJ_DECL(pjmedia_port*)
  117. pjmedia_vid_port_get_passive_port(pjmedia_vid_port *vid_port);
  118. /**
  119. * Get a clock source from the video port.
  120. *
  121. * @param vid_port The video port.
  122. *
  123. * @return The clock source.
  124. */
  125. PJ_DECL(pjmedia_clock_src *)
  126. pjmedia_vid_port_get_clock_src( pjmedia_vid_port *vid_port );
  127. /**
  128. * Set a clock source for the video port.
  129. *
  130. * @param vid_port The video port.
  131. * @param clocksrc The clock source.
  132. *
  133. * @return PJ_SUCCESS on success or the appropriate error code.
  134. */
  135. PJ_DECL(pj_status_t)
  136. pjmedia_vid_port_set_clock_src( pjmedia_vid_port *vid_port,
  137. pjmedia_clock_src *clocksrc );
  138. /**
  139. * Subscribe media event notifications from the specified media port.
  140. * Sample use case is that renderer video port needs to monitor stream port
  141. * events so renderer can adjust its param whenever stream port detects
  142. * format change.
  143. *
  144. * @param vid_port The video port.
  145. * @param port The media port whose events to be monitored.
  146. *
  147. * @return PJ_SUCCESS on success or the appropriate error code.
  148. */
  149. PJ_DECL(pj_status_t) pjmedia_vid_port_subscribe_event(
  150. pjmedia_vid_port *vid_port,
  151. pjmedia_port *port);
  152. /**
  153. * Unsubscribe media event notifications from the specified media port.
  154. *
  155. * @param vid_port The video port.
  156. * @param port The media port whose events to be unsubscribed.
  157. *
  158. * @return PJ_SUCCESS on success or the appropriate error code.
  159. */
  160. PJ_DECL(pj_status_t) pjmedia_vid_port_unsubscribe_event(
  161. pjmedia_vid_port *vid_port,
  162. pjmedia_port *port);
  163. /**
  164. * Connect the video port to a downstream (slave) media port. This operation
  165. * is only valid for video ports created with active interface selected.
  166. * Connecting a passive video port may raise an assertion.
  167. *
  168. * @param vid_port The video port.
  169. * @param port A downstream media port to be connected to
  170. * this video port.
  171. * @param destroy Specify if the downstream media port should also be
  172. * destroyed by this video port when the video port
  173. * is destroyed.
  174. *
  175. * @return PJ_SUCCESS on success or the appropriate error code.
  176. */
  177. PJ_DECL(pj_status_t) pjmedia_vid_port_connect(pjmedia_vid_port *vid_port,
  178. pjmedia_port *port,
  179. pj_bool_t destroy);
  180. /**
  181. * Disconnect the video port from its downstream (slave) media port, if any.
  182. * This operation is only valid for video ports created with active interface
  183. * selected, and assertion may be triggered if this is invoked on a passive
  184. * video port.
  185. *
  186. * @param vid_port The video port.
  187. *
  188. * @return PJ_SUCCESS on success or the appropriate error code.
  189. */
  190. PJ_DECL(pj_status_t) pjmedia_vid_port_disconnect(pjmedia_vid_port *vid_port);
  191. /**
  192. * Retrieve the media port currently connected as downstream media port of the
  193. * specified video port. This operation is only valid for video ports created
  194. * with active interface selected, and assertion may be triggered if this is
  195. * invoked on a passive video port.
  196. *
  197. * @param vid_port The video port.
  198. *
  199. * @return Media port currently connected to the video port,
  200. * if any.
  201. */
  202. PJ_DECL(pjmedia_port*)
  203. pjmedia_vid_port_get_connected_port(pjmedia_vid_port *vid_port);
  204. /**
  205. * Start the video port.
  206. *
  207. * @param vid_port The video port.
  208. *
  209. * @return PJ_SUCCESS on success or the appropriate error code.
  210. */
  211. PJ_DECL(pj_status_t) pjmedia_vid_port_start(pjmedia_vid_port *vid_port);
  212. /**
  213. * Query whether the video port has been started.
  214. *
  215. * @param vid_port The video port.
  216. *
  217. * @return PJ_TRUE if the video port has been started.
  218. */
  219. PJ_DECL(pj_bool_t) pjmedia_vid_port_is_running(pjmedia_vid_port *vid_port);
  220. /**
  221. * Stop the video port.
  222. *
  223. * @param vid_port The video port.
  224. *
  225. * @return PJ_SUCCESS on success or the appropriate error code.
  226. */
  227. PJ_DECL(pj_status_t) pjmedia_vid_port_stop(pjmedia_vid_port *vid_port);
  228. /**
  229. * Destroy the video port, along with its video stream. If the video port is
  230. * an active one, this may also destroy the downstream media port, if the
  231. * destroy flag is set when the media port is connected.
  232. *
  233. * @param vid_port The video port.
  234. */
  235. PJ_DECL(void) pjmedia_vid_port_destroy(pjmedia_vid_port *vid_port);
  236. PJ_END_DECL
  237. /**
  238. * @}
  239. */
  240. #endif /* __PJMEDIA_VIDPORT_H__ */