niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 8fe03af | 2012-01-23 14:56:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
| 12 | #define MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 3f55dea | 2016-02-29 05:51:59 -0800 | [diff] [blame] | 14 | #include <memory> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/include/module_common_types.h" |
| 17 | #include "modules/video_coding/include/video_coding.h" |
| 18 | #include "modules/video_coding/media_opt_util.h" |
| 19 | #include "rtc_base/criticalsection.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 23 | class Clock; |
stefan@webrtc.org | eb91792 | 2013-02-18 14:40:18 +0000 | [diff] [blame] | 24 | class FrameDropper; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 26 | namespace media_optimization { |
| 27 | |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 28 | class MediaOptimization { |
| 29 | public: |
stefan@webrtc.org | 34c5da6 | 2014-04-11 14:08:35 +0000 | [diff] [blame] | 30 | explicit MediaOptimization(Clock* clock); |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 31 | ~MediaOptimization(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 33 | // TODO(andresp): Can Reset and SetEncodingData be done at construction time |
| 34 | // only? |
| 35 | void Reset(); |
| 36 | |
| 37 | // Informs media optimization of initial encoding state. |
Per | 69b332d | 2016-06-02 15:45:42 +0200 | [diff] [blame] | 38 | // TODO(perkj): Deprecate SetEncodingData once its not used for stats in |
Åsa Persson | b52a4d9 | 2017-11-08 11:33:37 +0100 | [diff] [blame] | 39 | // VideoStreamEncoder. |
Per | 69b332d | 2016-06-02 15:45:42 +0200 | [diff] [blame] | 40 | void SetEncodingData(int32_t max_bit_rate, |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 41 | uint32_t bit_rate, |
Åsa Persson | b52a4d9 | 2017-11-08 11:33:37 +0100 | [diff] [blame] | 42 | uint32_t max_frame_rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 44 | // Sets target rates for the encoder given the channel parameters. |
asapersson | 60dfbdb | 2017-08-07 00:03:03 -0700 | [diff] [blame] | 45 | // Input: |target bitrate| - the encoder target bitrate in bits/s. |
asapersson | 9abd275 | 2016-12-08 02:19:40 -0800 | [diff] [blame] | 46 | uint32_t SetTargetRates(uint32_t target_bitrate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 48 | void EnableFrameDropper(bool enable); |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 49 | bool DropFrame(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 51 | // Informs Media Optimization of encoded output. |
Per | 69b332d | 2016-06-02 15:45:42 +0200 | [diff] [blame] | 52 | // TODO(perkj): Deprecate SetEncodingData once its not used for stats in |
Åsa Persson | b52a4d9 | 2017-11-08 11:33:37 +0100 | [diff] [blame] | 53 | // VideoStreamEncoder. |
Taylor Brandstetter | 0073301 | 2018-02-15 20:07:11 +0000 | [diff] [blame] | 54 | void UpdateWithEncodedData(const EncodedImage& encoded_image); |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 55 | |
Erik Språng | 66a641a | 2015-06-11 14:20:07 +0200 | [diff] [blame] | 56 | // InputFrameRate 0 = no frame rate estimate available. |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 57 | uint32_t InputFrameRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 59 | private: |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 60 | enum { kFrameCountHistorySize = 90 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 62 | void UpdateIncomingFrameRate() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
wuchengli@chromium.org | ae7cfd7 | 2014-06-30 08:01:47 +0000 | [diff] [blame] | 63 | void ProcessIncomingFrameRate(int64_t now) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 64 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 65 | uint32_t InputFrameRateInternal() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
wuchengli@chromium.org | ae7cfd7 | 2014-06-30 08:01:47 +0000 | [diff] [blame] | 66 | |
wuchengli@chromium.org | ae7cfd7 | 2014-06-30 08:01:47 +0000 | [diff] [blame] | 67 | // Protect all members. |
kthelgason | d701dfd | 2017-03-27 07:24:57 -0700 | [diff] [blame] | 68 | rtc::CriticalSection crit_sect_; |
wuchengli@chromium.org | ae7cfd7 | 2014-06-30 08:01:47 +0000 | [diff] [blame] | 69 | |
Åsa Persson | b52a4d9 | 2017-11-08 11:33:37 +0100 | [diff] [blame] | 70 | Clock* const clock_ RTC_GUARDED_BY(crit_sect_); |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 71 | int32_t max_bit_rate_ RTC_GUARDED_BY(crit_sect_); |
Åsa Persson | b52a4d9 | 2017-11-08 11:33:37 +0100 | [diff] [blame] | 72 | float max_frame_rate_ RTC_GUARDED_BY(crit_sect_); |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 73 | std::unique_ptr<FrameDropper> frame_dropper_ RTC_GUARDED_BY(crit_sect_); |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 74 | float incoming_frame_rate_ RTC_GUARDED_BY(crit_sect_); |
| 75 | int64_t incoming_frame_times_[kFrameCountHistorySize] RTC_GUARDED_BY( |
| 76 | crit_sect_); |
andresp@webrtc.org | e682aa5 | 2013-12-19 10:59:48 +0000 | [diff] [blame] | 77 | }; |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 78 | } // namespace media_optimization |
| 79 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 81 | #endif // MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |