mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 17:20:36 +00:00
jpegparse: add gst_jpeg_parse_remove_marker()
This function will remove the whole marker from the buffer. Also we set it as the default behavior for marker JPG{0-13}? in order to avoid a useless #if https://bugzilla.gnome.org/show_bug.cgi?id=626618
This commit is contained in:
parent
0e27f49dd4
commit
824364d152
1 changed files with 26 additions and 22 deletions
|
@ -511,6 +511,31 @@ gst_jpeg_parse_sof (GstJpegParse * parse, GstByteReader * reader)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline gboolean
|
||||||
|
gst_jpeg_parse_remove_marker (GstJpegParse * parse,
|
||||||
|
GstByteReader * reader, guint8 marker, GstBuffer * buffer)
|
||||||
|
{
|
||||||
|
guint16 size = 0;
|
||||||
|
guint pos = gst_byte_reader_get_pos (reader);
|
||||||
|
guint8 *data = GST_BUFFER_DATA (buffer);
|
||||||
|
|
||||||
|
if (!gst_byte_reader_peek_uint16_be (reader, &size))
|
||||||
|
return FALSE;
|
||||||
|
if (gst_byte_reader_get_remaining (reader) < size)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (parse, "unhandled marker %x removing %u bytes", marker, size);
|
||||||
|
|
||||||
|
memmove (&data[pos], &data[pos + size],
|
||||||
|
GST_BUFFER_SIZE (buffer) - (pos + size));
|
||||||
|
GST_BUFFER_SIZE (buffer) -= size;
|
||||||
|
|
||||||
|
if (!gst_byte_reader_set_pos (reader, pos - size))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static inline gboolean
|
static inline gboolean
|
||||||
gst_jpeg_parse_skip_marker (GstJpegParse * parse,
|
gst_jpeg_parse_skip_marker (GstJpegParse * parse,
|
||||||
GstByteReader * reader, guint8 marker)
|
GstByteReader * reader, guint8 marker)
|
||||||
|
@ -671,7 +696,6 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buffer);
|
GstByteReader reader = GST_BYTE_READER_INIT_FROM_BUFFER (buffer);
|
||||||
guint8 marker = 0;
|
guint8 marker = 0;
|
||||||
guint16 size = 0;
|
|
||||||
gboolean foundSOF = FALSE;
|
gboolean foundSOF = FALSE;
|
||||||
|
|
||||||
if (!gst_byte_reader_peek_uint8 (&reader, &marker))
|
if (!gst_byte_reader_peek_uint8 (&reader, &marker))
|
||||||
|
@ -729,28 +753,8 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer)
|
||||||
default:
|
default:
|
||||||
if (marker == JPG || (marker >= JPG0 && marker <= JPG13)) {
|
if (marker == JPG || (marker >= JPG0 && marker <= JPG13)) {
|
||||||
/* we'd like to remove them from the buffer */
|
/* we'd like to remove them from the buffer */
|
||||||
#if 1
|
if (!gst_jpeg_parse_remove_marker (parse, &reader, marker, buffer))
|
||||||
guint pos = gst_byte_reader_get_pos (&reader);
|
|
||||||
guint8 *data = GST_BUFFER_DATA (buffer);
|
|
||||||
|
|
||||||
if (!gst_byte_reader_peek_uint16_be (&reader, &size))
|
|
||||||
goto error;
|
goto error;
|
||||||
if (gst_byte_reader_get_remaining (&reader) < size)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
GST_LOG_OBJECT (parse, "unhandled marker %x removing %u bytes",
|
|
||||||
marker, size);
|
|
||||||
|
|
||||||
memmove (&data[pos], &data[pos + size],
|
|
||||||
GST_BUFFER_SIZE (buffer) - (pos + size));
|
|
||||||
GST_BUFFER_SIZE (buffer) -= size;
|
|
||||||
|
|
||||||
if (!gst_byte_reader_set_pos (&reader, pos - size))
|
|
||||||
goto error;
|
|
||||||
#else
|
|
||||||
if (!gst_jpeg_parse_skip_marker (parse, &reader, marker))
|
|
||||||
goto error;
|
|
||||||
#endif
|
|
||||||
} else if (marker >= APP0 && marker <= APP15) {
|
} else if (marker >= APP0 && marker <= APP15) {
|
||||||
if (!gst_jpeg_parse_skip_marker (parse, &reader, marker))
|
if (!gst_jpeg_parse_skip_marker (parse, &reader, marker))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Reference in a new issue