Commit graph

16 commits

Author SHA1 Message Date
Markus Handell
2e0f4f0f37 ZeroHertzAdapterMode: handle key frame requests.
Under zero-hertz mode, provided that a frame arrived to the
VideoStreamEncoder, the receiver may experience up to a second
between incoming frames. This results in key frame requests getting
serviced with that delay, which is undesired.

What's worse is also the fact that if no frame ever arrived to the
VideoStreamEncoder, it will not service the keyframe requests at all
until the first frame comes.

This change introduces VideoSourceInterface::RequestRefreshFrame
which results in a refresh frame being sent from complying sources.
The method is used under zero-hertz mode from the VideoStreamEncoder
when frames didn't arrive to it yet (with changes to the zero-hertz
adapter).

With this change, when the frame adapter has received at least one
frame, it will conditionally repeat the last frame in response to the
key frame request.

go/rtc-0hz-present

Bug: chromium:1255737
Change-Id: I6f97813b3a938747357d45e5dda54f759129b44d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/242361
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35562}
2021-12-21 19:52:56 +00:00
Artem Titov
ab30d72b72 Use backticks not vertical bars to denote variables in comments for /video
Bug: webrtc:12338
Change-Id: I47958800407482894ff6f17c1887dce907fdf35a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227030
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34585}
2021-07-28 13:22:27 +00:00
Henrik Boström
1124ed1ab2 Communicate encoder resolutions via rtc::VideoSinkWants.
This will allow us to optimize the internal buffers of
webrtc::VideoFrame for the resolution(s) that we actually want to
encode.

Bug: webrtc:12469, chromium:1157072
Change-Id: If378b52b5e35aa9a9800c1f7dfe189437ce43253
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/208540
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33342}
2021-02-25 11:10:55 +00:00
Artem Titov
d15a575ec3 Use SequenceChecker from public API
Bug: webrtc:12419
Change-Id: I00cca16a0ec70246156ba00b97aa7ae5ccbf5364
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/205323
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33220}
2021-02-10 15:04:55 +00:00
Mirko Bonadei
20e4c80fbe Reland "Introduce RTC_NO_UNIQUE_ADDRESS."
This is a reland of f5e261aaf6

This CL disables RTC_NO_UNIQUE_ADDRESS on MSan builds since
there have been some issues.

Original change's description:
> Introduce RTC_NO_UNIQUE_ADDRESS.
>
> This macro introduces the possibility to suggest the compiler that a
> data member doesn't need an address different from other non static
> data members.
>
> The usage of a macro is to maintain portability since at the moment
> the attribute [[no_unique_address]] is only supported by clang
> with at least -std=c++11 but it should be supported by all the
> compilers starting from C++20.
>
> Bug: webrtc:11495
> Change-Id: I9f12b67b4422a2749649eaa6b004a67d5fd572d8
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173331
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#32246}

Bug: webrtc:11495, webrtc:12218
Change-Id: I4e6c7cc37d3daffad2407c9a2acfa897fa5b426a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/189968
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32668}
2020-11-23 11:29:36 +00:00
Mirko Bonadei
0abd518abd Revert "Introduce RTC_NO_UNIQUE_ADDRESS."
This reverts commit f5e261aaf6.

Reason for revert: Breaks downstream projects.

Original change's description:
> Introduce RTC_NO_UNIQUE_ADDRESS.
>
> This macro introduces the possibility to suggest the compiler that a
> data member doesn't need an address different from other non static
> data members.
>
> The usage of a macro is to maintain portability since at the moment
> the attribute [[no_unique_address]] is only supported by clang
> with at least -std=c++11 but it should be supported by all the
> compilers starting from C++20.
>
> Bug: webrtc:11495
> Change-Id: I9f12b67b4422a2749649eaa6b004a67d5fd572d8
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173331
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#32246}

TBR=mbonadei@webrtc.org,kwiberg@webrtc.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: webrtc:11495
Change-Id: Ice318d1b11ca3dff09c190187a0b0a32ca945fe3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186944
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32335}
2020-10-07 07:37:01 +00:00
Mirko Bonadei
f5e261aaf6 Introduce RTC_NO_UNIQUE_ADDRESS.
This macro introduces the possibility to suggest the compiler that a
data member doesn't need an address different from other non static
data members.

The usage of a macro is to maintain portability since at the moment
the attribute [[no_unique_address]] is only supported by clang
with at least -std=c++11 but it should be supported by all the
compilers starting from C++20.

Bug: webrtc:11495
Change-Id: I9f12b67b4422a2749649eaa6b004a67d5fd572d8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173331
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32246}
2020-09-30 09:52:49 +00:00
Tomas Gunnarsson
612445ea60 Remove use of asyncinvoker from WebRtcVideoSendStream.
This turned out to be a bit complicated, mostly
related to the tests, but here's what's changed:

