OLD | NEW |
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 is the base class for an object that send frames to a receiver. | 5 // This is the base class for an object that send frames to a receiver. |
6 // TODO(hclam): Refactor such that there is no separate AudioSender vs. | 6 // TODO(hclam): Refactor such that there is no separate AudioSender vs. |
7 // VideoSender, and the functionality of both is rolled into this class. | 7 // VideoSender, and the functionality of both is rolled into this class. |
8 | 8 |
9 #ifndef MEDIA_CAST_SENDER_FRAME_SENDER_H_ | 9 #ifndef MEDIA_CAST_SENDER_FRAME_SENDER_H_ |
10 #define MEDIA_CAST_SENDER_FRAME_SENDER_H_ | 10 #define MEDIA_CAST_SENDER_FRAME_SENDER_H_ |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "media/cast/cast_environment.h" | 16 #include "media/cast/cast_environment.h" |
17 #include "media/cast/net/rtcp/rtcp.h" | 17 #include "media/cast/net/rtcp/rtcp.h" |
18 #include "media/cast/sender/rtp_timestamp_helper.h" | |
19 | 18 |
20 namespace media { | 19 namespace media { |
21 namespace cast { | 20 namespace cast { |
22 | 21 |
23 class FrameSender { | 22 class FrameSender { |
24 public: | 23 public: |
25 FrameSender(scoped_refptr<CastEnvironment> cast_environment, | 24 FrameSender(scoped_refptr<CastEnvironment> cast_environment, |
26 CastTransportSender* const transport_sender, | 25 CastTransportSender* const transport_sender, |
27 base::TimeDelta rtcp_interval, | 26 base::TimeDelta rtcp_interval, |
28 int frequency, | 27 int rtp_timebase, |
29 uint32 ssrc, | 28 uint32 ssrc, |
30 double max_frame_rate, | 29 double max_frame_rate, |
31 base::TimeDelta playout_delay); | 30 base::TimeDelta playout_delay); |
32 virtual ~FrameSender(); | 31 virtual ~FrameSender(); |
33 | 32 |
34 // Calling this function is only valid if the receiver supports the | 33 // Calling this function is only valid if the receiver supports the |
35 // "extra_playout_delay", rtp extension. | 34 // "extra_playout_delay", rtp extension. |
36 void SetTargetPlayoutDelay(base::TimeDelta new_target_playout_delay); | 35 void SetTargetPlayoutDelay(base::TimeDelta new_target_playout_delay); |
37 | 36 |
38 base::TimeDelta GetTargetPlayoutDelay() const { | 37 base::TimeDelta GetTargetPlayoutDelay() const { |
(...skipping 16 matching lines...) Expand all Loading... |
55 | 54 |
56 // Sends encoded frames over the configured transport (e.g., UDP). In | 55 // Sends encoded frames over the configured transport (e.g., UDP). In |
57 // Chromium, this could be a proxy that first sends the frames from a renderer | 56 // Chromium, this could be a proxy that first sends the frames from a renderer |
58 // process to the browser process over IPC, with the browser process being | 57 // process to the browser process over IPC, with the browser process being |
59 // responsible for "packetizing" the frames and pushing packets into the | 58 // responsible for "packetizing" the frames and pushing packets into the |
60 // network layer. | 59 // network layer. |
61 CastTransportSender* const transport_sender_; | 60 CastTransportSender* const transport_sender_; |
62 | 61 |
63 const uint32 ssrc_; | 62 const uint32 ssrc_; |
64 | 63 |
65 // Records lip-sync (i.e., mapping of RTP <--> NTP timestamps), and | |
66 // extrapolates this mapping to any other point in time. | |
67 RtpTimestampHelper rtp_timestamp_helper_; | |
68 | |
69 // RTT information from RTCP. | 64 // RTT information from RTCP. |
70 bool rtt_available_; | 65 bool rtt_available_; |
71 base::TimeDelta rtt_; | 66 base::TimeDelta rtt_; |
72 base::TimeDelta avg_rtt_; | 67 base::TimeDelta avg_rtt_; |
73 base::TimeDelta min_rtt_; | 68 base::TimeDelta min_rtt_; |
74 base::TimeDelta max_rtt_; | 69 base::TimeDelta max_rtt_; |
75 | 70 |
76 protected: | 71 protected: |
77 // Schedule and execute periodic checks for re-sending packets. If no | 72 // Schedule and execute periodic checks for re-sending packets. If no |
78 // acknowledgements have been received for "too long," AudioSender will | 73 // acknowledgements have been received for "too long," AudioSender will |
79 // speculatively re-send certain packets of an unacked frame to kick-start | 74 // speculatively re-send certain packets of an unacked frame to kick-start |
80 // re-transmission. This is a last resort tactic to prevent the session from | 75 // re-transmission. This is a last resort tactic to prevent the session from |
81 // getting stuck after a long outage. | 76 // getting stuck after a long outage. |
82 void ScheduleNextResendCheck(); | 77 void ScheduleNextResendCheck(); |
83 void ResendCheck(); | 78 void ResendCheck(); |
84 void ResendForKickstart(); | 79 void ResendForKickstart(); |
85 | 80 |
| 81 // Record or retrieve a recent history of each frame's timestamps. |
| 82 // Warning: If a frame ID too far in the past is requested, the getters will |
| 83 // silently succeed but return incorrect values. Be sure to respect |
| 84 // media::cast::kMaxUnackedFrames. |
| 85 void RecordLatestFrameTimestamps(uint32 frame_id, |
| 86 base::TimeTicks reference_time, |
| 87 RtpTimestamp rtp_timestamp); |
| 88 base::TimeTicks GetRecordedReferenceTime(uint32 frame_id) const; |
| 89 RtpTimestamp GetRecordedRtpTimestamp(uint32 frame_id) const; |
| 90 |
86 const base::TimeDelta rtcp_interval_; | 91 const base::TimeDelta rtcp_interval_; |
87 | 92 |
88 // The total amount of time between a frame's capture/recording on the sender | 93 // The total amount of time between a frame's capture/recording on the sender |
89 // and its playback on the receiver (i.e., shown to a user). This is fixed as | 94 // and its playback on the receiver (i.e., shown to a user). This is fixed as |
90 // a value large enough to give the system sufficient time to encode, | 95 // a value large enough to give the system sufficient time to encode, |
91 // transmit/retransmit, receive, decode, and render; given its run-time | 96 // transmit/retransmit, receive, decode, and render; given its run-time |
92 // environment (sender/receiver hardware performance, network conditions, | 97 // environment (sender/receiver hardware performance, network conditions, |
93 // etc.). | 98 // etc.). |
94 base::TimeDelta target_playout_delay_; | 99 base::TimeDelta target_playout_delay_; |
95 | 100 |
96 // If true, we transmit the target playout delay to the receiver. | 101 // If true, we transmit the target playout delay to the receiver. |
97 bool send_target_playout_delay_; | 102 bool send_target_playout_delay_; |
98 | 103 |
99 // Max encoded frames generated per second. | 104 // Max encoded frames generated per second. |
100 double max_frame_rate_; | 105 double max_frame_rate_; |
101 | 106 |
102 // Maximum number of outstanding frames before the encoding and sending of | 107 // Maximum number of outstanding frames before the encoding and sending of |
103 // new frames shall halt. | 108 // new frames shall halt. |
104 int max_unacked_frames_; | 109 int max_unacked_frames_; |
105 | 110 |
106 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per | 111 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per |
107 // frame) at the start of the session. Once a threshold is reached, RTCP | 112 // frame) at the start of the session. Once a threshold is reached, RTCP |
108 // reports are instead sent at the configured interval + random drift. | 113 // reports are instead sent at the configured interval + random drift. |
109 int num_aggressive_rtcp_reports_sent_; | 114 int num_aggressive_rtcp_reports_sent_; |
110 | 115 |
111 // This is "null" until the first frame is sent. Thereafter, this tracks the | 116 // This is "null" until the first frame is sent. Thereafter, this tracks the |
112 // last time any frame was sent or re-sent. | 117 // last time any frame was sent or re-sent. |
113 base::TimeTicks last_send_time_; | 118 base::TimeTicks last_send_time_; |
114 | 119 |
115 // The ID of the last frame sent. Logic throughout AudioSender assumes this | 120 // The ID of the last frame sent. Logic throughout FrameSender assumes this |
116 // can safely wrap-around. This member is invalid until | 121 // can safely wrap-around. This member is invalid until |
117 // |!last_send_time_.is_null()|. | 122 // |!last_send_time_.is_null()|. |
118 uint32 last_sent_frame_id_; | 123 uint32 last_sent_frame_id_; |
119 | 124 |
120 // The ID of the latest (not necessarily the last) frame that has been | 125 // The ID of the latest (not necessarily the last) frame that has been |
121 // acknowledged. Logic throughout AudioSender assumes this can safely | 126 // acknowledged. Logic throughout AudioSender assumes this can safely |
122 // wrap-around. This member is invalid until |!last_send_time_.is_null()|. | 127 // wrap-around. This member is invalid until |!last_send_time_.is_null()|. |
123 uint32 latest_acked_frame_id_; | 128 uint32 latest_acked_frame_id_; |
124 | 129 |
125 // Counts the number of duplicate ACK that are being received. When this | 130 // Counts the number of duplicate ACK that are being received. When this |
126 // number reaches a threshold, the sender will take this as a sign that the | 131 // number reaches a threshold, the sender will take this as a sign that the |
127 // receiver hasn't yet received the first packet of the next frame. In this | 132 // receiver hasn't yet received the first packet of the next frame. In this |
128 // case, VideoSender will trigger a re-send of the next frame. | 133 // case, VideoSender will trigger a re-send of the next frame. |
129 int duplicate_ack_counter_; | 134 int duplicate_ack_counter_; |
130 | 135 |
131 // If this sender is ready for use, this is STATUS_AUDIO_INITIALIZED or | 136 // If this sender is ready for use, this is STATUS_AUDIO_INITIALIZED or |
132 // STATUS_VIDEO_INITIALIZED. | 137 // STATUS_VIDEO_INITIALIZED. |
133 CastInitializationStatus cast_initialization_status_; | 138 CastInitializationStatus cast_initialization_status_; |
134 | 139 |
135 // This is a "good enough" mapping for finding the RTP timestamp associated | 140 private: |
136 // with a video frame. The key is the lowest 8 bits of frame id (which is | 141 // RTP timestamp increment representing one second. |
137 // what is sent via RTCP). This map is used for logging purposes. | 142 const int rtp_timebase_; |
138 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | |
139 | 143 |
140 private: | 144 // Ring buffers to keep track of recent frame timestamps (both in terms of |
| 145 // local reference time and RTP media time). These should only be accessed |
| 146 // through the Record/GetXXX() methods. |
| 147 base::TimeTicks frame_reference_times_[256]; |
| 148 RtpTimestamp frame_rtp_timestamps_[256]; |
| 149 |
141 // NOTE: Weak pointers must be invalidated before all other member variables. | 150 // NOTE: Weak pointers must be invalidated before all other member variables. |
142 base::WeakPtrFactory<FrameSender> weak_factory_; | 151 base::WeakPtrFactory<FrameSender> weak_factory_; |
143 | 152 |
144 DISALLOW_COPY_AND_ASSIGN(FrameSender); | 153 DISALLOW_COPY_AND_ASSIGN(FrameSender); |
145 }; | 154 }; |
146 | 155 |
147 } // namespace cast | 156 } // namespace cast |
148 } // namespace media | 157 } // namespace media |
149 | 158 |
150 #endif // MEDIA_CAST_SENDER_FRAME_SENDER_H_ | 159 #endif // MEDIA_CAST_SENDER_FRAME_SENDER_H_ |
OLD | NEW |