⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statistics.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    if(total30_is_set && lost30_is_set)    {        gdouble percent = 0;                        if(total30 > 0)        {            percent = 100.0 * (gdouble)lost30 / (gdouble)total30;        }                formatted_str = g_strdup_printf("(%.2f%%)", percent);        gtk_label_set_text(info->main[STATISTIC_UI_LOST30_PERCENT], formatted_str);        g_free(formatted_str);    }    else    {        gtk_label_set_text(info->main[STATISTIC_UI_LOST30_PERCENT], "---");    }    stream_prop = g_string_new("");        g_string_printf(stream_prop, "Source%d.ServerInfo", info->current_source);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        str_val = g_value_get_string(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_SERVER_INFO], str_val);        g_value_unset(&value);    }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_SERVER_INFO], "---");            }        // Codec is either CodecName or Codec - CodecText    g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.CodecName",                    info->current_source,                    info->current_stream);                                                  result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        str_val = g_value_get_string(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_CODEC_NAME], str_val);        g_value_unset(&value);    }    else    {        // Try Codec (CodecText)        gchar* codec = NULL;        gchar* codec_text = NULL;        g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.Codec",                        info->current_source,                        info->current_stream);        result = hx_player_get_statistic(info->player, stream_prop->str, &value);        if(result)        {            codec = g_strdup(g_value_get_string(&value));            g_value_unset(&value);        }        g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.CodecText",                        info->current_source,                        info->current_stream);        result = hx_player_get_statistic(info->player, stream_prop->str, &value);        if(result)        {            codec_text = g_strdup(g_value_get_string(&value));            g_value_unset(&value);        }        if(codec && codec_text)        {            formatted_str = g_strdup_printf("%s (%s)", codec, codec_text);        }        else if(codec)        {            formatted_str = g_strdup(codec);        }        else if(codec_text)        {            formatted_str = g_strdup(codec_text);        }        else        {            formatted_str = g_strdup("---");        }        if(codec)        {            g_free(codec);        }        if(codec_text)        {            g_free(codec_text);        }                gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_CODEC_NAME], formatted_str);        g_free(formatted_str);            }    g_string_printf(stream_prop, "Source%d.Stream%d.ClipBandwidth",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        val = g_value_get_int(&value);        formatted_str = g_strdup_printf("%.1f Kbps", (gdouble)val / 1000.0);        g_value_unset(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_CLIP_BANDWIDTH], formatted_str);        g_free(formatted_str);            }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_CLIP_BANDWIDTH], "---");            }    g_string_printf(stream_prop, "Source%d.TransportMode",                    info->current_source);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        str_val = g_value_get_string(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_TRANSPORT_MODE], str_val);        g_value_unset(&value);    }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_TRANSPORT_MODE], _("Unknown"));            }        g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.CodecRate",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        str_val = g_value_get_string(&value);        formatted_str = g_strdup_printf("%s fps", str_val);        g_value_unset(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_CODEC_RATE], formatted_str);        g_free(formatted_str);            }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_CODEC_RATE], "---");    }    g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.FramesDisplayed",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        str_val = g_value_get_string(&value);        formatted_str = g_strdup_printf("%s%%", str_val);        g_value_unset(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_DISPLAYED], formatted_str);        g_free(formatted_str);            }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_DISPLAYED], "---");    }    g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.CurrentFrameRate",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        str_val = g_value_get_string(&value);        formatted_str = g_strdup_printf("%s fps", str_val);        g_value_unset(&value);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_CURRENT_FRAME_RATE], formatted_str);        g_free(formatted_str);            }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_CURRENT_FRAME_RATE], "---");    }    g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.FramesLost",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        val = g_value_get_int(&value);        g_value_unset(&value);        formatted_str = g_strdup_printf("%d", val);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_LOST], formatted_str);        g_free(formatted_str);            }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_LOST], "---");    }        g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.PostFilter",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        val = g_value_get_int(&value);        g_value_unset(&value);                if(val)        {            gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_POST_FILTER], _("ON"));        }        else        {            gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_POST_FILTER], _("OFF"));        }    }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_POST_FILTER], "---");    }    g_string_printf(stream_prop, "Source%d.Stream%d.Renderer.FramesDropped",                    info->current_source,                    info->current_stream);    result = hx_player_get_statistic(info->player, stream_prop->str, &value);    if(result)    {        val = g_value_get_int(&value);        g_value_unset(&value);        formatted_str = g_strdup_printf("%d", val);        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_DROPPED], formatted_str);        g_free(formatted_str);            }    else    {        gtk_label_set_text(info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_DROPPED], "---");    }        g_string_free(stream_prop, TRUE);}   static gbooleanhsd_update_statistics(gpointer data){    HXStatisticsDialog* info = (HXStatisticsDialog*)data;    update_statistics(info);        return TRUE; // don't remove}voidhsd_stream_combo_changed(GtkEntry* entry){    /* GtkCombo's suck. Move this to GtkComboBox when our gtk baseline moves up. */    HXStatisticsDialog* info;    GtkWidget* toplevel;    const gchar* text;    guint source_len = sizeof("Source") - 1;    guint stream_len = sizeof("Stream") - 1;    toplevel = hxcommon_get_toplevel_widget_no_menus(GTK_WIDGET(entry));    info = (HXStatisticsDialog*)g_object_get_data(G_OBJECT(toplevel), "info");    g_return_if_fail(info != NULL);        text = gtk_entry_get_text(entry);    if(text)    {        if(strlen(text) >= source_len + stream_len + 3)        {            text += source_len;            info->current_source = atoi(text);                        while(*text && *text != '.')            {                text++;            }            text += stream_len + 1;            info->current_stream = atoi(text);                        update_statistics(info);        }    }    }static voidhsd_destroy (GtkWidget* /* widget */,             HXStatisticsDialog* info){    g_signal_handler_disconnect(G_OBJECT(info->player), info->clip_bandwidth_handler);    g_signal_handler_disconnect(G_OBJECT(info->player), info->play_handler);    g_array_free(info->stream_counts_array, TRUE);    gtk_timeout_remove(info->timer_id);    glade_xml_destroy (info->xml);    g_object_unref(info->bandwidth_observer);    g_free(info);}static voidhsd_size_request (GtkWidget *widget,                  GtkRequisition *request_out){    if(request_out->width > widget->allocation.width)    {        /* We're going to have to grow, so grow big  */        request_out->width = (gint)(1.05 * request_out->width);    }    else    {        /* Pin us at the currently allocated width */        request_out->width = widget->allocation.width;    }}GtkDialog*hxplay_statistics_dialog_new (HXPlayer* player){    GladeXML *xml;    GtkWidget *dialog;    gchar *filename;    HXStatisticsDialog* info;    gboolean result;    GtkWidget* bandwidth_graph;    GValue value;    memset(&value, 0, sizeof(value));        filename = hxcommon_locate_file("statistics.glade");    xml = glade_xml_new (filename, NULL, NULL);    g_free(filename);    g_return_val_if_fail(xml != NULL, NULL);    info = g_new0(HXStatisticsDialog, 1);        result = get_statistic_dialog_info(xml, player, info);    g_return_val_if_fail(result, NULL);    dialog = glade_xml_get_widget (xml, "hxplayer_statistics_dialog");    g_object_set_data(G_OBJECT(dialog), "info", info);    bandwidth_graph = glade_xml_get_widget (xml, "hsd_bandwidth_graph");        result = hx_player_get_statistic(player, "ClipBandwidth", &value);    if(result)    {        gint bandwidth;        bandwidth = g_value_get_int(&value);                hx_bandwidth_graph_set_ideal_bandwidth(HX_BANDWIDTH_GRAPH(bandwidth_graph),                                               bandwidth);        g_value_unset(&value);            }        info->bandwidth_observer = hx_statistics_observer_new(player,                                                         "CurrentBandwidth");    update_statistics(info);        info->timer_id = gtk_timeout_add(STATISTICS_UPDATE_INTERVAL,                                     hsd_update_statistics,                                     info);            /* Use current clip bandwidth as max/min bandwidth */    result = hx_player_get_statistic(player, "CurrentBandwidth", &value);    if(result)    {        update_bandwidth(info, &value);        g_value_unset(&value);    }    info->clip_bandwidth_handler =        g_signal_connect_swapped(G_OBJECT(player),                                 "clip_bandwidth_changed",                                 G_CALLBACK(hx_bandwidth_graph_set_ideal_bandwidth),                                 bandwidth_graph);    info->play_handler =        g_signal_connect_swapped(G_OBJECT(player),                                 "play",                                 G_CALLBACK(hsd_play),                                 info);    g_signal_connect(info->bandwidth_observer,                     "statistic_modified",                     G_CALLBACK(hsd_update_bandwidth),                     info);    g_signal_connect (G_OBJECT (dialog), "destroy",                      G_CALLBACK (hsd_destroy),                      info);    g_signal_connect (G_OBJECT (dialog), "size-request",                      G_CALLBACK (hsd_size_request),                      info);    return GTK_DIALOG(dialog);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -