| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 }; | 212 }; |
| 213 typedef std::set<uint16_t, SequenceNumberLessThan> SequenceNumberSet; | 213 typedef std::set<uint16_t, SequenceNumberLessThan> SequenceNumberSet; |
| 214 | 214 |
| 215 // Gets the frame assigned to the timestamp of the packet. May recycle | 215 // Gets the frame assigned to the timestamp of the packet. May recycle |
| 216 // existing frames if no free frames are available. Returns an error code if | 216 // existing frames if no free frames are available. Returns an error code if |
| 217 // failing, or kNoError on success. |frame_list| contains which list the | 217 // failing, or kNoError on success. |frame_list| contains which list the |
| 218 // packet was in, or NULL if it was not in a FrameList (a new frame). | 218 // packet was in, or NULL if it was not in a FrameList (a new frame). |
| 219 VCMFrameBufferEnum GetFrame(const VCMPacket& packet, | 219 VCMFrameBufferEnum GetFrame(const VCMPacket& packet, |
| 220 VCMFrameBuffer** frame, | 220 VCMFrameBuffer** frame, |
| 221 FrameList** frame_list) | 221 FrameList** frame_list) |
| 222 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 222 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 223 | 223 |
| 224 // Returns true if |frame| is continuous in |decoding_state|, not taking | 224 // Returns true if |frame| is continuous in |decoding_state|, not taking |
| 225 // decodable frames into account. | 225 // decodable frames into account. |
| 226 bool IsContinuousInState(const VCMFrameBuffer& frame, | 226 bool IsContinuousInState(const VCMFrameBuffer& frame, |
| 227 const VCMDecodingState& decoding_state) const | 227 const VCMDecodingState& decoding_state) const |
| 228 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 228 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 229 // Returns true if |frame| is continuous in the |last_decoded_state_|, taking | 229 // Returns true if |frame| is continuous in the |last_decoded_state_|, taking |
| 230 // all decodable frames into account. | 230 // all decodable frames into account. |
| 231 bool IsContinuous(const VCMFrameBuffer& frame) const | 231 bool IsContinuous(const VCMFrameBuffer& frame) const |
| 232 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 232 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 233 // Looks for frames in |incomplete_frames_| which are continuous in the | 233 // Looks for frames in |incomplete_frames_| which are continuous in the |
| 234 // provided |decoded_state|. Starts the search from the timestamp of | 234 // provided |decoded_state|. Starts the search from the timestamp of |
| 235 // |decoded_state|. | 235 // |decoded_state|. |
| 236 void FindAndInsertContinuousFramesWithState( | 236 void FindAndInsertContinuousFramesWithState( |
| 237 const VCMDecodingState& decoded_state) | 237 const VCMDecodingState& decoded_state) |
| 238 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 238 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 239 // Looks for frames in |incomplete_frames_| which are continuous in | 239 // Looks for frames in |incomplete_frames_| which are continuous in |
| 240 // |last_decoded_state_| taking all decodable frames into account. Starts | 240 // |last_decoded_state_| taking all decodable frames into account. Starts |
| 241 // the search from |new_frame|. | 241 // the search from |new_frame|. |
| 242 void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame) | 242 void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame) |
| 243 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 243 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 244 VCMFrameBuffer* NextFrame() const EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 244 VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 245 // Returns true if the NACK list was updated to cover sequence numbers up to | 245 // Returns true if the NACK list was updated to cover sequence numbers up to |
| 246 // |sequence_number|. If false a key frame is needed to get into a state where | 246 // |sequence_number|. If false a key frame is needed to get into a state where |
| 247 // we can continue decoding. | 247 // we can continue decoding. |
| 248 bool UpdateNackList(uint16_t sequence_number) | 248 bool UpdateNackList(uint16_t sequence_number) |
| 249 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 249 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 250 bool TooLargeNackList() const; | 250 bool TooLargeNackList() const; |
| 251 // Returns true if the NACK list was reduced without problem. If false a key | 251 // Returns true if the NACK list was reduced without problem. If false a key |
| 252 // frame is needed to get into a state where we can continue decoding. | 252 // frame is needed to get into a state where we can continue decoding. |
| 253 bool HandleTooLargeNackList() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 253 bool HandleTooLargeNackList() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 254 bool MissingTooOldPacket(uint16_t latest_sequence_number) const | 254 bool MissingTooOldPacket(uint16_t latest_sequence_number) const |
| 255 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 255 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 256 // Returns true if the too old packets was successfully removed from the NACK | 256 // Returns true if the too old packets was successfully removed from the NACK |
| 257 // list. If false, a key frame is needed to get into a state where we can | 257 // list. If false, a key frame is needed to get into a state where we can |
| 258 // continue decoding. | 258 // continue decoding. |
| 259 bool HandleTooOldPackets(uint16_t latest_sequence_number) | 259 bool HandleTooOldPackets(uint16_t latest_sequence_number) |
| 260 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 260 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 261 // Drops all packets in the NACK list up until |last_decoded_sequence_number|. | 261 // Drops all packets in the NACK list up until |last_decoded_sequence_number|. |
| 262 void DropPacketsFromNackList(uint16_t last_decoded_sequence_number); | 262 void DropPacketsFromNackList(uint16_t last_decoded_sequence_number); |
| 263 | 263 |
| 264 // Gets an empty frame, creating a new frame if necessary (i.e. increases | 264 // Gets an empty frame, creating a new frame if necessary (i.e. increases |
| 265 // jitter buffer size). | 265 // jitter buffer size). |
| 266 VCMFrameBuffer* GetEmptyFrame() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 266 VCMFrameBuffer* GetEmptyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 267 | 267 |
| 268 // Attempts to increase the size of the jitter buffer. Returns true on | 268 // Attempts to increase the size of the jitter buffer. Returns true on |
| 269 // success, false otherwise. | 269 // success, false otherwise. |
| 270 bool TryToIncreaseJitterBufferSize() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 270 bool TryToIncreaseJitterBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 271 | 271 |
| 272 // Recycles oldest frames until a key frame is found. Used if jitter buffer is | 272 // Recycles oldest frames until a key frame is found. Used if jitter buffer is |
| 273 // completely full. Returns true if a key frame was found. | 273 // completely full. Returns true if a key frame was found. |
| 274 bool RecycleFramesUntilKeyFrame() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 274 bool RecycleFramesUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 275 | 275 |
| 276 // Updates the frame statistics. | 276 // Updates the frame statistics. |
| 277 // Counts only complete frames, so decodable incomplete frames will not be | 277 // Counts only complete frames, so decodable incomplete frames will not be |
| 278 // counted. | 278 // counted. |
| 279 void CountFrame(const VCMFrameBuffer& frame) | 279 void CountFrame(const VCMFrameBuffer& frame) |
| 280 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 280 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 281 | 281 |
| 282 // Update rolling average of packets per frame. | 282 // Update rolling average of packets per frame. |
| 283 void UpdateAveragePacketsPerFrame(int current_number_packets_); | 283 void UpdateAveragePacketsPerFrame(int current_number_packets_); |
| 284 | 284 |
| 285 // Cleans the frame list in the JB from old/empty frames. | 285 // Cleans the frame list in the JB from old/empty frames. |
| 286 // Should only be called prior to actual use. | 286 // Should only be called prior to actual use. |
| 287 void CleanUpOldOrEmptyFrames() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 287 void CleanUpOldOrEmptyFrames() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 288 | 288 |
| 289 // Returns true if |packet| is likely to have been retransmitted. | 289 // Returns true if |packet| is likely to have been retransmitted. |
| 290 bool IsPacketRetransmitted(const VCMPacket& packet) const; | 290 bool IsPacketRetransmitted(const VCMPacket& packet) const; |
| 291 | 291 |
| 292 // The following three functions update the jitter estimate with the | 292 // The following three functions update the jitter estimate with the |
| 293 // payload size, receive time and RTP timestamp of a frame. | 293 // payload size, receive time and RTP timestamp of a frame. |
| 294 void UpdateJitterEstimate(const VCMJitterSample& sample, | 294 void UpdateJitterEstimate(const VCMJitterSample& sample, |
| 295 bool incomplete_frame); | 295 bool incomplete_frame); |
| 296 void UpdateJitterEstimate(const VCMFrameBuffer& frame, bool incomplete_frame); | 296 void UpdateJitterEstimate(const VCMFrameBuffer& frame, bool incomplete_frame); |
| 297 void UpdateJitterEstimate(int64_t latest_packet_time_ms, | 297 void UpdateJitterEstimate(int64_t latest_packet_time_ms, |
| 298 uint32_t timestamp, | 298 uint32_t timestamp, |
| 299 unsigned int frame_size, | 299 unsigned int frame_size, |
| 300 bool incomplete_frame); | 300 bool incomplete_frame); |
| 301 | 301 |
| 302 // Returns true if we should wait for retransmissions, false otherwise. | 302 // Returns true if we should wait for retransmissions, false otherwise. |
| 303 bool WaitForRetransmissions(); | 303 bool WaitForRetransmissions(); |
| 304 | 304 |
| 305 int NonContinuousOrIncompleteDuration() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 305 int NonContinuousOrIncompleteDuration() |
| 306 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 306 | 307 |
| 307 uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const; | 308 uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const; |
| 308 | 309 |
| 309 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 310 void UpdateHistograms() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 310 | 311 |
| 311 // Reset frame buffer and return it to free_frames_. | 312 // Reset frame buffer and return it to free_frames_. |
| 312 void RecycleFrameBuffer(VCMFrameBuffer* frame) | 313 void RecycleFrameBuffer(VCMFrameBuffer* frame) |
| 313 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 314 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 314 | 315 |
| 315 Clock* clock_; | 316 Clock* clock_; |
| 316 // If we are running (have started) or not. | 317 // If we are running (have started) or not. |
| 317 bool running_; | 318 bool running_; |
| 318 rtc::CriticalSection crit_sect_; | 319 rtc::CriticalSection crit_sect_; |
| 319 // Event to signal when we have a frame ready for decoder. | 320 // Event to signal when we have a frame ready for decoder. |
| 320 std::unique_ptr<EventWrapper> frame_event_; | 321 std::unique_ptr<EventWrapper> frame_event_; |
| 321 // Number of allocated frames. | 322 // Number of allocated frames. |
| 322 int max_number_of_frames_; | 323 int max_number_of_frames_; |
| 323 UnorderedFrameList free_frames_ GUARDED_BY(crit_sect_); | 324 UnorderedFrameList free_frames_ RTC_GUARDED_BY(crit_sect_); |
| 324 FrameList decodable_frames_ GUARDED_BY(crit_sect_); | 325 FrameList decodable_frames_ RTC_GUARDED_BY(crit_sect_); |
| 325 FrameList incomplete_frames_ GUARDED_BY(crit_sect_); | 326 FrameList incomplete_frames_ RTC_GUARDED_BY(crit_sect_); |
| 326 VCMDecodingState last_decoded_state_ GUARDED_BY(crit_sect_); | 327 VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(crit_sect_); |
| 327 bool first_packet_since_reset_; | 328 bool first_packet_since_reset_; |
| 328 | 329 |
| 329 // Statistics. | 330 // Statistics. |
| 330 VCMReceiveStatisticsCallback* stats_callback_ GUARDED_BY(crit_sect_); | 331 VCMReceiveStatisticsCallback* stats_callback_ RTC_GUARDED_BY(crit_sect_); |
| 331 // Frame counts for each type (key, delta, ...) | 332 // Frame counts for each type (key, delta, ...) |
| 332 FrameCounts receive_statistics_; | 333 FrameCounts receive_statistics_; |
| 333 // Latest calculated frame rates of incoming stream. | 334 // Latest calculated frame rates of incoming stream. |
| 334 unsigned int incoming_frame_rate_; | 335 unsigned int incoming_frame_rate_; |
| 335 unsigned int incoming_frame_count_; | 336 unsigned int incoming_frame_count_; |
| 336 int64_t time_last_incoming_frame_count_; | 337 int64_t time_last_incoming_frame_count_; |
| 337 unsigned int incoming_bit_count_; | 338 unsigned int incoming_bit_count_; |
| 338 unsigned int incoming_bit_rate_; | 339 unsigned int incoming_bit_rate_; |
| 339 // Number of packets in a row that have been too old. | 340 // Number of packets in a row that have been too old. |
| 340 int num_consecutive_old_packets_; | 341 int num_consecutive_old_packets_; |
| 341 // Number of packets received. | 342 // Number of packets received. |
| 342 int num_packets_ GUARDED_BY(crit_sect_); | 343 int num_packets_ RTC_GUARDED_BY(crit_sect_); |
| 343 // Number of duplicated packets received. | 344 // Number of duplicated packets received. |
| 344 int num_duplicated_packets_ GUARDED_BY(crit_sect_); | 345 int num_duplicated_packets_ RTC_GUARDED_BY(crit_sect_); |
| 345 // Number of packets discarded by the jitter buffer. | 346 // Number of packets discarded by the jitter buffer. |
| 346 int num_discarded_packets_ GUARDED_BY(crit_sect_); | 347 int num_discarded_packets_ RTC_GUARDED_BY(crit_sect_); |
| 347 // Time when first packet is received. | 348 // Time when first packet is received. |
| 348 int64_t time_first_packet_ms_ GUARDED_BY(crit_sect_); | 349 int64_t time_first_packet_ms_ RTC_GUARDED_BY(crit_sect_); |
| 349 | 350 |
| 350 // Jitter estimation. | 351 // Jitter estimation. |
| 351 // Filter for estimating jitter. | 352 // Filter for estimating jitter. |
| 352 VCMJitterEstimator jitter_estimate_; | 353 VCMJitterEstimator jitter_estimate_; |
| 353 // Calculates network delays used for jitter calculations. | 354 // Calculates network delays used for jitter calculations. |
| 354 VCMInterFrameDelay inter_frame_delay_; | 355 VCMInterFrameDelay inter_frame_delay_; |
| 355 VCMJitterSample waiting_for_completion_; | 356 VCMJitterSample waiting_for_completion_; |
| 356 int64_t rtt_ms_; | 357 int64_t rtt_ms_; |
| 357 | 358 |
| 358 // NACK and retransmissions. | 359 // NACK and retransmissions. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 371 float average_packets_per_frame_; | 372 float average_packets_per_frame_; |
| 372 // average_packets_per_frame converges fast if we have fewer than this many | 373 // average_packets_per_frame converges fast if we have fewer than this many |
| 373 // frames. | 374 // frames. |
| 374 int frame_counter_; | 375 int frame_counter_; |
| 375 | 376 |
| 376 RTC_DISALLOW_COPY_AND_ASSIGN(VCMJitterBuffer); | 377 RTC_DISALLOW_COPY_AND_ASSIGN(VCMJitterBuffer); |
| 377 }; | 378 }; |
| 378 } // namespace webrtc | 379 } // namespace webrtc |
| 379 | 380 |
| 380 #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_BUFFER_H_ | 381 #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_BUFFER_H_ |
| OLD | NEW |