Commit Graph

1929 Commits

Author SHA1 Message Date
mistraid121 574f269d32 af_lavcac3enc: fix memory leak on 2ch audio
If processing is not required, the frame would be leaked as it is not used.
2024-03-19 19:32:55 +01:00
nanahi 5fea0f9a47 various: use thread safe mp_strerror() 2024-03-19 19:30:27 +01:00
nanahi e9f966595c ao_lavc: fix warning: ISO C forbids forward references to 'enum' types 2024-03-19 08:58:18 +01:00
nanahi 82a186567e various: fix -Wold-style-declaration warning
warning: `static' is not at beginning of declaration
2024-03-19 08:58:18 +01:00
sfan5 ead9f892b3 various: use static assertions where appropriate 2024-03-17 20:04:04 +01:00
Vilius ab419a6660 ao_coreaudio: stop audio unit after idle timeout
Commit 39f7f83 changed ao_driver.reset to use AudioUnitReset instead of
AudioOutputUnitStop. The problem with calling AudioOutputUnitStop was
that AudioOutputUnitStart takes a significant amount of time after a
stop when a wireless audio device is being used. This resulted in
lagging that was noticeable to users during seeking and short
pause/resume cycles. Switching to AudioUnitReset eliminated this
lagging.

However with the switch to AudioUnitReset the macOS daemon coreaudiod
continued to consume CPU time and did not release a powerd assertion
that it created on behalf of mpv, preventing macOS from sleeping.

This commit will change ao_coreaudio.reset to call AudioOutputUnitStop
after a delay if playback has not resumed. This preserves the faster
restart of playback for seeking and short pause/resume cycles and avoids
preventing sleep and needless CPU consumption.

Fixes #11617

The code changes were authored by @orion1vi and @lhc70000.

Co-authored-by: Collider LI <lhc199652@gmail.com>
2024-03-16 15:00:46 +01:00
Alex Mitzsch 1bf821ebdc ad_spdif: update deprecated FF_PROFILE_DTS_HD_HRA definition
One deprecated FF_PROFILE_DTS_HD_HRA definition was left unaltered - fix that.
2024-03-10 20:59:20 +01:00
Dudemanguy 62b1bad755 ad_spdif: handle const buf pointee in avio_alloc_context
ffmpeg recently changed this field to be const which causes our CI to
fail on newer versions.

See: 2a68d945cd
2024-03-07 22:03:55 +00:00
Dudemanguy 83bad548d2 ad_spdif: handle deprecated FF_PROFILE_* definitions
See: 8238bc0b5e
2024-03-05 19:04:11 +01:00
sfan5 d955dfab29 misc/jni: reduce duplication in mapping struct
'name' was in fact unused when reading fields or methods, so it can be merged with 'method'.
Also changed the type of 'mandatory' to bool.
2024-02-28 16:11:54 +01:00
sfan5 5b1eaf3ff1 misc/jni: introduce macros for deleting references 2024-02-28 16:11:54 +01:00
sfan5 1f3758adea ao_audiotrack: refactor JNI class retrieval
- split mapping from field struct
- mark field struct static
- define list of classes to reduce more repetitive code
2024-02-28 16:11:54 +01:00
sfan5 87d30899ff ao_audiotrack: remove two dead variables 2024-02-28 16:11:54 +01:00
sfan5 3c1c848c2b ao_audiotrack: fix missing check for passthrough support 2024-02-28 16:11:54 +01:00
der richter 86fa9b18a3 osdep/mac: make mac naming of files, folders and function consistent
rename all macOS namings (osx, macosx, macOS, macos, apple) to mac, to
make naming consistent.
2024-02-28 15:52:47 +01:00
nanahi 2872e23aea ao: don't clip floating point formats at non-unity gain
Currently, the softvol gain control attempts to clip floating point ao
formats within -1 and +1. However, this is "optimized out" at unity gain,
where no clipping is applied. This results in inconsistent behavior when
the source audio is already out of -1 and +1 range, where a gain of 0.99
results in clipping, but not at exactly 1.

Since a big advantage of floating point audio data is that they do not
lose information through out-of-range data because the ao sink can apply
suitable negative gain to prevent clipping before converting them to
integer formats, clipping should not be performed on these data.

Fix this by removing the existing clipping behavior. It now results in
a simple multiplication, which faciliates compiler auto-vectorization
of this operation over audio data.
2024-02-25 18:23:57 +00:00
sunpenghao 2cc3bc12db ao_wasapi: scale queried AO volume to (0, 100)
This was done for `AOCONTROL_SET_VOLUME` but not `AOCONTROL_GET_VOLUME`.
2024-02-24 05:26:56 +00:00
sunpenghao 6863eefc3d ao_wasapi: address premature buffer fills in exclusive mode
Currently, running AO control wakes up the WASAPI renderer thread in the
`WASAPI_THREAD_FEED` state, where `thread_feed` will be called. However,
it seems that in recent Windows versions (tested on Windows 10 build
19044.3930 and Windows 11 build 22631.3007) we can't know if it is safe
to feed more audio data in event-driven exclusive mode:
- `IAudioClient_GetCurrentPadding` always returns `bufferFrameCount`,
  even if *NO* data has ever been written. This means we don't know how
  much free space we have that is available for writing. This is not the
  case in shared mode, where the return value correctly reflects the
  size of data waiting to be processed. As a sidenote, MS did not
  document the precise definition of the return value for an
  event-driven, exclusive stream [1].
- `IAudioRenderClient_GetBuffer` never fails. We can call it for 10
  times in a roll, each time requesting an entire buffer (the unit at
  which data is exchanged in exclusive mode using event-driven
  buffering; there are 2 such buffers) and get a successful return code
  everytime. In shared mode, we get `AUDCLNT_E_BUFFER_TOO_LARGE` if we
  request a buffer larger than that currently available.

As a result, `thread_feed` will always write `bufferFrameCount` frames
of audio in exclusive mode. There will therefore be glitches each time
`thread_control` is called due to the subsequent `thread_feed`
overwriting frames yet to be processed. Also, an irreversible error is
accumulated to `sample_count` as long as there is no AO reset, leading
to eventual, unbounded A/V desync.

As a fix to the issue, add a dedicated state for dispatch queue
processing so that `thread_feed` is only called when signaled by the OS.
The buffer checks in `thread_feed` that use `GetCurrentPadding` in
exclusive mode are kept in case there are older versions where the two
APIs behave differently.

Closes #12615.

[1] https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-getcurrentpadding
2024-02-24 05:26:56 +00:00
der richter d954646d29 various: make mentions of macOS consistent
change all mentions and variations of OSX, OS X, MacOSX, MacOS X, etc
consistent. use the official naming macOS.
2024-02-21 20:46:53 +01:00
llyyr 6a5a3ec3bf af_lavcac3enc: don't use deprecated `avcodec_close`
Deprecated upstream 1cc24d7495

We need to reallocate the context here because `avcodec_free_context`
also frees the context, and we want to reuse the context with some
reconfig.
2024-02-19 18:09:58 +01:00
Thomas Weißschuh 5c252715bd ao_pipewire: add support for SPDIF formats 2024-02-15 16:43:25 +00:00
Thomas Weißschuh 790b12da89 ao_pipewire: don't interpret unknown formats
Interpreting data in the wrong sample format has unpredictable results
and may damage hardware and hurt users.
Instead error out.
2024-02-15 16:43:25 +00:00
Kacper Michajłow 5d8faff9bf ao_sndio: add missing config.h include 2024-02-07 14:44:52 +00:00
Thomas Weißschuh 8ecb462a9c audio: rename ao_read_data_unlocked
As mentioned in [0] the suffix "_locked" would have been the appropriate
naming in line with similar uses inside mpv.
See `mp_abort_recheck_locked()`, `mp_abort_trigger_locked()`,
`retrigger_locked()`, `wakeup_locked()`...

[0] https://github.com/mpv-player/mpv/pull/12811#discussion_r1477518525
2024-02-05 09:25:48 -08:00
Alex Mitzsch 68f1057d2e ad_spdif: fix DTS 44.1khz passthrough playback
Fix DTS passthrough playback of 44.1 khz content. Also, take into account that there are some DTS variants with a samplerate of 96khz (e.g. DTS 24/96), somehow they are recognized wrongly as 48khz by the code. Don´t rely on this "bug", do it correctly. Now every samplerate above 44.1Khz is correctly treated as 48khz, and 44.1khz files are treated as 44.1khz for bitstreaming.
2024-01-24 21:21:01 +01:00
llyyr a05c363b7f chmap: mp_image_pool: drop stale mentions of Libav in comments 2024-01-20 16:10:20 +00:00
sfan5 431b420dd6 ao_null: fix reset() implementation
Stopping output implies that it can't be paused anymore.
This is consistent with the documented API in internal.h as well
as the behavior of other AOs.

resolves #13267
2024-01-12 20:36:04 +01:00
sfan5 9565675488 various: use correct PATH_MAX for win32
In commit c09245cdf2
long-path support was enabled for mpv without actually
making sure that there was no code left that used the
old limit (260 Unicode chars) for buffer sizes.
This commit fixes all but one case.
2023-12-27 22:55:56 +01:00
Kacper Michajłow b323d2877a ao_wasapi: clean GUID definitions
Add ifndefs to define only when needed and remove some already defined
ones in mingw.
2023-12-03 22:24:13 +01:00
Kacper Michajłow a436af0f26 ao_wasapi: fix MP3 GUID
While CEA-861 defines MP2 as 0x5 and MP3 as 0x4, the GUIDs defined in
ksmedia.h are in reverse order.

See: https://github.com/MicrosoftDocs/windows-driver-docs/pull/3742
2023-12-03 22:24:13 +01:00
Kacper Michajłow cb29cbe1ba ao_sndio: remove duplicated condition 2023-11-28 10:46:16 +01:00
Kacper Michajłow ed107c4116 meson: adjust win32 defines
- Don't define _GNU_SOURCE on Windows, no need
- Define WIN32_LEAN_AND_MEAN to strip some unneded headers from
  windows.h
- Define NOMINMAX and _USE_MATH_DEFINES as they are common for Windows
  headers
2023-11-25 12:38:20 +01:00
Kacper Michajłow f84024b9dd ao_coreaudio_chmap: suppress vla warning 2023-11-24 10:05:09 +01:00
sfan5 aa362fdcf4 various: replace some OOM handling
We prefer to fail fast rather than degrade in unpredictable ways.
The example in sub/ is particularly egregious because the code just
skips the work it's meant to do when an allocation fails.
2023-11-24 10:04:55 +01:00
leetoburrito e22a2f0483 ao/coreaudio_exclusive: fix segfault when changing formats
PR #12747 missed updating a variable declaration in
`ca_change_physical_format_sync`, which ultimately leads to the thread
crashing.  The problem reproduces consistently on AS Macs (I don't have
an Intel Mac to test on anymore), and produces stack traces like the
following:

```
Thread 3 Crashed:: mpv
0   libsystem_kernel.dylib                     0x18cebd11c __pthread_kill + 8
1   libsystem_pthread.dylib                    0x18cef4cc0 pthread_kill + 288
2   libsystem_c.dylib                          0x18ce04ad4 __abort + 136
3   libsystem_c.dylib                          0x18cdf56c4 __stack_chk_fail + 96
4   mpv                                        0x1026b66d0 ca_change_physical_format_sync + 420
5   mpv                                        0x1026b3b70 init + 1052
6   mpv                                        0x1025c5afc ao_init + 332
7   mpv                                        0x1025c5bec ao_init + 572
8   mpv                                        0x1025c5830 ao_init_best + 1228
9   mpv                                        0x102622fac fill_audio_out_buffers + 1820
10  mpv                                        0x1026450d0 run_playloop + 132
11  mpv                                        0x10263f958 play_current_file + 5116
12  mpv                                        0x10263e4e8 mp_play_files + 452
13  mpv                                        0x102641308 mpv_main + 128
14  mpv                                        0x10269f520 playback_thread + 40
15  libsystem_pthread.dylib                    0x18cef5034 _pthread_start + 136
16  libsystem_pthread.dylib                    0x18ceefe3c thread_start + 8
```

Note that non-exclusive output seems to be unaffected.  To reproduce
this problem (and/or test this fix), pass `--audio-exclusive=yes` to
mpv.
2023-11-23 11:22:21 +01:00
Kacper Michajłow fd0e2af1f2 ao_wasapi: add missing comma in strings array 2023-11-18 23:55:28 +00:00
Kacper Michajłow a6fb9321ea audio: fix UB when casting INFINITY to integer
Fixes busy wait, because in practice inf would be casted to 0.

Fixes: 174df99
2023-11-15 14:57:18 +00:00
Thomas Weißschuh a96d26e63a audio: avoid unnecessary silence padding in read_buffer()
Not all callers of read_buffer() require the buffer to be padded with
silence.
2023-11-08 20:26:23 +01:00
Thomas Weißschuh 0b43b74c15 ao_audiotrack: switch to ao_read_data_nonblocking() 2023-11-08 20:26:23 +01:00
Thomas Weißschuh 36d5b52612 ao_coreaudio: switch to ao_read_data_nonblocking() 2023-11-08 20:26:23 +01:00
Thomas Weißschuh 5aa2068270 ao_pipewire: switch to ao_read_data_nonblocking()
Avoid blocking the process callback as it runs with realtime privileges.
2023-11-08 20:26:23 +01:00
Thomas Weißschuh 4a134f441d audio: introduce ao_read_data_nonblocking()
This behaves similar to ao_read_data() but does not block and may return
partial data.
2023-11-08 20:26:23 +01:00
Kacper Michajłow 174df99ffa ALL: use new mp_thread abstraction 2023-11-05 17:36:17 +00:00
Guido Cella 040622f6b7 various: remove trailing whitespace 2023-10-30 16:45:47 +00:00
Umar Getagazov 0341a6f1d3 ao_coreaudio: signal buffer underruns
Change the resulting buffer sizes to match the actual amount of samples
read, and set a flag in case no samples were read at all.
2023-10-29 21:19:04 +01:00
Kacper Michajłow cb829879af mp_threads: rename threads for consistent naming across all of them
I'd like some names to be more descriptive, but to work with 15 chars
limit we have to make some sacrifice.

Also because of the limit, remove the `mpv/` prefix and prioritize
actuall thread name.
2023-10-27 23:18:56 +00:00
Kacper Michajłow 729f2fed2c semaphore_osx: change mp_sem_timedwait to mp_time 2023-10-26 20:06:14 +00:00
Kacper Michajłow f659a60dfa semaphore_osx: don't overwrite global symbols 2023-10-26 20:06:14 +00:00
sfan5 3af25edfa5 Revert "audio: don't block on lock in ao_read_data"
It was found that this causes issues with at least ao_coreaudio,
essentially revealing a way bigger issue:
Some AOs don't check for 0 and/or have no way to deal with short writes.
Someone will have to figure out a fix later but get rid of the direct
cause for now.

This reverts commit ae908a70ce.
2023-10-24 10:38:07 +02:00
Thomas Weißschuh ae908a70ce audio: don't block on lock in ao_read_data
ao_read_data() is used by pull AOs potentially from threads managed by
external libraries.  These threads can be sensitive to blocking.
For example the pipewire ao is using a realtime thread for the
callbacks.
2023-10-20 21:33:46 +02:00