Home | History | Annotate | Download | only in transport
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // This is the main interface for the cast transport sender.  It accepts encoded
      6 // frames (both audio and video), encrypts their encoded data, packetizes them
      7 // and feeds them into a transport (e.g., UDP).
      8 
      9 // Construction of the Cast Sender and the Cast Transport Sender should be done
     10 // in the following order:
     11 // 1. Create CastTransportSender.
     12 // 2. Create CastSender (accepts CastTransportSender as an input).
     13 // 3. Call CastTransportSender::SetPacketReceiver to ensure that the packets
     14 //    received by the CastTransportSender will be sent to the CastSender.
     15 // Steps 3 can be done interchangeably.
     16 
     17 // Destruction: The CastTransportSender is assumed to be valid as long as the
     18 // CastSender is alive. Therefore the CastSender should be destructed before the
     19 // CastTransportSender.
     20 // This also works when the CastSender acts as a receiver for the RTCP packets
     21 // due to the weak pointers in the ReceivedPacket method in cast_sender_impl.cc.
     22 
     23 #ifndef MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_SENDER_H_
     24 #define MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_SENDER_H_
     25 
     26 #include "base/basictypes.h"
     27 #include "base/callback.h"
     28 #include "base/single_thread_task_runner.h"
     29 #include "base/threading/non_thread_safe.h"
     30 #include "base/time/tick_clock.h"
     31 #include "media/cast/logging/logging_defines.h"
     32 #include "media/cast/transport/cast_transport_config.h"
     33 #include "media/cast/transport/cast_transport_defines.h"
     34 
     35 namespace net {
     36 class NetLog;
     37 }  // namespace net
     38 
     39 namespace media {
     40 namespace cast {
     41 namespace transport {
     42 
     43 // Following the initialization of either audio or video an initialization
     44 // status will be sent via this callback.
     45 typedef base::Callback<void(CastTransportStatus status)>
     46     CastTransportStatusCallback;
     47 
     48 typedef base::Callback<void(const std::vector<PacketEvent>&)>
     49     BulkRawEventsCallback;
     50 
     51 // The application should only trigger this class from the transport thread.
     52 class CastTransportSender : public base::NonThreadSafe {
     53  public:
     54   static scoped_ptr<CastTransportSender> Create(
     55       net::NetLog* net_log,
     56       base::TickClock* clock,
     57       const net::IPEndPoint& remote_end_point,
     58       const CastTransportStatusCallback& status_callback,
     59       const BulkRawEventsCallback& raw_events_callback,
     60       base::TimeDelta raw_events_callback_interval,
     61       const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
     62 
     63   virtual ~CastTransportSender() {}
     64 
     65   // Audio/Video initialization.
     66   // Encoded frames cannot be transmitted until the relevant initialize method
     67   // is called. Usually called by CastSender.
     68   virtual void InitializeAudio(const CastTransportAudioConfig& config) = 0;
     69 
     70   virtual void InitializeVideo(const CastTransportVideoConfig& config) = 0;
     71 
     72   // Sets the Cast packet receiver. Should be called after creation on the
     73   // Cast sender. Packets won't be received until this function is called.
     74   virtual void SetPacketReceiver(
     75       const PacketReceiverCallback& packet_receiver) = 0;
     76 
     77   // The following two functions handle the encoded media frames (audio and
     78   // video) to be processed.
     79   // Frames will be encrypted, packetized and transmitted to the network.
     80   virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) = 0;
     81   virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) = 0;
     82 
     83   // Builds an RTCP packet and sends it to the network.
     84   // |ntp_seconds|, |ntp_fraction| and |rtp_timestamp| are used in the
     85   // RTCP Sender Report.
     86   virtual void SendRtcpFromRtpSender(uint32 packet_type_flags,
     87                                      uint32 ntp_seconds,
     88                                      uint32 ntp_fraction,
     89                                      uint32 rtp_timestamp,
     90                                      const RtcpDlrrReportBlock& dlrr,
     91                                      uint32 sending_ssrc,
     92                                      const std::string& c_name) = 0;
     93 
     94   // Retransmission request.
     95   // |missing_packets| includes the list of frames and packets in each
     96   // frame to be re-transmitted.
     97   // If |cancel_rtx_if_not_in_list| is used as an optimization to cancel
     98   // pending re-transmission requests of packets not listed in
     99   // |missing_packets|. If the requested packet(s) were sent recently
    100   // (how long is specified by |dedupe_window|) then this re-transmit
    101   // will be ignored.
    102   virtual void ResendPackets(
    103       bool is_audio,
    104       const MissingFramesAndPacketsMap& missing_packets,
    105       bool cancel_rtx_if_not_in_list,
    106       base::TimeDelta dedupe_window) = 0;
    107 };
    108 
    109 }  // namespace transport
    110 }  // namespace cast
    111 }  // namespace media
    112 
    113 #endif  // MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_SENDER_H_
    114