static void update_stream_info (GthMediaViewerPage *self) { GstElement *audio_sink; GstElement *video_sink; GstPad *audio_pad; GstPad *video_pad; g_object_get (self->priv->playbin, "audio-sink", &audio_sink, "video-sink", &video_sink, NULL); if (audio_sink != NULL) { audio_pad = gst_element_get_static_pad (GST_ELEMENT (audio_sink), "sink"); if (audio_pad != NULL) self->priv->has_audio = TRUE; } if (video_sink != NULL) { video_pad = gst_element_get_static_pad (GST_ELEMENT (video_sink), "sink"); if (video_pad != NULL) { GstCaps *caps; self->priv->has_video = TRUE; if ((caps = gst_pad_get_current_caps (video_pad)) != NULL) { GstStructure *structure; int video_width; int video_height; structure = gst_caps_get_structure (caps, 0); gst_structure_get_fraction (structure, "framerate", &self->priv->video_fps_n, &self->priv->video_fps_d); gst_structure_get_int (structure, "width", &video_width); gst_structure_get_int (structure, "height", &video_height); g_file_info_set_attribute_int32 (self->priv->file_data->info, "frame::width", video_width); g_file_info_set_attribute_int32 (self->priv->file_data->info, "frame::height", video_height); gst_caps_unref (caps); } } } }
static void gth_metadata_provider_comment_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes, GCancellable *cancellable) { GthComment *comment; const char *value; GPtrArray *categories; char *comment_time; comment = gth_comment_new_for_file (file_data->file, cancellable, NULL); g_file_info_set_attribute_boolean (file_data->info, "comment::no-comment-file", (comment == NULL)); if (comment == NULL) return; value = gth_comment_get_note (comment); if (value != NULL) g_file_info_set_attribute_string (file_data->info, "comment::note", value); value = gth_comment_get_caption (comment); if (value != NULL) g_file_info_set_attribute_string (file_data->info, "comment::caption", value); value = gth_comment_get_place (comment); if (value != NULL) g_file_info_set_attribute_string (file_data->info, "comment::place", value); if (gth_comment_get_rating (comment) > 0) g_file_info_set_attribute_int32 (file_data->info, "comment::rating", gth_comment_get_rating (comment)); else g_file_info_remove_attribute (file_data->info, "comment::rating"); categories = gth_comment_get_categories (comment); if (categories->len > 0) { GthStringList *list; GthMetadata *metadata; list = gth_string_list_new_from_ptr_array (categories); metadata = gth_metadata_new_for_string_list (list); g_file_info_set_attribute_object (file_data->info, "comment::categories", G_OBJECT (metadata)); g_object_unref (metadata); g_object_unref (list); } else g_file_info_remove_attribute (file_data->info, "comment::categories"); comment_time = gth_comment_get_time_as_exif_format (comment); if (comment_time != NULL) { GTimeVal time_; char *formatted; if (_g_time_val_from_exif_date (comment_time, &time_)) formatted = _g_time_val_strftime (&time_, "%x %X"); else formatted = g_strdup (comment_time); set_attribute_from_string (file_data->info, "comment::time", comment_time, formatted); g_free (formatted); g_free (comment_time); } else g_file_info_remove_attribute (file_data->info, "comment::time"); gth_comment_update_general_attributes (file_data); g_object_unref (comment); }
static void extract_metadata (MetadataExtractor *extractor, GFileInfo *info) { gint64 duration; if (extractor->audio_channels >= 0) add_metadata (info, "audio-video::audio::channels", g_strdup_printf ("%d", (guint) extractor->audio_channels), g_strdup (extractor->audio_channels == 2 ? _("Stereo") : _("Mono"))); if (extractor->audio_samplerate >= 0) add_metadata (info, "audio-video::audio::samplerate", g_strdup_printf ("%d", (guint) extractor->audio_samplerate), g_strdup_printf ("%d Hz", (guint) extractor->audio_samplerate)); if (extractor->audio_bitrate >= 0) add_metadata (info, "audio-video::audio::bitrate", g_strdup_printf ("%d", (guint) extractor->audio_bitrate), g_strdup_printf ("%d bps", (guint) extractor->audio_bitrate)); if (extractor->video_height >= 0) { add_metadata (info, "audio-video::video::height", g_strdup_printf ("%d", (guint) extractor->video_height), NULL); g_file_info_set_attribute_int32 (info, "frame::height", extractor->video_height); } if (extractor->video_width >= 0) { add_metadata (info, "audio-video::video::width", g_strdup_printf ("%d", (guint) extractor->video_width), NULL); g_file_info_set_attribute_int32 (info, "frame::width", extractor->video_width); } if ((extractor->video_height >= 0) && (extractor->video_width >= 0)) add_metadata (info, "general::dimensions", g_strdup_printf (_("%d × %d"), (guint) extractor->video_width, (guint) extractor->video_height), NULL); if ((extractor->video_fps_n >= 0) && (extractor->video_fps_d >= 0)) add_metadata (info, "audio-video::video::framerate", g_strdup_printf ("%.7g", (gdouble) extractor->video_fps_n / (gdouble) extractor->video_fps_d), g_strdup_printf ("%.7g fps", (gdouble) extractor->video_fps_n / (gdouble) extractor->video_fps_d)); if (extractor->video_bitrate >= 0) add_metadata (info, "audio-video::video::bitrate", g_strdup_printf ("%d", (guint) extractor->video_bitrate), g_strdup_printf ("%d bps", (guint) extractor->video_bitrate)); duration = get_media_duration (extractor); if (duration >= 0) add_metadata (info, "general::duration", g_strdup_printf ("%" G_GINT64_FORMAT, duration), g_strdup_printf ("%" G_GINT64_FORMAT " sec", duration)); if (extractor->tagcache != NULL) gst_tag_list_foreach (extractor->tagcache, (GstTagForeachFunc) tag_iterate, info); }
GFileInfo * gvfs_file_info_demarshal (char *data, gsize size) { guint32 num_attrs, i; GInputStream *memstream; GDataInputStream *in; GFileInfo *info; char *attr, *str, **strv; GFileAttributeType type; GFileAttributeStatus status; GObject *obj; int objtype; memstream = g_memory_input_stream_new_from_data (data, size, NULL); in = g_data_input_stream_new (memstream); g_object_unref (memstream); info = g_file_info_new (); num_attrs = g_data_input_stream_read_uint32 (in, NULL, NULL); for (i = 0; i < num_attrs; i++) { attr = read_string (in); type = g_data_input_stream_read_byte (in, NULL, NULL); status = g_data_input_stream_read_byte (in, NULL, NULL); switch (type) { case G_FILE_ATTRIBUTE_TYPE_STRING: str = read_string (in); g_file_info_set_attribute_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: str = read_string (in); g_file_info_set_attribute_byte_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_STRINGV: strv = read_stringv (in); g_file_info_set_attribute_stringv (info, attr, strv); g_strfreev (strv); break; case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: g_file_info_set_attribute_boolean (info, attr, g_data_input_stream_read_byte (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT32: g_file_info_set_attribute_uint32 (info, attr, g_data_input_stream_read_uint32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT32: g_file_info_set_attribute_int32 (info, attr, g_data_input_stream_read_int32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT64: g_file_info_set_attribute_uint64 (info, attr, g_data_input_stream_read_uint64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT64: g_file_info_set_attribute_int64 (info, attr, g_data_input_stream_read_int64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_OBJECT: objtype = g_data_input_stream_read_byte (in, NULL, NULL); obj = NULL; if (objtype == 1) { char *icon_str; icon_str = read_string (in); obj = (GObject *)g_icon_new_for_string (icon_str, NULL); g_free (icon_str); } else { g_warning ("Unsupported GFileInfo object type %d\n", objtype); g_free (attr); goto out; } g_file_info_set_attribute_object (info, attr, obj); if (obj) g_object_unref (obj); break; case G_FILE_ATTRIBUTE_TYPE_INVALID: break; default: g_warning ("Unsupported GFileInfo attribute type %d\n", type); g_free (attr); goto out; break; } g_file_info_set_attribute_status (info, attr, status); g_free (attr); } out: g_object_unref (in); return info; }
static void gth_metadata_provider_image_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes, GCancellable *cancellable) { gboolean format_recognized; GFileInputStream *stream; char *description = NULL; int width; int height; const char *mime_type = NULL; format_recognized = FALSE; stream = g_file_read (file_data->file, cancellable, NULL); if (stream != NULL) { int buffer_size; guchar *buffer; gssize size; buffer_size = BUFFER_SIZE; buffer = g_new (guchar, buffer_size); size = g_input_stream_read (G_INPUT_STREAM (stream), buffer, buffer_size, cancellable, NULL); if (size >= 0) { if ((size >= 24) /* PNG signature */ && (buffer[0] == 0x89) && (buffer[1] == 0x50) && (buffer[2] == 0x4E) && (buffer[3] == 0x47) && (buffer[4] == 0x0D) && (buffer[5] == 0x0A) && (buffer[6] == 0x1A) && (buffer[7] == 0x0A) /* IHDR Image header */ && (buffer[12] == 0x49) && (buffer[13] == 0x48) && (buffer[14] == 0x44) && (buffer[15] == 0x52)) { /* PNG */ width = (buffer[16] << 24) + (buffer[17] << 16) + (buffer[18] << 8) + buffer[19]; height = (buffer[20] << 24) + (buffer[21] << 16) + (buffer[22] << 8) + buffer[23]; description = _("PNG"); mime_type = "image/png"; format_recognized = TRUE; } #if HAVE_LIBJPEG else if ((size >= 4) && (buffer[0] == 0xff) && (buffer[1] == 0xd8) && (buffer[2] == 0xff)) { /* JPEG */ GthTransform orientation; if (g_seekable_can_seek (G_SEEKABLE (stream))) { g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, cancellable, NULL); } else { g_object_unref (stream); stream = g_file_read (file_data->file, cancellable, NULL); } if (_jpeg_get_image_info (G_INPUT_STREAM (stream), &width, &height, &orientation, cancellable, NULL)) { description = _("JPEG"); mime_type = "image/jpeg"; format_recognized = TRUE; if ((orientation == GTH_TRANSFORM_ROTATE_90) || (orientation == GTH_TRANSFORM_ROTATE_270) || (orientation == GTH_TRANSFORM_TRANSPOSE) || (orientation == GTH_TRANSFORM_TRANSVERSE)) { int tmp = width; width = height; height = tmp; } } } #endif /* HAVE_LIBJPEG */ #if HAVE_LIBWEBP else if ((size > 15) && (memcmp (buffer + 8, "WEBPVP8", 7) == 0)) { WebPDecoderConfig config; if (WebPInitDecoderConfig (&config)) { if (WebPGetFeatures (buffer, buffer_size, &config.input) == VP8_STATUS_OK) { width = config.input.width; height = config.input.height; description = _("WebP"); mime_type = "image/webp"; format_recognized = TRUE; } WebPFreeDecBuffer (&config.output); } } #endif /* HAVE_LIBWEBP */ else if ((size >= 26) && (strncmp ((char *) buffer, "gimp xcf ", 9) == 0)) { /* XCF */ GInputStream *mem_stream; GDataInputStream *data_stream; mem_stream = g_memory_input_stream_new_from_data (buffer, BUFFER_SIZE, NULL); data_stream = g_data_input_stream_new (mem_stream); g_data_input_stream_set_byte_order (data_stream, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN); if (g_seekable_seek (G_SEEKABLE (data_stream), 14, G_SEEK_SET, NULL, NULL)) { int base_type; width = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); height = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); base_type = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); if (base_type == 0) description = "XCF RGB"; else if (base_type == 1) description = "XCF grayscale"; else if (base_type == 2) description = "XCF indexed"; else description = "XCF"; mime_type = "image/x-xcf"; format_recognized = TRUE; } g_object_unref (data_stream); g_object_unref (mem_stream); } } g_free (buffer); g_object_unref (stream); } if (! format_recognized) { /* use gdk_pixbuf_get_file_info */ char *filename; filename = g_file_get_path (file_data->file); if (filename != NULL) { GdkPixbufFormat *format; format = gdk_pixbuf_get_file_info (filename, &width, &height); if (format != NULL) { format_recognized = TRUE; description = gdk_pixbuf_format_get_description (format); } g_free (filename); } } if (format_recognized) { char *size; g_file_info_set_attribute_string (file_data->info, "general::format", description); g_file_info_set_attribute_int32 (file_data->info, "image::width", width); g_file_info_set_attribute_int32 (file_data->info, "image::height", height); g_file_info_set_attribute_int32 (file_data->info, "frame::width", width); g_file_info_set_attribute_int32 (file_data->info, "frame::height", height); if (mime_type != NULL) gth_file_data_set_mime_type (file_data, mime_type); size = g_strdup_printf (_("%d × %d"), width, height); g_file_info_set_attribute_string (file_data->info, "general::dimensions", size); g_free (size); } }
void ss__gth_catalog_write_metadata (GthCatalog *catalog, GthFileData *file_data) { if (g_value_hash_is_set (catalog->attributes, "slideshow::personalize")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::personalize", g_value_hash_get_boolean (catalog->attributes, "slideshow::personalize")); g_file_info_set_attribute_status (file_data->info, "slideshow::personalize", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::automatic")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::automatic", g_value_hash_get_boolean (catalog->attributes, "slideshow::automatic")); g_file_info_set_attribute_status (file_data->info, "slideshow::automatic", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::wrap-around")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::wrap-around", g_value_hash_get_boolean (catalog->attributes, "slideshow::wrap-around")); g_file_info_set_attribute_status (file_data->info, "slideshow::wrap-around", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::random-order")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::random-order", g_value_hash_get_boolean (catalog->attributes, "slideshow::random-order")); g_file_info_set_attribute_status (file_data->info, "slideshow::random-order", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::delay")) { g_file_info_set_attribute_int32 (file_data->info, "slideshow::delay", g_value_hash_get_int (catalog->attributes, "slideshow::delay")); g_file_info_set_attribute_status (file_data->info, "slideshow::delay", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::transition")) { g_file_info_set_attribute_string (file_data->info, "slideshow::transition", g_value_hash_get_string (catalog->attributes, "slideshow::transition")); g_file_info_set_attribute_status (file_data->info, "slideshow::transition", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::playlist")) { g_file_info_set_attribute_stringv (file_data->info, "slideshow::playlist", g_value_hash_get_stringv (catalog->attributes, "slideshow::playlist")); g_file_info_set_attribute_status (file_data->info, "slideshow::playlist", G_FILE_ATTRIBUTE_STATUS_SET); } }