File: sdp_message.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 2,982 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_SDP_MESSAGE_H_
#define REMOTING_PROTOCOL_SDP_MESSAGE_H_

#include <map>
#include <string>
#include <vector>

namespace webrtc {
struct SdpVideoFormat;
}

namespace remoting::protocol {

// SdpMessage is used to process session descriptions messages in SDP format
// generated by WebRTC (see RFC 4566). In particularly it allows configuring
// video and audio codecs.
//
// It also normalizes the SDP message to make sure the text used for HMAC
// signature verification is the same that was signed on the sending side.
// This is necessary because WebRTC generates SDP with CRLF line endings which
// are sometimes converted to LF after passing the signaling channel.
class SdpMessage {
 public:
  explicit SdpMessage(const std::string& sdp);
  ~SdpMessage();

  bool has_audio() const { return has_audio_; }
  bool has_video() const { return has_video_; }

  // Returns string representation of the SDP message. The result always has
  // line-endings normalized to CR+LF and empty lines removed.
  std::string ToString() const;

  // Returns string representation of the SDP message for the purpose of
  // computing or verifying its signature, which is transmitted along with the
  // SDP over signaling channel. This must be implemented in exactly the same
  // way at each end of the connection.
  std::string NormalizedForSignature() const;

  // Adds specified parameters for the |codec|. Returns false if the |codec| is
  // not listed anywhere in the SDP message.
  bool AddCodecParameter(const std::string& codec,
                         const std::string& parameters_to_add);

  // Reorders the list of video formats by placing the payload associated with
  // |format| at the front. By doing this, the sender-side of the connection
  // will try to use that codec first. The SDP message will not be modified if
  // |format| is not a supported codec.
  void SetPreferredVideoFormat(const webrtc::SdpVideoFormat& format);

 private:
  struct Payload {
    size_t index;
    std::string type;
  };
  using Payloads = std::vector<Payload>;

  // Finds the lines of the form "a=rtpmap:<payload_type> <codec>/.." with the
  // specified |codec| and returns a list of the matching payload types with
  // their line numbers.
  Payloads FindCodecPayloads(const std::string& codec) const;

  // Overload for |FindCodec| which also filters based on fmtp parameter, such
  // as profile-id for video codecs.
  Payloads FindCodecPayloads(const std::string& codec,
                             const std::string& fmtp_param) const;

  std::string GetFmtpFragmentForSdpVideoFormat(
      const webrtc::SdpVideoFormat& format) const;

  std::vector<std::string> sdp_lines_;

  bool has_audio_ = false;
  bool has_video_ = false;
};

}  // namespace remoting::protocol

#endif  // REMOTING_PROTOCOL_SDP_MESSAGE_H_