mpegtsdemux: Avoid vmethod calls

Depending on usage, tsparse and tsdemux might not need to be called
when new section/pes-data is available.
This commit is contained in:
Edward Hervey 2013-07-07 11:42:50 +02:00
parent 61b30175b3
commit 2fb7b87140
4 changed files with 28 additions and 12 deletions

View file

@ -236,6 +236,9 @@ mpegts_base_init (MpegTSBase * base)
base->program_size = sizeof (MpegTSBaseProgram);
base->stream_size = sizeof (MpegTSBaseStream);
base->push_data = TRUE;
base->push_section = TRUE;
mpegts_base_reset (base);
}
@ -1106,7 +1109,8 @@ mpegts_base_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
/* If it's a known PES, push it */
if (MPEGTS_BIT_IS_SET (base->is_pes, packet.pid)) {
/* push the packet downstream */
res = klass->push (base, &packet, NULL);
if (base->push_data)
res = klass->push (base, &packet, NULL);
} else if (packet.payload
&& MPEGTS_BIT_IS_SET (base->known_psi, packet.pid)) {
/* base PSI data */
@ -1123,7 +1127,8 @@ mpegts_base_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
}
/* we need to push section packet downstream */
res = klass->push (base, &packet, section);
if (base->push_section)
res = klass->push (base, &packet, section);
} else if (packet.payload && packet.pid != 0x1fff)
GST_LOG ("PID 0x%04x Saw packet on a pid we don't handle", packet.pid);

View file

@ -151,6 +151,10 @@ struct _MpegTSBase {
/* Whether to parse private section or not */
gboolean parse_private_sections;
/* Whether to push data and/or sections to subclasses */
gboolean push_data;
gboolean push_section;
};
struct _MpegTSBaseClass {

View file

@ -146,7 +146,12 @@ mpegts_parse_class_init (MpegTSParse2Class * klass)
static void
mpegts_parse_init (MpegTSParse2 * parse)
{
GST_MPEGTS_BASE (parse)->program_size = sizeof (MpegTSParseProgram);
MpegTSBase *base = (MpegTSBase *) parse;
base->program_size = sizeof (MpegTSParseProgram);
/* We will only need to handle data/section if we have request pads */
base->push_data = FALSE;
base->push_section = FALSE;
parse->srcpad = gst_pad_new_from_static_template (&src_template, "src");
parse->first = TRUE;
@ -269,6 +274,7 @@ static void
mpegts_parse_pad_removed (GstElement * element, GstPad * pad)
{
MpegTSParsePad *tspad;
MpegTSBase *base = (MpegTSBase *) element;
MpegTSParse2 *parse = GST_MPEGTS_PARSE (element);
if (gst_pad_get_direction (pad) == GST_PAD_SINK)
@ -280,6 +286,10 @@ mpegts_parse_pad_removed (GstElement * element, GstPad * pad)
parse->srcpads = g_list_remove_all (parse->srcpads, pad);
}
if (parse->srcpads == NULL) {
base->push_data = FALSE;
base->push_section = FALSE;
}
if (GST_ELEMENT_CLASS (parent_class)->pad_removed)
GST_ELEMENT_CLASS (parent_class)->pad_removed (element, pad);
@ -289,6 +299,7 @@ static GstPad *
mpegts_parse_request_new_pad (GstElement * element, GstPadTemplate * template,
const gchar * padname, const GstCaps * caps)
{
MpegTSBase *base = (MpegTSBase *) element;
MpegTSParse2 *parse;
MpegTSParsePad *tspad;
MpegTSParseProgram *parseprogram;
@ -320,6 +331,8 @@ mpegts_parse_request_new_pad (GstElement * element, GstPadTemplate * template,
pad = tspad->pad;
parse->srcpads = g_list_append (parse->srcpads, pad);
base->push_data = TRUE;
base->push_section = TRUE;
gst_pad_set_active (pad, TRUE);
@ -430,10 +443,6 @@ mpegts_parse_push (MpegTSBase * base, MpegTSPacketizerPacket * packet,
GstFlowReturn ret;
GList *srcpads;
/* Shortcut: If no request pads exist, just return */
if (parse->srcpads == NULL)
return GST_FLOW_OK;
GST_OBJECT_LOCK (parse);
srcpads = parse->srcpads;

View file

@ -339,6 +339,9 @@ gst_ts_demux_init (GstTSDemux * demux)
base->stream_size = sizeof (TSDemuxStream);
base->parse_private_sections = TRUE;
/* We are not interested in sections (all handled by mpegtsbase) */
base->push_section = FALSE;
gst_ts_demux_reset (base);
}
@ -1526,11 +1529,6 @@ gst_ts_demux_handle_packet (GstTSDemux * demux, TSDemuxStream * stream,
packet->payload_unit_start_indicator, packet->scram_afc_cc & 0x30,
FLAGS_CONTINUITY_COUNTER (packet->scram_afc_cc), packet->payload);
if (section) {
GST_LOG ("Got section, returning");
return res;
}
if (G_UNLIKELY (packet->payload_unit_start_indicator) &&
FLAGS_HAS_PAYLOAD (packet->scram_afc_cc))
/* Flush previous data */