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.
5 // This is the main interface for the cast transport sender. The cast sender
6 // handles the cast pipeline from encoded frames (both audio and video), to
7 // encryption, packetization and transport.
8 // All configurations are done at creation.
10 // Construction of the Cast Sender and the Cast Transport Sender should be done
11 // in the following order:
12 // 1. Create CastTransportSender.
13 // 2. Create CastSender (accepts CastTransportSender as an input).
14 // 3. Call CastTransportSender::SetPacketReceiver to ensure that the packets
15 // received by the CastTransportSender will be sent to the CastSender.
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.
23 #ifndef MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_SENDER_H_
24 #define MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_SENDER_H_
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/transport/cast_transport_config.h"
32 #include "media/cast/transport/cast_transport_defines.h"
38 typedef base::Callback<void(CastTransportStatus status)>
39 CastTransportStatusCallback;
41 typedef base::Callback<void(const RtcpSenderInfo& sender_info,
42 base::TimeTicks time_sent,
43 uint32 rtp_timestamp)> CastTransportRtpStatistics;
45 // The application should only trigger this class from the transport thread.
46 class CastTransportSender : public base::NonThreadSafe {
48 static CastTransportSender* CreateCastTransportSender(
49 base::TickClock* clock,
50 const CastTransportConfig& config,
51 const CastTransportStatusCallback& status_callback,
52 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
54 virtual ~CastTransportSender() {}
56 // Sets the Cast packet receiver. Should be called after creation on the
57 // Cast sender. Packets won't be received until this function is called.
58 virtual void SetPacketReceiver(
59 const PacketReceiverCallback& packet_receiver) = 0;
61 // The following two functions handle the encoded media frames (audio and
62 // video) to be processed.
63 // Frames will be encrypted, packetized and transmitted to the network.
64 virtual void InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame,
65 const base::TimeTicks& recorded_time) = 0;
67 virtual void InsertCodedVideoFrame(const EncodedVideoFrame* video_frame,
68 const base::TimeTicks& capture_time) = 0;
70 // Builds an RTCP packet and sends it to the network.
71 virtual void SendRtcpFromRtpSender(uint32 packet_type_flags,
72 const RtcpSenderInfo& sender_info,
73 const RtcpDlrrReportBlock& dlrr,
74 const RtcpSenderLogMessage& sender_log,
76 const std::string& c_name) = 0;
78 // Retransmission request.
79 virtual void ResendPackets(
81 const MissingFramesAndPacketsMap& missing_packets) = 0;
83 // Audio/Video RTP statistics.
84 // RTP statistics will be returned on a regular interval on the designated
86 virtual void SubscribeAudioRtpStatsCallback(
87 const CastTransportRtpStatistics& callback) = 0;
89 virtual void SubscribeVideoRtpStatsCallback(
90 const CastTransportRtpStatistics& callback) = 0;
93 } // namespace transport
97 #endif // MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_SENDER_H_