Commit Graph

45 Commits (master)

Author SHA1 Message Date
tududweb 25d84f40d6 libobs: Fix audio monitor output error in macOS 2022-07-25 17:28:42 +02:00
Norihiro Kamae af3890a4a9 libobs: Cleanup unused-parameters
- Add OBS_UNUSED to unused function parameters
- Remove unnecessary UNUSED_PARAMETER
Also update libobs-opengl/
2022-07-19 11:01:00 -04:00
bin c19946d7e8 libobs: Fix pulseaudio crash. 2022-07-16 16:25:47 -07:00
tt2468 167f539416 libobs: Rename obs_audio_monitoring_supported to _available
With the reasonable possibility of monitoring support becoming a
runtime check, the phrase `available` is more fitting.
2021-12-22 02:43:14 -08:00
tt2468 6e9644ec15 libobs: Add obs_audio_monitoring_supported()
Currently, ifdefs are used to determine if monitoring is supported.
This is difficult to maintain and restricts plugins from knowing if
monitoring is supported by OBS. This adds a runtime function to fix
that issue.
2021-11-20 20:00:59 -08:00
Kurt Kartaltepe 5142a7685d pulse: fill audio monitor buffer more aggressively
Previously we would wait for pulse to attempt to read from the monitor
source and obs buffered at least 5ms of audio data before we tried to
fill the buffer. In some cases this resulted in consistently triggering
underruns in pulse.

Instead we try to fill the buffer immediately as obs outputs audio data
and while the pa buffer is not full. We also stop trying to grow the
buffer to prevent underruns after we reach 1s of latency.
2021-11-04 13:00:46 -07:00
Norihiro Kamae 85f45a3ef6 libobs/audio-monitoring: Fix PulseAudio monitoring volume for u8 format
Change `char` to `uint8_t` in `process_byte` because the type is
expected unsigned 8-bit.
2021-10-23 23:59:53 -07:00
Norihiro Kamae 0eed7ca98f libobs/audio-monitoring: Fix PulseAudio monitoring volume for s32 format
When signed 32-bit audio arrived to pulseaudio-output and volume was
lowered, audio data was broken. In the function `process_volume`, the
type of the data is switched by `bytes_per_channel`. However the size of
signed 32-bit integer and the size of float are same so that the signed
32-bit integer is processed as float.
This commit changes these items.
- Use `format` instead of `bytes_per_channel` so that all the sample
  types can be differentiated.
- Change `short` to `int16_t` and renames existing function
  `process_short` to `process_s16` to clarify the function is
  processing signed 16-bit.
2021-10-23 23:59:53 -07:00
jpark37 3c71399650 libobs/audio-monitoring: Add reconnect logic
Automatically tear down if monitor is invalidated, and retry every time
an input sample is played.
2021-10-10 19:22:35 -07:00
jpark37 eb6050f3ce libobs/audio-monitoring: Move variable assignment
Assinged too early for upcoming change that may reset monitor->render.
2021-10-10 19:22:35 -07:00
jpark37 7af886581d libobs/audio-monitoring: Add WASAPI init helper
audio_monitor_init_wasapi will be used for reconnect logic.
2021-10-10 19:22:35 -07:00
jpark37 63ffae7d74 libobs/audio-monitoring: Remove unnecessary device 2021-10-10 19:22:35 -07:00
jpark37 b005e6748e libobs/audio-monitoring: Fix mutex leak
Use SRWLOCK for simplicity. Does not need to be destroyed.
2021-10-10 19:22:35 -07:00
Hector Martin a5d08e347e linux-pulseaudio: fix race conditions
PulseAudio code needs to be called with the PA lock held. This chiefly
fixes multiple races during stream shutdown:

* If the functions are called without the lock held, deferred event
  handling races end up with PA infinite looping on the mainloop, or
  asserting, or other badness, as the reentrant calls cause data
  structure corruption on the PA side.
* If we don't reset our callbacks, PA might call us even after we
  request stream disconnection (since the stream actually getting fully
  shut down is asynchronous), and then we dereference NULL pointers from
  our userdata etc. PA will keep its data structures alive until necessary
  via reference counting, but not ours.

The lock around pa_stream_begin_write doesn't result from any issues I
experienced, but it looks correct; PA doesn't say anywhere that that
function is thread-safe.
2020-12-12 12:05:12 -08:00
Hans Petter Selasky 0e4ea14ba1 libobs: Implement and use better scaling function for 64-bit integers
As os_gettime_ns() gets large the current scaling methods, mostly by casting
to uint64_t, may lead to numerical overflows. Sweep the code and use
util_mul_div64() where applicable.

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
2020-04-05 20:27:28 +02:00
Clayton Groeneveld 6a7260783e audio-monitoring: Fix Pulse Audio crash 2020-01-18 10:46:56 -06:00
luz.paz d124e6402c docs/sphinx: Fix various typos
(This modifies UI, libobs, deps/obs-scripting, various cmake files)

