mplex: port to 0.11

This commit is contained in:
Mark Nauwelaerts 2012-01-16 22:52:18 +01:00
parent 3f3a21ef49
commit 87937da798
4 changed files with 59 additions and 49 deletions

View file

@ -320,7 +320,7 @@ GST_PLUGINS_NONPORTED=" adpcmdec adpcmenc aiff asfmux \
videomaxrate videomeasure videosignal vmnc \ videomaxrate videomeasure videosignal vmnc \
decklink fbdev linsys shm vcd \ decklink fbdev linsys shm vcd \
apexsink bz2 cdaudio celt cog curl dc1394 dirac directfb resindvd \ apexsink bz2 cdaudio celt cog curl dc1394 dirac directfb resindvd \
gsettings gsm jp2k ladspa modplug mpeg2enc mplex mimic \ gsettings gsm jp2k ladspa modplug mpeg2enc mimic \
musepack musicbrainz nas neon ofa openal opencv rsvg schro sdl smooth sndfile soundtouch spandsp timidity \ musepack musicbrainz nas neon ofa openal opencv rsvg schro sdl smooth sndfile soundtouch spandsp timidity \
wildmidi xvid apple_media lv2 teletextdec" wildmidi xvid apple_media lv2 teletextdec"
AC_SUBST(GST_PLUGINS_NONPORTED) AC_SUBST(GST_PLUGINS_NONPORTED)

View file