* No AsyncInvoker (and avoid ClearInternal) in
  WebRtcVideoSendStream (WVSS)
* The reason it was there is due to a "design leak" from
  VideoSourceSinkController/VideoStreamEncoder where the former uses
  locks in all methods and is unaware of a threading model. That design
  affected downstream objects, pushed the need for an async hop into
  WVSS and added a lock.
  A suggestion was made to address this in a follow-up change, here:
  https://webrtc-review.googlesource.com/c/src/+/165684
* All methods in VideoSourceSinkController are now called on a known
  and checked sequence and this CL removes the lock. This also makes
  checking state consistent (i.e. calling a getter twice in a row on the
  same sequence, will always return the same value, avoiding race with
  other threads).
* Handling of reporting state changes from the encoder queue to the
  VSSC, is done by VideoStreamEncoder.
* VideoSendStreamImpl is still instantiated on the incorrect thread [1]
  but has two initialization steps [2]. The second one already runs on
  the right thread. Addressing that TODO [1] is something we should do
  but it has side effects to consider. For the purposes of this CL
  the steps relating to the encoder (setting the sink pointer) have
  been moved to [2].

[1] https://source.chromium.org/chromium/chromium/src/+/master:third_party/webrtc/video/video_send_stream.cc;l=94
[2] https://source.chromium.org/chromium/chromium/src/+/master:third_party/webrtc/video/video_send_stream.cc;drc=f4a9991cce74a37d006438ec0e366313ed33162e;l=115

Bug: webrtc:11222, webrtc:11908
Change-Id: Ie46d46e3a52bbe225951b4bd580ecb8cc9cad873
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184508
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32150}
2020-09-21 13:29:53 +00:00
Markus Handell
a376518817 Migrate video/ except video/end_to_end_tests and video/adaptation to webrtc::Mutex.
Also migrates test/ partly.

Bug: webrtc:11567
Change-Id: If5b2eae65c5f297f364b6e3c67f94946a09b4a96
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178862
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31672}
2020-07-08 12:21:08 +00:00
Markus Handell
a827a30bb7 Revert "Migrate video/ except video/end_to_end_tests and video/adaptation to webrtc::Mutex."
This reverts commit 0eba415fb4.

Reason for revert: previously unknown lock recursion occurring downstream.

Original change's description:
> Migrate video/ except video/end_to_end_tests and video/adaptation to webrtc::Mutex.
> 
> Also migrates test/ partly.
> 
> Bug: webrtc:11567
> Change-Id: I4203919615c087e5faca3b2fa1d54cba9f171e07
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178813
> Reviewed-by: Erik Språng <sprang@webrtc.org>
> Commit-Queue: Markus Handell <handellm@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31653}

TBR=sprang@webrtc.org,handellm@webrtc.org

Change-Id: I13f337e0de5b8f0eb19deb57cb5623444460ec4d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:11567
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178842
Reviewed-by: Markus Handell <handellm@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31656}
2020-07-07 20:46:48 +00:00
Markus Handell
0eba415fb4 Migrate video/ except video/end_to_end_tests and video/adaptation to webrtc::Mutex.
Also migrates test/ partly.

Bug: webrtc:11567
Change-Id: I4203919615c087e5faca3b2fa1d54cba9f171e07
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178813
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31653}
2020-07-07 18:01:44 +00:00
Evan Shrubsole
236e0ed83a Add logging for video restrictions
This will help show what the restrictions are before
and after they transform into sink wants.

These will not be so spammy as adaptations do not happen
very often.

Bug: None
Change-Id: Ib72b313f68c6934d7833d8a3f14ce00df602832b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175800
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#31341}
2020-05-25 09:32:13 +00:00
Henrik Boström
c55516dd55 [Adaptation] Make Resources reference counted and add more DCHECKs.
In a future CL, adaptation processing and stream encoder resource
management will happen on different task queues. When this is the case,
asynchronous tasks will be posted in both directions and some resources
will have internal states used on multiple threads.

This CL makes the Resource class reference counted in order to support
posting tasks to a different threads without risk of use-after-free
when a posted task is executed with a delay. This is preferred over
WeakPtr strategies because WeakPtrs are single-threaded and preferred
over raw pointer usage because the reference counted approach enables
more compile-time and run-time assurance. This is also "future proof";
when resources can be injected through public APIs, ownership needs to
be shared between libwebrtc and the application (e.g. Chrome).

To reduce the risk of making mistakes in the future CL, sequence
checkers and task queue DCHECKs are added as well as other DCHECKs to
make sure things have been cleaned up before destruction, e.g:
- Processor gets a sequence checker. It is entirely single-threaded.
- Processor must not have any attached listeners or resources on
  destruction.
