monitube-data_rtp.c

Go to the documentation of this file.
00001 /*
00002  * $Id: monitube-data_rtp.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00022 #include "monitube-data_main.h"
00023 #include "monitube-data_rtp.h"
00024 
00025 /*** Constants ***/
00026 
00027 
00028 /*** Data structures ***/
00029 
00030 
00031 /*** STATIC/INTERNAL Functions ***/
00032 
00033 
00043 static void
00044 init_seq(source_t * s, uint16_t seq)
00045 {
00046     s->base_seq = seq;
00047     s->max_seq = seq;
00048     s->bad_seq = RTP_SEQ_MOD + 1;
00049     s->cycles = 0;
00050     s->received = 0;
00051     s->received_prior = 0;
00052     s->expected_prior = 0;
00053 }
00054 
00055 /*** GLOBAL/EXTERNAL Functions ***/
00056 
00057 
00069 int
00070 update_seq(source_t * s, uint16_t seq)
00071 {
00072     const int MAX_DROPOUT    = 3000;
00073     const int MAX_MISORDER   =  100;
00074     
00075     uint16_t udelta = seq - s->max_seq;
00076 
00077     /*
00078      * Source is not valid until MIN_SEQUENTIAL packets with
00079      * sequential sequence numbers have been received.
00080      */
00081     
00082     if (s->probation) {
00083         /* packet is in sequence */
00084         if (seq == s->max_seq + 1) {
00085             s->probation--;
00086             s->max_seq = seq;
00087             if (s->probation == 0) {
00088                 init_seq(s, seq);
00089                 s->received++;
00090                 return 1;
00091             }
00092         } else {
00093             s->probation = MIN_SEQUENTIAL - 1;
00094             s->max_seq = seq;
00095         }
00096         return 0;
00097         
00098     } else if (udelta < MAX_DROPOUT) {
00099         /* in order, with permissible gap */
00100         if (seq < s->max_seq) {
00101             /*
00102              * Sequence number wrapped - count another 64K cycle.
00103              */
00104             s->cycles += RTP_SEQ_MOD;
00105         }
00106         s->max_seq = seq;
00107     } else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) {
00108         /* the sequence number made a very large jump */
00109         
00110         if (seq == s->bad_seq) {
00111             /*
00112              * Two sequential packets -- assume that the other side
00113              * restarted without telling us so just re-sync
00114              * (i.e., pretend this was the first packet).
00115              */
00116             init_seq(s, seq);
00117         } else {
00118             s->bad_seq = (seq + 1) & (RTP_SEQ_MOD-1);
00119             return 0;
00120         }
00121     } else {
00122         /* duplicate or reordered packet */
00123     }
00124     s->received++;
00125     return 1;
00126 }

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:02 2010 for SDK Your Net Corporation Monitube IPTV Monitoring Example: monitube-data 1.0 by Doxygen 1.5.1