Found using:
`codespell -q 3 -S *.ini,./UI/data/locale,./deps/w32-pthreads -L aci,dur,iff,mut,numer,uint`
2019-10-14 17:19:38 -07:00
jp9000 d6f9ff0406 Revert "libobs/audio-monitoring: Don't init until used"
This reverts commit 22aa66a6eb.

Apparently, starting audio on the fly like this can introduce latency in
to the audio playback, so for now revert it.  It was a bit of a
precautionary thing rather than an actual fix anyway, so it probably
wasn't all that necessary to begin with.
2019-10-11 23:34:27 -07:00
jp9000 254947eaa0 libobs/audio-monitoring: Add error logging
Helps diagnose issues if the user is unable to initialize audio
monitoring for whatever reason.
2019-10-10 02:04:59 -07:00
jp9000 22aa66a6eb libobs/audio-monitoring: Don't init until used
This prevents audio monitoring from actually initializing unless audio
is actually played back through the source.  This prevents many browser
sources from initializing audio monitoring all at once needlessly if
audio is not being rerouted to OBS.
2019-10-10 02:04:58 -07:00
jp9000 f53df7da64 clang-format: Apply formatting
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
2019-06-23 23:49:10 -07:00
Clayton Groeneveld d1be93ae69 UI, libobs, text-freetype2: Add missing pragma once in header files 2019-04-01 02:48:28 -05:00
Marvin Scholz 649fa7651b libobs/audio-monitoring: Use libobs CFString utils 2018-09-16 22:41:01 +02:00
Shaolin 226d4cadf5 libobs: Remove VLA in pulse monitoring backend 2018-09-03 17:39:49 -03:00
Luke Yelavich f29a4a8145 libobs: Copy the device uid string for mac audio monitor 2018-07-21 09:14:12 +10:00
Luke Yelavich 5c066ed48f libobs: Pass address of cf_uid rather than the contents of cf_uid 2018-07-21 09:14:12 +10:00
Luke Yelavich 002696e795 libobs: Rework checking Mac audio device capabilities
As of commit 2eb5a22, CoreAudio devices that use one device handle for
both input and output can no longer be used for audio monitoring. This
commit fixes that.

Tested with the built-in output, a Magewell XI100DUSB-HDMI which is
input only, and a MOTU UltraLite audio interface, which shows as
output/input capable.
2018-07-21 09:14:12 +10:00
Daniel Lopez 4cebbcc23b libobs: Fix compilation issue on case-sensitive filesystems
When using a macOS running on a case-sensitive filesystem, the project
build fails due to AudioToolBox/AudioQueue.h not being found.
The correct path is AudioToolbox/AudioQueue.h. Since macOS comes with a
case-insensitive filesystem by default, this is a rare ocurrence
among developers who change it to be case-sensitive.
2018-06-08 19:06:23 -05:00
Daniel Lopez ceac83e499 libobs: Add check for cf_uid pointer free
This little change skips returning true immediately when a call to
CoreAudio fails. Instead, it uses similar behavior as further 3 calls
below this change, just checking for unfreed pointers before also
returning true.
2018-06-08 19:05:23 -05:00
Daniel Lopez 2eb5a2288a libobs: Fix Monitoring devices showing input devices
This bug fix is to show output devices in the Advanced Audio
Settings configuration, where currently on macOS it shows erroneously
input devices.
2018-06-08 19:03:53 -05:00
jp9000 4b54bde426 cmake, libobs, win-capture: Fix VS2017 warnings 2018-03-12 16:16:38 -07:00
Jim 77643cce1e
Merge pull request #1139 from takev/pulseaudio-surround-selection
linux-pulseaudio: Surround speaker map
2018-01-19 16:14:04 -08:00
Tjienta Vara 48a8e750bb linux-pulseaudio: Surround speaker map
When using more than two channels, the channel map of pulse-audio is incorrect.

Add an API for getting a speaker map based on OBS speaker layout. Then use the
speaker map when connecting to a pulse-audio device, for both source and
monitor output.
2018-01-17 13:05:04 +01:00
Tjienta Vara 8f6d048817 linux-pulseaudio: Default sample format float32le
This pull request changes the fallback sample format for pulse-audio
to from PA_SAMPLE_S16LE to PA_SAMPLE_FLOAT32LE.

