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

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

Issue 765643006: Cast: Make receiver use cast_transport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix end2end test Created 6 years 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:
11 // 11 //
12 // CastTransportSender RTP RTCP 12 // CastTransportSender RTP RTCP
13 // ------------------------------------------------------------------ 13 // ------------------------------------------------------------------
14 // TransportEncryptionHandler (A/V) 14 // TransportEncryptionHandler (A/V)
15 // RtpSender (A/V) Rtcp (A/V) 15 // RtpSender (A/V) Rtcp (A/V)
16 // PacedSender (Shared) 16 // PacedSender (Shared)
17 // UdpTransport (Shared) 17 // UdpTransport (Shared)
18 // 18 //
19 // There are objects of TransportEncryptionHandler, RtpSender and Rtcp 19 // There are objects of TransportEncryptionHandler, RtpSender and Rtcp
20 // for each audio and video stream. 20 // for each audio and video stream.
21 // PacedSender and UdpTransport are shared between all RTP and RTCP 21 // PacedSender and UdpTransport are shared between all RTP and RTCP
22 // streams. 22 // streams.
23 23
24 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ 24 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_
25 #define MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ 25 #define MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_
26 26
27 #include <set>
28
27 #include "base/callback.h" 29 #include "base/callback.h"
28 #include "base/gtest_prod_util.h" 30 #include "base/gtest_prod_util.h"
29 #include "base/memory/ref_counted.h" 31 #include "base/memory/ref_counted.h"
30 #include "base/memory/scoped_ptr.h" 32 #include "base/memory/scoped_ptr.h"
31 #include "base/memory/weak_ptr.h" 33 #include "base/memory/weak_ptr.h"
32 #include "base/time/tick_clock.h" 34 #include "base/time/tick_clock.h"
33 #include "base/time/time.h" 35 #include "base/time/time.h"
34 #include "media/cast/common/transport_encryption_handler.h" 36 #include "media/cast/common/transport_encryption_handler.h"
35 #include "media/cast/logging/logging_defines.h" 37 #include "media/cast/logging/logging_defines.h"
36 #include "media/cast/logging/simple_event_subscriber.h" 38 #include "media/cast/logging/simple_event_subscriber.h"
37 #include "media/cast/net/cast_transport_config.h" 39 #include "media/cast/net/cast_transport_config.h"
38 #include "media/cast/net/cast_transport_sender.h" 40 #include "media/cast/net/cast_transport_sender.h"
39 #include "media/cast/net/pacing/paced_sender.h" 41 #include "media/cast/net/pacing/paced_sender.h"
40 #include "media/cast/net/rtcp/rtcp.h" 42 #include "media/cast/net/rtcp/rtcp.h"
43 #include "media/cast/net/rtp/rtp_parser.h"
41 #include "media/cast/net/rtp/rtp_sender.h" 44 #include "media/cast/net/rtp/rtp_sender.h"
42 45
43 namespace media { 46 namespace media {
44 namespace cast { 47 namespace cast {
45 48
46 class UdpTransport; 49 class UdpTransport;
47 50
48 class CastTransportSenderImpl : public CastTransportSender { 51 class CastTransportSenderImpl : public CastTransportSender {
49 public: 52 public:
50 // |external_transport| is only used for testing. 53 // |external_transport| is only used for testing.
51 // |raw_events_callback|: Raw events will be returned on this callback 54 // |raw_events_callback|: Raw events will be returned on this callback
52 // which will be invoked every |raw_events_callback_interval|. 55 // which will be invoked every |raw_events_callback_interval|.
53 // This can be a null callback, i.e. if user is not interested in raw events. 56 // This can be a null callback, i.e. if user is not interested in raw events.
54 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if 57 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if
55 // |raw_events_callback| is a null callback. 58 // |raw_events_callback| is a null callback.
56 // |options| contains optional settings for the transport, possible 59 // |options| contains optional settings for the transport, possible
57 // keys are: 60 // keys are:
58 // "DSCP" (value ignored) - turns DSCP on 61 // "DSCP" (value ignored) - turns DSCP on
59 // "pacer_target_burst_size": int - specifies how many packets to send 62 // "pacer_target_burst_size": int - specifies how many packets to send
60 // per 10 ms ideally. 63 // per 10 ms ideally.
61 // "pacer_max_burst_size": int - specifies how many pakcets to send 64 // "pacer_max_burst_size": int - specifies how many pakcets to send
62 // per 10 ms, max 65 // per 10 ms, max
63 // "send_buffer_min_size": int - specifies the minimum socket send buffer 66 // "send_buffer_min_size": int - specifies the minimum socket send buffer
64 // size 67 // size
65 // "disable_wifi_scan" (value ignored) - disable wifi scans while streaming 68 // "disable_wifi_scan" (value ignored) - disable wifi scans while streaming
66 // "media_streaming_mode" (value ignored) - turn media streaming mode on 69 // "media_streaming_mode" (value ignored) - turn media streaming mode on
67 // Note, these options may be ignored on some platforms. 70 // Note, these options may be ignored on some platforms.
71 // TODO(hubbe): Too many callbacks, replace with an interface.
68 CastTransportSenderImpl( 72 CastTransportSenderImpl(
69 net::NetLog* net_log, 73 net::NetLog* net_log,
70 base::TickClock* clock, 74 base::TickClock* clock,
75 const net::IPEndPoint& local_end_point,
71 const net::IPEndPoint& remote_end_point, 76 const net::IPEndPoint& remote_end_point,
72 scoped_ptr<base::DictionaryValue> options, 77 scoped_ptr<base::DictionaryValue> options,
73 const CastTransportStatusCallback& status_callback, 78 const CastTransportStatusCallback& status_callback,
74 const BulkRawEventsCallback& raw_events_callback, 79 const BulkRawEventsCallback& raw_events_callback,
75 base::TimeDelta raw_events_callback_interval, 80 base::TimeDelta raw_events_callback_interval,
76 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, 81 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner,
82 const PacketReceiverCallback& packet_callback,
77 PacketSender* external_transport); 83 PacketSender* external_transport);
78 84
79 ~CastTransportSenderImpl() override; 85 ~CastTransportSenderImpl() override;
80 86
87 // CastTransportSender implementation.
81 void InitializeAudio(const CastTransportRtpConfig& config, 88 void InitializeAudio(const CastTransportRtpConfig& config,
82 const RtcpCastMessageCallback& cast_message_cb, 89 const RtcpCastMessageCallback& cast_message_cb,
83 const RtcpRttCallback& rtt_cb) override; 90 const RtcpRttCallback& rtt_cb) override;
84 void InitializeVideo(const CastTransportRtpConfig& config, 91 void InitializeVideo(const CastTransportRtpConfig& config,
85 const RtcpCastMessageCallback& cast_message_cb, 92 const RtcpCastMessageCallback& cast_message_cb,
86 const RtcpRttCallback& rtt_cb) override; 93 const RtcpRttCallback& rtt_cb) override;
87 void InsertFrame(uint32 ssrc, const EncodedFrame& frame) override; 94 void InsertFrame(uint32 ssrc, const EncodedFrame& frame) override;
88 95
89 void SendSenderReport(uint32 ssrc, 96 void SendSenderReport(uint32 ssrc,
90 base::TimeTicks current_time, 97 base::TimeTicks current_time,
91 uint32 current_time_as_rtp_timestamp) override; 98 uint32 current_time_as_rtp_timestamp) override;
92 99
93 void CancelSendingFrames(uint32 ssrc, 100 void CancelSendingFrames(uint32 ssrc,
94 const std::vector<uint32>& frame_ids) override; 101 const std::vector<uint32>& frame_ids) override;
95 102
96 void ResendFrameForKickstart(uint32 ssrc, uint32 frame_id) override; 103 void ResendFrameForKickstart(uint32 ssrc, uint32 frame_id) override;
97 104
98 PacketReceiverCallback PacketReceiverForTesting() override; 105 PacketReceiverCallback PacketReceiverForTesting() override;
99 106
107 // CastTransportReceiver implementation.
108 void AddValidSsrc(uint32 ssrc) override;
109
110 void SendRtcpFromRtpReceiver(
111 uint32 ssrc,
112 uint32 sender_ssrc,
113 const RtcpTimeData& time_data,
114 const RtcpCastMessage* cast_message,
115 base::TimeDelta target_delay,
116 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events,
117 const RtpReceiverStatistics* rtp_receiver_statistics) override;
118
100 private: 119 private:
101 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits); 120 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, NacksCancelRetransmits);
102 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits); 121 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, CancelRetransmits);
103 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart); 122 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, Kickstart);
104 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest, 123 FRIEND_TEST_ALL_PREFIXES(CastTransportSenderImplTest,
105 DedupRetransmissionWithAudio); 124 DedupRetransmissionWithAudio);
106 125
107 // Resend packets for the stream identified by |ssrc|. 126 // Resend packets for the stream identified by |ssrc|.
108 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the 127 // If |cancel_rtx_if_not_in_list| is true then transmission of packets for the
109 // frames but not in the list will be dropped. 128 // frames but not in the list will be dropped.
110 // See PacedSender::ResendPackets() to see how |dedup_info| works. 129 // See PacedSender::ResendPackets() to see how |dedup_info| works.
111 void ResendPackets(uint32 ssrc, 130 void ResendPackets(uint32 ssrc,
112 const MissingFramesAndPacketsMap& missing_packets, 131 const MissingFramesAndPacketsMap& missing_packets,
113 bool cancel_rtx_if_not_in_list, 132 bool cancel_rtx_if_not_in_list,
114 const DedupInfo& dedup_info); 133 const DedupInfo& dedup_info);
115 134
116 // If |raw_events_callback_| is non-null, calls it with events collected 135 // If |raw_events_callback_| is non-null, calls it with events collected
117 // by |event_subscriber_| since last call. 136 // by |event_subscriber_| since last call.
118 void SendRawEvents(); 137 void SendRawEvents();
119 138
120 // Called when a packet is received. 139 // Called when a packet is received.
121 void OnReceivedPacket(scoped_ptr<Packet> packet); 140 bool OnReceivedPacket(scoped_ptr<Packet> packet);
122 141
123 // Called when a log message is received. 142 // Called when a log message is received.
124 void OnReceivedLogMessage(EventMediaType media_type, 143 void OnReceivedLogMessage(EventMediaType media_type,
125 const RtcpReceiverLogMessage& log); 144 const RtcpReceiverLogMessage& log);
126 145
127 // Called when a RTCP Cast message is received. 146 // Called when a RTCP Cast message is received.
128 void OnReceivedCastMessage(uint32 ssrc, 147 void OnReceivedCastMessage(uint32 ssrc,
129 const RtcpCastMessageCallback& cast_message_cb, 148 const RtcpCastMessageCallback& cast_message_cb,
130 const RtcpCastMessage& cast_message); 149 const RtcpCastMessage& cast_message);
131 150
(...skipping 28 matching lines...) Expand all
160 scoped_ptr<SimpleEventSubscriber> event_subscriber_; 179 scoped_ptr<SimpleEventSubscriber> event_subscriber_;
161 180
162 BulkRawEventsCallback raw_events_callback_; 181 BulkRawEventsCallback raw_events_callback_;
163 base::TimeDelta raw_events_callback_interval_; 182 base::TimeDelta raw_events_callback_interval_;
164 183
165 // Right after a frame is sent we record the number of bytes sent to the 184 // Right after a frame is sent we record the number of bytes sent to the
166 // socket. We record the corresponding bytes sent for the most recent ACKed 185 // socket. We record the corresponding bytes sent for the most recent ACKed
167 // audio packet. 186 // audio packet.
168 int64 last_byte_acked_for_audio_; 187 int64 last_byte_acked_for_audio_;
169 188
189 // Packets that don't match these ssrcs are ignored.
190 std::set<uint32> valid_ssrcs_;
191
192 // Called with incoming packets. (Unless they match the
193 // channels created by Initialize{Audio,Video}.
194 PacketReceiverCallback packet_callback_;
195
170 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_; 196 scoped_ptr<net::ScopedWifiOptions> wifi_options_autoreset_;
171 197
172 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_; 198 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_;
173 199
174 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); 200 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl);
175 }; 201 };
176 202
177 } // namespace cast 203 } // namespace cast
178 } // namespace media 204 } // namespace media
179 205
180 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_ 206 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_SENDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698