Commit graph

68 commits

Author SHA1 Message Date
gxalpha 2a4c8594a1 mac-virtualcam: Release pixel buffer pool for DAL as well
The pixel buffer pool is used to create pixel buffers with both the CMIO
extension and the DAL plugin. As such, it is created independent of
which camera type is used, and should be released independent of it as
well.
2023-05-27 17:37:11 +02:00
gxalpha 8151785c45 mac-virtualcam: Adjust admin privilege strings to use Apple terminology 2023-05-25 14:50:44 -04:00
gxalpha a874c19bef mac-virtualcam: Fix admin password locale string 2023-05-23 03:58:34 -07:00
tt2468 d314d4725d libobs, plugins: Deprecate obs_output_t functions with flag parameters
This deprecates the following functions, replacing them with new
versions:
- `obs_output_can_begin_data_capture()` - now `*capture2()`
- `obs_output_initialize_encoders()` - now `*encoders2()`
- `obs_output_begin_data_capture()` - now `*capture2()`

The flags parameter was initially designed to support audio-only or
video-only operation of an output which had the `OBS_OUTPUT_AV` flag,
however, full support for that was never implemented, and there are
likely fundamental issues with an implementation, mainly that most
outputs are programmed assuming that there will always be at least one
audio and one video track. This requires new flags specifying support
for optional audio/video, among other things.

An implementation to allow audio/video to be optional is best done
using the flag technique above, with audio/video enablement specified
by whether media (raw, `video_t/audio_t`) or encoder (`obs_encoder_t`)
objects are specified.

Since every implementation I could find always specifies `flags` as 0,
I was able to safely conclude that immediately removing the parameter's
functionality is safe to do.
2023-05-20 16:41:55 -07:00
gxalpha 47d6d7e943 mac-virtualcam: Omit enqueue result codes 2023-05-21 01:35:43 +02:00
Lain 106c7aa61f Update copyrights/names 2023-05-20 01:31:18 -07:00
PatTheMav 3f85e447a8 mac-virtualcam: Add Camera Extension to main CMake plugin project
Camera Extensions require specific entitlements for the hosting app,
which also require a provisioning profile. To avoid breaking local
builds that do not require the camera extension, an additional
entitlements file that will not trigger the provisioning profile
requirement will be used if the virtualcam (but not the Camera
Extension) is configured.
2023-05-18 14:41:08 -04:00
gxalpha aae2f7e8ff mac-virtualcam: Update obs-plugin to support macOS camera extensions
Co-authored-by: PatTheMav <PatTheMav@users.noreply.github.com>
2023-05-18 14:41:08 -04:00
gxalpha 5c6e471a56 mac-virtualcam: Add macOS camera extension project
Co-authored-by: PatTheMav <PatTheMav@users.noreply.github.com>
2023-05-18 14:41:08 -04:00
PatTheMav ea60fc2869 mac-virtualcam: Fix DAL plugin entrypoint not being exported
With the recent change to enforce C17 standard for compilers, default
visibility was also enforced to be hidden. This also automatically hid
the `PlugInMain` symbol required for DAL plugins. Adding the
`__exported` decorator makes the symbol explicitly visible.
2023-04-15 16:51:18 -07:00
PatTheMav 6e07b86729 cmake: Remove EXCLUDE_FROM_ALL directive from interface libraries 2023-04-04 17:27:54 +00:00
PatTheMav 349372b3b3 cmake: Add changes for CMake build framework 3.0
New code path only taken if OBS_CMAKE_VERSION is set to 3.0.0 or
greater, old functionality remains unchanged.
2023-03-26 18:20:38 -04:00
Mathijs Kadijk 970c284a65 mac-virtualcam: Prevent PTS rounding
All presentation time stamps are rounded to whole seconds during the
conversion from nanoseconds to seconds, because of the immediate cast
to `int64_t`. This results in the same presentation time stamp being
send to consumers for a whole second.

In previews/live streams this isn't super visible as last frame is
often assumed to be the newest and the stream is updated. It's more
problematic when recording since APIs like Apple's AVFoundation don't
allow duplicate presentation time stamps or it can look like frames are
produced in huge bursts once per second.

