Exemple #1
0
static GdkPixbuf *
gst_thumbnailer_cover_from_tags (GstTagList   *tags,
                                 GCancellable *cancellable)
{
  GstSample          *cover = NULL;
  guint               i;
  GstSample          *sample;
  GstCaps            *caps;
  const GstStructure *caps_struct;
  gint                type;
  GstBuffer          *buffer;
  GdkPixbuf          *pixbuf = NULL;

  for (i = 0; ; i++)
    {
      if (g_cancellable_is_cancelled (cancellable))
        break;

      /* look for image in the tags */
      if (!gst_tag_list_get_sample_index (tags, GST_TAG_IMAGE, i, &sample))
        break;

      caps = gst_sample_get_caps (sample);
      caps_struct = gst_caps_get_structure (caps, 0);
      gst_structure_get_enum (caps_struct,
                              "image-type",
                              GST_TYPE_TAG_IMAGE_TYPE,
                              &type);

      if (type == GST_TAG_IMAGE_TYPE_FRONT_COVER)
        {
          /* found the cover */
          cover = sample;
          break;
        }

      gst_sample_unref (sample);
    }

  if (cover == NULL
      && !g_cancellable_is_cancelled (cancellable))
    {
      /* look for preview image */
      gst_tag_list_get_sample_index (tags, GST_TAG_PREVIEW_IMAGE, 0, &cover);
    }

  if (cover != NULL)
    {
      /* create image */
      buffer = gst_sample_get_buffer (cover);
      pixbuf = gst_thumbnailer_buffer_to_pixbuf (buffer);
      gst_sample_unref (cover);
    }

  return pixbuf;
}
GdkPixbuf *
totem_gst_tag_list_get_cover (GstTagList *tag_list)
{
  GstSample *cover_sample;

  g_return_val_if_fail (tag_list != NULL, FALSE);

  cover_sample = totem_gst_tag_list_get_cover_real (tag_list);
  /* Fallback to preview */
    if (!cover_sample) {
      gst_tag_list_get_sample_index (tag_list, GST_TAG_PREVIEW_IMAGE, 0,
				     &cover_sample);
    }

  if (cover_sample) {
    GstBuffer *buffer;
    GdkPixbuf *pixbuf;

    buffer = gst_sample_get_buffer (cover_sample);
    pixbuf = totem_gst_buffer_to_pixbuf (buffer);
    gst_sample_unref (cover_sample);
    return pixbuf;
  }

  return NULL;
}
static GstSample *
totem_gst_tag_list_get_cover_real (GstTagList *tag_list)
{
  GstSample *cover_sample = NULL;
  guint i;

  for (i = 0; ; i++) {
    GstSample *sample;
    GstCaps *caps;
    const GstStructure *caps_struct;
    int type;

    if (!gst_tag_list_get_sample_index (tag_list, GST_TAG_IMAGE, i, &sample))
      break;

    caps = gst_sample_get_caps (sample);
    caps_struct = gst_caps_get_structure (caps, 0);
    gst_structure_get_enum (caps_struct,
			    "image-type",
			    GST_TYPE_TAG_IMAGE_TYPE,
			    &type);
    if (type == GST_TAG_IMAGE_TYPE_UNDEFINED) {
      if (cover_sample == NULL) {
	/* take a ref here since we will continue and unref below */
	cover_sample = gst_sample_ref (sample);
      }
    } else if (type == GST_TAG_IMAGE_TYPE_FRONT_COVER) {
      cover_sample = sample;
      break;
    }
    gst_sample_unref (sample);
  }

  return cover_sample;
}
Exemple #4
0
static void
save_embedded_art (PraghaBackend *backend, const GstTagList *taglist)
{
	PraghaBackendPrivate *priv = backend->priv;
	GstSample *sample = NULL;

	gst_tag_list_get_sample_index (taglist, GST_TAG_IMAGE, 0, &sample);
	if (!sample) //try harder
		gst_tag_list_get_sample_index (taglist, GST_TAG_PREVIEW_IMAGE, 0, &sample);

	if (!sample)
		goto out;

	//got art, now check if we need it

	const gchar *artist = pragha_musicobject_get_artist (priv->mobj);
	const gchar *album = pragha_musicobject_get_album (priv->mobj);

	if (pragha_art_cache_contains (priv->art_cache, artist, album))
		goto out;

	//ok, we need it

	GstBuffer *buf = gst_sample_get_buffer (sample);
	if (!buf)
		goto out;

	GstMapInfo info;
	if (!gst_buffer_map (buf, &info, GST_MAP_READ))
		goto out;

	pragha_art_cache_put (priv->art_cache, artist, album, info.data, info.size);

	gst_buffer_unmap (buf, &info);

out:
	if (sample)
		gst_sample_unref (sample);
}
Exemple #5
0
bool get_value(tag_list const &p_tag_list, std::string const &p_name, GstSample* &p_value, const guint p_index)
{
	g_assert(!p_name.empty());
	return p_tag_list.is_empty() ? false : gst_tag_list_get_sample_index(p_tag_list.get_tag_list(), p_name.c_str(), p_index, &p_value);
}