jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 11 | #ifndef WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 12 | #define WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
kwiberg | 4485ffb | 2016-04-26 08:14:39 -0700 | [diff] [blame] | 14 | #include "webrtc/base/constructormagic.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 15 | #include "webrtc/base/criticalsection.h" |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 16 | #include "webrtc/base/optional.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 17 | #include "webrtc/media/base/videocommon.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
| 19 | namespace cricket { |
| 20 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | // VideoAdapter adapts an input video frame to an output frame based on the |
| 22 | // specified input and output formats. The adaptation includes dropping frames |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 23 | // to reduce frame rate and scaling frames. |
| 24 | // VideoAdapter is thread safe. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | class VideoAdapter { |
| 26 | public: |
| 27 | VideoAdapter(); |
| 28 | virtual ~VideoAdapter(); |
| 29 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 30 | // Sets the expected frame interval. This controls how often frames should |
| 31 | // be dropped if |OnOutputFormatRequest| is called with a lower frame |
| 32 | // interval. |
| 33 | void SetExpectedInputFrameInterval(int64_t interval); |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 34 | |
| 35 | // Return the adapted resolution given the input resolution. The returned |
| 36 | // resolution will be 0x0 if the frame should be dropped. |
| 37 | VideoFormat AdaptFrameResolution(int in_width, int in_height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 39 | // Requests the output frame size and frame interval from |
| 40 | // |AdaptFrameResolution| to not be larger than |format|. |
| 41 | void OnOutputFormatRequest(const VideoFormat& format); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 42 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 43 | // Requests the output frame size from |AdaptFrameResolution| to not have |
| 44 | // more than |max_pixel_count| pixels and have "one step" up more pixels than |
| 45 | // max_pixel_count_step_up. |
| 46 | void OnResolutionRequest(rtc::Optional<int> max_pixel_count, |
| 47 | rtc::Optional<int> max_pixel_count_step_up); |
buildbot@webrtc.org | 71dffb7 | 2014-06-24 07:24:49 +0000 | [diff] [blame] | 48 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 49 | const VideoFormat& input_format() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | |
| 51 | private: |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 52 | void SetInputFormat(const VideoFormat& format); |
| 53 | bool Adapt(int max_num_pixels, int max_pixel_count_step_up); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | |
| 55 | VideoFormat input_format_; |
| 56 | VideoFormat output_format_; |
| 57 | int output_num_pixels_; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 58 | int frames_in_; // Number of input frames. |
| 59 | int frames_out_; // Number of output frames. |
| 60 | int frames_scaled_; // Number of frames scaled. |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 61 | int adaption_changes_; // Number of changes in scale factor. |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 62 | int previous_width_; // Previous adapter output width. |
| 63 | int previous_height_; // Previous adapter output height. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 64 | int64_t interval_next_frame_; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 65 | |
| 66 | // Max number of pixels requested via calls to OnOutputFormatRequest, |
| 67 | // OnResolutionRequest respectively. |
| 68 | // The adapted output format is the minimum of these. |
| 69 | int format_request_max_pixel_count_; |
| 70 | int resolution_request_max_pixel_count_; |
| 71 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | // The critical section to protect the above variables. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 73 | rtc::CriticalSection critical_section_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 75 | RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | } // namespace cricket |
| 79 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 80 | #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ |