Use the sample rate from SDP info in RTP stream analysis.
authorAnders Broman <anders.broman@ericsson.com>
Wed, 14 Apr 2010 20:48:37 +0000 (20:48 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Wed, 14 Apr 2010 20:48:37 +0000 (20:48 -0000)
svn path=/trunk/; revision=32466

asn1/h245/packet-h245-template.c
epan/dissectors/packet-ansi_a.c
epan/dissectors/packet-h245.c
epan/dissectors/packet-rtp.c
epan/dissectors/packet-rtp.h
epan/dissectors/packet-sdp.c
tap-rtp-common.c

index e6fb0b9f8f6fd3f805384c303824d9799b059b72..6aa63d8ba38cf9a3aff525ed394e48715a1bf6ca 100644 (file)
@@ -323,6 +323,13 @@ static void update_unicast_addr(unicast_addr_t *req_addr, unicast_addr_t *ack_ad
   }
 }
 
+static void free_encoding_name_str (encoding_name_and_rate_t *encoding_name_and_rate)
+{
+  if (encoding_name_and_rate->encoding_name) {
+    g_free(encoding_name_and_rate->encoding_name);
+  }
+}
+
 static void h245_setup_channels(packet_info *pinfo, channel_info_t *upcoming_channel_lcl)
 {
        gint *key;
@@ -343,10 +350,13 @@ static void h245_setup_channels(packet_info *pinfo, channel_info_t *upcoming_cha
 
        /* (S)RTP, (S)RTCP */
        if (upcoming_channel_lcl->rfc2198 > 0) {
-               rtp_dyn_payload = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
+               encoding_name_and_rate_t *encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
+               rtp_dyn_payload = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_encoding_name_str);
+               encoding_name_and_rate->encoding_name = g_strdup("red");
+               encoding_name_and_rate->sample_rate = 8000;
                key = g_malloc(sizeof(gint));
                *key = upcoming_channel_lcl->rfc2198;
-               g_hash_table_insert(rtp_dyn_payload, key, g_strdup("red"));
+               g_hash_table_insert(rtp_dyn_payload, key, encoding_name_and_rate);
        }
 
        if (upcoming_channel_lcl->srtp_flag) {
index 6369886c10543a103929e9d5b3b10e298de05fe5..b1e77e27039416c1435e8d1f03a3ee806594fd22 100644 (file)
@@ -8062,6 +8062,13 @@ elem_a2p_bearer_session(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint l
 /*
  * IOS 5 4.2.90
  */
+static void free_encoding_name_str (encoding_name_and_rate_t *encoding_name_and_rate)
+{
+  if (encoding_name_and_rate->encoding_name) {
+    g_free(encoding_name_and_rate->encoding_name);
+  }
+}
+
 static guint8
 elem_a2p_bearer_format(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint len, gchar *add_string _U_, int string_len _U_)
 {
@@ -8081,7 +8088,7 @@ elem_a2p_bearer_format(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint le
     GHashTable                          *rtp_dyn_payload;
     gint                                *key;
 
-    rtp_dyn_payload = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
+    rtp_dyn_payload = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_encoding_name_str);
 
     first_assigned_found = FALSE;
 
@@ -8305,9 +8312,13 @@ elem_a2p_bearer_format(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint le
             format_assigned &&
             (first_assigned_found == FALSE))
         {
+                       encoding_name_and_rate_t *encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
             key = (gint *)g_malloc(sizeof(gint));
             *key = rtp_payload_type;
-            g_hash_table_insert(rtp_dyn_payload, key, g_strdup(mime_type));
+                       encoding_name_and_rate->encoding_name =  g_strdup(mime_type);
+                       /* Assumtion; all pt:s above have a sample rate of 8000 */
+                       encoding_name_and_rate->sample_rate = 8000;
+            g_hash_table_insert(rtp_dyn_payload, key, encoding_name_and_rate);
 
             first_assigned_found = TRUE;
 
index d4e065e83b7be3d45f474f7ff8d1710bb98f47b4..d509579508389dea454d1695e866dd87100f5698 100644 (file)
@@ -454,6 +454,13 @@ static void update_unicast_addr(unicast_addr_t *req_addr, unicast_addr_t *ack_ad
   }
 }
 
+static void free_encoding_name_str (encoding_name_and_rate_t *encoding_name_and_rate)
+{
+  if (encoding_name_and_rate->encoding_name) {
+    g_free(encoding_name_and_rate->encoding_name);
+  }
+}
+
 static void h245_setup_channels(packet_info *pinfo, channel_info_t *upcoming_channel_lcl)
 {
        gint *key;
@@ -474,10 +481,13 @@ static void h245_setup_channels(packet_info *pinfo, channel_info_t *upcoming_cha
 
        /* (S)RTP, (S)RTCP */
        if (upcoming_channel_lcl->rfc2198 > 0) {
-               rtp_dyn_payload = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
+               encoding_name_and_rate_t *encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
+               rtp_dyn_payload = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_encoding_name_str);
+               encoding_name_and_rate->encoding_name = g_strdup("red");
+               encoding_name_and_rate->sample_rate = 8000;
                key = g_malloc(sizeof(gint));
                *key = upcoming_channel_lcl->rfc2198;
-               g_hash_table_insert(rtp_dyn_payload, key, g_strdup("red"));
+               g_hash_table_insert(rtp_dyn_payload, key, encoding_name_and_rate);
        }
 
        if (upcoming_channel_lcl->srtp_flag) {
@@ -1905,7 +1915,7 @@ static int hf_h245_encrypted = -1;                /* OCTET_STRING */
 static int hf_h245_encryptedAlphanumeric = -1;    /* EncryptedAlphanumeric */
 
 /*--- End of included file: packet-h245-hf.c ---*/
-#line 373 "packet-h245-template.c"
+#line 383 "packet-h245-template.c"
 
 /* Initialize the subtree pointers */
 static int ett_h245 = -1;
@@ -2406,7 +2416,7 @@ static gint ett_h245_FlowControlIndication = -1;
 static gint ett_h245_MobileMultilinkReconfigurationIndication = -1;
 
 /*--- End of included file: packet-h245-ett.c ---*/
-#line 378 "packet-h245-template.c"
+#line 388 "packet-h245-template.c"
 
 /* Forward declarations */
 static int dissect_h245_MultimediaSystemControlMessage(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_);
@@ -14451,7 +14461,7 @@ static void dissect_OpenLogicalChannel_PDU(tvbuff_t *tvb _U_, packet_info *pinfo
 
 
 /*--- End of included file: packet-h245-fn.c ---*/
-#line 387 "packet-h245-template.c"
+#line 397 "packet-h245-template.c"
 
 static void
 dissect_h245(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
@@ -20132,7 +20142,7 @@ void proto_register_h245(void) {
         "h245.EncryptedAlphanumeric", HFILL }},
 
 /*--- End of included file: packet-h245-hfarr.c ---*/
-#line 463 "packet-h245-template.c"
+#line 473 "packet-h245-template.c"
   };
 
   /* List of subtrees */
@@ -20635,7 +20645,7 @@ void proto_register_h245(void) {
     &ett_h245_MobileMultilinkReconfigurationIndication,
 
 /*--- End of included file: packet-h245-ettarr.c ---*/
-#line 470 "packet-h245-template.c"
+#line 480 "packet-h245-template.c"
   };
   module_t *h245_module;
 
index 369056a5db94328ee74310e92a863859fa036d9d..ca3c6a1f218472bf67e272d24f9e8a2a2538de5c 100644 (file)
@@ -649,7 +649,9 @@ process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
        else if ( (payload_type >= PT_UNDF_96 && payload_type <= PT_UNDF_127) ) {
                if (p_conv_data && p_conv_data->rtp_dyn_payload) {
                        gchar *payload_type_str = NULL;
-                       payload_type_str = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
+                       encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
+                       encoding_name_and_rate_pt = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
+                       payload_type_str = encoding_name_and_rate_pt->encoding_name;
                        if (payload_type_str){
                                found_match = dissector_try_string(rtp_dyn_pt_dissector_table,
                                                                   payload_type_str, newtvb, pinfo, tree);
@@ -934,7 +936,9 @@ dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
                /* if it is dynamic payload, let use the conv data to see if it is defined */
                if ((hdr_new->pt > 95) && (hdr_new->pt < 128)) {
                        if (p_conv_data && p_conv_data->rtp_dyn_payload){
+                               encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
                                payload_type_str = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &hdr_new->pt);
+                               payload_type_str = encoding_name_and_rate_pt->encoding_name;
                        }
                }
                /* Add a subtree for this header and add items */
@@ -1100,6 +1104,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
        rtp_info->info_is_srtp = FALSE;
        rtp_info->info_setup_frame_num = 0;
        rtp_info->info_payload_type_str = NULL;
+       rtp_info->info_payload_rate = 0;
 
        /*
         * Do we have all the data?
@@ -1162,8 +1167,10 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
        /* if it is dynamic payload, let use the conv data to see if it is defined */
        if ( (payload_type>95) && (payload_type<128) ) {
                if (p_conv_data && p_conv_data->rtp_dyn_payload){
-                       payload_type_str = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
-                       rtp_info->info_payload_type_str = payload_type_str;
+                       encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
+                       encoding_name_and_rate_pt = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
+                       rtp_info->info_payload_type_str = encoding_name_and_rate_pt->encoding_name;
+                       rtp_info->info_payload_rate = encoding_name_and_rate_pt->sample_rate;
                }
        }
 
index be06dacc90a69f5d4278d14d47e953b822dadb8e..9a0dd73aaba6571a27ff74f4d2d5ad2572eba88a 100644 (file)
@@ -45,6 +45,7 @@ struct _rtp_info {
        guint32           info_setup_frame_num; /* the frame num of the packet that set this RTP connection */
        const guint8* info_data;           /* pointer to raw rtp data */
        gchar             *info_payload_type_str;
+       gint              info_payload_rate;
        /*
        * info_data: pointer to raw rtp data = header + payload incl. padding.
        * That should be safe because the "epan_dissect_t" constructed for the packet
@@ -114,6 +115,11 @@ struct _rtp_conversation_info
        struct srtp_info *srtp_info;    /* SRTP context */
 };
 
+typedef struct {
+       char *encoding_name;
+       int   sample_rate;
+} encoding_name_and_rate_t;
+
 /* Add an RTP conversation with the given details */
 void rtp_add_address(packet_info *pinfo,
                      address *addr, int port,
index 0a5325f18e6725af8d6a19f114de79e0e3589dbf..717f277ad3abc91ee29d96ba3eeafe132cfd63ed 100644 (file)
@@ -208,8 +208,8 @@ typedef struct {
   char *connection_address;
   char *connection_type;
   char *media_type;
-  char *encoding_name[SDP_NO_OF_PT]; 
-  char *encoding_name_and_rate[SDP_NO_OF_PT]; 
+  char *encoding_name[SDP_NO_OF_PT];
+  int   sample_rate[SDP_NO_OF_PT];
   char *media_port[SDP_MAX_RTP_CHANNELS];
   char *media_proto[SDP_MAX_RTP_CHANNELS];
   transport_media_pt_t media[SDP_MAX_RTP_CHANNELS];
@@ -253,6 +253,13 @@ static void dissect_sdp_media(tvbuff_t *tvb, proto_item *ti,
                               transport_info_t *transport_info);
 static void dissect_sdp_media_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_item *ti, int length,transport_info_t *transport_info);
 
+static void free_encoding_name_str (encoding_name_and_rate_t *encoding_name_and_rate)
+{
+  if (encoding_name_and_rate->encoding_name) {
+    g_free(encoding_name_and_rate->encoding_name);
+  }
+}
+
 static void
 dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
@@ -297,7 +304,7 @@ dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   transport_info.media_type=NULL;
   for (n=0; n < SDP_NO_OF_PT; n++){
     transport_info.encoding_name[n]=unknown_encoding;
-       transport_info.encoding_name_and_rate[n]=unknown_encoding;
+       transport_info.sample_rate[n] = 0;
   }
   for (n=0; n < SDP_MAX_RTP_CHANNELS; n++)
   {
@@ -305,7 +312,7 @@ dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     transport_info.media_proto[n]=NULL;
     transport_info.media[n].pt_count = 0;
     transport_info.media[n].rtp_dyn_payload =
-        g_hash_table_new_full( g_int_hash, g_int_equal, g_free, g_free);
+        g_hash_table_new_full( g_int_hash, g_int_equal, g_free, free_encoding_name_str);
   }
   transport_info.media_count = 0;
 
@@ -539,9 +546,9 @@ dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     {
       /* if the payload type is dynamic (96 to 127), check the hash table to add the desc in the SDP summary */
       if ( (transport_info.media[n].pt[i] >=96) && (transport_info.media[n].pt[i] <=127) ) {
-        gchar *str_dyn_pt = g_hash_table_lookup(transport_info.media[n].rtp_dyn_payload, &transport_info.media[n].pt[i]);
-        if (str_dyn_pt)
-          g_snprintf(sdp_pi->summary_str, 50, "%s %s", sdp_pi->summary_str, str_dyn_pt);
+        encoding_name_and_rate_t *encoding_name_and_rate_pt = g_hash_table_lookup(transport_info.media[n].rtp_dyn_payload, &transport_info.media[n].pt[i]);
+        if (encoding_name_and_rate_pt)
+          g_snprintf(sdp_pi->summary_str, 50, "%s %s", sdp_pi->summary_str, encoding_name_and_rate_pt->encoding_name);
         else
           g_snprintf(sdp_pi->summary_str, 50, "%s %d", sdp_pi->summary_str, transport_info.media[n].pt[i]);
       } else
@@ -1476,6 +1483,7 @@ static void dissect_sdp_media_attribute(tvbuff_t *tvb, packet_info *pinfo, proto
   const char *h324ext_h223lcparm = "h324ext/h223lcparm";
   gboolean has_more_pars = TRUE;
   tvbuff_t *h245_tvb;
+  encoding_name_and_rate_t *encoding_name_and_rate;
 
   offset = 0;
   next_offset = 0;
@@ -1555,11 +1563,10 @@ static void dissect_sdp_media_attribute(tvbuff_t *tvb, packet_info *pinfo, proto
                        break;
                next_offset++;
        }
-       transport_info->encoding_name_and_rate[pt] = (char*)tvb_get_ephemeral_string(tvb, start_offset, next_offset - start_offset);
-       proto_tree_add_text(sdp_media_attribute_tree, tvb, start_offset, next_offset - start_offset, "[Debug: %s]",transport_info->encoding_name_and_rate[pt]);
     tokenlen = next_offset - offset;
     proto_tree_add_item(sdp_media_attribute_tree, hf_media_sample_rate, tvb,
                         offset, tokenlen, FALSE);
+       transport_info->sample_rate[pt] = atoi(tvb_get_ephemeral_string(tvb, offset, tokenlen));
     /* As per RFC2327 it is possible to have multiple Media Descriptions ("m=").
        For example:
 
@@ -1579,27 +1586,34 @@ static void dissect_sdp_media_attribute(tvbuff_t *tvb, packet_info *pinfo, proto
      */
     if (transport_info->media_count == 0) {
       for (n=0; n < SDP_MAX_RTP_CHANNELS; n++) {
-        if (n==0)
+        encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
+               encoding_name_and_rate->encoding_name = g_strdup(transport_info->encoding_name[pt]);
+               encoding_name_and_rate->sample_rate = transport_info->sample_rate[pt];
+           if (n==0){
           g_hash_table_insert(transport_info->media[n].rtp_dyn_payload,
-                              key, g_strdup(transport_info->encoding_name[pt]));
+                              key, encoding_name_and_rate);
+                 }
         else {    /* we create a new key and encoding_name to assign to the other hash tables */
           gint *key2;
           key2=g_malloc( sizeof(gint) );
           *key2=atol((char*)payload_type);
           g_hash_table_insert(transport_info->media[n].rtp_dyn_payload,
-                              key2, g_strdup(transport_info->encoding_name[pt]));
+                              key2, encoding_name_and_rate);
         }
       }
       return;
       /* if the "a=" is after an "m=", only apply to this "m=" */
     }else
       /* in case there is an overflow in SDP_MAX_RTP_CHANNELS, we keep always the last "m=" */
+      encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
+         encoding_name_and_rate->encoding_name = g_strdup(transport_info->encoding_name[pt]);
+         encoding_name_and_rate->sample_rate = transport_info->sample_rate[pt];
       if (transport_info->media_count == SDP_MAX_RTP_CHANNELS-1)
         g_hash_table_insert(transport_info->media[ transport_info->media_count ].rtp_dyn_payload,
-                            key, g_strdup(transport_info->encoding_name[pt]));
+                            key, encoding_name_and_rate);
       else
         g_hash_table_insert(transport_info->media[ transport_info->media_count-1 ].rtp_dyn_payload,
-                            key, g_strdup(transport_info->encoding_name[pt]));
+                            key, encoding_name_and_rate);
     break;
   case SDP_FMTP:
     if(sdp_media_attribute_tree){
index dd551fe2b4222a8fe85158e7dd2fb852f6c9aa3d..0ef5008f02a3e26063aa3de02abf275c6c55f0e0 100644 (file)
@@ -571,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;