OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
11 #ifndef WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ |
12 #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <memory> | 15 #include <memory> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
19 #include "webrtc/base/deprecation.h" | 19 #include "webrtc/base/deprecation.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 struct CodecInst; | 25 struct CodecInst; |
26 class VideoCodec; | 26 class VideoCodec; |
27 | 27 |
28 // TODO(magjed): Remove once external code is updated. | 28 // This strategy deals with the audio/video-specific aspects |
| 29 // of payload handling. |
29 class RTPPayloadStrategy { | 30 class RTPPayloadStrategy { |
30 public: | 31 public: |
31 static RTPPayloadStrategy* CreateStrategy(bool handling_audio) { | 32 virtual ~RTPPayloadStrategy() {} |
32 return nullptr; | 33 |
33 } | 34 virtual bool CodecsMustBeUnique() const = 0; |
| 35 |
| 36 virtual bool PayloadIsCompatible(const RtpUtility::Payload& payload, |
| 37 uint32_t frequency, |
| 38 size_t channels, |
| 39 uint32_t rate) const = 0; |
| 40 |
| 41 virtual void UpdatePayloadRate(RtpUtility::Payload* payload, |
| 42 uint32_t rate) const = 0; |
| 43 |
| 44 virtual RtpUtility::Payload* CreatePayloadType(const char* payload_name, |
| 45 int8_t payload_type, |
| 46 uint32_t frequency, |
| 47 size_t channels, |
| 48 uint32_t rate) const = 0; |
| 49 |
| 50 virtual int GetPayloadTypeFrequency( |
| 51 const RtpUtility::Payload& payload) const = 0; |
| 52 |
| 53 static RTPPayloadStrategy* CreateStrategy(bool handling_audio); |
| 54 |
| 55 protected: |
| 56 RTPPayloadStrategy() {} |
34 }; | 57 }; |
35 | 58 |
36 class RTPPayloadRegistry { | 59 class RTPPayloadRegistry { |
37 public: | 60 public: |
38 RTPPayloadRegistry(); | 61 // The registry takes ownership of the strategy. |
| 62 explicit RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy); |
39 ~RTPPayloadRegistry(); | 63 ~RTPPayloadRegistry(); |
40 // TODO(magjed): Remove once external code is updated. | |
41 explicit RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy) | |
42 : RTPPayloadRegistry() {} | |
43 | 64 |
44 // TODO(magjed): Split RTPPayloadRegistry into separate Audio and Video class | 65 // TODO(magjed): Split RTPPayloadRegistry into separate Audio and Video class |
45 // and simplify the code. http://crbug/webrtc/6743. | 66 // and remove RTPPayloadStrategy, RTPPayloadVideoStrategy, |
| 67 // RTPPayloadAudioStrategy, and simplify the code. http://crbug/webrtc/6743. |
46 int32_t RegisterReceivePayload(const CodecInst& audio_codec, | 68 int32_t RegisterReceivePayload(const CodecInst& audio_codec, |
47 bool* created_new_payload_type); | 69 bool* created_new_payload_type); |
48 int32_t RegisterReceivePayload(const VideoCodec& video_codec); | 70 int32_t RegisterReceivePayload(const VideoCodec& video_codec); |
49 | 71 |
50 int32_t DeRegisterReceivePayload(int8_t payload_type); | 72 int32_t DeRegisterReceivePayload(int8_t payload_type); |
51 | 73 |
52 int32_t ReceivePayloadType(const CodecInst& audio_codec, | 74 int32_t ReceivePayloadType(const CodecInst& audio_codec, |
53 int8_t* payload_type) const; | 75 int8_t* payload_type) const; |
54 int32_t ReceivePayloadType(const VideoCodec& video_codec, | 76 int32_t ReceivePayloadType(const VideoCodec& video_codec, |
55 int8_t* payload_type) const; | 77 int8_t* payload_type) const; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 111 } |
90 | 112 |
91 // This sets the payload type of the packets being received from the network | 113 // This sets the payload type of the packets being received from the network |
92 // on the media SSRC. For instance if packets are encapsulated with RED, this | 114 // on the media SSRC. For instance if packets are encapsulated with RED, this |
93 // payload type will be the RED payload type. | 115 // payload type will be the RED payload type. |
94 void SetIncomingPayloadType(const RTPHeader& header); | 116 void SetIncomingPayloadType(const RTPHeader& header); |
95 | 117 |
96 // Returns true if the new media payload type has not changed. | 118 // Returns true if the new media payload type has not changed. |
97 bool ReportMediaPayloadType(uint8_t media_payload_type); | 119 bool ReportMediaPayloadType(uint8_t media_payload_type); |
98 | 120 |
99 int8_t red_payload_type() const { return GetPayloadTypeWithName("red"); } | 121 int8_t red_payload_type() const { |
| 122 rtc::CritScope cs(&crit_sect_); |
| 123 return red_payload_type_; |
| 124 } |
100 int8_t ulpfec_payload_type() const { | 125 int8_t ulpfec_payload_type() const { |
101 return GetPayloadTypeWithName("ulpfec"); | 126 rtc::CritScope cs(&crit_sect_); |
| 127 return ulpfec_payload_type_; |
102 } | 128 } |
103 int8_t last_received_payload_type() const { | 129 int8_t last_received_payload_type() const { |
104 rtc::CritScope cs(&crit_sect_); | 130 rtc::CritScope cs(&crit_sect_); |
105 return last_received_payload_type_; | 131 return last_received_payload_type_; |
106 } | 132 } |
107 void set_last_received_payload_type(int8_t last_received_payload_type) { | 133 void set_last_received_payload_type(int8_t last_received_payload_type) { |
108 rtc::CritScope cs(&crit_sect_); | 134 rtc::CritScope cs(&crit_sect_); |
109 last_received_payload_type_ = last_received_payload_type; | 135 last_received_payload_type_ = last_received_payload_type; |
110 } | 136 } |
111 | 137 |
112 int8_t last_received_media_payload_type() const { | 138 int8_t last_received_media_payload_type() const { |
113 rtc::CritScope cs(&crit_sect_); | 139 rtc::CritScope cs(&crit_sect_); |
114 return last_received_media_payload_type_; | 140 return last_received_media_payload_type_; |
115 } | 141 } |
116 | 142 |
117 RTC_DEPRECATED void set_use_rtx_payload_mapping_on_restore(bool val) {} | 143 RTC_DEPRECATED void set_use_rtx_payload_mapping_on_restore(bool val) {} |
118 | 144 |
119 private: | 145 private: |
| 146 int32_t RegisterReceivePayload(const char* payload_name, |
| 147 int8_t payload_type, |
| 148 uint32_t frequency, |
| 149 size_t channels, |
| 150 uint32_t rate, |
| 151 bool* created_new_payload_type); |
| 152 |
| 153 int32_t ReceivePayloadType(const char* payload_name, |
| 154 uint32_t frequency, |
| 155 size_t channels, |
| 156 uint32_t rate, |
| 157 int8_t* payload_type) const; |
| 158 |
120 // Prunes the payload type map of the specific payload type, if it exists. | 159 // Prunes the payload type map of the specific payload type, if it exists. |
121 void DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType( | 160 void DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType( |
122 const CodecInst& audio_codec); | 161 const char* payload_name, |
| 162 size_t payload_name_length, |
| 163 uint32_t frequency, |
| 164 size_t channels, |
| 165 uint32_t rate); |
123 | 166 |
124 bool IsRtxInternal(const RTPHeader& header) const; | 167 bool IsRtxInternal(const RTPHeader& header) const; |
125 // Returns the payload type for the payload with name |payload_name|, or -1 if | |
126 // no such payload is registered. | |
127 int8_t GetPayloadTypeWithName(const char* payload_name) const; | |
128 | 168 |
129 rtc::CriticalSection crit_sect_; | 169 rtc::CriticalSection crit_sect_; |
130 std::map<int, RtpUtility::Payload> payload_type_map_; | 170 RtpUtility::PayloadTypeMap payload_type_map_; |
| 171 std::unique_ptr<RTPPayloadStrategy> rtp_payload_strategy_; |
| 172 int8_t red_payload_type_; |
| 173 int8_t ulpfec_payload_type_; |
131 int8_t incoming_payload_type_; | 174 int8_t incoming_payload_type_; |
132 int8_t last_received_payload_type_; | 175 int8_t last_received_payload_type_; |
133 int8_t last_received_media_payload_type_; | 176 int8_t last_received_media_payload_type_; |
134 bool rtx_; | 177 bool rtx_; |
135 // Mapping rtx_payload_type_map_[rtx] = associated. | 178 // Mapping rtx_payload_type_map_[rtx] = associated. |
136 std::map<int, int> rtx_payload_type_map_; | 179 std::map<int, int> rtx_payload_type_map_; |
137 uint32_t ssrc_rtx_; | 180 uint32_t ssrc_rtx_; |
138 // Only warn once per payload type, if an RTX packet is received but | 181 // Only warn once per payload type, if an RTX packet is received but |
139 // no associated payload type found in |rtx_payload_type_map_|. | 182 // no associated payload type found in |rtx_payload_type_map_|. |
140 std::set<int> payload_types_with_suppressed_warnings_ GUARDED_BY(crit_sect_); | 183 std::set<int> payload_types_with_suppressed_warnings_ GUARDED_BY(crit_sect_); |
141 }; | 184 }; |
142 | 185 |
143 } // namespace webrtc | 186 } // namespace webrtc |
144 | 187 |
145 #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | 188 #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ |
OLD | NEW |