Originally we used node id from PipeWire as an unique device name and
while this works, it will change everytime PipeWire is restarted. This
has an impact on default camera selection, where for example Firefox can
automatically request a camera device that was used before, but this can
break with the next PipeWire restart.
Bug: webrtc:42225999
Change-Id: I9440ee065ffeaa1ffb911a4dc7c405d57c9416dc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/367880
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43387}
We currently specify stream parameters to be a range for both framerate
and resolution, where preferred value is specified. The preferred value
doesn't seem to be taken into account and we end up accepting resolution
from 1x1 to MAX_INTxMAX_INT. In case the other side tries to first match
with lower resolution than requested, we will happily match it and start
streaming low quality video. We should instead request the exact stream
parameters as specified by requested capability. This capability always
come from what has been originally reported as supported so it shouldn't
happen we don't find a matching stream. This also applies to requested
video format. We previously requested mjpg for streams with resolution
higher than 640x480, but it doesn't necessarily mean the camera supports
mjpg for the requested resolution. Again, refer to requested capability
in this case as it should indicate what is supported and we know we can
request exactly the same video format. It can happen that framerate is
set to 0 as unspecified. In that case keep using a range as before, but
with more sane values.
Bug: webrtc:42225999
Change-Id: I46d8e83c636e25e12c45a462596fee1d5e59888e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/362820
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Cr-Commit-Position: refs/heads/main@{#43067}
In many cases, the framerate can be specified as list of possible values
and in that case, we would end up with max FPS to be set to 0 as this
case was not handled.
Bug: webrtc:42225999
Change-Id: I036af6db1da3309b1310b754504369e8fe392d09
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/362961
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43057}
We keep information about the PipeWire camera status as a member of the
PipeWire session, but it's never updated and remains in uninitialized
state. Make sure it gets updated once PipeWire is initialized or when it
fails. There is currently no use for this member variable, but there is
a plan to use it so I'm rather keeping it instead of removing it.
Bug: webrtc:42225999
Change-Id: If409761b148be8f0724fd9ab7a1ed4cf0e459503
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360922
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42926}
Filter out devices that do not support any format supported by WebRTC.
This will for example be IR cameras that show as duplicated in the list
of cameras, but support only GRAY8 format and for that reason do not
work at all.
Bug: webrtc:42225999
Change-Id: Ic2905bc66b55c3f48b49ff4097167f10d17ad656
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358864
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42785}
Similar to PipeWire implementation of desktop capture, we have to avoid
CFI check for calls of dlopened PipeWire library. This avoid crashing
PipeWire camera backend when "is_official_build=true" option is used as
this turns on "is_cfi=true" enabling control flow integrity.
Bug: chromium:354776214
Change-Id: I7a9fc1c2d77c4ee0e8fe0586369b7246e0bb9180
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358103
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/main@{#42706}
Similar to BGRA/RGBA we added recently, formats from PipeWire are in
big-endian, while WebRTC (using libyuv) is little-endian, therefore we
have to map BGR to RGB and not RGB to RGB as colors would be off. Also
add some additional formats supported by libyuv.
Bug: webrtc:42225999
Change-Id: Iee8303f0922fe434069b2b3f88994abecf7d2cc5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/355860
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#42609}
Some DMAbuf types don't properly implement MAP_PRIVATE as it requires
copy-on-write support. As we don't need to write to these buffers, we
can switch to MAP_SHARED instead, making it work reliably on current
kernels without having any drawbacks in this context.
Tested and confirmed with libcamera software ISP on Thinkpad X13 with
an arm processor.
Bug: webrtc:42225999
Change-Id: Ic47b8c90456cccf3742e8274945dbd64fb8aac6d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354623
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42484}
Do not add offset to the "length" argument for mmap call as it should be
passed as the last argument instead. This was not causing any problems
since the offset is usually 0, but it's still better to do it correctly.
Bug: webrtc:42225999
Change-Id: If1dbe7dfd2fb22c53493c0fafd23d782f0683a11
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354521
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#42481}
Adds support for 32 bits formats needed for libcamera software ISP. This
is needed, because libcamera enforces 8 byte alignment and we only
support 3 byte alignment for RGB. This will make it work with 32 bits
aligned output formats recently added to libcamera.
Relevant libcamera patch: https://patchwork.libcamera.org/patch/20253/
This has been verified on an snapdragon device using libcamera and software ISP and on my machine using "vivid" virtual camera from libcamera and enforcing specific format.
Bug: webrtc:346808586
Change-Id: I8d89120660b2304b880d952c5acd7f5cd09b611e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354400
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42474}
This avoids having duplicate camera entries presented to the user when
PipeWire camera is being used.
Bug: webrtc:346350844
Change-Id: I423db7fe0654cc1b1c91ee5264c6ba5dc4e24100
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354320
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Andreas Pehrson <apehrson@mozilla.com>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#42462}
and move usages to webrtc::RefCountInterface
This CL also moves more stuff to webrtc:: and adds backwards
compatible aliases for them.
Bug: webrtc:42225969
Change-Id: Iefb8542cff793bd8aa46bef8f2f3c66a1e979d07
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353720
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42446}
Also remove all dependencies on rtc_media_base except for a few
that are suspected of being linker directives.
Bug: webrtc:14775
Change-Id: Ic0daf88b5422047d3ed7079ee6af9e689853310c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/341461
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Jeremy Leconte <jleconte@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41886}
We want to copy device id to _lastUsedDeviceName variable, but we use
length of display name instead of length of device id, which might be
longer than expected and we end up reading beyond the source string.
Bug: webrtc:15853
Change-Id: Id278ed7e361ead85475910adec18b9db51e6890b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/341521
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41844}
Announce that we support SPA_DATA_DmaBuf and tell PipeWire not to map
memory for us so we can handle it ourself, similar like we do in case of
screen sharing. This fixes an issue when a camera is already in use by
gstreamer (pipewiresrc), where DMABufs are used, and we try to share
same camera and get no content, as PipeWire doesn't want to mmap DMABuf
memory for us and we get NULL data pointers.
Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1876895
Bug: webrtc:15654
Change-Id: I788d8d12b2fcd5588329d7265e45b479f74bb628
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/338921
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/main@{#41826}
This RaceChecker is intended to be used on API thread only when we are
not capturing, however, since StartCapture() can be called while already
capturing, we have to avoid using it to guard members that do not meet
this expectations. Use API checker for _captureStarted instead and move
the capture race checker down where we can be sure that capturing is not
happening.
Bug: webrtc:15181
Change-Id: I52f74b893f2c36c3ce0facd053b003fa497101b0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/338040
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#41714}
Use only one RaceChecker as intended with the original change. This gets
rid of specific RaceChecker for PipeWire members. Make PipeWireSession
guarded by API checker instead, since this member is accessed only in
[Start/Stop]Capture and move the race checker within PipeWire thread
loop lock. Also remove race check from OnStreamStateChanged where we
only modify one property guarded by API mutex.
Partially reverts a9d497b52dc21497fdfd0e8c03ab2f8559e02d15 reviewed
on https://webrtc-review.googlesource.com/c/src/+/326781.
Bug: webrtc:15181
Change-Id: I46449fce86611124688a65d5337771c75853f2ca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/338021
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#41713}
This allows to share an instance of VideoCaptureModulePipeWire which is
what browsers usually do when the same camera is being shared with more
than one consumer. This matches V4L2 implementation.
Bug: webrtc:15211
Change-Id: I2ae466739c2649029e76a29e6f16aad1014e9d42
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306964
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#41639}
in favor of stock StartsWith and HasSubstr matchers provided by gmock.
BUG=None
Change-Id: Ib7e9a0ac73d506c349b8ec102dd4236767077d61
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/334460
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41531}
There are two threads involved here, the thread that calls the API
functions and the pipwire main loop. Using one race checker for both is
wrong and triggers aborts.
Use a different race checker for all variables that are used by the
pipewire main loop or guarded against concurrent access with the
thread_loop_lock.
In one case, two RTC_CHECK_RUNS_SERIALIZED() checks are needed, so
enhance the macro to generate unique variable names.
Bug: webrtc:15181
Change-Id: Ib41514eb7aa98fe85d830461aa0c71e42ba821bd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/326781
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41198}
Make sure the notifier is reset when tearing down the camera portal and also when we already called it. Destruction of camera portal will be mostly invoked by an object holding it and serving as an implementation of the notifier interface and in such case we have to make sure it will
not get called at this moment.
Bug: webrtc:15407
Change-Id: If0c1fb1493d64d5e1f0228ed71813abbb9280083
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/315420
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#41167}
Moving the header file and definitions for PipeWireSession to the source
file allows DeviceInfoPipeWire to be reimplemented or used in wrappers
without the consumer needing to add PipeWire includes and definitions.
Bug: webrtc:15654
Change-Id: I895059d50bdf9e6ed152eca729c618261701457a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/327381
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#41163}
Support the Pipewire videotransform meta via the already existing shared
infrastructure. This is needed for mobile devices which often have a 90
degree rotated camera - which is likely the reason there is already
support in the shared code paths.
Bug: webrtc:15464
Change-Id: I15223055d8675502ae326d270ebd2debbcfbfa50
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/318641
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40708}
This can be helpful in various situations, such as debugging with an
unrestricted Pipewire socket or for downstream projects like
B2G/Capyloon. Additionally it will help once we move from the camera
portal to the more generic device portal.
Original patch by Fabrice Desré <fabrice@desre.org>
Bug: webrtc:15464
Change-Id: Iae6802f242d68244bca85947cb15ef3eee923ab0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/318642
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40706}
Make sure the callback is reset when tearing down the PipeWireSession
and that there is no concurrent access to it, which can potentially lead
to a crash.
Bug: webrtc:15386
Change-Id: I0b09002fe0479dc1cd946c80684bcc5d8754d54a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/311546
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#40464}
We will not always initialize PipeWire stream when we fail early and in
such case we will end up cleaning VideoCaptureModulePipeWire instance
where we will attempt to free it even when it is not initialized.
Bug: chromium:1457131
Change-Id: Id78310485aa5ae5d72c2d0d753dd5318b1b673ef
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/311261
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#40390}
This annotates all unannotated members in VideoCaptureImpl and its
subclasses with either of:
- api_checker_: access on the api thread only
- capture_checker_: access in callbacks/on the capture thread while
capture is active, on the api thread otherwise
- a Mutex if it is already protected by it
Bug: webrtc:15181
Change-Id: I5084e7752a4716c29b85a9b403a88696f66d811f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305647
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40335}
VideoCaptureV4L2 has some members that are set in StartCapture during
configuration of the device, but later accessed both on the capture
thread and on the api thread (same as StartCapture) in
CaptureSettings(), which can be called at any time. This is safe because
they are written only on the api thread when the capture thread is not
running. However, there is no helper class that separates the read and
write modes to allow annotations and static analysis of the thread
access of these members.
This commit allows annotations to be added by making VideoCaptureV4L2
use:
- VideoCaptureImpl::_requestedCapability for storing those members
requested through StartCapture(), to allow access on the api thread
through CaptureSettings().
- A new member configured_capability_ to replace those members mentioned
in the first paragraph above. Writes to it happen only in
StartCapture() and StopCapture(), while reads happen exclusively on
the capture thread in between.
Bug: webrtc:15181
Change-Id: I27e0f578e6ac2a2e6b0e34fbabfe4f743b296321
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306122
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40290}
CaptureSettings() can read started_ on the api thread at any time. But
it is written and read in pipewire callbacks, on other threads. A lock
seems suitable.
Bug: webrtc:15181
Change-Id: I3d26f02408a4e56921b955f059e504ffa9b8cae9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306121
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40286}
frameInfo_ is used on multiple threads. This commit splits it into:
- VideoCaptureImpl::_requestedCapability for writing what was requested
in StartCapture() and for reading in CaptureSettings(), on the api
thread only.
- A new member configured_capability_ (renamed from frameInfo_) for
accesses in callbacks, or on the api thread when no callbacks can
happen.
Bug: webrtc:15181
Change-Id: I105d8adfde52320e43ffe95fe23e11d028c80684
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306120
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40285}
A comment says SetApplyRotation could deadlock if grabbing the lock, but
it does not make any calls under the lock so that is impossible, unless
the caller of SetApplyRotation involves a second lock that the callback
tries to grab, in which case it appears to be a problem of the caller.
Bug: webrtc:15181
Change-Id: Ie16cb01ffb84e9118dd5c87863c29bd107a6c94e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305646
Commit-Queue: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40279}
This makes it possible to add a SequenceChecker guard to _deviceFd that
ensures it is accessed only on the api thread while the capture thread
is not running, and only on the capture thread otherwise.
Bug: webrtc:15181
Change-Id: Ibc414ee973a3c4798e38e9b9a63e3053b95b9599
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305645
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40194}
We use value -1 on over all the places through our code so it might be
better to define a constant and use it instead to make the code more
understandable on first look.
Bug: webrtc:15203
Change-Id: I4fc3e561bc7a7778c43ec6cfde7acebef2af79e8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306620
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40156}
Allows to use camera portal separately in implementations where each
implementation needs to be called in different places.
This is targeted for Firefox support, where we need to ask for camera
access in the FF frontend code, otherwise making camera access requests
in the backend WebRTC code might result into presenting portal dialogs
asking for access from the javascript API.
Bug: webrtc:15202
Change-Id: Ida8b010bb93e08a9e5ddd9dd8a2a3549ee7fde8b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305222
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#40148}
Per the docs, the caller is responsible for freeing the memory.
Bug: chromium:1441804
Change-Id: I9aaae493a1a86d8ab4f03930715a643a3c9fb61b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/304061
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39983}