diff options
Diffstat (limited to 'third_party/libwebrtc/modules/video_capture')
9 files changed, 59 insertions, 45 deletions
diff --git a/third_party/libwebrtc/modules/video_capture/linux/camera_portal.cc b/third_party/libwebrtc/modules/video_capture/linux/camera_portal.cc index 85b9f20228..106ca1682c 100644 --- a/third_party/libwebrtc/modules/video_capture/linux/camera_portal.cc +++ b/third_party/libwebrtc/modules/video_capture/linux/camera_portal.cc @@ -15,6 +15,7 @@ #include "modules/portal/pipewire_utils.h" #include "modules/portal/xdg_desktop_portal_utils.h" +#include "rtc_base/synchronization/mutex.h" namespace webrtc { @@ -54,7 +55,9 @@ class CameraPortalPrivate { GAsyncResult* result, gpointer user_data); - CameraPortal::PortalNotifier* notifier_ = nullptr; + webrtc::Mutex notifier_lock_; + CameraPortal::PortalNotifier* notifier_ RTC_GUARDED_BY(¬ifier_lock_) = + nullptr; GDBusConnection* connection_ = nullptr; GDBusProxy* proxy_ = nullptr; @@ -66,6 +69,11 @@ CameraPortalPrivate::CameraPortalPrivate(CameraPortal::PortalNotifier* notifier) : notifier_(notifier) {} CameraPortalPrivate::~CameraPortalPrivate() { + { + webrtc::MutexLock lock(¬ifier_lock_); + notifier_ = nullptr; + } + if (access_request_signal_id_) { g_dbus_connection_signal_unsubscribe(connection_, access_request_signal_id_); @@ -229,7 +237,11 @@ void CameraPortalPrivate::OnOpenResponse(GDBusProxy* proxy, } void CameraPortalPrivate::OnPortalDone(RequestResponse result, int fd) { - notifier_->OnCameraRequestResult(result, fd); + webrtc::MutexLock lock(¬ifier_lock_); + if (notifier_) { + notifier_->OnCameraRequestResult(result, fd); + notifier_ = nullptr; + } } CameraPortal::CameraPortal(PortalNotifier* notifier) diff --git a/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.cc b/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.cc index ad6cea57b8..31d922035b 100644 --- a/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.cc +++ b/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.cc @@ -20,10 +20,10 @@ #include <vector> +#include "modules/video_capture/linux/pipewire_session.h" #include "modules/video_capture/video_capture.h" #include "modules/video_capture/video_capture_defines.h" #include "modules/video_capture/video_capture_impl.h" -#include "modules/video_capture/video_capture_options.h" #include "rtc_base/logging.h" namespace webrtc { @@ -38,6 +38,8 @@ int32_t DeviceInfoPipeWire::Init() { DeviceInfoPipeWire::~DeviceInfoPipeWire() = default; uint32_t DeviceInfoPipeWire::NumberOfDevices() { + RTC_CHECK(pipewire_session_); + return pipewire_session_->nodes().size(); } @@ -50,6 +52,8 @@ int32_t DeviceInfoPipeWire::GetDeviceName(uint32_t deviceNumber, uint32_t productUniqueIdUTF8Length, pid_t* pid, bool* deviceIsPlaceholder) { + RTC_CHECK(pipewire_session_); + if (deviceNumber >= NumberOfDevices()) return -1; @@ -85,6 +89,8 @@ int32_t DeviceInfoPipeWire::GetDeviceName(uint32_t deviceNumber, int32_t DeviceInfoPipeWire::CreateCapabilityMap( const char* deviceUniqueIdUTF8) { + RTC_CHECK(pipewire_session_); + for (auto& node : pipewire_session_->nodes()) { if (node.unique_id().compare(deviceUniqueIdUTF8) != 0) continue; diff --git a/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.h b/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.h index 1a1324e92b..00715c94bc 100644 --- a/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.h +++ b/third_party/libwebrtc/modules/video_capture/linux/device_info_pipewire.h @@ -14,7 +14,7 @@ #include <stdint.h> #include "modules/video_capture/device_info_impl.h" -#include "modules/video_capture/linux/pipewire_session.h" +#include "modules/video_capture/video_capture_options.h" namespace webrtc { namespace videocapturemodule { diff --git a/third_party/libwebrtc/modules/video_capture/linux/device_info_v4l2.cc b/third_party/libwebrtc/modules/video_capture/linux/device_info_v4l2.cc index eaeed26b7c..401c38f9c5 100644 --- a/third_party/libwebrtc/modules/video_capture/linux/device_info_v4l2.cc +++ b/third_party/libwebrtc/modules/video_capture/linux/device_info_v4l2.cc @@ -57,24 +57,6 @@ #define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) #endif -// These defines are here to support building on kernel 3.16 which some -// downstream projects, e.g. Firefox, use. -// TODO(apehrson): Remove them and their undefs when no longer needed. -#ifndef V4L2_PIX_FMT_ABGR32 -#define ABGR32_OVERRIDE 1 -#define V4L2_PIX_FMT_ABGR32 v4l2_fourcc('A', 'R', '2', '4') -#endif - -#ifndef V4L2_PIX_FMT_ARGB32 -#define ARGB32_OVERRIDE 1 -#define V4L2_PIX_FMT_ARGB32 v4l2_fourcc('B', 'A', '2', '4') -#endif - -#ifndef V4L2_PIX_FMT_RGBA32 -#define RGBA32_OVERRIDE 1 -#define V4L2_PIX_FMT_RGBA32 v4l2_fourcc('A', 'B', '2', '4') -#endif - namespace webrtc { namespace videocapturemodule { #ifdef WEBRTC_LINUX diff --git a/third_party/libwebrtc/modules/video_capture/linux/video_capture_pipewire.cc b/third_party/libwebrtc/modules/video_capture/linux/video_capture_pipewire.cc index 8af483636a..319824d3c5 100644 --- a/third_party/libwebrtc/modules/video_capture/linux/video_capture_pipewire.cc +++ b/third_party/libwebrtc/modules/video_capture/linux/video_capture_pipewire.cc @@ -178,8 +178,7 @@ int32_t VideoCaptureModulePipeWire::StartCapture( int res = pw_stream_connect( stream_, PW_DIRECTION_INPUT, node_id_, static_cast<enum pw_stream_flags>(PW_STREAM_FLAG_AUTOCONNECT | - PW_STREAM_FLAG_DONT_RECONNECT | - PW_STREAM_FLAG_MAP_BUFFERS), + PW_STREAM_FLAG_DONT_RECONNECT), params.data(), params.size()); if (res != 0) { RTC_LOG(LS_ERROR) << "Could not connect to camera stream: " @@ -312,11 +311,11 @@ void VideoCaptureModulePipeWire::OnFormatChanged(const struct spa_pod* format) { 0); } + const int buffer_types = + (1 << SPA_DATA_DmaBuf) | (1 << SPA_DATA_MemFd) | (1 << SPA_DATA_MemPtr); spa_pod_builder_add( &builder, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32), - SPA_PARAM_BUFFERS_dataType, - SPA_POD_CHOICE_FLAGS_Int((1 << SPA_DATA_MemFd) | (1 << SPA_DATA_MemPtr)), - 0); + SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(buffer_types), 0); params.push_back( static_cast<spa_pod*>(spa_pod_builder_pop(&builder, &frame))); @@ -384,14 +383,15 @@ void VideoCaptureModulePipeWire::ProcessBuffers() { RTC_CHECK_RUNS_SERIALIZED(&capture_checker_); while (pw_buffer* buffer = pw_stream_dequeue_buffer(stream_)) { + spa_buffer* spaBuffer = buffer->buffer; struct spa_meta_header* h; h = static_cast<struct spa_meta_header*>( - spa_buffer_find_meta_data(buffer->buffer, SPA_META_Header, sizeof(*h))); + spa_buffer_find_meta_data(spaBuffer, SPA_META_Header, sizeof(*h))); struct spa_meta_videotransform* videotransform; videotransform = static_cast<struct spa_meta_videotransform*>(spa_buffer_find_meta_data( - buffer->buffer, SPA_META_VideoTransform, sizeof(*videotransform))); + spaBuffer, SPA_META_VideoTransform, sizeof(*videotransform))); if (videotransform) { VideoRotation rotation = VideorotationFromPipeWireTransform(videotransform->transform); @@ -401,11 +401,35 @@ void VideoCaptureModulePipeWire::ProcessBuffers() { if (h->flags & SPA_META_HEADER_FLAG_CORRUPTED) { RTC_LOG(LS_INFO) << "Dropping corruped frame."; - } else { - IncomingFrame(static_cast<unsigned char*>(buffer->buffer->datas[0].data), - buffer->buffer->datas[0].chunk->size, - configured_capability_); + pw_stream_queue_buffer(stream_, buffer); + continue; + } + + if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf || + spaBuffer->datas[0].type == SPA_DATA_MemFd) { + ScopedBuf frame; + frame.initialize( + static_cast<uint8_t*>( + mmap(nullptr, + spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset, + PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0)), + spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset, + spaBuffer->datas[0].fd, spaBuffer->datas[0].type == SPA_DATA_DmaBuf); + + if (!frame) { + RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " + << std::strerror(errno); + return; + } + + IncomingFrame( + SPA_MEMBER(frame.get(), spaBuffer->datas[0].mapoffset, uint8_t), + spaBuffer->datas[0].chunk->size, configured_capability_); + } else { // SPA_DATA_MemPtr + IncomingFrame(static_cast<uint8_t*>(spaBuffer->datas[0].data), + spaBuffer->datas[0].chunk->size, configured_capability_); } + pw_stream_queue_buffer(stream_, buffer); } } diff --git a/third_party/libwebrtc/modules/video_capture/linux/video_capture_v4l2.cc b/third_party/libwebrtc/modules/video_capture/linux/video_capture_v4l2.cc index c887683dc8..08d23f7f58 100644 --- a/third_party/libwebrtc/modules/video_capture/linux/video_capture_v4l2.cc +++ b/third_party/libwebrtc/modules/video_capture/linux/video_capture_v4l2.cc @@ -294,7 +294,7 @@ int32_t VideoCaptureModuleV4L2::StartCapture( if (_captureThread.empty()) { quit_ = false; _captureThread = rtc::PlatformThread::SpawnJoinable( - [self = rtc::scoped_refptr(this)] { + [self = scoped_refptr(this)] { while (self->CaptureProcess()) { } }, diff --git a/third_party/libwebrtc/modules/video_capture/video_capture.h b/third_party/libwebrtc/modules/video_capture/video_capture.h index 378a53b4d2..f59c34f8b2 100644 --- a/third_party/libwebrtc/modules/video_capture/video_capture.h +++ b/third_party/libwebrtc/modules/video_capture/video_capture.h @@ -34,7 +34,7 @@ protected: virtual ~VideoInputFeedBack(){} }; -class VideoCaptureModule : public rtc::RefCountInterface { +class VideoCaptureModule : public RefCountInterface { public: // Interface for receiving information about available camera devices. class DeviceInfo { diff --git a/third_party/libwebrtc/modules/video_capture/video_capture_internal_impl_gn/moz.build b/third_party/libwebrtc/modules/video_capture/video_capture_internal_impl_gn/moz.build index 24988a1ffc..f58aa8e782 100644 --- a/third_party/libwebrtc/modules/video_capture/video_capture_internal_impl_gn/moz.build +++ b/third_party/libwebrtc/modules/video_capture/video_capture_internal_impl_gn/moz.build @@ -267,7 +267,6 @@ if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": if CONFIG["OS_TARGET"] == "Android" and CONFIG["TARGET_CPU"] == "arm": OS_LIBS += [ - "android_support", "unwind" ] @@ -277,10 +276,6 @@ if CONFIG["OS_TARGET"] == "Android" and CONFIG["TARGET_CPU"] == "x86": "-msse2" ] - OS_LIBS += [ - "android_support" - ] - if CONFIG["OS_TARGET"] == "Linux" and CONFIG["TARGET_CPU"] == "aarch64": DEFINES["WEBRTC_USE_PIPEWIRE"] = True diff --git a/third_party/libwebrtc/modules/video_capture/video_capture_module_gn/moz.build b/third_party/libwebrtc/modules/video_capture/video_capture_module_gn/moz.build index 49c62d5cf6..820d5655df 100644 --- a/third_party/libwebrtc/modules/video_capture/video_capture_module_gn/moz.build +++ b/third_party/libwebrtc/modules/video_capture/video_capture_module_gn/moz.build @@ -204,7 +204,6 @@ if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": if CONFIG["OS_TARGET"] == "Android" and CONFIG["TARGET_CPU"] == "arm": OS_LIBS += [ - "android_support", "unwind" ] @@ -214,10 +213,6 @@ if CONFIG["OS_TARGET"] == "Android" and CONFIG["TARGET_CPU"] == "x86": "-msse2" ] - OS_LIBS += [ - "android_support" - ] - if CONFIG["OS_TARGET"] == "Linux" and CONFIG["TARGET_CPU"] == "aarch64": DEFINES["_GNU_SOURCE"] = True |