Home | History | Annotate | Download | only in video_engine
      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 RemoteNtpTimeEstimator;
     29 class ReceiveStatistics;
     30 class RemoteBitrateEstimator;
     31 class RtpDump;
     32 class RtpHeaderParser;
     33 class RTPPayloadRegistry;
     34 class RtpReceiver;
     35 class RtpRtcp;
     36 class VideoCodingModule;
     37 struct ReceiveBandwidthEstimatorStats;
     38 
     39 class ViEReceiver : public RtpData {
     40  public:
     41   ViEReceiver(const int32_t channel_id, VideoCodingModule* module_vcm,
     42               RemoteBitrateEstimator* remote_bitrate_estimator,
     43               RtpFeedback* rtp_feedback);
     44   ~ViEReceiver();
     45 
     46   bool SetReceiveCodec(const VideoCodec& video_codec);
     47   bool RegisterPayload(const VideoCodec& video_codec);
     48 
     49   void SetNackStatus(bool enable, int max_nack_reordering_threshold);
     50   void SetRtxPayloadType(int payload_type);
     51   void SetRtxSsrc(uint32_t ssrc);
     52 
     53   uint32_t GetRemoteSsrc() const;
     54   int GetCsrcs(uint32_t* csrcs) const;
     55 
     56   void SetRtpRtcpModule(RtpRtcp* module);
     57 
     58   RtpReceiver* GetRtpReceiver() const;
     59 
     60   void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
     61 
     62   bool SetReceiveTimestampOffsetStatus(bool enable, int id);
     63   bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
     64 
     65   void StartReceive();
     66   void StopReceive();
     67 
     68   int StartRTPDump(const char file_nameUTF8[1024]);
     69   int StopRTPDump();
     70 
     71   // Receives packets from external transport.
     72   int ReceivedRTPPacket(const void* rtp_packet, int rtp_packet_length,
     73                         const PacketTime& packet_time);
     74   int ReceivedRTCPPacket(const void* rtcp_packet, int rtcp_packet_length);
     75 
     76   // Implements RtpData.
     77   virtual int32_t OnReceivedPayloadData(
     78       const uint8_t* payload_data,
     79       const uint16_t payload_size,
     80       const WebRtcRTPHeader* rtp_header) OVERRIDE;
     81   virtual bool OnRecoveredPacket(const uint8_t* packet,
     82                                  int packet_length) OVERRIDE;
     83 
     84   void GetReceiveBandwidthEstimatorStats(
     85       ReceiveBandwidthEstimatorStats* output) const;
     86 
     87   ReceiveStatistics* GetReceiveStatistics() const;
     88 
     89   void ReceivedBWEPacket(int64_t arrival_time_ms, int payload_size,
     90                          const RTPHeader& header);
     91  private:
     92   int InsertRTPPacket(const uint8_t* rtp_packet, int rtp_packet_length,
     93                       const PacketTime& packet_time);
     94   bool ReceivePacket(const uint8_t* packet,
     95                      int packet_length,
     96                      const RTPHeader& header,
     97                      bool in_order);
     98   // Parses and handles for instance RTX and RED headers.
     99   // This function assumes that it's being called from only one thread.
    100   bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
    101                                          int packet_length,
    102                                          const RTPHeader& header);
    103   int InsertRTCPPacket(const uint8_t* rtcp_packet, int rtcp_packet_length);
    104   bool IsPacketInOrder(const RTPHeader& header) const;
    105   bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
    106 
    107   scoped_ptr<CriticalSectionWrapper> receive_cs_;
    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   scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
    119 
    120   RtpDump* rtp_dump_;
    121   bool receiving_;
    122   uint8_t restored_packet_[kViEMaxMtu];
    123   bool restored_packet_in_use_;
    124   bool receiving_ast_enabled_;
    125 };
    126 
    127 }  // namespace webrt
    128 
    129 #endif  // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
    130