gstcontext.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* GStreamer
  2. * Copyright (C) 2013 Collabora Ltd.
  3. * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
  4. * Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
  5. *
  6. * gstcontext.h: Header for GstContext subsystem
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library 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 GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. */
  23. #ifndef __GST_CONTEXT_H__
  24. #define __GST_CONTEXT_H__
  25. #include <glib.h>
  26. G_BEGIN_DECLS
  27. typedef struct _GstContext GstContext;
  28. #include <gst/gstminiobject.h>
  29. #include <gst/gststructure.h>
  30. GST_EXPORT GType _gst_context_type;
  31. #define GST_TYPE_CONTEXT (_gst_context_type)
  32. #define GST_IS_CONTEXT(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_CONTEXT))
  33. #define GST_CONTEXT_CAST(obj) ((GstContext*)(obj))
  34. #define GST_CONTEXT(obj) (GST_CONTEXT_CAST(obj))
  35. GType gst_context_get_type (void);
  36. /* refcounting */
  37. /**
  38. * gst_context_ref:
  39. * @context: the context to ref
  40. *
  41. * Convenience macro to increase the reference count of the context.
  42. *
  43. * Returns: @context (for convenience when doing assignments)
  44. */
  45. static inline GstContext *
  46. gst_context_ref (GstContext * context)
  47. {
  48. return (GstContext *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (context));
  49. }
  50. /**
  51. * gst_context_unref:
  52. * @context: the context to unref
  53. *
  54. * Convenience macro to decrease the reference count of the context, possibly
  55. * freeing it.
  56. */
  57. static inline void
  58. gst_context_unref (GstContext * context)
  59. {
  60. gst_mini_object_unref (GST_MINI_OBJECT_CAST (context));
  61. }
  62. /* copy context */
  63. /**
  64. * gst_context_copy:
  65. * @context: the context to copy
  66. *
  67. * Creates a copy of the context. Returns a copy of the context.
  68. *
  69. * Returns: (transfer full): a new copy of @context.
  70. *
  71. * MT safe
  72. */
  73. static inline GstContext *
  74. gst_context_copy (const GstContext * context)
  75. {
  76. return GST_CONTEXT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (context)));
  77. }
  78. /**
  79. * gst_context_is_writable:
  80. * @context: a #GstContext
  81. *
  82. * Tests if you can safely write into a context's structure or validly
  83. * modify the seqnum and timestamp fields.
  84. */
  85. #define gst_context_is_writable(context) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (context))
  86. /**
  87. * gst_context_make_writable:
  88. * @context: (transfer full): the context to make writable
  89. *
  90. * Checks if a context is writable. If not, a writable copy is made and
  91. * returned.
  92. *
  93. * Returns: (transfer full): a context (possibly a duplicate) that is writable.
  94. *
  95. * MT safe
  96. */
  97. #define gst_context_make_writable(context) GST_CONTEXT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (context)))
  98. /**
  99. * gst_context_replace:
  100. * @old_context: (inout) (transfer full): pointer to a pointer to a #GstContext
  101. * to be replaced.
  102. * @new_context: (allow-none) (transfer none): pointer to a #GstContext that will
  103. * replace the context pointed to by @old_context.
  104. *
  105. * Modifies a pointer to a #GstContext to point to a different #GstContext. The
  106. * modification is done atomically (so this is useful for ensuring thread safety
  107. * in some cases), and the reference counts are updated appropriately (the old
  108. * context is unreffed, the new one is reffed).
  109. *
  110. * Either @new_context or the #GstContext pointed to by @old_context may be %NULL.
  111. *
  112. * Returns: %TRUE if @new_context was different from @old_context
  113. */
  114. static inline gboolean
  115. gst_context_replace (GstContext **old_context, GstContext *new_context)
  116. {
  117. return gst_mini_object_replace ((GstMiniObject **) old_context, (GstMiniObject *) new_context);
  118. }
  119. GstContext * gst_context_new (const gchar * context_type,
  120. gboolean persistent) G_GNUC_MALLOC;
  121. const gchar * gst_context_get_context_type (const GstContext * context);
  122. gboolean gst_context_has_context_type (const GstContext * context, const gchar * context_type);
  123. const GstStructure * gst_context_get_structure (const GstContext * context);
  124. GstStructure * gst_context_writable_structure (GstContext * context);
  125. gboolean gst_context_is_persistent (const GstContext * context);
  126. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  127. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstContext, gst_context_unref)
  128. #endif
  129. G_END_DECLS
  130. #endif /* __GST_CONTEXT_H__ */