Line data Source code
1 : /*
2 : * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 : *
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
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #ifndef WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_
12 : #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_
13 :
14 : #include <map>
15 : #include <memory>
16 : #include <set>
17 :
18 : #include "webrtc/base/criticalsection.h"
19 : #include "webrtc/base/deprecation.h"
20 : #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
21 : #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
22 :
23 : namespace webrtc {
24 :
25 : struct CodecInst;
26 : class VideoCodec;
27 :
28 : // TODO(magjed): Remove once external code is updated.
29 : class RTPPayloadStrategy {
30 : public:
31 : static RTPPayloadStrategy* CreateStrategy(bool handling_audio) {
32 : return nullptr;
33 : }
34 : };
35 :
36 0 : class RTPPayloadRegistry {
37 : public:
38 : RTPPayloadRegistry();
39 : ~RTPPayloadRegistry();
40 : // TODO(magjed): Remove once external code is updated.
41 : explicit RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy)
42 : : RTPPayloadRegistry() {}
43 :
44 : // TODO(magjed): Split RTPPayloadRegistry into separate Audio and Video class
45 : // and simplify the code. http://crbug/webrtc/6743.
46 : int32_t RegisterReceivePayload(const CodecInst& audio_codec,
47 : bool* created_new_payload_type);
48 : int32_t RegisterReceivePayload(const VideoCodec& video_codec);
49 :
50 : int32_t DeRegisterReceivePayload(int8_t payload_type);
51 :
52 : int32_t ReceivePayloadType(const CodecInst& audio_codec,
53 : int8_t* payload_type) const;
54 : int32_t ReceivePayloadType(const VideoCodec& video_codec,
55 : int8_t* payload_type) const;
56 :
57 : bool RtxEnabled() const;
58 :
59 : void SetRtxSsrc(uint32_t ssrc);
60 :
61 : bool GetRtxSsrc(uint32_t* ssrc) const;
62 :
63 : void SetRtxPayloadType(int payload_type, int associated_payload_type);
64 :
65 : bool IsRtx(const RTPHeader& header) const;
66 :
67 : bool RestoreOriginalPacket(uint8_t* restored_packet,
68 : const uint8_t* packet,
69 : size_t* packet_length,
70 : uint32_t original_ssrc,
71 : const RTPHeader& header);
72 :
73 : bool IsRed(const RTPHeader& header) const;
74 :
75 : // Returns true if the media of this RTP packet is encapsulated within an
76 : // extra header, such as RTX or RED.
77 : bool IsEncapsulated(const RTPHeader& header) const;
78 :
79 : bool GetPayloadSpecifics(uint8_t payload_type, PayloadUnion* payload) const;
80 :
81 : int GetPayloadTypeFrequency(uint8_t payload_type) const;
82 :
83 : const RtpUtility::Payload* PayloadTypeToPayload(uint8_t payload_type) const;
84 :
85 : void ResetLastReceivedPayloadTypes() {
86 : rtc::CritScope cs(&crit_sect_);
87 : last_received_payload_type_ = -1;
88 : last_received_media_payload_type_ = -1;
89 : }
90 :
91 : // 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
93 : // payload type will be the RED payload type.
94 : void SetIncomingPayloadType(const RTPHeader& header);
95 :
96 : // Returns true if the new media payload type has not changed.
97 : bool ReportMediaPayloadType(uint8_t media_payload_type);
98 :
99 0 : int8_t red_payload_type() const { return GetPayloadTypeWithName("red"); }
100 0 : int8_t ulpfec_payload_type() const {
101 0 : return GetPayloadTypeWithName("ulpfec");
102 : }
103 0 : int8_t last_received_payload_type() const {
104 0 : rtc::CritScope cs(&crit_sect_);
105 0 : return last_received_payload_type_;
106 : }
107 0 : void set_last_received_payload_type(int8_t last_received_payload_type) {
108 0 : rtc::CritScope cs(&crit_sect_);
109 0 : last_received_payload_type_ = last_received_payload_type;
110 0 : }
111 :
112 0 : int8_t last_received_media_payload_type() const {
113 0 : rtc::CritScope cs(&crit_sect_);
114 0 : return last_received_media_payload_type_;
115 : }
116 :
117 : RTC_DEPRECATED void set_use_rtx_payload_mapping_on_restore(bool val) {}
118 :
119 : private:
120 : // Prunes the payload type map of the specific payload type, if it exists.
121 : void DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType(
122 : const CodecInst& audio_codec);
123 :
124 : 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 :
129 : rtc::CriticalSection crit_sect_;
130 : std::map<int, RtpUtility::Payload> payload_type_map_;
131 : int8_t incoming_payload_type_;
132 : int8_t last_received_payload_type_;
133 : int8_t last_received_media_payload_type_;
134 : bool rtx_;
135 : // Mapping rtx_payload_type_map_[rtx] = associated.
136 : std::map<int, int> rtx_payload_type_map_;
137 : uint32_t ssrc_rtx_;
138 : // Only warn once per payload type, if an RTX packet is received but
139 : // no associated payload type found in |rtx_payload_type_map_|.
140 : std::set<int> payload_types_with_suppressed_warnings_ GUARDED_BY(crit_sect_);
141 : };
142 :
143 : } // namespace webrtc
144 :
145 : #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_
|