1 /* GStreamer
2  *
3  * unit test for jifmux
4  *
5  * Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #  include <config.h>
25 #endif
26 
27 #include <stdio.h>
28 #include <unistd.h>
29 
30 #include <glib/gstdio.h>
31 
32 #include <gst/check/gstcheck.h>
33 #include <gst/tag/tag.h>
34 
35 #include <libexif/exif-data.h>
36 #include <libexif/exif-loader.h>
37 
38 typedef struct
39 {
40   gboolean result;
41   const GstTagList *taglist;
42   gint map_index;
43 } ExifTagCheckData;
44 
45 /* taken from the exif helper lib in -base */
46 /* Exif tag types */
47 #define EXIF_TYPE_BYTE       1
48 #define EXIF_TYPE_ASCII      2
49 #define EXIF_TYPE_SHORT      3
50 #define EXIF_TYPE_LONG       4
51 #define EXIF_TYPE_RATIONAL   5
52 #define EXIF_TYPE_UNDEFINED  7
53 #define EXIF_TYPE_SLONG      9
54 #define EXIF_TYPE_SRATIONAL 10
55 
56 typedef struct _GstExifTagMatch GstExifTagMatch;
57 typedef void (*CompareFunc) (ExifEntry * entry, ExifTagCheckData * testdata);
58 
59 struct _GstExifTagMatch
60 {
61   const gchar *gst_tag;
62   guint16 exif_tag;
63   guint16 exif_type;
64   CompareFunc compare_func;
65 };
66 
67 /* compare funcs */
68 
69 /* Copied over from gst-libs/gst/tag/gsttagedittingprivate.c from -base */
70 static gint
__exif_tag_image_orientation_to_exif_value(const gchar * str)71 __exif_tag_image_orientation_to_exif_value (const gchar * str)
72 {
73   if (str == NULL)
74     goto end;
75 
76   if (strcmp (str, "rotate-0") == 0)
77     return 1;
78   else if (strcmp (str, "flip-rotate-0") == 0)
79     return 2;
80   else if (strcmp (str, "rotate-180") == 0)
81     return 3;
82   else if (strcmp (str, "flip-rotate-180") == 0)
83     return 4;
84   else if (strcmp (str, "flip-rotate-270") == 0)
85     return 5;
86   else if (strcmp (str, "rotate-90") == 0)
87     return 6;
88   else if (strcmp (str, "flip-rotate-90") == 0)
89     return 7;
90   else if (strcmp (str, "rotate-270") == 0)
91     return 8;
92 
93 end:
94   GST_WARNING ("Invalid image orientation tag: %s", str);
95   return -1;
96 }
97 
98 static gint
__exif_tag_capture_exposure_program_to_exif_value(const gchar * str)99 __exif_tag_capture_exposure_program_to_exif_value (const gchar * str)
100 {
101   if (str == NULL)
102     goto end;
103 
104   if (strcmp (str, "undefined") == 0)
105     return 0;
106   else if (strcmp (str, "manual") == 0)
107     return 1;
108   else if (strcmp (str, "normal") == 0)
109     return 2;
110   else if (strcmp (str, "aperture-priority") == 0)
111     return 3;
112   else if (strcmp (str, "shutter-priority") == 0)
113     return 4;
114   else if (strcmp (str, "creative") == 0)
115     return 5;
116   else if (strcmp (str, "action") == 0)
117     return 6;
118   else if (strcmp (str, "portrait") == 0)
119     return 7;
120   else if (strcmp (str, "landscape") == 0)
121     return 8;
122 
123 end:
124   GST_WARNING ("Invalid capture exposure program tag: %s", str);
125   return -1;
126 }
127 
128 static gint
__exif_tag_capture_exposure_mode_to_exif_value(const gchar * str)129 __exif_tag_capture_exposure_mode_to_exif_value (const gchar * str)
130 {
131   if (str == NULL)
132     goto end;
133 
134   if (strcmp (str, "auto-exposure") == 0)
135     return 0;
136   else if (strcmp (str, "manual-exposure") == 0)
137     return 1;
138   else if (strcmp (str, "auto-bracket") == 0)
139     return 2;
140 
141 end:
142   GST_WARNING ("Invalid capture exposure mode tag: %s", str);
143   return -1;
144 }
145 
146 static gint
__exif_tag_capture_scene_capture_type_to_exif_value(const gchar * str)147 __exif_tag_capture_scene_capture_type_to_exif_value (const gchar * str)
148 {
149   if (str == NULL)
150     goto end;
151 
152   if (strcmp (str, "standard") == 0)
153     return 0;
154   else if (strcmp (str, "landscape") == 0)
155     return 1;
156   else if (strcmp (str, "portrait") == 0)
157     return 2;
158   else if (strcmp (str, "night-scene") == 0)
159     return 3;
160 
161 end:
162   GST_WARNING ("Invalid capture scene capture type: %s", str);
163   return -1;
164 }
165 
166 static gint
__exif_tag_capture_gain_adjustment_to_exif_value(const gchar * str)167 __exif_tag_capture_gain_adjustment_to_exif_value (const gchar * str)
168 {
169   if (str == NULL)
170     goto end;
171 
172   if (strcmp (str, "none") == 0)
173     return 0;
174   else if (strcmp (str, "low-gain-up") == 0)
175     return 1;
176   else if (strcmp (str, "high-gain-up") == 0)
177     return 2;
178   else if (strcmp (str, "low-gain-down") == 0)
179     return 3;
180   else if (strcmp (str, "high-gain-down") == 0)
181     return 4;
182 
183 end:
184   GST_WARNING ("Invalid capture gain adjustment type: %s", str);
185   return -1;
186 }
187 
188 static gint
__exif_tag_capture_white_balance_to_exif_value(const gchar * str)189 __exif_tag_capture_white_balance_to_exif_value (const gchar * str)
190 {
191   if (str == NULL)
192     goto end;
193 
194   if (strcmp (str, "auto") == 0)
195     return 0;
196   else                          /* everything else is just manual */
197     return 1;
198 
199 end:
200   GST_WARNING ("Invalid white balance: %s", str);
201   return -1;
202 }
203 
204 static gint
__exif_tag_capture_contrast_to_exif_value(const gchar * str)205 __exif_tag_capture_contrast_to_exif_value (const gchar * str)
206 {
207   if (str == NULL)
208     goto end;
209 
210   if (strcmp (str, "normal") == 0)
211     return 0;
212   else if (strcmp (str, "soft") == 0)
213     return 1;
214   else if (strcmp (str, "hard") == 0)
215     return 2;
216 
217 end:
218   GST_WARNING ("Invalid contrast type: %s", str);
219   return -1;
220 }
221 
222 static gint
__exif_tag_capture_sharpness_to_exif_value(const gchar * str)223 __exif_tag_capture_sharpness_to_exif_value (const gchar * str)
224 {
225   if (str == NULL)
226     goto end;
227 
228   if (strcmp (str, "normal") == 0)
229     return 0;
230   else if (strcmp (str, "soft") == 0)
231     return 1;
232   else if (strcmp (str, "hard") == 0)
233     return 2;
234 
235 end:
236   GST_WARNING ("Invalid sharpness type: %s", str);
237   return -1;
238 }
239 
240 static gint
__exif_tag_capture_saturation_to_exif_value(const gchar * str)241 __exif_tag_capture_saturation_to_exif_value (const gchar * str)
242 {
243   if (str == NULL)
244     goto end;
245 
246   if (strcmp (str, "normal") == 0)
247     return 0;
248   else if (strcmp (str, "low-saturation") == 0)
249     return 1;
250   else if (strcmp (str, "high-saturation") == 0)
251     return 2;
252 
253 end:
254   GST_WARNING ("Invalid saturation type: %s", str);
255   return -1;
256 }
257 
258 static gint
__exif_tag_capture_metering_mode_to_exif_value(const gchar * str)259 __exif_tag_capture_metering_mode_to_exif_value (const gchar * str)
260 {
261   if (str == NULL)
262     goto end;
263 
264   if (strcmp (str, "unknown") == 0)
265     return 0;
266   else if (strcmp (str, "average") == 0)
267     return 1;
268   else if (strcmp (str, "center-weighted-average") == 0)
269     return 2;
270   else if (strcmp (str, "spot") == 0)
271     return 3;
272   else if (strcmp (str, "multi-spot") == 0)
273     return 4;
274   else if (strcmp (str, "pattern") == 0)
275     return 5;
276   else if (strcmp (str, "partial") == 0)
277     return 6;
278   else if (strcmp (str, "other") == 0)
279     return 255;
280 
281 end:
282   GST_WARNING ("Invalid metering mode type: %s", str);
283   return -1;
284 }
285 
286 static gint
__exif_tag_capture_source_to_exif_value(const gchar * str)287 __exif_tag_capture_source_to_exif_value (const gchar * str)
288 {
289   if (str == NULL)
290     goto end;
291 
292   if (strcmp (str, "dsc") == 0)
293     return 3;
294   else if (strcmp (str, "other") == 0)
295     return 0;
296   else if (strcmp (str, "transparent-scanner") == 0)
297     return 1;
298   else if (strcmp (str, "reflex-scanner") == 0)
299     return 2;
300 
301 end:
302   GST_WARNING ("Invalid capturing source type: %s", str);
303   return -1;
304 }
305 
306 #define GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC(gst_tag,name)           \
307 static void                                                                   \
308 compare_ ## name (ExifEntry * entry, ExifTagCheckData * testdata)             \
309 {                                                                             \
310   gchar *str_tag = NULL;                                                      \
311   gint exif_value = -1;                                                       \
312   gint value = -1;                                                            \
313                                                                               \
314   if (!gst_tag_list_get_string_index (testdata->taglist,                      \
315           gst_tag, 0, &str_tag)) {                                            \
316     /* fail the test if we can't get the tag */                               \
317     fail ("Failed to get %s from taglist", gst_tag);                          \
318   }                                                                           \
319                                                                               \
320   value = __exif_tag_ ## name ## _to_exif_value (str_tag);                    \
321                                                                               \
322   if (value == -1) {                                                          \
323     fail ("Invalid %s tag value: %s", gst_tag, str_tag);                      \
324   }                                                                           \
325                                                                               \
326   if (entry->format == EXIF_TYPE_SHORT)                                       \
327     exif_value = (gint) exif_get_short (entry->data,                          \
328         exif_data_get_byte_order (entry->parent->parent));                    \
329   else if (entry->format == EXIF_TYPE_UNDEFINED)                              \
330     exif_value = (gint) entry->data[0];                                       \
331                                                                               \
332   if (value != exif_value) {                                                  \
333     fail ("Gstreamer tag value (%d) is different from libexif (%d)",          \
334         value, exif_value);                                                   \
335   }                                                                           \
336                                                                               \
337   testdata->result = TRUE;                                                    \
338                                                                               \
339   g_free (str_tag);                                                           \
340 }
341 
342 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC (GST_TAG_IMAGE_ORIENTATION,
343     image_orientation);
344 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC
345     (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, capture_exposure_program);
346 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC (GST_TAG_CAPTURING_EXPOSURE_MODE,
347     capture_exposure_mode);
348 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC (GST_TAG_CAPTURING_WHITE_BALANCE,
349     capture_white_balance);
350 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC (GST_TAG_CAPTURING_CONTRAST,
351     capture_contrast);
352 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC
353     (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, capture_gain_adjustment);
354 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC (GST_TAG_CAPTURING_SATURATION,
355     capture_saturation);
356 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC
357     (GST_TAG_CAPTURING_SHARPNESS, capture_sharpness);
358 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC
359     (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, capture_scene_capture_type);
360 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC
361     (GST_TAG_CAPTURING_METERING_MODE, capture_metering_mode);
362 GST_COMPARE_GST_STRING_TAG_TO_EXIF_SHORT_FUNC
363     (GST_TAG_CAPTURING_SOURCE, capture_source);
364 
365 static void
compare_date_time(ExifEntry * entry,ExifTagCheckData * testdata)366 compare_date_time (ExifEntry * entry, ExifTagCheckData * testdata)
367 {
368   gint year = 0, month = 1, day = 1, hour = 0, minute = 0, second = 0;
369   GstDateTime *exif_datetime;
370   GstDateTime *datetime;
371   const gchar *str;
372 
373   if (!gst_tag_list_get_date_time_index (testdata->taglist, GST_TAG_DATE_TIME,
374           0, &datetime)) {
375     GST_WARNING ("Failed to get datetime from taglist");
376     return;
377   }
378 
379   str = (gchar *) entry->data;
380 
381   sscanf (str, "%04d:%02d:%02d %02d:%02d:%02d", &year, &month, &day,
382       &hour, &minute, &second);
383   exif_datetime = gst_date_time_new_local_time (year, month, day, hour, minute,
384       second);
385   fail_if (exif_datetime == NULL);
386 
387   fail_unless (gst_date_time_get_year (datetime) ==
388       gst_date_time_get_year (exif_datetime)
389       && gst_date_time_get_month (datetime) ==
390       gst_date_time_get_month (exif_datetime)
391       && gst_date_time_get_day (datetime) ==
392       gst_date_time_get_day (exif_datetime)
393       && gst_date_time_get_hour (datetime) ==
394       gst_date_time_get_hour (exif_datetime)
395       && gst_date_time_get_minute (datetime) ==
396       gst_date_time_get_minute (exif_datetime)
397       && gst_date_time_get_second (datetime) ==
398       gst_date_time_get_second (exif_datetime));
399 
400   gst_date_time_unref (exif_datetime);
401   gst_date_time_unref (datetime);
402 
403   testdata->result = TRUE;
404 }
405 
406 static void
compare_shutter_speed(ExifEntry * entry,ExifTagCheckData * testdata)407 compare_shutter_speed (ExifEntry * entry, ExifTagCheckData * testdata)
408 {
409   gdouble gst_num, exif_num;
410   ExifSRational rational;
411   GValue exif_value = { 0 };
412   const GValue *gst_value = NULL;
413 
414   gst_value = gst_tag_list_get_value_index (testdata->taglist,
415       GST_TAG_CAPTURING_SHUTTER_SPEED, 0);
416   if (gst_value == NULL) {
417     GST_WARNING ("Failed to get shutter-speed from taglist");
418     return;
419   }
420 
421   rational = exif_get_srational (entry->data,
422       exif_data_get_byte_order (entry->parent->parent));
423 
424   g_value_init (&exif_value, GST_TYPE_FRACTION);
425   gst_value_set_fraction (&exif_value, rational.numerator,
426       rational.denominator);
427   gst_util_fraction_to_double (gst_value_get_fraction_numerator (&exif_value),
428       gst_value_get_fraction_denominator (&exif_value), &exif_num);
429   g_value_unset (&exif_value);
430 
431   gst_util_fraction_to_double (gst_value_get_fraction_numerator (gst_value),
432       gst_value_get_fraction_denominator (gst_value), &gst_num);
433 
434   exif_num = pow (2, -exif_num);
435 
436   GST_LOG ("Shutter speed in gst=%lf and in exif=%lf", gst_num, exif_num);
437   fail_unless (ABS (gst_num - exif_num) < 0.001);
438   testdata->result = TRUE;
439 }
440 
441 static void
compare_aperture_value(ExifEntry * entry,ExifTagCheckData * testdata)442 compare_aperture_value (ExifEntry * entry, ExifTagCheckData * testdata)
443 {
444   gdouble gst_value, exif_value;
445   ExifSRational rational;
446   GValue value = { 0 };
447 
448   if (!gst_tag_list_get_double_index (testdata->taglist,
449           GST_TAG_CAPTURING_FOCAL_RATIO, 0, &gst_value)) {
450     GST_WARNING ("Failed to get focal ratio from taglist");
451     return;
452   }
453 
454   rational = exif_get_srational (entry->data,
455       exif_data_get_byte_order (entry->parent->parent));
456 
457   g_value_init (&value, GST_TYPE_FRACTION);
458   gst_value_set_fraction (&value, rational.numerator, rational.denominator);
459   gst_util_fraction_to_double (gst_value_get_fraction_numerator (&value),
460       gst_value_get_fraction_denominator (&value), &exif_value);
461   g_value_unset (&value);
462 
463   exif_value = pow (2, exif_value / 2);
464 
465   GST_LOG ("Aperture value in gst=%lf and in exif=%lf", gst_value, exif_value);
466   fail_unless (ABS (gst_value - exif_value) < 0.001);
467   testdata->result = TRUE;
468 }
469 
470 static void
compare_flash(ExifEntry * entry,ExifTagCheckData * testdata)471 compare_flash (ExifEntry * entry, ExifTagCheckData * testdata)
472 {
473   guint16 flags;
474   gboolean flash_fired;
475   const gchar *flash_mode;
476 
477   flags = (gint) exif_get_short (entry->data,
478       exif_data_get_byte_order (entry->parent->parent));
479 
480   if (!gst_tag_list_get_boolean_index (testdata->taglist,
481           GST_TAG_CAPTURING_FLASH_FIRED, 0, &flash_fired)) {
482     GST_WARNING ("Failed to get %s tag", GST_TAG_CAPTURING_FLASH_FIRED);
483     return;
484   }
485   if (!gst_tag_list_peek_string_index (testdata->taglist,
486           GST_TAG_CAPTURING_FLASH_MODE, 0, &flash_mode)) {
487     GST_WARNING ("Failed to get %s tag", GST_TAG_CAPTURING_FLASH_MODE);
488     return;
489   }
490 
491   if (flash_fired)
492     fail_unless ((flags & 1) == 1);
493   else
494     fail_unless ((flags & 1) == 0);
495 
496   if (strcmp (flash_mode, "auto") == 0) {
497     fail_unless (((flags >> 3) & 0x3) == 3);
498   } else if (strcmp (flash_mode, "always") == 0) {
499     fail_unless (((flags >> 3) & 0x3) == 1);
500   } else if (strcmp (flash_mode, "never") == 0) {
501     fail_unless (((flags >> 3) & 0x3) == 2);
502   } else {
503     fail ("unexpected flash mode");
504   }
505   testdata->result = TRUE;
506 }
507 
508 static void
compare_geo_elevation(ExifEntry * entry,ExifTagCheckData * testdata)509 compare_geo_elevation (ExifEntry * entry, ExifTagCheckData * testdata)
510 {
511   gdouble altitude = 0, gst_value;
512   ExifRational rational;
513 
514   fail_unless (gst_tag_list_get_double_index (testdata->taglist,
515           GST_TAG_GEO_LOCATION_ELEVATION, 0, &gst_value));
516 
517   fail_unless (entry->components == 1);
518 
519   rational = exif_get_rational (entry->data,
520       exif_data_get_byte_order (entry->parent->parent));
521   gst_util_fraction_to_double (rational.numerator, rational.denominator,
522       &altitude);
523 
524   gst_value = ABS (gst_value);
525   fail_unless (ABS (gst_value - altitude) < 0.001);
526   testdata->result = TRUE;
527 }
528 
529 static void
compare_geo_elevation_ref(ExifEntry * entry,ExifTagCheckData * testdata)530 compare_geo_elevation_ref (ExifEntry * entry, ExifTagCheckData * testdata)
531 {
532   gdouble gst_value;
533 
534   fail_unless (gst_tag_list_get_double_index (testdata->taglist,
535           GST_TAG_GEO_LOCATION_ELEVATION, 0, &gst_value));
536 
537   fail_unless (entry->components == 1);
538 
539   if (gst_value >= 0) {
540     fail_unless (entry->data[0] == 0);
541   } else {
542     fail_unless (entry->data[0] == 1);
543   }
544   testdata->result = TRUE;
545 }
546 
547 static void
compare_speed(ExifEntry * entry,ExifTagCheckData * testdata)548 compare_speed (ExifEntry * entry, ExifTagCheckData * testdata)
549 {
550   gdouble speed = 0, gst_value;
551   ExifRational rational;
552 
553   fail_unless (gst_tag_list_get_double_index (testdata->taglist,
554           GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, 0, &gst_value));
555 
556   fail_unless (entry->components == 1);
557 
558   rational = exif_get_rational (entry->data,
559       exif_data_get_byte_order (entry->parent->parent));
560   gst_util_fraction_to_double (rational.numerator, rational.denominator,
561       &speed);
562 
563   speed = speed / 3.6;
564 
565   fail_unless (ABS (gst_value - speed) < 0.001);
566   testdata->result = TRUE;
567 }
568 
569 static void
compare_speed_ref(ExifEntry * entry,ExifTagCheckData * testdata)570 compare_speed_ref (ExifEntry * entry, ExifTagCheckData * testdata)
571 {
572   fail_unless (entry->components == 2);
573   fail_unless (entry->data[0] == 'K');
574   testdata->result = TRUE;
575 }
576 
577 static void
578 compare_geo_coordinate (ExifEntry * entry, ExifTagCheckData * testdata);
579 
580 static void
581 compare_geo_coordinate_ref (ExifEntry * entry, ExifTagCheckData * testdata);
582 
583 static void
584 compare_geo_direction (ExifEntry * entry, ExifTagCheckData * testdata);
585 
586 static void
587 compare_geo_direction_ref (ExifEntry * entry, ExifTagCheckData * testdata);
588 
589 static const GstExifTagMatch tag_map[] = {
590   {GST_TAG_DESCRIPTION, EXIF_TAG_IMAGE_DESCRIPTION, EXIF_TYPE_ASCII,
591       NULL},
592   {GST_TAG_DEVICE_MANUFACTURER, EXIF_TAG_MAKE, EXIF_TYPE_ASCII,
593       NULL},
594   {GST_TAG_DEVICE_MODEL, EXIF_TAG_MODEL, EXIF_TYPE_ASCII, NULL},
595   {GST_TAG_IMAGE_ORIENTATION, EXIF_TAG_ORIENTATION, EXIF_TYPE_SHORT,
596       compare_image_orientation},
597   {GST_TAG_IMAGE_HORIZONTAL_PPI, EXIF_TAG_X_RESOLUTION, EXIF_TYPE_RATIONAL,
598       NULL},
599   {GST_TAG_IMAGE_VERTICAL_PPI, EXIF_TAG_Y_RESOLUTION, EXIF_TYPE_RATIONAL, NULL},
600   {GST_TAG_APPLICATION_NAME, EXIF_TAG_SOFTWARE, EXIF_TYPE_ASCII,
601       NULL},
602   {GST_TAG_DATE_TIME, EXIF_TAG_DATE_TIME, EXIF_TYPE_ASCII,
603       compare_date_time},
604   {GST_TAG_ARTIST, EXIF_TAG_ARTIST, EXIF_TYPE_ASCII, NULL},
605   {GST_TAG_COPYRIGHT, EXIF_TAG_COPYRIGHT, EXIF_TYPE_ASCII, NULL},
606   {GST_TAG_CAPTURING_SHUTTER_SPEED, EXIF_TAG_EXPOSURE_TIME,
607       EXIF_TYPE_RATIONAL, NULL},
608   {GST_TAG_CAPTURING_FOCAL_RATIO, EXIF_TAG_FNUMBER, EXIF_TYPE_RATIONAL,
609       NULL},
610   {GST_TAG_CAPTURING_EXPOSURE_PROGRAM, EXIF_TAG_EXPOSURE_PROGRAM,
611       EXIF_TYPE_SHORT, compare_capture_exposure_program},
612 
613   /* This is called PhotographicSensitivity in 2.3 */
614   {GST_TAG_CAPTURING_ISO_SPEED, EXIF_TAG_ISO_SPEED_RATINGS,
615       EXIF_TYPE_SHORT, NULL},
616 
617   {GST_TAG_CAPTURING_SHUTTER_SPEED, EXIF_TAG_SHUTTER_SPEED_VALUE,
618       EXIF_TYPE_SRATIONAL, compare_shutter_speed},
619   {GST_TAG_CAPTURING_FOCAL_RATIO, EXIF_TAG_APERTURE_VALUE, EXIF_TYPE_RATIONAL,
620       compare_aperture_value},
621   {GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, EXIF_TAG_EXPOSURE_BIAS_VALUE,
622       EXIF_TYPE_SRATIONAL},
623   {GST_TAG_CAPTURING_FLASH_FIRED, EXIF_TAG_FLASH, EXIF_TYPE_SHORT,
624       compare_flash},
625   {GST_TAG_CAPTURING_FLASH_MODE, EXIF_TAG_FLASH, EXIF_TYPE_SHORT,
626       compare_flash},
627   {GST_TAG_CAPTURING_FOCAL_LENGTH, EXIF_TAG_FOCAL_LENGTH, EXIF_TYPE_RATIONAL,
628       NULL},
629   {GST_TAG_APPLICATION_DATA, EXIF_TAG_MAKER_NOTE, EXIF_TYPE_UNDEFINED, NULL},
630   {GST_TAG_CAPTURING_EXPOSURE_MODE, EXIF_TAG_EXPOSURE_MODE, EXIF_TYPE_SHORT,
631       compare_capture_exposure_mode},
632   {GST_TAG_CAPTURING_WHITE_BALANCE, EXIF_TAG_WHITE_BALANCE, EXIF_TYPE_SHORT,
633       compare_capture_white_balance},
634   {GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, EXIF_TAG_DIGITAL_ZOOM_RATIO,
635       EXIF_TYPE_RATIONAL, NULL},
636   {GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, EXIF_TAG_SCENE_CAPTURE_TYPE,
637       EXIF_TYPE_SHORT, compare_capture_scene_capture_type},
638   {GST_TAG_CAPTURING_GAIN_ADJUSTMENT, EXIF_TAG_GAIN_CONTROL,
639       EXIF_TYPE_SHORT, compare_capture_gain_adjustment},
640   {GST_TAG_CAPTURING_CONTRAST, EXIF_TAG_CONTRAST, EXIF_TYPE_SHORT,
641       compare_capture_contrast},
642   {GST_TAG_CAPTURING_SATURATION, EXIF_TAG_SATURATION, EXIF_TYPE_SHORT,
643       compare_capture_saturation},
644   {GST_TAG_CAPTURING_SHARPNESS, EXIF_TAG_SHARPNESS, EXIF_TYPE_SHORT,
645       compare_capture_sharpness},
646   {GST_TAG_CAPTURING_METERING_MODE, EXIF_TAG_METERING_MODE, EXIF_TYPE_SHORT,
647       compare_capture_metering_mode},
648   {GST_TAG_CAPTURING_SOURCE, EXIF_TAG_FILE_SOURCE, EXIF_TYPE_UNDEFINED,
649       compare_capture_source},
650 
651   /* gps tags */
652   {GST_TAG_GEO_LOCATION_LATITUDE, EXIF_TAG_GPS_LATITUDE, EXIF_TYPE_RATIONAL,
653       compare_geo_coordinate},
654   {GST_TAG_GEO_LOCATION_LATITUDE, EXIF_TAG_GPS_LATITUDE_REF, EXIF_TYPE_ASCII,
655       compare_geo_coordinate_ref},
656   {GST_TAG_GEO_LOCATION_LONGITUDE, EXIF_TAG_GPS_LONGITUDE, EXIF_TYPE_RATIONAL,
657       compare_geo_coordinate},
658   {GST_TAG_GEO_LOCATION_LONGITUDE, EXIF_TAG_GPS_LONGITUDE_REF, EXIF_TYPE_ASCII,
659       compare_geo_coordinate_ref},
660   {GST_TAG_GEO_LOCATION_ELEVATION, EXIF_TAG_GPS_ALTITUDE, EXIF_TYPE_RATIONAL,
661       compare_geo_elevation},
662   {GST_TAG_GEO_LOCATION_ELEVATION, EXIF_TAG_GPS_ALTITUDE_REF, EXIF_TYPE_BYTE,
663       compare_geo_elevation_ref},
664   {GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, EXIF_TAG_GPS_SPEED, EXIF_TYPE_RATIONAL,
665       compare_speed},
666   {GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, EXIF_TAG_GPS_SPEED_REF, EXIF_TYPE_ASCII,
667       compare_speed_ref},
668   {GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, EXIF_TAG_GPS_TRACK,
669       EXIF_TYPE_RATIONAL, compare_geo_direction},
670   {GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, EXIF_TAG_GPS_TRACK_REF,
671       EXIF_TYPE_ASCII, compare_geo_direction_ref},
672   {GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, EXIF_TAG_GPS_IMG_DIRECTION,
673       EXIF_TYPE_RATIONAL, compare_geo_direction},
674   {GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, EXIF_TAG_GPS_IMG_DIRECTION_REF,
675       EXIF_TYPE_ASCII, compare_geo_direction_ref}
676 
677 /*
678  * libexif doesn't have these tags
679  *  {GST_TAG_CAPTURING_ISO_SPEED, EXIF_TAG_ISO_SPEED, EXIF_TYPE_LONG, NULL},
680  *  {GST_TAG_CAPTURING_ISO_SPEED, EXIF_TAG_SENSITIVITY_TYPE,
681  *     EXIF_TYPE_SHORT, compare_sensitivity_type},
682  */
683 };
684 
685 static void
compare_geo_coordinate(ExifEntry * entry,ExifTagCheckData * testdata)686 compare_geo_coordinate (ExifEntry * entry, ExifTagCheckData * testdata)
687 {
688   gdouble coordinate = 0, aux, gst_value;
689   ExifRational rational;
690 
691   fail_unless (gst_tag_list_get_double_index (testdata->taglist,
692           tag_map[testdata->map_index].gst_tag, 0, &gst_value));
693 
694   fail_unless (entry->components == 3);
695 
696   rational = exif_get_rational (entry->data,
697       exif_data_get_byte_order (entry->parent->parent));
698   gst_util_fraction_to_double (rational.numerator, rational.denominator, &aux);
699   coordinate += aux;
700 
701   rational = exif_get_rational (entry->data + 8,
702       exif_data_get_byte_order (entry->parent->parent));
703   gst_util_fraction_to_double (rational.numerator, rational.denominator, &aux);
704   coordinate += aux / 60.0;
705 
706   rational = exif_get_rational (entry->data + 16,
707       exif_data_get_byte_order (entry->parent->parent));
708   gst_util_fraction_to_double (rational.numerator, rational.denominator, &aux);
709   coordinate += aux / 3600.0;
710 
711   gst_value = ABS (gst_value);
712   fail_unless (ABS (gst_value - coordinate) < 0.001);
713   testdata->result = TRUE;
714 }
715 
716 static void
compare_geo_coordinate_ref(ExifEntry * entry,ExifTagCheckData * testdata)717 compare_geo_coordinate_ref (ExifEntry * entry, ExifTagCheckData * testdata)
718 {
719   gdouble gst_value;
720   const gchar *tag;
721 
722   tag = tag_map[testdata->map_index].gst_tag;
723 
724   fail_unless (gst_tag_list_get_double_index (testdata->taglist, tag, 0,
725           &gst_value));
726 
727   fail_unless (entry->components == 2);
728 
729   if (strcmp (tag, GST_TAG_GEO_LOCATION_LATITUDE) == 0) {
730     if (gst_value >= 0) {
731       fail_unless (entry->data[0] == 'N');
732     } else {
733       fail_unless (entry->data[0] == 'S');
734     }
735   } else {
736     if (gst_value >= 0) {
737       fail_unless (entry->data[0] == 'E');
738     } else {
739       fail_unless (entry->data[0] == 'W');
740     }
741   }
742   testdata->result = TRUE;
743 }
744 
745 static void
compare_geo_direction(ExifEntry * entry,ExifTagCheckData * testdata)746 compare_geo_direction (ExifEntry * entry, ExifTagCheckData * testdata)
747 {
748   gdouble direction = 0, gst_value;
749   ExifRational rational;
750 
751   fail_unless (gst_tag_list_get_double_index (testdata->taglist,
752           tag_map[testdata->map_index].gst_tag, 0, &gst_value));
753 
754   fail_unless (entry->components == 1);
755 
756   rational = exif_get_rational (entry->data,
757       exif_data_get_byte_order (entry->parent->parent));
758   gst_util_fraction_to_double (rational.numerator, rational.denominator,
759       &direction);
760 
761   fail_unless (ABS (gst_value - direction) < 0.001);
762   testdata->result = TRUE;
763 }
764 
765 static void
compare_geo_direction_ref(ExifEntry * entry,ExifTagCheckData * testdata)766 compare_geo_direction_ref (ExifEntry * entry, ExifTagCheckData * testdata)
767 {
768   fail_unless (entry->components == 2);
769   fail_unless (entry->data[0] == 'T');
770   testdata->result = TRUE;
771 }
772 
773 static void
check_content(ExifContent * content,void * user_data)774 check_content (ExifContent * content, void *user_data)
775 {
776   ExifTagCheckData *test_data = (ExifTagCheckData *) user_data;
777   guint16 tagindex;
778   ExifEntry *entry;
779   GType gst_tag_type;
780 
781   tagindex = test_data->map_index;
782   gst_tag_type = gst_tag_get_type (tag_map[tagindex].gst_tag);
783 
784   GST_DEBUG ("Got tagindex %u for gsttag %s with type %s", tagindex,
785       tag_map[tagindex].gst_tag, g_type_name (gst_tag_type));
786 
787   /* search for the entry */
788   entry = exif_content_get_entry (content, tag_map[tagindex].exif_tag);
789   GST_DEBUG ("Entry found at %p", entry);
790   if (entry == NULL)
791     return;
792 
793   fail_unless (entry->format == tag_map[tagindex].exif_type);
794 
795   if (tag_map[tagindex].compare_func) {
796     tag_map[tagindex].compare_func (entry, test_data);
797     return;
798   }
799 
800   switch (entry->format) {
801     case EXIF_TYPE_ASCII:{
802       const gchar *str;
803       gchar *taglist_str;
804 
805       str = (gchar *) entry->data;
806       fail_unless (gst_tag_list_get_string (test_data->taglist,
807               tag_map[tagindex].gst_tag, &taglist_str));
808 
809       fail_unless (strcmp (str, taglist_str) == 0);
810       test_data->result = TRUE;
811       g_free (taglist_str);
812     }
813       break;
814     case EXIF_TYPE_SRATIONAL:
815     case EXIF_TYPE_RATIONAL:{
816       GValue exif_value = { 0 };
817 
818       g_value_init (&exif_value, GST_TYPE_FRACTION);
819       if (entry->format == EXIF_TYPE_RATIONAL) {
820         ExifRational exif_rational = exif_get_rational (entry->data,
821             exif_data_get_byte_order (entry->parent->parent));
822 
823         gst_value_set_fraction (&exif_value, exif_rational.numerator,
824             exif_rational.denominator);
825       } else {
826         ExifSRational exif_rational = exif_get_srational (entry->data,
827             exif_data_get_byte_order (entry->parent->parent));
828 
829         gst_value_set_fraction (&exif_value, exif_rational.numerator,
830             exif_rational.denominator);
831       }
832 
833       if (gst_tag_type == GST_TYPE_FRACTION) {
834         const GValue *value = gst_tag_list_get_value_index (test_data->taglist,
835             tag_map[tagindex].gst_tag, 0);
836 
837         fail_unless (value != NULL);
838         fail_unless (G_VALUE_TYPE (value) == GST_TYPE_FRACTION);
839 
840         fail_unless (gst_value_get_fraction_numerator (value) ==
841             gst_value_get_fraction_numerator (&exif_value) &&
842             gst_value_get_fraction_denominator (value) ==
843             gst_value_get_fraction_denominator (&exif_value));
844 
845         test_data->result = TRUE;
846       } else if (gst_tag_type == G_TYPE_DOUBLE) {
847         gdouble gst_num;
848         gdouble exif_num;
849 
850         gst_util_fraction_to_double (gst_value_get_fraction_numerator
851             (&exif_value), gst_value_get_fraction_denominator (&exif_value),
852             &exif_num);
853 
854         fail_unless (gst_tag_list_get_double_index (test_data->taglist,
855                 tag_map[tagindex].gst_tag, 0, &gst_num));
856 
857         fail_unless (gst_num == exif_num);
858         test_data->result = TRUE;
859       } else {
860         GST_WARNING ("Unhandled type for rational tag(%X): %s",
861             entry->tag, g_type_name (gst_tag_type));
862       }
863       g_value_unset (&exif_value);
864     }
865       break;
866     case EXIF_TYPE_SHORT:
867     case EXIF_TYPE_LONG:{
868       gint gst_num;
869       gint exif_num = -1;
870 
871       if (entry->format == EXIF_TYPE_LONG) {
872         exif_num = (gint) exif_get_long (entry->data,
873             exif_data_get_byte_order (entry->parent->parent));
874       } else if (entry->format == EXIF_TYPE_SHORT) {
875         exif_num = (gint) exif_get_short (entry->data,
876             exif_data_get_byte_order (entry->parent->parent));
877       }
878 
879       fail_unless (gst_tag_list_get_int_index (test_data->taglist,
880               tag_map[tagindex].gst_tag, 0, &gst_num));
881 
882       fail_unless (exif_num == gst_num);
883       test_data->result = TRUE;
884     }
885       break;
886     case EXIF_TYPE_UNDEFINED:{
887       GstMapInfo map;
888       GstBuffer *buf;
889       GstSample *sample;
890       gint i;
891 
892       if (!gst_tag_list_get_sample_index (test_data->taglist,
893               tag_map[tagindex].gst_tag, 0, &sample)) {
894         return;
895       }
896       buf = gst_sample_get_buffer (sample);
897       gst_buffer_map (buf, &map, GST_MAP_READ);
898       fail_unless (entry->size, map.size);
899       for (i = 0; i < map.size; i++) {
900         fail_unless (map.data[i] == (guint8) entry->data[i]);
901       }
902       gst_buffer_unmap (buf, &map);
903 
904       test_data->result = TRUE;
905       gst_sample_unref (sample);
906     }
907       break;
908     default:
909       fail ("unexpected exif type %d", entry->format);
910   }
911 }
912 
913 /*
914  * Iterates over the exif data searching for the mapping pointed by index
915  */
916 static void
libexif_check_tag_exists(const GstTagList * taglist,gint index,gpointer data)917 libexif_check_tag_exists (const GstTagList * taglist, gint index, gpointer data)
918 {
919   ExifData *exif_data = (ExifData *) data;
920   ExifTagCheckData test_data;
921 
922   test_data.result = FALSE;
923   test_data.taglist = taglist;
924   test_data.map_index = index;
925 
926   exif_data_foreach_content (exif_data, check_content, &test_data);
927 
928   fail_unless (test_data.result);
929 }
930 
931 static void
generate_jif_file_with_tags_from_taglist(GstTagList * taglist,const gchar * filepath)932 generate_jif_file_with_tags_from_taglist (GstTagList * taglist,
933     const gchar * filepath)
934 {
935   GstElement *pipeline;
936   GstBus *bus;
937   GstMessage *msg;
938   gchar *launchline;
939   GstElement *jifmux;
940   GstTagSetter *setter;
941 
942   launchline = g_strdup_printf ("videotestsrc num-buffers=1 ! jpegenc ! "
943       "jifmux name=jifmux0 ! filesink location=%s", filepath);
944 
945   pipeline = gst_parse_launch (launchline, NULL);
946   fail_unless (pipeline != NULL);
947   g_free (launchline);
948 
949   jifmux = gst_bin_get_by_name (GST_BIN (pipeline), "jifmux0");
950   fail_unless (jifmux != NULL);
951   setter = GST_TAG_SETTER (jifmux);
952   gst_tag_setter_merge_tags (setter, taglist, GST_TAG_MERGE_REPLACE);
953   gst_object_unref (jifmux);
954 
955   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
956 
957   fail_if (gst_element_set_state (pipeline, GST_STATE_PLAYING) ==
958       GST_STATE_CHANGE_FAILURE);
959 
960   msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10, GST_MESSAGE_EOS |
961       GST_MESSAGE_ERROR);
962   fail_if (!msg);
963   fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
964 
965   gst_message_unref (msg);
966   gst_object_unref (bus);
967   gst_element_set_state (pipeline, GST_STATE_NULL);
968   gst_object_unref (pipeline);
969 }
970 
971 static void
generate_jif_file_with_tags(const gchar * tags,const gchar * filepath)972 generate_jif_file_with_tags (const gchar * tags, const gchar * filepath)
973 {
974   GstTagList *taglist;
975 
976   taglist = gst_tag_list_new_from_string (tags);
977   generate_jif_file_with_tags_from_taglist (taglist, filepath);
978 
979   gst_tag_list_unref (taglist);
980 }
981 
982 static void
libexif_check_tags_from_taglist(GstTagList * taglist,const gchar * filepath)983 libexif_check_tags_from_taglist (GstTagList * taglist, const gchar * filepath)
984 {
985   ExifData *exif_data;
986   gint i;
987 
988   fail_unless (taglist != NULL);
989   exif_data = exif_data_new_from_file (filepath);
990 
991   /* iterate over our tag mapping */
992   for (i = 0; i < G_N_ELEMENTS (tag_map); i++) {
993     if (gst_tag_list_get_value_index (taglist, tag_map[i].gst_tag, 0)) {
994       /* we have added this field to the taglist, check if it was writen in
995        * exif */
996       libexif_check_tag_exists (taglist, i, exif_data);
997     }
998   }
999 
1000   exif_data_unref (exif_data);
1001 }
1002 
1003 static void
libexif_check_tags(const gchar * tags,const gchar * filepath)1004 libexif_check_tags (const gchar * tags, const gchar * filepath)
1005 {
1006   GstTagList *taglist;
1007 
1008   taglist = gst_tag_list_new_from_string (tags);
1009   fail_unless (taglist != NULL);
1010 
1011   libexif_check_tags_from_taglist (taglist, filepath);
1012 
1013   gst_tag_list_unref (taglist);
1014 }
1015 
GST_START_TEST(test_jifmux_tags)1016 GST_START_TEST (test_jifmux_tags)
1017 {
1018   gchar *tmpfile;
1019   gchar *tmp;
1020   GstTagList *taglist;
1021   GstDateTime *datetime;
1022   GstBuffer *buffer;
1023   GstSample *sample;
1024   GstMapInfo map;
1025   gint i;
1026 
1027   gst_tag_register_musicbrainz_tags ();
1028 
1029   tmp = g_strdup_printf ("%s%d", "gst-check-xmp-test-", g_random_int ());
1030   tmpfile = g_build_filename (g_get_tmp_dir (), tmp, NULL);
1031   g_free (tmp);
1032 
1033   datetime = gst_date_time_new_local_time (2000, 10, 5, 8, 45, 13);
1034   buffer = gst_buffer_new_and_alloc (100);
1035   gst_buffer_map (buffer, &map, GST_MAP_WRITE);
1036   for (i = 0; i < 100; i++) {
1037     map.data[i] = i;
1038   }
1039   gst_buffer_unmap (buffer, &map);
1040 
1041   sample = gst_sample_new (buffer, NULL, NULL, NULL);
1042   gst_buffer_unref (buffer);
1043 
1044   taglist = gst_tag_list_new (GST_TAG_ARTIST, "some artist",
1045       GST_TAG_COPYRIGHT, "My copyright notice",
1046       GST_TAG_DEVICE_MANUFACTURER, "MyFavoriteBrand",
1047       GST_TAG_DEVICE_MODEL, "123v42.1",
1048       GST_TAG_DESCRIPTION, "some description",
1049       GST_TAG_APPLICATION_NAME, "jifmux-test v1.2b",
1050       GST_TAG_CAPTURING_SHUTTER_SPEED, 1, 30,
1051       GST_TAG_CAPTURING_FOCAL_RATIO, 2.0,
1052       GST_TAG_CAPTURING_ISO_SPEED, 800, GST_TAG_DATE_TIME, datetime,
1053       GST_TAG_CAPTURING_FOCAL_LENGTH, 22.5,
1054       GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, 5.25,
1055       GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, -2.5,
1056       GST_TAG_APPLICATION_DATA, sample,
1057       GST_TAG_CAPTURING_FLASH_FIRED, TRUE,
1058       GST_TAG_CAPTURING_FLASH_MODE, "auto",
1059       GST_TAG_CAPTURING_SOURCE, "dsc",
1060       GST_TAG_CAPTURING_METERING_MODE, "multi-spot",
1061       GST_TAG_CAPTURING_SHARPNESS, "normal",
1062       GST_TAG_CAPTURING_SATURATION, "normal",
1063       GST_TAG_CAPTURING_CONTRAST, "normal",
1064       GST_TAG_GEO_LOCATION_LATITUDE, -32.375,
1065       GST_TAG_GEO_LOCATION_LONGITUDE, 76.0125,
1066       GST_TAG_GEO_LOCATION_ELEVATION, 300.85,
1067       GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, 3.6,
1068       GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, 35.4,
1069       GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, 12.345,
1070       GST_TAG_IMAGE_HORIZONTAL_PPI, 300.0,
1071       GST_TAG_IMAGE_VERTICAL_PPI, 96.0, NULL);
1072   gst_date_time_unref (datetime);
1073   gst_sample_unref (sample);
1074   generate_jif_file_with_tags_from_taglist (taglist, tmpfile);
1075   libexif_check_tags_from_taglist (taglist, tmpfile);
1076   gst_tag_list_unref (taglist);
1077 
1078 #define IMAGE_ORIENTATION_TAG(t) "taglist," GST_TAG_IMAGE_ORIENTATION "=" t
1079   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG ("rotate-0"), tmpfile);
1080   libexif_check_tags (IMAGE_ORIENTATION_TAG ("rotate-0"), tmpfile);
1081   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG ("flip-rotate-0"),
1082       tmpfile);
1083   libexif_check_tags (IMAGE_ORIENTATION_TAG ("flip-rotate-0"), tmpfile);
1084   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG ("rotate-180"), tmpfile);
1085   libexif_check_tags (IMAGE_ORIENTATION_TAG ("rotate-180"), tmpfile);
1086   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG ("flip-rotate-180"),
1087       tmpfile);
1088   libexif_check_tags (IMAGE_ORIENTATION_TAG ("flip-rotate-180"), tmpfile);
1089   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG
1090       ("flip-rotate-270"), tmpfile);
1091   libexif_check_tags (IMAGE_ORIENTATION_TAG ("flip-rotate-270"), tmpfile);
1092   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG ("rotate-90"), tmpfile);
1093   libexif_check_tags (IMAGE_ORIENTATION_TAG ("rotate-90"), tmpfile);
1094   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG
1095       ("flip-rotate-90"), tmpfile);
1096   libexif_check_tags (IMAGE_ORIENTATION_TAG ("flip-rotate-90"), tmpfile);
1097   generate_jif_file_with_tags (IMAGE_ORIENTATION_TAG ("rotate-270"), tmpfile);
1098   libexif_check_tags (IMAGE_ORIENTATION_TAG ("rotate-270"), tmpfile);
1099 
1100 #define EXPOSURE_PROGRAM_TAG(t) "taglist," GST_TAG_CAPTURING_EXPOSURE_PROGRAM \
1101     "=" t
1102   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("undefined"), tmpfile);
1103   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("undefined"), tmpfile);
1104   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("manual"), tmpfile);
1105   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("manual"), tmpfile);
1106   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("normal"), tmpfile);
1107   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("normal"), tmpfile);
1108   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("aperture-priority"),
1109       tmpfile);
1110   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("aperture-priority"), tmpfile);
1111   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("shutter-priority"),
1112       tmpfile);
1113   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("shutter-priority"), tmpfile);
1114   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("creative"), tmpfile);
1115   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("creative"), tmpfile);
1116   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("action"), tmpfile);
1117   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("action"), tmpfile);
1118   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("portrait"), tmpfile);
1119   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("portrait"), tmpfile);
1120   generate_jif_file_with_tags (EXPOSURE_PROGRAM_TAG ("landscape"), tmpfile);
1121   libexif_check_tags (EXPOSURE_PROGRAM_TAG ("landscape"), tmpfile);
1122 
1123 #define EXPOSURE_MODE_TAG(t) "taglist," GST_TAG_CAPTURING_EXPOSURE_MODE "=" t
1124   generate_jif_file_with_tags (EXPOSURE_MODE_TAG ("auto-exposure"), tmpfile);
1125   libexif_check_tags (EXPOSURE_MODE_TAG ("auto-exposure"), tmpfile);
1126   generate_jif_file_with_tags (EXPOSURE_MODE_TAG ("manual-exposure"), tmpfile);
1127   libexif_check_tags (EXPOSURE_MODE_TAG ("manual-exposure"), tmpfile);
1128   generate_jif_file_with_tags (EXPOSURE_MODE_TAG ("auto-bracket"), tmpfile);
1129   libexif_check_tags (EXPOSURE_MODE_TAG ("auto-bracket"), tmpfile);
1130 
1131 #define SCENE_CAPTURE_TYPE_TAG(t) "taglist," GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE\
1132     "=" t
1133   generate_jif_file_with_tags (SCENE_CAPTURE_TYPE_TAG ("standard"), tmpfile);
1134   libexif_check_tags (SCENE_CAPTURE_TYPE_TAG ("standard"), tmpfile);
1135   generate_jif_file_with_tags (SCENE_CAPTURE_TYPE_TAG ("landscape"), tmpfile);
1136   libexif_check_tags (SCENE_CAPTURE_TYPE_TAG ("landscape"), tmpfile);
1137   generate_jif_file_with_tags (SCENE_CAPTURE_TYPE_TAG ("portrait"), tmpfile);
1138   libexif_check_tags (SCENE_CAPTURE_TYPE_TAG ("portrait"), tmpfile);
1139   generate_jif_file_with_tags (SCENE_CAPTURE_TYPE_TAG ("night-scene"), tmpfile);
1140   libexif_check_tags (SCENE_CAPTURE_TYPE_TAG ("night-scene"), tmpfile);
1141 
1142 #define WHITE_BALANCE_TAG(t) "taglist," GST_TAG_CAPTURING_WHITE_BALANCE "=" t
1143   generate_jif_file_with_tags (WHITE_BALANCE_TAG ("auto"), tmpfile);
1144   libexif_check_tags (WHITE_BALANCE_TAG ("auto"), tmpfile);
1145   generate_jif_file_with_tags (WHITE_BALANCE_TAG ("manual"), tmpfile);
1146   libexif_check_tags (WHITE_BALANCE_TAG ("manual"), tmpfile);
1147 
1148 #define GAIN_ADJUSTMENT_TAG(t) "taglist," GST_TAG_CAPTURING_GAIN_ADJUSTMENT "=" t
1149   generate_jif_file_with_tags (GAIN_ADJUSTMENT_TAG ("none"), tmpfile);
1150   libexif_check_tags (GAIN_ADJUSTMENT_TAG ("none"), tmpfile);
1151   generate_jif_file_with_tags (GAIN_ADJUSTMENT_TAG ("high-gain-up"), tmpfile);
1152   libexif_check_tags (GAIN_ADJUSTMENT_TAG ("high-gain-up"), tmpfile);
1153   generate_jif_file_with_tags (GAIN_ADJUSTMENT_TAG ("low-gain-up"), tmpfile);
1154   libexif_check_tags (GAIN_ADJUSTMENT_TAG ("low-gain-up"), tmpfile);
1155   generate_jif_file_with_tags (GAIN_ADJUSTMENT_TAG ("high-gain-down"), tmpfile);
1156   libexif_check_tags (GAIN_ADJUSTMENT_TAG ("high-gain-down"), tmpfile);
1157   generate_jif_file_with_tags (GAIN_ADJUSTMENT_TAG ("low-gain-down"), tmpfile);
1158   libexif_check_tags (GAIN_ADJUSTMENT_TAG ("low-gain-down"), tmpfile);
1159 
1160 #define CONTRAST_TAG(t) "taglist," GST_TAG_CAPTURING_CONTRAST "=" t
1161   generate_jif_file_with_tags (CONTRAST_TAG ("normal"), tmpfile);
1162   libexif_check_tags (CONTRAST_TAG ("normal"), tmpfile);
1163   generate_jif_file_with_tags (CONTRAST_TAG ("soft"), tmpfile);
1164   libexif_check_tags (CONTRAST_TAG ("soft"), tmpfile);
1165   generate_jif_file_with_tags (CONTRAST_TAG ("hard"), tmpfile);
1166   libexif_check_tags (CONTRAST_TAG ("hard"), tmpfile);
1167 
1168 #define SATURATION_TAG(t) "taglist," GST_TAG_CAPTURING_SATURATION "=" t
1169   generate_jif_file_with_tags (SATURATION_TAG ("normal"), tmpfile);
1170   libexif_check_tags (SATURATION_TAG ("normal"), tmpfile);
1171   generate_jif_file_with_tags (SATURATION_TAG ("low-saturation"), tmpfile);
1172   libexif_check_tags (SATURATION_TAG ("low-saturation"), tmpfile);
1173   generate_jif_file_with_tags (SATURATION_TAG ("high-saturation"), tmpfile);
1174   libexif_check_tags (SATURATION_TAG ("high-saturation"), tmpfile);
1175 
1176 #define SHARPNESS_TAG(t) "taglist," GST_TAG_CAPTURING_SHARPNESS "=" t
1177   generate_jif_file_with_tags (SHARPNESS_TAG ("normal"), tmpfile);
1178   libexif_check_tags (SHARPNESS_TAG ("normal"), tmpfile);
1179   generate_jif_file_with_tags (SHARPNESS_TAG ("soft"), tmpfile);
1180   libexif_check_tags (SHARPNESS_TAG ("soft"), tmpfile);
1181   generate_jif_file_with_tags (SHARPNESS_TAG ("hard"), tmpfile);
1182   libexif_check_tags (SHARPNESS_TAG ("hard"), tmpfile);
1183 
1184 #define METERING_MODE_TAG(t) "taglist," GST_TAG_CAPTURING_METERING_MODE "=" t
1185   generate_jif_file_with_tags (METERING_MODE_TAG ("unknown"), tmpfile);
1186   libexif_check_tags (METERING_MODE_TAG ("unknown"), tmpfile);
1187   generate_jif_file_with_tags (METERING_MODE_TAG ("average"), tmpfile);
1188   libexif_check_tags (METERING_MODE_TAG ("average"), tmpfile);
1189   generate_jif_file_with_tags (METERING_MODE_TAG ("center-weighted-average"),
1190       tmpfile);
1191   libexif_check_tags (METERING_MODE_TAG ("center-weighted-average"), tmpfile);
1192   generate_jif_file_with_tags (METERING_MODE_TAG ("spot"), tmpfile);
1193   libexif_check_tags (METERING_MODE_TAG ("spot"), tmpfile);
1194   generate_jif_file_with_tags (METERING_MODE_TAG ("multi-spot"), tmpfile);
1195   libexif_check_tags (METERING_MODE_TAG ("multi-spot"), tmpfile);
1196   generate_jif_file_with_tags (METERING_MODE_TAG ("pattern"), tmpfile);
1197   libexif_check_tags (METERING_MODE_TAG ("pattern"), tmpfile);
1198   generate_jif_file_with_tags (METERING_MODE_TAG ("partial"), tmpfile);
1199   libexif_check_tags (METERING_MODE_TAG ("partial"), tmpfile);
1200   generate_jif_file_with_tags (METERING_MODE_TAG ("other"), tmpfile);
1201   libexif_check_tags (METERING_MODE_TAG ("other"), tmpfile);
1202 
1203 #define FILE_SOURCE_TAG(t) "taglist," GST_TAG_CAPTURING_SOURCE "=" t
1204   generate_jif_file_with_tags (FILE_SOURCE_TAG ("dsc"), tmpfile);
1205   libexif_check_tags (FILE_SOURCE_TAG ("dsc"), tmpfile);
1206   generate_jif_file_with_tags (FILE_SOURCE_TAG ("other"), tmpfile);
1207   libexif_check_tags (FILE_SOURCE_TAG ("other"), tmpfile);
1208   generate_jif_file_with_tags (FILE_SOURCE_TAG ("reflex-scanner"), tmpfile);
1209   libexif_check_tags (FILE_SOURCE_TAG ("reflex-scanner"), tmpfile);
1210   generate_jif_file_with_tags (FILE_SOURCE_TAG ("transparent-scanner"),
1211       tmpfile);
1212   libexif_check_tags (FILE_SOURCE_TAG ("transparent-scanner"), tmpfile);
1213 
1214   g_unlink (tmpfile);
1215   g_free (tmpfile);
1216 }
1217 
1218 GST_END_TEST;
1219 
1220 #define HAVE_ELEMENT(name) \
1221   gst_registry_check_feature_version (gst_registry_get (), name,\
1222       GST_VERSION_MAJOR, GST_VERSION_MINOR, 0)
1223 
1224 static Suite *
jifmux_suite(void)1225 jifmux_suite (void)
1226 {
1227   Suite *s = suite_create ("jifmux");
1228   TCase *tc_chain = tcase_create ("general");
1229 
1230   if (HAVE_ELEMENT ("taginject") && HAVE_ELEMENT ("jpegenc")) {
1231     tcase_add_test (tc_chain, test_jifmux_tags);
1232   } else {
1233     GST_WARNING ("jpegenc or taginject element not available, skipping tests");
1234   }
1235 
1236   suite_add_tcase (s, tc_chain);
1237 
1238   return s;
1239 }
1240 
1241 GST_CHECK_MAIN (jifmux);
1242