blob: af1868e9f5e44febaedbe3f2f5788a08234ac9c5 [file] [log] [blame]
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
12#define MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/rtp_rtcp/include/rtp_rtcp.h"
15#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16#include "modules/rtp_rtcp/source/rtp_utility.h"
17#include "rtc_base/criticalsection.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "typedefs.h" // NOLINT(build/include)
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000019
20namespace webrtc {
21
magjed56124bd2016-11-24 09:34:46 -080022struct CodecInst;
23
wu@webrtc.org822fbd82013-08-15 23:38:54 +000024class TelephoneEventHandler;
25
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000026// This strategy deals with media-specific RTP packet processing.
27// This class is not thread-safe and must be protected by its caller.
28class RTPReceiverStrategy {
29 public:
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +000030 static RTPReceiverStrategy* CreateVideoStrategy(RtpData* data_callback);
solenberg1d031392016-03-30 02:42:32 -070031 static RTPReceiverStrategy* CreateAudioStrategy(RtpData* data_callback);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000032
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000033 virtual ~RTPReceiverStrategy() {}
stefan@webrtc.org66b2e5c2013-07-05 14:30:48 +000034
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000035 // Parses the RTP packet and calls the data callback with the payload data.
36 // Implementations are encouraged to use the provided packet buffer and RTP
37 // header as arguments to the callback; implementations are also allowed to
38 // make changes in the data as necessary. The specific_payload argument
Niels Möllerbbf389c2017-09-26 14:05:05 +020039 // provides audio or video-specific data.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000040 virtual int32_t ParseRtpPacket(WebRtcRTPHeader* rtp_header,
41 const PayloadUnion& specific_payload,
42 bool is_red,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000043 const uint8_t* payload,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000044 size_t payload_length,
Niels Möllerbbf389c2017-09-26 14:05:05 +020045 int64_t timestamp_ms) = 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000046
danilchap799a9d02016-09-22 03:36:27 -070047 virtual TelephoneEventHandler* GetTelephoneEventHandler() = 0;
48
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000049 // Computes the current dead-or-alive state.
50 virtual RTPAliveType ProcessDeadOrAlive(
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051 uint16_t last_payload_length) const = 0;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000052
53 // Returns true if we should report CSRC changes for this payload type.
54 // TODO(phoglund): should move out of here along with other payload stuff.
55 virtual bool ShouldReportCsrcChanges(uint8_t payload_type) const = 0;
56
magjed56124bd2016-11-24 09:34:46 -080057 // Notifies the strategy that we have created a new non-RED audio payload type
58 // in the payload registry.
59 virtual int32_t OnNewPayloadTypeCreated(const CodecInst& audio_codec) = 0;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000060
61 // Invokes the OnInitializeDecoder callback in a media-specific way.
62 virtual int32_t InvokeOnInitializeDecoder(
wu@webrtc.org822fbd82013-08-15 23:38:54 +000063 RtpFeedback* callback,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000064 int8_t payload_type,
65 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
66 const PayloadUnion& specific_payload) const = 0;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000067
68 // Checks if the payload type has changed, and returns whether we should
69 // reset statistics and/or discard this packet.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000070 virtual void CheckPayloadChanged(int8_t payload_type,
71 PayloadUnion* specific_payload,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000072 bool* should_discard_changes);
73
74 virtual int Energy(uint8_t array_of_energy[kRtpCsrcSize]) const;
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000075
76 // Stores / retrieves the last media specific payload for later reference.
wu@webrtc.org822fbd82013-08-15 23:38:54 +000077 void GetLastMediaSpecificPayload(PayloadUnion* payload) const;
78 void SetLastMediaSpecificPayload(const PayloadUnion& payload);
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +000079
80 protected:
wu@webrtc.org822fbd82013-08-15 23:38:54 +000081 // The data callback is where we should send received payload data.
82 // See ParseRtpPacket. This class does not claim ownership of the callback.
83 // Implementations must NOT hold any critical sections while calling the
84 // callback.
85 //
86 // Note: Implementations may call the callback for other reasons than calls
87 // to ParseRtpPacket, for instance if the implementation somehow recovers a
88 // packet.
danilchap6db6cdc2015-12-15 02:54:47 -080089 explicit RTPReceiverStrategy(RtpData* data_callback);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000090
danilchap7c9426c2016-04-14 03:05:31 -070091 rtc::CriticalSection crit_sect_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000092 PayloadUnion last_payload_;
phoglund@webrtc.orga22a9bd2013-01-14 10:01:55 +000093 RtpData* data_callback_;
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000094};
phoglund@webrtc.org07bf43c2012-12-18 15:40:53 +000095} // namespace webrtc
96
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_STRATEGY_H_