In this PR `CMTimeMakeWithSeconds` is used instead of `CMTimeMake` to
make sure the conversion is done correctly and simplify the calculation
we have to do a little.
2023-03-09 15:45:48 +01:00
Mathijs Kadijk ecaa5466cb mac-virtualcam: Fix incorrect PTS on Apple Silicon
The `fillFrame` method of the mac-virtualcam plugin is creating samples
directly using the value from `mach_absolute_time()` as `hostTime`.
This assumes this value is in nanoseconds, while it is in fact in mach
tick units. On Intel Macs mach tick units will be exactly 1 nanosecond
resulting in valid values, but on Apple Silicon macs this is no longer
the case.

This results in sample buffers with the placeholder image that have
much lower presentation time stamps than the samples containing content
produced by OBS. In previews/live streams this shows due to the last
content sample being shown frozen until the whole buffer is filled with
samples containing the placeholder image. Applications recording the
video stream are even more confused and crash or record videos with
wildly incorrect lengths.

In this PR `clock_gettime_nsec_np` is used to convert from mach tick units
to nanoseconds. This will make sure the `hostTime` value is correct on
both Apple Silicon and Intel macs. Making sure we produce stable
presentation time stamps from the virtual camera plugin at all times.
2023-03-09 15:45:48 +01:00
PatTheMav 8c8a44b26a mac-virtualcam: Fix compiler warnings
CMake build framework 3.0 introduces more strict typing checks, which
require additional code fixes to silence.

* Fixes warnings about implicit casts
* Fixes warnings about weak references used multiple times inside
  blocks
2023-02-18 15:22:33 -08:00
PatTheMav 447adfbe38 mac-virtualcam: Fix memory access issues for shared IOSurfaces
The DAL plugin-based virtualcamera shares data between OBS and the
plugin using an IOSurface. IOSurface locks are necessary to ensure
race conditions between data generation (OBS side) and consumption
(virtual camera side) and also that an IOSurface is not offloaded to
GPU memory when it is indeed needed in CPU memory.

Also moves the invalidation of the NSMachPort for the frames to after
the IOSurface data has been converted into a pixelbuffer and added to
the frame queue of the virtual camera, as an early invalidation will
cut off access to the pixel data shared with the DAL plugin.
2023-01-16 12:16:16 -05:00
PatTheMav 0b0ac1b958
mac-virtualcam: Remove unnecessary IOSurfaceLocks in Mach Server
IOSurface locks are only necessary when any processing with the data
contained in the surface is done and an explicit copy of data from GPU
memory back to CPU memory is needed.
2022-10-19 01:59:11 +02:00
PatTheMav 558c2a7074
mac-virtualcam: Remove unnecessary use of NSAppleEventDescriptor 2022-10-19 01:59:11 +02:00
PatTheMav a754cacc7f
mac-virtualcam: Use IOSurfaceLock on Intel-based Macs only
Apple Silicon-based Macs have a unified memory architecture, as such
an IOSurface will always be available in memory accessible to the CPU
and GPU (and an off-load of the IOSurface will not take place).

eGPUs are not supported on Apple Silicon-based Macs either, so an
IOSurface lock to ensure data is copied back to CPU memory is not
necessary.
2022-10-19 01:59:11 +02:00
PatTheMav 36a86f5217
mac-virtualcam: Fix random crashes in applications loading VirtualCam
Without invalidating the mach port used for sharing the IOSurface
between OBS and the application displaying the virtual camera output,
IOKit seems to run into the issue of receiving "shared" mach ports,
possibly because of port exhaustion. IOKit requires a "new" port
however and crashes upon that error otherwise.

Co-authored-by: Steven Michaud <smichaud@pobox.com>
2022-10-19 01:59:11 +02:00
PatTheMav 967bce5e15 mac-virtualcam: Fix distorted virtual cam image when using full range
The root cause of the issue is `swscale` dropping the second plane of
biplanar pixel data, resulting in an "incomplete" frame being fed to the
CVPixelBuffer.

As CVPixelBuffers have dedicated support for full range colour, use
these directly, which improves performance even further (as any
conversion for full range data is avoided as well).

