OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ | |
6 #define CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "base/time/time.h" | |
11 #include "media/cast/cast_config.h" | |
12 #include "media/cast/cast_environment.h" | |
13 #include "media/cast/net/cast_transport.h" | |
14 #include "media/cast/net/rtcp/rtcp_defines.h" | |
15 | |
16 namespace cast { | |
17 | |
18 // RTP sender for a single Cast Remoting RTP stream. The client calls Send() to | |
19 // instruct the sender to transmit the data using a CastTransport. | |
20 // | |
21 // This class is instantiated and owned by CastTransportHostFilter in response | |
22 // to IPC messages from an extension process to create RTP streams for the media | |
23 // remoting use case. CastTransportHostFilter is also responsible for destroying | |
24 // the instance in response to later IPCs. | |
25 // | |
26 // TODO(miu): Mojo service bindings/implementation to read from data pipes will | |
27 // be added in a soon-upcoming change. | |
28 | |
29 class CastRemotingSender { | |
30 public: | |
31 // |transport| is expected to outlive this class. | |
32 explicit CastRemotingSender( | |
33 scoped_refptr<media::cast::CastEnvironment> cast_environment, | |
34 media::cast::CastTransport* const transport, | |
dcheng
2016/09/10 02:31:36
Nit: the const here doesn't enforce much other tha
xjz
2016/09/12 18:22:05
Done.
| |
35 const media::cast::CastTransportRtpConfig& config); | |
36 ~CastRemotingSender(); | |
37 | |
38 private: | |
39 // Friend class for unit tests. | |
40 friend class CastRemotingSenderTest; | |
41 | |
42 class RemotingRtcpClient; | |
43 | |
44 // Called to send the serialized frame data. | |
45 void SendFrame(); | |
46 | |
47 // Called to cancel all the in flight frames when seeking happens. | |
48 void CancelFramesInFlight(); | |
49 | |
50 // These are called to deliver RTCP feedback from the remoter peer. | |
dcheng
2016/09/10 02:31:36
remoter =? remote?
xjz
2016/09/12 18:22:05
Modified the comment. The RTCP feedbacks are from
| |
51 void OnReceivedCastMessage(const media::cast::RtcpCastMessage& cast_feedback); | |
52 void OnReceivedRtt(base::TimeDelta round_trip_time); | |
53 | |
54 // Returns the number of frames that were sent but not yet acknowledged. This | |
55 // does not account for frames acknowledged out-of-order, and is always a high | |
56 // watermark estimate. | |
57 int NumberOfFramesInFlight() const; | |
58 | |
59 // Schedule and execute periodic checks for re-sending packets. If no | |
60 // acknowledgements have been received for "too long," CastRemotingSender will | |
61 // speculatively re-send certain packets of an unacked frame to kick-start | |
62 // re-transmission. This is a last resort tactic to prevent the session from | |
63 // getting stuck after a long outage. | |
64 void ScheduleNextResendCheck(); | |
65 void ResendCheck(); | |
66 void ResendForKickstart(); | |
67 | |
68 void RecordLatestFrameTimestamps(media::cast::FrameId frame_id, | |
69 media::cast::RtpTimeTicks rtp_timestamp); | |
70 media::cast::RtpTimeTicks GetRecordedRtpTimestamp( | |
71 media::cast::FrameId frame_id) const; | |
72 | |
73 // Unique identifier for the RTP stream and this CastRemotingSender. | |
74 const int32_t remoting_stream_id_; | |
75 | |
76 const scoped_refptr<media::cast::CastEnvironment> cast_environment_; | |
77 | |
78 // Sends encoded frames over the configured transport (e.g., UDP). It outlives | |
79 // this class. | |
80 media::cast::CastTransport* const transport_; | |
81 | |
82 const uint32_t ssrc_; | |
83 | |
84 const bool is_audio_; | |
85 | |
86 // This is the maximum delay that the sender should get ack from receiver. | |
87 // Otherwise, sender will call ResendForKickstart(). | |
88 base::TimeDelta max_ack_delay_; | |
89 | |
90 // This is "null" until the first frame is sent. Thereafter, this tracks the | |
91 // last time any frame was sent or re-sent. | |
92 base::TimeTicks last_send_time_; | |
93 | |
94 // The ID of the last frame sent. This member is invalid until | |
95 // |!last_send_time_.is_null()|. | |
96 media::cast::FrameId last_sent_frame_id_; | |
97 | |
98 // The ID of the latest (not necessarily the last) frame that has been | |
99 // acknowledged. This member is invalid until |!last_send_time_.is_null()|. | |
100 media::cast::FrameId latest_acked_frame_id_; | |
101 | |
102 // Counts the number of duplicate ACK that are being received. When this | |
103 // number reaches a threshold, the sender will take this as a sign that the | |
104 // receiver hasn't yet received the first packet of the next frame. In this | |
105 // case, CastRemotingSender will trigger a re-send of the next frame. | |
106 int duplicate_ack_counter_; | |
107 | |
108 // The most recently measured round trip time. | |
109 base::TimeDelta current_round_trip_time_; | |
110 | |
111 // The next frame's payload data. Populated by one or more calls to | |
112 // ConsumeDataChunk(). | |
113 // TODO(miu): To be implemented in soon upcoming change. | |
114 std::string next_frame_data_; | |
115 | |
116 // Ring buffer to keep track of recent frame RTP timestamps. This should | |
117 // only be accessed through the Record/GetXX() methods. The index into this | |
118 // ring buffer is the lower 8 bits of the FrameId. | |
119 media::cast::RtpTimeTicks frame_rtp_timestamps_[256]; | |
120 | |
121 // This flag indicates whether CancelFramesInFlight() was called. | |
122 bool last_frame_was_canceled_; | |
123 | |
124 // NOTE: Weak pointers must be invalidated before all other member variables. | |
125 base::WeakPtrFactory<CastRemotingSender> weak_factory_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(CastRemotingSender); | |
128 }; | |
129 | |
130 } // namespace cast | |
131 | |
132 #endif // CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ | |
OLD | NEW |