static void print_tag (const GstTagList * list, const gchar * tag, gpointer unused) { gint i, count; count = gst_tag_list_get_tag_size (list, tag); for (i = 0; i < count; i++) { gchar *str; if (gst_tag_get_type (tag) == G_TYPE_STRING) { if (!gst_tag_list_get_string_index (list, tag, i, &str)) g_assert_not_reached (); } else if (gst_tag_get_type (tag) == GST_TYPE_BUFFER) { GstBuffer *img; img = gst_value_get_buffer (gst_tag_list_get_value_index (list, tag, i)); if (img) { gchar *caps_str; caps_str = GST_BUFFER_CAPS (img) ? gst_caps_to_string (GST_BUFFER_CAPS (img)) : g_strdup ("unknown"); str = g_strdup_printf ("buffer of %u bytes, type: %s", GST_BUFFER_SIZE (img), caps_str); g_free (caps_str); } else { str = g_strdup ("NULL buffer"); } } else { str = g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i)); } if (i == 0) { g_print ("%16s: %s\n", gst_tag_get_nick (tag), str); } else { g_print ("%16s: %s\n", "", str); } g_free (str); } }
/* checks that a tag contains the given values and not more values */ static void check_tags (const GstTagList * list, const gchar * tag, const gchar * value, ...) { va_list args; gchar *str; guint i = 0; va_start (args, value); while (value != NULL) { fail_unless (gst_tag_list_get_string_index (list, tag, i, &str)); fail_unless (strcmp (value, str) == 0); g_free (str); value = va_arg (args, gchar *); i++; } fail_unless (i == gst_tag_list_get_tag_size (list, tag)); va_end (args); }
/* special serialization functions */ static void serialize_orientation (GstExifWriter * writer, const GstTagList * taglist, const GstExifTagMatch * exiftag) { gchar *str = NULL; gint exif_value; if (!gst_tag_list_get_string_index (taglist, GST_TAG_IMAGE_ORIENTATION, 0, &str)) { GST_WARNING ("No image orientation tag present in taglist"); return; } exif_value = gst_tag_image_orientation_to_exif_value (str); if (exif_value == -1) { GST_WARNING ("Invalid image orientation value: %s", str); g_free (str); return; } g_free (str); gst_exif_writer_write_short_tag (writer, exiftag->exif_tag, exif_value); }
static void send_tag (const GstTagList * list, const gchar * tag, gpointer data) { InsanityGstPipelineTest *ptest = INSANITY_GST_PIPELINE_TEST (data); gint i, count; GValue string_value = { 0 }; char label[48]; count = gst_tag_list_get_tag_size (list, tag); g_value_init (&string_value, G_TYPE_STRING); ptest->priv->tag_count++; for (i = 0; i < count; i++) { gchar *str; if (gst_tag_get_type (tag) == G_TYPE_STRING) { if (!gst_tag_list_get_string_index (list, tag, i, &str)) g_assert_not_reached (); } else if (gst_tag_get_type (tag) == GST_TYPE_SAMPLE) { GstSample *img; img = gst_value_get_sample (gst_tag_list_get_value_index (list, tag, i)); if (img) { GstBuffer *buffer; GstCaps *caps; gchar *caps_str; buffer = gst_sample_get_buffer (img); caps = gst_sample_get_caps (img); caps_str = caps ? gst_caps_to_string (caps) : g_strdup ("unknown"); str = g_strdup_printf ("sample of %" G_GSIZE_FORMAT " bytes, type: %s", gst_buffer_get_size (buffer), caps_str); g_free (caps_str); } else { str = g_strdup ("NULL sample"); } } else if (gst_tag_get_type (tag) == GST_TYPE_DATE_TIME) { GstDateTime *dt = NULL; gst_tag_list_get_date_time_index (list, tag, i, &dt); str = gst_date_time_to_iso8601_string (dt); gst_date_time_unref (dt); } else { str = g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i)); } if (i == 0) { g_value_set_string (&string_value, gst_tag_get_nick (tag)); snprintf (label, sizeof (label), "tags.%u.id", ptest->priv->tag_count); insanity_test_set_extra_info (INSANITY_TEST (ptest), label, &string_value); g_value_reset (&string_value); } g_value_set_string (&string_value, str); if (count > 1) snprintf (label, sizeof (label), "tags.%u.value.%u", ptest->priv->tag_count, i); else snprintf (label, sizeof (label), "tags.%u.value", ptest->priv->tag_count); insanity_test_set_extra_info (INSANITY_TEST (ptest), label, &string_value); g_value_reset (&string_value); g_free (str); } }
static void rc_tag_get_tag(const GstTagList *tags, RCMusicMetaData *mmd) { gchar *tag_title = NULL; gchar *tag_artist = NULL; gchar *tag_filetype = NULL; gchar *tag_album = NULL; gchar *tag_comment = NULL; gchar *tag_cuelist = NULL; GstBuffer *tag_image = NULL; guint bitrates = 0; guint tracknum = 0; guint tag_cue_num = 0; guint i = 0; if(mmd==NULL || mmd->uri==NULL || tags==NULL) return; if(gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &tag_filetype)) { if(tag_filetype!=NULL) { if(mmd->file_type!=NULL) g_free(mmd->file_type); mmd->file_type = g_strdup(tag_filetype); g_free(tag_filetype); } } if(gst_tag_list_get_string(tags, GST_TAG_TITLE, &tag_title)) { if(tag_title!=NULL) { if(mmd->title!=NULL) g_free(mmd->title); mmd->title = g_strdup(tag_title); g_free(tag_title); } } if(gst_tag_list_get_string(tags, GST_TAG_ARTIST, &tag_artist)) { if(tag_artist!=NULL) { if(mmd->artist!=NULL) g_free(mmd->artist); mmd->artist = g_strdup(tag_artist); g_free(tag_artist); } } if(gst_tag_list_get_string(tags, GST_TAG_ALBUM, &tag_album)) { if(tag_album!=NULL) { if(mmd->album!=NULL) g_free(mmd->album); mmd->album = g_strdup(tag_album); g_free(tag_album); } } if(gst_tag_list_get_string(tags, GST_TAG_COMMENT, &tag_comment)) { if(tag_comment!=NULL) { if(mmd->comment!=NULL) g_free(mmd->comment); mmd->comment = g_strdup(tag_comment); g_free(tag_comment); } } if(gst_tag_list_get_buffer(tags, GST_TAG_IMAGE, &tag_image)) { if(tag_image!=NULL) { if(mmd->image!=NULL) gst_buffer_unref(mmd->image); mmd->image = tag_image; } } if(gst_tag_list_get_buffer(tags, GST_TAG_PREVIEW_IMAGE, &tag_image)) { if(tag_image==NULL) mmd->image = tag_image; else gst_buffer_unref(tag_image); } if(gst_tag_list_get_uint(tags, GST_TAG_NOMINAL_BITRATE, &bitrates)) if(bitrates>0) mmd->bitrate = bitrates; if(gst_tag_list_get_uint(tags, GST_TAG_TRACK_NUMBER, &tracknum)) mmd->tracknum = tracknum; tag_cue_num = gst_tag_list_get_tag_size(tags, GST_TAG_EXTENDED_COMMENT); for(i=0;i<tag_cue_num && mmd->emb_cue==NULL;i++) { if(gst_tag_list_get_string_index(tags, GST_TAG_EXTENDED_COMMENT, i, &tag_cuelist)) { if(!strncmp(tag_cuelist, "cuesheet=", 9)) { if(mmd->emb_cue!=NULL) g_free(mmd->emb_cue); mmd->emb_cue = g_strdup(tag_cuelist+9); } if(tag_cuelist!=NULL) g_free(tag_cuelist); } } }
GdkPixbuf * xplayer_gst_playbin_get_frame (GstElement *play) { GstStructure *s; GstSample *sample = NULL; GdkPixbuf *pixbuf = NULL; GstCaps *to_caps, *sample_caps; gint outwidth = 0; gint outheight = 0; GstMemory *memory; GstMapInfo info; GdkPixbufRotation rotation = GDK_PIXBUF_ROTATE_NONE; g_return_val_if_fail (play != NULL, NULL); g_return_val_if_fail (GST_IS_ELEMENT (play), NULL); /* our desired output format (RGB24) */ to_caps = gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "RGB", /* Note: we don't ask for a specific width/height here, so that * videoscale can adjust dimensions from a non-1/1 pixel aspect * ratio to a 1/1 pixel-aspect-ratio. We also don't ask for a * specific framerate, because the input framerate won't * necessarily match the output framerate if there's a deinterlacer * in the pipeline. */ "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL); /* get frame */ g_signal_emit_by_name (play, "convert-sample", to_caps, &sample); gst_caps_unref (to_caps); if (!sample) { GST_DEBUG ("Could not take screenshot: %s", "failed to retrieve or convert video frame"); g_warning ("Could not take screenshot: %s", "failed to retrieve or convert video frame"); return NULL; } sample_caps = gst_sample_get_caps (sample); if (!sample_caps) { GST_DEBUG ("Could not take screenshot: %s", "no caps on output buffer"); g_warning ("Could not take screenshot: %s", "no caps on output buffer"); return NULL; } GST_DEBUG ("frame caps: %" GST_PTR_FORMAT, sample_caps); s = gst_caps_get_structure (sample_caps, 0); gst_structure_get_int (s, "width", &outwidth); gst_structure_get_int (s, "height", &outheight); if (outwidth <= 0 || outheight <= 0) goto done; memory = gst_buffer_get_memory (gst_sample_get_buffer (sample), 0); gst_memory_map (memory, &info, GST_MAP_READ); /* create pixbuf from that - use our own destroy function */ pixbuf = gdk_pixbuf_new_from_data (info.data, GDK_COLORSPACE_RGB, FALSE, 8, outwidth, outheight, GST_ROUND_UP_4 (outwidth * 3), destroy_pixbuf, sample); gst_memory_unmap (memory, &info); done: if (!pixbuf) { GST_DEBUG ("Could not take screenshot: %s", "could not create pixbuf"); g_warning ("Could not take screenshot: %s", "could not create pixbuf"); gst_sample_unref (sample); } /* Did we check whether we need to rotate the video? */ if (g_object_get_data (G_OBJECT (play), "orientation-checked") == NULL) { GstTagList *tags = NULL; g_signal_emit_by_name (G_OBJECT (play), "get-video-tags", 0, &tags); if (tags) { char *orientation_str; gboolean ret; ret = gst_tag_list_get_string_index (tags, GST_TAG_IMAGE_ORIENTATION, 0, &orientation_str); if (!ret || !orientation_str) rotation = GDK_PIXBUF_ROTATE_NONE; else if (g_str_equal (orientation_str, "rotate-90")) rotation = GDK_PIXBUF_ROTATE_CLOCKWISE; else if (g_str_equal (orientation_str, "rotate-180")) rotation = GDK_PIXBUF_ROTATE_UPSIDEDOWN; else if (g_str_equal (orientation_str, "rotate-270")) rotation = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; gst_tag_list_unref (tags); } g_object_set_data (G_OBJECT (play), "orientation-checked", GINT_TO_POINTER(1)); g_object_set_data (G_OBJECT (play), "orientation", GINT_TO_POINTER(rotation)); } rotation = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (play), "orientation")); if (rotation != GDK_PIXBUF_ROTATE_NONE) { GdkPixbuf *rotated; rotated = gdk_pixbuf_rotate_simple (pixbuf, rotation); if (rotated) { g_object_unref (pixbuf); pixbuf = rotated; } } return pixbuf; }