]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
If we get a codec offer using a well-known payload type, but using it for another
authorOlle Johansson <oej@edvina.net>
Tue, 27 Nov 2007 15:23:17 +0000 (15:23 +0000)
committerOlle Johansson <oej@edvina.net>
Tue, 27 Nov 2007 15:23:17 +0000 (15:23 +0000)
codec that we don't know, Asterisk did not remove that codec from the list.

With this patch, we remove the codec from audio and video rtp objects and
deny it ever existed. Thanks to lasse for testing.

(closes issue #11376)
Reported by: lasse
Patches:
      bug11376.txt uploaded by oej (license 306)
Tested by: lasse

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@89630 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
include/asterisk/rtp.h
main/rtp.c

index 9023d0939eb200a4f482c6bb4690ce81085cb060..c9281c75fe53b0aaaff768917d380f7924dbe5ea 100644 (file)
@@ -5203,16 +5203,37 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
                        continue;
                } else if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) == 2) {
                        /* We have a rtpmap to handle */
-                       if (debug)
-                               ast_verbose("Found description format %s for ID %d\n", mimeSubtype, codec);
-                       found_rtpmap_codecs[last_rtpmap_codec] = codec;
-                       last_rtpmap_codec++;
+                       int found = FALSE;
+                       /* We should propably check if this is an audio or video codec
+                               so we know where to look */
 
                        /* Note: should really look at the 'freq' and '#chans' params too */
-                       ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype,
-                                       ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0);
-                       if (p->vrtp)
-                               ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype, 0);
+                       if(ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype,
+                                       ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0) != -1) {
+                               if (debug)
+                                       ast_verbose("Found audio description format %s for ID %d\n", mimeSubtype, codec);
+                               found_rtpmap_codecs[last_rtpmap_codec] = codec;
+                               last_rtpmap_codec++;
+                               found = TRUE;
+
+                       } else if (p->vrtp) {
+                               if(ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype, 0) != -1) {
+                                       if (debug)
+                                               ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec);
+                                       found_rtpmap_codecs[last_rtpmap_codec] = codec;
+                                       last_rtpmap_codec++;
+                                       found = TRUE;
+                               }
+                       }
+                       if (!found) {
+                               /* Remove this codec since it's an unknown media type for us */
+                               /* XXX This is buggy since the media line for audio and video can have the
+                                       same numbers. We need to check as described above, but for testing this works... */
+                               ast_rtp_unset_m_type(newaudiortp, codec);
+                               ast_rtp_unset_m_type(newvideortp, codec);
+                               if (debug) 
+                                       ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec);
+                       }
                }
        }
        
index cbcb6aae64f5e88a7c0e9143ae62f08aa09d058c..1ffa04d0d287090eda5b697d35c0c459abd56c5c 100644 (file)
@@ -170,8 +170,14 @@ void ast_rtp_pt_default(struct ast_rtp* rtp);
 /*! \brief Copy payload types between RTP structures */
 void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src);
 
+/*! \brief Activate payload type */
 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
-void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
+
+/*! \brief clear payload type */
+void ast_rtp_unset_m_type(struct ast_rtp* rtp, int pt);
+
+/*! \brief Initiate payload type to a known MIME media type for a codec */
+int ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
                             char *mimeType, char *mimeSubtype,
                             enum ast_rtp_options options);
 
index 624f1673dd9ca2f4abb27c0169f84de1434a470a..7885a57785736f67ad0f402f280c7da4615435a0 100644 (file)
@@ -1640,23 +1640,36 @@ void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt)
        ast_mutex_unlock(&rtp->bridge_lock);
 } 
 
+/*! \brief remove setting from payload type list if the rtpmap header indicates
+    an unknown media type */
+void ast_rtp_unset_m_type(struct ast_rtp* rtp, int pt) 
+{
+       ast_mutex_lock(&rtp->bridge_lock);
+       rtp->current_RTP_PT[pt].isAstFormat = 0;
+       rtp->current_RTP_PT[pt].code = 0;
+       ast_mutex_unlock(&rtp->bridge_lock);
+}
+
 /*! \brief Make a note of a RTP payload type (with MIME type) that was seen in
  * an SDP "a=rtpmap:" line.
+ * \return 0 if the MIME type was found and set, -1 if it wasn't found
  */
-void ast_rtp_set_rtpmap_type(struct ast_rtp *rtp, int pt,
+int ast_rtp_set_rtpmap_type(struct ast_rtp *rtp, int pt,
                             char *mimeType, char *mimeSubtype,
                             enum ast_rtp_options options)
 {
        unsigned int i;
+       int found = 0;
 
        if (pt < 0 || pt > MAX_RTP_PT) 
-               return; /* bogus payload type */
+               return -1; /* bogus payload type */
        
        ast_mutex_lock(&rtp->bridge_lock);
 
        for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) {
                if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
                    strcasecmp(mimeType, mimeTypes[i].type) == 0) {
+                       found = 1;
                        rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType;
                        if ((mimeTypes[i].payloadType.code == AST_FORMAT_G726) &&
                            mimeTypes[i].payloadType.isAstFormat &&
@@ -1668,7 +1681,7 @@ void ast_rtp_set_rtpmap_type(struct ast_rtp *rtp, int pt,
 
        ast_mutex_unlock(&rtp->bridge_lock);
 
-       return;
+       return (found ? 0 : -1);
 } 
 
 /*! \brief Return the union of all of the codecs that were set by rtp_set...() calls