diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index 36d3285b7e..e306ef7434 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -1437,7 +1437,6 @@ mpegts_base_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) if (G_LIKELY (section.complete)) { /* section complete */ based = mpegts_base_handle_psi (base, §ion); - g_free (section.data); if (G_UNLIKELY (!based)) { /* bad PSI table */ diff --git a/gst/mpegtsdemux/mpegtspacketizer.c b/gst/mpegtsdemux/mpegtspacketizer.c index 7bafb82ddd..2f60ec2f97 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.c +++ b/gst/mpegtsdemux/mpegtspacketizer.c @@ -172,9 +172,6 @@ mpegts_packetizer_stream_new (void) static void mpegts_packetizer_clear_section (MpegTSPacketizerStream * stream) { - if (stream->section_data) - g_free (stream->section_data); - stream->section_data = NULL; stream->continuity_counter = CONTINUITY_UNSET; stream->section_length = 0; stream->section_offset = 0; @@ -185,6 +182,8 @@ static void mpegts_packetizer_stream_free (MpegTSPacketizerStream * stream) { mpegts_packetizer_clear_section (stream); + if (stream->section_data) + g_free (stream->section_data); g_slist_foreach (stream->subtables, (GFunc) g_free, NULL); g_slist_free (stream->subtables); g_free (stream); @@ -399,9 +398,8 @@ mpegts_packetizer_parse_section_header (MpegTSPacketizer2 * packetizer, GSList *subtable_list = NULL; section->complete = TRUE; - /* get the section buffer, pass the ownership to the caller */ + /* get the section buffer, ownership stays with the stream */ data = section->data = stream->section_data; - stream->section_data = NULL; section->offset = stream->offset; GST_MEMDUMP ("section header", data, stream->section_length); @@ -476,7 +474,6 @@ no_changes: section->pid, section->table_id, section->subtable_extension, section->current_next_indicator, section->version_number, section->crc); section->complete = FALSE; - g_free (section->data); return TRUE; not_applicable: @@ -485,7 +482,6 @@ not_applicable: section->pid, section->table_id, section->subtable_extension, section->current_next_indicator, section->version_number, section->crc); section->complete = FALSE; - g_free (section->data); return TRUE; } @@ -2567,7 +2563,14 @@ mpegts_packetizer_push_section (MpegTSPacketizer2 * packetizer, stream->section_length = section_length; /* Create enough room to store chunks of sections, including FF padding */ - stream->section_data = g_malloc (section_length + 188); + if (stream->section_allocated == 0) { + stream->section_data = g_malloc (section_length + 188); + stream->section_allocated = section_length + 188; + } else if (G_UNLIKELY (stream->section_allocated < section_length + 188)) { + stream->section_data = + g_realloc (stream->section_data, section_length + 188); + stream->section_allocated = section_length + 188; + } memcpy (stream->section_data, data_start, packet->data_end - data_start); stream->section_offset = packet->data_end - data_start; diff --git a/gst/mpegtsdemux/mpegtspacketizer.h b/gst/mpegtsdemux/mpegtspacketizer.h index b3600591a9..b971b35719 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.h +++ b/gst/mpegtsdemux/mpegtspacketizer.h @@ -64,14 +64,20 @@ typedef struct { guint continuity_counter; + /* Section data (reused) */ guint8 *section_data; + /* Expected length of the section */ guint section_length; + /* Allocated length of section_data */ + guint section_allocated; + /* Current offset in section_data */ guint16 section_offset; + /* table_id of the pending section_data */ guint8 section_table_id; GSList *subtables; - /* Offset of the data contained in the section */ + /* Upstream offset of the data contained in the section */ guint64 offset; } MpegTSPacketizerStream;