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