Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: webrtc/media/base/videoadapter.h

Issue 2698203003: Update sink wants with ranges for both pixel count and frame rate.
Patch Set: Slightly updated sink wants merging in videobroadcaster Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "webrtc/media/base/videosourceinterface.h"
18 19
19 namespace cricket { 20 namespace cricket {
20 21
21 // VideoAdapter adapts an input video frame to an output frame based on the 22 // VideoAdapter adapts an input video frame to an output frame based on the
22 // specified input and output formats. The adaptation includes dropping frames 23 // specified input and output formats. The adaptation includes dropping frames
23 // to reduce frame rate and scaling frames. 24 // to reduce frame rate and scaling frames.
24 // VideoAdapter is thread safe. 25 // VideoAdapter is thread safe.
25 class VideoAdapter { 26 class VideoAdapter {
26 public: 27 public:
27 VideoAdapter(); 28 VideoAdapter();
28 VideoAdapter(int required_resolution_alignment); 29 explicit VideoAdapter(int required_resolution_alignment);
29 virtual ~VideoAdapter(); 30 virtual ~VideoAdapter();
30 31
31 // Return the adapted resolution and cropping parameters given the 32 // Return the adapted resolution and cropping parameters given the
32 // input resolution. The input frame should first be cropped, then 33 // input resolution. The input frame should first be cropped, then
33 // scaled to the final output resolution. Returns true if the frame 34 // scaled to the final output resolution. Returns true if the frame
34 // should be adapted, and false if it should be dropped. 35 // should be adapted, and false if it should be dropped.
35 bool AdaptFrameResolution(int in_width, 36 bool AdaptFrameResolution(int in_width,
36 int in_height, 37 int in_height,
37 int64_t in_timestamp_ns, 38 int64_t in_timestamp_ns,
38 int* cropped_width, 39 int* cropped_width,
39 int* cropped_height, 40 int* cropped_height,
40 int* out_width, 41 int* out_width,
41 int* out_height); 42 int* out_height);
42 43
43 // Requests the output frame size and frame interval from 44 // Requests the output frame size and frame interval from
44 // |AdaptFrameResolution| to not be larger than |format|. Also, the input 45 // |AdaptFrameResolution| to not be larger than |format|. Also, the input
45 // frame size will be cropped to match the requested aspect ratio. The 46 // frame size will be cropped to match the requested aspect ratio. The
46 // requested aspect ratio is orientation agnostic and will be adjusted to 47 // 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 48 // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or
48 // 720x1280 is requested. 49 // 720x1280 is requested.
49 void OnOutputFormatRequest(const VideoFormat& format); 50 void OnOutputFormatRequest(const VideoFormat& format);
50 51
51 // Requests the output frame size from |AdaptFrameResolution| to have as close 52 // Requests resolution and/or framerate to be restricted according to the
52 // as possible to |target_pixel_count|, but no more than |max_pixel_count| 53 // constraints specified.
53 // pixels. If |target_pixel_count| is not set, treat it as being equal to 54 void OnResolutionFramerateRequest(
54 // |max_pixel_count|. If |max_pixel_count| is not set, treat is as being the 55 const rtc::Optional<rtc::VideoSinkWants::Range>& pixel_count,
55 // highest resolution available. 56 const rtc::Optional<rtc::VideoSinkWants::Range>& framerate_fps);
56 void OnResolutionRequest(const rtc::Optional<int>& target_pixel_count,
57 const rtc::Optional<int>& max_pixel_count);
58 57
59 private: 58 private:
60 // Determine if frame should be dropped based on input fps and requested fps. 59 // Determine if frame should be dropped based on input fps and requested fps.
61 bool KeepFrame(int64_t in_timestamp_ns); 60 bool KeepFrame(int64_t in_timestamp_ns);
62 61
63 int frames_in_; // Number of input frames. 62 int frames_in_; // Number of input frames.
64 int frames_out_; // Number of output frames. 63 int frames_out_; // Number of output frames.
65 int frames_scaled_; // Number of frames scaled. 64 int frames_scaled_; // Number of frames scaled.
66 int adaption_changes_; // Number of changes in scale factor. 65 int adaption_changes_; // Number of changes in scale factor.
67 int previous_width_; // Previous adapter output width. 66 int previous_width_; // Previous adapter output width.
68 int previous_height_; // Previous adapter output height. 67 int previous_height_; // Previous adapter output height.
69 // Resolution must be divisible by this factor. 68 // Resolution must be divisible by this factor.
70 const int required_resolution_alignment_; 69 const int required_resolution_alignment_;
71 // The target timestamp for the next frame based on requested format. 70 // The target timestamp for the next frame based on requested format.
72 rtc::Optional<int64_t> next_frame_timestamp_ns_ GUARDED_BY(critical_section_); 71 rtc::Optional<int64_t> next_frame_timestamp_ns_ GUARDED_BY(critical_section_);
73 72
74 // Max number of pixels requested via calls to OnOutputFormatRequest, 73 // Max number of pixels requested via calls to OnOutputFormatRequest,
75 // OnResolutionRequest respectively. 74 // OnResolutionRequest respectively.
76 // The adapted output format is the minimum of these. 75 // The adapted output format is the minimum of these.
77 rtc::Optional<VideoFormat> requested_format_ GUARDED_BY(critical_section_); 76 rtc::Optional<VideoFormat> requested_format_ GUARDED_BY(critical_section_);
78 int resolution_request_target_pixel_count_ GUARDED_BY(critical_section_); 77 rtc::Optional<rtc::VideoSinkWants::Range> requested_pixel_count_
79 int resolution_request_max_pixel_count_ GUARDED_BY(critical_section_); 78 GUARDED_BY(critical_section_);
79 rtc::Optional<rtc::VideoSinkWants::Range> requested_framerate_fps_
80 GUARDED_BY(critical_section_);
80 81
81 // The critical section to protect the above variables. 82 // The critical section to protect the above variables.
82 rtc::CriticalSection critical_section_; 83 rtc::CriticalSection critical_section_;
83 84
84 RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter); 85 RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter);
85 }; 86 };
86 87
87 } // namespace cricket 88 } // namespace cricket
88 89
89 #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ 90 #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698