Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 15 matching lines...) Expand all Loading... | |
| 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 |
| 153 const transport::AudioCodec codec_; | 148 const transport::AudioCodec codec_; |
| 154 const int frequency_; | 149 const int frequency_; |
| 155 base::TimeDelta target_delay_delta_; | 150 base::TimeDelta target_playout_delay_; |
| 151 bool reports_are_scheduled_; | |
|
hubbe
2014/05/14 23:12:23
Maybe add comments for these variables?
miu
2014/05/16 22:45:47
Done.
| |
| 156 Framer framer_; | 152 Framer framer_; |
| 157 scoped_ptr<AudioDecoder> audio_decoder_; | 153 scoped_ptr<AudioDecoder> audio_decoder_; |
| 158 Rtcp rtcp_; | 154 Rtcp rtcp_; |
| 159 base::TimeDelta time_offset_; | |
| 160 base::TimeTicks time_first_incoming_packet_; | |
| 161 uint32 first_incoming_rtp_timestamp_; | |
| 162 transport::TransportEncryptionHandler decryptor_; | 155 transport::TransportEncryptionHandler decryptor_; |
| 163 | 156 |
| 164 // Outstanding callbacks to run to deliver on client requests for frames. | 157 // Outstanding callbacks to run to deliver on client requests for frames. |
| 165 std::list<AudioFrameEncodedCallback> frame_request_queue_; | 158 std::list<AudioFrameEncodedCallback> frame_request_queue_; |
| 166 | 159 |
| 167 // True while there's an outstanding task to re-invoke | 160 // True while there's an outstanding task to re-invoke |
| 168 // EmitAvailableEncodedFrames(). | 161 // EmitAvailableEncodedFrames(). |
| 169 bool is_waiting_for_consecutive_frame_; | 162 bool is_waiting_to_emit_frames_; |
| 170 | 163 |
| 171 // This mapping allows us to log AUDIO_ACK_SENT as a frame event. In addition | 164 // 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. | 165 // it allows the event to be transmitted via RTCP. |
| 173 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | 166 RtpTimestamp frame_id_to_rtp_timestamp_[256]; |
| 174 | 167 |
| 175 // NOTE: Weak pointers must be invalidated before all other member variables. | 168 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 176 base::WeakPtrFactory<AudioReceiver> weak_factory_; | 169 base::WeakPtrFactory<AudioReceiver> weak_factory_; |
| 177 | 170 |
| 178 DISALLOW_COPY_AND_ASSIGN(AudioReceiver); | 171 DISALLOW_COPY_AND_ASSIGN(AudioReceiver); |
| 179 }; | 172 }; |
| 180 | 173 |
| 181 } // namespace cast | 174 } // namespace cast |
| 182 } // namespace media | 175 } // namespace media |
| 183 | 176 |
| 184 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_ | 177 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_RECEIVER_H_ |
| OLD | NEW |