- Resources must not have any listeners on destruction.
- The Manager, EncodeUsageResource and QualityScalerResource DCHECKs
  they are running on the encoder queue.
- TODOs are added illustrating where we want to add PostTasks in the
  future CL.

Lastly, upon VideoStreamEncoder::Stop() we delete the
ResourceAdaptationProcessor. Because the Processor is already used in
posted tasks, some if statements are added to ensure the Processor is
not used after destruction.

Bug: webrtc:11542, webrtc:11520
Change-Id: Ibaa8a61d86d87a71f477d1075a117c28d9d2d285
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174760
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31217}
2020-05-11 20:35:30 +00:00
Henrik Boström
62057627ef [Adaptation] Rename and move resource adaptation module/processor stuff.
Rename:
- call/adaptation/resource_adaptation_module_interface.[h/cc] -->
  call/adaptation/resource_adaptation_processor_interface.[h/cc]
- call/adaptation/resource_adaptation_processor.[h/cc] -->
  call/adaptation/new_resource_adaptation_processor_poc.[h/cc]

Move + Rename:
- video/overuse_frame_detector_resource_adaptation_module.[h/cc] -->
  video/adaptation/resource_adaptation_processor.[h/cc]

Move:
- video/encode_usage_resource.[h/cc] --> video/adaptation/...
- video/overuse_frame_detector.[h/cc] --> video/adaptation/...
- video/quality_scaler_resource.[h/cc] --> video/adaptation/...

Unittests are also moved. In order to avoid a circular dependency,
VideoStreamEncoder::kDefaultLastFrameInfo[Width/Height] is moved and
renamed to kDefaultInputPixels[Width/Height] in
video/adaptation/resource_adaptation_processor.[h/cc].

Bug: webrtc:11222
Change-Id: Icf920e8a7362002b1c63c42b2d9e2e63c990b532
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170117
Reviewed-by: Evan Shrubsole <eshr@google.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30754}
2020-03-11 09:30:16 +00:00
Henrik Boström
8234b92ba3 Move DegradationPreference logic out of VideoSourceSinkController.
The DegradationPreference logic is moved into
OveruseFrameDetectorResourceAdaptationModule. This makes the adaptation
module solely responsible for degradation preference, and the
VideoStreamEncoder the only bridge between the adaptation module and the
VideoSourceSinkController.

The adaptation module is now unaware of the existence of a controller.
It only "speaks" VideoSourceRestrictions, which is a big milestone in
making adaptation modules injectable.

A follow-up CL will explore the possibility of reconfiguring the
controller's source and which degradation preference to use to the
encoder queue. This would allow us to make several classes
single-threaded, but it is a change in behavior and should be done in a
separate CL.

Bug: webrtc:11222
Change-Id: Ib7f640e12789da5f801177926c2072a51818f261
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165684
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30237}
2020-01-13 17:24:48 +00:00
Henrik Boström
ce0ea49001 VideoStreamEncoder configuring source/sink with VideoSourceController.
This is part of the work for making VideoStreamEncoder responsible for
configuring its source/sink and limiting the responsibility of
OveruseFrameDetectorResourceAdaptationModule to only output relevant
VideoSourceRestrictions.

BEFORE THIS CL

Prior to this CL, OveruseFrameDetector was responsible for performing
AddOrUpdateSink() on the source, which it did using its nested class
VideoSourceProxy.

AddOrUpdateSink() could happen for both adaptation and non-adaptation
related reasons. For example:
- Adaptation related: AdaptUp() or AdaptDown() happens, causing updated
  VideoSourceRestrictions.
- Non-adaptation related: VideoStreamEncoder asks the module to
  reconfigure the source/sink for it, such as with
  SetMaxFramerateAndAlignment() or SetWantsRotationApplied().

AFTER THIS CL

AddOrUpdateSink() is performed by VideoSourceController, which is owned
by VideoStreamEncoder. Any reconfiguration has to go through the
VideoStreamEncoder. This means that:
- Non-adaptation related settings happen between VideoStreamEncoder and
  VideoSourceController directly (without going through the adaptation
  module).
- Adaptation related changes can be expressed in terms of
  VideoSourceRestrictions. OveruseFrameDetectorResourceAdaptationModule
  only has to output the restrictions and not know or care about other
  source/sink settings.

For now, VideoSourceController has to know about DegradationPreference.
In a future CL, the DegradationPreference logic should move back to
the adaptation module. The VideoSourceRestrictions are fully capable of
expressing all possible source/sink values without the "modifier" that
is the degradation preference.

Bug: webrtc:11222
Change-Id: I0f058c4700ca108e2d9f212e38b61f6f728aa419
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/162802
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#30228}
2020-01-13 11:14:04 +00:00