2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
14 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
15 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
17 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
18 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
19 #include "webrtc/typedefs.h"
23 class TelephoneEventHandler;
25 // This strategy deals with media-specific RTP packet processing.
26 // This class is not thread-safe and must be protected by its caller.
27 class RTPReceiverStrategy {
29 static RTPReceiverStrategy* CreateVideoStrategy(RtpData* data_callback);
30 static RTPReceiverStrategy* CreateAudioStrategy(
31 int32_t id, RtpData* data_callback,
32 RtpAudioFeedback* incoming_messages_callback);
34 virtual ~RTPReceiverStrategy() {}
36 // Parses the RTP packet and calls the data callback with the payload data.
37 // Implementations are encouraged to use the provided packet buffer and RTP
38 // header as arguments to the callback; implementations are also allowed to
39 // make changes in the data as necessary. The specific_payload argument
40 // provides audio or video-specific data. The is_first_packet argument is true
41 // if this packet is either the first packet ever or the first in its frame.
42 virtual int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header,
43 const PayloadUnion& specific_payload,
45 const uint8_t* payload,
46 uint16_t payload_length,
48 bool is_first_packet) = 0;
50 virtual TelephoneEventHandler* GetTelephoneEventHandler() = 0;
52 // Retrieves the last known applicable frequency.
53 virtual int GetPayloadTypeFrequency() const = 0;
55 // Computes the current dead-or-alive state.
56 virtual RTPAliveType ProcessDeadOrAlive(
57 uint16_t last_payload_length) const = 0;
59 // Returns true if we should report CSRC changes for this payload type.
60 // TODO(phoglund): should move out of here along with other payload stuff.
61 virtual bool ShouldReportCsrcChanges(uint8_t payload_type) const = 0;
63 // Notifies the strategy that we have created a new non-RED payload type in
64 // the payload registry.
65 virtual int32_t OnNewPayloadTypeCreated(
66 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
68 uint32_t frequency) = 0;
70 // Invokes the OnInitializeDecoder callback in a media-specific way.
71 virtual int32_t InvokeOnInitializeDecoder(
72 RtpFeedback* callback,
75 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
76 const PayloadUnion& specific_payload) const = 0;
78 // Checks if the payload type has changed, and returns whether we should
79 // reset statistics and/or discard this packet.
80 virtual void CheckPayloadChanged(int8_t payload_type,
81 PayloadUnion* specific_payload,
82 bool* should_reset_statistics,
83 bool* should_discard_changes);
85 virtual int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const;
87 // Stores / retrieves the last media specific payload for later reference.
88 void GetLastMediaSpecificPayload(PayloadUnion* payload) const;
89 void SetLastMediaSpecificPayload(const PayloadUnion& payload);
92 // The data callback is where we should send received payload data.
93 // See ParseRtpPacket. This class does not claim ownership of the callback.
94 // Implementations must NOT hold any critical sections while calling the
97 // Note: Implementations may call the callback for other reasons than calls
98 // to ParseRtpPacket, for instance if the implementation somehow recovers a
100 RTPReceiverStrategy(RtpData* data_callback);
102 scoped_ptr<CriticalSectionWrapper> crit_sect_;
103 PayloadUnion last_payload_;
104 RtpData* data_callback_;
106 } // namespace webrtc
108 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_