static void
add_dlna_info (GString           *str,
               GUPnPProtocolInfo *info)
{
        const char *dlna_profile;
        const char **speeds;
        GUPnPDLNAConversion conversion;
        GUPnPDLNAFlags flags;

        dlna_profile = gupnp_protocol_info_get_dlna_profile (info);
        if (dlna_profile == NULL) {
                g_string_append_printf (str, ":*");
                return;
        }

        g_string_append_printf (str, ":DLNA.ORG_PN=%s", dlna_profile);

        /* the OP parameter is only allowed for the "http-get"
         * and "rtsp-rtp-udp" protocols
         */
        if (strcmp (gupnp_protocol_info_get_protocol (info),
                    "http-get") == 0 ||
            strcmp (gupnp_protocol_info_get_protocol (info),
                    "rtsp-rtp-udp") == 0)
                g_string_append_printf
                        (str,
                         ";DLNA.ORG_OP=%.2x",
                         gupnp_protocol_info_get_dlna_operation (info));

        /* Specify PS parameter if list of play speeds is provided */
        speeds = gupnp_protocol_info_get_play_speeds (info);
        if (speeds != NULL) {
                int i;

                g_string_append_printf (str, ";DLNA.ORG_PS=");

                for (i = 0; speeds[i]; i++) {
                        g_string_append (str, speeds[i]);

                        if (speeds[i + 1])
                                g_string_append_c (str, ',');
                }
        }

        conversion = gupnp_protocol_info_get_dlna_conversion (info);
        /* omit the CI parameter for non-converted content */
        if (conversion != GUPNP_DLNA_CONVERSION_NONE)
                g_string_append_printf (str, ";DLNA.ORG_CI=%d", conversion);

        flags = gupnp_protocol_info_get_dlna_flags (info);
        /* Omit the FLAGS parameter if no flags set */
        if (flags != GUPNP_DLNA_FLAGS_NONE) {
                g_string_append_printf (str, ";DLNA.ORG_FLAGS=%.8x", flags);
                /*  append 24 reserved hex-digits */
                g_string_append_printf (str,
                                        "0000" "0000" "0000"
                                        "0000" "0000" "0000");
        }
}
static void
gupnp_protocol_info_get_property (GObject    *object,
                                  guint       property_id,
                                  GValue     *value,
                                  GParamSpec *pspec)
{
        GUPnPProtocolInfo *info;

        info = GUPNP_PROTOCOL_INFO (object);

        switch (property_id) {
        case PROP_PROTOCOL:
                g_value_set_string (value,
                                    gupnp_protocol_info_get_protocol (info));
                break;
        case PROP_NETWORK:
                g_value_set_string (value,
                                    gupnp_protocol_info_get_network (info));
                break;
        case PROP_MIME_TYPE:
                g_value_set_string (value,
                                    gupnp_protocol_info_get_mime_type (info));
                break;
        case PROP_DLNA_PROFILE:
                g_value_set_string
                              (value,
                               gupnp_protocol_info_get_dlna_profile (info));
                break;
        case PROP_PLAY_SPEEDS:
                g_value_set_boxed (value,
                                   gupnp_protocol_info_get_play_speeds (info));
                break;
        case PROP_DLNA_CONVERSION:
                g_value_set_flags
                                (value,
                                 gupnp_protocol_info_get_dlna_conversion
                                                                (info));
                break;
        case PROP_DLNA_OPERATION:
                g_value_set_flags
                                (value,
                                 gupnp_protocol_info_get_dlna_operation (info));
                break;
        case PROP_DLNA_FLAGS:
                g_value_set_flags (value,
                                   gupnp_protocol_info_get_dlna_flags (info));
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
        }
}
static void
add_dlna_info (GString           *str,
               GUPnPProtocolInfo *info)
{
        const char *dlna_profile;
        const char **speeds;
        GUPnPDLNAConversion conversion;
        GUPnPDLNAOperation operation;
        GUPnPDLNAFlags flags;

        dlna_profile = gupnp_protocol_info_get_dlna_profile (info);
        if (dlna_profile == NULL) {
                g_string_append_printf (str, ":");
        } else {
                g_string_append_printf (str, ":DLNA.ORG_PN=%s;", dlna_profile);
        }

        operation = gupnp_protocol_info_get_dlna_operation (info);
        if (operation != GUPNP_DLNA_OPERATION_NONE &&
            /* the OP parameter is only allowed for the "http-get"
             * and "rtsp-rtp-udp" protocols
             */
            (strcmp (gupnp_protocol_info_get_protocol (info),
                     "http-get") == 0 ||
             strcmp (gupnp_protocol_info_get_protocol (info),
                     "rtsp-rtp-udp") == 0))
                g_string_append_printf (str, "DLNA.ORG_OP=%.2x;", operation);

        /* Specify PS parameter if list of play speeds is provided */
        speeds = gupnp_protocol_info_get_play_speeds (info);
        if (speeds != NULL) {
                int i;

                g_string_append (str, "DLNA.ORG_PS=");

                for (i = 0; speeds[i]; i++) {
                        g_string_append (str, speeds[i]);

                        if (speeds[i + 1])
                                g_string_append_c (str, ',');
                }
                g_string_append_c (str, ';');
        }

        conversion = gupnp_protocol_info_get_dlna_conversion (info);
        /* omit the CI parameter for non-converted content */
        if (conversion != GUPNP_DLNA_CONVERSION_NONE)
                g_string_append_printf (str, "DLNA.ORG_CI=%d;", conversion);

        flags = gupnp_protocol_info_get_dlna_flags (info);
        /* Omit the FLAGS parameter if no or DLNA profile are set */
        if (flags != GUPNP_DLNA_FLAGS_NONE && dlna_profile != NULL) {
                g_string_append_printf (str, "DLNA.ORG_FLAGS=%.8x", flags);
                /*  append 24 reserved hex-digits */
                g_string_append_printf (str,
                                        "0000" "0000" "0000"
                                        "0000" "0000" "0000");
        }

        /* if nothing of the above was set, use the "match all" rule */
        switch (str->str[str->len - 1]) {
                case ':':
                        g_string_append_c (str, '*');
                        break;
                case ';':
                        g_string_erase (str, str->len - 1, 1);
                        break;
                default:
                        break;
        }
}
Exemple #4
0
static QString createDetailsForObject(GUPnPDIDLLiteObject *object)
{
    QString result;

    if (GUPNP_IS_DIDL_LITE_CONTAINER(object)) {
        return result;
    }

    GList* resources = gupnp_didl_lite_object_get_resources(object);
    GList* it = resources;

    const char *author = gupnp_didl_lite_object_get_artist(object);
    const char *album = gupnp_didl_lite_object_get_album(object);

    if (author != 0) {
        result += QString::fromLatin1("%1").arg(QString::fromUtf8(author));
    }

    if (album != 0) {
        if (not result.isEmpty()) {
            result += QLatin1String(" | ");
        }
        result += QString::fromLatin1("%1").arg(QString::fromUtf8(album));
    }

    const QLatin1String empty = QLatin1String(" ");
    while (it) {
        GUPnPDIDLLiteResource *res = (GUPnPDIDLLiteResource*) it->data;
        GUPnPProtocolInfo *info = gupnp_didl_lite_resource_get_protocol_info(res);
        // use first non-transcoded uri; might be problematic
        if (gupnp_protocol_info_get_dlna_conversion (info) == GUPNP_DLNA_CONVERSION_NONE) {
            long duration = gupnp_didl_lite_resource_get_duration(res);
            if (duration > 0) {
                if (not result.isEmpty()) {
                    result += empty;
                }
                result += formatTime(duration);

            }

            int width = gupnp_didl_lite_resource_get_width(res);
            int height = gupnp_didl_lite_resource_get_height(res);
            if (width > 0 && height > 0) {
                if (not result.isEmpty()) {
                    result += empty;
                }
                result += QString::fromLatin1("%1x%2").arg(QString::number(width), QString::number(height));
            }

            gint64 size = gupnp_didl_lite_resource_get_size64(res);
            if (size > 0) {
                if (not result.isEmpty()) {
                    result += empty;
                }

                result += formatSize(size);
            }

            break;
        }
        it = it->next;
    }

    g_list_free_full(resources, g_object_unref);

    return result;
}