| 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_message.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 SdpMessage::SdpMessage(const std::string& sdp) { |
| 14 sdp_lines_ = |
| 15 SplitString(sdp, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 16 for (const auto& line : sdp_lines_) { |
| 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 SdpMessage::~SdpMessage() {} |
| 25 |
| 26 std::string SdpMessage::ToString() const { |
| 27 return base::JoinString(sdp_lines_, "\n") + "\n"; |
| 28 } |
| 29 |
| 30 bool SdpMessage::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 SdpMessage::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 const auto& line = sdp_lines_[i]; |
| 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 && |
| 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 |