Add #ifndef __PRIVILEGES_H__ / #define / #endif logic to prevent multiple
[obnox/wireshark/wip.git] / tap-rtp-common.c
index c21013fa821dc44c249f6a94f52993bc52c38a6d..d3364d5d2f8e725bff2762e56c7a7f8a974c4a73 100644 (file)
 # include "config.h"
 #endif
 
+#include <stdio.h>
 #include <math.h>
 #include "globals.h"
 
 #include <epan/tap.h>
-#include "register.h"
 #include <string.h>
 #include <epan/rtp_pt.h>
 #include <epan/addr_resolv.h>
@@ -130,7 +130,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);
@@ -279,14 +279,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;
@@ -294,8 +294,10 @@ int rtpstream_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
                        rtp_write_sample(&sample, tapinfo->save_file);
                }
        }
+       /* TODO: This doesn't belong here. We really shouldn't refer to cf_mark_frame()
+        * which only make sense if we're using the GTK UI backend. This effectively forces
+        * tshark/rawshark to implement a cf_mark_frame() stub */
        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)
                {
@@ -419,7 +421,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--) {
@@ -443,7 +445,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);
@@ -457,6 +458,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;
@@ -478,8 +480,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
@@ -561,15 +562,19 @@ int rtp_packet_analyse(tap_rtp_stat_t *statinfo,
        }else{ /* Dynamic PT */
                if ( rtpinfo->info_payload_type_str != NULL ){
                        /* Is it a "telephone-event" ?
-                        * Timestamp is not increased for telepone-event packets inpacting
-                        * caluculation of Jitter Skew and clock drift.
+                        * Timestamp is not increased for telepone-event packets impacting
+                        * calculation of Jitter Skew and clock drift.
                         * see 2.2.1 of RFC 4733
                         */
                        if (g_ascii_strncasecmp("telephone-event",rtpinfo->info_payload_type_str,(strlen("telephone-event")))==0){
                                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;
@@ -587,7 +592,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);
@@ -613,7 +618,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;
@@ -667,7 +672,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;