* </refsect2>
*/
+#ifndef GST_DISABLE_GST_DEBUG
+#define GST_CAT_DEFAULT gst_tag_ensure_debug_category()
+
+static GstDebugCategory *
+gst_tag_ensure_debug_category (void)
+{
+ static gsize cat_gonce = 0;
+
+ if (g_once_init_enter (&cat_gonce)) {
+ GstDebugCategory *cat = NULL;
+
+ GST_DEBUG_CATEGORY_INIT (cat, "tag-tags", 0, "GstTag helper functions");
+
+ g_once_init_leave (&cat_gonce, (gsize) cat);
+ }
+
+ return (GstDebugCategory *) cat_gonce;
+}
+#endif /* GST_DISABLE_GST_DEBUG */
static gpointer
gst_tag_register_tags_internal (gpointer unused)
"Musicbrainz discid for metadata retrieval (full)",
gst_tag_merge_use_first);
+ /* photography tags */
+ gst_tag_register (GST_TAG_CAPTURING_SHUTTER_SPEED, GST_TAG_FLAG_META,
+ GST_TYPE_FRACTION, _("capturing shutter speed"),
+ _("Shutter speed used when capturing an image, in seconds"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_FOCAL_RATIO, GST_TAG_FLAG_META,
+ G_TYPE_DOUBLE, _("capturing focal ratio"),
+ _("Focal ratio (f-number) used when capturing the image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_FOCAL_LENGTH, GST_TAG_FLAG_META,
+ G_TYPE_DOUBLE, _("capturing focal length"),
+ _("Focal length of the lens used capturing the image, in mm"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO, GST_TAG_FLAG_META,
+ G_TYPE_DOUBLE, _("capturing digital zoom ratio"),
+ _("Digital zoom ratio used when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_ISO_SPEED, GST_TAG_FLAG_META,
+ G_TYPE_INT, _("capturing iso speed"),
+ _("The ISO speed used when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_EXPOSURE_PROGRAM, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing exposure program"),
+ _("The exposure program used when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_EXPOSURE_MODE, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing exposure mode"),
+ _("The exposure mode used when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION, GST_TAG_FLAG_META,
+ G_TYPE_DOUBLE, _("capturing exposure compensation"),
+ _("The exposure compensation used when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing scene capture type"),
+ _("The scene capture mode used when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing gain adjustment"),
+ _("The overall gain adjustment applied on an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_WHITE_BALANCE, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing white balance"),
+ _("The white balance mode set when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_CONTRAST, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing contrast"),
+ _("The direction of contrast processing applied "
+ "when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_SATURATION, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing saturation"),
+ _("The direction of saturation processing applied when "
+ "capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_SHARPNESS, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing sharpness"),
+ _("The direction of sharpness processing applied "
+ "when capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_FLASH_FIRED, GST_TAG_FLAG_META,
+ G_TYPE_BOOLEAN, _("capturing flash fired"),
+ _("If the flash fired while capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_FLASH_MODE, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing flash mode"),
+ _("The selected flash mode while capturing an image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_METERING_MODE, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing metering mode"),
+ _("The metering mode used while determining exposure for capturing an"
+ " image"), NULL);
+
+ gst_tag_register (GST_TAG_CAPTURING_SOURCE, GST_TAG_FLAG_META,
+ G_TYPE_STRING, _("capturing source"),
+ _("The source or type of device used for the capture"), NULL);
+
+ gst_tag_register (GST_TAG_IMAGE_HORIZONTAL_PPI, GST_TAG_FLAG_META,
+ G_TYPE_DOUBLE, _("image horizontal ppi"),
+ _("Media (image/video) intended horizontal pixel density in ppi"), NULL);
+
+ gst_tag_register (GST_TAG_IMAGE_VERTICAL_PPI, GST_TAG_FLAG_META,
+ G_TYPE_DOUBLE, _("image vertical ppi"),
+ _("Media (image/video) intended vertical pixel density in ppi"), NULL);
+
return NULL;
}
*
* Convenience function to read a string with unknown character encoding. If
* the string is already in UTF-8 encoding, it will be returned right away.
+ * If not it tries to detect byte-order-mark for UTF-16/32 cases and use that.
* Otherwise, the environment will be searched for a number of environment
* variables (whose names are specified in the NULL-terminated string array
* @env_vars) containing a list of character encodings to try/use. If none
* are specified, the current locale will be tried. If that also doesn't work,
- * ISO-8859-1 is assumed (which will almost always succeed).
+ * WINDOWS-1252/ISO-8859-1 is assumed (which will almost always succeed).
*
* Returns: a newly-allocated string in UTF-8 encoding, or NULL
*
goto beach;
}
+ /* check for and use byte-order-mark for UTF-16/32 cases */
+ if (size >= 2) {
+ const gchar *c = NULL;
+ gint prefix, ssize;
+
+ if (size >= 4) {
+ prefix = 4;
+ ssize = GST_ROUND_DOWN_4 (size - 4);
+ switch (GST_READ_UINT32_BE (data)) {
+ case 0x0000FEFF:
+ c = "UTF-32BE";
+ break;
+ case 0xFFFE0000:
+ c = "UTF-32LE";
+ break;
+ default:
+ break;
+ }
+ }
+ if (!c) {
+ prefix = 2;
+ ssize = GST_ROUND_DOWN_2 (size - 2);
+ switch (GST_READ_UINT16_BE (data)) {
+ case 0xFEFF:
+ c = "UTF-16BE";
+ break;
+ case 0xFFFE:
+ c = "UTF-16LE";
+ break;
+ default:
+ break;
+ }
+ }
+ if (c) {
+ GST_LOG ("Trying to convert freeform string to UTF-8 from '%s'", c);
+ if ((utf8 =
+ g_convert (data + prefix, ssize, "UTF-8", c, &bytes_read, NULL,
+ NULL))) {
+ if (bytes_read == ssize)
+ goto beach;
+ g_free (utf8);
+ utf8 = NULL;
+ }
+ }
+ }
+
while (env_vars && *env_vars != NULL) {
const gchar *env = NULL;
}
}
- /* Try ISO-8859-1 */
- GST_LOG ("Trying to convert freeform string using ISO-8859-1 fallback");
- utf8 = g_convert (data, size, "UTF-8", "ISO-8859-1", &bytes_read, NULL, NULL);
- if (utf8 != NULL && bytes_read == size) {
- goto beach;
+ /* Try Windows-1252 (which is a superset of ISO 8859-1 that uses a control
+ * character range in ISO 8859-1 for more printable characters) */
+ {
+ GError *err = NULL;
+
+ GST_LOG ("Trying to convert freeform string using Windows-1252/ISO-8859-1 "
+ "fallback");
+ utf8 = g_convert (data, size, "UTF-8", "WINDOWS-1252", &bytes_read, NULL,
+ &err);
+ if (err != NULL) {
+ /* fallback in case iconv implementation doesn't support windows-1252
+ * for some reason */
+ if (err->code == G_CONVERT_ERROR_NO_CONVERSION) {
+ utf8 = g_convert (data, size, "UTF-8", "ISO-8859-1", &bytes_read,
+ NULL, NULL);
+ }
+ g_error_free (err);
+ }
+
+ if (utf8 != NULL && bytes_read == size)
+ goto beach;
}
g_free (utf8);
guint image_data_len, GstTagImageType image_type)
{
const gchar *name;
-
GstBuffer *image;
-
GstCaps *caps;
+ guint8 *data;
g_return_val_if_fail (image_data != NULL, NULL);
g_return_val_if_fail (image_data_len > 0, NULL);
GST_DEBUG ("image data len: %u bytes", image_data_len);
/* allocate space for a NUL terminator for an uri too */
- image = gst_buffer_try_new_and_alloc (image_data_len + 1);
- if (image == NULL) {
- GST_WARNING ("failed to allocate buffer of %d for image", image_data_len);
- return NULL;
- }
+ image = gst_buffer_new_and_alloc (image_data_len + 1);
+ if (image == NULL)
+ goto alloc_failed;
- memcpy (GST_BUFFER_DATA (image), image_data, image_data_len);
- GST_BUFFER_DATA (image)[image_data_len] = '\0';
- GST_BUFFER_SIZE (image) = image_data_len;
+ data = gst_buffer_map (image, NULL, NULL, GST_MAP_WRITE);
+ memcpy (data, image_data, image_data_len);
+ data[image_data_len] = '\0';
+ gst_buffer_unmap (image, data, image_data_len + 1);
/* Find GStreamer media type, can't trust declared type */
caps = gst_type_find_helper_for_buffer (NULL, image, NULL);
* to keep the original size of the image
*/
if (!g_str_equal (name, "text/uri-list"))
- GST_BUFFER_SIZE (image) = GST_BUFFER_SIZE (image) - 1;
+ gst_buffer_set_size (image, image_data_len);
if (image_type != GST_TAG_IMAGE_TYPE_NONE) {
GST_LOG ("Setting image type: %d", image_type);
gst_caps_unref (caps);
return NULL;
}
+alloc_failed:
+ {
+ GST_WARNING ("failed to allocate buffer of %d for image", image_data_len);
+ gst_buffer_unref (image);
+ return NULL;
+ }
+
}