From c5324fb7bd68719d64673c099234acf9efe1164e Mon Sep 17 00:00:00 2001 From: Markus Handell Date: Thu, 14 May 2020 14:59:55 +0200 Subject: [PATCH] VideoAdapter: remove lock recursions. This change removes lock recursions and adds thread annotations. Bug: webrtc:11567 Change-Id: I984a0b7993b03c039c220206e2a930ff766e54b0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175125 Reviewed-by: Karl Wiberg Reviewed-by: Niels Moller Commit-Queue: Markus Handell Cr-Commit-Position: refs/heads/master@{#31323} --- media/base/video_adapter.cc | 2 -- media/base/video_adapter.h | 16 ++++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/media/base/video_adapter.cc b/media/base/video_adapter.cc index 27b82646ac..8ba91d7189 100644 --- a/media/base/video_adapter.cc +++ b/media/base/video_adapter.cc @@ -145,8 +145,6 @@ VideoAdapter::VideoAdapter() : VideoAdapter(1) {} VideoAdapter::~VideoAdapter() {} bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { - rtc::CritScope cs(&critical_section_); - int max_fps = max_framerate_request_; if (max_fps_) max_fps = std::min(max_fps, *max_fps_); diff --git a/media/base/video_adapter.h b/media/base/video_adapter.h index 65c2d42267..b7acf0e67c 100644 --- a/media/base/video_adapter.h +++ b/media/base/video_adapter.h @@ -46,7 +46,8 @@ class VideoAdapter { int* cropped_width, int* cropped_height, int* out_width, - int* out_height); + int* out_height) + RTC_LOCKS_EXCLUDED(critical_section_); // DEPRECATED. Please use OnOutputFormatRequest below. // TODO(asapersson): Remove this once it is no longer used. @@ -57,7 +58,8 @@ class VideoAdapter { // maintain the input orientation, so it doesn't matter if e.g. 1280x720 or // 720x1280 is requested. // Note: Should be called from the source only. - void OnOutputFormatRequest(const absl::optional& format); + void OnOutputFormatRequest(const absl::optional& format) + RTC_LOCKS_EXCLUDED(critical_section_); // Requests output frame size and frame interval from |AdaptFrameResolution|. // |target_aspect_ratio|: The input frame size will be cropped to match the @@ -70,7 +72,7 @@ class VideoAdapter { void OnOutputFormatRequest( const absl::optional>& target_aspect_ratio, const absl::optional& max_pixel_count, - const absl::optional& max_fps); + const absl::optional& max_fps) RTC_LOCKS_EXCLUDED(critical_section_); // Same as above, but allows setting two different target aspect ratios // depending on incoming frame orientation. This gives more fine-grained @@ -81,7 +83,7 @@ class VideoAdapter { const absl::optional& max_landscape_pixel_count, const absl::optional>& target_portrait_aspect_ratio, const absl::optional& max_portrait_pixel_count, - const absl::optional& max_fps); + const absl::optional& max_fps) RTC_LOCKS_EXCLUDED(critical_section_); // Requests the output frame size from |AdaptFrameResolution| to have as close // as possible to |sink_wants.target_pixel_count| pixels (if set) @@ -93,11 +95,13 @@ class VideoAdapter { // The sink resolution alignment requirement is given by // |sink_wants.resolution_alignment|. // Note: Should be called from the sink only. - void OnSinkWants(const rtc::VideoSinkWants& sink_wants); + void OnSinkWants(const rtc::VideoSinkWants& sink_wants) + RTC_LOCKS_EXCLUDED(critical_section_); private: // Determine if frame should be dropped based on input fps and requested fps. - bool KeepFrame(int64_t in_timestamp_ns); + bool KeepFrame(int64_t in_timestamp_ns) + RTC_EXCLUSIVE_LOCKS_REQUIRED(critical_section_); int frames_in_ RTC_GUARDED_BY(critical_section_); // Number of input frames. int frames_out_