Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / media / cast / net / cast_transport_sender.h
blobfc88a5c350b43242040c920388c5b16ebe986790
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"
33 namespace base {
34 class DictionaryValue;
35 } // namespace base
37 namespace net {
38 class NetLog;
39 } // namespace net
41 namespace media {
42 namespace cast {
43 struct RtpReceiverStatistics;
44 struct RtcpTimeData;
46 // Following the initialization of either audio or video an initialization
47 // status will be sent via this callback.
48 typedef base::Callback<void(CastTransportStatus status)>
49 CastTransportStatusCallback;
51 typedef base::Callback<void(const std::vector<PacketEvent>&,
52 const std::vector<FrameEvent>&)>
53 BulkRawEventsCallback;
55 // The application should only trigger this class from the transport thread.
56 class CastTransportSender : public base::NonThreadSafe {
57 public:
58 static scoped_ptr<CastTransportSender> Create(
59 net::NetLog* net_log,
60 base::TickClock* clock,
61 const net::IPEndPoint& local_end_point,
62 const net::IPEndPoint& remote_end_point,
63 scoped_ptr<base::DictionaryValue> options,
64 const CastTransportStatusCallback& status_callback,
65 const BulkRawEventsCallback& raw_events_callback,
66 base::TimeDelta raw_events_callback_interval,
67 const PacketReceiverCallback& packet_callback,
68 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
70 virtual ~CastTransportSender() {}
72 // Audio/Video initialization.
73 // Encoded frames cannot be transmitted until the relevant initialize method
74 // is called.
75 virtual void InitializeAudio(const CastTransportRtpConfig& config,
76 const RtcpCastMessageCallback& cast_message_cb,
77 const RtcpRttCallback& rtt_cb) = 0;
78 virtual void InitializeVideo(const CastTransportRtpConfig& config,
79 const RtcpCastMessageCallback& cast_message_cb,
80 const RtcpRttCallback& rtt_cb) = 0;
82 // Encrypt, packetize and transmit |frame|. |ssrc| must refer to a
83 // a channel already established with InitializeAudio / InitializeVideo.
84 virtual void InsertFrame(uint32 ssrc, const EncodedFrame& frame) = 0;
86 // Sends a RTCP sender report to the receiver.
87 // |ssrc| is the SSRC for this report.
88 // |current_time| is the current time reported by a tick clock.
89 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
90 virtual void SendSenderReport(
91 uint32 ssrc,
92 base::TimeTicks current_time,
93 uint32 current_time_as_rtp_timestamp) = 0;
95 // Cancels sending packets for the frames in the set.
96 // |ssrc| is the SSRC for the stream.
97 // |frame_ids| contains the IDs of the frames that will be cancelled.
98 virtual void CancelSendingFrames(uint32 ssrc,
99 const std::vector<uint32>& frame_ids) = 0;
101 // Resends a frame or part of a frame to kickstart. This is used when the
102 // stream appears to be stalled.
103 virtual void ResendFrameForKickstart(uint32 ssrc, uint32 frame_id) = 0;
105 // Returns a callback for receiving packets for testing purposes.
106 virtual PacketReceiverCallback PacketReceiverForTesting();
108 // The following functions are needed for receving.
110 // Add a valid SSRC. This is used to verify that incoming packets
111 // come from the right sender. Without valid SSRCs, the return address cannot
112 // be automatically established.
113 virtual void AddValidSsrc(uint32 ssrc) = 0;
115 // Send an RTCP message from receiver to sender.
116 virtual void SendRtcpFromRtpReceiver(
117 uint32 ssrc,
118 uint32 sender_ssrc,
119 const RtcpTimeData& time_data,
120 const RtcpCastMessage* cast_message,
121 base::TimeDelta target_delay,
122 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events,
123 const RtpReceiverStatistics* rtp_receiver_statistics) = 0;
126 } // namespace cast
127 } // namespace media
129 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_H_