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

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

Issue 387933005: Cast: Refactor RTCP handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: smaller diff Created 6 years, 5 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 | Annotate | Revision Log
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
6 // Streaming session.
7 // Audio, video frames and RTCP messages are submitted to this object
8 // and then packetized and paced to the underlying UDP socket.
9 //
10 // The hierarchy of send transport in a Cast Streaming session:
11 //
12 // CastTransportSender RTP RTCP
13 // ------------------------------------------------------------------
14 // TransportEncryptionHandler (A/V)
15 // RtpSender (A/V) Rtcp (A/V)
16 // PacedSender (Shared)
17 // UdpTransport (Shared)
18 //
19 // There are objects of TransportEncryptionHandler, RtpSender and Rtcp
20 // for each audio and video stream.
21 // PacedSender and UdpTransport are shared between all RTP and RTCP
22 // streams.
23
5 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_ 24 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_
6 #define MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_ 25 #define MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_
7 26
8 #include "base/callback.h" 27 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 28 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 29 #include "base/memory/scoped_ptr.h"
30 #include "base/memory/weak_ptr.h"
11 #include "base/time/tick_clock.h" 31 #include "base/time/tick_clock.h"
12 #include "base/time/time.h" 32 #include "base/time/time.h"
13 #include "base/timer/timer.h" 33 #include "base/timer/timer.h"
14 #include "media/cast/common/transport_encryption_handler.h" 34 #include "media/cast/common/transport_encryption_handler.h"
15 #include "media/cast/logging/logging_defines.h" 35 #include "media/cast/logging/logging_defines.h"
16 #include "media/cast/logging/simple_event_subscriber.h" 36 #include "media/cast/logging/simple_event_subscriber.h"
17 #include "media/cast/net/cast_transport_config.h" 37 #include "media/cast/net/cast_transport_config.h"
18 #include "media/cast/net/cast_transport_sender.h" 38 #include "media/cast/net/cast_transport_sender.h"
19 #include "media/cast/net/pacing/paced_sender.h" 39 #include "media/cast/net/pacing/paced_sender.h"
20 #include "media/cast/net/rtcp/rtcp_builder.h" 40 #include "media/cast/net/rtcp/rtcp.h"
21 #include "media/cast/net/rtp/rtp_sender.h" 41 #include "media/cast/net/rtp/rtp_sender.h"
22 42
23 namespace media { 43 namespace media {
24 namespace cast { 44 namespace cast {
25 45
26 class UdpTransport; 46 class UdpTransport;
27 47
28 class CastTransportSenderImpl : public CastTransportSender { 48 class CastTransportSenderImpl : public CastTransportSender {
29 public: 49 public:
30 // external_transport is only used for testing. 50 // |external_transport| is only used for testing.
31 // Note that SetPacketReceiver does not work if an external
32 // transport is provided.
33 // |raw_events_callback|: Raw events will be returned on this callback 51 // |raw_events_callback|: Raw events will be returned on this callback
34 // which will be invoked every |raw_events_callback_interval|. 52 // which will be invoked every |raw_events_callback_interval|.
35 // This can be a null callback, i.e. if user is not interested in raw events. 53 // This can be a null callback, i.e. if user is not interested in raw events.
36 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if 54 // |raw_events_callback_interval|: This can be |base::TimeDelta()| if
37 // |raw_events_callback| is a null callback. 55 // |raw_events_callback| is a null callback.
38 CastTransportSenderImpl( 56 CastTransportSenderImpl(
39 net::NetLog* net_log, 57 net::NetLog* net_log,
40 base::TickClock* clock, 58 base::TickClock* clock,
41 const net::IPEndPoint& remote_end_point, 59 const net::IPEndPoint& remote_end_point,
42 const CastTransportStatusCallback& status_callback, 60 const CastTransportStatusCallback& status_callback,
43 const BulkRawEventsCallback& raw_events_callback, 61 const BulkRawEventsCallback& raw_events_callback,
44 base::TimeDelta raw_events_callback_interval, 62 base::TimeDelta raw_events_callback_interval,
45 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner, 63 const scoped_refptr<base::SingleThreadTaskRunner>& transport_task_runner,
46 PacketSender* external_transport); 64 PacketSender* external_transport);
47 65
48 virtual ~CastTransportSenderImpl(); 66 virtual ~CastTransportSenderImpl();
49 67
50 virtual void InitializeAudio(const CastTransportRtpConfig& config) OVERRIDE; 68 virtual void InitializeAudio(const CastTransportRtpConfig& config,
51 virtual void InitializeVideo(const CastTransportRtpConfig& config) OVERRIDE; 69 const RtcpCastMessageCallback& cast_message_cb,
52 70 const RtcpRttCallback& rtt_cb) OVERRIDE;
53 // CastTransportSender implementation. 71 virtual void InitializeVideo(const CastTransportRtpConfig& config,
54 virtual void SetPacketReceiver(const PacketReceiverCallback& packet_receiver) 72 const RtcpCastMessageCallback& cast_message_cb,
55 OVERRIDE; 73 const RtcpRttCallback& rtt_cb) OVERRIDE;
56
57 virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) OVERRIDE; 74 virtual void InsertCodedAudioFrame(const EncodedFrame& audio_frame) OVERRIDE;
58 virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) OVERRIDE; 75 virtual void InsertCodedVideoFrame(const EncodedFrame& video_frame) OVERRIDE;
59 76
60 virtual void SendRtcpFromRtpSender(uint32 packet_type_flags, 77 virtual void SendRtcpFromRtpSender(
61 uint32 ntp_seconds, 78 bool audio,
62 uint32 ntp_fraction, 79 base::TimeTicks current_time,
63 uint32 rtp_timestamp, 80 uint32 current_time_as_rtp_timestamp) OVERRIDE;
64 const RtcpDlrrReportBlock& dlrr,
65 uint32 sending_ssrc,
66 const std::string& c_name) OVERRIDE;
67 81
68 virtual void ResendPackets(bool is_audio, 82 virtual void ResendPackets(bool is_audio,
69 const MissingFramesAndPacketsMap& missing_packets, 83 const MissingFramesAndPacketsMap& missing_packets,
70 bool cancel_rtx_if_not_in_list, 84 bool cancel_rtx_if_not_in_list,
71 base::TimeDelta dedupe_window) 85 base::TimeDelta dedupe_window)
72 OVERRIDE; 86 OVERRIDE;
73 87
88 virtual PacketReceiverCallback PacketReceiverForTesting() OVERRIDE;
89
74 private: 90 private:
75 // If |raw_events_callback_| is non-null, calls it with events collected 91 // If |raw_events_callback_| is non-null, calls it with events collected
76 // by |event_subscriber_| since last call. 92 // by |event_subscriber_| since last call.
77 void SendRawEvents(); 93 void SendRawEvents();
78 94
95 // Start receiving packets.
96 void StartReceiving();
97
98 // Called when a packet is received.
99 void OnReceivedPacket(scoped_ptr<Packet> packet);
100
101 // Called when a log message is received.
102 void OnReceivedLogMessage(EventMediaType media_type,
103 const RtcpReceiverLogMessage& log);
104
79 base::TickClock* clock_; // Not owned by this class. 105 base::TickClock* clock_; // Not owned by this class.
80 CastTransportStatusCallback status_callback_; 106 CastTransportStatusCallback status_callback_;
81 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_; 107 scoped_refptr<base::SingleThreadTaskRunner> transport_task_runner_;
82 108
109 LoggingImpl logging_;
110
111 // Interface to a UDP socket.
83 scoped_ptr<UdpTransport> transport_; 112 scoped_ptr<UdpTransport> transport_;
84 LoggingImpl logging_; 113
114 // Packet sender that performs pacing.
85 PacedSender pacer_; 115 PacedSender pacer_;
86 RtcpBuilder rtcp_builder_; 116
117 // Packetizer for audio and video frames.
87 scoped_ptr<RtpSender> audio_sender_; 118 scoped_ptr<RtpSender> audio_sender_;
88 scoped_ptr<RtpSender> video_sender_; 119 scoped_ptr<RtpSender> video_sender_;
89 120
121 // Maintains RTCP session for audio and video.
122 scoped_ptr<Rtcp> audio_rtcp_session_;
123 scoped_ptr<Rtcp> video_rtcp_session_;
124
90 // Encrypts data in EncodedFrames before they are sent. Note that it's 125 // Encrypts data in EncodedFrames before they are sent. Note that it's
91 // important for the encryption to happen here, in code that would execute in 126 // important for the encryption to happen here, in code that would execute in
92 // the main browser process, for security reasons. This helps to mitigate 127 // the main browser process, for security reasons. This helps to mitigate
93 // the damage that could be caused by a compromised renderer process. 128 // the damage that could be caused by a compromised renderer process.
94 TransportEncryptionHandler audio_encryptor_; 129 TransportEncryptionHandler audio_encryptor_;
95 TransportEncryptionHandler video_encryptor_; 130 TransportEncryptionHandler video_encryptor_;
96 131
97 // This is non-null iff |raw_events_callback_| is non-null. 132 // This is non-null iff |raw_events_callback_| is non-null.
98 scoped_ptr<SimpleEventSubscriber> event_subscriber_; 133 scoped_ptr<SimpleEventSubscriber> event_subscriber_;
99 base::RepeatingTimer<CastTransportSenderImpl> raw_events_timer_; 134 base::RepeatingTimer<CastTransportSenderImpl> raw_events_timer_;
100 135
101 BulkRawEventsCallback raw_events_callback_; 136 BulkRawEventsCallback raw_events_callback_;
102 137
138 base::WeakPtrFactory<CastTransportSenderImpl> weak_factory_;
139
103 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl); 140 DISALLOW_COPY_AND_ASSIGN(CastTransportSenderImpl);
104 }; 141 };
105 142
106 } // namespace cast 143 } // namespace cast
107 } // namespace media 144 } // namespace media
108 145
109 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_ 146 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698