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 #ifndef MEDIA_CAST_SENDER_AUDIO_SENDER_H_ | 5 #ifndef MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
6 #define MEDIA_CAST_SENDER_AUDIO_SENDER_H_ | 6 #define MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Note: It is invalid to call this method if InitializationResult() returns | 48 // Note: It is invalid to call this method if InitializationResult() returns |
49 // anything but STATUS_AUDIO_INITIALIZED. | 49 // anything but STATUS_AUDIO_INITIALIZED. |
50 void InsertAudio(scoped_ptr<AudioBus> audio_bus, | 50 void InsertAudio(scoped_ptr<AudioBus> audio_bus, |
51 const base::TimeTicks& recorded_time); | 51 const base::TimeTicks& recorded_time); |
52 | 52 |
53 protected: | 53 protected: |
54 // Protected for testability. | 54 // Protected for testability. |
55 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); | 55 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); |
56 | 56 |
57 private: | 57 private: |
58 // Schedule and execute periodic checks for re-sending packets. If no | |
59 // acknowledgements have been received for "too long," AudioSender will | |
60 // speculatively re-send certain packets of an unacked frame to kick-start | |
61 // re-transmission. This is a last resort tactic to prevent the session from | |
62 // getting stuck after a long outage. | |
63 void ScheduleNextResendCheck(); | |
64 void ResendCheck(); | |
65 void ResendForKickstart(); | |
66 | |
67 // Returns true if there are too many frames in flight, as defined by the | 58 // Returns true if there are too many frames in flight, as defined by the |
68 // configured target playout delay plus simple logic. When this is true, | 59 // configured target playout delay plus simple logic. When this is true, |
69 // InsertAudio() will silenty drop frames instead of sending them to the audio | 60 // InsertAudio() will silenty drop frames instead of sending them to the audio |
70 // encoder. | 61 // encoder. |
71 bool AreTooManyFramesInFlight() const; | 62 bool AreTooManyFramesInFlight() const; |
72 | 63 |
73 // Called by the |audio_encoder_| with the next EncodedFrame to send. | 64 // Called by the |audio_encoder_| with the next EncodedFrame to send. |
74 void SendEncodedAudioFrame(scoped_ptr<EncodedFrame> audio_frame); | 65 void SendEncodedAudioFrame(scoped_ptr<EncodedFrame> audio_frame); |
75 | 66 |
76 // Encodes AudioBuses into EncodedFrames. | 67 // Encodes AudioBuses into EncodedFrames. |
77 scoped_ptr<AudioEncoder> audio_encoder_; | 68 scoped_ptr<AudioEncoder> audio_encoder_; |
78 const int configured_encoder_bitrate_; | 69 const int configured_encoder_bitrate_; |
79 | 70 |
80 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per | |
81 // frame) at the start of the session. Once a threshold is reached, RTCP | |
82 // reports are instead sent at the configured interval + random drift. | |
83 int num_aggressive_rtcp_reports_sent_; | |
84 | |
85 // This is "null" until the first frame is sent. Thereafter, this tracks the | |
86 // last time any frame was sent or re-sent. | |
87 base::TimeTicks last_send_time_; | |
88 | |
89 // The ID of the last frame sent. Logic throughout AudioSender assumes this | |
90 // can safely wrap-around. This member is invalid until | |
91 // |!last_send_time_.is_null()|. | |
92 uint32 last_sent_frame_id_; | |
93 | |
94 // The ID of the latest (not necessarily the last) frame that has been | |
95 // acknowledged. Logic throughout AudioSender assumes this can safely | |
96 // wrap-around. This member is invalid until |!last_send_time_.is_null()|. | |
97 uint32 latest_acked_frame_id_; | |
98 | |
99 // Counts the number of duplicate ACK that are being received. When this | |
100 // number reaches a threshold, the sender will take this as a sign that the | |
101 // receiver hasn't yet received the first packet of the next frame. In this | |
102 // case, AudioSender will trigger a re-send of the next frame. | |
103 int duplicate_ack_counter_; | |
104 | |
105 // If this sender is ready for use, this is STATUS_AUDIO_INITIALIZED. | |
106 CastInitializationStatus cast_initialization_status_; | |
107 | |
108 // This is a "good enough" mapping for finding the RTP timestamp associated | |
109 // with a video frame. The key is the lowest 8 bits of frame id (which is | |
110 // what is sent via RTCP). This map is used for logging purposes. | |
111 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | |
112 | |
113 // NOTE: Weak pointers must be invalidated before all other member variables. | 71 // NOTE: Weak pointers must be invalidated before all other member variables. |
114 base::WeakPtrFactory<AudioSender> weak_factory_; | 72 base::WeakPtrFactory<AudioSender> weak_factory_; |
115 | 73 |
116 DISALLOW_COPY_AND_ASSIGN(AudioSender); | 74 DISALLOW_COPY_AND_ASSIGN(AudioSender); |
117 }; | 75 }; |
118 | 76 |
119 } // namespace cast | 77 } // namespace cast |
120 } // namespace media | 78 } // namespace media |
121 | 79 |
122 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_ | 80 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
OLD | NEW |