jpegparse: Finish port to 1.0 API

This commit is contained in:
Olivier Crête 2012-09-11 19:36:24 -04:00
parent c2c6ef1697
commit 1826c126bf
4 changed files with 64 additions and 84 deletions

View file

@ -314,7 +314,7 @@ GST_PLUGINS_NONPORTED=" aiff \
cdxaparse \ cdxaparse \
dccp faceoverlay \ dccp faceoverlay \
fieldanalysis freeverb freeze frei0r \ fieldanalysis freeverb freeze frei0r \
hdvparse inter ivfparse jpegformat jp2kdecimator \ hdvparse inter ivfparse jp2kdecimator \
kate liveadder librfb \ kate liveadder librfb \
mpegpsmux mve mxf mythtv nsf nuvdemux \ mpegpsmux mve mxf mythtv nsf nuvdemux \
patchdetect pnm real \ patchdetect pnm real \

View file

@ -108,9 +108,11 @@ struct _GstJifMuxPrivate
static void gst_jif_mux_finalize (GObject * object); static void gst_jif_mux_finalize (GObject * object);
static void gst_jif_mux_reset (GstJifMux * self); 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_setcaps (GstJifMux * self, GstCaps * caps);
static gboolean gst_jif_mux_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_jif_mux_sink_event (GstPad * pad, GstObject * parent,
static GstFlowReturn gst_jif_mux_chain (GstPad * pad, GstBuffer * buffer); GstEvent * event);
static GstFlowReturn gst_jif_mux_chain (GstPad * pad, GstObject * parent,
GstBuffer * buffer);
static GstStateChangeReturn gst_jif_mux_change_state (GstElement * element, static GstStateChangeReturn gst_jif_mux_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
@ -180,15 +182,14 @@ gst_jif_mux_finalize (GObject * object)
} }
static gboolean 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); GstStructure *s = gst_caps_get_structure (caps, 0);
const gchar *variant; const gchar *variant;
/* should be {combined (default), EXIF, JFIF} */ /* should be {combined (default), EXIF, JFIF} */
if ((variant = gst_structure_get_string (s, "variant")) != NULL) { 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 ? */ /* 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 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; gboolean ret;
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
@ -207,7 +208,7 @@ gst_jif_mux_sink_event (GstPad * pad, GstEvent * event)
GstCaps *caps; GstCaps *caps;
gst_event_parse_caps (event, &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); gst_event_unref (event);
break; break;
} }
@ -220,11 +221,11 @@ gst_jif_mux_sink_event (GstPad * pad, GstEvent * event)
gst_tag_setter_merge_tags (setter, list, mode); gst_tag_setter_merge_tags (setter, list, mode);
ret = gst_pad_event_default (pad, event); ret = gst_pad_event_default (pad, parent, event);
break; break;
} }
default: default:
ret = gst_pad_event_default (pad, event); ret = gst_pad_event_default (pad, parent, event);
break; break;
} }
return ret; return ret;
@ -275,13 +276,12 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
guint8 marker = 0; guint8 marker = 0;
guint16 size = 0; guint16 size = 0;
const guint8 *data = NULL; const guint8 *data = NULL;
guint8 *bdata; GstMapInfo map;
gsize bsize;
bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ); gst_buffer_map (buf, &map, GST_MAP_READ);
gst_byte_reader_init (&reader, bdata, bsize); 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)) if (!gst_byte_reader_peek_uint8 (&reader, &marker))
goto error; goto error;
@ -329,23 +329,19 @@ gst_jif_mux_parse_image (GstJifMux * self, GstBuffer * buf)
if (marker == SOS) { if (marker == SOS) {
gint eoi_pos = -1; gint eoi_pos = -1;
gint i; gint i;
guint8 *mdata;
gsize msize;
/* search the last 5 bytes for the EOI marker */ /* search the last 5 bytes for the EOI marker */
mdata = gst_buffer_map (buf, &msize, NULL, GST_MAP_READ); g_assert (map.size >= 5);
g_assert (msize >= 5);
for (i = 5; i >= 2; i--) { for (i = 5; i >= 2; i--) {
if (mdata[msize - i] == 0xFF && mdata[msize - i + 1] == EOI) { if (map.data[map.size - i] == 0xFF && map.data[map.size - i + 1] == EOI) {
eoi_pos = msize - i; eoi_pos = map.size - i;
break; break;
} }
} }
if (eoi_pos == -1) { if (eoi_pos == -1) {
GST_WARNING_OBJECT (self, "Couldn't find an EOI marker"); 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 */ /* remaining size except EOI is scan data */
self->priv->scan_size = eoi_pos - gst_byte_reader_get_pos (&reader); 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; goto error;
} }
GST_INFO_OBJECT (self, "done parsing at 0x%x / 0x%x", 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: done:
self->priv->markers = g_list_reverse (self->priv->markers); self->priv->markers = g_list_reverse (self->priv->markers);
gst_buffer_unmap (buf, bdata, bsize); gst_buffer_unmap (buf, &map);
return TRUE; return TRUE;
@ -374,7 +370,7 @@ error:
GST_WARNING_OBJECT (self, GST_WARNING_OBJECT (self,
"Error parsing image header (need more that %u bytes available)", "Error parsing image header (need more that %u bytes available)",
gst_byte_reader_get_remaining (&reader)); gst_byte_reader_get_remaining (&reader));
gst_buffer_unmap (buf, bdata, bsize); gst_buffer_unmap (buf, &map);
return FALSE; return FALSE;
} }
} }
@ -523,7 +519,7 @@ gst_jif_mux_mangle_markers (GstJifMux * self)
cleanup_tags = FALSE; cleanup_tags = FALSE;
} }
if (!tags) { if (!tags) {
tags = gst_tag_list_new (); tags = gst_tag_list_new_empty ();
cleanup_tags = TRUE; cleanup_tags = TRUE;
} }
@ -652,8 +648,7 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
GList *node; GList *node;
guint size = self->priv->scan_size; guint size = self->priv->scan_size;
gboolean writer_status = TRUE; gboolean writer_status = TRUE;
guint8 *bdata; GstMapInfo map;
gsize bsize;
/* iterate list and collect size */ /* iterate list and collect size */
for (node = self->priv->markers; node; node = g_list_next (node)) { 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); GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
/* memcopy markers */ /* memcopy markers */
bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_WRITE); gst_buffer_map (buf, &map, GST_MAP_WRITE);
writer = gst_byte_writer_new_with_data (bdata, bsize, TRUE); writer = gst_byte_writer_new_with_data (map.data, map.size, TRUE);
for (node = self->priv->markers; node && writer_status; for (node = self->priv->markers; node && writer_status;
node = g_list_next (node)) { node = g_list_next (node)) {
@ -701,7 +696,7 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
self->priv->scan_size); self->priv->scan_size);
} }
} }
gst_buffer_unmap (buf, bdata, bsize); gst_buffer_unmap (buf, &map);
gst_byte_writer_free (writer); gst_byte_writer_free (writer);
if (!writer_status) { if (!writer_status) {
@ -715,9 +710,9 @@ gst_jif_mux_recombine_image (GstJifMux * self, GstBuffer ** new_buf,
} }
static GstFlowReturn 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; GstFlowReturn fret = GST_FLOW_OK;
#if 0 #if 0

View file

@ -121,10 +121,12 @@ struct _GstJpegParsePrivate
static void gst_jpeg_parse_dispose (GObject * object); static void gst_jpeg_parse_dispose (GObject * object);
static GstFlowReturn gst_jpeg_parse_chain (GstPad * pad, GstBuffer * buffer); static GstFlowReturn gst_jpeg_parse_chain (GstPad * pad, GstObject * parent,
static gboolean gst_jpeg_parse_sink_setcaps (GstPad * pad, GstCaps * caps); GstBuffer * buffer);
static gboolean gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_jpeg_parse_sink_setcaps (GstJpegParse * parse,
static GstCaps *gst_jpeg_parse_src_getcaps (GstPad * pad, GstCaps * filter); GstCaps * caps);
static gboolean gst_jpeg_parse_sink_event (GstPad * pad, GstObject * parent,
GstEvent * event);
static GstStateChangeReturn gst_jpeg_parse_change_state (GstElement * element, static GstStateChangeReturn gst_jpeg_parse_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
@ -180,8 +182,7 @@ gst_jpeg_parse_init (GstJpegParse * parse)
parse->priv->srcpad = parse->priv->srcpad =
gst_pad_new_from_static_template (&gst_jpeg_parse_src_pad_template, gst_pad_new_from_static_template (&gst_jpeg_parse_src_pad_template,
"src"); "src");
gst_pad_set_getcaps_function (parse->priv->srcpad, gst_pad_use_fixed_caps (parse->priv->srcpad);
GST_DEBUG_FUNCPTR (gst_jpeg_parse_src_getcaps));
gst_element_add_pad (GST_ELEMENT (parse), parse->priv->srcpad); gst_element_add_pad (GST_ELEMENT (parse), parse->priv->srcpad);
parse->priv->next_ts = GST_CLOCK_TIME_NONE; parse->priv->next_ts = GST_CLOCK_TIME_NONE;
@ -204,9 +205,8 @@ gst_jpeg_parse_dispose (GObject * object)
static gboolean 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); GstStructure *s = gst_caps_get_structure (caps, 0);
const GValue *framerate; const GValue *framerate;
@ -225,19 +225,6 @@ gst_jpeg_parse_sink_setcaps (GstPad * pad, GstCaps * caps)
return TRUE; 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: * gst_jpeg_parse_skip_to_jpeg_header:
@ -508,8 +495,7 @@ gst_jpeg_parse_remove_marker (GstJpegParse * parse,
{ {
guint16 size = 0; guint16 size = 0;
guint pos = gst_byte_reader_get_pos (reader); guint pos = gst_byte_reader_get_pos (reader);
guint8 *data; GstMapInfo map;
gsize bsize;
if (!gst_byte_reader_peek_uint16_be (reader, &size)) if (!gst_byte_reader_peek_uint16_be (reader, &size))
return FALSE; 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); GST_LOG_OBJECT (parse, "unhandled marker %x removing %u bytes", marker, size);
data = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READWRITE); gst_buffer_map (buffer, &map, GST_MAP_READWRITE);
memmove (&data[pos], &data[pos + size], bsize - (pos + size)); memmove (&map.data[pos], &map.data[pos + size], map.size - (pos + size));
gst_buffer_unmap (buffer, data, bsize - size); gst_buffer_unmap (buffer, &map);
if (!gst_byte_reader_set_pos (reader, pos - size)) if (!gst_byte_reader_set_pos (reader, pos - size))
return FALSE; return FALSE;
@ -565,7 +552,7 @@ static inline GstTagList *
get_tag_list (GstJpegParse * parse) get_tag_list (GstJpegParse * parse)
{ {
if (!parse->priv->tags) if (!parse->priv->tags)
parse->priv->tags = gst_tag_list_new (); parse->priv->tags = gst_tag_list_new_empty ();
return parse->priv->tags; return parse->priv->tags;
} }
@ -576,7 +563,8 @@ extract_and_queue_tags (GstJpegParse * parse, guint size, guint8 * data,
GstTagList *tags; GstTagList *tags;
GstBuffer *buf; 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); tags = tag_func (buf);
gst_buffer_unref (buf); gst_buffer_unref (buf);
@ -695,11 +683,10 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer)
GstByteReader reader; GstByteReader reader;
guint8 marker = 0; guint8 marker = 0;
gboolean foundSOF = FALSE; gboolean foundSOF = FALSE;
guint8 *data; GstMapInfo map;
gsize size;
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); gst_buffer_map (buffer, &map, GST_MAP_READ);
gst_byte_reader_init (&reader, data, size); gst_byte_reader_init (&reader, map.data, map.size);
if (!gst_byte_reader_peek_uint8 (&reader, &marker)) if (!gst_byte_reader_peek_uint8 (&reader, &marker))
goto error; goto error;
@ -769,7 +756,7 @@ gst_jpeg_parse_read_header (GstJpegParse * parse, GstBuffer * buffer)
goto error; goto error;
} }
done: done:
gst_buffer_unmap (buffer, data, size); gst_buffer_unmap (buffer, &map);
return foundSOF; return foundSOF;
@ -779,7 +766,7 @@ error:
GST_WARNING_OBJECT (parse, GST_WARNING_OBJECT (parse,
"Error parsing image header (need more than %u bytes available)", "Error parsing image header (need more than %u bytes available)",
gst_byte_reader_get_remaining (&reader)); gst_byte_reader_get_remaining (&reader));
gst_buffer_unmap (buffer, data, size); gst_buffer_unmap (buffer, &map);
return FALSE; return FALSE;
} }
unhandled: unhandled:
@ -787,7 +774,7 @@ unhandled:
GST_WARNING_OBJECT (parse, "unhandled marker %x, leaving", marker); GST_WARNING_OBJECT (parse, "unhandled marker %x, leaving", marker);
/* Not SOF or SOI. Must not be a JPEG file (or file pointer /* Not SOF or SOI. Must not be a JPEG file (or file pointer
* is placed wrong). In either case, it's an error. */ * is placed wrong). In either case, it's an error. */
gst_buffer_unmap (buffer, data, size); gst_buffer_unmap (buffer, &map);
return FALSE; return FALSE;
} }
} }
@ -876,8 +863,8 @@ gst_jpeg_parse_push_buffer (GstJpegParse * parse, guint len)
if (parse->priv->tags) { if (parse->priv->tags) {
GST_DEBUG_OBJECT (parse, "Pushing tags: %" GST_PTR_FORMAT, GST_DEBUG_OBJECT (parse, "Pushing tags: %" GST_PTR_FORMAT,
parse->priv->tags); parse->priv->tags);
gst_element_found_tags_for_pad (GST_ELEMENT_CAST (parse), gst_pad_push_event (parse->priv->srcpad,
parse->priv->srcpad, parse->priv->tags); gst_event_new_tag (parse->priv->tags));
parse->priv->tags = NULL; parse->priv->tags = NULL;
} }
@ -910,16 +897,14 @@ gst_jpeg_parse_push_buffer (GstJpegParse * parse, guint len)
} }
static GstFlowReturn 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; gint len;
GstClockTime timestamp, duration; GstClockTime timestamp, duration;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
parse = GST_JPEG_PARSE (GST_PAD_PARENT (pad)); timestamp = GST_BUFFER_PTS (buf);
timestamp = GST_BUFFER_TIMESTAMP (buf);
duration = GST_BUFFER_DURATION (buf); duration = GST_BUFFER_DURATION (buf);
gst_adapter_push (parse->priv->adapter, buf); gst_adapter_push (parse->priv->adapter, buf);
@ -951,9 +936,9 @@ gst_jpeg_parse_chain (GstPad * pad, GstBuffer * buf)
} }
static gboolean 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; gboolean res = TRUE;
parse = GST_JPEG_PARSE (gst_pad_get_parent (pad)); parse = GST_JPEG_PARSE (gst_pad_get_parent (pad));
@ -966,7 +951,7 @@ gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
GstCaps *caps; GstCaps *caps;
gst_event_parse_caps (event, &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); gst_event_unref (event);
break; break;
} }
@ -995,7 +980,7 @@ gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
break; break;
case GST_EVENT_TAG:{ case GST_EVENT_TAG:{
if (!parse->priv->new_segment) if (!parse->priv->new_segment)
res = gst_pad_event_default (pad, event); res = gst_pad_event_default (pad, parent, event);
else { else {
GstTagList *taglist = NULL; GstTagList *taglist = NULL;
@ -1009,7 +994,7 @@ gst_jpeg_parse_sink_event (GstPad * pad, GstEvent * event)
break; break;
} }
default: default:
res = gst_pad_event_default (pad, event); res = gst_pad_event_default (pad, parent, event);
break; break;
} }

View file

@ -308,8 +308,8 @@ make_my_output_buffer (GstBuffer * buffer_in)
GstBuffer *buffer; GstBuffer *buffer;
GstMapInfo map; GstMapInfo map;
buffer = gst_buffer_new ();
gst_buffer_map (buffer_in, &map, GST_MAP_READ); 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_fill (buffer, 0, map.data, map.size);
gst_buffer_unmap (buffer_in, &map); gst_buffer_unmap (buffer_in, &map);