Bug 1436403: Setting rtpmap channels in rust. r=dminor draft
authorJohannes Willbold <j.willbold@mozilla.com>
Mon, 25 Jun 2018 14:01:37 -0700
changeset 812557 ae54885e3d2cccdd04f5f758bddcf2d134f3a843
parent 811977 6041c030780420b6205cf2d6640513606609884c
push id114588
push userbmo:johannes.willbold@rub.de
push dateFri, 29 Jun 2018 16:07:14 +0000
reviewersdminor
bugs1436403
milestone63.0a1
Bug 1436403: Setting rtpmap channels in rust. r=dminor Removed the code setting the channels for an rtpmap attribute in the C++ glue code. Added Rust code that accounts the data in SdpMedia accordingly for rtpmap. MozReview-Commit-ID: 2D5MVLJxXoh
media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.cpp
media/webrtc/signaling/src/sdp/rsdparsa/src/media_type.rs
--- a/media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.cpp
+++ b/media/webrtc/signaling/src/sdp/RsdparsaSdpAttributeList.cpp
@@ -683,23 +683,16 @@ RsdparsaSdpAttributeList::LoadRtpmap(Rus
   sdp_get_rtpmaps(attributeList, numRtpmap, rustRtpmaps.get());
   auto rtpmapList = MakeUnique<SdpRtpmapAttributeList>();
   for(size_t i = 0; i < numRtpmap; i++) {
     RustSdpAttributeRtpmap& rtpmap = rustRtpmaps[i];
     std::string payloadType = std::to_string(rtpmap.payloadType);
     std::string name = convertStringView(rtpmap.codecName);
     auto codec = strToCodecType(name);
     uint32_t channels = rtpmap.channels;
-    if (mIsVideo) {
-      // channels is expected to be 0 for video in higher level code,
-      // channels don't make sense, so the value is arbitrary. 1 is
-      // the arbitrary value for that code.
-      // TODO: handle this in Rust parser, see Bug 1436403
-      channels = 0;
-    }
     rtpmapList->PushEntry(payloadType, codec, name,
                           rtpmap.frequency, channels);
   }
   SetAttribute(rtpmapList.release());
 }
 
 void
 RsdparsaSdpAttributeList::LoadFmtp(RustAttributeList* attributeList)
--- a/media/webrtc/signaling/src/sdp/rsdparsa/src/media_type.rs
+++ b/media/webrtc/signaling/src/sdp/rsdparsa/src/media_type.rs
@@ -426,39 +426,53 @@ pub fn parse_media_vector(lines: &[SdpLi
             return Err(SdpParserError::Sequence {
                            message: "first line in media section needs to be a media line"
                                .to_string(),
                            line_number: lines[0].line_number,
                        })
         }
     };
 
-
     for line in lines.iter().skip(1) {
         match line.sdp_type {
             SdpType::Connection(ref c) => {
                 sdp_media
                     .set_connection(c)
                     .map_err(|e: SdpParserInternalError| {
                                  SdpParserError::Sequence {
                                      message: format!("{}", e),
                                      line_number: line.line_number,
                                  }
                              })?
             }
             SdpType::Bandwidth(ref b) => sdp_media.add_bandwidth(b),
             SdpType::Attribute(ref a) => {
-                sdp_media
-                    .add_attribute(a)
-                    .map_err(|e: SdpParserInternalError| {
-                                 SdpParserError::Sequence {
-                                     message: format!("{}", e),
-                                     line_number: line.line_number,
-                                 }
-                             })?
+                match a {
+                    &SdpAttribute::Rtpmap(ref rtpmap) => {
+                        sdp_media.add_attribute(&SdpAttribute::Rtpmap(
+                            SdpAttributeRtpmap {
+                                payload_type: rtpmap.payload_type,
+                                codec_name: rtpmap.codec_name.clone(),
+                                frequency: rtpmap.frequency,
+                                channels: match sdp_media.media.media {
+                                    SdpMediaValue::Video => Some(0),
+                                    _ => rtpmap.channels
+                                },
+                            }
+                        ))
+                    },
+                    _ => {
+                        sdp_media.add_attribute(a)
+                    }
+                }.map_err(|e: SdpParserInternalError| {
+                             SdpParserError::Sequence {
+                                 message: format!("{}", e),
+                                 line_number: line.line_number,
+                             }
+                         })?
             }
             SdpType::Media(ref v) => {
                 media_sections.push(sdp_media);
                 sdp_media = SdpMedia::new(v.clone());
             }
 
             SdpType::Email(_) |
             SdpType::Phone(_) |