mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
jpegparse: Finish port to 1.0 API
This commit is contained in:
parent
c2c6ef1697
commit
1826c126bf
4 changed files with 64 additions and 84 deletions
|
@ -314,7 +314,7 @@ GST_PLUGINS_NONPORTED=" aiff \
|
|||
cdxaparse \
|
||||
dccp faceoverlay \
|
||||
fieldanalysis freeverb freeze frei0r \
|
||||
hdvparse inter ivfparse jpegformat jp2kdecimator \
|
||||
hdvparse inter ivfparse jp2kdecimator \
|
||||
kate liveadder librfb \
|
||||
mpegpsmux mve mxf mythtv nsf nuvdemux \
|
||||
patchdetect pnm real \
|
||||
|
|
|
@ -108,9 +108,11 @@ struct _GstJifMuxPrivate
|
|||
static void gst_jif_mux_finalize (GObject * object);
|
||||
|
||||
static void gst_jif_mux_reset (GstJifMux * self);
|
||||
static gboolean gst_jif_mux_sink_setcaps (GstPad * pad, GstCaps * caps);
|
||||
static gboolean gst_jif_mux_sink_event (GstPad * pad, GstEvent * event);
|
||||
static GstFlowReturn gst_jif_mux_chain (GstPad * pad, GstBuffer * buffer);
|
||||
static gboolean gst_jif_mux_sink_setcaps (GstJifMux * self, GstCaps * caps);
|
||||
static gboolean gst_jif_mux_sink_event (GstPad * pad, GstObject * parent,
|
||||
GstEvent * event);
|
||||
static GstFlowReturn gst_jif_mux_chain (GstPad * pad, GstObject * parent,
|
||||
GstBuffer * buffer);
|
||||
static GstStateChangeReturn gst_jif_mux_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
|
||||
|
@ -180,15 +182,14 @@ gst_jif_mux_finalize (GObject * object)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_jif_mux_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||
gst_jif_mux_sink_setcaps (GstJifMux * self, GstCaps * caps)
|
||||
{
|
||||
GstJifMux *self = GST_JIF_MUX_CAST (GST_PAD_PARENT (pad));
|
||||
GstStructure *s = gst_caps_get_structure (caps, 0);
|
||||
const gchar *variant;
|
||||
|
||||
/* should be {combined (default), EXIF, JFIF} */
|
||||
if ((variant = gst_structure_get_string (s, "variant")) != NULL) {
|
||||
GST_INFO_OBJECT (pad, "muxing to '%s'", variant);
|
||||
GST_INFO_OBJECT (self, "muxing to '%s'", variant);
|
||||
/* FIXME: do we want to switch it like this or use a gobject property ? */
|
||||
}
|
||||
|
||||
|
@ -196,9 +197,9 @@ gst_jif_mux_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_jif_mux_sink_event (GstPad * pad, GstEvent * event)
|
||||
gst_jif_mux_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||
{
|
||||
GstJifMux *self = GST_JIF_MUX (GST_PAD_PARENT (pad));
|
||||
GstJifMux *self = GST_JIF_MUX (parent);
|
||||
gboolean ret;
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
|
@ -207,7 +208,7 @@ gst_jif_mux_sink_event (GstPad * pad, GstEvent * event)
|
|||
GstCaps *caps;
|
||||
|
||||
gst_event_parse_caps (event, &caps);
|
||||
ret = gst_jif_mux_sink_setcaps (pad, caps);
|
||||
ret = gst_jif_mux_sink_setcaps (self, caps);
|
||||
gst_event_unref (event);
|
||||
break;
|
||||
}
|
||||
|
@ -220,11 +221,11 @@ gst_jif_mux_sink_event (GstPad * pad, GstEvent * event)
|
|||
|
||||
gst_tag_setter_merge_tags (setter, list, mode);
|
||||
|
||||
ret = gst_pad_event_default (pad, event);
|
||||
ret = gst_pad_event_default (pad, parent, event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = gst_pad_event_default (pad, event);
|
||||
ret = gst_pad_event_default (pad, parent, event);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
|
@ -275,13 +276,12 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
|
|||
guint8 marker = 0;
|
||||
guint16 size = 0;
|
||||
const guint8 *data = NULL;
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
GstMapInfo map;
|
||||
|
||||
bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ);
|
||||
gst_byte_reader_init (&reader, bdata, bsize);
|
||||
gst_buffer_map (buf, &map, GST_MAP_READ);
|
||||
gst_byte_reader_init (&reader, map.data, map.size);
|
||||
|
||||
GST_LOG_OBJECT (self, "Received buffer of size: %u", bsize);
|
||||
GST_LOG_OBJECT (self, "Received buffer of size: %u", map.size);
|
||||
|
||||
if (!gst_byte_reader_peek_uint8 (&reader, &marker))
|
||||
goto error;
|
||||
|
@ -329,23 +329,19 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
|
|||
if (marker == SOS) {
|
||||
gint eoi_pos = -1;
|
||||
gint i;
|
||||
guint8 *mdata;
|
||||
gsize msize;
|
||||
|
||||
/* search the last 5 bytes for the EOI marker */
|
||||
mdata = gst_buffer_map (buf, &msize, NULL, GST_MAP_READ);
|
||||
g_assert (msize >= 5);
|
||||
g_assert (map.size >= 5);
|
||||
for (i = 5; i >= 2; i--) {
|
||||
if (mdata[msize - i] == 0xFF && mdata[msize - i + 1] == EOI) {
|
||||
eoi_pos = msize - i;
|
||||
if (map.data[map.size - i] == 0xFF && map.data[map.size - i + 1] == EOI) {
|
||||
eoi_pos = map.size - i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (eoi_pos == -1) {
|
||||
GST_WARNING_OBJECT (self, "Couldn't find an EOI marker");
|
||||
eoi_pos = msize;
|
||||
eoi_pos = map.size;
|
||||
}
|
||||
gst_buffer_unmap (buf, mdata, msize);
|
||||
|
||||
/* remaining size except EOI is scan data */
|
||||
self->priv->scan_size = eoi_pos - gst_byte_reader_get_pos (&reader);
|
||||
|
@ -360,11 +356,11 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
|
|||
goto error;
|
||||
}
|
||||
GST_INFO_OBJECT (self, "done parsing at 0x%x / 0x%x",
|
||||
gst_byte_reader_get_pos (&reader), bsize);
|
||||
gst_byte_reader_get_pos (&reader), map.size);
|
||||
|
||||
done:
|
||||
self->priv->markers = g_list_reverse (self->priv->markers);
|
||||
gst_buffer_unmap (buf, bdata, bsize);
|
||||
gst_buffer_unmap (buf, &map);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
@ -374,7 +370,7 @@ error:
|
|||
GST_WARNING_OBJECT (self,
|
||||
"Error parsing image header (need more that %u bytes available)",
|
||||
gst_byte_reader_get_remaining (&reader));
|
||||
gst_buffer_unmap (buf, bdata, bsize);
|
||||
gst_buffer_unmap (buf, &map);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +519,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
|
|||
cleanup_tags = FALSE;
|
||||
}
|
||||
if (!tags) {
|
||||
tags = gst_tag_list_new ();
|
||||
tags = gst_tag_list_new_empty ();
|
||||
cleanup_tags = TRUE;
|
||||
}
|
||||
|
||||
|
@ -652,8 +648,7 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
|
|||
GList *node;
|
||||
guint size = self->priv->scan_size;
|
||||
gboolean writer_status = TRUE;
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
GstMapInfo map;
|
||||
|
||||
/* iterate list and collect size */
|
||||
for (node = self->priv->markers; node; node = g_list_next (node)) {
|
||||
|
@ -677,8 +672,8 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
|
|||
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
|
||||
|
||||
/* memcopy markers */
|
||||
bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_WRITE);
|
||||
writer = gst_byte_writer_new_with_data (bdata, bsize, TRUE);
|
||||
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
||||
writer = gst_byte_writer_new_with_data (map.data, map.size, TRUE);
|
||||
|
||||
for (node = self->priv->markers; node && writer_status;
|
||||
node = g_list_next (node)) {
|
||||
|
@ -701,7 +696,7 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
|
|||
self->priv->scan_size);
|
||||
}
|
||||
}
|
||||
gst_buffer_unmap (buf, bdata, bsize);
|
||||
gst_buffer_unmap (buf, &map);
|
||||
gst_byte_writer_free (writer);
|
||||
|
||||
if (!writer_status) {
|
||||
|
@ -715,9 +710,9 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
|
|||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_jif_mux_chain (GstPad * pad, GstBuffer * buf)
|
||||
gst_jif_mux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
||||
{
|
||||
GstJifMux *self = GST_JIF_MUX (GST_PAD_PARENT (pad));
|
||||
GstJifMux *self = GST_JIF_MUX (parent);
|
||||
GstFlowReturn fret = GST_FLOW_OK;
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -121,10 +121,12 @@ struct _GstJpegParsePrivate
|
|||
|
||||
static void gst_jpeg_parse_dispose (GObject * object);
|
||||
|
||||
static GstFlowReturn gst_jpeg_parse_chain (GstPad * pad, GstBuffer * buffer);
|
||||
static gboolean gst_jpeg_parse_sink_setcaps (GstPad * pad, GstCaps * caps);
|
||||
static gboolean gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event);
|
||||
static GstCaps *gst_jpeg_parse_src_getcaps (GstPad * pad, GstCaps * filter);
|
||||
static GstFlowReturn gst_jpeg_parse_chain (GstPad * pad, GstObject * parent,
|
||||
GstBuffer * buffer);
|
||||
static gboolean gst_jpeg_parse_sink_setcaps (GstJpegParse * parse,
|
||||
GstCaps * caps);
|
||||
static gboolean gst_jpeg_parse_sink_event (GstPad * pad, GstObject * parent,
|
||||
GstEvent * event);
|
||||
static GstStateChangeReturn gst_jpeg_parse_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
|
||||
|
@ -180,8 +182,7 @@ gst_jpeg_parse_init (GstJpegParse * parse)
|
|||
parse->priv->srcpad =
|
||||
gst_pad_new_from_static_template (&gst_jpeg_parse_src_pad_template,
|
||||
"src");
|
||||
gst_pad_set_getcaps_function (parse->priv->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_jpeg_parse_src_getcaps));
|
||||
gst_pad_use_fixed_caps (parse->priv->srcpad);
|
||||
gst_element_add_pad (GST_ELEMENT (parse), parse->priv->srcpad);
|
||||
|
||||
parse->priv->next_ts = GST_CLOCK_TIME_NONE;
|
||||
|
@ -204,9 +205,8 @@ gst_jpeg_parse_dispose (GObject * object)
|
|||
|
||||
|
||||
static gboolean
|
||||
gst_jpeg_parse_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||
gst_jpeg_parse_sink_setcaps (GstJpegParse * parse, GstCaps * caps)
|
||||
{
|
||||
GstJpegParse *parse = GST_JPEG_PARSE (GST_OBJECT_PARENT (pad));
|
||||
GstStructure *s = gst_caps_get_structure (caps, 0);
|
||||
const GValue *framerate;
|
||||
|
||||
|
@ -225,19 +225,6 @@ gst_jpeg_parse_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
gst_jpeg_parse_src_getcaps (GstPad * pad, GstCaps * filter)
|
||||
{
|
||||
GstCaps *result;
|
||||
|
||||
if ((result = gst_pad_get_current_caps (pad))) {
|
||||
GST_DEBUG_OBJECT (pad, "using pad caps %" GST_PTR_FORMAT, result);
|
||||
} else {
|
||||
result = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad)));
|
||||
GST_DEBUG_OBJECT (pad, "using pad template caps %" GST_PTR_FORMAT, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* gst_jpeg_parse_skip_to_jpeg_header:
|
||||
|
@ -508,8 +495,7 @@ gst_jpeg_parse_remove_marker (GstJpegParse * parse,
|
|||
{
|
||||
guint16 size = 0;
|
||||
guint pos = gst_byte_reader_get_pos (reader);
|
||||
guint8 *data;
|
||||
gsize bsize;
|
||||
GstMapInfo map;
|
||||
|
||||
if (!gst_byte_reader_peek_uint16_be (reader, &size))
|
||||
return FALSE;
|
||||
|
@ -518,9 +504,10 @@ gst_jpeg_parse_remove_marker (GstJpegParse * parse,
|
|||
|
||||
GST_LOG_OBJECT (parse, "unhandled marker %x removing %u bytes", marker, size);
|
||||
|
||||
data = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READWRITE);
|
||||
memmove (&data[pos], &data[pos + size], bsize - (pos + size));
|
||||
gst_buffer_unmap (buffer, data, bsize - size);
|
||||
gst_buffer_map (buffer, &map, GST_MAP_READWRITE);
|
||||
memmove (&map.data[pos], &map.data[pos + size], map.size - (pos + size));
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
|
||||
|
||||
if (!gst_byte_reader_set_pos (reader, pos - size))
|
||||
return FALSE;
|
||||
|
@ -565,7 +552,7 @@ static inline GstTagList *
|
|||
get_tag_list (GstJpegParse * parse)
|
||||
{
|
||||
if (!parse->priv->tags)
|
||||
parse->priv->tags = gst_tag_list_new ();
|
||||
parse->priv->tags = gst_tag_list_new_empty ();
|
||||
return parse->priv->tags;
|
||||
}
|
||||
|
||||
|
@ -576,7 +563,8 @@ extract_and_queue_tags (GstJpegParse * parse, guint size, guint8 * data,
|
|||
GstTagList *tags;
|
||||
GstBuffer *buf;
|
||||
|
||||
buf = gst_buffer_new_wrapped_full (data, NULL, 0, size);
|
||||
buf = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, data, size, 0,
|
||||
size, NULL, NULL);
|
||||
|
||||
tags = tag_func (buf);
|
||||
gst_buffer_unref (buf);
|
||||
|
@ -695,11 +683,10 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer)
|
|||
GstByteReader reader;
|
||||
guint8 marker = 0;
|
||||
gboolean foundSOF = FALSE;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo map;
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
gst_byte_reader_init (&reader, data, size);
|
||||
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||
gst_byte_reader_init (&reader, map.data, map.size);
|
||||
|
||||
if (!gst_byte_reader_peek_uint8 (&reader, &marker))
|
||||
goto error;
|
||||
|
@ -769,7 +756,7 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer)
|
|||
goto error;
|
||||
}
|
||||
done:
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
|
||||
return foundSOF;
|
||||
|
||||
|
@ -779,7 +766,7 @@ error:
|
|||
GST_WARNING_OBJECT (parse,
|
||||
"Error parsing image header (need more than %u bytes available)",
|
||||
gst_byte_reader_get_remaining (&reader));
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
return FALSE;
|
||||
}
|
||||
unhandled:
|
||||
|
@ -787,7 +774,7 @@ unhandled:
|
|||
GST_WARNING_OBJECT (parse, "unhandled marker %x, leaving", marker);
|
||||
/* Not SOF or SOI. Must not be a JPEG file (or file pointer
|
||||
* is placed wrong). In either case, it's an error. */
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -876,8 +863,8 @@ gst_jpeg_parse_push_buffer (GstJpegParse * parse, guint len)
|
|||
if (parse->priv->tags) {
|
||||
GST_DEBUG_OBJECT (parse, "Pushing tags: %" GST_PTR_FORMAT,
|
||||
parse->priv->tags);
|
||||
gst_element_found_tags_for_pad (GST_ELEMENT_CAST (parse),
|
||||
parse->priv->srcpad, parse->priv->tags);
|
||||
gst_pad_push_event (parse->priv->srcpad,
|
||||
gst_event_new_tag (parse->priv->tags));
|
||||
parse->priv->tags = NULL;
|
||||
}
|
||||
|
||||
|
@ -910,16 +897,14 @@ gst_jpeg_parse_push_buffer (GstJpegParse * parse, guint len)
|
|||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_jpeg_parse_chain (GstPad * pad, GstBuffer * buf)
|
||||
gst_jpeg_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
||||
{
|
||||
GstJpegParse *parse;
|
||||
GstJpegParse *parse = GST_JPEG_PARSE (parent);
|
||||
gint len;
|
||||
GstClockTime timestamp, duration;
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
|
||||
parse = GST_JPEG_PARSE (GST_PAD_PARENT (pad));
|
||||
|
||||
timestamp = GST_BUFFER_TIMESTAMP (buf);
|
||||
timestamp = GST_BUFFER_PTS (buf);
|
||||
duration = GST_BUFFER_DURATION (buf);
|
||||
|
||||
gst_adapter_push (parse->priv->adapter, buf);
|
||||
|
@ -951,9 +936,9 @@ gst_jpeg_parse_chain (GstPad * pad, GstBuffer * buf)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
|
||||
gst_jpeg_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||
{
|
||||
GstJpegParse *parse;
|
||||
GstJpegParse *parse = GST_JPEG_PARSE (parent);
|
||||
gboolean res = TRUE;
|
||||
|
||||
parse = GST_JPEG_PARSE (gst_pad_get_parent (pad));
|
||||
|
@ -966,7 +951,7 @@ gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
|
|||
GstCaps *caps;
|
||||
|
||||
gst_event_parse_caps (event, &caps);
|
||||
res = gst_jpeg_parse_sink_setcaps (pad, caps);
|
||||
res = gst_jpeg_parse_sink_setcaps (parse, caps);
|
||||
gst_event_unref (event);
|
||||
break;
|
||||
}
|
||||
|
@ -995,7 +980,7 @@ gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
|
|||
break;
|
||||
case GST_EVENT_TAG:{
|
||||
if (!parse->priv->new_segment)
|
||||
res = gst_pad_event_default (pad, event);
|
||||
res = gst_pad_event_default (pad, parent, event);
|
||||
else {
|
||||
GstTagList *taglist = NULL;
|
||||
|
||||
|
@ -1009,7 +994,7 @@ gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
|
|||
break;
|
||||
}
|
||||
default:
|
||||
res = gst_pad_event_default (pad, event);
|
||||
res = gst_pad_event_default (pad, parent, event);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -308,8 +308,8 @@ make_my_output_buffer (GstBuffer * buffer_in)
|
|||
GstBuffer *buffer;
|
||||
GstMapInfo map;
|
||||
|
||||
buffer = gst_buffer_new ();
|
||||
gst_buffer_map (buffer_in, &map, GST_MAP_READ);
|
||||
buffer = gst_buffer_new_and_alloc (map.size);
|
||||
gst_buffer_fill (buffer, 0, map.data, map.size);
|
||||
gst_buffer_unmap (buffer_in, &map);
|
||||
|
||||
|
|
Loading…
Reference in a new issue