mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 22:16:22 +00:00
tsdemux: Make jp2k handling more robust and efficient
* Avoid copying the pending data and instead create a buffer directly from that data with the appropriate offset. * Locate the jp2k magic to determine the exact location of the (first) frame data instead of assuming that the header is of an expected size https://bugzilla.gnome.org/show_bug.cgi?id=786111
This commit is contained in:
parent
c393f0d768
commit
52d0ef2665
1 changed files with 20 additions and 24 deletions
|
@ -2675,9 +2675,8 @@ parse_jp2k_access_unit (TSDemuxStream * stream)
|
||||||
guint8 CollC G_GNUC_UNUSED;
|
guint8 CollC G_GNUC_UNUSED;
|
||||||
guint8 b G_GNUC_UNUSED;
|
guint8 b G_GNUC_UNUSED;
|
||||||
|
|
||||||
guint8 *packet_data = NULL;
|
guint data_location;
|
||||||
guint packet_size;
|
GstBuffer *retbuf = NULL;
|
||||||
guint remaining = 0;
|
|
||||||
|
|
||||||
if (stream->current_size < header_size) {
|
if (stream->current_size < header_size) {
|
||||||
GST_ERROR_OBJECT (stream->pad, "Not enough data for header");
|
GST_ERROR_OBJECT (stream->pad, "Not enough data for header");
|
||||||
|
@ -2686,6 +2685,16 @@ parse_jp2k_access_unit (TSDemuxStream * stream)
|
||||||
|
|
||||||
gst_byte_reader_init (&reader, stream->data, stream->current_size);
|
gst_byte_reader_init (&reader, stream->data, stream->current_size);
|
||||||
|
|
||||||
|
/* Check for the location of the jp2k magic */
|
||||||
|
data_location =
|
||||||
|
gst_byte_reader_masked_scan_uint32 (&reader, 0xffffffff, 0xff4fff51, 0,
|
||||||
|
stream->current_size);
|
||||||
|
GST_DEBUG_OBJECT (stream->pad, "data location %d", data_location);
|
||||||
|
if (data_location == -1) {
|
||||||
|
GST_ERROR_OBJECT (stream->pad, "Stream does not contain jp2k magic header");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
/* Elementary stream header box 'elsm' == 0x656c736d */
|
/* Elementary stream header box 'elsm' == 0x656c736d */
|
||||||
header_tag = gst_byte_reader_get_uint32_be_unchecked (&reader);
|
header_tag = gst_byte_reader_get_uint32_be_unchecked (&reader);
|
||||||
if (header_tag != 0x656c736d) {
|
if (header_tag != 0x656c736d) {
|
||||||
|
@ -2759,33 +2768,20 @@ parse_jp2k_access_unit (TSDemuxStream * stream)
|
||||||
}
|
}
|
||||||
CollC = gst_byte_reader_get_uint8_unchecked (&reader);
|
CollC = gst_byte_reader_get_uint8_unchecked (&reader);
|
||||||
b = gst_byte_reader_get_uint8_unchecked (&reader);
|
b = gst_byte_reader_get_uint8_unchecked (&reader);
|
||||||
remaining = gst_byte_reader_get_remaining (&reader);
|
|
||||||
packet_size = remaining;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (stream->pad,
|
/* Check if we have enough data to create a valid buffer */
|
||||||
"Size of first codestream in TS stream: %d; bytes remaining: %d", AUF[0],
|
if ((stream->current_size - data_location) < (AUF[0] + AUF[1])) {
|
||||||
remaining);
|
GST_ERROR ("Required size (%d) greater than remaining size in buffer (%d)",
|
||||||
|
AUF[0] + AUF[1], (stream->current_size - data_location));
|
||||||
if (!gst_byte_reader_dup_data (&reader, packet_size, &packet_data)) {
|
|
||||||
GST_ERROR ("Required size %d > %d than remaining size in buffer", AUF[0],
|
|
||||||
packet_size);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
#ifdef TSDEMUX_JP2K_SUPPORT_INTERLACE
|
|
||||||
if (stream->jp2kInfos.interlace) {
|
|
||||||
remaining = gst_byte_reader_get_remaining (&reader);
|
|
||||||
if (!gst_byte_reader_dup_data (&reader, AUF[1], &packet_data)) {
|
|
||||||
GST_ERROR ("Required size %d > %d than remaining size in buffer", AUF[1],
|
|
||||||
remaining);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
retbuf = gst_buffer_new_wrapped_full (0, stream->data, stream->current_size,
|
||||||
#endif
|
data_location, stream->current_size - data_location,
|
||||||
g_free (stream->data);
|
stream->data, g_free);
|
||||||
stream->data = NULL;
|
stream->data = NULL;
|
||||||
stream->current_size = 0;
|
stream->current_size = 0;
|
||||||
return gst_buffer_new_wrapped (packet_data, packet_size);
|
return retbuf;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
GST_ERROR ("Failed to parse JP2K access unit");
|
GST_ERROR ("Failed to parse JP2K access unit");
|
||||||
|
|
Loading…
Reference in a new issue