File: ui_send_stats.c

package info (click to toggle)
rat 4.2.22-2.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,896 kB
  • ctags: 3,717
  • sloc: ansic: 36,542; tcl: 2,740; sh: 2,675; makefile: 295
file content (143 lines) | stat: -rw-r--r-- 5,042 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * FILE:    ui_send_stats.c
 * PROGRAM: RAT
 * AUTHOR:  Colin Perkins 
 * 	
 * Routines which send stats updates to the user interface.
 *
 * Copyright (c) 2000-2001 University College London
 * All rights reserved.
 */
 
#ifndef HIDE_SOURCE_STRINGS
static const char cvsid[] = 
	"$Id: ui_send_stats.c,v 1.5 2001/01/08 20:30:13 ucaccsp Exp $";
#endif /* HIDE_SOURCE_STRINGS */

#include "config_unix.h"
#include "config_win32.h"
#include "debug.h"
#include "session.h"
#include "pdb.h"
#include "source.h"
#include "mix.h"
#include "transmit.h"
#include "mbus.h"
#include "mbus_parser.h"
#include "ui_send_rtp.h"
#include "ui_send_stats.h"
#include "ui_send_audio.h"

#include "parameters.h"

void
ui_send_stats(session_t *sp, char *addr, uint32_t ssrc)
{
	/* Send RAT specific statistics to the user interface... */
        const rtcp_rr           *rr;
        uint32_t                  fract_lost, my_ssrc, total_lost;
        double                   skew_rate;
	char			*args, *mbes;
        struct s_source      	*src;
        uint32_t               	 buffered, delay;
        pdb_entry_t             *pdbe;

	session_validate(sp);
	if (!sp->ui_on) return;
        if (pdb_item_get(sp->pdb, ssrc, &pdbe) == FALSE) {
                debug_msg("pdb entry does not exist (0x%08x)\n", ssrc);
                return;
        }
        pdbe->last_ui_update = sp->cur_ts;

        if (pdbe->enc_fmt) {
		mbes = mbus_encode_str(pdbe->enc_fmt);
                args = (char *) xmalloc(strlen(mbes) + 12);
                sprintf(args, "\"%08x\" %s", pdbe->ssrc, mbes);
                xfree(mbes);
        } else {
                args = (char *) xmalloc(19);
                sprintf(args, "\"%08x\" unknown", pdbe->ssrc);
        }

        mbus_qmsg(sp->mbus_engine, addr, "rtp.source.codec", args, FALSE);
        xfree(args);

        src = source_get_by_ssrc(sp->active_sources, pdbe->ssrc);
        if (src) {
                buffered = timestamp_to_ms(source_get_audio_buffered(src));
                delay    = timestamp_to_ms(source_get_playout_delay(src));
                skew_rate = source_get_skew_rate(src);
        } else {
                buffered  = 0;
                delay     = 0;
                skew_rate = 1.0;
        }

        mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.audio.buffered", "\"%08lx\" %ld", pdbe->ssrc, buffered);
        mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.audio.delay", "\"%08lx\" %ld", pdbe->ssrc, delay);
        mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.audio.skew", "\"%08lx\" %.5f", pdbe->ssrc, skew_rate);
        mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.spike.events", "\"%08lx\" %ld", pdbe->ssrc, pdbe->spike_events);
        mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.spike.toged", "\"%08lx\" %ld",  pdbe->ssrc, pdbe->spike_toged);
        my_ssrc = rtp_my_ssrc(sp->rtp_session[0]);
        rr = rtp_get_rr(sp->rtp_session[0], my_ssrc, pdbe->ssrc);
        if (rr != NULL) {
                fract_lost = (rr->fract_lost * 100) >> 8;
                total_lost = rr->total_lost;
        } else {
                debug_msg("No rr\n");
                fract_lost = 0;
                total_lost = 0;
        }

        ui_send_rtp_packet_loss(sp, addr, my_ssrc, pdbe->ssrc, fract_lost);
	mbus_qmsgf(sp->mbus_engine, addr, FALSE, "rtp.source.reception", "\"%08lx\" %6ld %6ld %6ld %6ld %6ld %6d", 
		  pdbe->ssrc, pdbe->received, total_lost, pdbe->misordered, pdbe->duplicates, timestamp_to_ms(pdbe->jitter), pdbe->jit_toged);
	mbus_qmsgf(sp->mbus_engine, addr, FALSE, "rtp.source.packet.duration", "\"%08lx\" %3d", 
	           pdbe->ssrc, pdbe->inter_pkt_gap * 1000 / pdbe->sample_rate);
}

void
ui_send_periodic_updates(session_t *sp, char *addr, int elapsed_time) 
{
        static uint32_t power_time = 0;
        static uint32_t bps_time   = 0;

	if (!sp->ui_on) return;
	session_validate(sp);

        bps_time   += elapsed_time;
        if (bps_time > 10 * sp->meter_period) {
		double inbps = 0.0, outbps = 0.0;
		uint32_t scnt, sidx;
		struct s_source *s;
		
		if (!sp->ui_on) return;
		scnt = source_list_source_count(sp->active_sources);
		for(sidx = 0; sidx < scnt; sidx++) {
			s = source_list_get_source_no(sp->active_sources, sidx);
			inbps += source_get_bps(s);
		}
		mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.bps.in", "%.0f", inbps);        

		outbps = tx_get_bps(sp->tb);
		mbus_qmsgf(sp->mbus_engine, addr, FALSE, "tool.rat.bps.out", "%.0f", outbps);        
                bps_time = 0;
        }

        power_time += elapsed_time;
        if (power_time > sp->meter_period) {
		if (sp->meter && (sp->ms != NULL)) {
                        uint16_t me = 0;
                        if (sp->playing_audio) {
                                me = mix_get_energy(sp->ms, 160);
                        }
                        ui_send_audio_output_powermeter(sp, sp->mbus_ui_addr, lin2vu(me, 100, VU_OUTPUT));
		}
		if (tx_is_sending(sp->tb)) {
			tx_update_ui(sp->tb);
		}
                power_time = 0;
        }
}