summaryrefslogtreecommitdiffstats
path: root/ext/metadata/metadataparsejpeg.c
diff options
context:
space:
mode:
authorEdgard Lima <edgard.lima@indt.org.br>2007-11-23 17:35:21 +0000
committerEdgard Lima <edgard.lima@indt.org.br>2007-11-23 17:35:21 +0000
commit1cb35c75741314f40f098250108b1b0e7db643cc (patch)
tree6aac146d2ba54a9bdd7e7c720d39d4e92a9d496c /ext/metadata/metadataparsejpeg.c
parentdb93cd7461e32ce9e4261309e6d972758c0de8db (diff)
downloadgst-plugins-bad-1cb35c75741314f40f098250108b1b0e7db643cc.tar.gz
gst-plugins-bad-1cb35c75741314f40f098250108b1b0e7db643cc.tar.bz2
gst-plugins-bad-1cb35c75741314f40f098250108b1b0e7db643cc.zip
Now parser is generic (just add/remove a list of chunks). And a template of muxer has been created.
Original commit message from CVS: Now parser is generic (just add/remove a list of chunks). And a template of muxer has been created.
Diffstat (limited to 'ext/metadata/metadataparsejpeg.c')
-rw-r--r--ext/metadata/metadataparsejpeg.c136
1 files changed, 85 insertions, 51 deletions
diff --git a/ext/metadata/metadataparsejpeg.c b/ext/metadata/metadataparsejpeg.c
index daf7ad27..4b81d1ec 100644
--- a/ext/metadata/metadataparsejpeg.c
+++ b/ext/metadata/metadataparsejpeg.c
@@ -71,16 +71,20 @@ metadataparse_jpeg_jump (JpegData * jpeg_data, guint8 ** buf,
#define READ(buf, size) ( (size)--, *((buf)++) )
void
-metadataparse_jpeg_init (JpegData * jpeg_data, MetadataChunk * exif,
- MetadataChunk * iptc, MetadataChunk * xmp)
+metadataparse_jpeg_init (JpegData * jpeg_data, GstAdapter ** exif_adpt,
+ GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
+ MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks)
{
jpeg_data->state = JPEG_NULL;
- jpeg_data->exif = exif;
- jpeg_data->iptc = iptc;
- jpeg_data->xmp = xmp;
+ jpeg_data->exif_adapter = exif_adpt;
+ jpeg_data->iptc_adapter = iptc_adpt;
+ jpeg_data->xmp_adapter = xmp_adpt;
jpeg_data->read = 0;
jpeg_data->jfif_found = FALSE;
+ jpeg_data->strip_chunks = strip_chunks;
+ jpeg_data->inject_chunks = inject_chunks;
+
metadataparse_xmp_init ();
}
@@ -89,9 +93,9 @@ metadataparse_jpeg_dispose (JpegData * jpeg_data)
{
metadataparse_xmp_dispose ();
- jpeg_data->exif = NULL;
- jpeg_data->iptc = NULL;
- jpeg_data->xmp = NULL;
+ jpeg_data->exif_adapter = NULL;
+ jpeg_data->iptc_adapter = NULL;
+ jpeg_data->xmp_adapter = NULL;
}
int
@@ -242,28 +246,42 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
goto done;
}
- if (jpeg_data->exif) {
- if (0 == memcmp (ExifHeader, *buf, 6)) {
- jpeg_data->exif->offset = (*buf - step_buf) + offset - 4; /* maker + size */
- jpeg_data->exif->size = chunk_size + 2; /* chunk size plus app marker */
- jpeg_data->read = chunk_size - 2;
- ret = 0;
+ if (0 == memcmp (ExifHeader, *buf, 6)) {
+ MetadataChunk chunk;
- if (!jpeg_data->jfif_found) {
- static const guint8 chunk[] = { 0xff, 0xe0, 0x00, 0x10,
- 0x4a, 0x46, 0x49, 0x46, 0x00,
- 0x01, 0x02,
- 0x00, 0x00, 0x01, 0x00, 0x01,
- 0x00, 0x00
- };
-
- /* only inject if no JFIF has been found */
- jpeg_data->exif->size_inject = 18;
- jpeg_data->exif->buffer = malloc (18);
- memcpy (jpeg_data->exif->buffer, chunk, 18);
- }
+ 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 */
+
+ metadata_chunk_array_append_sorted (jpeg_data->strip_chunks, &chunk);
+
+ if (!jpeg_data->jfif_found) {
+ /* only inject if no JFIF has been found */
+
+ static const guint8 segment[] = { 0xff, 0xe0, 0x00, 0x10,
+ 0x4a, 0x46, 0x49, 0x46, 0x00,
+ 0x01, 0x02,
+ 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x00, 0x00
+ };
+
+
+ memset (&chunk, 0x00, sizeof (MetadataChunk));
+ chunk.offset_orig = 2;
+ chunk.size = 18;
+ chunk.data = g_new (guint8, 18);
+ memcpy (chunk.data, segment, 18);
+
+ metadata_chunk_array_append_sorted (jpeg_data->inject_chunks,
+ &chunk);
+
+ }
+
+ if (jpeg_data->exif_adapter) {
+ jpeg_data->read = chunk_size - 2;
jpeg_data->state = JPEG_EXIF;
+ ret = 0;
goto done;
}
}
@@ -274,15 +292,23 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
goto done;
}
- if (jpeg_data->xmp) {
- if (0 == memcmp (XmpHeader, *buf, 29)) {
- jpeg_data->xmp->offset = (*buf - step_buf) + offset - 4; /* maker + size */
- jpeg_data->xmp->size = chunk_size + 2; /* chunk size plus app marker */
+ if (0 == memcmp (XmpHeader, *buf, 29)) {
+ MetadataChunk chunk;
+
+ 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 */
+
+ metadata_chunk_array_append_sorted (jpeg_data->strip_chunks,
+ &chunk);
+
+ /* if adapter has been provided, prepare to hold chunk */
+ if (jpeg_data->xmp_adapter) {
*buf += 29;
*bufsize -= 29;
jpeg_data->read = chunk_size - 2 - 29;
- ret = 0;
jpeg_data->state = JPEG_XMP;
+ ret = 0;
goto done;
}
}
@@ -297,13 +323,21 @@ metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf,
goto done;
}
- if (jpeg_data->iptc) {
- if (0 == memcmp (IptcHeader, *buf, 14)) {
- jpeg_data->iptc->offset = (*buf - step_buf) + offset - 4; /* maker + size */
- jpeg_data->iptc->size = chunk_size + 2; /* chunk size plus app marker */
+
+ if (0 == memcmp (IptcHeader, *buf, 14)) {
+ MetadataChunk chunk;
+
+ 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 */
+
+ 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;
- ret = 0;
jpeg_data->state = JPEG_IPTC;
+ ret = 0;
goto done;
}
}
@@ -335,13 +369,13 @@ metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf,
int ret;
ret = metadataparse_util_hold_chunk (&jpeg_data->read, buf,
- bufsize, next_start, next_size, &jpeg_data->exif->adapter);
+ bufsize, next_start, next_size, jpeg_data->exif_adapter);
if (ret == 0) {
jpeg_data->state = JPEG_READING;
/* if there is a second Exif chunk in the file it will be jumped */
- jpeg_data->exif = NULL;
+ jpeg_data->exif_adapter = NULL;
}
return ret;
@@ -355,7 +389,7 @@ metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
int ret;
ret = metadataparse_util_hold_chunk (&jpeg_data->read, buf,
- bufsize, next_start, next_size, &jpeg_data->iptc->adapter);
+ bufsize, next_start, next_size, jpeg_data->iptc_adapter);
if (ret == 0) {
@@ -367,8 +401,8 @@ metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
jpeg_data->state = JPEG_READING;
- size = gst_adapter_available (jpeg_data->iptc->adapter);
- buf = gst_adapter_peek (jpeg_data->iptc->adapter, size);
+ size = gst_adapter_available (*jpeg_data->iptc_adapter);
+ buf = gst_adapter_peek (*jpeg_data->iptc_adapter, size);
res = iptc_jpeg_ps3_find_iptc (buf, size, &iptc_len);
@@ -377,21 +411,21 @@ metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf,
ret = -1;
} else if (res == 0) {
/* no iptc data found */
- gst_adapter_clear (jpeg_data->iptc->adapter);
+ gst_adapter_clear (*jpeg_data->iptc_adapter);
} else {
- gst_adapter_flush (jpeg_data->iptc->adapter, res);
- size = gst_adapter_available (jpeg_data->iptc->adapter);
+ gst_adapter_flush (*jpeg_data->iptc_adapter, res);
+ size = gst_adapter_available (*jpeg_data->iptc_adapter);
if (size > iptc_len) {
GstBuffer *buf;
- buf = gst_adapter_take_buffer (jpeg_data->iptc->adapter, iptc_len);
- gst_adapter_clear (jpeg_data->iptc->adapter);
- gst_adapter_push (jpeg_data->iptc->adapter, buf);
+ buf = gst_adapter_take_buffer (*jpeg_data->iptc_adapter, iptc_len);
+ gst_adapter_clear (*jpeg_data->iptc_adapter);
+ gst_adapter_push (*jpeg_data->iptc_adapter, buf);
}
}
/* if there is a second Iptc chunk in the file it will be jumped */
- jpeg_data->iptc = NULL;
+ jpeg_data->iptc_adapter = NULL;
}
@@ -406,12 +440,12 @@ metadataparse_jpeg_xmp (JpegData * jpeg_data, guint8 ** buf,
int ret;
ret = metadataparse_util_hold_chunk (&jpeg_data->read, buf,
- bufsize, next_start, next_size, &jpeg_data->xmp->adapter);
+ bufsize, next_start, next_size, jpeg_data->xmp_adapter);
if (ret == 0) {
jpeg_data->state = JPEG_READING;
/* if there is a second XMP chunk in the file it will be jumped */
- jpeg_data->xmp = NULL;
+ jpeg_data->xmp_adapter = NULL;
}
return ret;
}