Re: [PATCH] upnp: add support for thumbnails



On 01/18/2011 07:54 PM, Guillaume Emont wrote:
> This needed several helper functions to keep the code clean, because a lot of
> specific cases need to be handled.

Just to make it a bit more complex: what about "upnp:albumArtURI"? I
assume you'd have to add a new mapping for that -- or have I
misunderstood how that works?

example:

  <upnp:albumArtURI dlna:profileID="JPEG_TN"
                    xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/">
    http://uri-to-media
  </upnp:albumArtURI>

another comment below.

> ---
>  src/upnp/grl-upnp.c |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 83 insertions(+), 0 deletions(-)
> 
> diff --git a/src/upnp/grl-upnp.c b/src/upnp/grl-upnp.c
> index c831cf8..8bc203b 100644
> --- a/src/upnp/grl-upnp.c
> +++ b/src/upnp/grl-upnp.c
> @@ -669,6 +669,84 @@ didl_h_mm_ss_to_int (const gchar *time)
>  
>  }
>  
> +static gboolean
> +is_image (xmlNode *node)
> +{
> +  gchar *mime_type;
> +  gboolean ret;
> +
> +  mime_type = didl_res_get_protocol_info (node, 2);
> +  ret = g_str_has_prefix (mime_type, "image/");
> +
> +  g_free (mime_type);
> +  return ret;
> +}
> +
> +static gboolean
> +is_http_get (xmlNode *node)
> +{
> +  gboolean ret;
> +  gchar *protocol;
> +
> +  protocol = didl_res_get_protocol_info (node, 0);
> +  ret = g_str_has_prefix (protocol, "http-get");
> +
> +  g_free (protocol);
> +  return ret;
> +}
> +
> +static gboolean
> +has_thumbnail_marker (xmlNode *node)
> +{
> +  gchar *dlna_stuff;
> +  gboolean ret;
> +
> +  dlna_stuff = didl_res_get_protocol_info (node, 3);
> +  ret = strstr("JPEG_TN", dlna_stuff) != NULL;



JPEG_TN is, IIRC, 160x160 maximum size. This is useful for many usecases
but still on the small side for many implementations (think coverflow
type). I know some servers provide JPEG_SM size images as well: I think
these should be taken into consideration when picking a thumbnail.

More generally speaking, is it possible to support several different
size thumbnails in grilo? Or maybe make the preferred size application
configurable?


Should this also check for "PNG_TN"/"PNG_SM"?

> +
> +  g_free (dlna_stuff);
> +  return ret;
> +}
> +
> +static gchar *
> +get_thumbnail (GList *nodes)
> +{
> +  GList *element;
> +  gchar *val = NULL;
> +  guint counter = 0;
> +
> +  /* chose, depending on availability, the first with DLNA.ORG_PN=JPEG_TN, or
> +   * the last http-get with mimetype image/something if there is more than one
> +   * http-get.
> +   * This covers at least mediatomb and rygel.
> +   * This could be improved by handling resolution and/or size */
> +  for (element=nodes; element; element=g_list_next (element)) {
> +    xmlNode *node = (xmlNode *)element->data;
> +
> +    if (is_http_get (node)) {
> +      counter++;
> +      if (is_image (node)) {
> +        if (val)
> +          g_free (val);
> +        val = xmlNodeGetContent (node);
> +
> +        if (has_thumbnail_marker (node))  /* that's definitely it! */
> +          return val;
> +      }
> +    }
> +  }
> +
> +  if (val && counter == 1) {
> +    /* There was only one element with http-get protocol: that's the uri of the
> +     * media itself, not a thumbnail */
> +    g_free (val);
> +    val = NULL;
> +  }
> +
> +  return val;
> +}
> +
>  static gchar *
>  get_value_for_key (GrlKeyID key_id,
>  #ifdef GUPNPAV_OLD_VERSION
> @@ -716,6 +794,9 @@ get_value_for_key (GrlKeyID key_id,
>      val = (gchar *) xmlNodeGetContent ((xmlNode *) props->data);
>  #endif
>  
> +  } else if (key_id == GRL_METADATA_KEY_THUMBNAIL && props) {
> +    val = get_thumbnail (props);
> +
>    } else if (upnp_key) {
>  
>  #ifdef GUPNPAV_OLD_VERSION
> @@ -769,6 +850,8 @@ set_metadata_value (GrlMedia *media,
>      }
>    } else if (key_id == GRL_METADATA_KEY_CHILDCOUNT && value && GRL_IS_MEDIA_BOX (media)) {
>        grl_media_box_set_childcount (GRL_MEDIA_BOX (media), atoi (value));
> +  } else if (key_id == GRL_METADATA_KEY_THUMBNAIL) {
> +    grl_media_set_thumbnail (media, value);
>    }
>  }
>  



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]