1 /* GStreamer mplex (mjpegtools) wrapper 2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net> 3 * 4 * gstmplex.hh: gstreamer mplex wrapper 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library; if not, write to the 18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __GST_MPLEX_H__ 23 #define __GST_MPLEX_H__ 24 25 #include <gst/gst.h> 26 #include <gst/base/gstadapter.h> 27 #include <multiplexor.hpp> 28 #include "gstmplexibitstream.hh" 29 #include "gstmplexjob.hh" 30 31 G_BEGIN_DECLS 32 33 #define GST_TYPE_MPLEX \ 34 (gst_mplex_get_type ()) 35 #define GST_MPLEX(obj) \ 36 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MPLEX, GstMplex)) 37 #define GST_MPLEX_CLASS(klass) \ 38 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MPLEX, GstMplex)) 39 #define GST_IS_MPLEX(obj) \ 40 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MPLEX)) 41 #define GST_IS_MPLEX_CLASS(obj) \ 42 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MPLEX)) 43 44 GST_DEBUG_CATEGORY_EXTERN (mplex_debug); 45 #define GST_CAT_DEFAULT mplex_debug 46 47 #define GST_MPLEX_MUTEX_LOCK(m) G_STMT_START { \ 48 GST_LOG_OBJECT (m, "locking tlock from thread %p", g_thread_self ()); \ 49 g_mutex_lock (&(m)->tlock); \ 50 GST_LOG_OBJECT (m, "locked tlock from thread %p", g_thread_self ()); \ 51 } G_STMT_END 52 53 #define GST_MPLEX_MUTEX_UNLOCK(m) G_STMT_START { \ 54 GST_LOG_OBJECT (m, "unlocking tlock from thread %p", g_thread_self ()); \ 55 g_mutex_unlock (&(m)->tlock); \ 56 } G_STMT_END 57 58 #define GST_MPLEX_WAIT(m, p) G_STMT_START { \ 59 GST_LOG_OBJECT (m, "thread %p waiting", g_thread_self ()); \ 60 g_cond_wait (&(p)->cond, &(m)->tlock); \ 61 } G_STMT_END 62 63 #define GST_MPLEX_SIGNAL(m, p) G_STMT_START { \ 64 GST_LOG_OBJECT (m, "signalling from thread %p", g_thread_self ()); \ 65 g_cond_signal (&(p)->cond); \ 66 } G_STMT_END 67 68 #define GST_MPLEX_SIGNAL_ALL(m) G_STMT_START { \ 69 GST_LOG_OBJECT (m, "signalling all from thread %p", g_thread_self ()); \ 70 GSList *walk = m->pads; \ 71 while (walk) { \ 72 GST_MPLEX_SIGNAL (m, (GstMplexPad *) walk->data); \ 73 walk = walk->next; \ 74 } \ 75 } G_STMT_END 76 77 typedef struct _GstMplexPad 78 { 79 /* associated pad */ 80 GstPad *pad; 81 /* with mplex TLOCK */ 82 /* adapter collecting buffers for this pad */ 83 GstAdapter *adapter; 84 /* no more to expect on this pad */ 85 gboolean eos; 86 /* signals counterpart thread to have a look */ 87 GCond cond; 88 /* amount needed by mplex on this stream */ 89 guint needed; 90 /* bitstream for this pad */ 91 GstMplexIBitStream *bs; 92 } GstMplexPad; 93 94 typedef struct _GstMplex { 95 GstElement parent; 96 97 /* pads */ 98 GSList *pads; 99 GstPad *srcpad; 100 guint num_apads, num_vpads; 101 102 /* options wrapper */ 103 GstMplexJob *job; 104 105 /* lock for syncing */ 106 GMutex tlock; 107 /* with TLOCK */ 108 /* muxer writer generated eos */ 109 gboolean eos; 110 /* flowreturn obtained by muxer task */ 111 GstFlowReturn srcresult; 112 } GstMplex; 113 114 typedef struct _GstMplexClass { 115 GstElementClass parent; 116 } GstMplexClass; 117 118 GType gst_mplex_get_type (void); 119 120 GST_ELEMENT_REGISTER_DECLARE (mplex); 121 122 G_END_DECLS 123 124 #endif /* __GST_MPLEX_H__ */ 125