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