OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 |
11 #ifndef WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ |
12 #define WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ | 12 #define WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ |
13 | 13 |
14 #include "webrtc/base/constructormagic.h" | 14 #include "webrtc/base/constructormagic.h" |
15 #include "webrtc/base/criticalsection.h" | 15 #include "webrtc/base/criticalsection.h" |
16 #include "webrtc/base/optional.h" | 16 #include "webrtc/base/optional.h" |
17 #include "webrtc/media/base/videocommon.h" | 17 #include "webrtc/media/base/videocommon.h" |
18 | 18 |
19 namespace cricket { | 19 namespace cricket { |
20 | 20 |
21 // VideoAdapter adapts an input video frame to an output frame based on the | 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 | 22 // specified input and output formats. The adaptation includes dropping frames |
23 // to reduce frame rate and scaling frames. | 23 // to reduce frame rate and scaling frames. |
24 // VideoAdapter is thread safe. | 24 // VideoAdapter is thread safe. |
25 class VideoAdapter { | 25 class VideoAdapter { |
26 public: | 26 public: |
27 VideoAdapter(); | 27 VideoAdapter(); |
28 VideoAdapter(int required_resolution_alignment); | 28 explicit VideoAdapter(int required_resolution_alignment); |
nisse-webrtc
2017/03/08 08:08:54
Not your change, but this argument deserves a comm
sprang_webrtc
2017/03/09 13:19:34
Done.
| |
29 virtual ~VideoAdapter(); | 29 virtual ~VideoAdapter(); |
30 | 30 |
31 // Return the adapted resolution and cropping parameters given the | 31 // Return the adapted resolution and cropping parameters given the |
32 // input resolution. The input frame should first be cropped, then | 32 // input resolution. The input frame should first be cropped, then |
33 // scaled to the final output resolution. Returns true if the frame | 33 // scaled to the final output resolution. Returns true if the frame |
34 // should be adapted, and false if it should be dropped. | 34 // should be adapted, and false if it should be dropped. |
35 bool AdaptFrameResolution(int in_width, | 35 bool AdaptFrameResolution(int in_width, |
36 int in_height, | 36 int in_height, |
37 int64_t in_timestamp_ns, | 37 int64_t in_timestamp_ns, |
38 int* cropped_width, | 38 int* cropped_width, |
39 int* cropped_height, | 39 int* cropped_height, |
40 int* out_width, | 40 int* out_width, |
41 int* out_height); | 41 int* out_height); |
42 | 42 |
43 // Requests the output frame size and frame interval from | 43 // Requests the output frame size and frame interval from |
44 // |AdaptFrameResolution| to not be larger than |format|. Also, the input | 44 // |AdaptFrameResolution| to not be larger than |format|. Also, the input |
45 // frame size will be cropped to match the requested aspect ratio. The | 45 // frame size will be cropped to match the requested aspect ratio. The |
46 // requested aspect ratio is orientation agnostic and will be adjusted to | 46 // requested aspect ratio is orientation agnostic and will be adjusted to |
47 // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or | 47 // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or |
48 // 720x1280 is requested. | 48 // 720x1280 is requested. |
49 void OnOutputFormatRequest(const VideoFormat& format); | 49 void OnOutputFormatRequest(const VideoFormat& format); |
50 | 50 |
51 // Requests the output frame size from |AdaptFrameResolution| to have as close | 51 // Requests the output frame size from |AdaptFrameResolution| to have as close |
52 // as possible to |target_pixel_count|, but no more than |max_pixel_count| | 52 // as possible to |target_pixel_count|, but no more than |max_pixel_count| |
53 // pixels. If |target_pixel_count| is not set, treat it as being equal to | 53 // pixels. If |target_pixel_count| is not set, treat it as being equal to |
54 // |max_pixel_count|. If |max_pixel_count| is not set, treat is as being the | 54 // |max_pixel_count|. If |max_pixel_count| is not set, treat is as being the |
55 // highest resolution available. | 55 // highest resolution available. |
56 void OnResolutionRequest(const rtc::Optional<int>& target_pixel_count, | 56 // |framerate_fps| is essentially analogous to |max_pixel_count|, but for |
57 const rtc::Optional<int>& max_pixel_count); | 57 // framerate rather than resolution. |
58 void OnResolutionFramerateRequest( | |
59 const rtc::Optional<int>& target_pixel_count, | |
60 const rtc::Optional<int>& max_pixel_count, | |
61 const rtc::Optional<int>& framerate_fps); | |
58 | 62 |
59 private: | 63 private: |
60 // Determine if frame should be dropped based on input fps and requested fps. | 64 // Determine if frame should be dropped based on input fps and requested fps. |
61 bool KeepFrame(int64_t in_timestamp_ns); | 65 bool KeepFrame(int64_t in_timestamp_ns); |
62 | 66 |
63 int frames_in_; // Number of input frames. | 67 int frames_in_; // Number of input frames. |
64 int frames_out_; // Number of output frames. | 68 int frames_out_; // Number of output frames. |
65 int frames_scaled_; // Number of frames scaled. | 69 int frames_scaled_; // Number of frames scaled. |
66 int adaption_changes_; // Number of changes in scale factor. | 70 int adaption_changes_; // Number of changes in scale factor. |
67 int previous_width_; // Previous adapter output width. | 71 int previous_width_; // Previous adapter output width. |
68 int previous_height_; // Previous adapter output height. | 72 int previous_height_; // Previous adapter output height. |
69 // Resolution must be divisible by this factor. | 73 // Resolution must be divisible by this factor. |
70 const int required_resolution_alignment_; | 74 const int required_resolution_alignment_; |
71 // The target timestamp for the next frame based on requested format. | 75 // The target timestamp for the next frame based on requested format. |
72 rtc::Optional<int64_t> next_frame_timestamp_ns_ GUARDED_BY(critical_section_); | 76 rtc::Optional<int64_t> next_frame_timestamp_ns_ GUARDED_BY(critical_section_); |
73 | 77 |
74 // Max number of pixels requested via calls to OnOutputFormatRequest, | 78 // Max number of pixels requested via calls to OnOutputFormatRequest, |
75 // OnResolutionRequest respectively. | 79 // OnResolutionRequest respectively. |
76 // The adapted output format is the minimum of these. | 80 // The adapted output format is the minimum of these. |
77 rtc::Optional<VideoFormat> requested_format_ GUARDED_BY(critical_section_); | 81 rtc::Optional<VideoFormat> requested_format_ GUARDED_BY(critical_section_); |
78 int resolution_request_target_pixel_count_ GUARDED_BY(critical_section_); | 82 int resolution_request_target_pixel_count_ GUARDED_BY(critical_section_); |
79 int resolution_request_max_pixel_count_ GUARDED_BY(critical_section_); | 83 int resolution_request_max_pixel_count_ GUARDED_BY(critical_section_); |
84 int max_framerate_request_ GUARDED_BY(critical_section_); | |
80 | 85 |
81 // The critical section to protect the above variables. | 86 // The critical section to protect the above variables. |
82 rtc::CriticalSection critical_section_; | 87 rtc::CriticalSection critical_section_; |
83 | 88 |
84 RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter); | 89 RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter); |
85 }; | 90 }; |
86 | 91 |
87 } // namespace cricket | 92 } // namespace cricket |
88 | 93 |
89 #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ | 94 #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ |
OLD | NEW |