To ensure that OBS does not implicitly enable conversion via `swscale`
a video conversion struct needs to be set in any case, ensuring that the
output range and colourspace match the output configuration.
2022-09-21 11:04:25 -04:00
PatTheMav ee34d8fbfe mac-virtualcam: Fix virtualcam video on Intel-based Macs
This issue primarily seems to affect Intel-based Macs without unified
memory: While an IOSurface is supposed to be shared via a mach port
with other processes, each process needs to lock the surface during
access (as is common with other shared resources).

Apple Silicon-based Macs seem to be less affected as a switch between
GPU and CPU memory (which can happen dynamically for IOSurfaces) would
still point to the same unified memory.
2022-09-21 11:04:25 -04:00
Translation Updater 4aaa07f93d Update translations from Crowdin 2022-08-17 04:22:50 +00:00
gxalpha a9b83c7ffd mac-virtualcam: Don't convert color space when converting color format
Converting the color space was likely accidental as it isn't explicitly
set. Unfortunately, not setting it means that it gets set to the
default, which is Rec. 709 and thus a conversion takes place when having
any other space. This conversion leads to a massive performance penalty
that isn't necessary.
2022-08-13 01:32:14 -07:00
gxalpha d9c4c0f5da mac-virtualcam: Avoid conversion of P010 2022-08-13 01:31:40 -07:00
Translation Updater 81734be37c Update translations from Crowdin 2022-07-31 23:40:53 +00:00
Fabian Mastenbroek b02e4b109b mac-virtualcam: Fix IOSurface memory leak
This change fixes a memory leak in the mac-virtualcam plugin that causes
OBS to not release the CVPixelBuffers (and underlying IOSurfaces)
it emits to the virtual camera consumers.

Pull request https://github.com/obsproject/obs-studio/pull/6573 (Avoid
transcoding where possible) updated the mac-virtualcam to share the
virtual camera feed with other processes via IOSurfaces.

Although the changes work correctly, users have observed that OBS memory
usage keeps increasing when the virtual camera is active until OBS runs
out of memory or the consuming application is closed.
See the report by @SciTechNick for more information:
https://github.com/obsproject/obs-studio/pull/6573#issuecomment-1161979765

After some debugging, I have found that the plugin is leaking Mach ports
associated with IOSurfaces, preventing them from being re-used. The
previous approach using `NSMachPort` does not seem to properly release
the Mach port allocated via `CVPixelBufferGetIOSurface` and
`IOSurfaceLookupFromMachPort`. Instead, we must explicitly deallocate
the port using `mach_port_deallocate`.

I have tested the changes on a Macbook Pro (M1) running macOS Monterey with
Google Chrome, Zoom, and Cameo. OBS shows no signs of memory leakage
after multiple minutes.
2022-06-25 16:12:26 -07:00
gxalpha a1f9170180
mac-virtualcam: Free virtualcam data when destroying
Fixes a memory leak introduced in db733032e
2022-06-16 18:45:24 +02:00
Fabian Mastenbroek 37c76abf0d
mac-virtualcam: Fix CMIO errors due to unsettable properties
This change fixes an issue with the CMIO DAL plugin where the CMIO
subsystem would log multiple errors when starting the virtual camera,
due to certain properties that could not be set (frame rate and format).

For now, we just ignore the assignment, but mark the property as
settable to suppress the error messages that are reported by the CMIO
subsystem.
2022-06-10 14:29:55 +02:00
Fabian Mastenbroek 40cb92a7a5
mac-virtualcam: Fix port leakage in Mach server
This change fixes an issue in the Mach server exposed by the macOS
virtual camera for OBS, where it would not invalidate ports that were
disconnected by the remote application, causing sporadic crashes.

These crashes can be reproduced in the previous builds by opening the
virtual camera in a remote application and closing the application
(without stopping the virtual camera).
2022-06-10 13:37:03 +02:00
Fabian Mastenbroek db733032e0
mac-virtualcam: Do not rely on global state
This change updates the implementation of the mac-virtualcam plugin to
not use any global state and instead rely on the state object that is
passed by the OBS module system.

