• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SOURCE_RTP_RECEIVER_IMPL_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_
13 
14 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h"
15 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.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"
20 
21 namespace webrtc {
22 
23 class RtpReceiverImpl : public RtpReceiver {
24  public:
25   // Callbacks passed in here may not be NULL (use Null Object callbacks if you
26   // want callbacks to do nothing). This class takes ownership of the media
27   // receiver but nothing else.
28   RtpReceiverImpl(int32_t id,
29                   Clock* clock,
30                   RtpAudioFeedback* incoming_audio_messages_callback,
31                   RtpFeedback* incoming_messages_callback,
32                   RTPPayloadRegistry* rtp_payload_registry,
33                   RTPReceiverStrategy* rtp_media_receiver);
34 
35   virtual ~RtpReceiverImpl();
36 
37   RTPReceiverStrategy* GetMediaReceiver() const;
38 
39   int32_t RegisterReceivePayload(
40       const char payload_name[RTP_PAYLOAD_NAME_SIZE],
41       const int8_t payload_type,
42       const uint32_t frequency,
43       const uint8_t channels,
44       const uint32_t rate);
45 
46   int32_t DeRegisterReceivePayload(const int8_t payload_type);
47 
48   bool IncomingRtpPacket(
49       const RTPHeader& rtp_header,
50       const uint8_t* payload,
51       int payload_length,
52       PayloadUnion payload_specific,
53       bool in_order);
54 
55   NACKMethod NACK() const;
56 
57   // Turn negative acknowledgement requests on/off.
58   void SetNACKStatus(const NACKMethod method);
59 
60   // Returns the last received timestamp.
61   bool Timestamp(uint32_t* timestamp) const;
62   bool LastReceivedTimeMs(int64_t* receive_time_ms) const;
63 
64   uint32_t SSRC() const;
65 
66   int32_t CSRCs(uint32_t array_of_csrc[kRtpCsrcSize]) const;
67 
68   int32_t Energy(uint8_t array_of_energy[kRtpCsrcSize]) const;
69 
70   // RTX.
71   void SetRTXStatus(bool enable, uint32_t ssrc);
72 
73   void RTXStatus(bool* enable, uint32_t* ssrc, int* payload_type) const;
74 
75   void SetRtxPayloadType(int payload_type);
76 
77   TelephoneEventHandler* GetTelephoneEventHandler();
78 
79  private:
80   bool HaveReceivedFrame() const;
81 
82   RtpVideoCodecTypes VideoCodecType() const;
83 
84   void CheckSSRCChanged(const RTPHeader& rtp_header);
85   void CheckCSRC(const WebRtcRTPHeader& rtp_header);
86   int32_t CheckPayloadChanged(const RTPHeader& rtp_header,
87                               const int8_t first_payload_byte,
88                               bool& is_red,
89                               PayloadUnion* payload,
90                               bool* should_reset_statistics);
91 
92   Clock* clock_;
93   RTPPayloadRegistry* rtp_payload_registry_;
94   scoped_ptr<RTPReceiverStrategy> rtp_media_receiver_;
95 
96   int32_t id_;
97 
98   RtpFeedback* cb_rtp_feedback_;
99 
100   scoped_ptr<CriticalSectionWrapper> critical_section_rtp_receiver_;
101   int64_t last_receive_time_;
102   uint16_t last_received_payload_length_;
103 
104   // SSRCs.
105   uint32_t ssrc_;
106   uint8_t num_csrcs_;
107   uint32_t current_remote_csrc_[kRtpCsrcSize];
108 
109   uint32_t last_received_timestamp_;
110   int64_t last_received_frame_time_ms_;
111   uint16_t last_received_sequence_number_;
112 
113   NACKMethod nack_method_;
114 };
115 }  // namespace webrtc
116 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_
117