1 // Copyright 2014 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.
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).
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).
14 // Destruction: The CastTransportSender is assumed to be valid as long as the
15 // CastSender is alive. Therefore the CastSender should be destructed before the
16 // CastTransportSender.
18 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_
19 #define MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_
21 #include "base/basictypes.h"
22 #include "base/callback.h"
23 #include "base/single_thread_task_runner.h"
24 #include "base/threading/non_thread_safe.h"
25 #include "base/time/tick_clock.h"
26 #include "media/cast/logging/logging_defines.h"
27 #include "media/cast/net/cast_transport_config.h"
28 #include "media/cast/net/cast_transport_defines.h"
29 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h"
30 #include "media/cast/net/rtcp/rtcp_defines.h"
31 #include "net/base/ip_endpoint.h"
40 // Following the initialization of either audio or video an initialization
41 // status will be sent via this callback.
42 typedef base::Callback<void(CastTransportStatus status)>
43 CastTransportStatusCallback;
45 typedef base::Callback<void(const std::vector<PacketEvent>&,
46 const std::vector<FrameEvent>&)>
47 BulkRawEventsCallback;
49 // The application should only trigger this class from the transport thread.
50 class CastTransportSender : public base::NonThreadSafe {
52 static scoped_ptr<CastTransportSender> Create(
54 base::TickClock* clock,
55 const net::IPEndPoint& remote_end_point,
56 const CastTransportStatusCallback& status_callback,
57 const BulkRawEventsCallback& raw_events_callback,
58 base::TimeDelta raw_events_callback_interval,
59 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
61 virtual ~CastTransportSender() {}
63 // Audio/Video initialization.
64 // Encoded frames cannot be transmitted until the relevant initialize method
66 virtual void InitializeAudio(const CastTransportRtpConfig& config,
67 const RtcpCastMessageCallback& cast_message_cb,
68 const RtcpRttCallback& rtt_cb) = 0;
69 virtual void InitializeVideo(const CastTransportRtpConfig& config,
70 const RtcpCastMessageCallback& cast_message_cb,
71 const RtcpRttCallback& rtt_cb) = 0;
73 // The following two functions handle the encoded media frames (audio and
74 // video) to be processed.
75 // Frames will be encrypted, packetized and transmitted to the network.
76 virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) = 0;
77 virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) = 0;
79 // Sends a RTCP sender report to the receiver.
80 // |ssrc| is the SSRC for this report.
81 // |current_time| is the current time reported by a tick clock.
82 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
83 virtual void SendSenderReport(
85 base::TimeTicks current_time,
86 uint32 current_time_as_rtp_timestamp) = 0;
88 // Retransmission request.
89 // |missing_packets| includes the list of frames and packets in each
90 // frame to be re-transmitted.
91 // If |cancel_rtx_if_not_in_list| is used as an optimization to cancel
92 // pending re-transmission requests of packets not listed in
93 // |missing_packets|. If the requested packet(s) were sent recently
94 // (how long is specified by |dedupe_window|) then this re-transmit
96 virtual void ResendPackets(
98 const MissingFramesAndPacketsMap& missing_packets,
99 bool cancel_rtx_if_not_in_list,
100 base::TimeDelta dedupe_window) = 0;
102 // Returns a callback for receiving packets for testing purposes.
103 virtual PacketReceiverCallback PacketReceiverForTesting();
109 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_