root/rat/trunk/rtcp.c @ 1939

Revision 1939, 4.5 KB (checked in by ucaccsp, 16 years ago)

Rearrange time.c and rat_time.h to be timers.[ch], 'coz it's neater.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * FILE:    rtcp.c
3 * PROGRAM: RAT
4 * AUTHORS: Vicky Hardman + Isidor Kouvelas + Colin Perkins
5 *
6 * $Revision$
7 * $Date$
8 *
9 * Copyright (c) 1995,1996 University College London
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, is permitted, for non-commercial use only, provided
14 * that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 *    must display the following acknowledgement:
22 *      This product includes software developed by the Computer Science
23 *      Department at University College London
24 * 4. Neither the name of the University nor of the Department may be used
25 *    to endorse or promote products derived from this software without
26 *    specific prior written permission.
27 * Use of this software for commercial purposes is explicitly forbidden
28 * unless prior written permission is obtained from the authors.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 */
42
43#include "config_unix.h"
44#include "config_win32.h"
45#include "assert.h"
46#include "util.h"
47#include "rtcp.h"
48#include "session.h"
49#include "interfaces.h"
50#include "rtcp_pckt.h"
51#include "rtcp_db.h"
52#include "timers.h"
53
54void 
55service_rtcp(session_struct    *sp,
56             session_struct    *sp2,
57             pckt_queue_struct *rtcp_pckt_queue_ptr,
58             u_int32            cur_time)
59{
60        double                           RTCP_SIZE_GAIN = (1.0/16.0);   /* Copied from RFC1889 [csp] */
61        pckt_queue_element_struct       *pckt;
62
63        while (rtcp_pckt_queue_ptr->queue_empty == FALSE) {
64                pckt = get_pckt_off_queue(rtcp_pckt_queue_ptr);
65                if (rtcp_check_rtcp_pkt(pckt->pckt_ptr, pckt->len)) {
66                        rtcp_decode_rtcp_pkt(sp, sp2, pckt->pckt_ptr, pckt->len, cur_time);
67                        sp->db->avg_size += (int)((pckt->len - sp->db->avg_size)*RTCP_SIZE_GAIN);    /* Update the average RTCP packet size... */
68                        sp->db->report_interval = rtcp_interval(sp->db->members, sp->db->senders, sp->db->rtcp_bw, sp->db->sending,
69                                                        0, &(sp->db->avg_size), sp->db->initial_rtcp, get_freq(sp->device_clock));
70                } else {
71#ifdef DEBUG
72                        int i;
73
74                        printf("RTCP packet failed header validity check!\n");
75                        for (i=0; i<pckt->len; i++) {
76                                printf("%02x ", (unsigned char) pckt->pckt_ptr[i]);
77                                if ((i % 16) == 15) {
78                                        printf("\n");
79                                }
80                         }
81                         printf("\n");
82#endif
83                }
84                free_pckt_queue_element(&pckt);
85        }
86        rtcp_update(sp, sp->rtcp_fd, sp->net_maddress, (u_int16)sp->rtcp_port);
87}
88
89char *get_cname(void)
90{
91        /* Set the CNAME. This is "user@hostname" or just "hostname" if the username cannot be found. */
92        char                    *uname;
93        char                    *hname;
94        char                    *cname;
95        struct hostent          *hent;
96        struct in_addr           iaddr;
97#ifndef WIN32
98        struct passwd           *pwent;
99#endif
100
101        cname = (char *) xmalloc(MAXHOSTNAMELEN + 10);
102        cname[0] = '\0';
103
104        /* First, fill in the username... */
105#ifdef WIN32
106        uname = getenv("USER");
107#else
108        pwent = getpwuid(getuid());
109        uname = pwent->pw_name;
110#endif
111        if (uname != NULL) {
112                sprintf(cname, "%s@", uname);
113        }
114
115        /* Now the hostname. Must be dotted-quad IP address. */
116        hname = cname + strlen(cname);
117        if (gethostname(hname, MAXHOSTNAMELEN) != 0) {
118                perror("Cannot get hostname!");
119                return NULL;
120        }
121        hent = gethostbyname(hname);
122        memcpy(&iaddr.s_addr, hent->h_addr, sizeof(iaddr.s_addr));
123        strcpy(hname, inet_ntoa(iaddr));
124        return cname;
125}
126
127u_int32 get_ssrc(void)
128{
129#ifdef WIN32
130        srand48((unsigned int)GetTickCount());
131        return (lrand48()<<16)|(GetTickCount() & 0xffff);
132#else
133        return lrand48();
134#endif
135}
Note: See TracBrowser for help on using the browser.