Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / video_engine / vie_receiver.h
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_VIDEO_ENGINE_VIE_RECEIVER_H_
12 #define WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
13
14 #include <list>
15
16 #include "webrtc/engine_configurations.h"
17 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
18 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
19 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
20 #include "webrtc/typedefs.h"
21 #include "webrtc/video_engine/include/vie_network.h"
22 #include "webrtc/video_engine/vie_defines.h"
23
24 namespace webrtc {
25
26 class CriticalSectionWrapper;
27 class FecReceiver;
28 class ReceiveStatistics;
29 class RemoteBitrateEstimator;
30 class RtpDump;
31 class RtpHeaderParser;
32 class RTPPayloadRegistry;
33 class RtpReceiver;
34 class RtpRtcp;
35 class VideoCodingModule;
36 struct ReceiveBandwidthEstimatorStats;
37
38 class ViEReceiver : public RtpData {
39  public:
40   ViEReceiver(const int32_t channel_id, VideoCodingModule* module_vcm,
41               RemoteBitrateEstimator* remote_bitrate_estimator,
42               RtpFeedback* rtp_feedback);
43   ~ViEReceiver();
44
45   bool SetReceiveCodec(const VideoCodec& video_codec);
46   bool RegisterPayload(const VideoCodec& video_codec);
47
48   void SetNackStatus(bool enable, int max_nack_reordering_threshold);
49   void SetRtxStatus(bool enable, uint32_t ssrc);
50   void SetRtxPayloadType(uint32_t payload_type);
51
52   uint32_t GetRemoteSsrc() const;
53   int GetCsrcs(uint32_t* csrcs) const;
54
55   void SetRtpRtcpModule(RtpRtcp* module);
56
57   RtpReceiver* GetRtpReceiver() const;
58
59   void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
60
61   bool SetReceiveTimestampOffsetStatus(bool enable, int id);
62   bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
63
64   void StartReceive();
65   void StopReceive();
66
67   int StartRTPDump(const char file_nameUTF8[1024]);
68   int StopRTPDump();
69
70   // Receives packets from external transport.
71   int ReceivedRTPPacket(const void* rtp_packet, int rtp_packet_length,
72                         const PacketTime& packet_time);
73   int ReceivedRTCPPacket(const void* rtcp_packet, int rtcp_packet_length);
74   virtual bool OnRecoveredPacket(const uint8_t* packet,
75                                  int packet_length) OVERRIDE;
76
77   // Implements RtpData.
78   virtual int32_t OnReceivedPayloadData(
79       const uint8_t* payload_data,
80       const uint16_t payload_size,
81       const WebRtcRTPHeader* rtp_header);
82
83   void EstimatedReceiveBandwidth(unsigned int* available_bandwidth) const;
84
85   void GetReceiveBandwidthEstimatorStats(
86       ReceiveBandwidthEstimatorStats* output) const;
87
88   ReceiveStatistics* GetReceiveStatistics() const;
89
90  private:
91   int InsertRTPPacket(const uint8_t* rtp_packet, int rtp_packet_length,
92                       const PacketTime& packet_time);
93   bool ReceivePacket(const uint8_t* packet,
94                      int packet_length,
95                      const RTPHeader& header,
96                      bool in_order);
97   // Parses and handles for instance RTX and RED headers.
98   // This function assumes that it's being called from only one thread.
99   bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
100                                          int packet_length,
101                                          const RTPHeader& header);
102   int InsertRTCPPacket(const uint8_t* rtcp_packet, int rtcp_packet_length);
103   bool IsPacketInOrder(const RTPHeader& header) const;
104   bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
105
106   scoped_ptr<CriticalSectionWrapper> receive_cs_;
107   const int32_t channel_id_;
108   scoped_ptr<RtpHeaderParser> rtp_header_parser_;
109   scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
110   scoped_ptr<RtpReceiver> rtp_receiver_;
111   scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
112   scoped_ptr<FecReceiver> fec_receiver_;
113   RtpRtcp* rtp_rtcp_;
114   std::list<RtpRtcp*> rtp_rtcp_simulcast_;
115   VideoCodingModule* vcm_;
116   RemoteBitrateEstimator* remote_bitrate_estimator_;
117
118   RtpDump* rtp_dump_;
119   bool receiving_;
120   uint8_t restored_packet_[kViEMaxMtu];
121   bool restored_packet_in_use_;
122 };
123
124 }  // namespace webrt
125
126 #endif  // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_