isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_PLAYOUT_DELAY_ORACLE_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_SOURCE_PLAYOUT_DELAY_ORACLE_H_ |
| 13 | |
pbos | 67d12ed | 2017-01-02 16:42:32 | [diff] [blame] | 14 | #include <stdint.h> |
| 15 | |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 16 | #include "webrtc/modules/include/module_common_types.h" |
| 17 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 18 | #include "webrtc/rtc_base/criticalsection.h" |
| 19 | #include "webrtc/rtc_base/thread_annotations.h" |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // This class tracks the application requests to limit minimum and maximum |
| 24 | // playout delay and makes a decision on whether the current RTP frame |
| 25 | // should include the playout out delay extension header. |
| 26 | // |
| 27 | // Playout delay can be defined in terms of capture and render time as follows: |
| 28 | // |
| 29 | // Render time = Capture time in receiver time + playout delay |
| 30 | // |
| 31 | // The application specifies a minimum and maximum limit for the playout delay |
| 32 | // which are both communicated to the receiver and the receiver can adapt |
| 33 | // the playout delay within this range based on observed network jitter. |
| 34 | class PlayoutDelayOracle { |
| 35 | public: |
| 36 | PlayoutDelayOracle(); |
| 37 | ~PlayoutDelayOracle(); |
| 38 | |
| 39 | // Returns true if the current frame should include the playout delay |
| 40 | // extension |
| 41 | bool send_playout_delay() const { |
| 42 | rtc::CritScope lock(&crit_sect_); |
| 43 | return send_playout_delay_; |
| 44 | } |
| 45 | |
Danil Chapovalov | 812fea5 | 2016-09-07 11:29:47 | [diff] [blame] | 46 | // Returns current playout delay. |
| 47 | PlayoutDelay playout_delay() const { |
isheriff | 338a67c | 2016-06-14 17:55:36 | [diff] [blame] | 48 | rtc::CritScope lock(&crit_sect_); |
Danil Chapovalov | 812fea5 | 2016-09-07 11:29:47 | [diff] [blame] | 49 | return playout_delay_; |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // Updates the application requested playout delay, current ssrc |
| 53 | // and the current sequence number. |
| 54 | void UpdateRequest(uint32_t ssrc, |
| 55 | PlayoutDelay playout_delay, |
| 56 | uint16_t seq_num); |
| 57 | |
| 58 | void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); |
| 59 | |
| 60 | private: |
isheriff | 338a67c | 2016-06-14 17:55:36 | [diff] [blame] | 61 | // The playout delay information is updated from the encoder thread(s). |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 62 | // The sequence number feedback is updated from the worker thread. |
isheriff | 338a67c | 2016-06-14 17:55:36 | [diff] [blame] | 63 | // Guards access to data across multiple threads. |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 64 | rtc::CriticalSection crit_sect_; |
| 65 | // The current highest sequence number on which playout delay has been sent. |
danilchap | c4ae80f | 2017-09-07 14:53:45 | [diff] [blame] | 66 | int64_t high_sequence_number_ RTC_GUARDED_BY(crit_sect_); |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 67 | // Indicates whether the playout delay should go on the next frame. |
danilchap | c4ae80f | 2017-09-07 14:53:45 | [diff] [blame] | 68 | bool send_playout_delay_ RTC_GUARDED_BY(crit_sect_); |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 69 | // Sender ssrc. |
danilchap | c4ae80f | 2017-09-07 14:53:45 | [diff] [blame] | 70 | uint32_t ssrc_ RTC_GUARDED_BY(crit_sect_); |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 71 | // Sequence number unwrapper. |
danilchap | c4ae80f | 2017-09-07 14:53:45 | [diff] [blame] | 72 | SequenceNumberUnwrapper unwrapper_ RTC_GUARDED_BY(crit_sect_); |
Danil Chapovalov | 812fea5 | 2016-09-07 11:29:47 | [diff] [blame] | 73 | // Playout delay values on the next frame if |send_playout_delay_| is set. |
danilchap | c4ae80f | 2017-09-07 14:53:45 | [diff] [blame] | 74 | PlayoutDelay playout_delay_ RTC_GUARDED_BY(crit_sect_); |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 75 | |
| 76 | RTC_DISALLOW_COPY_AND_ASSIGN(PlayoutDelayOracle); |
| 77 | }; |
| 78 | |
| 79 | } // namespace webrtc |
| 80 | |
| 81 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_PLAYOUT_DELAY_ORACLE_H_ |