2009-01-26 15:06:44 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2009-01-26 15:06:44 +00:00
|
|
|
*
|
audio/out: change license of some core files to LGPL
All contributors of the current code have agreed. ao.c requires a
"driver" entry for each audio output - we assume that if someone who
didn't agree to LGPL added a line, it's fine for ao.c to be LGPL
anyway. If the affected audio output is not disabled at compilation
time, the resulting binary will be GPL anyway, and ootherwise the
code is not included.
The audio output code itself was inspired or partially copied from
libao in 7a2eec4b59f4 (thus why MPlayer's audio code is named libao2).
Just to be sure we got permission from Aaron Holtzman, Jack Moffitt, and
Stan Seibert, who according to libao's SVN history and README are the
initial author. (Something similar was done for libvo, although the
commit relicensing it forgot to mention it.)
242aa6ebd40: anders mostly disagreed with the LGPL relicensing, but we
got permission for this particular commit.
0ef8e555735: nick could not be reached, but the include statement was
removed again anyway.
879e05a7c17: iive agreed to LGPL v3+ only, but this line of code was
removed anyway, so ao_null.c can be LGPL v2.1+.
9dd8f241ac2: patch author could not be reached, but the corresponding
code (old slave mode interface) was completely removed later.
2017-05-20 09:35:25 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-01-26 15:06:44 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-01-26 15:06:44 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
audio/out: change license of some core files to LGPL
All contributors of the current code have agreed. ao.c requires a
"driver" entry for each audio output - we assume that if someone who
didn't agree to LGPL added a line, it's fine for ao.c to be LGPL
anyway. If the affected audio output is not disabled at compilation
time, the resulting binary will be GPL anyway, and ootherwise the
code is not included.
The audio output code itself was inspired or partially copied from
libao in 7a2eec4b59f4 (thus why MPlayer's audio code is named libao2).
Just to be sure we got permission from Aaron Holtzman, Jack Moffitt, and
Stan Seibert, who according to libao's SVN history and README are the
initial author. (Something similar was done for libvo, although the
commit relicensing it forgot to mention it.)
242aa6ebd40: anders mostly disagreed with the LGPL relicensing, but we
got permission for this particular commit.
0ef8e555735: nick could not be reached, but the include statement was
removed again anyway.
879e05a7c17: iive agreed to LGPL v3+ only, but this line of code was
removed anyway, so ao_null.c can be LGPL v2.1+.
9dd8f241ac2: patch author could not be reached, but the corresponding
code (old slave mode interface) was completely removed later.
2017-05-20 09:35:25 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2009-01-26 15:06:44 +00:00
|
|
|
*
|
audio/out: change license of some core files to LGPL
All contributors of the current code have agreed. ao.c requires a
"driver" entry for each audio output - we assume that if someone who
didn't agree to LGPL added a line, it's fine for ao.c to be LGPL
anyway. If the affected audio output is not disabled at compilation
time, the resulting binary will be GPL anyway, and ootherwise the
code is not included.
The audio output code itself was inspired or partially copied from
libao in 7a2eec4b59f4 (thus why MPlayer's audio code is named libao2).
Just to be sure we got permission from Aaron Holtzman, Jack Moffitt, and
Stan Seibert, who according to libao's SVN history and README are the
initial author. (Something similar was done for libvo, although the
commit relicensing it forgot to mention it.)
242aa6ebd40: anders mostly disagreed with the LGPL relicensing, but we
got permission for this particular commit.
0ef8e555735: nick could not be reached, but the include statement was
removed again anyway.
879e05a7c17: iive agreed to LGPL v3+ only, but this line of code was
removed anyway, so ao_null.c can be LGPL v2.1+.
9dd8f241ac2: patch author could not be reached, but the corresponding
code (old slave mode interface) was completely removed later.
2017-05-20 09:35:25 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2009-01-26 15:06:44 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_AUDIO_OUT_H
|
|
|
|
#define MPLAYER_AUDIO_OUT_H
|
2002-07-25 20:28:47 +00:00
|
|
|
|
2011-04-09 00:03:22 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
2013-04-05 21:06:22 +00:00
|
|
|
#include "audio/chmap.h"
|
2013-05-09 13:12:16 +00:00
|
|
|
#include "audio/chmap_sel.h"
|
2012-04-07 13:26:56 +00:00
|
|
|
|
|
|
|
enum aocontrol {
|
|
|
|
// _VOLUME commands take struct ao_control_vol pointer for input/output.
|
|
|
|
// If there's only one volume, SET should use average of left/right.
|
|
|
|
AOCONTROL_GET_VOLUME,
|
|
|
|
AOCONTROL_SET_VOLUME,
|
2012-04-10 01:45:53 +00:00
|
|
|
// _MUTE commands take a pointer to bool
|
|
|
|
AOCONTROL_GET_MUTE,
|
|
|
|
AOCONTROL_SET_MUTE,
|
2013-11-09 23:49:13 +00:00
|
|
|
// Has char* as argument, which contains the desired stream title.
|
|
|
|
AOCONTROL_UPDATE_STREAM_TITLE,
|
2012-04-07 13:26:56 +00:00
|
|
|
};
|
|
|
|
|
2014-02-27 23:56:10 +00:00
|
|
|
// If set, then the queued audio data is the last. Note that after a while, new
|
|
|
|
// data might be written again, instead of closing the AO.
|
2012-04-07 13:26:56 +00:00
|
|
|
#define AOPLAY_FINAL_CHUNK 1
|
|
|
|
|
2014-11-09 08:58:44 +00:00
|
|
|
enum {
|
|
|
|
AO_EVENT_RELOAD = 1,
|
2015-02-12 15:53:56 +00:00
|
|
|
AO_EVENT_HOTPLUG = 2,
|
2018-04-29 17:42:18 +00:00
|
|
|
AO_EVENT_INITIAL_UNBLOCK = 4,
|
2019-10-11 17:25:45 +00:00
|
|
|
AO_EVENT_UNDERRUN = 8,
|
2014-11-09 08:58:44 +00:00
|
|
|
};
|
|
|
|
|
2016-08-04 18:49:20 +00:00
|
|
|
enum {
|
|
|
|
// Allow falling back to ao_null if nothing else works.
|
|
|
|
AO_INIT_NULL_FALLBACK = 1 << 0,
|
|
|
|
// Only accept multichannel configurations that are guaranteed to work
|
|
|
|
// (i.e. not sending arbitrary layouts over HDMI).
|
|
|
|
AO_INIT_SAFE_MULTICHANNEL_ONLY = 1 << 1,
|
2016-08-09 14:22:06 +00:00
|
|
|
// Stream silence as long as no audio is playing.
|
|
|
|
AO_INIT_STREAM_SILENCE = 1 << 2,
|
2016-09-05 19:07:34 +00:00
|
|
|
// Force exclusive mode, i.e. lock out the system mixer.
|
|
|
|
AO_INIT_EXCLUSIVE = 1 << 3,
|
2016-08-04 18:49:20 +00:00
|
|
|
};
|
|
|
|
|
2012-04-07 13:26:56 +00:00
|
|
|
typedef struct ao_control_vol {
|
|
|
|
float left;
|
|
|
|
float right;
|
|
|
|
} ao_control_vol_t;
|
|
|
|
|
2014-10-09 19:21:31 +00:00
|
|
|
struct ao_device_desc {
|
2014-10-10 16:27:21 +00:00
|
|
|
const char *name; // symbolic name; will be set on ao->device
|
|
|
|
const char *desc; // verbose human readable name
|
2014-10-09 19:21:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ao_device_list {
|
|
|
|
struct ao_device_desc *devices;
|
|
|
|
int num_devices;
|
|
|
|
};
|
|
|
|
|
2011-05-04 11:55:15 +00:00
|
|
|
struct ao;
|
2013-08-01 15:41:32 +00:00
|
|
|
struct mpv_global;
|
2014-03-07 14:24:32 +00:00
|
|
|
struct input_ctx;
|
|
|
|
struct encode_lavc_context;
|
|
|
|
|
2018-05-21 13:11:19 +00:00
|
|
|
struct ao_opts {
|
|
|
|
struct m_obj_settings *audio_driver_list;
|
|
|
|
char *audio_device;
|
|
|
|
char *audio_client_name;
|
|
|
|
double audio_buffer;
|
|
|
|
};
|
|
|
|
|
2013-08-01 15:41:32 +00:00
|
|
|
struct ao *ao_init_best(struct mpv_global *global,
|
2016-08-04 18:49:20 +00:00
|
|
|
int init_flags,
|
2016-09-16 12:23:54 +00:00
|
|
|
void (*wakeup_cb)(void *ctx), void *wakeup_ctx,
|
2013-07-21 19:33:17 +00:00
|
|
|
struct encode_lavc_context *encode_lavc_ctx,
|
|
|
|
int samplerate, int format, struct mp_chmap channels);
|
2014-03-08 23:49:39 +00:00
|
|
|
void ao_uninit(struct ao *ao);
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
void ao_get_format(struct ao *ao,
|
|
|
|
int *samplerate, int *format, struct mp_chmap *channels);
|
2014-03-07 14:24:32 +00:00
|
|
|
const char *ao_get_name(struct ao *ao);
|
|
|
|
const char *ao_get_description(struct ao *ao);
|
|
|
|
bool ao_untimed(struct ao *ao);
|
2013-11-10 22:38:18 +00:00
|
|
|
int ao_play(struct ao *ao, void **data, int samples, int flags);
|
2012-04-07 13:26:56 +00:00
|
|
|
int ao_control(struct ao *ao, enum aocontrol cmd, void *arg);
|
audio: add audio softvol processing to AO
This does what af_volume used to do. Since we couldn't relicense it,
just rewrite it. Since we don't have a new filter mechanism yet, and the
libavfilter is too inconvenient, do applying the volume gain in ao.c
directly. This is done before handling the audio data to the driver.
Since push.c runs a separate thread, and pull.c is called asynchronously
from the audio driver's thread, the volume value needs to be
synchronized. There's no existing central mutex, so do some shit with
atomics. Since there's no atomic_float type predefined (which is at
least needed when using the legacy wrapper), do some nonsense about
reinterpret casting the float value to an int for the purpose of atomic
access. Not sure if using memcpy() is undefined behavior, but for now I
don't care.
The advantage of not using a filter is lower complexity (no filter auto
insertion), and lower latency (gain processing is done after our
internal audio buffer of at least 200ms).
Disavdantages include inability to use native volume control _before_
other filters with custom filter chains, and the need to add new
processing for each new sample type.
Since this doesn't reuse any of the old GPL code, nor does indirectly
rely on it, volume and replaygain handling now works in LGPL mode.
How to process the gain is inspired by libavfilter's af_volume (LGPL).
In particular, we use exactly the same rounding, and we quantize
processing for integer sample types by 256 steps. Some of libavfilter's
copyright may or may not apply, but I think not, and it's the same
license anyway.
2017-11-29 20:30:10 +00:00
|
|
|
void ao_set_gain(struct ao *ao, float gain);
|
2011-04-09 00:03:22 +00:00
|
|
|
double ao_get_delay(struct ao *ao);
|
|
|
|
int ao_get_space(struct ao *ao);
|
|
|
|
void ao_reset(struct ao *ao);
|
|
|
|
void ao_pause(struct ao *ao);
|
|
|
|
void ao_resume(struct ao *ao);
|
2014-03-08 23:49:39 +00:00
|
|
|
void ao_drain(struct ao *ao);
|
2014-04-17 21:48:09 +00:00
|
|
|
bool ao_eof_reached(struct ao *ao);
|
2014-11-09 08:58:44 +00:00
|
|
|
int ao_query_and_reset_events(struct ao *ao, int events);
|
2020-02-13 00:06:02 +00:00
|
|
|
int ao_add_events(struct ao *ao, int events);
|
2018-04-29 17:42:18 +00:00
|
|
|
void ao_unblock(struct ao *ao);
|
2014-11-09 08:58:44 +00:00
|
|
|
void ao_request_reload(struct ao *ao);
|
2015-02-12 15:53:56 +00:00
|
|
|
void ao_hotplug_event(struct ao *ao);
|
|
|
|
|
|
|
|
struct ao_hotplug;
|
|
|
|
struct ao_hotplug *ao_hotplug_create(struct mpv_global *global,
|
2016-09-16 12:23:54 +00:00
|
|
|
void (*wakeup_cb)(void *ctx),
|
|
|
|
void *wakeup_ctx);
|
2015-02-12 15:53:56 +00:00
|
|
|
void ao_hotplug_destroy(struct ao_hotplug *hp);
|
|
|
|
bool ao_hotplug_check_update(struct ao_hotplug *hp);
|
|
|
|
struct ao_device_list *ao_hotplug_get_device_list(struct ao_hotplug *hp);
|
2011-04-09 00:03:22 +00:00
|
|
|
|
2014-10-10 16:27:21 +00:00
|
|
|
void ao_print_devices(struct mpv_global *global, struct mp_log *log);
|
2014-10-09 19:21:31 +00:00
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_AUDIO_OUT_H */
|