@ -106,9 +106,10 @@ static void gst_mplex_finalize (GObject * object);
static void gst_mplex_reset (GstMplex * mplex); static void gst_mplex_reset (GstMplex * mplex);
static void gst_mplex_loop (GstMplex * mplex); static void gst_mplex_loop (GstMplex * mplex);
static GstPad *gst_mplex_request_new_pad (GstElement * element, 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 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, static GstStateChangeReturn gst_mplex_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
@ -117,27 +118,8 @@ static void gst_mplex_get_property (GObject * object,
static void gst_mplex_set_property (GObject * object, static void gst_mplex_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
GST_BOILERPLATE (GstMplex, gst_mplex, GstElement, GST_TYPE_ELEMENT); #define parent_class gst_mplex_parent_class
G_DEFINE_TYPE (GstMplex, gst_mplex, 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_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 static void
gst_mplex_class_init (GstMplexClass * klass) gst_mplex_class_init (GstMplexClass * klass)
@ -159,6 +141,20 @@ gst_mplex_class_init (GstMplexClass * klass)
element_class->request_new_pad = element_class->request_new_pad =
GST_DEBUG_FUNCPTR (gst_mplex_request_new_pad); GST_DEBUG_FUNCPTR (gst_mplex_request_new_pad);
element_class->release_pad = GST_DEBUG_FUNCPTR (gst_mplex_release_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 static void
@ -189,18 +185,16 @@ gst_mplex_finalize (GObject * object)
} }
static void static void
gst_mplex_init (GstMplex * mplex, GstMplexClass * g_class) gst_mplex_init (GstMplex * mplex)
{ {
GstElement *element = GST_ELEMENT (mplex); GstElement *element = GST_ELEMENT (mplex);
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
mplex->srcpad = mplex->srcpad =
gst_pad_new_from_template (gst_element_class_get_pad_template gst_pad_new_from_static_template (&src_templ, "src");
(element_class, "src"), "src");
gst_element_add_pad (element, mplex->srcpad); gst_element_add_pad (element, mplex->srcpad);
gst_pad_use_fixed_caps (mplex->srcpad); gst_pad_use_fixed_caps (mplex->srcpad);
gst_pad_set_activatepush_function (mplex->srcpad, gst_pad_set_activatemode_function (mplex->srcpad,
GST_DEBUG_FUNCPTR (gst_mplex_src_activate_push)); GST_DEBUG_FUNCPTR (gst_mplex_src_activate_mode));
mplex->job = new GstMplexJob (); mplex->job = new GstMplexJob ();
mplex->num_apads = 0; mplex->num_apads = 0;
@ -367,7 +361,7 @@ refuse_caps:
GST_WARNING_OBJECT (mplex, "refused caps %" GST_PTR_FORMAT, caps); GST_WARNING_OBJECT (mplex, "refused caps %" GST_PTR_FORMAT, caps);
/* undo if we were a bit too fast/confident */ /* 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); gst_pad_set_caps (mplex->srcpad, NULL);
return FALSE; return FALSE;
@ -387,6 +381,7 @@ gst_mplex_loop (GstMplex * mplex)
GstMplexOutputStream *out = NULL; GstMplexOutputStream *out = NULL;
Multiplexor *mux = NULL; Multiplexor *mux = NULL;
GSList *walk; GSList *walk;
GstSegment segment;
/* do not try to resume muxing after it finished /* do not try to resume muxing after it finished
* this can be relevant mainly/only in case of forced state change */ * this can be relevant mainly/only in case of forced state change */
@ -394,8 +389,8 @@ gst_mplex_loop (GstMplex * mplex)
goto eos; goto eos;
/* inform downstream about what's coming */ /* inform downstream about what's coming */
gst_pad_push_event (mplex->srcpad, gst_event_new_new_segment (FALSE, 1.0, gst_segment_init (&segment, GST_FORMAT_BYTES);
GST_FORMAT_BYTES, 0, -1, 0)); gst_pad_push_event (mplex->srcpad, gst_event_new_segment (&segment));
/* hm (!) each inputstream really needs an initial read /* hm (!) each inputstream really needs an initial read
* so that all is internally in the proper state */ * so that all is internally in the proper state */
@ -453,20 +448,20 @@ eos:
} }
static gboolean static gboolean
gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event) gst_mplex_sink_event (GstPad * sinkpad, GstObject * parent, GstEvent * event)
{ {
GstMplex *mplex; GstMplex *mplex;
GstMplexPad *mpad; GstMplexPad *mpad;
gboolean result = TRUE; gboolean result = TRUE;
mplex = (GstMplex *) (GST_PAD_PARENT (sinkpad)); mplex = (GstMplex *) parent;
mpad = (GstMplexPad *) gst_pad_get_element_private (sinkpad); mpad = (GstMplexPad *) gst_pad_get_element_private (sinkpad);
g_return_val_if_fail (mpad, FALSE); g_return_val_if_fail (mpad, FALSE);
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START: case GST_EVENT_FLUSH_START:
/* forward event */ /* forward event */
gst_pad_event_default (sinkpad, event); gst_pad_event_default (sinkpad, parent, event);
/* now unblock the chain function */ /* now unblock the chain function */
GST_MPLEX_MUTEX_LOCK (mplex); GST_MPLEX_MUTEX_LOCK (mplex);
@ -477,7 +472,7 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
goto done; goto done;
case GST_EVENT_FLUSH_STOP: case GST_EVENT_FLUSH_STOP:
/* forward event */ /* forward event */
gst_pad_event_default (sinkpad, event); gst_pad_event_default (sinkpad, parent, event);
/* clear state and resume */ /* clear state and resume */
GST_MPLEX_MUTEX_LOCK (mplex); GST_MPLEX_MUTEX_LOCK (mplex);
@ -485,7 +480,7 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
mplex->srcresult = GST_FLOW_OK; mplex->srcresult = GST_FLOW_OK;
GST_MPLEX_MUTEX_UNLOCK (mplex); GST_MPLEX_MUTEX_UNLOCK (mplex);
goto done; goto done;
case GST_EVENT_NEWSEGMENT: case GST_EVENT_SEGMENT:
/* eat segments; we make our own (byte)stream */ /* eat segments; we make our own (byte)stream */
gst_event_unref (event); gst_event_unref (event);
goto done; goto done;
@ -499,6 +494,16 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
/* eat this event for now, task will send eos when finished */ /* eat this event for now, task will send eos when finished */
gst_event_unref (event); gst_event_unref (event);
goto done; 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: default:
/* for a serialized event, wait until earlier data is gone, /* for a serialized event, wait until earlier data is gone,
* though this is no guarantee as to when task is done with it. * though this is no guarantee as to when task is done with it.
@ -512,7 +517,7 @@ gst_mplex_sink_event (GstPad * sinkpad, GstEvent * event)
break; break;
} }
result = gst_pad_event_default (sinkpad, event); result = gst_pad_event_default (sinkpad, parent, event);
done: done:
return result; return result;
@ -533,12 +538,12 @@ gst_mplex_start_task (GstMplex * mplex)
} }
static GstFlowReturn static GstFlowReturn
gst_mplex_chain (GstPad * sinkpad, GstBuffer * buffer) gst_mplex_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buffer)
{ {
GstMplex *mplex; GstMplex *mplex;
GstMplexPad *mpad; GstMplexPad *mpad;
mplex = (GstMplex *) (GST_PAD_PARENT (sinkpad)); mplex = (GstMplex *) parent;
mpad = (GstMplexPad *) gst_pad_get_element_private (sinkpad); mpad = (GstMplexPad *) gst_pad_get_element_private (sinkpad);
g_return_val_if_fail (mpad, GST_FLOW_ERROR); g_return_val_if_fail (mpad, GST_FLOW_ERROR);
@ -583,7 +588,7 @@ eos:
GST_MPLEX_MUTEX_UNLOCK (mplex); GST_MPLEX_MUTEX_UNLOCK (mplex);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
return GST_FLOW_UNEXPECTED; return GST_FLOW_EOS;
} }
ignore: ignore:
{ {
@ -601,7 +606,7 @@ ignore:
static GstPad * static GstPad *
gst_mplex_request_new_pad (GstElement * element, 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); GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
GstMplex *mplex = GST_MPLEX (element); GstMplex *mplex = GST_MPLEX (element);
@ -629,7 +634,6 @@ gst_mplex_request_new_pad (GstElement * element,
gst_object_ref (newpad); gst_object_ref (newpad);
mpad->pad = 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_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_event_function (newpad, GST_DEBUG_FUNCPTR (gst_mplex_sink_event));
gst_pad_set_element_private (newpad, mpad); gst_pad_set_element_private (newpad, mpad);
@ -688,12 +692,16 @@ gst_mplex_set_property (GObject * object,
} }
static gboolean 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; gboolean result = TRUE;
GstMplex *mplex; GstMplex *mplex;
mplex = GST_MPLEX (GST_PAD_PARENT (pad)); mplex = GST_MPLEX (parent);
if (mode != GST_PAD_MODE_PUSH)
return FALSE;
if (active) { if (active) {
/* chain will start task once all streams have been setup */ /* chain will start task once all streams have been setup */

View file

@ -53,7 +53,7 @@ size_t
GstMplexIBitStream::ReadStreamBytes (uint8_t * buf, size_t size = GstMplexIBitStream::ReadStreamBytes (uint8_t * buf, size_t size =
BUFFER_SIZE) BUFFER_SIZE)
{ {
guint8 *data; gpointer data;
GST_MPLEX_MUTEX_LOCK (mplex); GST_MPLEX_MUTEX_LOCK (mplex);

View file

@ -101,13 +101,15 @@ void
GstMplexOutputStream::Write (guint8 * data, guint len) GstMplexOutputStream::Write (guint8 * data, guint len)
{ {
GstBuffer *buf; GstBuffer *buf;
gpointer bdata;
buf = gst_buffer_new_and_alloc (len); buf = gst_buffer_new_and_alloc (len);
memcpy (GST_BUFFER_DATA (buf), data, len); bdata = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memcpy (bdata, data, len);
gst_buffer_unmap (buf, bdata, -1);
size += len; size += len;
GST_MPLEX_MUTEX_LOCK (mplex); GST_MPLEX_MUTEX_LOCK (mplex);
gst_buffer_set_caps (buf, GST_PAD_CAPS (pad));
mplex->srcresult = gst_pad_push (pad, buf); mplex->srcresult = gst_pad_push (pad, buf);
GST_MPLEX_MUTEX_UNLOCK (mplex); GST_MPLEX_MUTEX_UNLOCK (mplex);
} }