This approach is similar to the virtual camera implementations for Linux
and Windows.
2022-06-10 13:37:03 +02:00
Fabian Mastenbroek 5edabfe7c1
mac-virtualcam: Remove unused CMSampleBuffer utility functions
This change removes the unused CMSampleBuffer utility functions that
were still left from the previous implementation. Since we construct the
CMSampleBuffer directly from an IOSurface, we do not need any custom
construction logic anymore, since that is now performed by the OBS
plugin.
2022-06-10 13:37:03 +02:00
Fabian Mastenbroek 202eb8f513
mac-virtualcam: Prevent output conversion if possible
This change updates the mac-virtualcam implementation to conditionally
enable conversion of the output video format. Previously, the output
video was always converted into UYVY. However, this conversion exhibits
high CPU usage, as reported in:
https://github.com/johnboiles/obs-mac-virtualcam/issues/102

Therefore, we disable conversion when the selected output format (e.g.,
NV12) is natively supported by CoreVideo's pixel buffers.
2022-06-10 13:37:03 +02:00
Fabian Mastenbroek 8683eb10e1
mac-virtualcam: Support multiple AV planes
This change updates the plugin to support video formats that contain
multiple planes (such as NV12). Such functionality is necessary to
prevent transcoding the raw video data, which is often delivered in a
planar format.
2022-06-10 13:37:03 +02:00
Fabian Mastenbroek 29ca91852b
mac-virtualcam: Pool pixel buffers
This change updates the mac-virtualcam implementation to pool the
CVPixelBuffers used to share the output frames. This allows the plugin
to recycle the pixel buffers used by the plugin.
2022-06-10 13:37:03 +02:00
Fabian Mastenbroek aa3781fde9
mac-virtualcam: Use IOSurface to share output with virtual cameras
This change updates the virtual camera implementation on macOS to
utilize IOSurface to share the output feed with the virtual cameras.

By using IOSurface, we remove the need for copying the frames across
multiple buffers, since they can be shared across Mach connections using
zero-copy.
2022-06-10 13:36:54 +02:00
Fabian Mastenbroek 9e29be5c79
mac-virtualcam: Build DAL plugin for ARM64e target as well
This change fixes an issue where the DAL plugin would not load due to
not supporting the architecture arm64e. We update the build
configuration to build a universal binary that includes arm64e as well.

See https://github.com/obsproject/obs-studio/issues/6285 for more
information regarding this issue.
2022-06-10 13:34:17 +02:00
PatTheMav 5e13460fae mac-virtualcam: Fix compiler warnings 2022-05-04 12:09:04 -04:00
PatTheMav aae3a6a466 cmake: Fix diverging prefix padding for OBS status outputs
Status output related to OBS configuration is prefixed with the string
"OBS" and added padding for enabled and disabled features. This padding
was not aligned between platforms.

By moving the padding and prefix decoration into its own function,
both elements are controlled in a single place. CMake scripts were
changed to use this new function `obs_status` instead of using CMake's
`message` function directly.
2022-03-26 09:44:23 -04:00
PatTheMav 49e9d49943
plugins: Update CMakeLists.txt for included plugins 2022-03-16 23:11:08 +01:00
Translation Updater ac8dbf67be Update translations from Crowdin 2022-02-06 02:24:08 +00:00
Translation Updater 062de2c998 Update translations from Crowdin 2021-12-17 08:01:29 +00:00
Translation Updater 261345f9ef Update translations from Crowdin 2021-12-12 02:38:59 +00:00
gxalpha 4a50e62120 mac-virtualcam: Remove unnecessary plugin version number 2021-10-24 00:22:53 -07:00
gxalpha fab23d523b mac-virtualcam: Remove unneeded includes 2021-10-16 15:27:51 -07:00
Vainock 11a690b038 Update translations from Crowdin 2021-09-24 09:42:08 -07:00
gxalpha 0d755c3691 mac-virtualcam: Move DAL plugin to plugin data directory
Moves the DAL plugin to the data directory of the mac-virtualcam. Until
now, it was just lying in the top-level data directory
2021-08-17 08:21:32 -07:00
jp9000 33130d7d15 Revert "mac-virtualcam: Move DAL plugin to plugin data directory"
This reverts commit 4d1764036f.
2021-08-16 07:36:54 -07:00
gxalpha 4d1764036f mac-virtualcam: Move DAL plugin to plugin data directory
Moves the DAL plugin to the data directory of the mac-virtualcam. Until
now, it was just lying in the top-level data directory
2021-08-16 06:52:50 -07:00
Translation ef2b1eb1c6 Update translations from Crowdin 2021-06-11 07:18:15 -07:00