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

Side by Side Diff: media/cast/audio_receiver/audio_receiver.h

Issue 280993002: [Cast] Repair receiver playout time calculations and frame skip logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed hubbe's comments. Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_AUDIO_RECEIVER_AUDIO_RECEIVER_H_ 5 #ifndef MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_
6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_ 6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 21 matching lines...) Expand all
32 // AudioReceiver receives packets out-of-order while clients make requests for 32 // AudioReceiver receives packets out-of-order while clients make requests for
33 // complete frames in-order. (A frame consists of one or more packets.) 33 // complete frames in-order. (A frame consists of one or more packets.)
34 // 34 //
35 // AudioReceiver also includes logic for computing the playout time for each 35 // AudioReceiver also includes logic for computing the playout time for each
36 // frame, accounting for a constant targeted playout delay. The purpose of the 36 // frame, accounting for a constant targeted playout delay. The purpose of the
37 // playout delay is to provide a fixed window of time between the capture event 37 // playout delay is to provide a fixed window of time between the capture event
38 // on the sender and the playout on the receiver. This is important because 38 // on the sender and the playout on the receiver. This is important because
39 // each step of the pipeline (i.e., encode frame, then transmit/retransmit from 39 // each step of the pipeline (i.e., encode frame, then transmit/retransmit from
40 // the sender, then receive and re-order packets on the receiver, then decode 40 // the sender, then receive and re-order packets on the receiver, then decode
41 // frame) can vary in duration and is typically very hard to predict. 41 // frame) can vary in duration and is typically very hard to predict.
42 // Heuristics will determine when the targeted playout delay is insufficient in
43 // the current environment; and the receiver can then increase the playout
44 // delay, notifying the sender, to account for the extra variance.
45 // TODO(miu): Make the last sentence true. http://crbug.com/360111
46 // 42 //
47 // Two types of frames can be requested: 1) A frame of decoded audio data; or 2) 43 // Two types of frames can be requested: 1) A frame of decoded audio data; or 2)
48 // a frame of still-encoded audio data, to be passed into an external audio 44 // a frame of still-encoded audio data, to be passed into an external audio
49 // decoder. Each request for a frame includes a callback which AudioReceiver 45 // decoder. Each request for a frame includes a callback which AudioReceiver
50 // guarantees will be called at some point in the future unless the 46 // guarantees will be called at some point in the future unless the
51 // AudioReceiver is destroyed. Clients should generally limit the number of 47 // AudioReceiver is destroyed. Clients should generally limit the number of
52 // outstanding requests (perhaps to just one or two). 48 // outstanding requests (perhaps to just one or two).
53 // 49 //
54 // This class is not thread safe. Should only be called from the Main cast 50 // This class is not thread safe. Should only be called from the Main cast
55 // thread. 51 // thread.
(...skipping 18 matching lines...) Expand all
74 70
75 // Request an encoded audio frame. 71 // Request an encoded audio frame.
76 // 72 //
77 // The given |callback| is guaranteed to be run at some point in the future, 73 // The given |callback| is guaranteed to be run at some point in the future,
78 // even if to respond with NULL at shutdown time. 74 // even if to respond with NULL at shutdown time.
79 void GetEncodedAudioFrame(const AudioFrameEncodedCallback& callback); 75 void GetEncodedAudioFrame(const AudioFrameEncodedCallback& callback);
80 76
81 // Deliver another packet, possibly a duplicate, and possibly out-of-order. 77 // Deliver another packet, possibly a duplicate, and possibly out-of-order.
82 void IncomingPacket(scoped_ptr<Packet> packet); 78 void IncomingPacket(scoped_ptr<Packet> packet);
83 79
84 // Update target audio delay used to compute the playout time. Rtcp
85 // will also be updated (will be included in all outgoing reports).
86 void SetTargetDelay(base::TimeDelta target_delay);
87
88 protected: 80 protected:
89 friend class AudioReceiverTest; // Invokes OnReceivedPayloadData(). 81 friend class AudioReceiverTest; // Invokes OnReceivedPayloadData().
90 82
91 virtual void OnReceivedPayloadData(const uint8* payload_data, 83 virtual void OnReceivedPayloadData(const uint8* payload_data,
92 size_t payload_size, 84 size_t payload_size,
93 const RtpCastHeader& rtp_header) OVERRIDE; 85 const RtpCastHeader& rtp_header) OVERRIDE;
94 86
95 // RtpPayloadFeedback implementation. 87 // RtpPayloadFeedback implementation.
96 virtual void CastFeedback(const RtcpCastMessage& cast_message) OVERRIDE; 88 virtual void CastFeedback(const RtcpCastMessage& cast_message) OVERRIDE;
97 89
98 private: 90 private:
99 // Processes ready-to-consume packets from |framer_|, decrypting each packet's 91 // Processes ready-to-consume packets from |framer_|, decrypting each packet's
100 // payload data, and then running the enqueued callbacks in order (one for 92 // payload data, and then running the enqueued callbacks in order (one for
101 // each packet). This method may post a delayed task to re-invoke itself in 93 // each packet). This method may post a delayed task to re-invoke itself in
102 // the future to wait for missing/incomplete frames. 94 // the future to wait for missing/incomplete frames.
103 void EmitAvailableEncodedFrames(); 95 void EmitAvailableEncodedFrames();
104 96
97 // Helper used by EmitAvailableEncodedFrames() to schedule itself to be called
98 // again after |wait_time| has elapsed.
99 void RetryEmitAfterWaiting(base::TimeDelta wait_time);
100
105 // Clears the |is_waiting_for_consecutive_frame_| flag and invokes 101 // Clears the |is_waiting_for_consecutive_frame_| flag and invokes
106 // EmitAvailableEncodedFrames(). 102 // EmitAvailableEncodedFrames().
107 void EmitAvailableEncodedFramesAfterWaiting(); 103 void EmitAvailableEncodedFramesAfterWaiting();
108 104
109 // Feeds an EncodedAudioFrame into |audio_decoder_|. GetRawAudioFrame() uses 105 // Feeds an EncodedAudioFrame into |audio_decoder_|. GetRawAudioFrame() uses
110 // this as a callback for GetEncodedAudioFrame(). 106 // this as a callback for GetEncodedAudioFrame().
111 void DecodeEncodedAudioFrame( 107 void DecodeEncodedAudioFrame(
112 const AudioFrameDecodedCallback& callback, 108 const AudioFrameDecodedCallback& callback,
113 scoped_ptr<transport::EncodedAudioFrame> encoded_frame, 109 scoped_ptr<transport::EncodedAudioFrame> encoded_frame,
114 const base::TimeTicks& playout_time); 110 const base::TimeTicks& playout_time);
115 111
116 // Return the playout time based on the current time and rtp timestamp. 112 // Computes the playout time for a frame with the given |rtp_timestamp|. If
117 base::TimeTicks GetPlayoutTime(base::TimeTicks now, uint32 rtp_timestamp); 113 // lip-sync info is not available, a best-guess is returned (a hack).
118 114 base::TimeTicks GetPlayoutTime(uint32 rtp_timestamp) const;
119 void InitializeTimers();
120 115
121 // Schedule the next RTCP report. 116 // Schedule the next RTCP report.
122 void ScheduleNextRtcpReport(); 117 void ScheduleNextRtcpReport();
123 118
124 // Actually send the next RTCP report. 119 // Actually send the next RTCP report.
125 void SendNextRtcpReport(); 120 void SendNextRtcpReport();
126 121
127 // Schedule timing for the next cast message. 122 // Schedule timing for the next cast message.
128 void ScheduleNextCastMessage(); 123 void ScheduleNextCastMessage();
129 124
(...skipping 13 matching lines...) Expand all
143 const base::TimeTicks& playout_time, 138 const base::TimeTicks& playout_time,
144 scoped_ptr<AudioBus> audio_bus, 139 scoped_ptr<AudioBus> audio_bus,
145 bool is_continuous); 140 bool is_continuous);
146 141
147 const scoped_refptr<CastEnvironment> cast_environment_; 142 const scoped_refptr<CastEnvironment> cast_environment_;
148 143
149 // Subscribes to raw events. 144 // Subscribes to raw events.
150 // Processes raw audio events to be sent over to the cast sender via RTCP. 145 // Processes raw audio events to be sent over to the cast sender via RTCP.
151 ReceiverRtcpEventSubscriber event_subscriber_; 146 ReceiverRtcpEventSubscriber event_subscriber_;
152 147
148 // Configured audio codec.
153 const transport::AudioCodec codec_; 149 const transport::AudioCodec codec_;
150
151 // RTP timebase: The number of RTP units advanced per one second. For audio,
152 // this is the sampling rate.
154 const int frequency_; 153 const int frequency_;
155 base::TimeDelta target_delay_delta_; 154
155 // The total amount of time between a frame's capture/recording on the sender
156 // and its playback on the receiver (i.e., shown to a user). This is fixed as
157 // a value large enough to give the system sufficient time to encode,
158 // transmit/retransmit, receive, decode, and render; given its run-time
159 // environment (sender/receiver hardware performance, network conditions,
160 // etc.).
161 const base::TimeDelta target_playout_delay_;
162
163 // Set to false initially, then set to true after scheduling the periodic
164 // sending of reports back to the sender. Reports are first scheduled just
165 // after receiving a first packet (since the first packet identifies the
166 // sender for the remainder of the session).
167 bool reports_are_scheduled_;
168
169 // Assembles packets into frames, providing this receiver with complete,
170 // decodable EncodedFrames.
156 Framer framer_; 171 Framer framer_;
172
173 // Decodes frames into raw audio for playback.
157 scoped_ptr<AudioDecoder> audio_decoder_; 174 scoped_ptr<AudioDecoder> audio_decoder_;
175
176 // Manages sending/receiving of RTCP packets, including sender/receiver
177 // reports.
158 Rtcp rtcp_; 178 Rtcp rtcp_;
159 base::TimeDelta time_offset_; 179
160 base::TimeTicks time_first_incoming_packet_; 180 // Decrypts encrypted frames.
161 uint32 first_incoming_rtp_timestamp_;
162 transport::TransportEncryptionHandler decryptor_; 181 transport::TransportEncryptionHandler decryptor_;
163 182
164 // Outstanding callbacks to run to deliver on client requests for frames. 183 // Outstanding callbacks to run to deliver on client requests for frames.
165 std::list<AudioFrameEncodedCallback> frame_request_queue_; 184 std::list<AudioFrameEncodedCallback> frame_request_queue_;
166 185
167 // True while there's an outstanding task to re-invoke 186 // True while there's an outstanding task to re-invoke
168 // EmitAvailableEncodedFrames(). 187 // EmitAvailableEncodedFrames().
169 bool is_waiting_for_consecutive_frame_; 188 bool is_waiting_to_emit_frames_;
170 189
171 // This mapping allows us to log AUDIO_ACK_SENT as a frame event. In addition 190 // This mapping allows us to log AUDIO_ACK_SENT as a frame event. In addition
172 // it allows the event to be transmitted via RTCP. 191 // it allows the event to be transmitted via RTCP.
173 RtpTimestamp frame_id_to_rtp_timestamp_[256]; 192 RtpTimestamp frame_id_to_rtp_timestamp_[256];
174 193
175 // NOTE: Weak pointers must be invalidated before all other member variables. 194 // NOTE: Weak pointers must be invalidated before all other member variables.
176 base::WeakPtrFactory<AudioReceiver> weak_factory_; 195 base::WeakPtrFactory<AudioReceiver> weak_factory_;
177 196
178 DISALLOW_COPY_AND_ASSIGN(AudioReceiver); 197 DISALLOW_COPY_AND_ASSIGN(AudioReceiver);
179 }; 198 };
180 199
181 } // namespace cast 200 } // namespace cast
182 } // namespace media 201 } // namespace media
183 202
184 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_ 203 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_
OLDNEW
« no previous file with comments | « no previous file | media/cast/audio_receiver/audio_receiver.cc » ('j') | media/cast/audio_receiver/audio_receiver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698