📄 statistics.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: statistics.cpp,v 1.6.2.4 2004/10/18 18:53:31 rggammon Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** */#include "hxcom.h"#include "hxwintyp.h"#include "hxcore.h"#include "statistics.h"#include "commonapp.h"#include "hxstatisticsobserver.h"#include "hxplayer-i18n.h"#include "hxbandwidthgraph.h"#include <gtk/gtk.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#define STATISTICS_UPDATE_INTERVAL 1000 /* in ms */extern "C"{GtkWidget* hsd_create_bandwidth_graph(gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2);void hsd_stream_combo_changed(GtkEntry* entry);}/* Per-player statistics */enum{ STATISTIC_UI_CLIP_BANDWIDTH = 0, STATISTIC_UI_CURRENT_BANDWIDTH, STATISTIC_UI_MIN_BANDWIDTH, STATISTIC_UI_MAX_BANDWIDTH, STATISTIC_UI_AVERAGE_BANDWIDTH, STATISTIC_UI_RECEIVED, STATISTIC_UI_RECEIVED_PERCENT, STATISTIC_UI_RECOVERED, STATISTIC_UI_RECOVERED_PERCENT, STATISTIC_UI_TOTAL_RECEIVED, STATISTIC_UI_TOTAL_RECEIVED_PERCENT, STATISTIC_UI_LOST, STATISTIC_UI_LOST_PERCENT, STATISTIC_UI_LATE, STATISTIC_UI_LATE_PERCENT, STATISTIC_UI_TOTAL_MISSED, STATISTIC_UI_TOTAL_MISSED_PERCENT, STATISTIC_UI_RESEND_REQUESTED, STATISTIC_UI_RESEND_RECEIVED, STATISTIC_UI_LOW_LATENCY, STATISTIC_UI_AVERAGE_LATENCY, STATISTIC_UI_HIGH_LATENCY, STATISTIC_UI_LOST30, STATISTIC_UI_LOST30_PERCENT, STATISTIC_UI_COUNT};/* Per-source statistics */enum{ STATISTIC_UI_SOURCE_SERVER_INFO = 0, STATISTIC_UI_SOURCE_RENDERER_CODEC_NAME, STATISTIC_UI_SOURCE_CLIP_BANDWIDTH, STATISTIC_UI_SOURCE_TRANSPORT_MODE, STATISTIC_UI_SOURCE_RENDERER_CODEC_RATE, STATISTIC_UI_SOURCE_RENDERER_FRAMES_DISPLAYED, STATISTIC_UI_SOURCE_RENDERER_CURRENT_FRAME_RATE, STATISTIC_UI_SOURCE_RENDERER_FRAMES_LOST, STATISTIC_UI_SOURCE_RENDERER_POST_FILTER, STATISTIC_UI_SOURCE_RENDERER_FRAMES_DROPPED, /* These stats aren't reported in the other players: Duplicate Normal Total30 BufferingMode OutOfOrder */ STATISTIC_UI_SOURCE_COUNT};typedef struct _HXStatisticsDialog{ GtkLabel* main [STATISTIC_UI_COUNT]; GtkLabel* source[STATISTIC_UI_SOURCE_COUNT]; GladeXML* xml; HXPlayer* player; HXBandwidthGraph* bandwidth_graph; /* These are updated by statistics observers */ gint max_bandwidth; gint min_bandwidth; gboolean max_bandwidth_is_set; gboolean min_bandwidth_is_set; HXStatisticsObserver* bandwidth_observer; HXStatisticsObserver* advanced_observer; GtkCombo* streams_combo; gint source_count; GArray* stream_counts_array; gint current_source; gint current_stream; gint clip_bandwidth_handler; gint play_handler; guint timer_id;} HXStatisticsDialog;static voidupdate_bandwidth(HXStatisticsDialog* info, GValue* value){ gint bandwidth; bandwidth = g_value_get_int(value); if(bandwidth < info->min_bandwidth || !info->min_bandwidth_is_set) { info->min_bandwidth_is_set = TRUE; info->min_bandwidth = bandwidth; } if(bandwidth > info->max_bandwidth || !info->max_bandwidth_is_set) { info->max_bandwidth_is_set = TRUE; info->max_bandwidth = bandwidth; } if(info->bandwidth_graph) { hx_bandwidth_graph_add_value(info->bandwidth_graph, bandwidth); }}static voidhsd_update_bandwidth(GObject* /* observer */, const gchar* /* key */, GValue* value, gpointer data){ HXStatisticsDialog* info; info = (HXStatisticsDialog*) data; update_bandwidth(info, value);}static voidhsd_play(HXStatisticsDialog* info){ gboolean result; GValue value; memset(&value, 0, sizeof(value)); info->min_bandwidth_is_set = FALSE; info->max_bandwidth_is_set = FALSE; result = hx_player_get_statistic(info->player, "CurrentBandwidth", &value); if(result) { update_bandwidth(info, &value); g_value_unset(&value); }}static gbooleanget_statistic_dialog_info(GladeXML* xml, HXPlayer* player, HXStatisticsDialog* info){ guint i; info->player = player; info->xml = xml; info->streams_combo = GTK_COMBO(glade_xml_get_widget (info->xml, "hsd_stream_combo")); info->bandwidth_graph = HX_BANDWIDTH_GRAPH(glade_xml_get_widget (info->xml, "hsd_bandwidth_graph")); g_return_val_if_fail(info->streams_combo && info->bandwidth_graph, FALSE); info->stream_counts_array = g_array_new(TRUE, TRUE, sizeof(guint)); info->main[STATISTIC_UI_CLIP_BANDWIDTH ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_clip_bandwidth")); info->main[STATISTIC_UI_CURRENT_BANDWIDTH] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_current_bandwidth")); info->main[STATISTIC_UI_MIN_BANDWIDTH ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_min_bandwidth")); info->main[STATISTIC_UI_MAX_BANDWIDTH ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_max_bandwidth")); info->main[STATISTIC_UI_AVERAGE_BANDWIDTH] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_average_bandwidth")); info->main[STATISTIC_UI_RECEIVED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_received")); info->main[STATISTIC_UI_RECEIVED_PERCENT ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_received_percent")); info->main[STATISTIC_UI_RECOVERED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_recovered")); info->main[STATISTIC_UI_RECOVERED_PERCENT] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_recovered_percent")); info->main[STATISTIC_UI_TOTAL_RECEIVED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_total_received")); info->main[STATISTIC_UI_TOTAL_RECEIVED_PERCENT] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_total_received_percent")); info->main[STATISTIC_UI_LOST ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_lost")); info->main[STATISTIC_UI_LOST_PERCENT ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_lost_percent")); info->main[STATISTIC_UI_LATE ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_late")); info->main[STATISTIC_UI_LATE_PERCENT ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_late_percent")); info->main[STATISTIC_UI_TOTAL_MISSED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_total_missed")); info->main[STATISTIC_UI_TOTAL_MISSED_PERCENT] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_total_missed_percent")); info->main[STATISTIC_UI_RESEND_REQUESTED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_resend_requested")); info->main[STATISTIC_UI_RESEND_RECEIVED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_resend_received")); info->main[STATISTIC_UI_LOW_LATENCY ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_low_latency")); info->main[STATISTIC_UI_AVERAGE_LATENCY ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_average_latency")); info->main[STATISTIC_UI_HIGH_LATENCY ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_high_latency")); info->main[STATISTIC_UI_LOST30 ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_lost_30")); info->main[STATISTIC_UI_LOST30_PERCENT ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_lost_30_percent")); info->source[STATISTIC_UI_SOURCE_SERVER_INFO ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_server_info")); info->source[STATISTIC_UI_SOURCE_RENDERER_CODEC_NAME ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_codec_name")); info->source[STATISTIC_UI_SOURCE_CLIP_BANDWIDTH ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_clip_bandwidth")); info->source[STATISTIC_UI_SOURCE_TRANSPORT_MODE ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_transport_mode")); info->source[STATISTIC_UI_SOURCE_RENDERER_CODEC_RATE ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_codec_frame_rate")); info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_DISPLAYED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_frames_displayed")); info->source[STATISTIC_UI_SOURCE_RENDERER_CURRENT_FRAME_RATE] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_current_frame_rate")); info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_LOST ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_frames_lost")); info->source[STATISTIC_UI_SOURCE_RENDERER_POST_FILTER ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_post_filter")); info->source[STATISTIC_UI_SOURCE_RENDERER_FRAMES_DROPPED ] = GTK_LABEL(glade_xml_get_widget (info->xml, "hsd_source_renderer_frames_dropped")); for(i = 0; i < STATISTIC_UI_COUNT; i++) { g_return_val_if_fail(info->main[i], FALSE); } for(i = 0; i < STATISTIC_UI_SOURCE_COUNT; i++) { g_return_val_if_fail(info->source[i], FALSE); } return TRUE;}GtkWidget*hsd_create_bandwidth_graph(gchar*, gchar*, gchar*, gint, gint){ GtkWidget* bandwidth_graph; bandwidth_graph = hx_bandwidth_graph_new(); return bandwidth_graph;}static voidupdate_source_stream_count(HXPlayer* player, gint* sources_count_ptr, GArray** stream_counts_ptr, gboolean* changed_ptr){ gint source = 0; gint stream = 0; gchar* stream_id; gboolean result; GValue value; memset(&value, 0, sizeof(value)); for(source = 0; ; source++) { for(stream = 0; ; stream++) { stream_id = g_strdup_printf("Source%d.Stream%d", source, stream);#if 0 result = hx_player_get_statistic(player, stream_id, &value);#else // XXXRGG: Hack! Can't check for composite statistics right now, so // append Total, a randomly chosen child that should exist gchar stream_id_non_composite_hack[256]; snprintf(stream_id_non_composite_hack, sizeof(stream_id_non_composite_hack), "%s.Total", stream_id); result = hx_player_get_statistic(player, stream_id_non_composite_hack, &value);#endif g_free(stream_id); if(result) { guint sources_count = source + 1; g_value_unset(&value); if((source + 1) > *sources_count_ptr) { *sources_count_ptr = sources_count; *changed_ptr = TRUE; } } else { guint stream_count = stream; guint old_stream_count = g_array_index(*stream_counts_ptr, guint, source); if(stream_count != old_stream_count) { *changed_ptr = TRUE; g_array_insert_val(*stream_counts_ptr, source, stream); } break; } } if(!result && stream == 0) { break; } }}static voidupdate_statistics(HXStatisticsDialog* info){ gboolean result; GValue value; gint val; const gchar* str_val; gchar* formatted_str; memset(&value, 0, sizeof(value)); gint total = 0; gint received = 0; gint recovered = 0; gint lost = 0; gint late = 0; gint total30 = 0; gint lost30 = 0; gboolean total_is_set = FALSE; gboolean received_is_set = FALSE; gboolean recovered_is_set = FALSE; gboolean lost_is_set = FALSE; gboolean late_is_set = FALSE; gboolean total30_is_set = FALSE; gboolean lost30_is_set = FALSE; GString* stream_prop = NULL; gboolean streams_combo_dirty = FALSE; hx_bandwidth_graph_update(info->bandwidth_graph); update_source_stream_count(info->player, &info->source_count, &info->stream_counts_array, &streams_combo_dirty); /* Build streams combo */ if(streams_combo_dirty) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -