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

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

Issue 1878883003: Refactor: simplify interface of SenderRtcpSession and CastTransport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 transport for audio and video in a Cast Streaming 5 // This class maintains a transport for audio and video in a Cast Streaming
6 // session. 6 // 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 15 matching lines...) Expand all
26 26
27 #include <stdint.h> 27 #include <stdint.h>
28 28
29 #include <set> 29 #include <set>
30 #include <vector> 30 #include <vector>
31 31
32 #include "base/callback.h" 32 #include "base/callback.h"
33 #include "base/gtest_prod_util.h" 33 #include "base/gtest_prod_util.h"
34 #include "base/macros.h" 34 #include "base/macros.h"
35 #include "base/memory/ref_counted.h" 35 #include "base/memory/ref_counted.h"
36 #include "base/memory/scoped_ptr.h"
37 #include "base/memory/weak_ptr.h" 36 #include "base/memory/weak_ptr.h"
38 #include "base/time/tick_clock.h" 37 #include "base/time/tick_clock.h"
39 #include "base/time/time.h" 38 #include "base/time/time.h"
40 #include "media/cast/common/transport_encryption_handler.h" 39 #include "media/cast/common/transport_encryption_handler.h"
41 #include "media/cast/logging/logging_defines.h" 40 #include "media/cast/logging/logging_defines.h"
42 #include "media/cast/net/cast_transport.h" 41 #include "media/cast/net/cast_transport.h"
43 #include "media/cast/net/cast_transport_config.h" 42 #include "media/cast/net/cast_transport_config.h"
44 #include "media/cast/net/pacing/paced_sender.h" 43 #include "media/cast/net/pacing/paced_sender.h"
45 #include "media/cast/net/rtcp/rtcp_builder.h" 44 #include "media/cast/net/rtcp/rtcp_builder.h"
46 #include "media/cast/net/rtcp/sender_rtcp_session.h" 45 #include "media/cast/net/rtcp/sender_rtcp_session.h"
47 #include "media/cast/net/rtp/rtp_parser.h" 46 #include "media/cast/net/rtp/rtp_parser.h"
48 #include "media/cast/net/rtp/rtp_sender.h" 47 #include "media/cast/net/rtp/rtp_sender.h"
49 #include "net/base/network_interfaces.h" 48 #include "net/base/network_interfaces.h"
50 49
51 namespace media { 50 namespace media {
52 namespace cast { 51 namespace cast {
53 52
54 class UdpTransport; 53 class UdpTransport;
55 54
56 class CastTransportImpl final : public CastTransport { 55 class CastTransportImpl final : public CastTransport {
57 public: 56 public:
58 CastTransportImpl( 57 CastTransportImpl(
59 base::TickClock* clock, // Owned by the caller. 58 base::TickClock* clock, // Owned by the caller.
60 base::TimeDelta logging_flush_interval, 59 base::TimeDelta logging_flush_interval,
61 scoped_ptr<Client> client, 60 std::unique_ptr<Client> client,
62 scoped_ptr<PacketTransport> transport, 61 std::unique_ptr<PacketTransport> transport,
63 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner); 62 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner);
64 63
65 ~CastTransportImpl() final; 64 ~CastTransportImpl() final;
66 65
67 // CastTransport implementation for sending. 66 // CastTransport implementation for sending.
68 void InitializeAudio(const CastTransportRtpConfig& config, 67 void InitializeAudio(const CastTransportRtpConfig& config,
69 const RtcpCastMessageCallback& cast_message_cb, 68 std::unique_ptr<RtpSenderRtcpClient> rtcp_client) final;
70 const RtcpRttCallback& rtt_cb,
71 const RtcpPliCallback& pli_cb) final;
72 void InitializeVideo(const CastTransportRtpConfig& config, 69 void InitializeVideo(const CastTransportRtpConfig& config,
73 const RtcpCastMessageCallback& cast_message_cb, 70 std::unique_ptr<RtpSenderRtcpClient> rtcp_client) final;
74 const RtcpRttCallback& rtt_cb,
75 const RtcpPliCallback& pli_cb) final;
76 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final; 71 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final;
77 72
78 void SendSenderReport(uint32_t ssrc, 73 void SendSenderReport(uint32_t ssrc,
79 base::TimeTicks current_time, 74 base::TimeTicks current_time,
80 RtpTimeTicks current_time_as_rtp_timestamp) final; 75 RtpTimeTicks current_time_as_rtp_timestamp) final;
81 76
82 void CancelSendingFrames(uint32_t ssrc, 77 void CancelSendingFrames(uint32_t ssrc,
83 const std::vector<uint32_t>& frame_ids) final; 78 const std::vector<uint32_t>& frame_ids) final;
84 79
85 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final; 80 void ResendFrameForKickstart(uint32_t ssrc, uint32_t frame_id) final;
(...skipping 23 matching lines...) Expand all
109 const RtcpTimeData& time_data) final; 104 const RtcpTimeData& time_data) final;
110 void AddCastFeedback(const RtcpCastMessage& cast_message, 105 void AddCastFeedback(const RtcpCastMessage& cast_message,
111 base::TimeDelta target_delay) final; 106 base::TimeDelta target_delay) final;
112 void AddPli(const RtcpPliMessage& pli_message) final; 107 void AddPli(const RtcpPliMessage& pli_message) final;
113 void AddRtcpEvents( 108 void AddRtcpEvents(
114 const ReceiverRtcpEventSubscriber::RtcpEvents& rtcp_events) final; 109 const ReceiverRtcpEventSubscriber::RtcpEvents& rtcp_events) final;
115 void AddRtpReceiverReport( 110 void AddRtpReceiverReport(
116 const RtcpReportBlock& rtp_receiver_report_block) final; 111 const RtcpReportBlock& rtp_receiver_report_block) final;
117 void SendRtcpFromRtpReceiver() final; 112 void SendRtcpFromRtpReceiver() final;
118 113
114 // Called when a log message is received.
115 void OnReceivedLogMessage(EventMediaType media_type,
miu 2016/04/15 23:14:39 These don't need to be made public. (See my comme
xjz 2016/04/20 01:09:03 Done.
116 const RtcpReceiverLogMessage& log);
117
118 // Called when a RTCP Cast message is received.
119 void OnReceivedCastMessage(uint32_t ssrc,
120 const RtcpCastMessage& cast_message);
121
119 private: 122 private:
120 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, NacksCancelRetransmits); 123 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, NacksCancelRetransmits);
121 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, CancelRetransmits); 124 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, CancelRetransmits);
122 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, Kickstart); 125 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, Kickstart);
123 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, DedupRetransmissionWithAudio); 126 FRIEND_TEST_ALL_PREFIXES(CastTransportImplTest, DedupRetransmissionWithAudio);
124 127
125 // Resend packets for the stream identified by |ssrc|. 128 // Resend packets for the stream identified by |ssrc|.
126 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the 129 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the
127 // frames but not in the list will be dropped. 130 // frames but not in the list will be dropped.
128 // See PacedSender::ResendPackets() to see how |dedup_info| works. 131 // See PacedSender::ResendPackets() to see how |dedup_info| works.
129 void ResendPackets(uint32_t ssrc, 132 void ResendPackets(uint32_t ssrc,
130 const MissingFramesAndPacketsMap& missing_packets, 133 const MissingFramesAndPacketsMap& missing_packets,
131 bool cancel_rtx_if_not_in_list, 134 bool cancel_rtx_if_not_in_list,
132 const DedupInfo& dedup_info); 135 const DedupInfo& dedup_info);
133 136
134 // If |logging_flush_interval| is set, this is called at approximate periodic 137 // If |logging_flush_interval| is set, this is called at approximate periodic
135 // intervals. 138 // intervals.
136 void SendRawEvents(); 139 void SendRawEvents();
137 140
138 // Called when a packet is received. 141 // Called when a packet is received.
139 bool OnReceivedPacket(scoped_ptr<Packet> packet); 142 bool OnReceivedPacket(std::unique_ptr<Packet> packet);
140
141 // Called when a log message is received.
142 void OnReceivedLogMessage(EventMediaType media_type,
143 const RtcpReceiverLogMessage& log);
144
145 // Called when a RTCP Cast message is received.
146 void OnReceivedCastMessage(uint32_t ssrc,
147 const RtcpCastMessageCallback& cast_message_cb,
148 const RtcpCastMessage& cast_message);
149 143
150 base::TickClock* const clock_; // Not owned by this class. 144 base::TickClock* const clock_; // Not owned by this class.
151 const base::TimeDelta logging_flush_interval_; 145 const base::TimeDelta logging_flush_interval_;
152 const scoped_ptr<Client> transport_client_; 146 const std::unique_ptr<Client> transport_client_;
153 const scoped_ptr<PacketTransport> transport_; 147 const std::unique_ptr<PacketTransport> transport_;
154 const scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; 148 const scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_;
155 149
156 // FrameEvents and PacketEvents pending delivery via raw events callback. 150 // FrameEvents and PacketEvents pending delivery via raw events callback.
157 // Do not add elements to these when |logging_flush_interval| is 151 // Do not add elements to these when |logging_flush_interval| is
158 // |base::TimeDelta()|. 152 // |base::TimeDelta()|.
159 std::vector<FrameEvent> recent_frame_events_; 153 std::vector<FrameEvent> recent_frame_events_;
160 std::vector<PacketEvent> recent_packet_events_; 154 std::vector<PacketEvent> recent_packet_events_;
161 155
162 // Packet sender that performs pacing. 156 // Packet sender that performs pacing.
163 PacedSender pacer_; 157 PacedSender pacer_;
164 158
165 // Packetizer for audio and video frames. 159 // Packetizer for audio and video frames.
166 scoped_ptr<RtpSender> audio_sender_; 160 std::unique_ptr<RtpSender> audio_sender_;
167 scoped_ptr<RtpSender> video_sender_; 161 std::unique_ptr<RtpSender> video_sender_;
168 162
169 // Maintains RTCP session for audio and video. 163 // Maintains RTCP session for audio and video.
170 scoped_ptr<SenderRtcpSession> audio_rtcp_session_; 164 std::unique_ptr<SenderRtcpSession> audio_rtcp_session_;
171 scoped_ptr<SenderRtcpSession> video_rtcp_session_; 165 std::unique_ptr<SenderRtcpSession> video_rtcp_session_;
172 166
173 // Encrypts data in EncodedFrames before they are sent. Note that it's 167 // Encrypts data in EncodedFrames before they are sent. Note that it's
174 // important for the encryption to happen here, in code that would execute in 168 // important for the encryption to happen here, in code that would execute in
175 // the main browser process, for security reasons. This helps to mitigate 169 // the main browser process, for security reasons. This helps to mitigate
176 // the damage that could be caused by a compromised renderer process. 170 // the damage that could be caused by a compromised renderer process.
177 TransportEncryptionHandler audio_encryptor_; 171 TransportEncryptionHandler audio_encryptor_;
178 TransportEncryptionHandler video_encryptor_; 172 TransportEncryptionHandler video_encryptor_;
179 173
180 // Right after a frame is sent we record the number of bytes sent to the 174 // Right after a frame is sent we record the number of bytes sent to the
181 // socket. We record the corresponding bytes sent for the most recent ACKed 175 // socket. We record the corresponding bytes sent for the most recent ACKed
182 // audio packet. 176 // audio packet.
183 int64_t last_byte_acked_for_audio_; 177 int64_t last_byte_acked_for_audio_;
184 178
185 // Packets that don't match these sender ssrcs are ignored. 179 // Packets that don't match these sender ssrcs are ignored.
186 std::set<uint32_t> valid_sender_ssrcs_; 180 std::set<uint32_t> valid_sender_ssrcs_;
187 181
188 // While non-null, global WiFi behavior modifications are in effect. This is 182 // While non-null, global WiFi behavior modifications are in effect. This is
189 // used, for example, to turn off WiFi scanning that tends to interfere with 183 // used, for example, to turn off WiFi scanning that tends to interfere with
190 // the reliability of UDP packet transmission. 184 // the reliability of UDP packet transmission.
191 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; 185 std::unique_ptr<net::ScopedWifiOptions> wifi_options_autoreset_;
192 186
193 // Do not initialize the |rtcp_builder_at_rtp_receiver_| if the RTP receiver 187 // Do not initialize the |rtcp_builder_at_rtp_receiver_| if the RTP receiver
194 // SSRC does not match these ssrcs. Only RTP receiver needs to register its 188 // SSRC does not match these ssrcs. Only RTP receiver needs to register its
195 // SSRC in this set. 189 // SSRC in this set.
196 std::set<uint32_t> valid_rtp_receiver_ssrcs_; 190 std::set<uint32_t> valid_rtp_receiver_ssrcs_;
197 191
198 scoped_ptr<RtcpBuilder> rtcp_builder_at_rtp_receiver_; 192 std::unique_ptr<RtcpBuilder> rtcp_builder_at_rtp_receiver_;
199 193
200 base::WeakPtrFactory<CastTransportImpl> weak_factory_; 194 base::WeakPtrFactory<CastTransportImpl> weak_factory_;
201 195
202 DISALLOW_COPY_AND_ASSIGN(CastTransportImpl); 196 DISALLOW_COPY_AND_ASSIGN(CastTransportImpl);
203 }; 197 };
204 198
205 } // namespace cast 199 } // namespace cast
206 } // namespace media 200 } // namespace media
207 201
208 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_ 202 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698