summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2016-03-18 14:09:37 +0000
committerSebastian Dröge <sebastian@centricular.com>2016-10-25 16:00:29 +0300
commit8da992d1aab57363e2ce4dc02b3180d18539b669 (patch)
tree995f640b635d0e421594ba7f7446c13ea78a920e /gst
parenta1794b689fa99d5bae39ceca8ab69d5333f7929e (diff)
downloadgstreamer-plugins-bad-8da992d1aab57363e2ce4dc02b3180d18539b669.tar.gz
mpegtsmux: fix buffer size mismatch in M2TS mode
In M2TS mode, we need an extra 4 bytes in the buffer, so need to ensure the buffer can contain these. The allocation site does not know the mode, so this is done in all cases.
Diffstat (limited to 'gst')
-rw-r--r--gst/mpegtsmux/tsmux/tsmux.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c
index 638de15aa..ee2870498 100644
--- a/gst/mpegtsmux/tsmux/tsmux.c
+++ b/gst/mpegtsmux/tsmux/tsmux.c
@@ -853,6 +853,7 @@ tsmux_section_write_packet (GstMpegtsSectionType * type,
gsize data_size = 0;
gsize payload_written;
guint len = 0, offset = 0, payload_len = 0;
+ guint extra_alloc_bytes = 0;
g_return_val_if_fail (section != NULL, FALSE);
g_return_val_if_fail (mux != NULL, FALSE);
@@ -907,12 +908,35 @@ tsmux_section_write_packet (GstMpegtsSectionType * type,
TS_DEBUG ("Creating packet buffer at offset "
"%" G_GSIZE_FORMAT " with length %u", payload_written, payload_len);
+ /* If in M2TS mode, we will need to resize to 4 bytes after the end
+ of the buffer. For performance reasons, we will now try to include
+ 4 extra bytes from the source buffer, then resize down, to avoid
+ having an extra 4 byte GstMemory appended. If the source buffer
+ does not have enough data for this, a new GstMemory will be used */
+ if (gst_buffer_get_size (section_buffer) - (payload_written +
+ payload_len) >= 4) {
+ /* enough space */
+ extra_alloc_bytes = 4;
+ }
packet_buffer = gst_buffer_copy_region (section_buffer, GST_BUFFER_COPY_ALL,
- payload_written, payload_len);
+ payload_written, payload_len + extra_alloc_bytes);
/* Prepend the header to the section data */
gst_buffer_prepend_memory (packet_buffer, mem);
+ /* add an extra 4 bytes if it could not be reserved already */
+ if (extra_alloc_bytes == 4) {
+ /* we allocated those already, resize */
+ gst_buffer_set_size (packet_buffer,
+ gst_buffer_get_size (packet_buffer) - extra_alloc_bytes);
+ } else {
+ void *ptr = g_malloc (4);
+ GstMemory *extra =
+ gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, ptr, 4, 0, 0, ptr,
+ g_free);
+ gst_buffer_append_memory (packet_buffer, extra);
+ }
+
TS_DEBUG ("Writing %d bytes to section. %d bytes remaining",
len, section->pi.stream_avail - len);