mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-02 14:20:06 +00:00
Fixed get_range bug when injecting and stripping. And mux is almost done now.
Original commit message from CVS: Fixed get_range bug when injecting and stripping. And mux is almost done now.
This commit is contained in:
parent
aedf92f474
commit
794ad7ca1b
17 changed files with 1193 additions and 279 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
2007-11-30 Edgard Lima <edgard.lima@indt.org.br>
|
||||
|
||||
* ext/metadata/Makefile.am:
|
||||
* ext/metadata/gstmetadatamux.c:
|
||||
* ext/metadata/gstmetadatamux.h:
|
||||
* ext/metadata/gstmetadataparse.c:
|
||||
* ext/metadata/metadata.c:
|
||||
* ext/metadata/metadata.h:
|
||||
* ext/metadata/metadatamuxjpeg.c:
|
||||
* ext/metadata/metadatamuxjpeg.h:
|
||||
* ext/metadata/metadatamuxpng.c:
|
||||
* ext/metadata/metadatamuxpng.h:
|
||||
* ext/metadata/metadataparsejpeg.c:
|
||||
* ext/metadata/metadataparsejpeg.h:
|
||||
* ext/metadata/metadataparsepng.c:
|
||||
* ext/metadata/metadataparsepng.h:
|
||||
* ext/metadata/metadatatypes.c:
|
||||
* ext/metadata/metadatatypes.h:
|
||||
Fixed get_range bug when injecting and stripping. And mux is almost
|
||||
done now.
|
||||
|
||||
2007-11-30 Thijs Vermeir <thijsvermeir@gmail.com>
|
||||
|
||||
* gst/librfb/rfbdecoder.c:
|
||||
|
|
|
@ -4,7 +4,9 @@ libgstmetadata_la_SOURCES = gstmetadata.c \
|
|||
gstmetadataparse.c \
|
||||
metadata.c \
|
||||
metadataparsejpeg.c \
|
||||
metadatamuxjpeg.c \
|
||||
metadataparsepng.c \
|
||||
metadatamuxpng.c \
|
||||
metadataexif.c \
|
||||
metadataiptc.c \
|
||||
metadataxmp.c \
|
||||
|
@ -20,7 +22,9 @@ libgstmetadata_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
|||
noinst_HEADERS = gstmetadataparse.h \
|
||||
metadata.h \
|
||||
metadataparsejpeg.h \
|
||||
metadatamuxjpeg.h \
|
||||
metadataparsepng.h \
|
||||
metadatamuxpng.h \
|
||||
metadataexif.h \
|
||||
metadataiptc.h \
|
||||
metadataxmp.h \
|
||||
|
|
|
@ -172,6 +172,8 @@ static const GstQueryType *gst_metadata_mux_get_query_types (GstPad * pad);
|
|||
|
||||
static gboolean gst_metadata_mux_src_query (GstPad * pad, GstQuery * query);
|
||||
|
||||
static gboolean gst_metadata_mux_calculate_offsets (GstMetadataMux * filter);
|
||||
|
||||
static void
|
||||
gst_metadata_mux_base_init (gpointer gclass)
|
||||
{
|
||||
|
@ -426,8 +428,10 @@ gst_metadata_mux_src_event (GstPad * pad, GstEvent * event)
|
|||
gint64 stop;
|
||||
|
||||
/* we don't know where are the chunks to be stripped before mux */
|
||||
if (filter->state != MT_STATE_MUXED)
|
||||
goto done;
|
||||
if (filter->need_calculate_offset) {
|
||||
if (!gst_metadata_mux_calculate_offsets (filter))
|
||||
goto done;
|
||||
}
|
||||
|
||||
gst_event_parse_seek (event, &rate, &format, &flags,
|
||||
&start_type, &start, &stop_type, &stop);
|
||||
|
@ -583,7 +587,7 @@ gst_metadata_mux_dispose_members (GstMetadataMux * filter)
|
|||
static void
|
||||
gst_metadata_mux_init_members (GstMetadataMux * filter)
|
||||
{
|
||||
filter->need_send_tag = FALSE;
|
||||
filter->need_calculate_offset = FALSE;
|
||||
filter->exif = TRUE;
|
||||
filter->iptc = FALSE;
|
||||
filter->xmp = FALSE;
|
||||
|
@ -748,6 +752,38 @@ gst_metadata_mux_get_type_name (int img_type)
|
|||
return type_name;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_metadata_update_segment (GstMetadataMux * filter, GstAdapter * adapter,
|
||||
MetadataChunkType type)
|
||||
{
|
||||
int i;
|
||||
MetadataChunk *inject = filter->mux_data.inject_chunks.chunk;
|
||||
const gsize inject_len = filter->mux_data.inject_chunks.len;
|
||||
guint32 size;
|
||||
|
||||
if (adapter == NULL)
|
||||
goto done;
|
||||
|
||||
size = gst_adapter_available (adapter);
|
||||
|
||||
if (size == 0)
|
||||
goto done;
|
||||
|
||||
/* calculate the new position off injected chunks */
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
if (inject[i].type == type) {
|
||||
inject[i].size = size;
|
||||
inject[i].data = (guint8 *) gst_adapter_peek (adapter, inject[i].size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gst_metadata_create_chunks_from_tags (GstMetadataMux * filter)
|
||||
{
|
||||
|
@ -756,33 +792,29 @@ gst_metadata_create_chunks_from_tags (GstMetadataMux * filter)
|
|||
GstTagList *taglist;
|
||||
GstEvent *event;
|
||||
|
||||
if (META_DATA_OPTION (filter->mux_data) & META_OPT_EXIF)
|
||||
if (META_DATA_OPTION (filter->mux_data) & META_OPT_EXIF) {
|
||||
metadatamux_exif_create_chunk_from_tag_list (&filter->mux_data.exif_adapter,
|
||||
filter->taglist);
|
||||
|
||||
if (META_DATA_OPTION (filter->mux_data) & META_OPT_IPTC)
|
||||
metadatamux_iptc_create_chunk_from_tag_list (&filter->mux_data.iptc_adapter,
|
||||
filter->taglist);
|
||||
|
||||
if (META_DATA_OPTION (filter->mux_data) & META_OPT_XMP)
|
||||
metadatamux_xmp_create_chunk_from_tag_list (&filter->mux_data.exif_adapter,
|
||||
filter->taglist);
|
||||
|
||||
|
||||
if (!gst_tag_list_is_empty (filter->taglist)) {
|
||||
|
||||
taglist = gst_tag_list_copy (filter->taglist);
|
||||
msg = gst_message_new_tag (GST_OBJECT (filter), taglist);
|
||||
gst_element_post_message (GST_ELEMENT (filter), msg);
|
||||
|
||||
taglist = gst_tag_list_copy (filter->taglist);
|
||||
event = gst_event_new_tag (taglist);
|
||||
gst_pad_push_event (filter->srcpad, event);
|
||||
gst_metadata_update_segment (filter, filter->mux_data.exif_adapter,
|
||||
MD_CHUNK_EXIF);
|
||||
}
|
||||
|
||||
if (META_DATA_OPTION (filter->mux_data) & META_OPT_IPTC) {
|
||||
metadatamux_iptc_create_chunk_from_tag_list (&filter->mux_data.iptc_adapter,
|
||||
filter->taglist);
|
||||
gst_metadata_update_segment (filter, filter->mux_data.iptc_adapter,
|
||||
MD_CHUNK_IPTC);
|
||||
}
|
||||
|
||||
if (META_DATA_OPTION (filter->mux_data) & META_OPT_XMP) {
|
||||
metadatamux_xmp_create_chunk_from_tag_list (&filter->mux_data.xmp_adapter,
|
||||
filter->taglist);
|
||||
gst_metadata_update_segment (filter, filter->mux_data.xmp_adapter,
|
||||
MD_CHUNK_XMP);
|
||||
}
|
||||
|
||||
metadata_chunk_array_remove_zero_size (&filter->mux_data.inject_chunks);
|
||||
|
||||
filter->need_send_tag = FALSE;
|
||||
}
|
||||
|
||||
static const GstQueryType *
|
||||
|
@ -815,8 +847,10 @@ gst_metadata_mux_src_query (GstPad * pad, GstQuery * query)
|
|||
}
|
||||
break;
|
||||
case GST_QUERY_DURATION:
|
||||
if (filter->state != MT_STATE_MUXED)
|
||||
goto done;
|
||||
if (filter->need_calculate_offset) {
|
||||
if (!gst_metadata_mux_calculate_offsets (filter))
|
||||
goto done;
|
||||
}
|
||||
|
||||
gst_query_parse_duration (query, &format, NULL);
|
||||
|
||||
|
@ -850,6 +884,80 @@ done:
|
|||
* 1 -> need more data
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
gst_metadata_mux_calculate_offsets (GstMetadataMux * filter)
|
||||
{
|
||||
int i, j;
|
||||
guint32 append_size;
|
||||
guint32 bytes_striped, bytes_inject;
|
||||
MetadataChunk *strip = filter->mux_data.strip_chunks.chunk;
|
||||
MetadataChunk *inject = filter->mux_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->mux_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->mux_data.inject_chunks.len;
|
||||
|
||||
if (filter->state != MT_STATE_MUXED)
|
||||
return FALSE;
|
||||
|
||||
gst_metadata_create_chunks_from_tags (filter);
|
||||
|
||||
bytes_striped = 0;
|
||||
bytes_inject = 0;
|
||||
|
||||
/* calculate the new position off injected chunks */
|
||||
j = 0;
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
for (; j < strip_len; ++j) {
|
||||
if (strip[j].offset_orig >= inject[i].offset_orig) {
|
||||
break;
|
||||
}
|
||||
bytes_striped += strip[j].size;
|
||||
}
|
||||
inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject;
|
||||
bytes_inject += inject[i].size;
|
||||
}
|
||||
|
||||
/* calculate append (doesnt make much sense, but, anyway..) */
|
||||
append_size = 0;
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig)
|
||||
append_size += inject[i].size;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (append_size) {
|
||||
guint8 *data;
|
||||
|
||||
filter->append_buffer = gst_buffer_new_and_alloc (append_size);
|
||||
GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY);
|
||||
data = GST_BUFFER_DATA (filter->append_buffer);
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig) {
|
||||
memcpy (data, inject[i].data, inject[i].size);
|
||||
data += inject[i].size;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metadata_lazy_update (&filter->mux_data);
|
||||
|
||||
if (filter->duration_orig) {
|
||||
filter->duration = filter->duration_orig;
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
filter->duration += inject[i].size;
|
||||
}
|
||||
for (i = 0; i < strip_len; ++i) {
|
||||
filter->duration -= strip[i].size;
|
||||
}
|
||||
}
|
||||
|
||||
filter->need_calculate_offset = FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
gst_metadata_mux_mux (GstMetadataMux * filter, const guint8 * buf, guint32 size)
|
||||
{
|
||||
|
@ -872,56 +980,9 @@ gst_metadata_mux_mux (GstMetadataMux * filter, const guint8 * buf, guint32 size)
|
|||
} else if (ret > 0) {
|
||||
filter->need_more_data = TRUE;
|
||||
} else {
|
||||
int i, j;
|
||||
guint32 append_size;
|
||||
guint32 bytes_striped, bytes_inject;
|
||||
MetadataChunk *strip = filter->mux_data.strip_chunks.chunk;
|
||||
MetadataChunk *inject = filter->mux_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->mux_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->mux_data.inject_chunks.len;
|
||||
|
||||
bytes_striped = 0;
|
||||
bytes_inject = 0;
|
||||
|
||||
/* calculate the new position off injected chunks */
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
for (j = 0; j < strip_len; ++i) {
|
||||
if (strip[j].offset_orig >= inject[i].offset_orig) {
|
||||
break;
|
||||
}
|
||||
inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject;
|
||||
bytes_striped += strip[j].size;
|
||||
}
|
||||
bytes_inject += inject[i].size;
|
||||
}
|
||||
|
||||
/* calculate append (doesnt make much sense, but, anyway..) */
|
||||
append_size = 0;
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig)
|
||||
append_size += inject[i].size;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (append_size) {
|
||||
guint8 *data;
|
||||
|
||||
filter->append_buffer = gst_buffer_new_and_alloc (append_size);
|
||||
GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY);
|
||||
data = GST_BUFFER_DATA (filter->append_buffer);
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig) {
|
||||
memcpy (data, inject[i].data, inject[i].size);
|
||||
data += inject[i].size;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filter->state = MT_STATE_MUXED;
|
||||
filter->need_more_data = FALSE;
|
||||
filter->need_send_tag = TRUE;
|
||||
filter->need_calculate_offset = TRUE;
|
||||
}
|
||||
|
||||
if (filter->img_type != META_DATA_IMG_TYPE (filter->mux_data)) {
|
||||
|
@ -1018,8 +1079,9 @@ gst_metadata_mux_chain (GstPad * pad, GstBuffer * buf)
|
|||
filter->adapter_holding = NULL;
|
||||
}
|
||||
|
||||
if (filter->need_send_tag) {
|
||||
gst_metadata_create_chunks_from_tags (filter);
|
||||
if (filter->need_calculate_offset) {
|
||||
if (!gst_metadata_mux_calculate_offsets (filter))
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (filter->offset_orig + GST_BUFFER_SIZE (buf) == filter->duration_orig)
|
||||
|
@ -1094,6 +1156,8 @@ gst_metadata_mux_pull_range_mux (GstMetadataMux * filter)
|
|||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
filter->duration_orig = duration;
|
||||
|
||||
if (format != GST_FORMAT_BYTES) {
|
||||
/* this should never happen, but try chain anyway */
|
||||
ret = TRUE;
|
||||
|
@ -1133,24 +1197,6 @@ gst_metadata_mux_pull_range_mux (GstMetadataMux * filter)
|
|||
|
||||
} while (res > 0);
|
||||
|
||||
if (res == 0) {
|
||||
int i;
|
||||
MetadataChunk *strip = filter->mux_data.strip_chunks.chunk;
|
||||
MetadataChunk *inject = filter->mux_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->mux_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->mux_data.inject_chunks.len;
|
||||
|
||||
filter->duration = duration;
|
||||
filter->duration_orig = duration;
|
||||
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
filter->duration += inject[i].size;
|
||||
}
|
||||
for (i = 0; i < strip_len; ++i) {
|
||||
filter->duration -= strip[i].size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
|
@ -1614,9 +1660,11 @@ gst_metadata_mux_get_range (GstPad * pad,
|
|||
|
||||
filter = GST_METADATA_MUX (GST_PAD_PARENT (pad));
|
||||
|
||||
if (filter->state != MT_STATE_MUXED) {
|
||||
ret = GST_FLOW_ERROR;
|
||||
goto done;
|
||||
if (filter->need_calculate_offset) {
|
||||
if (!gst_metadata_mux_calculate_offsets (filter)) {
|
||||
ret = GST_FLOW_ERROR;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset + size > filter->duration) {
|
||||
|
@ -1625,10 +1673,6 @@ gst_metadata_mux_get_range (GstPad * pad,
|
|||
|
||||
size_orig = size;
|
||||
|
||||
if (filter->need_send_tag) {
|
||||
gst_metadata_create_chunks_from_tags (filter);
|
||||
}
|
||||
|
||||
gst_metadata_mux_translate_pos_to_orig (filter, offset, &offset_orig,
|
||||
&prepend);
|
||||
|
||||
|
@ -1703,7 +1747,7 @@ gst_metadata_mux_change_state (GstElement * element, GstStateChange transition)
|
|||
gst_metadata_mux_init_members (filter);
|
||||
filter->adapter_parsing = gst_adapter_new ();
|
||||
filter->taglist = gst_tag_list_new ();
|
||||
metadata_init (&filter->mux_data);
|
||||
metadata_init (&filter->mux_data, FALSE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1727,7 +1771,7 @@ gst_metadata_mux_change_state (GstElement * element, GstStateChange transition)
|
|||
/* cleanup parser */
|
||||
/* FIXME: could be improved a bit to avoid mem allocation */
|
||||
metadata_dispose (&filter->mux_data);
|
||||
metadata_init (&filter->mux_data);
|
||||
metadata_init (&filter->mux_data, FALSE);
|
||||
}
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
|
|
|
@ -79,8 +79,6 @@ struct _GstMetadataMux
|
|||
gboolean iptc;
|
||||
gboolean xmp;
|
||||
|
||||
gboolean need_send_tag;
|
||||
|
||||
GstTagList *taglist;
|
||||
MetaData mux_data;
|
||||
GstAdapter *adapter_parsing;
|
||||
|
@ -101,7 +99,8 @@ struct _GstMetadataMux
|
|||
|
||||
gboolean need_more_data;
|
||||
|
||||
|
||||
gboolean need_send_tag; /* demux still need send tags */
|
||||
gboolean need_calculate_offset; /* mux need to calculate offsets of insert chunks */
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -870,6 +870,72 @@ done:
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
gst_metadata_parse_calculate_offsets (GstMetadataParse * filter)
|
||||
{
|
||||
int i, j;
|
||||
guint32 append_size;
|
||||
guint32 bytes_striped, bytes_inject;
|
||||
MetadataChunk *strip = filter->parse_data.strip_chunks.chunk;
|
||||
MetadataChunk *inject = filter->parse_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->parse_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->parse_data.inject_chunks.len;
|
||||
|
||||
bytes_striped = 0;
|
||||
bytes_inject = 0;
|
||||
|
||||
/* calculate the new position off injected chunks */
|
||||
j = 0;
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
for (; j < strip_len; ++j) {
|
||||
if (strip[j].offset_orig >= inject[i].offset_orig) {
|
||||
break;
|
||||
}
|
||||
bytes_striped += strip[j].size;
|
||||
}
|
||||
inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject;
|
||||
bytes_inject += inject[i].size;
|
||||
}
|
||||
|
||||
/* calculate append (doesnt make much sense, but, anyway..) */
|
||||
append_size = 0;
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig)
|
||||
append_size += inject[i].size;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (append_size) {
|
||||
guint8 *data;
|
||||
|
||||
filter->append_buffer = gst_buffer_new_and_alloc (append_size);
|
||||
GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY);
|
||||
data = GST_BUFFER_DATA (filter->append_buffer);
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig) {
|
||||
memcpy (data, inject[i].data, inject[i].size);
|
||||
data += inject[i].size;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* do nothing but just call for consistence */
|
||||
metadata_lazy_update (&filter->parse_data);
|
||||
|
||||
if (filter->duration_orig) {
|
||||
filter->duration = filter->duration_orig;
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
filter->duration += inject[i].size;
|
||||
}
|
||||
for (i = 0; i < strip_len; ++i) {
|
||||
filter->duration -= strip[i].size;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* return:
|
||||
* -1 -> error
|
||||
|
@ -900,52 +966,7 @@ gst_metadata_parse_parse (GstMetadataParse * filter, const guint8 * buf,
|
|||
} else if (ret > 0) {
|
||||
filter->need_more_data = TRUE;
|
||||
} else {
|
||||
int i, j;
|
||||
guint32 append_size;
|
||||
guint32 bytes_striped, bytes_inject;
|
||||
MetadataChunk *strip = filter->parse_data.strip_chunks.chunk;
|
||||
MetadataChunk *inject = filter->parse_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->parse_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->parse_data.inject_chunks.len;
|
||||
|
||||
bytes_striped = 0;
|
||||
bytes_inject = 0;
|
||||
|
||||
/* calculate the new position off injected chunks */
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
for (j = 0; j < strip_len; ++i) {
|
||||
if (strip[j].offset_orig >= inject[i].offset_orig) {
|
||||
break;
|
||||
}
|
||||
inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject;
|
||||
bytes_striped += strip[j].size;
|
||||
}
|
||||
bytes_inject += inject[i].size;
|
||||
}
|
||||
|
||||
/* calculate append (doesnt make much sense, but, anyway..) */
|
||||
append_size = 0;
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig)
|
||||
append_size += inject[i].size;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (append_size) {
|
||||
guint8 *data;
|
||||
|
||||
filter->append_buffer = gst_buffer_new_and_alloc (append_size);
|
||||
GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY);
|
||||
data = GST_BUFFER_DATA (filter->append_buffer);
|
||||
for (i = inject_len - 1; i >= 0; --i) {
|
||||
if (inject[i].offset_orig == filter->duration_orig) {
|
||||
memcpy (data, inject[i].data, inject[i].size);
|
||||
data += inject[i].size;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
gst_metadata_parse_calculate_offsets (filter);
|
||||
|
||||
filter->state = MT_STATE_PARSED;
|
||||
filter->need_more_data = FALSE;
|
||||
|
@ -1122,6 +1143,7 @@ gst_metadata_parse_pull_range_parse (GstMetadataParse * filter)
|
|||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
filter->duration_orig = duration;
|
||||
if (format != GST_FORMAT_BYTES) {
|
||||
/* this should never happen, but try chain anyway */
|
||||
ret = TRUE;
|
||||
|
@ -1161,25 +1183,6 @@ gst_metadata_parse_pull_range_parse (GstMetadataParse * filter)
|
|||
|
||||
} while (res > 0);
|
||||
|
||||
if (res == 0) {
|
||||
int i;
|
||||
MetadataChunk *strip = filter->parse_data.strip_chunks.chunk;
|
||||
MetadataChunk *inject = filter->parse_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->parse_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->parse_data.inject_chunks.len;
|
||||
|
||||
filter->duration = duration;
|
||||
filter->duration_orig = duration;
|
||||
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
filter->duration += inject[i].size;
|
||||
}
|
||||
for (i = 0; i < strip_len; ++i) {
|
||||
filter->duration -= strip[i].size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
@ -1732,7 +1735,7 @@ gst_metadata_parse_change_state (GstElement * element,
|
|||
gst_metadata_parse_init_members (filter);
|
||||
filter->adapter_parsing = gst_adapter_new ();
|
||||
filter->taglist = gst_tag_list_new ();
|
||||
metadata_init (&filter->parse_data);
|
||||
metadata_init (&filter->parse_data, TRUE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1756,7 +1759,7 @@ gst_metadata_parse_change_state (GstElement * element,
|
|||
/* cleanup parser */
|
||||
/* FIXME: could be improved a bit to avoid mem allocation */
|
||||
metadata_dispose (&filter->parse_data);
|
||||
metadata_init (&filter->parse_data);
|
||||
metadata_init (&filter->parse_data, TRUE);
|
||||
}
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
|
|
|
@ -58,7 +58,7 @@ metadata_parse_none (MetaData * meta_data, const guint8 * buf,
|
|||
*/
|
||||
|
||||
void
|
||||
metadata_init (MetaData * meta_data)
|
||||
metadata_init (MetaData * meta_data, gboolean parse)
|
||||
{
|
||||
meta_data->state = STATE_NULL;
|
||||
meta_data->img_type = IMG_NONE;
|
||||
|
@ -67,8 +67,16 @@ metadata_init (MetaData * meta_data)
|
|||
meta_data->exif_adapter = NULL;
|
||||
meta_data->iptc_adapter = NULL;
|
||||
meta_data->xmp_adapter = NULL;
|
||||
metadata_chunk_array_init (&meta_data->strip_chunks, 4);
|
||||
metadata_chunk_array_init (&meta_data->inject_chunks, 1);
|
||||
meta_data->parse = parse;
|
||||
|
||||
if (parse) {
|
||||
metadata_chunk_array_init (&meta_data->strip_chunks, 4);
|
||||
metadata_chunk_array_init (&meta_data->inject_chunks, 1);
|
||||
} else {
|
||||
metadata_chunk_array_init (&meta_data->strip_chunks, 1);
|
||||
metadata_chunk_array_init (&meta_data->inject_chunks, 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -99,16 +107,30 @@ metadata_parse (MetaData * meta_data, const guint8 * buf,
|
|||
|
||||
switch (meta_data->img_type) {
|
||||
case IMG_JPEG:
|
||||
ret =
|
||||
metadataparse_jpeg_parse (&meta_data->format_data.jpeg,
|
||||
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
|
||||
next_size);
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
ret =
|
||||
metadataparse_jpeg_parse (&meta_data->format_data.jpeg_parse,
|
||||
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
|
||||
next_size);
|
||||
else
|
||||
ret =
|
||||
metadatamux_jpeg_parse (&meta_data->format_data.jpeg_mux,
|
||||
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
|
||||
next_size);
|
||||
break;
|
||||
case IMG_PNG:
|
||||
ret =
|
||||
metadataparse_png_parse (&meta_data->format_data.png,
|
||||
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
|
||||
next_size);
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
ret =
|
||||
metadataparse_png_parse (&meta_data->format_data.png_parse,
|
||||
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
|
||||
next_size);
|
||||
/*
|
||||
else
|
||||
ret =
|
||||
metadatamux_png_parse (&meta_data->format_data.png_mux,
|
||||
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
|
||||
next_size);
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
/* unexpected */
|
||||
|
@ -135,10 +157,18 @@ metadata_dispose (MetaData * meta_data)
|
|||
|
||||
switch (meta_data->img_type) {
|
||||
case IMG_JPEG:
|
||||
metadataparse_jpeg_dispose (&meta_data->format_data.jpeg);
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
metadataparse_jpeg_dispose (&meta_data->format_data.jpeg_parse);
|
||||
else
|
||||
metadatamux_jpeg_dispose (&meta_data->format_data.jpeg_mux);
|
||||
break;
|
||||
case IMG_PNG:
|
||||
metadataparse_png_dispose (&meta_data->format_data.png);
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
metadataparse_png_dispose (&meta_data->format_data.png_parse);
|
||||
/*
|
||||
else
|
||||
metadatamux_png_dispose (&meta_data->format_data.png_mux);
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -195,8 +225,12 @@ metadata_parse_none (MetaData * meta_data, const guint8 * buf,
|
|||
xmp = &meta_data->xmp_adapter;
|
||||
|
||||
if (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF) {
|
||||
metadataparse_jpeg_init (&meta_data->format_data.jpeg, exif, iptc, xmp,
|
||||
&meta_data->strip_chunks, &meta_data->inject_chunks);
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
metadataparse_jpeg_init (&meta_data->format_data.jpeg_parse, exif, iptc,
|
||||
xmp, &meta_data->strip_chunks, &meta_data->inject_chunks);
|
||||
else
|
||||
metadatamux_jpeg_init (&meta_data->format_data.jpeg_mux, exif, iptc, xmp,
|
||||
&meta_data->strip_chunks, &meta_data->inject_chunks);
|
||||
ret = 0;
|
||||
meta_data->img_type = IMG_JPEG;
|
||||
goto done;
|
||||
|
@ -210,8 +244,14 @@ metadata_parse_none (MetaData * meta_data, const guint8 * buf,
|
|||
|
||||
if (buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4E && buf[3] == 0x47 &&
|
||||
buf[4] == 0x0D && buf[5] == 0x0A && buf[6] == 0x1A && buf[7] == 0x0A) {
|
||||
metadataparse_png_init (&meta_data->format_data.png, exif, iptc, xmp,
|
||||
&meta_data->strip_chunks, &meta_data->inject_chunks);
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
metadataparse_png_init (&meta_data->format_data.png_parse, exif, iptc,
|
||||
xmp, &meta_data->strip_chunks, &meta_data->inject_chunks);
|
||||
/*
|
||||
else
|
||||
metadatamux_png_init (&meta_data->format_data.png_mux, exif, iptc, xmp,
|
||||
&meta_data->strip_chunks, &meta_data->inject_chunks);
|
||||
*/
|
||||
ret = 0;
|
||||
meta_data->img_type = IMG_PNG;
|
||||
goto done;
|
||||
|
@ -221,3 +261,28 @@ done:
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
metadata_lazy_update (MetaData * meta_data)
|
||||
{
|
||||
switch (meta_data->img_type) {
|
||||
case IMG_JPEG:
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
metadataparse_jpeg_lazy_update (&meta_data->format_data.jpeg_parse);
|
||||
else
|
||||
metadatamux_jpeg_lazy_update (&meta_data->format_data.jpeg_mux);
|
||||
break;
|
||||
case IMG_PNG:
|
||||
if (G_LIKELY (meta_data->parse))
|
||||
metadataparse_png_lazy_update (&meta_data->format_data.png_parse);
|
||||
/*
|
||||
else
|
||||
metadatamux_png_lazy_update (&meta_data->format_data.png_mux);
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
/* unexpected */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,9 @@
|
|||
#include "metadatatypes.h"
|
||||
|
||||
#include "metadataparsejpeg.h"
|
||||
#include "metadatamuxjpeg.h"
|
||||
#include "metadataparsepng.h"
|
||||
#include "metadatamuxpng.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -82,8 +84,10 @@ typedef struct _tag_MetaData
|
|||
guint32 offset_orig; /* offset since begining of stream */
|
||||
union
|
||||
{
|
||||
JpegData jpeg;
|
||||
PngData png;
|
||||
JpegParseData jpeg_parse;
|
||||
JpegMuxData jpeg_mux;
|
||||
PngParseData png_parse;
|
||||
PngMuxData png_mux;
|
||||
} format_data;
|
||||
GstAdapter * exif_adapter;
|
||||
GstAdapter * iptc_adapter;
|
||||
|
@ -92,6 +96,8 @@ typedef struct _tag_MetaData
|
|||
MetadataChunkArray strip_chunks;
|
||||
MetadataChunkArray inject_chunks;
|
||||
|
||||
gboolean parse; /* true - parsing, false - muxing */
|
||||
|
||||
} MetaData;
|
||||
|
||||
#define META_DATA_IMG_TYPE(p) (p).img_type
|
||||
|
@ -99,7 +105,7 @@ typedef struct _tag_MetaData
|
|||
#define set_meta_option(p, m) do { (p).option = (p).option | (m); } while(FALSE)
|
||||
#define unset_meta_option(p, m) do { (p).option = (p).option & ~(m); } while(FALSE)
|
||||
|
||||
extern void metadata_init (MetaData * meta_data);
|
||||
extern void metadata_init (MetaData * meta_data, gboolean parse);
|
||||
|
||||
/*
|
||||
* offset: number of bytes that MUST be jumped after current "buf" pointer
|
||||
|
@ -112,10 +118,12 @@ extern void metadata_init (MetaData * meta_data);
|
|||
* 1 -> need more data
|
||||
*/
|
||||
extern int
|
||||
metadata_meta (MetaData * meta_data, const guint8 * buf,
|
||||
metadata_parse (MetaData * meta_data, const guint8 * buf,
|
||||
guint32 bufsize, guint32 * next_offset, guint32 * next_size);
|
||||
|
||||
|
||||
extern void metadata_lazy_update (MetaData * meta_data);
|
||||
|
||||
extern void metadata_dispose (MetaData * meta_data);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
272
ext/metadata/metadatamuxjpeg.c
Normal file
272
ext/metadata/metadatamuxjpeg.c
Normal file
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "metadatamuxjpeg.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <libiptcdata/iptc-jpeg.h>
|
||||
|
||||
static int
|
||||
metadatamux_jpeg_reading (JpegMuxData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
#define READ(buf, size) ( (size)--, *((buf)++) )
|
||||
|
||||
void
|
||||
metadatamux_jpeg_lazy_update (JpegMuxData * jpeg_data)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
for (i = 0; i < jpeg_data->inject_chunks->len; ++i) {
|
||||
if (jpeg_data->inject_chunks->chunk[i].type == MD_CHUNK_EXIF &&
|
||||
jpeg_data->inject_chunks->chunk[i].size > 0) {
|
||||
/* zero size chunks should be removed before but we check anyway */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == jpeg_data->inject_chunks->len) {
|
||||
/* EXIF not injected so not strip JFIF anymore */
|
||||
metadata_chunk_array_clear (jpeg_data->strip_chunks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
metadatamux_jpeg_init (JpegMuxData * jpeg_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks)
|
||||
{
|
||||
jpeg_data->state = JPEG_MUX_NULL;
|
||||
|
||||
jpeg_data->strip_chunks = strip_chunks;
|
||||
jpeg_data->inject_chunks = inject_chunks;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
metadatamux_jpeg_dispose (JpegMuxData * jpeg_data)
|
||||
{
|
||||
jpeg_data->inject_chunks = NULL;
|
||||
jpeg_data->strip_chunks = NULL;
|
||||
|
||||
jpeg_data->state = JPEG_MUX_NULL;
|
||||
}
|
||||
|
||||
int
|
||||
metadatamux_jpeg_parse (JpegMuxData * jpeg_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start,
|
||||
guint32 * next_size)
|
||||
{
|
||||
|
||||
int ret = 0;
|
||||
guint8 mark[2] = { 0x00, 0x00 };
|
||||
const guint8 *step_buf = buf;
|
||||
|
||||
*next_start = buf;
|
||||
|
||||
if (jpeg_data->state == JPEG_MUX_NULL) {
|
||||
|
||||
if (*bufsize < 2) {
|
||||
*next_size = (buf - *next_start) + 2;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
mark[0] = READ (buf, *bufsize);
|
||||
mark[1] = READ (buf, *bufsize);
|
||||
|
||||
if (mark[0] != 0xFF || mark[1] != 0xD8) {
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
jpeg_data->state = JPEG_MUX_READING;
|
||||
|
||||
}
|
||||
|
||||
while (ret == 0) {
|
||||
switch (jpeg_data->state) {
|
||||
case JPEG_MUX_READING:
|
||||
ret =
|
||||
metadatamux_jpeg_reading (jpeg_data, &buf, bufsize,
|
||||
offset, step_buf, next_start, next_size);
|
||||
break;
|
||||
case JPEG_MUX_DONE:
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* look for markers */
|
||||
static int
|
||||
metadatamux_jpeg_reading (JpegMuxData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
|
||||
int ret = -1;
|
||||
guint8 mark[2] = { 0x00, 0x00 };
|
||||
guint16 chunk_size = 0;
|
||||
gint64 new_chunk_offset = 0;
|
||||
MetadataChunk chunk;
|
||||
gboolean jfif_found = FALSE;
|
||||
|
||||
static const char JfifHeader[] = "JFIF";
|
||||
static const unsigned char ExifHeader[] =
|
||||
{ 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 };
|
||||
static const char IptcHeader[] = "Photoshop 3.0";
|
||||
static const char XmpHeader[] = "http://ns.adobe.com/xap/1.0/";
|
||||
|
||||
*next_start = *buf;
|
||||
|
||||
if (*bufsize < 2) {
|
||||
*next_size = (*buf - *next_start) + 2;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
mark[0] = READ (*buf, *bufsize);
|
||||
mark[1] = READ (*buf, *bufsize);
|
||||
|
||||
if (mark[0] == 0xFF) {
|
||||
if (mark[1] == 0xD9) { /* end of image */
|
||||
ret = 0;
|
||||
jpeg_data->state = JPEG_MUX_DONE;
|
||||
goto done;
|
||||
} else if (mark[1] == 0xDA) { /* start of scan, lets not look behinf of this */
|
||||
ret = 0;
|
||||
jpeg_data->state = JPEG_MUX_DONE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (*bufsize < 2) {
|
||||
*next_size = (*buf - *next_start) + 2;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
chunk_size = READ (*buf, *bufsize) << 8;
|
||||
chunk_size += READ (*buf, *bufsize);
|
||||
|
||||
if (mark[1] == 0xE0) { /* may be JFIF */
|
||||
|
||||
if (chunk_size >= 16) {
|
||||
if (*bufsize < 14) {
|
||||
*next_size = (*buf - *next_start) + 14;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (0 == memcmp (JfifHeader, *buf, 5)) {
|
||||
jfif_found = TRUE;
|
||||
/* FIXME: should we fail if not find JFIF */
|
||||
/* Yes, I think so */
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new_chunk_offset = (*buf - step_buf) + offset - 4; /* maker + size */
|
||||
|
||||
/* EXIF will always be in the begining */
|
||||
|
||||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = new_chunk_offset;
|
||||
chunk.type = MD_CHUNK_EXIF;
|
||||
metadata_chunk_array_append_sorted (jpeg_data->inject_chunks, &chunk);
|
||||
|
||||
if (jfif_found) {
|
||||
/* remove JFIF chunk */
|
||||
/* this acation can be canceled with lazy update if no Exif is add */
|
||||
|
||||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = new_chunk_offset;
|
||||
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
||||
chunk.type = MD_CHUNK_UNKNOWN;
|
||||
|
||||
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks, &chunk);
|
||||
|
||||
new_chunk_offset = chunk.offset_orig + chunk.size;
|
||||
}
|
||||
|
||||
/* IPTC */
|
||||
|
||||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = new_chunk_offset;
|
||||
chunk.type = MD_CHUNK_IPTC;
|
||||
metadata_chunk_array_append_sorted (jpeg_data->inject_chunks, &chunk);
|
||||
|
||||
/* XMP */
|
||||
|
||||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = new_chunk_offset;
|
||||
chunk.type = MD_CHUNK_XMP;
|
||||
metadata_chunk_array_append_sorted (jpeg_data->inject_chunks, &chunk);
|
||||
|
||||
jpeg_data->state = JPEG_MUX_DONE;
|
||||
ret = 0;
|
||||
|
||||
} else {
|
||||
/* invalid JPEG chunk */
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
85
ext/metadata/metadatamuxjpeg.h
Normal file
85
ext/metadata/metadatamuxjpeg.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __METADATAMUX_JPEG_H__
|
||||
#define __METADATAMUX_JPEG_H__
|
||||
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#include "metadatatypes.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum _tag_JpegMuxState
|
||||
{
|
||||
JPEG_MUX_NULL,
|
||||
JPEG_MUX_READING,
|
||||
JPEG_MUX_DONE
|
||||
} JpegMuxState;
|
||||
|
||||
|
||||
typedef struct _tag_JpegMuxData
|
||||
{
|
||||
JpegMuxState state;
|
||||
|
||||
MetadataChunkArray * strip_chunks;
|
||||
MetadataChunkArray * inject_chunks;
|
||||
|
||||
} JpegMuxData;
|
||||
|
||||
|
||||
extern void
|
||||
metadatamux_jpeg_init (JpegMuxData * jpeg_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks);
|
||||
|
||||
extern void metadatamux_jpeg_dispose (JpegMuxData * jpeg_data);
|
||||
|
||||
extern void metadatamux_jpeg_lazy_update (JpegMuxData * jpeg_data);
|
||||
|
||||
int
|
||||
metadatamux_jpeg_parse (JpegMuxData * jpeg_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __METADATAMUX_JPEG_H__ */
|
273
ext/metadata/metadatamuxpng.c
Normal file
273
ext/metadata/metadatamuxpng.c
Normal file
|
@ -0,0 +1,273 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "metadatamuxpng.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static int
|
||||
metadatamux_png_reading (PngMuxData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadatamux_png_xmp (PngMuxData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadatamux_png_jump (PngMuxData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
#define READ(buf, size) ( (size)--, *((buf)++) )
|
||||
|
||||
void
|
||||
metadatamux_png_lazy_update (PngMuxData * jpeg_data)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
void
|
||||
metadatamux_png_init (PngMuxData * png_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks)
|
||||
{
|
||||
png_data->state = PNG_MUX_NULL;
|
||||
png_data->xmp_adapter = xmp_adpt;
|
||||
png_data->read = 0;
|
||||
|
||||
png_data->strip_chunks = strip_chunks;
|
||||
png_data->inject_chunks = inject_chunks;
|
||||
|
||||
metadataparse_xmp_init ();
|
||||
}
|
||||
|
||||
void
|
||||
metadatamux_png_dispose (PngMuxData * png_data)
|
||||
{
|
||||
metadataparse_xmp_dispose ();
|
||||
|
||||
png_data->xmp_adapter = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
metadatamux_png_parse (PngMuxData * png_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start,
|
||||
guint32 * next_size)
|
||||
{
|
||||
|
||||
int ret = 0;
|
||||
guint8 mark[8];
|
||||
const guint8 *step_buf = buf;
|
||||
|
||||
*next_start = buf;
|
||||
|
||||
if (png_data->state == PNG_MUX_NULL) {
|
||||
|
||||
if (*bufsize < 8) {
|
||||
*next_size = (buf - *next_start) + 8;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
mark[0] = READ (buf, *bufsize);
|
||||
mark[1] = READ (buf, *bufsize);
|
||||
mark[2] = READ (buf, *bufsize);
|
||||
mark[3] = READ (buf, *bufsize);
|
||||
mark[4] = READ (buf, *bufsize);
|
||||
mark[5] = READ (buf, *bufsize);
|
||||
mark[6] = READ (buf, *bufsize);
|
||||
mark[7] = READ (buf, *bufsize);
|
||||
|
||||
if (mark[0] != 0x89 || mark[1] != 0x50 || mark[2] != 0x4E || mark[3] != 0x47
|
||||
|| mark[4] != 0x0D || mark[5] != 0x0A || mark[6] != 0x1A
|
||||
|| mark[7] != 0x0A) {
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
png_data->state = PNG_MUX_READING;
|
||||
|
||||
}
|
||||
|
||||
/* JUST UNTIL NOT IMPLEMENTED */
|
||||
return 0;
|
||||
|
||||
while (ret == 0) {
|
||||
switch (png_data->state) {
|
||||
case PNG_MUX_READING:
|
||||
ret =
|
||||
metadatamux_png_reading (png_data, &buf, bufsize,
|
||||
offset, step_buf, next_start, next_size);
|
||||
break;
|
||||
case PNG_MUX_JUMPING:
|
||||
ret =
|
||||
metadatamux_png_jump (png_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case PNG_MUX_XMP:
|
||||
ret =
|
||||
metadatamux_png_xmp (png_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case PNG_MUX_DONE:
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* look for markers */
|
||||
static int
|
||||
metadatamux_png_reading (PngMuxData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
|
||||
int ret = -1;
|
||||
guint8 mark[4];
|
||||
guint32 chunk_size = 0;
|
||||
|
||||
static const char XmpHeader[] = "XML:com.adobe.xmp";
|
||||
|
||||
*next_start = *buf;
|
||||
|
||||
if (*bufsize < 8) {
|
||||
*next_size = (*buf - *next_start) + 8;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
chunk_size = READ (*buf, *bufsize) << 24;
|
||||
chunk_size += READ (*buf, *bufsize) << 16;
|
||||
chunk_size += READ (*buf, *bufsize) << 8;
|
||||
chunk_size += READ (*buf, *bufsize);
|
||||
|
||||
mark[0] = READ (*buf, *bufsize);
|
||||
mark[1] = READ (*buf, *bufsize);
|
||||
mark[2] = READ (*buf, *bufsize);
|
||||
mark[3] = READ (*buf, *bufsize);
|
||||
|
||||
if (mark[0] == 'I' && mark[1] == 'E' && mark[2] == 'N' && mark[3] == 'D') {
|
||||
ret = 0;
|
||||
png_data->state = PNG_MUX_DONE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (mark[0] == 'i' && mark[1] == 'T' && mark[2] == 'X' && mark[3] == 't') {
|
||||
if (chunk_size >= 22) { /* "XML:com.adobe.xmp" plus some flags */
|
||||
if (*bufsize < 22) {
|
||||
*next_size = (*buf - *next_start) + 22;
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (0 == memcmp (XmpHeader, *buf, 18)) {
|
||||
MetadataChunk chunk;
|
||||
|
||||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = (*buf - step_buf) + offset - 8; /* maker + size */
|
||||
chunk.size = chunk_size + 12; /* chunk size plus app marker plus crc */
|
||||
|
||||
metadata_chunk_array_append_sorted (png_data->strip_chunks, &chunk);
|
||||
|
||||
/* if adapter has been provided, prepare to hold chunk */
|
||||
if (png_data->xmp_adapter) {
|
||||
*buf += 22; /* jump "XML:com.adobe.xmp" plus some flags */
|
||||
*bufsize -= 22;
|
||||
png_data->read = chunk_size - 22; /* four CRC bytes at the end will be jumped after */
|
||||
png_data->state = PNG_MUX_XMP;
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* just set jump sise */
|
||||
png_data->read = chunk_size + 4; /* four CRC bytes at the end */
|
||||
png_data->state = PNG_MUX_JUMPING;
|
||||
ret = 0;
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
metadatamux_png_jump (PngMuxData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
png_data->state = PNG_MUX_READING;
|
||||
return metadataparse_util_jump_chunk (&png_data->read, buf,
|
||||
bufsize, next_start, next_size);
|
||||
}
|
||||
|
||||
static int
|
||||
metadatamux_png_xmp (PngMuxData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = metadataparse_util_hold_chunk (&png_data->read, buf,
|
||||
bufsize, next_start, next_size, png_data->xmp_adapter);
|
||||
if (ret == 0) {
|
||||
/* jump four CRC bytes at the end of chunk */
|
||||
png_data->read = 4;
|
||||
png_data->state = PNG_MUX_JUMPING;
|
||||
/* if there is a second XMP chunk in the file it will be jumped */
|
||||
png_data->xmp_adapter = NULL;
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
90
ext/metadata/metadatamuxpng.h
Normal file
90
ext/metadata/metadatamuxpng.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __METADATAMUX_PNG_H__
|
||||
#define __METADATAMUX_PNG_H__
|
||||
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#include "metadatatypes.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum _tag_PngMuxState
|
||||
{
|
||||
PNG_MUX_NULL,
|
||||
PNG_MUX_READING,
|
||||
PNG_MUX_JUMPING,
|
||||
PNG_MUX_XMP,
|
||||
PNG_MUX_DONE
|
||||
} PngMuxState;
|
||||
|
||||
|
||||
typedef struct _tag_PngMuxData
|
||||
{
|
||||
PngMuxState state;
|
||||
|
||||
GstAdapter ** xmp_adapter;
|
||||
|
||||
MetadataChunkArray * strip_chunks;
|
||||
MetadataChunkArray * inject_chunks;
|
||||
|
||||
guint32 read;
|
||||
} PngMuxData;
|
||||
|
||||
|
||||
extern void
|
||||
metadatamux_png_init (PngMuxData * png_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks);
|
||||
|
||||
extern void metadatamux_png_dispose (PngMuxData * png_data);
|
||||
|
||||
extern void metadatamux_png_lazy_update (PngMuxData * jpeg_data);
|
||||
|
||||
int
|
||||
metadatamux_png_parse (PngMuxData * png_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __METADATAMUX_PNG_H__ */
|
|
@ -48,34 +48,40 @@
|
|||
#include <libiptcdata/iptc-jpeg.h>
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_reading (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_exif (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_iptc (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_xmp (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_xmp (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_jump (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_jump (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
#define READ(buf, size) ( (size)--, *((buf)++) )
|
||||
|
||||
void
|
||||
metadataparse_jpeg_init (JpegData * jpeg_data, GstAdapter ** exif_adpt,
|
||||
metadataparse_jpeg_lazy_update (JpegParseData * jpeg_data)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
void
|
||||
metadataparse_jpeg_init (JpegParseData * jpeg_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks)
|
||||
{
|
||||
jpeg_data->state = JPEG_NULL;
|
||||
jpeg_data->state = JPEG_PARSE_NULL;
|
||||
jpeg_data->exif_adapter = exif_adpt;
|
||||
jpeg_data->iptc_adapter = iptc_adpt;
|
||||
jpeg_data->xmp_adapter = xmp_adpt;
|
||||
|
@ -89,7 +95,7 @@ metadataparse_jpeg_init (JpegData * jpeg_data, GstAdapter ** exif_adpt,
|
|||
}
|
||||
|
||||
void
|
||||
metadataparse_jpeg_dispose (JpegData * jpeg_data)
|
||||
metadataparse_jpeg_dispose (JpegParseData * jpeg_data)
|
||||
{
|
||||
metadataparse_xmp_dispose ();
|
||||
|
||||
|
@ -99,7 +105,7 @@ metadataparse_jpeg_dispose (JpegData * jpeg_data)
|
|||
}
|
||||
|
||||
int
|
||||
metadataparse_jpeg_parse (JpegData * jpeg_data, guint8 * buf,
|
||||
metadataparse_jpeg_parse (JpegParseData * jpeg_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start,
|
||||
guint32 * next_size)
|
||||
{
|
||||
|
@ -110,7 +116,7 @@ metadataparse_jpeg_parse (JpegData * jpeg_data, guint8 * buf,
|
|||
|
||||
*next_start = buf;
|
||||
|
||||
if (jpeg_data->state == JPEG_NULL) {
|
||||
if (jpeg_data->state == JPEG_PARSE_NULL) {
|
||||
|
||||
if (*bufsize < 2) {
|
||||
*next_size = (buf - *next_start) + 2;
|
||||
|
@ -126,38 +132,38 @@ metadataparse_jpeg_parse (JpegData * jpeg_data, guint8 * buf,
|
|||
goto done;
|
||||
}
|
||||
|
||||
jpeg_data->state = JPEG_READING;
|
||||
jpeg_data->state = JPEG_PARSE_READING;
|
||||
|
||||
}
|
||||
|
||||
while (ret == 0) {
|
||||
switch (jpeg_data->state) {
|
||||
case JPEG_READING:
|
||||
case JPEG_PARSE_READING:
|
||||
ret =
|
||||
metadataparse_jpeg_reading (jpeg_data, &buf, bufsize,
|
||||
offset, step_buf, next_start, next_size);
|
||||
break;
|
||||
case JPEG_JUMPING:
|
||||
case JPEG_PARSE_JUMPING:
|
||||
ret =
|
||||
metadataparse_jpeg_jump (jpeg_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case JPEG_EXIF:
|
||||
case JPEG_PARSE_EXIF:
|
||||
ret =
|
||||
metadataparse_jpeg_exif (jpeg_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case JPEG_IPTC:
|
||||
case JPEG_PARSE_IPTC:
|
||||
ret =
|
||||
metadataparse_jpeg_iptc (jpeg_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case JPEG_XMP:
|
||||
case JPEG_PARSE_XMP:
|
||||
ret =
|
||||
metadataparse_jpeg_xmp (jpeg_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case JPEG_DONE:
|
||||
case JPEG_PARSE_DONE:
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
|
@ -175,7 +181,7 @@ done:
|
|||
|
||||
/* look for markers */
|
||||
static int
|
||||
metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_reading (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
|
@ -204,11 +210,11 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
if (mark[0] == 0xFF) {
|
||||
if (mark[1] == 0xD9) { /* end of image */
|
||||
ret = 0;
|
||||
jpeg_data->state = JPEG_DONE;
|
||||
jpeg_data->state = JPEG_PARSE_DONE;
|
||||
goto done;
|
||||
} else if (mark[1] == 0xDA) { /* start of scan, lets not look behinf of this */
|
||||
ret = 0;
|
||||
jpeg_data->state = JPEG_DONE;
|
||||
jpeg_data->state = JPEG_PARSE_DONE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -252,6 +258,7 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = (*buf - step_buf) + offset - 4; /* maker + size */
|
||||
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
||||
chunk.type = MD_CHUNK_EXIF;
|
||||
|
||||
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks, &chunk);
|
||||
|
||||
|
@ -269,6 +276,7 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = 2;
|
||||
chunk.size = 18;
|
||||
chunk.type = MD_CHUNK_UNKNOWN;
|
||||
chunk.data = g_new (guint8, 18);
|
||||
memcpy (chunk.data, segment, 18);
|
||||
|
||||
|
@ -280,7 +288,7 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
if (jpeg_data->exif_adapter) {
|
||||
|
||||
jpeg_data->read = chunk_size - 2;
|
||||
jpeg_data->state = JPEG_EXIF;
|
||||
jpeg_data->state = JPEG_PARSE_EXIF;
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
|
@ -298,6 +306,7 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = (*buf - step_buf) + offset - 4; /* maker + size */
|
||||
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
||||
chunk.type = MD_CHUNK_XMP;
|
||||
|
||||
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks,
|
||||
&chunk);
|
||||
|
@ -307,7 +316,7 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
*buf += 29;
|
||||
*bufsize -= 29;
|
||||
jpeg_data->read = chunk_size - 2 - 29;
|
||||
jpeg_data->state = JPEG_XMP;
|
||||
jpeg_data->state = JPEG_PARSE_XMP;
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
|
@ -330,13 +339,14 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
||||
chunk.offset_orig = (*buf - step_buf) + offset - 4; /* maker + size */
|
||||
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
||||
chunk.type = MD_CHUNK_IPTC;
|
||||
|
||||
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks, &chunk);
|
||||
|
||||
/* if adapter has been provided, prepare to hold chunk */
|
||||
if (jpeg_data->iptc_adapter) {
|
||||
jpeg_data->read = chunk_size - 2;
|
||||
jpeg_data->state = JPEG_IPTC;
|
||||
jpeg_data->state = JPEG_PARSE_IPTC;
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
|
@ -346,7 +356,7 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
|
|||
|
||||
/* just set jump sise */
|
||||
jpeg_data->read = chunk_size - 2;
|
||||
jpeg_data->state = JPEG_JUMPING;
|
||||
jpeg_data->state = JPEG_PARSE_JUMPING;
|
||||
ret = 0;
|
||||
|
||||
} else {
|
||||
|
@ -363,7 +373,7 @@ done:
|
|||
}
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_exif (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
int ret;
|
||||
|
@ -372,7 +382,7 @@ metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf,
|
|||
bufsize, next_start, next_size, jpeg_data->exif_adapter);
|
||||
if (ret == 0) {
|
||||
|
||||
jpeg_data->state = JPEG_READING;
|
||||
jpeg_data->state = JPEG_PARSE_READING;
|
||||
|
||||
/* if there is a second Exif chunk in the file it will be jumped */
|
||||
jpeg_data->exif_adapter = NULL;
|
||||
|
@ -382,7 +392,7 @@ metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf,
|
|||
}
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_iptc (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
|
||||
|
@ -399,7 +409,7 @@ metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
|
|||
unsigned int iptc_len;
|
||||
int res;
|
||||
|
||||
jpeg_data->state = JPEG_READING;
|
||||
jpeg_data->state = JPEG_PARSE_READING;
|
||||
|
||||
size = gst_adapter_available (*jpeg_data->iptc_adapter);
|
||||
buf = gst_adapter_peek (*jpeg_data->iptc_adapter, size);
|
||||
|
@ -434,7 +444,7 @@ metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
|
|||
}
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_xmp (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_xmp (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
int ret;
|
||||
|
@ -443,7 +453,7 @@ metadataparse_jpeg_xmp (JpegData * jpeg_data, guint8 ** buf,
|
|||
bufsize, next_start, next_size, jpeg_data->xmp_adapter);
|
||||
|
||||
if (ret == 0) {
|
||||
jpeg_data->state = JPEG_READING;
|
||||
jpeg_data->state = JPEG_PARSE_READING;
|
||||
/* if there is a second XMP chunk in the file it will be jumped */
|
||||
jpeg_data->xmp_adapter = NULL;
|
||||
}
|
||||
|
@ -451,10 +461,10 @@ metadataparse_jpeg_xmp (JpegData * jpeg_data, guint8 ** buf,
|
|||
}
|
||||
|
||||
static int
|
||||
metadataparse_jpeg_jump (JpegData * jpeg_data, guint8 ** buf,
|
||||
metadataparse_jpeg_jump (JpegParseData * jpeg_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
jpeg_data->state = JPEG_READING;
|
||||
jpeg_data->state = JPEG_PARSE_READING;
|
||||
return metadataparse_util_jump_chunk (&jpeg_data->read, buf,
|
||||
bufsize, next_start, next_size);
|
||||
}
|
||||
|
|
|
@ -50,21 +50,21 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum _tag_JpegState
|
||||
typedef enum _tag_JpegParseState
|
||||
{
|
||||
JPEG_NULL,
|
||||
JPEG_READING,
|
||||
JPEG_JUMPING,
|
||||
JPEG_EXIF,
|
||||
JPEG_IPTC,
|
||||
JPEG_XMP,
|
||||
JPEG_DONE
|
||||
} JpegState;
|
||||
JPEG_PARSE_NULL,
|
||||
JPEG_PARSE_READING,
|
||||
JPEG_PARSE_JUMPING,
|
||||
JPEG_PARSE_EXIF,
|
||||
JPEG_PARSE_IPTC,
|
||||
JPEG_PARSE_XMP,
|
||||
JPEG_PARSE_DONE
|
||||
} JpegParseState;
|
||||
|
||||
|
||||
typedef struct _tag_JpegData
|
||||
typedef struct _tag_JpegParseData
|
||||
{
|
||||
JpegState state;
|
||||
JpegParseState state;
|
||||
|
||||
GstAdapter ** exif_adapter;
|
||||
GstAdapter ** iptc_adapter;
|
||||
|
@ -75,19 +75,20 @@ typedef struct _tag_JpegData
|
|||
|
||||
guint32 read;
|
||||
gboolean jfif_found;
|
||||
} JpegData;
|
||||
} JpegParseData;
|
||||
|
||||
|
||||
extern void
|
||||
metadataparse_jpeg_init (JpegData * jpeg_data, GstAdapter ** exif_adpt,
|
||||
metadataparse_jpeg_init (JpegParseData * jpeg_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks);
|
||||
|
||||
extern void metadataparse_jpeg_dispose (JpegData * jpeg_data);
|
||||
extern void metadataparse_jpeg_dispose (JpegParseData * jpeg_data);
|
||||
|
||||
extern void metadataparse_jpeg_lazy_update (JpegParseData * jpeg_data);
|
||||
|
||||
int
|
||||
metadataparse_jpeg_parse (JpegData * jpeg_data, guint8 * buf,
|
||||
metadataparse_jpeg_parse (JpegParseData * jpeg_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -46,26 +46,32 @@
|
|||
#include <string.h>
|
||||
|
||||
static int
|
||||
metadataparse_png_reading (PngData * png_data, guint8 ** buf,
|
||||
metadataparse_png_reading (PngParseData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadataparse_png_xmp (PngData * png_data, guint8 ** buf,
|
||||
metadataparse_png_xmp (PngParseData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
static int
|
||||
metadataparse_png_jump (PngData * png_data, guint8 ** buf,
|
||||
metadataparse_png_jump (PngParseData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
#define READ(buf, size) ( (size)--, *((buf)++) )
|
||||
|
||||
void
|
||||
metadataparse_png_init (PngData * png_data, GstAdapter ** exif_adpt,
|
||||
metadataparse_png_lazy_update (PngParseData * jpeg_data)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
void
|
||||
metadataparse_png_init (PngParseData * png_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks)
|
||||
{
|
||||
png_data->state = PNG_NULL;
|
||||
png_data->state = PNG_PARSE_NULL;
|
||||
png_data->xmp_adapter = xmp_adpt;
|
||||
png_data->read = 0;
|
||||
|
||||
|
@ -76,7 +82,7 @@ metadataparse_png_init (PngData * png_data, GstAdapter ** exif_adpt,
|
|||
}
|
||||
|
||||
void
|
||||
metadataparse_png_dispose (PngData * png_data)
|
||||
metadataparse_png_dispose (PngParseData * png_data)
|
||||
{
|
||||
metadataparse_xmp_dispose ();
|
||||
|
||||
|
@ -84,7 +90,7 @@ metadataparse_png_dispose (PngData * png_data)
|
|||
}
|
||||
|
||||
int
|
||||
metadataparse_png_parse (PngData * png_data, guint8 * buf,
|
||||
metadataparse_png_parse (PngParseData * png_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start,
|
||||
guint32 * next_size)
|
||||
{
|
||||
|
@ -95,7 +101,7 @@ metadataparse_png_parse (PngData * png_data, guint8 * buf,
|
|||
|
||||
*next_start = buf;
|
||||
|
||||
if (png_data->state == PNG_NULL) {
|
||||
if (png_data->state == PNG_PARSE_NULL) {
|
||||
|
||||
if (*bufsize < 8) {
|
||||
*next_size = (buf - *next_start) + 8;
|
||||
|
@ -119,28 +125,28 @@ metadataparse_png_parse (PngData * png_data, guint8 * buf,
|
|||
goto done;
|
||||
}
|
||||
|
||||
png_data->state = PNG_READING;
|
||||
png_data->state = PNG_PARSE_READING;
|
||||
|
||||
}
|
||||
|
||||
while (ret == 0) {
|
||||
switch (png_data->state) {
|
||||
case PNG_READING:
|
||||
case PNG_PARSE_READING:
|
||||
ret =
|
||||
metadataparse_png_reading (png_data, &buf, bufsize,
|
||||
offset, step_buf, next_start, next_size);
|
||||
break;
|
||||
case PNG_JUMPING:
|
||||
case PNG_PARSE_JUMPING:
|
||||
ret =
|
||||
metadataparse_png_jump (png_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case PNG_XMP:
|
||||
case PNG_PARSE_XMP:
|
||||
ret =
|
||||
metadataparse_png_xmp (png_data, &buf, bufsize, next_start,
|
||||
next_size);
|
||||
break;
|
||||
case PNG_DONE:
|
||||
case PNG_PARSE_DONE:
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
|
@ -158,7 +164,7 @@ done:
|
|||
|
||||
/* look for markers */
|
||||
static int
|
||||
metadataparse_png_reading (PngData * png_data, guint8 ** buf,
|
||||
metadataparse_png_reading (PngParseData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
||||
guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
|
@ -189,7 +195,7 @@ metadataparse_png_reading (PngData * png_data, guint8 ** buf,
|
|||
|
||||
if (mark[0] == 'I' && mark[1] == 'E' && mark[2] == 'N' && mark[3] == 'D') {
|
||||
ret = 0;
|
||||
png_data->state = PNG_DONE;
|
||||
png_data->state = PNG_PARSE_DONE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -215,7 +221,7 @@ metadataparse_png_reading (PngData * png_data, guint8 ** buf,
|
|||
*buf += 22; /* jump "XML:com.adobe.xmp" plus some flags */
|
||||
*bufsize -= 22;
|
||||
png_data->read = chunk_size - 22; /* four CRC bytes at the end will be jumped after */
|
||||
png_data->state = PNG_XMP;
|
||||
png_data->state = PNG_PARSE_XMP;
|
||||
ret = 0;
|
||||
goto done;
|
||||
}
|
||||
|
@ -225,7 +231,7 @@ metadataparse_png_reading (PngData * png_data, guint8 ** buf,
|
|||
|
||||
/* just set jump sise */
|
||||
png_data->read = chunk_size + 4; /* four CRC bytes at the end */
|
||||
png_data->state = PNG_JUMPING;
|
||||
png_data->state = PNG_PARSE_JUMPING;
|
||||
ret = 0;
|
||||
|
||||
done:
|
||||
|
@ -236,16 +242,16 @@ done:
|
|||
}
|
||||
|
||||
static int
|
||||
metadataparse_png_jump (PngData * png_data, guint8 ** buf,
|
||||
metadataparse_png_jump (PngParseData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
png_data->state = PNG_READING;
|
||||
png_data->state = PNG_PARSE_READING;
|
||||
return metadataparse_util_jump_chunk (&png_data->read, buf,
|
||||
bufsize, next_start, next_size);
|
||||
}
|
||||
|
||||
static int
|
||||
metadataparse_png_xmp (PngData * png_data, guint8 ** buf,
|
||||
metadataparse_png_xmp (PngParseData * png_data, guint8 ** buf,
|
||||
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
||||
{
|
||||
int ret;
|
||||
|
@ -255,7 +261,7 @@ metadataparse_png_xmp (PngData * png_data, guint8 ** buf,
|
|||
if (ret == 0) {
|
||||
/* jump four CRC bytes at the end of chunk */
|
||||
png_data->read = 4;
|
||||
png_data->state = PNG_JUMPING;
|
||||
png_data->state = PNG_PARSE_JUMPING;
|
||||
/* if there is a second XMP chunk in the file it will be jumped */
|
||||
png_data->xmp_adapter = NULL;
|
||||
}
|
||||
|
|
|
@ -50,19 +50,19 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum _tag_PngState
|
||||
typedef enum _tag_PngParseState
|
||||
{
|
||||
PNG_NULL,
|
||||
PNG_READING,
|
||||
PNG_JUMPING,
|
||||
PNG_XMP,
|
||||
PNG_DONE
|
||||
} PngState;
|
||||
PNG_PARSE_NULL,
|
||||
PNG_PARSE_READING,
|
||||
PNG_PARSE_JUMPING,
|
||||
PNG_PARSE_XMP,
|
||||
PNG_PARSE_DONE
|
||||
} PngParseState;
|
||||
|
||||
|
||||
typedef struct _tag_PngData
|
||||
typedef struct _tag_PngParseData
|
||||
{
|
||||
PngState state;
|
||||
PngParseState state;
|
||||
|
||||
GstAdapter ** xmp_adapter;
|
||||
|
||||
|
@ -70,19 +70,20 @@ typedef struct _tag_PngData
|
|||
MetadataChunkArray * inject_chunks;
|
||||
|
||||
guint32 read;
|
||||
} PngData;
|
||||
} PngParseData;
|
||||
|
||||
|
||||
extern void
|
||||
metadataparse_png_init (PngData * png_data, GstAdapter ** exif_adpt,
|
||||
metadataparse_png_init (PngParseData * png_data, GstAdapter ** exif_adpt,
|
||||
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
||||
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks);
|
||||
|
||||
extern void metadataparse_png_dispose (PngData * png_data);
|
||||
extern void metadataparse_png_dispose (PngParseData * png_data);
|
||||
|
||||
extern void metadataparse_png_lazy_update (PngParseData * jpeg_data);
|
||||
|
||||
int
|
||||
metadataparse_png_parse (PngData * png_data, guint8 * buf,
|
||||
metadataparse_png_parse (PngParseData * png_data, guint8 * buf,
|
||||
guint32 * bufsize, const guint32 offset, guint8 ** next_start, guint32 * next_size);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -80,7 +80,8 @@ metadata_chunk_array_append (MetadataChunkArray * array, MetadataChunk * chunk)
|
|||
{
|
||||
if (array->len == array->allocated_len) {
|
||||
array->allocated_len += 2;
|
||||
array->chunk = g_realloc (array->chunk, array->allocated_len);
|
||||
array->chunk =
|
||||
g_realloc (array->chunk, sizeof (MetadataChunk) * array->allocated_len);
|
||||
}
|
||||
memcpy (&array->chunk[array->len], chunk, sizeof (MetadataChunk));
|
||||
++array->len;
|
||||
|
@ -94,7 +95,8 @@ metadata_chunk_array_append_sorted (MetadataChunkArray * array,
|
|||
|
||||
if (array->len == array->allocated_len) {
|
||||
array->allocated_len += 2;
|
||||
array->chunk = g_realloc (array->chunk, array->allocated_len);
|
||||
array->chunk =
|
||||
g_realloc (array->chunk, sizeof (MetadataChunk) * array->allocated_len);
|
||||
}
|
||||
pos = array->len;
|
||||
for (i = array->len - 1; i >= 0; --i) {
|
||||
|
@ -113,3 +115,21 @@ metadata_chunk_array_append_sorted (MetadataChunkArray * array,
|
|||
return;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
metadata_chunk_array_remove_zero_size (MetadataChunkArray * array)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < array->len;) {
|
||||
if (array->chunk[i].size == 0) {
|
||||
if (i < --array->len) {
|
||||
memmove (&array->chunk[i], &array->chunk[i + 1],
|
||||
sizeof (MetadataChunk) * (array->len - i));
|
||||
}
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,21 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum _tag_MetadataChunkType {
|
||||
MD_CHUNK_UNKNOWN,
|
||||
MD_CHUNK_EXIF,
|
||||
MD_CHUNK_IPTC,
|
||||
MD_CHUNK_XMP
|
||||
} MetadataChunkType;
|
||||
|
||||
typedef struct _tag_MetadataChunk
|
||||
{
|
||||
gint64 offset_orig; /* from the beginning of original file */
|
||||
gint64 offset; /*here just for convinience (filled by element) offset in new stream */
|
||||
gint64 offset_orig; /* from the beginning of original file */
|
||||
/*here just for convinience (filled by element) offset in new stream */
|
||||
gint64 offset;
|
||||
guint32 size; /* chunk or buffer size*/
|
||||
guint8 * data;
|
||||
MetadataChunkType type; /* used by mux to see what tags to insert here */
|
||||
} MetadataChunk;
|
||||
|
||||
typedef struct _tag_MetadataChunkArray
|
||||
|
@ -81,5 +90,8 @@ metadata_chunk_array_append(MetadataChunkArray * array, MetadataChunk * chunk);
|
|||
extern void
|
||||
metadata_chunk_array_append_sorted(MetadataChunkArray * array, MetadataChunk * chunk);
|
||||
|
||||
extern void
|
||||
metadata_chunk_array_remove_zero_size (MetadataChunkArray * array);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __METADATATYPES_H__ */
|
||||
|
|
Loading…
Reference in a new issue