From a744a28b92bac9a98816bc0cae0104c2ecdd0edb Mon Sep 17 00:00:00 2001 From: "jlmiller@webrtc.org" Date: Wed, 18 Feb 2015 21:37:46 +0000 Subject: [PATCH] Templatize and clean up codec wildcards. BUG=4123 R=pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39209004 Cr-Commit-Position: refs/heads/master@{#8422} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8422 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/app/webrtc/webrtcsdp.cc | 38 +++++++++++++-------------- talk/app/webrtc/webrtcsdp_unittest.cc | 14 +++++----- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/talk/app/webrtc/webrtcsdp.cc b/talk/app/webrtc/webrtcsdp.cc index de45c0998..d34ce3e65 100644 --- a/talk/app/webrtc/webrtcsdp.cc +++ b/talk/app/webrtc/webrtcsdp.cc @@ -2436,10 +2436,9 @@ void UpdateCodec(MediaContentDescription* content_desc, int payload_type, AddOrReplaceCodec(content_desc, new_codec); } -bool PopWildcardCodec(std::vector* codecs, - cricket::VideoCodec* wildcard_codec) { - for (std::vector::iterator iter = codecs->begin(); - iter != codecs->end(); ++iter) { +template +bool PopWildcardCodec(std::vector* codecs, T* wildcard_codec) { + for (auto iter = codecs->begin(); iter != codecs->end(); ++iter) { if (iter->id == kWildcardPayloadType) { *wildcard_codec = *iter; codecs->erase(iter); @@ -2449,18 +2448,17 @@ bool PopWildcardCodec(std::vector* codecs, return false; } -void UpdateFromWildcardVideoCodecs(VideoContentDescription* video_desc) { - std::vector codecs = video_desc->codecs(); - cricket::VideoCodec wildcard_codec; +template +void UpdateFromWildcardCodecs(cricket::MediaContentDescriptionImpl* desc) { + auto codecs = desc->codecs(); + T wildcard_codec; if (!PopWildcardCodec(&codecs, &wildcard_codec)) { return; } - for (std::vector::iterator iter = codecs.begin(); - iter != codecs.end(); ++iter) { - cricket::VideoCodec& codec = *iter; + for (auto& codec : codecs) { AddFeedbackParameters(wildcard_codec.feedback_params, &codec); } - video_desc->set_codecs(codecs); + desc->set_codecs(codecs); } void AddAudioAttribute(const std::string& name, const std::string& value, @@ -2704,6 +2702,8 @@ bool ParseContent(const std::string& message, if (media_type == cricket::MEDIA_TYPE_AUDIO) { AudioContentDescription* audio_desc = static_cast(media_desc); + UpdateFromWildcardCodecs(audio_desc); + // Verify audio codec ensures that no audio codec has been populated with // only fmtp. if (!VerifyAudioCodecs(audio_desc)) { @@ -2714,14 +2714,14 @@ bool ParseContent(const std::string& message, } if (media_type == cricket::MEDIA_TYPE_VIDEO) { - VideoContentDescription* video_desc = - static_cast(media_desc); - UpdateFromWildcardVideoCodecs(video_desc); - // Verify video codec ensures that no video codec has been populated with - // only rtcp-fb. - if (!VerifyVideoCodecs(video_desc)) { - return ParseFailed("Failed to parse video codecs correctly.", error); - } + VideoContentDescription* video_desc = + static_cast(media_desc); + UpdateFromWildcardCodecs(video_desc); + // Verify video codec ensures that no video codec has been populated with + // only rtcp-fb. + if (!VerifyVideoCodecs(video_desc)) { + return ParseFailed("Failed to parse video codecs correctly.", error); + } } // RFC 5245 diff --git a/talk/app/webrtc/webrtcsdp_unittest.cc b/talk/app/webrtc/webrtcsdp_unittest.cc index 0778491ad..a80f4012b 100644 --- a/talk/app/webrtc/webrtcsdp_unittest.cc +++ b/talk/app/webrtc/webrtcsdp_unittest.cc @@ -1255,7 +1255,7 @@ class WebRtcSdpTest : public testing::Test { void TestDeserializeRtcpFb(JsepSessionDescription* jdesc_output, bool use_wildcard) { - std::string sdp = + std::string sdp_session_and_audio = "v=0\r\n" "o=- 18446744069414584320 18446462598732840960 IN IP4 127.0.0.1\r\n" "s=-\r\n" @@ -1265,17 +1265,19 @@ class WebRtcSdpTest : public testing::Test { // description. "a=msid-semantic: WMS\r\n" "m=audio 9 RTP/SAVPF 111\r\n" - "a=rtpmap:111 opus/48000/2\r\n" - "a=rtcp-fb:111 nack\r\n" + "a=rtpmap:111 opus/48000/2\r\n"; + std::string sdp_video = "m=video 3457 RTP/SAVPF 101\r\n" "a=rtpmap:101 VP8/90000\r\n" "a=rtcp-fb:101 nack\r\n" "a=rtcp-fb:101 nack pli\r\n" - "a=rtcp-fb:101 goog-remb\r\n" - "a=rtcp-fb:101 ccm fir\r\n"; + "a=rtcp-fb:101 goog-remb\r\n"; std::ostringstream os; + os << sdp_session_and_audio; + os << "a=rtcp-fb:" << (use_wildcard ? "*" : "111") << " nack\r\n"; + os << sdp_video; os << "a=rtcp-fb:" << (use_wildcard ? "*" : "101") << " ccm fir\r\n"; - sdp += os.str(); + std::string sdp = os.str(); // Deserialize SdpParseError error; EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jdesc_output, &error));