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
This commit is contained in:
jlmiller@webrtc.org 2015-02-18 21:37:46 +00:00
parent 30540fe722
commit a744a28b92
2 changed files with 27 additions and 25 deletions

View File

@ -2436,10 +2436,9 @@ void UpdateCodec(MediaContentDescription* content_desc, int payload_type,
AddOrReplaceCodec<T, U>(content_desc, new_codec);
}
bool PopWildcardCodec(std::vector<cricket::VideoCodec>* codecs,
cricket::VideoCodec* wildcard_codec) {
for (std::vector<cricket::VideoCodec>::iterator iter = codecs->begin();
iter != codecs->end(); ++iter) {
template <class T>
bool PopWildcardCodec(std::vector<T>* 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<cricket::VideoCodec>* codecs,
return false;
}
void UpdateFromWildcardVideoCodecs(VideoContentDescription* video_desc) {
std::vector<cricket::VideoCodec> codecs = video_desc->codecs();
cricket::VideoCodec wildcard_codec;
template<class T>
void UpdateFromWildcardCodecs(cricket::MediaContentDescriptionImpl<T>* desc) {
auto codecs = desc->codecs();
T wildcard_codec;
if (!PopWildcardCodec(&codecs, &wildcard_codec)) {
return;
}
for (std::vector<cricket::VideoCodec>::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<AudioContentDescription*>(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<VideoContentDescription*>(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<VideoContentDescription*>(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

View File

@ -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));