Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/protocol/sdp_helper.h" | |
| 6 | |
| 7 #include "base/strings/string_split.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 | |
| 10 namespace remoting { | |
| 11 namespace protocol { | |
| 12 | |
| 13 SdpHelper::SdpHelper(const std::string& sdp) { | |
| 14 sdp_lines_ = | |
| 15 SplitString(sdp, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 16 for (auto& line : sdp_lines_) { | |
|
Jamie
2016/11/28 21:02:51
const auto?
Sergey Ulanov
2016/11/28 22:45:08
Done.
| |
| 17 if (base::StartsWith(line, "m=audio", base::CompareCase::SENSITIVE)) | |
| 18 has_audio_ = true; | |
| 19 if (base::StartsWith(line, "m=video", base::CompareCase::SENSITIVE)) | |
| 20 has_video_ = true; | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 SdpHelper::~SdpHelper() {} | |
| 25 | |
| 26 std::string SdpHelper::ToString() const { | |
| 27 return base::JoinString(sdp_lines_, "\n") + "\n"; | |
| 28 } | |
| 29 | |
| 30 bool SdpHelper::AddCodecParameter(const std::string& codec, | |
| 31 const std::string& parameters_to_add) { | |
| 32 int line_num; | |
| 33 std::string payload_type; | |
| 34 bool codec_found = FindCodec(codec, &line_num, &payload_type); | |
| 35 if (!codec_found) { | |
| 36 return false; | |
| 37 } | |
| 38 sdp_lines_.insert(sdp_lines_.begin() + line_num + 1, | |
| 39 "a=fmtp:" + payload_type + ' ' + parameters_to_add); | |
| 40 return true; | |
| 41 } | |
| 42 | |
| 43 bool SdpHelper::FindCodec(const std::string& codec, | |
| 44 int* line_num, | |
| 45 std::string* payload_type) const { | |
| 46 const std::string kRtpMapPrefix = "a=rtpmap:"; | |
| 47 for (size_t i = 0; i < sdp_lines_.size(); ++i) { | |
| 48 auto& line = sdp_lines_[i]; | |
|
Jamie
2016/11/28 21:02:51
const?
Sergey Ulanov
2016/11/28 22:45:08
Done.
| |
| 49 if (!base::StartsWith(line, kRtpMapPrefix, base::CompareCase::SENSITIVE)) | |
| 50 continue; | |
| 51 size_t space_pos = line.find(' '); | |
| 52 if (space_pos == std::string::npos) | |
| 53 continue; | |
| 54 if (line.substr(space_pos + 1, codec.size()) == codec && | |
|
Jamie
2016/11/28 21:02:51
Can we assume there will be only one space between
Sergey Ulanov
2016/11/28 22:45:08
Yes, I think we can assume that. The standard defi
| |
| 55 line[space_pos + 1 + codec.size()] == '/') { | |
| 56 *line_num = i; | |
| 57 *payload_type = | |
| 58 line.substr(kRtpMapPrefix.size(), space_pos - kRtpMapPrefix.size()); | |
| 59 return true; | |
| 60 } | |
| 61 } | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 } // namespace protocol | |
| 66 } // namespace remoting | |
| OLD | NEW |