Example #1
0
RCMusicMetaData *rc_tag_read_metadata(const gchar *uri)
{
    GstElement *pipeline;
    GstElement *urisrc;
    GstElement *decodebin;
    GstElement *fakesink;
    GstPad *sink_pad;
    GstCaps *caps;
    GstStructure *structure;
    gint64 dura = 0;
    GstStateChangeReturn state_ret;
    GstMessage *msg;
    GstFormat fmt = GST_FORMAT_TIME;
    RCMusicMetaData *mmd;
    RCTagDecodedPadData decoded_pad_data;
    GstTagList *tags = NULL;
    gchar *encoding;
    const gchar *locale;
    if(uri==NULL)
    {
        return NULL;
    }
    if(rc_set_get_boolean("Metadata", "AutoEncodingDetect", NULL))
    {
        locale = rc_player_get_locale();
        if(strncmp(locale, "zh_CN", 5)==0)
        {
            g_setenv("GST_ID3_TAG_ENCODING", "GB18030:UTF-8", TRUE);
            g_setenv("GST_ID3V2_TAG_ENCODING", "GB18030:UTF-8", TRUE);
            rc_set_set_string("Metadata", "TagExEncoding", "GB18030:UTF-8");
        }
        else if(strncmp(locale, "zh_TW", 5)==0)
        {
            g_setenv("GST_ID3_TAG_ENCODING", "BIG5:UTF-8", TRUE);
            g_setenv("GST_ID3V2_TAG_ENCODING", "BIG5:UTF-8", TRUE);
            rc_set_set_string("Metadata", "TagExEncoding", "BIG5:UTF-8");
        }
        else if(strncmp(locale, "ja_JP", 5)==0)
        {
            g_setenv("GST_ID3_TAG_ENCODING", "ShiftJIS:UTF-8", TRUE);
            g_setenv("GST_ID3V2_TAG_ENCODING", "ShiftJIS:UTF-8", TRUE);
            rc_set_set_string("Metadata", "TagExEncoding", "ShiftJIS:UTF-8");
        }
    }
    else
    {
        encoding = rc_set_get_string("Metadata", "TagExEncoding", NULL);
        if(encoding!=NULL && strlen(encoding)>0)
        {
            g_setenv("GST_ID3_TAG_ENCODING", encoding, TRUE);
            g_setenv("GST_ID3V2_TAG_ENCODING", encoding, TRUE);
            g_free(encoding);
        }
    }
    mmd = g_new0(RCMusicMetaData, 1);
    mmd->uri = g_strdup(uri);
    urisrc = gst_element_make_from_uri(GST_URI_SRC, mmd->uri, "urisrc");
    if(urisrc==NULL)
    {
        rc_debug_module_perror(module_name, "Cannot load urisrc from "
            "given URI!");
        g_free(mmd);
        return NULL;
    }
    pipeline = gst_pipeline_new("pipeline");
    decodebin = gst_element_factory_make("decodebin2", NULL);
    if(decodebin==NULL)
        decodebin = gst_element_factory_make("decodebin", NULL);
    fakesink = gst_element_factory_make("fakesink", NULL);
    decoded_pad_data.pipeline = pipeline;
    decoded_pad_data.fakesink = fakesink;
    gst_bin_add_many(GST_BIN(pipeline), urisrc, decodebin, fakesink, NULL);
    gst_element_link(urisrc, decodebin);
    g_signal_connect(decodebin, "new-decoded-pad",
        G_CALLBACK(rc_tag_gst_new_decoded_pad_cb), &decoded_pad_data);
    gst_element_set_state(pipeline, GST_STATE_NULL);
    state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
    if(!state_ret)
    {
        if(pipeline!=NULL) gst_object_unref(GST_OBJECT(pipeline));
        g_free(mmd);
        return NULL;
    }
    while(1)
    {
        msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(pipeline),
            GST_CLOCK_TIME_NONE, GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_TAG |
            GST_MESSAGE_ERROR);
        if(GST_MESSAGE_TYPE(msg)!=GST_MESSAGE_TAG)
            break;
        gst_message_parse_tag(msg, &tags);
        rc_tag_get_tag(tags, mmd);
        gst_tag_list_free(tags);
        gst_message_unref(msg);
    }
    if(GST_MESSAGE_TYPE(msg)==GST_MESSAGE_ERROR)
        rc_debug_module_perror(module_name, "Cannot get tag!");
    gst_message_unref(msg);
    gst_element_query_duration(pipeline, &fmt, &dura);
    sink_pad = gst_element_get_static_pad(fakesink, "sink");
    if(sink_pad!=NULL)
    {
        caps = gst_pad_get_negotiated_caps(sink_pad);
        if(caps!=NULL)
        {
            structure = gst_caps_get_structure(caps, 0);
            gst_structure_get_int(structure, "rate", &mmd->samplerate);
            gst_structure_get_int(structure, "channels", &mmd->channels);
            gst_caps_unref(caps);
        }
        gst_object_unref(sink_pad);
    }
    mmd->length = dura;
    mmd->audio_flag = decoded_pad_data.audio_flag;
    mmd->video_flag = decoded_pad_data.video_flag;
    state_ret = gst_element_set_state(pipeline, GST_STATE_NULL);
    if(pipeline!=NULL) gst_object_unref(GST_OBJECT(pipeline));
    return mmd;
}
Example #2
0
static void rc_gui_list2_dnd_data_received(GtkWidget *widget,
    GdkDragContext *context, gint x, gint y, GtkSelectionData *seldata,
    guint info, guint time, gpointer data)
{
    guint length = 0;
    gint i, j, k;
    gint *reorder_array = NULL;
    gint *indices = NULL;
    gint *index = NULL;
    gint target = 0;
    guint insert_num = 0;
    GList *path_list_foreach = NULL;
    GtkTreeViewDropPosition pos;
    GtkTreePath *path_start = NULL;
    GtkTreePath *path_drop = NULL;
    gint list_length = 0;
    gboolean insert_flag = FALSE;
    GList *path_list = NULL;
    gchar *uris = NULL;
    gchar **uri_array = NULL;
    gchar *uri = NULL;
    guint count = 0;
    gboolean flag = FALSE;
    gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(
        rc_ui->list2_tree_view), x,y, &path_drop, &pos);
    if(path_drop!=NULL)
    {
        index = gtk_tree_path_get_indices(path_drop);
        target = index[0];
        gtk_tree_path_free(path_drop);
    }
    else target = -2;
    switch(info)
    {
        case 1: 
        {
            memcpy(&path_list, gtk_selection_data_get_data(seldata),
                sizeof(path_list));
            if(path_list==NULL) break;
            length = g_list_length(path_list);
            indices = g_new(gint, length);
            for(path_list_foreach=path_list;path_list_foreach!=NULL;
                path_list_foreach=g_list_next(path_list_foreach))
            {
                path_start = path_list_foreach->data;
                index = gtk_tree_path_get_indices(path_start);
                indices[count] = index[0];
                count++;
            }
            g_qsort_with_data(indices, length, sizeof(gint),
                (GCompareDataFunc)rc_gui_list2_comp_func, NULL);
            if(pos==GTK_TREE_VIEW_DROP_AFTER ||
                pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER) target++;
            list_length = gtk_tree_model_iter_n_children(
                rc_ui->list2_tree_model, NULL);
            if(target<0) target = list_length;
            reorder_array = g_new0(gint, list_length);
            i = 0;
            j = 0;
            count = 0;
            while(i<list_length)
            {
                if((j>=length || count!=indices[j]) && count!=target)
                {
                    reorder_array[i] = count;
                    count++;
                    i++;
                }
                else if(count==target && !insert_flag)
                {
                    for(k=0;k<length;k++)
                    {
                        if(target==indices[k])
                        {
                            target++;
                            count++;
                        }
                        reorder_array[i] = indices[k];
                        i++;
                    }
                    reorder_array[i] = target;
                    i++;
                    count++;
                    insert_flag = TRUE;
                }
                else if(j<length && count==indices[j])
                {
                    count++;             
                    j++;
                }
                else break;
            }
            gtk_list_store_reorder(GTK_LIST_STORE(rc_ui->list2_tree_model),
                reorder_array);
            g_free(reorder_array);
            g_free(indices);
            break;
        }
        case 6:
        {
            uris = (gchar *)gtk_selection_data_get_data(seldata);
            if(uris==NULL) break;
            if(pos==GTK_TREE_VIEW_DROP_AFTER ||
                pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER) target++;
            list_length = gtk_tree_model_iter_n_children(
                rc_ui->list2_tree_model, NULL);
            if(target<0) target = list_length;
            uri_array = g_uri_list_extract_uris(uris);
            insert_num = 0;
            for(count=0;uri_array[count]!=NULL;count++)
            {
                uri = uri_array[count];
                if(rc_player_check_supported_format(uri))
                {
                    flag = rc_plist_insert_music(uri, 
                        rc_gui_list1_get_selected_index(), target);
                    target++;
                    insert_num++;
                }
            }
            g_strfreev(uri_array);
            if(insert_num>0)
                rc_gui_status_task_set(1, insert_num);
            break;
        }
        case 7:
        {
            rc_debug_module_perror(module_name,
                "Unknown dnd data in list2: %s",
                gtk_selection_data_get_data(seldata));
        }
        default: break;
    }
}