Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: media/cast/net/cast_transport_sender_impl.h

Issue 1515023002: Simplify interface for media/cast: CastTransportSenderImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add changes on tests. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 class maintains a send transport for audio and video in a Cast 5 // This class maintains a send transport for audio and video in a Cast
6 // Streaming session. 6 // Streaming session.
7 // Audio, video frames and RTCP messages are submitted to this object 7 // Audio, video frames and RTCP messages are submitted to this object
8 // and then packetized and paced to the underlying UDP socket. 8 // and then packetized and paced to the underlying UDP socket.
9 // 9 //
10 // The hierarchy of send transport in a Cast Streaming session: 10 // The hierarchy of send transport in a Cast Streaming session:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "media/cast/net/rtp/rtp_sender.h" 47 #include "media/cast/net/rtp/rtp_sender.h"
48 #include "net/base/network_interfaces.h" 48 #include "net/base/network_interfaces.h"
49 49
50 namespace media { 50 namespace media {
51 namespace cast { 51 namespace cast {
52 52
53 class UdpTransport; 53 class UdpTransport;
54 54
55 class CastTransportSenderImpl : public CastTransportSender { 55 class CastTransportSenderImpl : public CastTransportSender {
56 public: 56 public:
57 // |external_transport| is only used for testing.
58 // |raw_events_callback|: Raw events will be returned on this callback
59 // which will be invoked every |raw_events_callback_interval|.
60 // This can be a null callback, i.e. if user is not interested in raw events.
61 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if
62 // |raw_events_callback| is a null callback.
63 // |options| contains optional settings for the transport, possible
64 // keys are:
65 // "DSCP" (value ignored)
66 // - Turns DSCP on (higher IP Precedence and Type of Service).
67 // "disable_non_blocking_io" (value ignored)
68 // - Windows only. Turns off non-blocking IO for the socket.
69 // Note: Non-blocking IO is, by default, enabled on all platforms.
70 // "pacer_target_burst_size": int
71 // - Specifies how many packets to send per 10 ms ideally.
72 // "pacer_max_burst_size": int
73 // - Specifies how many pakcets to send per 10 ms, maximum.
74 // "send_buffer_min_size": int
75 // - Specifies the minimum socket send buffer size.
76 // "disable_wifi_scan" (value ignored)
77 // - Disable wifi scans while streaming.
78 // "media_streaming_mode" (value ignored)
79 // - Turn media streaming mode on.
80 // Note, these options may be ignored on some platforms.
81 // TODO(hubbe): Too many callbacks, replace with an interface.
82 // http://crbug.com/557477
83 CastTransportSenderImpl( 57 CastTransportSenderImpl(
84 net::NetLog* net_log, 58 base::TickClock* clock, // Owned by the caller.
85 base::TickClock* clock, 59 base::TimeDelta logging_flush_interval,
86 const net::IPEndPoint& local_end_point, 60 scoped_ptr<Client> client,
87 const net::IPEndPoint& remote_end_point, 61 scoped_ptr<PacketSender> transport,
88 scoped_ptr<base::DictionaryValue> options, 62 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
89 const CastTransportStatusCallback& status_callback,
90 const BulkRawEventsCallback& raw_events_callback,
91 base::TimeDelta raw_events_callback_interval,
92 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner,
93 const PacketReceiverCallback& packet_callback,
94 PacketSender* external_transport);
95 63
96 ~CastTransportSenderImpl() final; 64 ~CastTransportSenderImpl() final;
97 65
98 // CastTransportSender implementation. 66 // CastTransportSender implementation.
99 void InitializeAudio(const CastTransportRtpConfig& config, 67 void InitializeAudio(const CastTransportRtpConfig& config,
100 const RtcpCastMessageCallback& cast_message_cb, 68 const RtcpCastMessageCallback& cast_message_cb,
101 const RtcpRttCallback& rtt_cb) final; 69 const RtcpRttCallback& rtt_cb) final;
102 void InitializeVideo(const CastTransportRtpConfig& config, 70 void InitializeVideo(const CastTransportRtpConfig& config,
103 const RtcpCastMessageCallback& cast_message_cb, 71 const RtcpCastMessageCallback& cast_message_cb,
104 const RtcpRttCallback& rtt_cb) final; 72 const RtcpRttCallback& rtt_cb) final;
105 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final; 73 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final;
106 74
107 void SendSenderReport(uint32_t ssrc, 75 void SendSenderReport(uint32_t ssrc,
108 base::TimeTicks current_time, 76 base::TimeTicks current_time,
109 RtpTimeTicks current_time_as_rtp_timestamp) final; 77 RtpTimeTicks current_time_as_rtp_timestamp) final;
110 78
111 void CancelSendingFrames(uint32_t ssrc, 79 void CancelSendingFrames(uint32_t ssrc,
112 const std::vector<uint32_t>& frame_ids) final; 80 const std::vector<uint32_t>& frame_ids) final;
113 81
114 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final; 82 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final;
115 83
116 PacketReceiverCallback PacketReceiverForTesting() final; 84 PacketReceiverCallback PacketReceiverForTesting() final;
117 85
86 void SetOptions(const base::DictionaryValue& options) final;
87
118 // CastTransportReceiver implementation. 88 // CastTransportReceiver implementation.
119 void AddValidSsrc(uint32_t ssrc) final; 89 void AddValidSsrc(uint32_t ssrc) final;
120 90
121 void SendRtcpFromRtpReceiver( 91 void SendRtcpFromRtpReceiver(
122 uint32_t ssrc, 92 uint32_t ssrc,
123 uint32_t sender_ssrc, 93 uint32_t sender_ssrc,
124 const RtcpTimeData& time_data, 94 const RtcpTimeData& time_data,
125 const RtcpCastMessage* cast_message, 95 const RtcpCastMessage* cast_message,
126 base::TimeDelta target_delay, 96 base::TimeDelta target_delay,
127 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, 97 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events,
128 const RtpReceiverStatistics* rtp_receiver_statistics) final; 98 const RtpReceiverStatistics* rtp_receiver_statistics) final;
129 99
130 private: 100 private:
131 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits); 101 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits);
132 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits); 102 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits);
133 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart); 103 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart);
134 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, 104 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest,
135 DedupRetransmissionWithAudio); 105 DedupRetransmissionWithAudio);
136 106
137 // Resend packets for the stream identified by |ssrc|. 107 // Resend packets for the stream identified by |ssrc|.
138 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the 108 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the
139 // frames but not in the list will be dropped. 109 // frames but not in the list will be dropped.
140 // See PacedSender::ResendPackets() to see how |dedup_info| works. 110 // See PacedSender::ResendPackets() to see how |dedup_info| works.
141 void ResendPackets(uint32_t ssrc, 111 void ResendPackets(uint32_t ssrc,
142 const MissingFramesAndPacketsMap& missing_packets, 112 const MissingFramesAndPacketsMap& missing_packets,
143 bool cancel_rtx_if_not_in_list, 113 bool cancel_rtx_if_not_in_list,
144 const DedupInfo& dedup_info); 114 const DedupInfo& dedup_info);
145 115
146 // If |raw_events_callback_| is non-null, calls it with events collected 116 // If |logging_flush_interval| is set, this is called at approximate periodic
147 // in |recent_frame_events_| and |recent_packet_events_| since last call. 117 // intervals.
148 void SendRawEvents(); 118 void SendRawEvents();
149 119
150 // Called when a packet is received. 120 // Called when a packet is received.
151 bool OnReceivedPacket(scoped_ptr<Packet> packet); 121 bool OnReceivedPacket(scoped_ptr<Packet> packet);
152 122
153 // Called when a log message is received. 123 // Called when a log message is received.
154 void OnReceivedLogMessage(EventMediaType media_type, 124 void OnReceivedLogMessage(EventMediaType media_type,
155 const RtcpReceiverLogMessage& log); 125 const RtcpReceiverLogMessage& log);
156 126
157 // Called when a RTCP Cast message is received. 127 // Called when a RTCP Cast message is received.
158 void OnReceivedCastMessage(uint32_t ssrc, 128 void OnReceivedCastMessage(uint32_t ssrc,
159 const RtcpCastMessageCallback& cast_message_cb, 129 const RtcpCastMessageCallback& cast_message_cb,
160 const RtcpCastMessage& cast_message); 130 const RtcpCastMessage& cast_message);
161 131
162 base::TickClock* clock_; // Not owned by this class. 132 base::TickClock* const clock_; // Not owned by this class.
163 CastTransportStatusCallback status_callback_; 133 const base::TimeDelta logging_flush_interval_;
164 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; 134 const scoped_ptr<Client> transport_client_;
135 const scoped_ptr<PacketSender> transport_;
136 const scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_;
165 137
166 // FrameEvents and PacketEvents pending delivery via |raw_events_callback_|. 138 // FrameEvents and PacketEvents pending delivery via raw events callback.
167 // Do not add elements to these when |raw_events_callback_.is_null()|. 139 // Do not add elements to these when |logging_flush_interval| is
140 // |base::TimeDelta()|.
168 std::vector<FrameEvent> recent_frame_events_; 141 std::vector<FrameEvent> recent_frame_events_;
169 std::vector<PacketEvent> recent_packet_events_; 142 std::vector<PacketEvent> recent_packet_events_;
170 143
171 // Interface to a UDP socket.
172 scoped_ptr<UdpTransport> transport_;
173
174 // Packet sender that performs pacing. 144 // Packet sender that performs pacing.
175 PacedSender pacer_; 145 PacedSender pacer_;
176 146
177 // Packetizer for audio and video frames. 147 // Packetizer for audio and video frames.
178 scoped_ptr<RtpSender> audio_sender_; 148 scoped_ptr<RtpSender> audio_sender_;
179 scoped_ptr<RtpSender> video_sender_; 149 scoped_ptr<RtpSender> video_sender_;
180 150
181 // Maintains RTCP session for audio and video. 151 // Maintains RTCP session for audio and video.
182 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; 152 scoped_ptr<SenderRtcpSession> audio_rtcp_session_;
183 scoped_ptr<SenderRtcpSession> video_rtcp_session_; 153 scoped_ptr<SenderRtcpSession> video_rtcp_session_;
184 154
185 // Encrypts data in EncodedFrames before they are sent. Note that it's 155 // Encrypts data in EncodedFrames before they are sent. Note that it's
186 // important for the encryption to happen here, in code that would execute in 156 // important for the encryption to happen here, in code that would execute in
187 // the main browser process, for security reasons. This helps to mitigate 157 // the main browser process, for security reasons. This helps to mitigate
188 // the damage that could be caused by a compromised renderer process. 158 // the damage that could be caused by a compromised renderer process.
189 TransportEncryptionHandler audio_encryptor_; 159 TransportEncryptionHandler audio_encryptor_;
190 TransportEncryptionHandler video_encryptor_; 160 TransportEncryptionHandler video_encryptor_;
191 161
192 BulkRawEventsCallback raw_events_callback_;
193 base::TimeDelta raw_events_callback_interval_;
194
195 // Right after a frame is sent we record the number of bytes sent to the 162 // Right after a frame is sent we record the number of bytes sent to the
196 // socket. We record the corresponding bytes sent for the most recent ACKed 163 // socket. We record the corresponding bytes sent for the most recent ACKed
197 // audio packet. 164 // audio packet.
198 int64_t last_byte_acked_for_audio_; 165 int64_t last_byte_acked_for_audio_;
199 166
200 // Packets that don't match these ssrcs are ignored. 167 // Packets that don't match these ssrcs are ignored.
201 std::set<uint32_t> valid_ssrcs_; 168 std::set<uint32_t> valid_ssrcs_;
202 169
203 // Called with incoming packets. (Unless they match the 170 // While non-null, global WiFi behavior modifications are in effect. This is
204 // channels created by Initialize{Audio,Video}. 171 // used, for example, to turn off WiFi scanning that tends to interfere with
205 PacketReceiverCallback packet_callback_; 172 // the reliability of UDP packet transmission.
206
207 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; 173 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_;
208 174
209 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; 175 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_;
210 176
211 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); 177 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl);
212 }; 178 };
213 179
214 } // namespace cast 180 } // namespace cast
215 } // namespace media 181 } // namespace media
216 182
217 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ 183 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698