Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: webrtc/api/webrtcsdp.cc

Issue 1762003003: If MSID is encoded in both ways, make the SSRC-level one take priority. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding unit test. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/api/webrtcsdp_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 static const int kIsacWbDefaultRate = 32000; // From acm_common_defs.h 205 static const int kIsacWbDefaultRate = 32000; // From acm_common_defs.h
206 static const int kIsacSwbDefaultRate = 56000; // From acm_common_defs.h 206 static const int kIsacSwbDefaultRate = 56000; // From acm_common_defs.h
207 207
208 static const char kDefaultSctpmapProtocol[] = "webrtc-datachannel"; 208 static const char kDefaultSctpmapProtocol[] = "webrtc-datachannel";
209 209
210 // RTP payload type is in the 0-127 range. Use -1 to indicate "all" payload 210 // RTP payload type is in the 0-127 range. Use -1 to indicate "all" payload
211 // types. 211 // types.
212 const int kWildcardPayloadType = -1; 212 const int kWildcardPayloadType = -1;
213 213
214 struct SsrcInfo { 214 struct SsrcInfo {
215 SsrcInfo()
216 : stream_id(kDefaultMsid),
217 // TODO(ronghuawu): What should we do if the track id doesn't appear?
218 // Create random string (which will be used as track label later)?
219 track_id(rtc::CreateRandomString(8)) {}
220 uint32_t ssrc_id; 215 uint32_t ssrc_id;
221 std::string cname; 216 std::string cname;
222 std::string stream_id; 217 std::string stream_id;
223 std::string track_id; 218 std::string track_id;
224 219
225 // For backward compatibility. 220 // For backward compatibility.
226 // TODO(ronghuawu): Remove below 2 fields once all the clients support msid. 221 // TODO(ronghuawu): Remove below 2 fields once all the clients support msid.
227 std::string label; 222 std::string label;
228 std::string mslabel; 223 std::string mslabel;
229 }; 224 };
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 561 }
567 562
568 static bool GetPayloadTypeFromString(const std::string& line, 563 static bool GetPayloadTypeFromString(const std::string& line,
569 const std::string& s, 564 const std::string& s,
570 int* payload_type, 565 int* payload_type,
571 SdpParseError* error) { 566 SdpParseError* error) {
572 return GetValueFromString(line, s, payload_type, error) && 567 return GetValueFromString(line, s, payload_type, error) &&
573 cricket::IsValidRtpPayloadType(*payload_type); 568 cricket::IsValidRtpPayloadType(*payload_type);
574 } 569 }
575 570
571 // |msid_stream_id| and |msid_track_id| represent the stream/track ID from the
572 // "a=msid" attribute, if it exists. They are empty if the attribute does not
573 // exist.
576 void CreateTracksFromSsrcInfos(const SsrcInfoVec& ssrc_infos, 574 void CreateTracksFromSsrcInfos(const SsrcInfoVec& ssrc_infos,
575 const std::string& msid_stream_id,
576 const std::string& msid_track_id,
577 StreamParamsVec* tracks) { 577 StreamParamsVec* tracks) {
578 ASSERT(tracks != NULL); 578 ASSERT(tracks != NULL);
579 ASSERT(msid_stream_id.empty() == msid_track_id.empty());
579 for (SsrcInfoVec::const_iterator ssrc_info = ssrc_infos.begin(); 580 for (SsrcInfoVec::const_iterator ssrc_info = ssrc_infos.begin();
580 ssrc_info != ssrc_infos.end(); ++ssrc_info) { 581 ssrc_info != ssrc_infos.end(); ++ssrc_info) {
581 if (ssrc_info->cname.empty()) { 582 if (ssrc_info->cname.empty()) {
582 continue; 583 continue;
583 } 584 }
584 585
585 std::string sync_label; 586 std::string stream_id;
586 std::string track_id; 587 std::string track_id;
587 if (ssrc_info->stream_id == kDefaultMsid && !ssrc_info->mslabel.empty()) { 588 if (ssrc_info->stream_id.empty() && !ssrc_info->mslabel.empty()) {
588 // If there's no msid and there's mslabel, we consider this is a sdp from 589 // If there's no msid and there's mslabel, we consider this is a sdp from
589 // a older version of client that doesn't support msid. 590 // a older version of client that doesn't support msid.
590 // In that case, we use the mslabel and label to construct the track. 591 // In that case, we use the mslabel and label to construct the track.
591 sync_label = ssrc_info->mslabel; 592 stream_id = ssrc_info->mslabel;
592 track_id = ssrc_info->label; 593 track_id = ssrc_info->label;
594 } else if (ssrc_info->stream_id.empty() && !msid_stream_id.empty()) {
595 // If there's no msid in the SSRC attributes, but there's a global one
596 // (from a=msid), use that. This is the case with unified plan SDP.
597 stream_id = msid_stream_id;
598 track_id = msid_track_id;
593 } else { 599 } else {
594 sync_label = ssrc_info->stream_id; 600 stream_id = ssrc_info->stream_id;
595 track_id = ssrc_info->track_id; 601 track_id = ssrc_info->track_id;
596 } 602 }
597 if (sync_label.empty() || track_id.empty()) { 603 // If a stream/track ID wasn't populated from the SSRC attributes OR the
598 ASSERT(false); 604 // msid attribute, use default/random values.
599 continue; 605 if (stream_id.empty()) {
606 stream_id = kDefaultMsid;
607 }
608 if (track_id.empty()) {
609 // TODO(ronghuawu): What should we do if the track id doesn't appear?
610 // Create random string (which will be used as track label later)?
611 track_id = rtc::CreateRandomString(8);
600 } 612 }
601 613
602 StreamParamsVec::iterator track = tracks->begin(); 614 StreamParamsVec::iterator track = tracks->begin();
603 for (; track != tracks->end(); ++track) { 615 for (; track != tracks->end(); ++track) {
604 if (track->id == track_id) { 616 if (track->id == track_id) {
605 break; 617 break;
606 } 618 }
607 } 619 }
608 if (track == tracks->end()) { 620 if (track == tracks->end()) {
609 // If we don't find an existing track, create a new one. 621 // If we don't find an existing track, create a new one.
610 tracks->push_back(StreamParams()); 622 tracks->push_back(StreamParams());
611 track = tracks->end() - 1; 623 track = tracks->end() - 1;
612 } 624 }
613 track->add_ssrc(ssrc_info->ssrc_id); 625 track->add_ssrc(ssrc_info->ssrc_id);
614 track->cname = ssrc_info->cname; 626 track->cname = ssrc_info->cname;
615 track->sync_label = sync_label; 627 track->sync_label = stream_id;
616 track->id = track_id; 628 track->id = track_id;
617 } 629 }
618 } 630 }
619 631
620 void GetMediaStreamLabels(const ContentInfo* content, 632 void GetMediaStreamLabels(const ContentInfo* content,
621 std::set<std::string>* labels) { 633 std::set<std::string>* labels) {
622 const MediaContentDescription* media_desc = 634 const MediaContentDescription* media_desc =
623 static_cast<const MediaContentDescription*>( 635 static_cast<const MediaContentDescription*>(
624 content->description); 636 content->description);
625 const cricket::StreamParamsVec& streams = media_desc->streams(); 637 const cricket::StreamParamsVec& streams = media_desc->streams();
(...skipping 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 return false; 2675 return false;
2664 } 2676 }
2665 } 2677 }
2666 } else { 2678 } else {
2667 // Only parse lines that we are interested of. 2679 // Only parse lines that we are interested of.
2668 LOG(LS_INFO) << "Ignored line: " << line; 2680 LOG(LS_INFO) << "Ignored line: " << line;
2669 continue; 2681 continue;
2670 } 2682 }
2671 } 2683 }
2672 2684
2673 // Found an msid attribute.
2674 // Setting the stream_id/track_id will cause only one StreamParams
2675 // to be created in CreateTracksFromSsrcInfos, containing all the SSRCs from
2676 // the m= section.
2677 if (!stream_id.empty() && !track_id.empty()) {
2678 for (SsrcInfo& ssrc_info : ssrc_infos) {
2679 ssrc_info.stream_id = stream_id;
2680 ssrc_info.track_id = track_id;
2681 }
2682 }
2683
2684 // Create tracks from the |ssrc_infos|. 2685 // Create tracks from the |ssrc_infos|.
2685 CreateTracksFromSsrcInfos(ssrc_infos, &tracks); 2686 // If the stream_id/track_id for all SSRCS are identical, one StreamParams
2687 // will be created in CreateTracksFromSsrcInfos, containing all the SSRCs from
2688 // the m= section.
2689 CreateTracksFromSsrcInfos(ssrc_infos, stream_id, track_id, &tracks);
2686 2690
2687 // Add the ssrc group to the track. 2691 // Add the ssrc group to the track.
2688 for (SsrcGroupVec::iterator ssrc_group = ssrc_groups.begin(); 2692 for (SsrcGroupVec::iterator ssrc_group = ssrc_groups.begin();
2689 ssrc_group != ssrc_groups.end(); ++ssrc_group) { 2693 ssrc_group != ssrc_groups.end(); ++ssrc_group) {
2690 if (ssrc_group->ssrcs.empty()) { 2694 if (ssrc_group->ssrcs.empty()) {
2691 continue; 2695 continue;
2692 } 2696 }
2693 uint32_t ssrc = ssrc_group->ssrcs.front(); 2697 uint32_t ssrc = ssrc_group->ssrcs.front();
2694 for (StreamParamsVec::iterator track = tracks.begin(); 2698 for (StreamParamsVec::iterator track = tracks.begin();
2695 track != tracks.end(); ++track) { 2699 track != tracks.end(); ++track) {
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( 3128 UpdateCodec<AudioContentDescription, cricket::AudioCodec>(
3125 media_desc, payload_type, feedback_param); 3129 media_desc, payload_type, feedback_param);
3126 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { 3130 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
3127 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( 3131 UpdateCodec<VideoContentDescription, cricket::VideoCodec>(
3128 media_desc, payload_type, feedback_param); 3132 media_desc, payload_type, feedback_param);
3129 } 3133 }
3130 return true; 3134 return true;
3131 } 3135 }
3132 3136
3133 } // namespace webrtc 3137 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/api/webrtcsdp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698