Xcode 4 isn't available on DVD, but is available for download from
[obnox/wireshark/wip.git] / tap-rtp-common.c
index a57c7c3ec87be4c7518ca2e6e8836d6ea4cd6b61..8efbc06ef9a9cc4a5876ea0b0ddd58fb26d6c3ed 100644 (file)
@@ -38,7 +38,6 @@
 #include "globals.h"
 
 #include <epan/tap.h>
-#include "register.h"
 #include <string.h>
 #include <epan/rtp_pt.h>
 #include <epan/addr_resolv.h>
 #include "gtk/rtp_stream.h"
 #include "tap-rtp-common.h"
 
-
+/* XXX: are changes needed to properly handle situations where
+        info_all_data_present == FALSE ?
+        E.G., when captured frames are truncated.
+ */
 
 /****************************************************************************/
 /* GCompareFunc style comparison function for _rtp_stream_info */
@@ -131,7 +133,7 @@ void rtp_write_header(rtp_stream_info_t *strinfo, FILE *file)
        size_t sourcelen;
        guint16 port;          /* UDP port */
        guint16 padding;       /* 2 padding bytes */
-       
+
        fprintf(file, "#!rtpplay%s %s/%u\n", RTPFILE_VERSION,
                get_addr_name(&(strinfo->dest_addr)),
                strinfo->dest_port);
@@ -280,14 +282,14 @@ int rtpstream_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
 
                /* increment the packets counter of all streams */
                ++(tapinfo->npackets);
-               
+
                return 1;  /* refresh output */
        }
        else if (tapinfo->mode == TAP_SAVE) {
                if (rtp_stream_info_cmp(&tmp_strinfo, tapinfo->filter_stream_fwd)==0) {
                        /* XXX - what if rtpinfo->info_all_data_present is
                           FALSE, so that we don't *have* all the data? */
-                       sample.header.rec_time = 
+                       sample.header.rec_time =
                                (pinfo->fd->abs_ts.nsecs/1000 + 1000000 - tapinfo->filter_stream_fwd->start_usec)/1000
                                + (guint32) (pinfo->fd->abs_ts.secs - tapinfo->filter_stream_fwd->start_sec - 1)*1000;
                        sample.header.frame_length = rtpinfo->info_data_len;
@@ -295,15 +297,15 @@ int rtpstream_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
                        rtp_write_sample(&sample, tapinfo->save_file);
                }
        }
+#ifdef __GTK_H__
        else if (tapinfo->mode == TAP_MARK) {
-
                if (rtp_stream_info_cmp(&tmp_strinfo, tapinfo->filter_stream_fwd)==0
                        || rtp_stream_info_cmp(&tmp_strinfo, tapinfo->filter_stream_rev)==0)
                {
                        cf_mark_frame(&cfile, pinfo->fd);
                }
        }
-
+#endif
        return 0;
 }
 
@@ -420,7 +422,7 @@ static guint32
 get_dyn_pt_clock_rate(gchar *payload_type_str)
 {
        int i;
-       
+
        /* Search for matching mimetype in reverse order to avoid false matches
         * when pt_mime_name_str is the prefix of payload_type_str */
        for (i = NUM_DYN_CLOCK_VALUES - 1; i > -1 ; i--) {
@@ -444,7 +446,6 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
        double expected_time;
        double absskew;
        guint32 clock_rate;
-       guint32 old_flags;
 
        /* Store the current time */
        current_time = nstime_to_msec(&pinfo->fd->rel_ts);
@@ -458,6 +459,7 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                statinfo->timestamp = rtpinfo->info_timestamp;
                statinfo->first_timestamp = rtpinfo->info_timestamp;
                statinfo->time = current_time;
+               statinfo->lastnominaltime = 0;
                statinfo->pt = rtpinfo->info_payload_type;
                statinfo->reg_pt = rtpinfo->info_payload_type;
                statinfo->bw_history[statinfo->bw_index].bytes = rtpinfo->info_data_len + 28;
@@ -479,8 +481,7 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                return 0;
        }
 
-       /* Save old flags and reset flags */
-       old_flags = statinfo->flags;
+       /* Reset flags */
        statinfo->flags = 0;
 
        /* When calculating expected rtp packets the seq number can wrap around
@@ -570,7 +571,11 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                                clock_rate = 0;
                                statinfo->flags |= STAT_FLAG_PT_T_EVENT;
                        }else{
-                               clock_rate = get_dyn_pt_clock_rate(rtpinfo-> info_payload_type_str);
+                               if(rtpinfo->info_payload_rate !=0){
+                                       clock_rate = rtpinfo->info_payload_rate;
+                               }else{
+                                       clock_rate = get_dyn_pt_clock_rate(rtpinfo-> info_payload_type_str);
+                               }
                        }
                }else{
                        clock_rate = 0;
@@ -588,7 +593,7 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
        }
 
        /* Can only analyze defined sampling rates */
-    if (clock_rate != 0) { 
+    if (clock_rate != 0) {
                statinfo->clock_rate = clock_rate;
                /* Convert from sampling clock to ms */
                nominaltime = nominaltime /(clock_rate/1000);
@@ -614,7 +619,7 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                }
                /* Gather data for calculation of average, minimum and maximum framerate based on timestamp */
 #if 0
-               if (numPackets > 0 && (!hardPayloadType || !alternatePayloadType)) { 
+               if (numPackets > 0 && (!hardPayloadType || !alternatePayloadType)) {
                        /* Skip first packet and possibly alternate payload type packets */
                        double dt;
                        dt     = nominaltime - statinfo->lastnominaltime;
@@ -631,8 +636,8 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                statinfo->sumtTS += 1.0 * current_time * nominaltime;
        }
 
-       /* Calculate the BW in Kbps adding the IP+UDP header to the RTP -> 20bytes(IP)+8bytes(UDP) = 28bytes */
-       statinfo->bw_history[statinfo->bw_index].bytes = rtpinfo->info_data_len + 28;
+       /* Calculate the BW in Kbps adding the IP+UDP header to the RTP -> IP header+8bytes(UDP) */
+       statinfo->bw_history[statinfo->bw_index].bytes = rtpinfo->info_data_len + pinfo->iphdrlen + 8;
        statinfo->bw_history[statinfo->bw_index].time = current_time;
 
        /* Check if there are more than 1sec in the history buffer to calculate BW in bps. If so, remove those for the calculation */
@@ -641,7 +646,8 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                statinfo->bw_start_index++;
                if (statinfo->bw_start_index == BUFF_BW) statinfo->bw_start_index=0;
        };
-       statinfo->total_bytes += rtpinfo->info_data_len + 28;
+       /* IP hdr + UDP + RTP */
+       statinfo->total_bytes += rtpinfo->info_data_len + pinfo->iphdrlen + 8;
        statinfo->bandwidth = (double)(statinfo->total_bytes*8)/1000;
        statinfo->bw_index++;
        if (statinfo->bw_index == BUFF_BW) statinfo->bw_index = 0;
@@ -668,7 +674,7 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
                        statinfo->max_delta = statinfo->delta;
                        statinfo->max_nr = pinfo->fd->num;
                }
-               if (clock_rate != 0) { 
+               if (clock_rate != 0) {
                        /* Maximum and mean jitter calculation */
                        if (statinfo->jitter > statinfo->max_jitter) {
                                statinfo->max_jitter = statinfo->jitter;