summaryrefslogtreecommitdiff
path: root/ext/mplex
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mplex')
-rw-r--r--ext/mplex/gstmplex.cc121
-rw-r--r--ext/mplex/gstmplex.hh12
-rw-r--r--ext/mplex/gstmplexibitstream.cc2
-rw-r--r--ext/mplex/gstmplexoutputstream.cc3
4 files changed, 73 insertions, 65 deletions
diff --git a/ext/mplex/gstmplex.cc b/ext/mplex/gstmplex.cc
index 31de91e5a..2c9328d17 100644
--- a/ext/mplex/gstmplex.cc
+++ b/ext/mplex/gstmplex.cc
@@ -68,7 +68,7 @@ static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
);
static GstStaticPadTemplate video_sink_templ =
-GST_STATIC_PAD_TEMPLATE ("video_%d",
+GST_STATIC_PAD_TEMPLATE ("video_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
GST_STATIC_CAPS ("video/mpeg, "
@@ -83,7 +83,7 @@ GST_STATIC_PAD_TEMPLATE ("video_%d",
"rate = (int) [ 8000, 96000 ]"
static GstStaticPadTemplate audio_sink_templ =
- GST_STATIC_PAD_TEMPLATE ("audio_%d",
+ GST_STATIC_PAD_TEMPLATE ("audio_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
GST_STATIC_CAPS ("audio/mpeg, "
@@ -107,9 +107,10 @@ static void gst_mplex_finalize (GObject * object);
static void gst_mplex_reset (GstMplex * mplex);
static void gst_mplex_loop (GstMplex * mplex);
static GstPad *gst_mplex_request_new_pad (GstElement * element,
- GstPadTemplate * templ, const gchar * name);
+ GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
static void gst_mplex_release_pad (GstElement * element, GstPad * pad);
-static gboolean gst_mplex_src_activate_push (GstPad * pad, gboolean active);
+static gboolean gst_mplex_src_activate_mode (GstPad * pad, GstObject * parent,
+ GstPadMode mode, gboolean active);
static GstStateChangeReturn gst_mplex_change_state (GstElement * element,
GstStateChange transition);
@@ -118,26 +119,8 @@ static void gst_mplex_get_property (GObject * object,
static void gst_mplex_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
-GST_BOILERPLATE (GstMplex, gst_mplex, GstElement, GST_TYPE_ELEMENT);
-
-static void
-gst_mplex_base_init (gpointer klass)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-
- gst_element_class_set_details_simple (element_class,
- "mplex video multiplexer", "Codec/Muxer",
- "High-quality MPEG/DVD/SVCD/VCD video/audio multiplexer",
- "Andrew Stevens <andrew.stevens@nexgo.de>\n"
- "Ronald Bultje <rbultje@ronald.bitfreak.net>\n"
- "Mark Nauwelaerts <mnauw@users.sourceforge.net>");
-
- gst_element_class_add_static_pad_template (element_class, &src_templ);
- gst_element_class_add_static_pad_template (element_class,
- &video_sink_templ);
- gst_element_class_add_static_pad_template (element_class,
- &audio_sink_templ);
-}
+#define parent_class gst_mplex_parent_class
+G_DEFINE_TYPE (GstMplex, gst_mplex, GST_TYPE_ELEMENT);
static void
gst_mplex_class_init (GstMplexClass * klass)
@@ -159,6 +142,20 @@ gst_mplex_class_init (GstMplexClass * klass)
element_class->request_new_pad =
GST_DEBUG_FUNCPTR (gst_mplex_request_new_pad);
element_class->release_pad = GST_DEBUG_FUNCPTR (gst_mplex_release_pad);
+
+ gst_element_class_set_details_simple (element_class,
+ "mplex video multiplexer", "Codec/Muxer",
+ "High-quality MPEG/DVD/SVCD/VCD video/audio multiplexer",
+ "Andrew Stevens <andrew.stevens@nexgo.de>\n"
+ "Ronald Bultje <rbultje@ronald.bitfreak.net>\n"
+ "Mark Nauwelaerts <mnauw@users.sourceforge.net>");
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&src_templ));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&video_sink_templ));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&audio_sink_templ));
}
static void
@@ -183,30 +180,28 @@ gst_mplex_finalize (GObject * object)
/* ... and of the rest */
delete mplex->job;
- g_mutex_free (mplex->tlock);
+ g_mutex_clear (&mplex->tlock);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
-gst_mplex_init (GstMplex * mplex, GstMplexClass * g_class)
+gst_mplex_init (GstMplex * mplex)
{
GstElement *element = GST_ELEMENT (mplex);
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
mplex->srcpad =
- gst_pad_new_from_template (gst_element_class_get_pad_template
- (element_class, "src"), "src");
+ gst_pad_new_from_static_template (&src_templ, "src");
gst_element_add_pad (element, mplex->srcpad);
gst_pad_use_fixed_caps (mplex->srcpad);
- gst_pad_set_activatepush_function (mplex->srcpad,
- GST_DEBUG_FUNCPTR (gst_mplex_src_activate_push));
+ gst_pad_set_activatemode_function (mplex->srcpad,
+ GST_DEBUG_FUNCPTR (gst_mplex_src_activate_mode));
mplex->job = new GstMplexJob ();
mplex->num_apads = 0;
mplex->num_vpads = 0;
- mplex->tlock = g_mutex_new ();
+ g_mutex_init (&mplex->tlock);
gst_mplex_reset (mplex);
}
@@ -237,7 +232,7 @@ gst_mplex_reset (GstMplex * mplex)
}
if (!mpad->pad) {
- g_cond_free (mpad->cond);
+ g_cond_clear (&mpad->cond);
g_object_unref (mpad->adapter);
g_free (mpad);
} else
@@ -367,7 +362,7 @@ refuse_caps:
GST_WARNING_OBJECT (mplex, "refused caps %" GST_PTR_FORMAT, caps);
/* undo if we were a bit too fast/confident */
- if (GST_PAD_CAPS (mplex->srcpad))
+ if (gst_pad_has_current_caps (mplex->srcpad))
gst_pad_set_caps (mplex->srcpad, NULL);
return FALSE;
@@ -387,6 +382,7 @@ gst_mplex_loop (GstMplex * mplex)
GstMplexOutputStream *out = NULL;
Multiplexor *mux = NULL;
GSList *walk;
+ GstSegment segment;
/* do not try to resume muxing after it finished
* this can be relevant mainly/only in case of forced state change */
@@ -394,8 +390,8 @@ gst_mplex_loop (GstMplex * mplex)
goto eos;
/* inform downstream about what's coming */
- gst_pad_push_event (mplex->srcpad, gst_event_new_new_segment (FALSE, 1.0,
- GST_FORMAT_BYTES, 0, -1, 0));
+ gst_segment_init (&segment, GST_FORMAT_BYTES);
+ gst_pad_push_event (mplex->srcpad, gst_event_new_segment (&segment));
/* hm (!) each inputstream really needs an initial read
* so that all is internally in the proper state */
@@ -453,31 +449,31 @@ eos:
}
static gboolean
-gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
+gst_mplex_sink_event (GstPad * sinkpad, GstObject * parent, GstEvent * event)
{
GstMplex *mplex;
GstMplexPad *mpad;
gboolean result = TRUE;
- mplex = (GstMplex *) (GST_PAD_PARENT (sinkpad));
+ mplex = (GstMplex *) parent;
mpad = (GstMplexPad *) gst_pad_get_element_private (sinkpad);
g_return_val_if_fail (mpad, FALSE);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
/* forward event */
- gst_pad_event_default (sinkpad, event);
+ gst_pad_event_default (sinkpad, parent, event);
/* now unblock the chain function */
GST_MPLEX_MUTEX_LOCK (mplex);
- mplex->srcresult = GST_FLOW_WRONG_STATE;
+ mplex->srcresult = GST_FLOW_FLUSHING;
GST_MPLEX_SIGNAL (mplex, mpad);
GST_MPLEX_MUTEX_UNLOCK (mplex);
/* no way to pause/restart loop task */
goto done;
case GST_EVENT_FLUSH_STOP:
/* forward event */
- gst_pad_event_default (sinkpad, event);
+ gst_pad_event_default (sinkpad, parent, event);
/* clear state and resume */
GST_MPLEX_MUTEX_LOCK (mplex);
@@ -485,7 +481,7 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
mplex->srcresult = GST_FLOW_OK;
GST_MPLEX_MUTEX_UNLOCK (mplex);
goto done;
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_SEGMENT:
/* eat segments; we make our own (byte)stream */
gst_event_unref (event);
goto done;
@@ -499,6 +495,16 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
/* eat this event for now, task will send eos when finished */
gst_event_unref (event);
goto done;
+ case GST_EVENT_CAPS:
+ {
+ GstCaps *caps;
+
+ gst_event_parse_caps (event, &caps);
+ result = gst_mplex_setcaps (sinkpad, caps);
+ gst_event_unref (event);
+ goto done;
+ break;
+ }
default:
/* for a serialized event, wait until earlier data is gone,
* though this is no guarantee as to when task is done with it.
@@ -512,7 +518,7 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
break;
}
- result = gst_pad_event_default (sinkpad, event);
+ result = gst_pad_event_default (sinkpad, parent, event);
done:
return result;
@@ -533,12 +539,12 @@ gst_mplex_start_task (GstMplex * mplex)
}
static GstFlowReturn
-gst_mplex_chain (GstPad * sinkpad, GstBuffer * buffer)
+gst_mplex_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buffer)
{
GstMplex *mplex;
GstMplexPad *mpad;
- mplex = (GstMplex *) (GST_PAD_PARENT (sinkpad));
+ mplex = (GstMplex *) parent;
mpad = (GstMplexPad *) gst_pad_get_element_private (sinkpad);
g_return_val_if_fail (mpad, GST_FLOW_ERROR);
@@ -583,7 +589,7 @@ eos:
GST_MPLEX_MUTEX_UNLOCK (mplex);
gst_buffer_unref (buffer);
- return GST_FLOW_UNEXPECTED;
+ return GST_FLOW_EOS;
}
ignore:
{
@@ -601,7 +607,7 @@ ignore:
static GstPad *
gst_mplex_request_new_pad (GstElement * element,
- GstPadTemplate * templ, const gchar * name)
+ GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
{
GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
GstMplex *mplex = GST_MPLEX (element);
@@ -609,12 +615,12 @@ gst_mplex_request_new_pad (GstElement * element,
GstPad *newpad;
GstMplexPad *mpad;
- if (templ == gst_element_class_get_pad_template (klass, "audio_%d")) {
+ if (templ == gst_element_class_get_pad_template (klass, "audio_%u")) {
GST_DEBUG_OBJECT (mplex, "request pad audio %d", mplex->num_apads);
- padname = g_strdup_printf ("audio_%d", mplex->num_apads++);
- } else if (templ == gst_element_class_get_pad_template (klass, "video_%d")) {
+ padname = g_strdup_printf ("audio_%u", mplex->num_apads++);
+ } else if (templ == gst_element_class_get_pad_template (klass, "video_%u")) {
GST_DEBUG_OBJECT (mplex, "request pad video %d", mplex->num_vpads);
- padname = g_strdup_printf ("video_%d", mplex->num_vpads++);
+ padname = g_strdup_printf ("video_%u", mplex->num_vpads++);
} else {
GST_WARNING_OBJECT (mplex, "This is not our template!");
return NULL;
@@ -625,11 +631,10 @@ gst_mplex_request_new_pad (GstElement * element,
mpad = g_new0 (GstMplexPad, 1);
mpad->adapter = gst_adapter_new ();
- mpad->cond = g_cond_new ();
+ g_cond_init (&mpad->cond);
gst_object_ref (newpad);
mpad->pad = newpad;
- gst_pad_set_setcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_mplex_setcaps));
gst_pad_set_chain_function (newpad, GST_DEBUG_FUNCPTR (gst_mplex_chain));
gst_pad_set_event_function (newpad, GST_DEBUG_FUNCPTR (gst_mplex_sink_event));
gst_pad_set_element_private (newpad, mpad);
@@ -688,12 +693,16 @@ gst_mplex_set_property (GObject * object,
}
static gboolean
-gst_mplex_src_activate_push (GstPad * pad, gboolean active)
+gst_mplex_src_activate_mode (GstPad * pad, GstObject * parent,
+ GstPadMode mode, gboolean active)
{
gboolean result = TRUE;
GstMplex *mplex;
- mplex = GST_MPLEX (GST_PAD_PARENT (pad));
+ mplex = GST_MPLEX (parent);
+
+ if (mode != GST_PAD_MODE_PUSH)
+ return FALSE;
if (active) {
/* chain will start task once all streams have been setup */
@@ -701,7 +710,7 @@ gst_mplex_src_activate_push (GstPad * pad, gboolean active)
/* end the muxing loop by forcing eos and unblock chains */
GST_MPLEX_MUTEX_LOCK (mplex);
mplex->eos = TRUE;
- mplex->srcresult = GST_FLOW_WRONG_STATE;
+ mplex->srcresult = GST_FLOW_FLUSHING;
GST_MPLEX_SIGNAL_ALL (mplex);
GST_MPLEX_MUTEX_UNLOCK (mplex);
diff --git a/ext/mplex/gstmplex.hh b/ext/mplex/gstmplex.hh
index c519f1dc3..5e64ef1d1 100644
--- a/ext/mplex/gstmplex.hh
+++ b/ext/mplex/gstmplex.hh
@@ -46,23 +46,23 @@ GST_DEBUG_CATEGORY_EXTERN (mplex_debug);
#define GST_MPLEX_MUTEX_LOCK(m) G_STMT_START { \
GST_LOG_OBJECT (m, "locking tlock from thread %p", g_thread_self ()); \
- g_mutex_lock ((m)->tlock); \
+ g_mutex_lock (&(m)->tlock); \
GST_LOG_OBJECT (m, "locked tlock from thread %p", g_thread_self ()); \
} G_STMT_END
#define GST_MPLEX_MUTEX_UNLOCK(m) G_STMT_START { \
GST_LOG_OBJECT (m, "unlocking tlock from thread %p", g_thread_self ()); \
- g_mutex_unlock ((m)->tlock); \
+ g_mutex_unlock (&(m)->tlock); \
} G_STMT_END
#define GST_MPLEX_WAIT(m, p) G_STMT_START { \
GST_LOG_OBJECT (m, "thread %p waiting", g_thread_self ()); \
- g_cond_wait ((p)->cond, (m)->tlock); \
+ g_cond_wait (&(p)->cond, &(m)->tlock); \
} G_STMT_END
#define GST_MPLEX_SIGNAL(m, p) G_STMT_START { \
GST_LOG_OBJECT (m, "signalling from thread %p", g_thread_self ()); \
- g_cond_signal ((p)->cond); \
+ g_cond_signal (&(p)->cond); \
} G_STMT_END
#define GST_MPLEX_SIGNAL_ALL(m) G_STMT_START { \
@@ -84,7 +84,7 @@ typedef struct _GstMplexPad
/* no more to expect on this pad */
gboolean eos;
/* signals counterpart thread to have a look */
- GCond *cond;
+ GCond cond;
/* amount needed by mplex on this stream */
guint needed;
/* bitstream for this pad */
@@ -103,7 +103,7 @@ typedef struct _GstMplex {
GstMplexJob *job;
/* lock for syncing */
- GMutex *tlock;
+ GMutex tlock;
/* with TLOCK */
/* muxer writer generated eos */
gboolean eos;
diff --git a/ext/mplex/gstmplexibitstream.cc b/ext/mplex/gstmplexibitstream.cc
index 4249aea31..6f5ede7e7 100644
--- a/ext/mplex/gstmplexibitstream.cc
+++ b/ext/mplex/gstmplexibitstream.cc
@@ -53,7 +53,7 @@ size_t
GstMplexIBitStream::ReadStreamBytes (uint8_t * buf, size_t size =
BUFFER_SIZE)
{
- guint8 *data;
+ gpointer data;
GST_MPLEX_MUTEX_LOCK (mplex);
diff --git a/ext/mplex/gstmplexoutputstream.cc b/ext/mplex/gstmplexoutputstream.cc
index 5a0cc5ae9..8f56540fd 100644
--- a/ext/mplex/gstmplexoutputstream.cc
+++ b/ext/mplex/gstmplexoutputstream.cc
@@ -103,11 +103,10 @@ GstMplexOutputStream::Write (guint8 * data, guint len)
GstBuffer *buf;
buf = gst_buffer_new_and_alloc (len);
- memcpy (GST_BUFFER_DATA (buf), data, len);
+ gst_buffer_fill (buf, 0, data, len);
size += len;
GST_MPLEX_MUTEX_LOCK (mplex);
- gst_buffer_set_caps (buf, GST_PAD_CAPS (pad));
mplex->srcresult = gst_pad_push (pad, buf);
GST_MPLEX_MUTEX_UNLOCK (mplex);
}