| 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 // This strategy deals with the audio/video-specific aspects | |
| 29 // of payload handling. | |
| 30 class RTPPayloadStrategy { | |
| 31 public: | |
| 32 virtual ~RTPPayloadStrategy() {} | |
| 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() {} | |
| 57 }; | |
| 58 | |
| 59 class RTPPayloadRegistry { | 28 class RTPPayloadRegistry { |
| 60 public: | 29 public: |
| 61 // The registry takes ownership of the strategy. | 30 RTPPayloadRegistry(); |
| 62 explicit RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy); | |
| 63 ~RTPPayloadRegistry(); | 31 ~RTPPayloadRegistry(); |
| 64 | 32 |
| 65 // TODO(magjed): Split RTPPayloadRegistry into separate Audio and Video class | 33 // TODO(magjed): Split RTPPayloadRegistry into separate Audio and Video class |
| 66 // and remove RTPPayloadStrategy, RTPPayloadVideoStrategy, | 34 // and simplify the code. http://crbug/webrtc/6743. |
| 67 // RTPPayloadAudioStrategy, and simplify the code. http://crbug/webrtc/6743. | |
| 68 int32_t RegisterReceivePayload(const CodecInst& audio_codec, | 35 int32_t RegisterReceivePayload(const CodecInst& audio_codec, |
| 69 bool* created_new_payload_type); | 36 bool* created_new_payload_type); |
| 70 int32_t RegisterReceivePayload(const VideoCodec& video_codec); | 37 int32_t RegisterReceivePayload(const VideoCodec& video_codec); |
| 71 | 38 |
| 72 int32_t DeRegisterReceivePayload(int8_t payload_type); | 39 int32_t DeRegisterReceivePayload(int8_t payload_type); |
| 73 | 40 |
| 74 int32_t ReceivePayloadType(const CodecInst& audio_codec, | 41 int32_t ReceivePayloadType(const CodecInst& audio_codec, |
| 75 int8_t* payload_type) const; | 42 int8_t* payload_type) const; |
| 76 int32_t ReceivePayloadType(const VideoCodec& video_codec, | 43 int32_t ReceivePayloadType(const VideoCodec& video_codec, |
| 77 int8_t* payload_type) const; | 44 int8_t* payload_type) const; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 78 } |
| 112 | 79 |
| 113 // This sets the payload type of the packets being received from the network | 80 // This sets the payload type of the packets being received from the network |
| 114 // on the media SSRC. For instance if packets are encapsulated with RED, this | 81 // on the media SSRC. For instance if packets are encapsulated with RED, this |
| 115 // payload type will be the RED payload type. | 82 // payload type will be the RED payload type. |
| 116 void SetIncomingPayloadType(const RTPHeader& header); | 83 void SetIncomingPayloadType(const RTPHeader& header); |
| 117 | 84 |
| 118 // Returns true if the new media payload type has not changed. | 85 // Returns true if the new media payload type has not changed. |
| 119 bool ReportMediaPayloadType(uint8_t media_payload_type); | 86 bool ReportMediaPayloadType(uint8_t media_payload_type); |
| 120 | 87 |
| 121 int8_t red_payload_type() const { | 88 int8_t red_payload_type() const { return GetPayloadTypeWithName("red"); } |
| 122 rtc::CritScope cs(&crit_sect_); | |
| 123 return red_payload_type_; | |
| 124 } | |
| 125 int8_t ulpfec_payload_type() const { | 89 int8_t ulpfec_payload_type() const { |
| 126 rtc::CritScope cs(&crit_sect_); | 90 return GetPayloadTypeWithName("ulpfec"); |
| 127 return ulpfec_payload_type_; | |
| 128 } | 91 } |
| 129 int8_t last_received_payload_type() const { | 92 int8_t last_received_payload_type() const { |
| 130 rtc::CritScope cs(&crit_sect_); | 93 rtc::CritScope cs(&crit_sect_); |
| 131 return last_received_payload_type_; | 94 return last_received_payload_type_; |
| 132 } | 95 } |
| 133 void set_last_received_payload_type(int8_t last_received_payload_type) { | 96 void set_last_received_payload_type(int8_t last_received_payload_type) { |
| 134 rtc::CritScope cs(&crit_sect_); | 97 rtc::CritScope cs(&crit_sect_); |
| 135 last_received_payload_type_ = last_received_payload_type; | 98 last_received_payload_type_ = last_received_payload_type; |
| 136 } | 99 } |
| 137 | 100 |
| 138 int8_t last_received_media_payload_type() const { | 101 int8_t last_received_media_payload_type() const { |
| 139 rtc::CritScope cs(&crit_sect_); | 102 rtc::CritScope cs(&crit_sect_); |
| 140 return last_received_media_payload_type_; | 103 return last_received_media_payload_type_; |
| 141 } | 104 } |
| 142 | 105 |
| 143 RTC_DEPRECATED void set_use_rtx_payload_mapping_on_restore(bool val) {} | 106 RTC_DEPRECATED void set_use_rtx_payload_mapping_on_restore(bool val) {} |
| 144 | 107 |
| 145 private: | 108 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 | |
| 159 // Prunes the payload type map of the specific payload type, if it exists. | 109 // Prunes the payload type map of the specific payload type, if it exists. |
| 160 void DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType( | 110 void DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType( |
| 161 const char* payload_name, | 111 const CodecInst& audio_codec); |
| 162 size_t payload_name_length, | |
| 163 uint32_t frequency, | |
| 164 size_t channels, | |
| 165 uint32_t rate); | |
| 166 | 112 |
| 167 bool IsRtxInternal(const RTPHeader& header) const; | 113 bool IsRtxInternal(const RTPHeader& header) const; |
| 114 // Returns the payload type for the payload with name |payload_name|, or -1 if |
| 115 // no such payload is registered. |
| 116 int8_t GetPayloadTypeWithName(const char* payload_name) const; |
| 168 | 117 |
| 169 rtc::CriticalSection crit_sect_; | 118 rtc::CriticalSection crit_sect_; |
| 170 RtpUtility::PayloadTypeMap payload_type_map_; | 119 std::map<int, RtpUtility::Payload> payload_type_map_; |
| 171 std::unique_ptr<RTPPayloadStrategy> rtp_payload_strategy_; | |
| 172 int8_t red_payload_type_; | |
| 173 int8_t ulpfec_payload_type_; | |
| 174 int8_t incoming_payload_type_; | 120 int8_t incoming_payload_type_; |
| 175 int8_t last_received_payload_type_; | 121 int8_t last_received_payload_type_; |
| 176 int8_t last_received_media_payload_type_; | 122 int8_t last_received_media_payload_type_; |
| 177 bool rtx_; | 123 bool rtx_; |
| 178 // Mapping rtx_payload_type_map_[rtx] = associated. | 124 // Mapping rtx_payload_type_map_[rtx] = associated. |
| 179 std::map<int, int> rtx_payload_type_map_; | 125 std::map<int, int> rtx_payload_type_map_; |
| 180 uint32_t ssrc_rtx_; | 126 uint32_t ssrc_rtx_; |
| 181 // Only warn once per payload type, if an RTX packet is received but | 127 // Only warn once per payload type, if an RTX packet is received but |
| 182 // no associated payload type found in |rtx_payload_type_map_|. | 128 // no associated payload type found in |rtx_payload_type_map_|. |
| 183 std::set<int> payload_types_with_suppressed_warnings_ GUARDED_BY(crit_sect_); | 129 std::set<int> payload_types_with_suppressed_warnings_ GUARDED_BY(crit_sect_); |
| 184 }; | 130 }; |
| 185 | 131 |
| 186 } // namespace webrtc | 132 } // namespace webrtc |
| 187 | 133 |
| 188 #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | 134 #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ |
| OLD | NEW |