summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorEdward Hervey <edward.hervey@collabora.co.uk>2012-06-04 08:39:11 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2012-06-26 12:42:40 +0200
commit18187dd170297932ca302b889ffdc65483b4348d (patch)
tree389f948ce89a380a173529fe90e67630237911b7 /gst
parent634b5dffd54ef84b5a183e2620c11b1334821149 (diff)
mpegtspacketizer: Avoid alloc/free where possible
Helps for streams with a lot of sections, like EIT
Diffstat (limited to 'gst')
-rw-r--r--gst/mpegtsdemux/mpegtsbase.c1
-rw-r--r--gst/mpegtsdemux/mpegtspacketizer.c19
-rw-r--r--gst/mpegtsdemux/mpegtspacketizer.h8
3 files changed, 18 insertions, 10 deletions
diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c
index 4d32d5df8..ec93798ad 100644
--- a/gst/mpegtsdemux/mpegtsbase.c
+++ b/gst/mpegtsdemux/mpegtsbase.c
@@ -1456,7 +1456,6 @@ mpegts_base_chain (GstPad * pad, GstBuffer * buf)
if (G_LIKELY (section.complete)) {
/* section complete */
based = mpegts_base_handle_psi (base, &section);
- g_free (section.data);
if (G_UNLIKELY (!based)) {
/* bad PSI table */
diff --git a/gst/mpegtsdemux/mpegtspacketizer.c b/gst/mpegtsdemux/mpegtspacketizer.c
index 093257931..0bf032716 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;
}
@@ -2561,7 +2557,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 0614cbb71..4121d2189 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;