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

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

Issue 1982983003: VideoAdapter: Drop frames based on actual fps instead of expected fps (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add jitter test Created 4 years, 7 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
« no previous file with comments | « no previous file | webrtc/media/base/videoadapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 virtual ~VideoAdapter(); 28 virtual ~VideoAdapter();
29 29
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);
34
35 // Return the adapted resolution given the input resolution. The input 30 // Return the adapted resolution given the input resolution. The input
36 // resolution should first be cropped to the specified resolution, and then 31 // resolution should first be cropped to the specified resolution, and then
37 // scaled to the final output resolution. The output resolution will be 0x0 if 32 // scaled to the final output resolution. The output resolution will be 0x0 if
38 // the frame should be dropped. 33 // the frame should be dropped.
39 void AdaptFrameResolution(int in_width, 34 void AdaptFrameResolution(int in_width,
40 int in_height, 35 int in_height,
36 int64_t in_timestamp_ns,
41 int* cropped_width, 37 int* cropped_width,
42 int* cropped_height, 38 int* cropped_height,
43 int* out_width, 39 int* out_width,
44 int* out_height); 40 int* out_height);
45 41
46 // Requests the output frame size and frame interval from 42 // Requests the output frame size and frame interval from
47 // |AdaptFrameResolution| to not be larger than |format|. Also, the input 43 // |AdaptFrameResolution| to not be larger than |format|. Also, the input
48 // frame size will be cropped to match the requested aspect ratio. The 44 // frame size will be cropped to match the requested aspect ratio. The
49 // requested aspect ratio is orientation agnostic and will be adjusted to 45 // requested aspect ratio is orientation agnostic and will be adjusted to
50 // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or 46 // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or
51 // 720x1280 is requested. 47 // 720x1280 is requested.
52 void OnOutputFormatRequest(const VideoFormat& format); 48 void OnOutputFormatRequest(const VideoFormat& format);
53 49
54 // Requests the output frame size from |AdaptFrameResolution| to not have 50 // Requests the output frame size from |AdaptFrameResolution| to not have
55 // more than |max_pixel_count| pixels and have "one step" up more pixels than 51 // more than |max_pixel_count| pixels and have "one step" up more pixels than
56 // max_pixel_count_step_up. 52 // max_pixel_count_step_up.
57 void OnResolutionRequest(rtc::Optional<int> max_pixel_count, 53 void OnResolutionRequest(rtc::Optional<int> max_pixel_count,
58 rtc::Optional<int> max_pixel_count_step_up); 54 rtc::Optional<int> max_pixel_count_step_up);
59 55
60 private: 56 private:
57 // Determine if frame should be dropped based on input fps and requested fps.
58 bool KeepFrame(int64_t in_timestamp_ns);
59
61 int frames_in_; // Number of input frames. 60 int frames_in_; // Number of input frames.
62 int frames_out_; // Number of output frames. 61 int frames_out_; // Number of output frames.
63 int frames_scaled_; // Number of frames scaled. 62 int frames_scaled_; // Number of frames scaled.
64 int adaption_changes_; // Number of changes in scale factor. 63 int adaption_changes_; // Number of changes in scale factor.
65 int previous_width_; // Previous adapter output width. 64 int previous_width_; // Previous adapter output width.
66 int previous_height_; // Previous adapter output height. 65 int previous_height_; // Previous adapter output height.
67 int input_interval_ GUARDED_BY(critical_section_); 66 // The target timestamp for the next frame based on requested format.
68 int64_t interval_next_frame_ GUARDED_BY(critical_section_); 67 rtc::Optional<int64_t> next_frame_timestamp_ns_ GUARDED_BY(critical_section_);
69 68
70 // Max number of pixels requested via calls to OnOutputFormatRequest, 69 // Max number of pixels requested via calls to OnOutputFormatRequest,
71 // OnResolutionRequest respectively. 70 // OnResolutionRequest respectively.
72 // The adapted output format is the minimum of these. 71 // The adapted output format is the minimum of these.
73 rtc::Optional<VideoFormat> requested_format_ GUARDED_BY(critical_section_); 72 rtc::Optional<VideoFormat> requested_format_ GUARDED_BY(critical_section_);
74 int resolution_request_max_pixel_count_ GUARDED_BY(critical_section_); 73 int resolution_request_max_pixel_count_ GUARDED_BY(critical_section_);
75 int resolution_request_max_pixel_count_step_up_ GUARDED_BY(critical_section_); 74 int resolution_request_max_pixel_count_step_up_ GUARDED_BY(critical_section_);
76 75
77 // The critical section to protect the above variables. 76 // The critical section to protect the above variables.
78 rtc::CriticalSection critical_section_; 77 rtc::CriticalSection critical_section_;
79 78
80 RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter); 79 RTC_DISALLOW_COPY_AND_ASSIGN(VideoAdapter);
81 }; 80 };
82 81
83 } // namespace cricket 82 } // namespace cricket
84 83
85 #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_ 84 #endif // WEBRTC_MEDIA_BASE_VIDEOADAPTER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/base/videoadapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698