gstelement.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /* GStreamer
  2. * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  3. * 2000,2004 Wim Taymans <wim@fluendo.com>
  4. *
  5. * gstelement.h: Header for GstElement
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef __GST_ELEMENT_H__
  23. #define __GST_ELEMENT_H__
  24. /* gstelement.h and gstelementfactory.h include eachother */
  25. typedef struct _GstElement GstElement;
  26. typedef struct _GstElementClass GstElementClass;
  27. /* gstmessage.h needs State */
  28. /**
  29. * GstState:
  30. * @GST_STATE_VOID_PENDING: no pending state.
  31. * @GST_STATE_NULL : the NULL state or initial state of an element.
  32. * @GST_STATE_READY : the element is ready to go to PAUSED.
  33. * @GST_STATE_PAUSED : the element is PAUSED, it is ready to accept and
  34. * process data. Sink elements however only accept one
  35. * buffer and then block.
  36. * @GST_STATE_PLAYING : the element is PLAYING, the #GstClock is running and
  37. * the data is flowing.
  38. *
  39. * The possible states an element can be in. States can be changed using
  40. * gst_element_set_state() and checked using gst_element_get_state().
  41. */
  42. typedef enum {
  43. GST_STATE_VOID_PENDING = 0,
  44. GST_STATE_NULL = 1,
  45. GST_STATE_READY = 2,
  46. GST_STATE_PAUSED = 3,
  47. GST_STATE_PLAYING = 4
  48. } GstState;
  49. #include <gst/gstconfig.h>
  50. #include <gst/gstobject.h>
  51. #include <gst/gstpad.h>
  52. #include <gst/gstbus.h>
  53. #include <gst/gstclock.h>
  54. #include <gst/gstelementfactory.h>
  55. #include <gst/gstplugin.h>
  56. #include <gst/gstpluginfeature.h>
  57. #include <gst/gstiterator.h>
  58. #include <gst/gstmessage.h>
  59. #include <gst/gstquery.h>
  60. #include <gst/gsttaglist.h>
  61. G_BEGIN_DECLS
  62. #define GST_TYPE_ELEMENT (gst_element_get_type ())
  63. #define GST_IS_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ELEMENT))
  64. #define GST_IS_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ELEMENT))
  65. #define GST_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ELEMENT, GstElementClass))
  66. #define GST_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ELEMENT, GstElement))
  67. #define GST_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ELEMENT, GstElementClass))
  68. #define GST_ELEMENT_CAST(obj) ((GstElement*)(obj))
  69. /**
  70. * GstStateChangeReturn:
  71. * @GST_STATE_CHANGE_FAILURE : the state change failed
  72. * @GST_STATE_CHANGE_SUCCESS : the state change succeeded
  73. * @GST_STATE_CHANGE_ASYNC : the state change will happen asynchronously
  74. * @GST_STATE_CHANGE_NO_PREROLL: the state change succeeded but the element
  75. * cannot produce data in %GST_STATE_PAUSED.
  76. * This typically happens with live sources.
  77. *
  78. * The possible return values from a state change function such as
  79. * gst_element_set_state(). Only @GST_STATE_CHANGE_FAILURE is a real failure.
  80. */
  81. typedef enum {
  82. GST_STATE_CHANGE_FAILURE = 0,
  83. GST_STATE_CHANGE_SUCCESS = 1,
  84. GST_STATE_CHANGE_ASYNC = 2,
  85. GST_STATE_CHANGE_NO_PREROLL = 3
  86. } GstStateChangeReturn;
  87. /* NOTE: this probably should be done with an #ifdef to decide
  88. * whether to safe-cast or to just do the non-checking cast.
  89. */
  90. /**
  91. * GST_STATE:
  92. * @elem: a #GstElement to return state for.
  93. *
  94. * This macro returns the current #GstState of the element.
  95. */
  96. #define GST_STATE(elem) (GST_ELEMENT_CAST(elem)->current_state)
  97. /**
  98. * GST_STATE_NEXT:
  99. * @elem: a #GstElement to return the next state for.
  100. *
  101. * This macro returns the next #GstState of the element.
  102. */
  103. #define GST_STATE_NEXT(elem) (GST_ELEMENT_CAST(elem)->next_state)
  104. /**
  105. * GST_STATE_PENDING:
  106. * @elem: a #GstElement to return the pending state for.
  107. *
  108. * This macro returns the currently pending #GstState of the element.
  109. */
  110. #define GST_STATE_PENDING(elem) (GST_ELEMENT_CAST(elem)->pending_state)
  111. /**
  112. * GST_STATE_TARGET:
  113. * @elem: a #GstElement to return the target state for.
  114. *
  115. * This macro returns the target #GstState of the element.
  116. */
  117. #define GST_STATE_TARGET(elem) (GST_ELEMENT_CAST(elem)->target_state)
  118. /**
  119. * GST_STATE_RETURN:
  120. * @elem: a #GstElement to return the last state result for.
  121. *
  122. * This macro returns the last #GstStateChangeReturn value.
  123. */
  124. #define GST_STATE_RETURN(elem) (GST_ELEMENT_CAST(elem)->last_return)
  125. #define __GST_SIGN(val) ((val) < 0 ? -1 : ((val) > 0 ? 1 : 0))
  126. /**
  127. * GST_STATE_GET_NEXT:
  128. * @cur: A starting #GstState
  129. * @pending: A target #GstState
  130. *
  131. * Given a current state @cur and a target state @pending, calculate the next (intermediate)
  132. * #GstState.
  133. */
  134. #define GST_STATE_GET_NEXT(cur,pending) ((GstState)((cur) + __GST_SIGN ((gint)(pending) - (gint)(cur))))
  135. /**
  136. * GST_STATE_TRANSITION:
  137. * @cur: A current state
  138. * @next: A next state
  139. *
  140. * Given a current state @cur and a next state @next, calculate the associated
  141. * #GstStateChange transition.
  142. */
  143. #define GST_STATE_TRANSITION(cur,next) ((GstStateChange)(((cur)<<3)|(next)))
  144. /**
  145. * GST_STATE_TRANSITION_CURRENT:
  146. * @trans: A #GstStateChange
  147. *
  148. * Given a state transition @trans, extract the current #GstState.
  149. */
  150. #define GST_STATE_TRANSITION_CURRENT(trans) ((GstState)((trans)>>3))
  151. /**
  152. * GST_STATE_TRANSITION_NEXT:
  153. * @trans: A #GstStateChange
  154. *
  155. * Given a state transition @trans, extract the next #GstState.
  156. */
  157. #define GST_STATE_TRANSITION_NEXT(trans) ((GstState)((trans)&0x7))
  158. /**
  159. * GstStateChange:
  160. * @GST_STATE_CHANGE_NULL_TO_READY : state change from NULL to READY.
  161. * <itemizedlist>
  162. * <listitem><para>
  163. * The element must check if the resources it needs are available. Device
  164. * sinks and -sources typically try to probe the device to constrain their
  165. * caps.
  166. * </para></listitem>
  167. * <listitem><para>
  168. * The element opens the device (in case feature need to be probed).
  169. * </para></listitem>
  170. * </itemizedlist>
  171. * @GST_STATE_CHANGE_READY_TO_PAUSED : state change from READY to PAUSED.
  172. * <itemizedlist>
  173. * <listitem><para>
  174. * The element pads are activated in order to receive data in PAUSED.
  175. * Streaming threads are started.
  176. * </para></listitem>
  177. * <listitem><para>
  178. * Some elements might need to return %GST_STATE_CHANGE_ASYNC and complete
  179. * the state change when they have enough information. It is a requirement
  180. * for sinks to return %GST_STATE_CHANGE_ASYNC and complete the state change
  181. * when they receive the first buffer or %GST_EVENT_EOS (preroll).
  182. * Sinks also block the dataflow when in PAUSED.
  183. * </para></listitem>
  184. * <listitem><para>
  185. * A pipeline resets the running_time to 0.
  186. * </para></listitem>
  187. * <listitem><para>
  188. * Live sources return %GST_STATE_CHANGE_NO_PREROLL and don't generate data.
  189. * </para></listitem>
  190. * </itemizedlist>
  191. * @GST_STATE_CHANGE_PAUSED_TO_PLAYING: state change from PAUSED to PLAYING.
  192. * <itemizedlist>
  193. * <listitem><para>
  194. * Most elements ignore this state change.
  195. * </para></listitem>
  196. * <listitem><para>
  197. * The pipeline selects a #GstClock and distributes this to all the children
  198. * before setting them to PLAYING. This means that it is only allowed to
  199. * synchronize on the #GstClock in the PLAYING state.
  200. * </para></listitem>
  201. * <listitem><para>
  202. * The pipeline uses the #GstClock and the running_time to calculate the
  203. * base_time. The base_time is distributed to all children when performing
  204. * the state change.
  205. * </para></listitem>
  206. * <listitem><para>
  207. * Sink elements stop blocking on the preroll buffer or event and start
  208. * rendering the data.
  209. * </para></listitem>
  210. * <listitem><para>
  211. * Sinks can post %GST_MESSAGE_EOS in the PLAYING state. It is not allowed
  212. * to post %GST_MESSAGE_EOS when not in the PLAYING state.
  213. * </para></listitem>
  214. * <listitem><para>
  215. * While streaming in PAUSED or PLAYING elements can create and remove
  216. * sometimes pads.
  217. * </para></listitem>
  218. * <listitem><para>
  219. * Live sources start generating data and return %GST_STATE_CHANGE_SUCCESS.
  220. * </para></listitem>
  221. * </itemizedlist>
  222. * @GST_STATE_CHANGE_PLAYING_TO_PAUSED: state change from PLAYING to PAUSED.
  223. * <itemizedlist>
  224. * <listitem><para>
  225. * Most elements ignore this state change.
  226. * </para></listitem>
  227. * <listitem><para>
  228. * The pipeline calculates the running_time based on the last selected
  229. * #GstClock and the base_time. It stores this information to continue
  230. * playback when going back to the PLAYING state.
  231. * </para></listitem>
  232. * <listitem><para>
  233. * Sinks unblock any #GstClock wait calls.
  234. * </para></listitem>
  235. * <listitem><para>
  236. * When a sink does not have a pending buffer to play, it returns
  237. * %GST_STATE_CHANGE_ASYNC from this state change and completes the state
  238. * change when it receives a new buffer or an %GST_EVENT_EOS.
  239. * </para></listitem>
  240. * <listitem><para>
  241. * Any queued %GST_MESSAGE_EOS items are removed since they will be reposted
  242. * when going back to the PLAYING state. The EOS messages are queued in
  243. * #GstBin containers.
  244. * </para></listitem>
  245. * <listitem><para>
  246. * Live sources stop generating data and return %GST_STATE_CHANGE_NO_PREROLL.
  247. * </para></listitem>
  248. * </itemizedlist>
  249. * @GST_STATE_CHANGE_PAUSED_TO_READY : state change from PAUSED to READY.
  250. * <itemizedlist>
  251. * <listitem><para>
  252. * Sinks unblock any waits in the preroll.
  253. * </para></listitem>
  254. * <listitem><para>
  255. * Elements unblock any waits on devices
  256. * </para></listitem>
  257. * <listitem><para>
  258. * Chain or get_range functions return %GST_FLOW_FLUSHING.
  259. * </para></listitem>
  260. * <listitem><para>
  261. * The element pads are deactivated so that streaming becomes impossible and
  262. * all streaming threads are stopped.
  263. * </para></listitem>
  264. * <listitem><para>
  265. * The sink forgets all negotiated formats
  266. * </para></listitem>
  267. * <listitem><para>
  268. * Elements remove all sometimes pads
  269. * </para></listitem>
  270. * </itemizedlist>
  271. * @GST_STATE_CHANGE_READY_TO_NULL : state change from READY to NULL.
  272. * <itemizedlist>
  273. * <listitem><para>
  274. * Elements close devices
  275. * </para></listitem>
  276. * <listitem><para>
  277. * Elements reset any internal state.
  278. * </para></listitem>
  279. * </itemizedlist>
  280. *
  281. * These are the different state changes an element goes through.
  282. * %GST_STATE_NULL &rArr; %GST_STATE_PLAYING is called an upwards state change
  283. * and %GST_STATE_PLAYING &rArr; %GST_STATE_NULL a downwards state change.
  284. */
  285. typedef enum /*< flags=0 >*/
  286. {
  287. GST_STATE_CHANGE_NULL_TO_READY = (GST_STATE_NULL<<3) | GST_STATE_READY,
  288. GST_STATE_CHANGE_READY_TO_PAUSED = (GST_STATE_READY<<3) | GST_STATE_PAUSED,
  289. GST_STATE_CHANGE_PAUSED_TO_PLAYING = (GST_STATE_PAUSED<<3) | GST_STATE_PLAYING,
  290. GST_STATE_CHANGE_PLAYING_TO_PAUSED = (GST_STATE_PLAYING<<3) | GST_STATE_PAUSED,
  291. GST_STATE_CHANGE_PAUSED_TO_READY = (GST_STATE_PAUSED<<3) | GST_STATE_READY,
  292. GST_STATE_CHANGE_READY_TO_NULL = (GST_STATE_READY<<3) | GST_STATE_NULL
  293. } GstStateChange;
  294. /**
  295. * GstElementFlags:
  296. * @GST_ELEMENT_FLAG_LOCKED_STATE: ignore state changes from parent
  297. * @GST_ELEMENT_FLAG_SINK: the element is a sink
  298. * @GST_ELEMENT_FLAG_SOURCE: the element is a source.
  299. * @GST_ELEMENT_FLAG_PROVIDE_CLOCK: the element can provide a clock
  300. * @GST_ELEMENT_FLAG_REQUIRE_CLOCK: the element requires a clock
  301. * @GST_ELEMENT_FLAG_INDEXABLE: the element can use an index
  302. * @GST_ELEMENT_FLAG_LAST: offset to define more flags
  303. *
  304. * The standard flags that an element may have.
  305. */
  306. typedef enum
  307. {
  308. GST_ELEMENT_FLAG_LOCKED_STATE = (GST_OBJECT_FLAG_LAST << 0),
  309. GST_ELEMENT_FLAG_SINK = (GST_OBJECT_FLAG_LAST << 1),
  310. GST_ELEMENT_FLAG_SOURCE = (GST_OBJECT_FLAG_LAST << 2),
  311. GST_ELEMENT_FLAG_PROVIDE_CLOCK = (GST_OBJECT_FLAG_LAST << 3),
  312. GST_ELEMENT_FLAG_REQUIRE_CLOCK = (GST_OBJECT_FLAG_LAST << 4),
  313. GST_ELEMENT_FLAG_INDEXABLE = (GST_OBJECT_FLAG_LAST << 5),
  314. /* padding */
  315. GST_ELEMENT_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 10)
  316. } GstElementFlags;
  317. /**
  318. * GST_ELEMENT_IS_LOCKED_STATE:
  319. * @elem: A #GstElement to query
  320. *
  321. * Check if the element is in the locked state and therefore will ignore state
  322. * changes from its parent object.
  323. */
  324. #define GST_ELEMENT_IS_LOCKED_STATE(elem) (GST_OBJECT_FLAG_IS_SET(elem,GST_ELEMENT_FLAG_LOCKED_STATE))
  325. /**
  326. * GST_ELEMENT_NAME:
  327. * @elem: A #GstElement to query
  328. *
  329. * Gets the name of this element. This is not thread-safe by default
  330. * (i.e. you will have to make sure the object lock is taken yourself).
  331. * If in doubt use gst_element_get_name() instead.
  332. */
  333. #define GST_ELEMENT_NAME(elem) (GST_OBJECT_NAME(elem))
  334. /**
  335. * GST_ELEMENT_PARENT:
  336. * @elem: A #GstElement to query
  337. *
  338. * Get the parent object of this element. This is not thread-safe by default
  339. * (i.e. you will have to make sure the object lock is taken yourself).
  340. * If in doubt use gst_object_get_parent() instead.
  341. */
  342. #define GST_ELEMENT_PARENT(elem) (GST_ELEMENT_CAST(GST_OBJECT_PARENT(elem)))
  343. /**
  344. * GST_ELEMENT_BUS:
  345. * @elem: A #GstElement to query
  346. *
  347. * Get the message bus of this element. This is not thread-safe by default
  348. * (i.e. you will have to make sure the object lock is taken yourself).
  349. * If in doubt use gst_element_get_bus() instead.
  350. */
  351. #define GST_ELEMENT_BUS(elem) (GST_ELEMENT_CAST(elem)->bus)
  352. /**
  353. * GST_ELEMENT_CLOCK:
  354. * @elem: A #GstElement to query
  355. *
  356. * Get the clock of this element.This is not thread-safe by default
  357. * (i.e. you will have to make sure it is safe yourself).
  358. * If in doubt use gst_element_get_clock() instead.
  359. */
  360. #define GST_ELEMENT_CLOCK(elem) (GST_ELEMENT_CAST(elem)->clock)
  361. /**
  362. * GST_ELEMENT_PADS:
  363. * @elem: A #GstElement to query
  364. *
  365. * Get the pads of this elements.
  366. */
  367. #define GST_ELEMENT_PADS(elem) (GST_ELEMENT_CAST(elem)->pads)
  368. /**
  369. * GST_ELEMENT_START_TIME:
  370. * @elem: a #GstElement to return the start time for.
  371. *
  372. * This macro returns the start_time of the @elem. The start_time is the
  373. * running_time of the pipeline when the element went to PAUSED.
  374. */
  375. #define GST_ELEMENT_START_TIME(elem) (GST_ELEMENT_CAST(elem)->start_time)
  376. /**
  377. * GST_ELEMENT_ERROR:
  378. * @el: the element that generates the error
  379. * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
  380. * @code: error code defined for that domain (see #gstreamer-GstGError)
  381. * @text: the message to display (format string and args enclosed in
  382. parentheses)
  383. * @debug: debugging information for the message (format string and args
  384. enclosed in parentheses)
  385. *
  386. * Utility function that elements can use in case they encountered a fatal
  387. * data processing error. The pipeline will post an error message and the
  388. * application will be requested to stop further media processing.
  389. */
  390. #define GST_ELEMENT_ERROR(el, domain, code, text, debug) \
  391. G_STMT_START { \
  392. gchar *__txt = _gst_element_error_printf text; \
  393. gchar *__dbg = _gst_element_error_printf debug; \
  394. if (__txt) \
  395. GST_WARNING_OBJECT (el, "error: %s", __txt); \
  396. if (__dbg) \
  397. GST_WARNING_OBJECT (el, "error: %s", __dbg); \
  398. gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_ERROR, \
  399. GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \
  400. __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__); \
  401. } G_STMT_END
  402. /**
  403. * GST_ELEMENT_WARNING:
  404. * @el: the element that generates the warning
  405. * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
  406. * @code: error code defined for that domain (see #gstreamer-GstGError)
  407. * @text: the message to display (format string and args enclosed in
  408. parentheses)
  409. * @debug: debugging information for the message (format string and args
  410. enclosed in parentheses)
  411. *
  412. * Utility function that elements can use in case they encountered a non-fatal
  413. * data processing problem. The pipeline will post a warning message and the
  414. * application will be informed.
  415. */
  416. #define GST_ELEMENT_WARNING(el, domain, code, text, debug) \
  417. G_STMT_START { \
  418. gchar *__txt = _gst_element_error_printf text; \
  419. gchar *__dbg = _gst_element_error_printf debug; \
  420. if (__txt) \
  421. GST_WARNING_OBJECT (el, "warning: %s", __txt); \
  422. if (__dbg) \
  423. GST_WARNING_OBJECT (el, "warning: %s", __dbg); \
  424. gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_WARNING, \
  425. GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \
  426. __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__); \
  427. } G_STMT_END
  428. /**
  429. * GST_ELEMENT_INFO:
  430. * @el: the element that generates the information
  431. * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
  432. * @code: error code defined for that domain (see #gstreamer-GstGError)
  433. * @text: the message to display (format string and args enclosed in
  434. parentheses)
  435. * @debug: debugging information for the message (format string and args
  436. enclosed in parentheses)
  437. *
  438. * Utility function that elements can use in case they want to inform
  439. * the application of something noteworthy that is not an error.
  440. * The pipeline will post a info message and the
  441. * application will be informed.
  442. */
  443. #define GST_ELEMENT_INFO(el, domain, code, text, debug) \
  444. G_STMT_START { \
  445. gchar *__txt = _gst_element_error_printf text; \
  446. gchar *__dbg = _gst_element_error_printf debug; \
  447. if (__txt) \
  448. GST_INFO_OBJECT (el, "info: %s", __txt); \
  449. if (__dbg) \
  450. GST_INFO_OBJECT (el, "info: %s", __dbg); \
  451. gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_INFO, \
  452. GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \
  453. __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__); \
  454. } G_STMT_END
  455. /* the state change mutexes and conds */
  456. /**
  457. * GST_STATE_GET_LOCK:
  458. * @elem: a #GstElement
  459. *
  460. * Get a reference to the state lock of @elem.
  461. * This lock is used by the core. It is taken while getting or setting
  462. * the state, during state changes, and while finalizing.
  463. */
  464. #define GST_STATE_GET_LOCK(elem) (&(GST_ELEMENT_CAST(elem)->state_lock))
  465. /**
  466. * GST_STATE_GET_COND:
  467. * @elem: a #GstElement
  468. *
  469. * Get the conditional used to signal the completion of a state change.
  470. */
  471. #define GST_STATE_GET_COND(elem) (&GST_ELEMENT_CAST(elem)->state_cond)
  472. #define GST_STATE_LOCK(elem) g_rec_mutex_lock(GST_STATE_GET_LOCK(elem))
  473. #define GST_STATE_TRYLOCK(elem) g_rec_mutex_trylock(GST_STATE_GET_LOCK(elem))
  474. #define GST_STATE_UNLOCK(elem) g_rec_mutex_unlock(GST_STATE_GET_LOCK(elem))
  475. #define GST_STATE_WAIT(elem) g_cond_wait (GST_STATE_GET_COND (elem), \
  476. GST_OBJECT_GET_LOCK (elem))
  477. #define GST_STATE_WAIT_UNTIL(elem, end_time) g_cond_wait_until (GST_STATE_GET_COND (elem), \
  478. GST_OBJECT_GET_LOCK (elem), end_time)
  479. #define GST_STATE_SIGNAL(elem) g_cond_signal (GST_STATE_GET_COND (elem));
  480. #define GST_STATE_BROADCAST(elem) g_cond_broadcast (GST_STATE_GET_COND (elem));
  481. /**
  482. * GstElement:
  483. * @state_lock: Used to serialize execution of gst_element_set_state()
  484. * @state_cond: Used to signal completion of a state change
  485. * @state_cookie: Used to detect concurrent execution of
  486. * gst_element_set_state() and gst_element_get_state()
  487. * @target_state: the target state of an element as set by the application
  488. * @current_state: the current state of an element
  489. * @next_state: the next state of an element, can be #GST_STATE_VOID_PENDING if
  490. * the element is in the correct state.
  491. * @pending_state: the final state the element should go to, can be
  492. * #GST_STATE_VOID_PENDING if the element is in the correct state
  493. * @last_return: the last return value of an element state change
  494. * @bus: the bus of the element. This bus is provided to the element by the
  495. * parent element or the application. A #GstPipeline has a bus of its own.
  496. * @clock: the clock of the element. This clock is usually provided to the
  497. * element by the toplevel #GstPipeline.
  498. * @base_time: the time of the clock right before the element is set to
  499. * PLAYING. Subtracting @base_time from the current clock time in the PLAYING
  500. * state will yield the running_time against the clock.
  501. * @start_time: the running_time of the last PAUSED state
  502. * @numpads: number of pads of the element, includes both source and sink pads.
  503. * @pads: (element-type Gst.Pad): list of pads
  504. * @numsrcpads: number of source pads of the element.
  505. * @srcpads: (element-type Gst.Pad): list of source pads
  506. * @numsinkpads: number of sink pads of the element.
  507. * @sinkpads: (element-type Gst.Pad): list of sink pads
  508. * @pads_cookie: updated whenever the a pad is added or removed
  509. *
  510. * GStreamer element abstract base class.
  511. */
  512. struct _GstElement
  513. {
  514. GstObject object;
  515. /*< public >*/ /* with LOCK */
  516. GRecMutex state_lock;
  517. /* element state */
  518. GCond state_cond;
  519. guint32 state_cookie;
  520. GstState target_state;
  521. GstState current_state;
  522. GstState next_state;
  523. GstState pending_state;
  524. GstStateChangeReturn last_return;
  525. GstBus *bus;
  526. /* allocated clock */
  527. GstClock *clock;
  528. GstClockTimeDiff base_time; /* NULL/READY: 0 - PAUSED: current time - PLAYING: difference to clock */
  529. GstClockTime start_time;
  530. /* element pads, these lists can only be iterated while holding
  531. * the LOCK or checking the cookie after each LOCK. */
  532. guint16 numpads;
  533. GList *pads;
  534. guint16 numsrcpads;
  535. GList *srcpads;
  536. guint16 numsinkpads;
  537. GList *sinkpads;
  538. guint32 pads_cookie;
  539. /* with object LOCK */
  540. GList *contexts;
  541. /*< private >*/
  542. gpointer _gst_reserved[GST_PADDING-1];
  543. };
  544. /**
  545. * GstElementClass:
  546. * @parent_class: the parent class structure
  547. * @metadata: metadata for elements of this class
  548. * @elementfactory: the #GstElementFactory that creates these elements
  549. * @padtemplates: a #GList of #GstPadTemplate
  550. * @numpadtemplates: the number of padtemplates
  551. * @pad_templ_cookie: changed whenever the padtemplates change
  552. * @request_new_pad: called when a new pad is requested
  553. * @release_pad: called when a request pad is to be released
  554. * @get_state: get the state of the element
  555. * @set_state: set a new state on the element
  556. * @change_state: called by @set_state to perform an incremental state change
  557. * @set_bus: set a #GstBus on the element
  558. * @provide_clock: gets the #GstClock provided by the element
  559. * @set_clock: set the #GstClock on the element
  560. * @send_event: send a #GstEvent to the element
  561. * @query: perform a #GstQuery on the element
  562. * @state_changed: called immediately after a new state was set.
  563. * @post_message: called when a message is posted on the element. Chain up to
  564. * the parent class' handler to have it posted on the bus.
  565. * @set_context: set a #GstContext on the element
  566. *
  567. * GStreamer element class. Override the vmethods to implement the element
  568. * functionality.
  569. */
  570. struct _GstElementClass
  571. {
  572. GstObjectClass parent_class;
  573. /*< public >*/
  574. /* the element metadata */
  575. gpointer metadata;
  576. /* factory that the element was created from */
  577. GstElementFactory *elementfactory;
  578. /* templates for our pads */
  579. GList *padtemplates;
  580. gint numpadtemplates;
  581. guint32 pad_templ_cookie;
  582. /*< private >*/
  583. /* signal callbacks */
  584. void (*pad_added) (GstElement *element, GstPad *pad);
  585. void (*pad_removed) (GstElement *element, GstPad *pad);
  586. void (*no_more_pads) (GstElement *element);
  587. /*< public >*/
  588. /* virtual methods for subclasses */
  589. /* request/release pads */
  590. /* FIXME 2.0 harmonize naming with gst_element_request_pad */
  591. GstPad* (*request_new_pad) (GstElement *element, GstPadTemplate *templ,
  592. const gchar* name, const GstCaps *caps);
  593. void (*release_pad) (GstElement *element, GstPad *pad);
  594. /* state changes */
  595. GstStateChangeReturn (*get_state) (GstElement * element, GstState * state,
  596. GstState * pending, GstClockTime timeout);
  597. GstStateChangeReturn (*set_state) (GstElement *element, GstState state);
  598. GstStateChangeReturn (*change_state) (GstElement *element, GstStateChange transition);
  599. void (*state_changed) (GstElement *element, GstState oldstate,
  600. GstState newstate, GstState pending);
  601. /* bus */
  602. void (*set_bus) (GstElement * element, GstBus * bus);
  603. /* set/get clocks */
  604. GstClock* (*provide_clock) (GstElement *element);
  605. gboolean (*set_clock) (GstElement *element, GstClock *clock);
  606. /* query functions */
  607. gboolean (*send_event) (GstElement *element, GstEvent *event);
  608. gboolean (*query) (GstElement *element, GstQuery *query);
  609. gboolean (*post_message) (GstElement *element, GstMessage *message);
  610. void (*set_context) (GstElement *element, GstContext *context);
  611. /*< private >*/
  612. gpointer _gst_reserved[GST_PADDING_LARGE-2];
  613. };
  614. /* element class pad templates */
  615. void gst_element_class_add_pad_template (GstElementClass *klass, GstPadTemplate *templ);
  616. void gst_element_class_add_static_pad_template (GstElementClass *klass, GstStaticPadTemplate *static_templ);
  617. GstPadTemplate* gst_element_class_get_pad_template (GstElementClass *element_class, const gchar *name);
  618. GList* gst_element_class_get_pad_template_list (GstElementClass *element_class);
  619. /* element class meta data */
  620. void gst_element_class_set_metadata (GstElementClass *klass,
  621. const gchar *longname,
  622. const gchar *classification,
  623. const gchar *description,
  624. const gchar *author);
  625. void gst_element_class_set_static_metadata (GstElementClass *klass,
  626. const gchar *longname,
  627. const gchar *classification,
  628. const gchar *description,
  629. const gchar *author);
  630. void gst_element_class_add_metadata (GstElementClass * klass,
  631. const gchar * key, const gchar * value);
  632. void gst_element_class_add_static_metadata (GstElementClass * klass,
  633. const gchar * key, const gchar * value);
  634. const gchar * gst_element_class_get_metadata (GstElementClass * klass,
  635. const gchar * key);
  636. /* element instance */
  637. GType gst_element_get_type (void);
  638. /* basic name and parentage stuff from GstObject */
  639. /**
  640. * gst_element_get_name:
  641. * @elem: a #GstElement to get the name of @elem.
  642. *
  643. * Returns a copy of the name of @elem.
  644. * Caller should g_free() the return value after usage.
  645. * For a nameless element, this returns %NULL, which you can safely g_free()
  646. * as well.
  647. *
  648. * Returns: (transfer full) (nullable): the name of @elem. g_free()
  649. * after usage. MT safe.
  650. *
  651. */
  652. #define gst_element_get_name(elem) gst_object_get_name(GST_OBJECT_CAST(elem))
  653. /**
  654. * gst_element_set_name:
  655. * @elem: a #GstElement to set the name of.
  656. * @name: the new name
  657. *
  658. * Sets the name of the element, getting rid of the old name if there was one.
  659. */
  660. #define gst_element_set_name(elem,name) gst_object_set_name(GST_OBJECT_CAST(elem),name)
  661. /**
  662. * gst_element_get_parent:
  663. * @elem: a #GstElement to get the parent of.
  664. *
  665. * Get the parent of an element.
  666. *
  667. * Returns: (transfer full): the parent of an element.
  668. */
  669. #define gst_element_get_parent(elem) gst_object_get_parent(GST_OBJECT_CAST(elem))
  670. /**
  671. * gst_element_set_parent:
  672. * @elem: a #GstElement to set the parent of.
  673. * @parent: the new parent #GstObject of the element.
  674. *
  675. * Sets the parent of an element.
  676. */
  677. #define gst_element_set_parent(elem,parent) gst_object_set_parent(GST_OBJECT_CAST(elem),parent)
  678. /* clocking */
  679. GstClock* gst_element_provide_clock (GstElement *element);
  680. GstClock* gst_element_get_clock (GstElement *element);
  681. gboolean gst_element_set_clock (GstElement *element, GstClock *clock);
  682. void gst_element_set_base_time (GstElement *element, GstClockTime time);
  683. GstClockTime gst_element_get_base_time (GstElement *element);
  684. void gst_element_set_start_time (GstElement *element, GstClockTime time);
  685. GstClockTime gst_element_get_start_time (GstElement *element);
  686. /* bus */
  687. void gst_element_set_bus (GstElement * element, GstBus * bus);
  688. GstBus * gst_element_get_bus (GstElement * element);
  689. /* context */
  690. void gst_element_set_context (GstElement * element, GstContext * context);
  691. GList * gst_element_get_contexts (GstElement * element);
  692. GstContext * gst_element_get_context (GstElement * element, const gchar * context_type);
  693. GstContext * gst_element_get_context_unlocked (GstElement * element, const gchar * context_type);
  694. /* pad management */
  695. gboolean gst_element_add_pad (GstElement *element, GstPad *pad);
  696. gboolean gst_element_remove_pad (GstElement *element, GstPad *pad);
  697. void gst_element_no_more_pads (GstElement *element);
  698. GstPad* gst_element_get_static_pad (GstElement *element, const gchar *name);
  699. GstPad* gst_element_get_request_pad (GstElement *element, const gchar *name);
  700. GstPad* gst_element_request_pad (GstElement *element, GstPadTemplate *templ,
  701. const gchar * name, const GstCaps *caps);
  702. void gst_element_release_request_pad (GstElement *element, GstPad *pad);
  703. GstIterator * gst_element_iterate_pads (GstElement * element);
  704. GstIterator * gst_element_iterate_src_pads (GstElement * element);
  705. GstIterator * gst_element_iterate_sink_pads (GstElement * element);
  706. /* event/query/format stuff */
  707. gboolean gst_element_send_event (GstElement *element, GstEvent *event);
  708. gboolean gst_element_seek (GstElement *element, gdouble rate,
  709. GstFormat format, GstSeekFlags flags,
  710. GstSeekType start_type, gint64 start,
  711. GstSeekType stop_type, gint64 stop);
  712. gboolean gst_element_query (GstElement *element, GstQuery *query);
  713. /* messages */
  714. gboolean gst_element_post_message (GstElement * element, GstMessage * message);
  715. /* error handling */
  716. /* gcc versions < 3.3 warn about NULL being passed as format to printf */
  717. #if (!defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 3))
  718. gchar * _gst_element_error_printf (const gchar *format, ...);
  719. #else
  720. gchar * _gst_element_error_printf (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
  721. #endif
  722. void gst_element_message_full (GstElement * element, GstMessageType type,
  723. GQuark domain, gint code, gchar * text,
  724. gchar * debug, const gchar * file,
  725. const gchar * function, gint line);
  726. /* state management */
  727. gboolean gst_element_is_locked_state (GstElement *element);
  728. gboolean gst_element_set_locked_state (GstElement *element, gboolean locked_state);
  729. gboolean gst_element_sync_state_with_parent (GstElement *element);
  730. GstStateChangeReturn gst_element_get_state (GstElement * element,
  731. GstState * state,
  732. GstState * pending,
  733. GstClockTime timeout);
  734. GstStateChangeReturn gst_element_set_state (GstElement *element, GstState state);
  735. void gst_element_abort_state (GstElement * element);
  736. GstStateChangeReturn gst_element_change_state (GstElement * element,
  737. GstStateChange transition);
  738. GstStateChangeReturn gst_element_continue_state (GstElement * element,
  739. GstStateChangeReturn ret);
  740. void gst_element_lost_state (GstElement * element);
  741. /* factory management */
  742. GstElementFactory* gst_element_get_factory (GstElement *element);
  743. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  744. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstElement, gst_object_unref)
  745. #endif
  746. G_END_DECLS
  747. #endif /* __GST_ELEMENT_H__ */