3
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice shall be included in
13
* all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
* DEALINGS IN THE SOFTWARE.
23
* Alternatively, the contents of this file may be used under the
24
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
25
* which case the following provisions apply instead of the ones
28
* This library is free software; you can redistribute it and/or
29
* modify it under the terms of the GNU Library General Public
30
* License as published by the Free Software Foundation; either
31
* version 2 of the License, or (at your option) any later version.
33
* This library is distributed in the hope that it will be useful,
34
* but WITHOUT ANY WARRANTY; without even the implied warranty of
35
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36
* Library General Public License for more details.
38
* You should have received a copy of the GNU Library General Public
39
* License along with this library; if not, write to the
40
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41
* Boston, MA 02111-1307, USA.
45
* SECTION: metadataiptc
46
* @short_description: This module provides functions to extract tags from
47
* IPTC metadata chunks and create IPTC chunks from metadata tags.
48
* @see_also: #metadatatags.[c/h]
50
* If libiptcdata isn't available at compilation time, only the whole chunk
51
* (#METADATA_TAG_MAP_WHOLECHUNK) tags is created. It means that individual
54
* Last reviewed on 2008-01-24 (0.10.15)
61
#include "metadataiptc.h"
62
#include "metadataparseutil.h"
63
#include "metadatatags.h"
69
GST_DEBUG_CATEGORY (gst_metadata_iptc_debug);
70
#define GST_CAT_DEFAULT gst_metadata_iptc_debug
73
* Implementation when libiptcdata isn't available at compilation time
79
* extern functions implementations
83
metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode,
84
GstAdapter * adapter, MetadataTagMapping mapping)
87
if (mapping & METADATA_TAG_MAP_WHOLECHUNK) {
88
GST_LOG ("IPTC not defined, sending just one tag as whole chunk");
89
metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC,
97
metadatamux_iptc_create_chunk_from_tag_list (guint8 ** buf, guint32 * size,
98
const GstTagList * taglist)
103
#else /* ifndef HAVE_IPTC */
106
* Implementation when libiptcdata is available at compilation time
113
#include <iptc-data.h>
114
#include <iptc-tag.h>
116
#include <gst/gsttaglist.h>
122
typedef struct _tag_MEUserData
125
GstTagMergeMode mode;
128
typedef struct _tag_MapIntStr
136
* defines and static global vars
140
/* When changing this table, update 'metadata_mapping.htm' file too. */
141
static MapIntStr mappedTags[] = {
142
{IPTC_RECORD_APP_2, IPTC_TAG_OBJECT_NAME, /*ASCII*/
143
GST_TAG_TITLE /*STRING*/},
144
{IPTC_RECORD_APP_2, IPTC_TAG_BYLINE, /*ASCII*/
145
GST_TAG_COMPOSER /*STRING*/},
146
{IPTC_RECORD_APP_2, IPTC_TAG_CAPTION, /*ASCII*/
147
GST_TAG_DESCRIPTION /*STRING*/},
148
{IPTC_RECORD_APP_2, IPTC_TAG_COPYRIGHT_NOTICE, /*ASCII*/
149
GST_TAG_COPYRIGHT /*STRING*/},
155
* static helper functions declaration
158
static const gchar *metadataparse_iptc_get_tag_from_iptc (IptcTag iptc,
159
GType * type, IptcRecord * record);
163
metadatamux_iptc_get_iptc_from_tag (const gchar * tag, GType * type,
164
IptcRecord * record);
167
metadataparse_iptc_data_foreach_dataset_func (IptcDataSet * dataset,
171
metadatamux_iptc_for_each_tag_in_list (const GstTagList * list,
172
const gchar * tag, gpointer user_data);
175
* extern functions implementations
179
* metadataparse_iptc_tag_list_add:
180
* @taglist: tag list in which extracted tags will be added
181
* @mode: tag list merge mode
182
* @adapter: contains the IPTC metadata chunk
183
* @mapping: if is to extract individual tags and/or the whole chunk.
185
* This function gets a IPTC chunk (@adapter) and extract tags form it
186
* and then add to @taglist.
187
* Note: The IPTC chunk (@adapetr) must NOT be wrapped by any bytes specific
194
metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode,
195
GstAdapter * adapter, MetadataTagMapping mapping)
199
IptcData *iptc = NULL;
200
MEUserData user_data = { taglist, mode };
202
if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) {
207
if (mapping & METADATA_TAG_MAP_WHOLECHUNK)
208
metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC,
211
if (!(mapping & METADATA_TAG_MAP_INDIVIDUALS))
214
buf = gst_adapter_peek (adapter, size);
216
iptc = iptc_data_new_from_data (buf, size);
221
iptc_data_foreach_dataset (iptc,
222
metadataparse_iptc_data_foreach_dataset_func, (void *) &user_data);
227
iptc_data_unref (iptc);
234
* metadatamux_iptc_create_chunk_from_tag_list:
235
* @buf: buffer that will have the created IPTC chunk
236
* @size: size of the buffer that will be created
237
* @taglist: list of tags to be added to IPTC chunk
239
* Get tags from @taglist, create a IPTC chunk based on it and save to @buf.
240
* Note: The IPTC chunk is NOT wrapped by any bytes specific to any file format
246
metadatamux_iptc_create_chunk_from_tag_list (guint8 ** buf, guint32 * size,
247
const GstTagList * taglist)
249
IptcData *iptc = NULL;
250
GstBuffer *iptc_chunk = NULL;
251
const GValue *val = NULL;
261
val = gst_tag_list_get_value_index (taglist, GST_TAG_IPTC, 0);
263
iptc_chunk = gst_value_get_buffer (val);
265
iptc = iptc_data_new_from_data (GST_BUFFER_DATA (iptc_chunk),
266
GST_BUFFER_SIZE (iptc_chunk));
271
iptc = iptc_data_new ();
274
gst_tag_list_foreach (taglist, metadatamux_iptc_for_each_tag_in_list, iptc);
276
iptc_data_save (iptc, buf, size);
282
iptc_data_unref (iptc);
288
* static helper functions implementation
292
* metadataparse_iptc_get_tag_from_iptc:
293
* @iptc: IPTC tag to look for
294
* @type: the type of the GStreamer tag mapped to @iptc
295
* @record: the place into IPTC chunk @iptc belongs to.
297
* This returns the GStreamer tag mapped to an IPTC tag.
301
* <listitem><para>The GStreamer tag mapped to the @iptc
303
* <listitem><para>%NULL if there is no mapped GST tag for @iptc
309
metadataparse_iptc_get_tag_from_iptc (IptcTag iptc, GType * type,
314
while (mappedTags[i].iptc) {
315
if (iptc == mappedTags[i].iptc) {
316
*type = gst_tag_get_type (mappedTags[i].str);
317
*record = mappedTags[i].record;
323
return mappedTags[i].str;
328
* metadatamux_iptc_get_iptc_from_tag:
329
* @tag: GST tag to look for
330
* @type: the type of the GStreamer @tag
331
* @record: the place into IPTC chunk @iptc belongs to.
333
* This returns thet IPTC tag mapped to an GStreamer @tag.
337
* <listitem><para>The IPTC tag mapped to the GST @tag
339
* <listitem><para>0 if there is no mapped IPTC tag for GST @tag
345
metadatamux_iptc_get_iptc_from_tag (const gchar * tag, GType * type,
350
while (mappedTags[i].iptc) {
351
if (0 == strcmp (mappedTags[i].str, tag)) {
352
*type = gst_tag_get_type (tag);
353
*record = mappedTags[i].record;
359
return mappedTags[i].iptc;
364
* metadataparse_iptc_data_foreach_dataset_func:
365
* @dataset: IPTC structure from libiptcdata having IPTC tag
366
* @user_data: pointer to #MEUserData
368
* This function designed to be called for each IPTC tag in a IPTC chunk. This
369
* function gets the IPTC tag from @dataset and then add to the tag list
370
* in @user_data by using a merge mode also specified in @user_data
371
* @see_also: #metadataparse_iptc_tag_list_add
377
metadataparse_iptc_data_foreach_dataset_func (IptcDataSet * dataset,
382
MEUserData *meudata = (MEUserData *) user_data;
386
metadataparse_iptc_get_tag_from_iptc (dataset->tag, &type, &record);
387
const gchar *value = iptc_dataset_get_as_str (dataset, buf, 1024);
392
gst_tag_list_add (meudata->taglist, meudata->mode, tag, value, NULL);
396
GST_LOG ("name -> %s", iptc_tag_get_name (dataset->record, dataset->tag));
397
GST_LOG ("title -> %s", iptc_tag_get_title (dataset->record, dataset->tag));
398
GST_LOG ("description -> %s", iptc_tag_get_description (dataset->record,
400
GST_LOG ("value = %s", value);
401
GST_LOG ("record = %d", dataset->record);
408
* metadatamux_iptc_for_each_tag_in_list:
409
* @list: GStreamer tag list from which @tag belongs to
410
* @tag: GStreamer tag to be added to the IPTC chunk
411
* @user_data: pointer to #IptcData in which the tag will be added
413
* This function designed to be called for each tag in GST tag list. This
414
* function adds get the tag value from tag @list and then add it to the IPTC
415
* chunk by using #IptcData and related functions from libiptcdata
416
* @see_also: #metadatamux_iptc_create_chunk_from_tag_list
422
metadatamux_iptc_for_each_tag_in_list (const GstTagList * list,
423
const gchar * tag, gpointer user_data)
425
IptcData *iptc = (IptcData *) user_data;
429
IptcDataSet *dataset = NULL;
430
gboolean new_dataset = FALSE;
431
gchar *tag_value = NULL;
433
iptc_tag = metadatamux_iptc_get_iptc_from_tag (tag, &type, &record);
438
dataset = iptc_data_get_dataset (iptc, record, iptc_tag);
441
dataset = iptc_dataset_new ();
445
iptc_dataset_set_tag (dataset, record, iptc_tag);
447
if (gst_tag_list_get_string (list, tag, &tag_value)) {
448
iptc_dataset_set_data (dataset, (guint8 *) tag_value, strlen (tag_value),
456
iptc_data_add_dataset (iptc, dataset);
461
iptc_dataset_unref (dataset);
465
#endif /* else (ifndef HAVE_IPTC) */