root/vic/branches/cc/rtp/session.h @ 4260

Revision 4260, 7.4 KB (checked in by soohyunc, 6 years ago)

o XR header modified (simplified than before for the simplicity).

o fixed some header leength calculation part.

o basic control loop works, but due to the header length calculation problem,

the conveyed information over RTCP XR seems to be corrupted (or incorrect).
for example, the seqno and/or timestamp from the data sender does not reach
to the data receiver through XR channel correctly.

o first, we need to see "send_xreport()" method and check if XR packet length

was calculated (or assigned) correctly.

o second, we may need to change "parse_xr_records()" method such that when we

send the XR report back to the data sender, it needs to send the whole RTCP
packet (i.e., including RTCP packet header). However, current implementatiaon
does not include the RTCP hearder. maybe, this is the reason why the
information conveyed through RTCP XR is displayed incorrectly on console.

To-do:
(1) resolve the two issues above.
(2) TfwcSndr? still cannot handle if multiple packets passed to it from

Transmitter module.

(3) main TFWC algorithm still missing (once, the XR control loop works, it

would be just a matter of time to imeplement it.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * Copyright (c) 1995 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the Network Research
16 *      Group at Lawrence Berkeley National Laboratory.
17 * 4. Neither the name of the University nor of the Laboratory may be used
18 *    to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#) $Header$ (LBL)
34 * $Id$
35 */
36
37#ifndef vic_session_h
38#define vic_session_h
39
40#include "net.h"
41#include "transmitter.h"
42#include "timer.h"
43#include "iohandler.h"
44#include "source.h"
45#include "mbus_handler.h"
46
47class Source;
48class SessionManager;
49
50class DataHandler : public IOHandler {
51    public:
52        DataHandler* next;
53        inline DataHandler() : next(0), sm_(0), net_(0), addrp_(0) {}
54//      inline DataHandler(SessionManager& sm) : sm_(sm), net_(0), addrp_(0) {}
55        virtual void dispatch(int mask);
56        inline Network* net() const { return (net_); }
57        virtual void net(Network* net) {
58                unlink();
59                link(net->rchannel(), TK_READABLE);
60                net_ = net;
61                if (addrp_) delete addrp_;
62                addrp_ = net->addr().copy(); // get right type of address
63        }
64        inline int recv(u_char* bp, int len, Address*& addrp) {
65                return (net_->recv(bp, len, *(addrp = addrp_)));
66        }
67        inline void send(u_char* bp, int len) {
68                net_->send(bp, len);
69        }
70        inline void manager(SessionManager* sm) { sm_ = sm; }
71    protected:
72        SessionManager *sm_;
73        Network* net_;
74        Address *addrp_;
75};
76/*
77 * Parameters controling the RTCP report rate timer.
78 */
79#define CTRL_SESSION_BW_FRACTION (0.05)
80#define CTRL_MIN_RPT_TIME (5.)
81#define CTRL_SENDER_BW_FRACTION (0.25)
82#define CTRL_RECEIVER_BW_FRACTION (1. - CTRL_SENDER_BW_FRACTION)
83#define CTRL_SIZE_GAIN (1./8.)
84
85class CtrlHandler : public DataHandler, public Timer {
86    public:
87        CtrlHandler();
88//      inline CtrlHandler(SessionManager& sm) : DataHandler(sm) {}
89        virtual void dispatch(int mask);
90        inline Network* net() const { return (net_); }
91// new for layering - individual report timers for each layer
92        virtual void timeout();
93        virtual void net(Network* net);
94        void adapt(int nsrc, int nrr, int we_sent);
95        void sample_size(int cc);
96        inline double rint() const { return (rint_); }
97        void send_aoa();        // send ackofack (TfwcSndr side)
98        void send_ts();         // send timestamp (TfwcSndr side)
99
100 protected:
101        void schedule_timer();
102        double ctrl_inv_bw_;
103        double ctrl_avg_size_;  /* (estimated) average size of ctrl packets */
104        double rint_;           /* current session report rate (in ms) */
105};
106
107class ReportTimer : public Timer {
108    public:
109        inline ReportTimer(SessionManager& sm) : sm_(sm) {}
110        void timeout();
111    protected:
112        SessionManager& sm_;
113};
114
115// set AckVec bitmap
116//#define SET_BIT_VEC(ackvec_, bit) (ackvec_ = ((ackvec_ << 1) | bit))
117
118// see AckVec bitmap
119//#define SEE_BIT_VEC(ackvec_, ix, seqno) ((1 << (seqno - ix)) & ackvec_)
120
121class SessionManager : public Transmitter, public MtuAlloc {
122public:
123        SessionManager();
124        virtual ~SessionManager();
125        virtual int command(int argc, const char*const* argv);
126        virtual void recv(CtrlHandler*);
127        virtual void recv(DataHandler*);
128        virtual void announce(CtrlHandler*); //LLL
129//      virtual void send_bye();
130        virtual inline void send_bye() { send_report(&ch_[0], 1); }
131//      virtual void send_report();
132        virtual void send_report(CtrlHandler*, int bye, int app = 0);
133        virtual void send_xreport(CtrlHandler*, int bt, int bye);
134        void build_aoa_pkt(CtrlHandler* ch);
135        void build_ts_pkt(CtrlHandler* ch);
136
137protected:
138//      void demux(rtphdr* rh, u_char* bp, int cc, Address & addr, int layer);
139        void demux(pktbuf* pb, Address & addr);
140        virtual int check_format(int fmt) const = 0;
141        virtual void transmit(pktbuf* pb);
142        void send_report(int bye);
143        int build_bye(rtcphdr* rh, Source& local);
144        u_char* build_sdes_item(u_char* p, int code, Source&);
145        int build_sdes(rtcphdr* rh, Source& s);
146        int build_app(rtcphdr* rh, Source& ls, const char *name,
147                        void *data, int datalen);
148
149        void parse_sr(rtcphdr* rh, int flags, u_char* ep,
150                      Source* ps, Address & addr, int layer);
151        void parse_rr(rtcphdr* rh, int flags, u_char* ep,
152                      Source* ps, Address & addr, int layer);
153        void parse_xr(rtcphdr* rh, int flags, u_char* ep,
154                      Source* ps, Address & addr, int layer);
155        void parse_rr_records(u_int32_t ssrc, rtcp_rr* r, int cnt,
156                              const u_char* ep, Address & addr);
157        void parse_xr_records(u_int32_t ssrc, rtcp_xr* xr, int cnt,
158                              const u_char* ep, Address & addr);
159        int sdesbody(u_int32_t* p, u_char* ep, Source* ps,
160                     Address & addr, u_int32_t ssrc, int layer);
161        void parse_sdes(rtcphdr* rh, int flags, u_char* ep, Source* ps,
162                        Address & addr, u_int32_t ssrc, int layer);
163        void parse_bye(rtcphdr* rh, int flags, u_char* ep, Source* ps);
164        u_char* build_ackv_pkt(rtcp_xr* xr, u_int32_t ssrc);
165        u_char* build_ts_echo_pkt(rtcp_xr* xr, u_int32_t ssrc);
166
167        int parseopts(const u_char* bp, int cc, Address & addr) const;
168        int ckid(const char*, int len);
169
170        u_int32_t alloc_srcid(Address & addr) const;
171
172        int lipSyncEnabled() { return (lipSyncEnabled_);}
173        void lipSyncEnabled(int v) { lipSyncEnabled_=v;}
174
175        char* stats(char* cp) const;
176
177        DataHandler dh_[NLAYER];
178        CtrlHandler ch_[NLAYER];
179
180        // MBus stuff
181        MBusHandler mb_; // Handles mbus and interfaces to mbus
182                                         // code in common libraries
183        int lipSyncEnabled_;
184
185        /*XXX cleanup*/
186        u_int badversion_;
187        u_int badoptions_;
188        u_int badfmt_;
189        u_int badext_;
190        u_int nrunt_;
191
192        u_int32_t last_np_;
193        u_int32_t sdes_seq_;
194
195        double rtcp_inv_bw_;
196        double rtcp_avg_size_;  /* (estimated) average size of rtcp packets */
197        double rint_;           /* current session report rate (in ms) */
198
199        int confid_;
200
201        BufferPool* pool_;
202        u_char* pktbuf_;
203
204        SourceManager *sm_;
205
206        // RTP packet sequence number (for the use of AckVec)
207        u_int16_t seqno_;               // RTP packet sequence number
208        u_int16_t lastseq_;             // last packet's seqno
209        u_int16_t ackofack_;    // Ack of ack
210
211        // AckVector
212        u_int32_t ackvec_;      // this is a bit vector
213        u_int32_t ts_;          // timestamp
214        u_int32_t ts_echo_;     // timestamp echo
215};
216
217class AudioSessionManager : public SessionManager {
218    protected:
219        int check_format(int fmt) const;
220};
221
222class VideoSessionManager : public SessionManager {
223    protected:
224        int check_format(int fmt) const;
225};
226
227
228#endif
Note: See TracBrowser for help on using the browser.