• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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_SOURCE_RTP_RECEIVER_STRATEGY_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
13 
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
19 #include "webrtc/typedefs.h"
20 
21 namespace webrtc {
22 
23 class TelephoneEventHandler;
24 
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 {
28  public:
29   static RTPReceiverStrategy* CreateVideoStrategy(RtpData* data_callback);
30   static RTPReceiverStrategy* CreateAudioStrategy(
31       RtpData* data_callback,
32       RtpAudioFeedback* incoming_messages_callback);
33 
~RTPReceiverStrategy()34   virtual ~RTPReceiverStrategy() {}
35 
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,
44                                  bool is_red,
45                                  const uint8_t* payload,
46                                  size_t payload_length,
47                                  int64_t timestamp_ms,
48                                  bool is_first_packet) = 0;
49 
50   virtual TelephoneEventHandler* GetTelephoneEventHandler() = 0;
51 
52   // Retrieves the last known applicable frequency.
53   virtual int GetPayloadTypeFrequency() const = 0;
54 
55   // Computes the current dead-or-alive state.
56   virtual RTPAliveType ProcessDeadOrAlive(
57       uint16_t last_payload_length) const = 0;
58 
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;
62 
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],
67       int8_t payloadType,
68       uint32_t frequency) = 0;
69 
70   // Invokes the OnInitializeDecoder callback in a media-specific way.
71   virtual int32_t InvokeOnInitializeDecoder(
72       RtpFeedback* callback,
73       int8_t payload_type,
74       const char payload_name[RTP_PAYLOAD_NAME_SIZE],
75       const PayloadUnion& specific_payload) const = 0;
76 
77   // Checks if the payload type has changed, and returns whether we should
78   // reset statistics and/or discard this packet.
79   virtual void CheckPayloadChanged(int8_t payload_type,
80                                    PayloadUnion* specific_payload,
81                                    bool* should_discard_changes);
82 
83   virtual int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const;
84 
85   // Stores / retrieves the last media specific payload for later reference.
86   void GetLastMediaSpecificPayload(PayloadUnion* payload) const;
87   void SetLastMediaSpecificPayload(const PayloadUnion& payload);
88 
89  protected:
90   // The data callback is where we should send received payload data.
91   // See ParseRtpPacket. This class does not claim ownership of the callback.
92   // Implementations must NOT hold any critical sections while calling the
93   // callback.
94   //
95   // Note: Implementations may call the callback for other reasons than calls
96   // to ParseRtpPacket, for instance if the implementation somehow recovers a
97   // packet.
98   explicit RTPReceiverStrategy(RtpData* data_callback);
99 
100   rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
101   PayloadUnion last_payload_;
102   RtpData* data_callback_;
103 };
104 }  // namespace webrtc
105 
106 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
107