The pulseaudio plugin can handle the following sample format:
* PA_SAMPlE_U8
* PA_SAMPLE_S16LE
* PA_SAMPLE_S32LE
* PA_SAMPLE_FLOAT32LE

When an audio device advertises itself as another format, the pulseaudio-plugin
will ask pulse audio to convert to the fallback sample format.

The fallback PA_SAMPLE_S16LE is not ideal when your audio interface advertises
as PA_SAMPLE_S24LE since the conversion will lose precision.
With PA_SAMPLE_FLOAT32LE there is no precision loss and it is also equals OBS's
internal format.
2018-01-08 19:31:09 +01:00
Shaolin 9de1ffe32b libobs: Fix pulseaudio monitor playback stuttering 2018-01-07 19:27:58 -02:00
pkviet 67e48ecc2c libobs/media-io: Replace quad with 4.0
(also obs, deps/media-playback, libobs/audio-monitoring, decklink,
linux-alsa, linux-pulseaudio, mac-capture, obs-ffmpeg, win-dshow,
win-wasapi)

Default channel layout for 4 channels is 4.0 in FFmpeg.
Replacing quad with 4.0 will improve compatibility since FFmpeg has
better support of its default channel layouts.
2018-01-05 09:48:52 -08:00
pkviet fb580535c9 libobs/media-io: Clean surround API
(also modifies obs-ffmpeg, audio-monitoring, win-wasapi, decklink,
obs-outputs)

Removes speaker layouts which are not exposed in UI.  The speaker
layouts selectable by users in the UI are the most common ones.  It is
not necessary to keep other layouts.  (This basically removes
5POINT1_SURROUND, 7POINT1_SURROUND, SURROUND =3.0).
2018-01-05 09:47:59 -08:00
pkviet bbac3280c1 libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)

Adds surround sound audio support to the core, core plugins, and user
interface.

Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts  (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
		   opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
	 HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
	 videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
         (due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST:	 stereo plugins keep in general only the first two channels.
	 surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
         (not implemented due to lack of usefulness)

Closes jp9000/obs-studio#968
2017-11-26 03:41:53 -08:00
jp9000 b54f70ef8d libobs: Add async video/audio decoupling functions
Decoupling the audio from the video causes the audio to be played right
when it's received rather than attempt to sync up to the video frames.
This is useful with certain async sources/devices when the audio/video
timestamps are not reliable.

Naturally because it plays audio right when it's received, this should
only be used when the async source is operating in unbuffered mode,
otherwise the video frame timing will be out of sync by the amount of
buffering the video currently has.
2017-10-10 06:45:34 -07:00
Shaolin b6042d91ea libobs: Add Pulseaudio audio monitoring support
Checks if the system has Pulseaudio and enables support via the
HAVE_PULSEAUDIO flag.

Closes jp9000/obs-studio#940
2017-09-12 03:37:54 -07:00
Richard Stanway 9e95b2eb6f
Various: Don't use boolean bitfields
Using bitfields causes less optimized code generation and the memory
savings are minimal as none of the objects are instantiated enough
times to be worth it.

See https://blogs.msdn.microsoft.com/oldnewthing/20081126-00/?p=20073
2017-05-10 23:28:46 +02:00
Shaolin e006d961a4 audio-monitoring: Add ability to monitor Outputs
(Note: This commits also modifies the linux-pulseaudio, mac-capture, and
win-wasapi plugins)

Do not prevent the targeted output device from being monitored if the
selected monitor output device is a different one.

Closes jp9000/obs-studio#872
2017-04-05 18:58:08 -07:00
jp9000 65ffb8800c libobs: Apply sync offset to win32 audio monitoring 2017-03-05 14:29:59 -08:00
jp9000 528325578f libobs: Fix audio monitoring delaying perpetually
On windows, when a source has only audio (no video) yet is marked as
capable of both video and audio, it would be programmed to expect a
video frame to synchronize with.  This fixes that potential issue by
detecting whether any video is actually playing or not.
2017-02-21 10:59:02 -08:00
jp9000 d2934eca7e libobs: Implement audio monitoring
Adds functions to turn on audio monitoring to allow the user to hear
playback of an audio source over the user's speaker.  It can be set to
turn off monitoring and only output to stream, or it can be set to
output only to monitoring, or it can be set to both.

On windows, audio monitoring uses WASAPI.  Windows also is capable of
syncing the audio to the video according to when the video frame itself
was played.

On mac, it uses AudioQueue.

On linux, it's not currently implemented and won't do anything (to be
implemented).
2017-02-06 11:44:02 -08:00