Commit Graph

374 Commits

Author SHA1 Message Date
Stefano Pigozzi 6473cc59b1 ao_coreaudio: remove chmap selection if format is digital 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 6d2f9a2804 ao_coreaudio: remove volume multiplication by 4
kHALOutputParam_Volume is the linear gain so it should be at maximum 1 to
keep the audio quality good. No idea why it was more than that.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi a2d106cb31 ao_coreaudio: remove device property listener on uninit
Also extract this functionality inside a function in coreaudio_common
2013-07-22 21:53:18 +02:00
Stefano Pigozzi 7b2b292343 ao_coreaudio: print help string in one go 2013-07-22 21:53:18 +02:00
Stefano Pigozzi 5a4ae42892 ao_coreaudio: change all ++var to var++
Luckily they all were inside for loops so the functionality does not actually
change.
2013-07-22 21:53:18 +02:00
Stefano Pigozzi d3fb585b58 ao_coreaudio: change private vars names to match mpv conventions 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d9c0dc7733 ao_coreaudio: remove packetSize private variable 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 7d7381f9cf ao_coreaudio: refactor play/pause 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d4b161f37d ao_coreaudio: refactor uninit 2013-07-22 21:53:17 +02:00
Stefano Pigozzi f392ffe95c ao_coreaudio: remove a fixme since that seems fixed 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 6e44b12240 ao_coreaudio: ca_msg: add trailing \n where missing 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 88425625cf ao_coreaudio: refactor play 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 065e446e04 ao_coreaudio: extract mixmode set/unset in utility functions 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 838fa07376 ao_coreaudio: move AudioStreamChangeFormat to common file and refactor 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 40f6e2e041 ao_coreaudio: extract methods to lock/unlock device for digital output 2013-07-22 21:53:17 +02:00
Stefano Pigozzi e3ce0f0f8e ao_coreaudio: lpcm: remove buffer size calculation depending on audio unit 2013-07-22 21:53:17 +02:00
Stefano Pigozzi 1640ce3262 ao_coreaudio: refactor initialization
The initialization is split more clearly between compressed and lpcm case.
For the compressed case, format selection is simplified a lot and negotiation
removed. The way it was written it just passed back to the core the original
requested format, not what was found available on hardware.

Since this is most likely useless for the compressed case, I didn't bother
with this. In the future I'd like to split this AO in two one that only uses
the AUHAL and the other with direct access to the hardware so that even
passthrough of lcpm can be possible. This would decrease the latency,
audiophiles would like that.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi f9a31bc3d9 ao_coreaudio: refactor print_help 2013-07-22 21:53:17 +02:00
Stefano Pigozzi f35f6a34b5 ao_coreaudio: split out some utility functions and refactor them
Split out some utility functions that use the CoreAudio API but are not related
the main task of the AOs (which is to move data correctly to the ringbuffer).
These are mainly need for the verbosity of the CoreAudio API and are just
obscuring the 'real' code.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi dc8eb9d77a ao_coreaudio: make variable names shorter
property_address -> p_addr
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 45479825ba ao_coreaudio: add error check function and macro
WIP
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 3edb605172 ao_coreaudio: dry up ca_msg and use it everywhere
Change the ca_msg macro to pass along MSGT_AO automatically. Also use it for
every output for consistency.
2013-07-22 21:53:17 +02:00
Stefano Pigozzi c4bed92280 ao_coreaudio: simplify digital render callback
It was reported that it also works by not setting the read size in the
AudioBuffer (now idea how, but I will discover it later).
2013-07-22 21:53:17 +02:00
Stefano Pigozzi 8cf36cf950 ao_coreaudio: rewrite spdif render callback 2013-07-22 21:53:17 +02:00
Stefano Pigozzi d427b4fd1c ao_coreaudio: simplify render callback
Read only the requested amount by the AUHAL (instead of all the buffered data).
No idea what the deal is with pausing the audio units if there is no audio to
play, maybe to avoid underruns of some sort. Anyway from my tests this
condition never occurred so I'm removing it all.
2013-07-22 21:53:16 +02:00
wm4 c729df3d10 af_bs2b: use new option API 2013-07-22 15:11:04 +02:00
wm4 74146a855c af_lavfi: switch to new option API
This makes it actually possible to use the filter with more complicated
filter graphs (such as graphs containing the "," character).
2013-07-22 15:11:04 +02:00
wm4 465b162d13 af_scaletempo: use new option API 2013-07-22 15:11:04 +02:00
wm4 7c2bf06615 af_lavrresample: switch to new option API
Also add a "o" suboption, which should allow fine control over
libavresample.
2013-07-22 15:11:04 +02:00
wm4 1189f64dd1 af_force: use new option API 2013-07-22 15:11:04 +02:00
wm4 3b8dfddb4c audio/filter: use new option API
Make the VF/VO/AO option parser available to audio filters. No audio
filter uses this yet, but it's still a quite intrusive change.

In particular, the commands for manipulating filters at runtime
completely change. We delete the old code, and use the same
infrastructure as for video filters. (This forces complete
reinitialization of the filter chain, which hopefully isn't a problem
for any use cases. The old code forced reinitialization too, but it
could potentially allow a filter to cache things; e.g. consider loaded
ladspa plugins and such.)
2013-07-22 15:11:03 +02:00
wm4 221ef23d0d af_force: add option that causes filter to fail at initialization
This is useful for debugging.
2013-07-22 15:06:43 +02:00
wm4 0c9b0ba40d af: fix recovery code for filter insertion (changing volume with spdif crash)
This code is supposed to run if dynamic filter insertion (such as when
inserting a volume filter in mixer.c) fails. Then it removes all filters
and recreates the default list of filters. But the code just blew up and
entered an endless loop, because it removed even the sentinel in/out
filters. This could happen when trying to use softvol controls while
using spdif, but also other situations. Fix it by calling the correct
code.

Also remove these obnoxious yoda-conditions.
2013-07-22 15:06:07 +02:00
wm4 f86b94f9b4 audio/decode: remove macro crap
Declare decoders directly, instead of using the LIBAD_EXTERN macro. This
is simpler (no weird magic) and more extensible.
2013-07-22 14:41:56 +02:00
Diogo Franco (Kovensky) 58338f9240 ao_wasapi: Make default on Windows.
Ahead of OSS because cygwin provides OSS.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 1b2dc3613f ao_wasapi: Fix S/PDIF passthrough init
MSDN tells me to multiply the samplerates by 4 (for setting up the S/PDIF
signal frequency), but doesn't mention that I'm only supposed to do it
on the new, NT6.1+ IEC 61937 structs. Works on my Realtek Digital Output,
but as I can't connect any hardware to it I can't hear the result.

Also, always ask for little-endian AC3. I'm not sure if this is supposed
to be LE or NE, but Windows is LE on all platforms, so we go with LE.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 9fe2772780 ao_wasapi: Log the passthrough format in MSGL_V 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) a8b4be274c ao_wasapi: Also do passthrough for AF_FORMAT_MPEG2
That's the sample format ad_spdif uses when the source is MP3.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) dcf38e0190 ao_wasapi: Support S/PDIF passthrough
Entirely untested as this troper has no S/PDIF hardware.

Refuses trying any other format if we can't use passthrough, or we would
end up sending white noise at the user.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 58e3d3f207 ao_wasapi: Fix double free on uninit
Caused by incorrect conversion to the m_option API: since we don't allocate
the state ourselves, we also don't free it ourselves.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) c62395dc09 ao_wasapi: Support loading devices by name
Do an strstr match against the device description and, if we have only
a single match, take it. This works as long as the devices in the system
don't change, but it's not supposed to be reliable; if one wants
reliability, one uses the device ID string.

Formatting.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) ad6acddbcf ao_wasapi: Don't search for devices as part of validation
This could turn valid parameters into syntax errors by the mere presence
or abscence of a device (e.g. USB audio devices), so don't do that.

We do validate that, if the parameter is an integer, it is not negative.
We also respond to the "help" parameter, which does the same as the "list"
suboption but exits after listing.

Demote the validation logging to MSGL_DBG2.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d68fa0531f ao_wasapi: Change function macros to require semicolon after invocation
Add semicolons where they were missing.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 964341b02d ao_wasapi: Use OPT_STRING_VALIDATE for device suboption
Validates by trying to pick the device using the device enumerator and
aborting with out of range on failure.

Refactors find_and_load_device to not use the wasapi_state; it might be
called during validation. Adds missing CoInitialize/CoUninitialize calls.
Remove unused variables (the SAFE_RELEASE macros keep them referenced so
compiler warnings don't help finding them...).

Remove the IMMDeviceEnumerator from the wasapi_state, it's only needed
during initialization and initialization is now well factored enough to
get rid of it.

Try and connect to unplugged devices as well when using the device ID
string.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d42c3e51b4 ao_wasapi: Fully convert to m_option API 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 56274c6664 ao_wasapi: Don't leak the default device's ID when listing devices
Also remove unused variable.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 32cb190855 ao_wasapi: Annotate the default device when listing devices 2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) efc3668fbe ao_wasapi: Refactor device listing/loading
Omit "{0.0.0.00000000}." on devices that start with that substring,
re-add when searching for devices by ID.

Log the device ID of the default device.

Log the friendly name of the used device.

Consistently refer to endpoints/devices as devices, as this is more
consistent with mpv terminology.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) d5adaed9d8 ao_wasapi0: Rename to ao_wasapi
Nobody knows what the 0 was for. There's no "WASAPI version 0". Just take
it out.
2013-07-22 02:42:38 +02:00
Diogo Franco (Kovensky) 553ed6b32f ao_wasapi0: Use the mix format directly in try_mix_format 2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) d9a1358505 ao_wasapi0: Don't complain about failed init during AO probing
Only if the user specifically asked for ao_wasapi0.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) 4cf1fc678f ao_wasapi0: Don't fail init when listing devices 2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) 0081f1facd ao_wasapi0: Demote "negotiation failed" message to MSGL_V
Could spam the console with what may be harmless in some cases. We already
complain loudly if we're stuck checking this too many times.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) df1922babe ao_wasapi0: Support shared mode, better format guessing method
Uses WASAPI in shared mode by default, add :exclusive flag to choose
exclusive mode (duh). WASAPI works somewhat different in shared mode:
the OS suggests the sample format to use, and the GetBuffer call is
done slightly differently.

The shared mode driver does not consume audio as fast as it notifies
the thread; we need to check how much we're allowed to write. Not doing
this correctly results in spamming the console with
AUDCLNT_E_BUFFER_TOO_LARGE errors.

When guessing formats for exclusive mode, try several sample size and
sample rate combinations instead of just falling back to s16le@44100hz.
If none of the rates are accepted, tries remixing >6 channels to 5.1
channels. Failing that, tries remixing to stereo. Failing everything,
including the CD Red Book format, what else is left to test?

Calculate buffer_block_size based on the configured channels and bytes
per sample; MSDN docs say nBlockAlign is not guaranteed to be set for
anything but integer PCM formats.
2013-07-22 02:42:37 +02:00
Diogo Franco (Kovensky) f12e14849d ao_wasapi0: Support device enumeration and selection
Adds the :list suboption to ao_wasapi0, which enumerates the audio endpoints
in the system.

Adds the :device=<n> suboption, which either takes an ID string (as output by
list) or a device number and uses the requested device instead of the system
default.
2013-07-22 02:42:37 +02:00
wm4 15ab75c7a0 ao_dsound: use new option API 2013-07-22 00:11:06 +02:00
wm4 0c28dc6adc ao_jack: use new option API 2013-07-22 00:03:57 +02:00
wm4 ecc5cb67f8 ao_oss: switch to new option API 2013-07-21 23:52:40 +02:00
wm4 5b91ba0a8d options: remove --mixer and --mixer-channel, turn them into alsa/oss subopts
These two options were supported by ALSA and OSS only. Further, their
values were specific to the respective audio systems, so it doesn't make
sense to keep them as top-level options.
2013-07-21 23:35:14 +02:00
wm4 5c610836cd ao_rsound: use new option API
Untested. I don't even know if this compiles. I have no clue what rsound
even is.
2013-07-21 23:27:32 +02:00
wm4 12e645fc24 ao_sdl: use new option API 2013-07-21 23:27:32 +02:00
wm4 73dc678c25 ao_openal: use new option API 2013-07-21 23:27:32 +02:00
wm4 ce89ba6d75 ao_pulse: use new option API
Untested, but should be fine.
2013-07-21 23:27:31 +02:00
wm4 3cdf4cf14d options: hide encoding AO/VO in help output
These can't be used manually. Encoding is enabled with -o instead, and
the encoding AO/VO is selected using internal mechanisms.
2013-07-21 23:27:31 +02:00
wm4 2111d7bc05 ao_alsa: use new option API (changes syntax)
This changes how device names are handled. Before this commit, device
names were mangled in strange ways to avoid clashing with the option
parser syntax. "." was replaced with ",", and "=" with ":" (the user had
to do the inverse to get the correct device name).

The "new" option parser has multiple ways to escape option strings, so
we don't need this confusing hack anymore.

Add an explicit note to the manpage as well.
2013-07-21 23:27:31 +02:00
wm4 38f81c618e ao_pcm: use new option API 2013-07-21 23:27:31 +02:00
wm4 38f712d96d ao_portaudio: use new option API
This basically serves as example. All other AOs should be ported as
well.
2013-07-21 23:27:31 +02:00
wm4 7eba27c125 options: use new option code for --ao
This requires completely refactoring the AO creation code too.
2013-07-21 23:27:31 +02:00
Diogo Franco (Kovensky) d0b129971a ao_wasapi0: Don't starve the WASAPI thread on seeks
Seeking calls thread_reset, but doesn't call thread_play. thread_reset
would disable WASAPI events, but they would never get re-enabled unless
the user paused and then unpaused.

Keep track of whether the stream is paused or not (there already was a
field for that, but it was apparently unused), and if it's not paused,
call thread_play after thread_reset. Fixes mpv freezing after seeks.
2013-07-20 02:21:04 +02:00
Diogo Franco (Kovensky) 20c2947cbb ao_wasapi0: Don't release WASAPI buffer twice
Would cause bogus AUDCLNT_E_OUT_OF_ORDER errors.
2013-07-20 02:21:00 +02:00
Diogo Franco (Kovensky) 9ab73b6373 ao_wasapi0: Make it compile on cygwin64
Fixes format specifies that assume windows TYPEDEFS are as long as they look
like they are.

Remove calls to _beginthreadex and _endthreadex, these are only present on
microsoft's C runtimes. Replace by the otherwise identical CreateThread and
ExitThread calls.

This actually requires fixes to devicetopology.h, but the problem has been
(kinda) reported to mingw-w64:

<Kovensky> I see that those KSJACK* structs are supposedly declared in
  devicetopology.h itself, but for some reason (some of?) the decls that use
  them aren't seeing them?
<Kovensky> ok, it seems that it expects ks.h and ksmedia.h to declare those
  structs, but it doesn't
<Kovensky> the included files declare KDATAFORMAT, KSIDENTIFIER and LUID (and
  the associated pointer typedefs)
<Kovensky> but everything else is essentially inside #if 0
<Kovensky> changing the #ifndef _KS_ to only include KDATAFORMAT, KSIDENTIFIER
  and LUID (and putting the KSJACK stuff outside that #ifndef) makes the
  header compile
<Kovensky> it solves my immediate problem, but if that happened to begin with
  there's probably something more wrong with the ks headers :S
2013-07-20 02:20:46 +02:00
wm4 66a9eb570d demux_mkv: never force output sample rate
Matroska has an output sample rate (OutputSamplingFrequency), which in
theory should be forced instead of whatever the decoder outputs. But it
appears no software (other than mplayer2 and mpv until now) actually
respects this. Even worse, there were broken files around, which played
correctly with (in theory) broken software, but not mplayer2/mpv. Hacks
were added to our code to play these files correctly, but they didn't
catch all cases.

Simplify this by doing what everyone else does, and always use the
decoder's sample rate instead. In particular, we try to handle all
sample rate issues like libavformat's Matroska demuxer does.
2013-07-16 22:44:15 +02:00
wm4 e18ffd6b99 Merge branch 'remove_old_demuxers'
The merged branch doesn't actually just remove old demuxers, but also
includes a branch of cleanups and some refactoring.

Conflicts:
	stream/stream.c
2013-07-14 17:59:26 +02:00
Jonathan Yong 27d352afbd ao_wasapi0: use new mp_ring buffer 2013-07-12 20:01:23 +02:00
wm4 6f6632b8dd ad_lavc: re-unsimplify, fix libavcodec API usage
It turns out that some code that was removed earlier was still needed.
avcodec_decode_audio4() can decode packets "partially". In that case,
you have to "slice" the packet and call the decode function again.

Codecs which need this are obscure and in low numbers. One sample that
needs it is here:

   rsync://fate-suite.ffmpeg.org/fate-suite/lossless-audio/luckynight-partial.shn

(This one decodes in rather small increments.)

The new code is much simpler than what has been removed earlier,
though. The fact that we own the packet returned by the demuxer helps
a lot.

Not sure what should happen if avcodec_decode_audio4() returns 0.
Currently, we throw away the packet in this case. We don't want to be
stuck in an endless loop (could happen if the decoder produces no
output either).
2013-07-11 19:20:41 +02:00
wm4 23e303859a mplayer: fix incorrect audio sync after format changes
This is not directly related to the handling of format changes itself,
but playing audio normally after the change. This was broken: the output
byte rate was not recalculated, so audio-video sync was simply broken.
Fix this by calculating the byte rate on the fly, instead of storing it
in sh_audio.

Format changes are relatively common (switches between stereo and 5.1
in TV recordings), so this fixes a somewhat critical bug.
2013-07-11 19:15:09 +02:00
wm4 7a4f9cc4d2 ad_spdif: better PTS sync
pts_bytes can't just be changed at the end. It must be offset to the pts
value, which is reset with each packet read from the demuxer. Make sure
the pts_byte field is always reset after receiving a new PTS, i.e.
increment it after actually writing to the output buffer.

Flush the AVFormatContext's write buffer, because otherwise the audio
PTS will jump around too much: the calculation doesn't use the exact
output buffer size if there's still data in the avio buffer.
2013-07-11 19:14:30 +02:00
wm4 a522483629 demux: remove facility for partial packet reads
Partial packet reads were needed because the video/audio parsers were
working on top of them. So it could happen that a parser read a part of
a packet, and returned that to the decoder. With libavformat/libavcodec,
packets are already parsed, and everything is much simpler.

Most of the simplifications in ad_spdif could have been done earlier.
Remove some other stuff as well, like the questionable slave mode start
time reporting (could be replaced by proper code, but we don't bother).
Remove the unused skip_audio_frame() functionality as well (it was used
by old demuxers). Some functions become private to demux.c, like
demux_fill_buffer(). Introduce new packet read functions, which have
simpler semantics. Packets returned from them are owned by the caller,
and all packets in the demux.c packet queue are considered unread.
Remove special code that dropped subtitle packets with size 0. This
used to be needed because it caused special cases in the old code.
2013-07-11 19:10:33 +02:00
wm4 052d4ddbbb ad_lavc: simplify
We don't need to deal with partial packet reads, manually using an audio
parser, or having to call the libavcodec decoder multiple times per
packet.

Actually, I'm not sure about the last point. ffplay still does this, but
the ffmpeg demuxing.c example doesn't.
2013-07-10 02:06:49 +02:00
wm4 9200538b39 audio: remove decoder input buffer
This was unused.
2013-07-10 02:00:46 +02:00
wm4 aac5d758c5 demux: remove audio parser
The audio parser was needed only by the "old" demuxers, and
demux_rawaudio. All other demuxers output already parsed packets.

demux_rawaudio is usually for raw audio, so using a parser with it
doesn't usually make sense. But you can also force it to read
compressed formats with fixed packet sizes, in which case the parser
would have been used. This use case is probably broken now, but you
will be able to do the same thing with libavformat demuxers.
2013-07-08 00:13:53 +02:00
wm4 af0c41e162 Remove old demuxers
Delete demux_avi, demux_asf, demux_mpg, demux_ts. libavformat does
better than them (except in rare corner cases), and the demuxers have
a bad influence on the rest of the code. Often they don't output
proper packets, and require additional audio and video parsing. Most
work only in --no-correct-pts mode.

Remove them to facilitate further cleanups.
2013-07-07 23:54:11 +02:00
wm4 2c732a46ba ao_jack: allow more control about channel layouts 2013-07-07 18:37:55 +02:00
wm4 886d982aa3 ao_jack: increase buffer size, always round up buffer size
This should help with github issue #128, which reported stuttering
distorted sound with 6 channel audio, but not with 2 channels.
2013-07-06 13:11:22 +02:00
Jonathan Yong a9f76c6d86 ao_wasapi0: add new wasapi event mode ao 2013-06-18 13:16:58 +02:00
wm4 16211268b4 ao_dsound: fix compilation 2013-06-16 22:19:00 +02:00
wm4 4d3a2c7e0d audio/out: remove ao->outburst/buffersize fields
The core didn't use these fields, and use of them was inconsistent
accross AOs. Some didn't use them at all. Some only set them; the values
were completely unused by the core. Some made full use of them.

Remove these fields. In places where they are still needed, make them
private AO state.

Remove the --abs option. It set the buffer size for ao_oss and ao_dsound
(being ignored by all other AOs), and was already marked as obsolete. If
it turns out that it's still needed for ao_oss or ao_dsound, their
default buffer sizes could be adjusted, and if even that doesn't help,
AO suboptions could be added in these cases.
2013-06-16 19:36:56 +02:00
wm4 f88193091b audio/out: don't require AOs to set ao->bps
Some still do, because they use the value in other places of the init
function. ao_portaudio is tricky and reads ao->bps in the stream
thread, which might be started on initialization (not sure about that,
but better safe than sorry).
2013-06-16 19:32:18 +02:00
Stefano Pigozzi c8c70dce57 audio: fix af_fmt_seconds_to_bytes
Was missing samplerate
2013-06-16 19:28:04 +02:00
wm4 b24bb7076d audio/out: remove wrapper for old AOs
It's unused now.
2013-06-16 18:33:19 +02:00
Stefano Pigozzi 953b3b3699 ao_jack: use mp_ring 2013-06-16 18:20:39 +02:00
Stefano Pigozzi c5ee7740c4 ao_portaudio: use mp_ring 2013-06-16 18:20:39 +02:00
Stefano Pigozzi bff03a181f core: add a spsc ringbuffer implementation
Currently every single AO was implementing it's own ringbuffer, many times
with slightly different semantics. This is an attempt to fix the problem.

I stole some good ideas from ao_portaudio's ringbuffer and went from there.
The main difference is this one stores wpos and rpos which are absolute
positions in an "infinite" buffer. To find the actual position for writing /
reading just apply modulo size.

The producer only modifies wpos while the consumer only modifies rpos. This
makes it pretty easy to reason about and make the operations thread safe by
using barriers (thread safety is guaranteed only in the Single-Producer/Single-
Consumer case).

Also adapted ao_coreaudio to use this ringbuffer.
2013-06-16 18:20:39 +02:00
Stefano Pigozzi b537467fd3 ao_coreaudio: fix output with spdif
The mute condition was inverted...
2013-06-16 18:20:39 +02:00
Stefano Pigozzi a66041a332 ao_coreaudio: split ringbuffer in it's own file
This is hopefully the start of something good. ca_ringbuffer_read and
ca_ringbuffer_write can probably cleaned up from all the NULL checks once
ao_coreaudio.c gets simplyfied.

Conflicts:
	audio/out/ao_coreaudio.c
2013-06-16 18:20:39 +02:00
Stefano Pigozzi 6807906177 ao_coreaudio: move to new libao API
This is just a first pass and the bare minimum to make it compile and work.
SPDIF is untested for lack of hardware.
2013-06-16 18:20:38 +02:00
Stefano Pigozzi 74eb98279a ao_coreaudio: uncrustify
uncrustify -l C -c TOOLS/uncrustify.cfg --no-backup --replace \
  audio/out/ao_coreaudio.c
2013-06-16 18:20:38 +02:00
Rudolf Polzer dcd36c79c7 encode_lavc strings: use new option syntax 2013-06-16 17:14:47 +02:00
wm4 a9bbe0a576 options: remove --stereo
Whatever this was supposed to be originally, it doesn't have much value
anymore. It just forced ad_mpg123 to upmix mono to stereo by default
(the audio chain can do that). As an option, it was mostly useless and
misleading, so get rid of it.
2013-06-13 00:59:27 +02:00
wm4 d2d9ba326a ao_oss: fix compilation on BSD
This was overlooked with commit 32a898f, because OSS4 volume control is
typically not available on Linux. BSD does have this feature, so the
broken code broke compilation there.
2013-06-11 12:24:11 +02:00
wm4 667c8352f3 core: make options.c compile standalone
This also removes the split between "mplayer" and "common" opts (common
opts used to be shared between mencoder and mplayer).
2013-06-08 17:08:20 +02:00
wm4 925662b193 ao_jack: remove global variables 2013-06-07 16:42:29 +02:00
wm4 e54ab16d1a ao_jack: align data sizes on audio frame size
Fixes crashes when playing with certain numbers of channels. The core
assumes AOs accept data aligned on channels * samplesize, and ao_jack's
play() function broke that assumption:

    mpv: core/mplayer.c:2348: fill_audio_out_buffers: Assertion `played % unitsize == 0' failed.

Fix by aligning the buffer and chunk sizes as needed.
2013-06-07 15:58:28 +02:00
wm4 4e6098ed49 ao_jack: switch to new AO API 2013-06-07 15:44:49 +02:00
wm4 5dec12f525 ao_jack: uncrustify 2013-06-07 15:39:32 +02:00
wm4 6cc60710e4 ao_oss: remove duplicated format info
Instead of having two big switch statements to convert between two
audio formats, use a single table.
2013-06-07 15:30:40 +02:00
wm4 32a898ff5d ao_oss: remove global variables 2013-06-07 15:20:07 +02:00
wm4 15202ebc76 ao_oss: switch to new AO API 2013-06-07 15:05:34 +02:00
wm4 f8f4285671 ao_oss: uncrustify 2013-06-07 14:29:59 +02:00
wm4 1b6888ae8e ao_openal: switch to new AO API 2013-06-04 01:42:57 +02:00
wm4 a933cf28f2 ao_openal: uncrustify 2013-06-04 01:34:53 +02:00
reimar 774dc23ab3 ao_jack: add (no-)connect suboption
Add (no)connect option to ao_jack.

Patch by Markus Appel [masolomaster3000 googlemail com].

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@36297 b3059339-0415-0410-9bf9-f77b7e298cf2

Conflicts:
	DOCS/man/de/mplayer.1
	DOCS/man/en/mplayer.1
	audio/out/ao_jack.c
2013-06-04 01:31:20 +02:00
wm4 3725ab980c ao_dsound: remove global variables 2013-06-04 01:22:50 +02:00
wm4 8afcb84ee5 ao_dsound: switch to new AO API 2013-06-04 01:07:56 +02:00
wm4 cee56e8623 ao_dsound: uncrustify 2013-06-04 00:56:28 +02:00
wm4 9f4261de65 core: add common function to initialize AVPacket
Audio and video had their own (very similar) functions to initialize an
AVPacket (ffmpeg's packet struct) from a demux_packet (mplayer's packet
struct). Add a common function for these.

Also use this function for sd_lavc_conv. This is actually a functional
change, as some libavfilter subtitle demuxers add weird out-of-band
stuff as side-data.
2013-06-03 22:40:07 +02:00
wm4 f44a242258 Replace calls to usec_sleep()
This is just dumb sed replacement to mp_sleep_us().

Also remove the now unused usec_sleep() wrapper.
2013-05-26 16:44:20 +02:00
wm4 e56d8a200d Replace all calls to GetTimer()/GetTimerMS()
GetTimer() is generally replaced with mp_time_us(). Both calls return
microseconds, but the latter uses int64_t, us defined to never wrap,
and never returns 0 or negative values.

GetTimerMS() has no direct replacement. Instead the other functions are
used.

For some code, switch to mp_time_sec(), which returns the time as double
float value in seconds. The returned time is offset to program start
time, so there is enough precision left to deliver microsecond
resolution for at least 100 years. Unless it's casted to a float
(or the CPU reduces precision), which is why we still use mp_time_us()
out of paranoia in places where precision is clearly needed.

Always switch to the correct time. The whole point of the new timer
calls is that they don't wrap, and storing microseconds in unsigned int
variables would negate this.

In some cases, remove wrap-around handling for time values.
2013-05-26 16:44:20 +02:00
wm4 3546188a41 ao_alsa: always unset ALSA error handler, cleanup on init error
The ALSA device was not closed when initialization failed.

The ALSA error handler (set with snd_lib_error_set_handler()) was not
unset when closing ao_alsa. If this is not done, the handler will still
be called when other libraries using ALSA cause errors, even though
ao_alsa was long closed. Since these messages were prefixed with
"[AO_ALSA]", they were misleading and implying ao_alsa was still used.

For some reason, our error handler is still called even after doing
snd_lib_error_set_handler(NULL), which should be impossible. Checking
with the debuggers, inserting printf(), as well as the alsa-lib source
code all suggest our error handler should not be called, but it still
happens. It's a complete mystery.
2013-05-26 16:44:18 +02:00
wm4 60a7f3b8bc af_lavfi: add libavfilter bridge
Mostly copied from vf_lavfi. The parts that could be shared are minor,
because most code is about setting up audio and video, which are too
different.

This won't work with Libav. I used ffplay.c as guide, and noticed too
late that their setup methods are incompatible with Libav's. Trying to
make it work with both would be too much effort. The configure test for
av_opt_set_int_list() should disable af_lavfi gracefully when compiling
with Libav.

Due to option parser chaos, you currently can't have a "," as part of
the filter graph string - not even with quoting or escaping. This will
probably be fixed later.

The audio filter chain is not PTS aware. So we have to do some hacks
to make up a fake PTS, and we have to map the output PTS back to the
filter chain's method of tracking PTS changes and buffering, by
adjusting af->delay.
2013-05-23 17:44:06 +02:00
wm4 4931085a1b chmap: fix oddity due to ambiguous 6.1 ffmpeg channel layout
FFmpeg (as well as Libav) have two layouts called "6.1":
AV_CH_LAYOUT_6POINT1 and AV_CH_LAYOUT_6POINT1_BACK. We call them "6.1"
and "6.1(back)". Change the default layout for 7 channels as well to
return the same layout as av_get_default_channel_layout(). (Looks a bit
questionable, but for now it's better to follow FFmpeg.)
2013-05-13 23:55:39 +02:00
wm4 a39d369c25 audio: fix ALSA 4 channel surround output
It turns out that ALSA's 4 channel layout is different from mpv's and
ffmpeg's 4.0 layout. Thus trying to do 4 channel output led to incorrect
remixing via lib{av,sw}resample.

Fix the default layouts for the internal filter chain as well, although
I'm not sure if it matters at all.
2013-05-13 18:27:09 +02:00
wm4 636e1edd9e af_lavrresample: fix inverted condition
This was added with the previous commit. It likely broke some obscure
special-cases, which (hopefully) do not happen with normal playback.
2013-05-13 18:05:37 +02:00
wm4 279f4b59dc audio: fix compilation with older libavresample versions
The libavresample version of the current Libav stable release lacks the
avresample_set_channel_mapping() function. (FFmpeg's libswresample seems
to be fine, because they added swr_set_channel_mapping() first.)

Add a cheap/slow workaround to do channel reordering on our own. We
don't use the recently removed MPlayer code (see commit 586b75a),
because that is not generic enough.

The functionality should be the same as with full-featured
libavresample, and any differences are bugs. It's probably slower,
though.
2013-05-13 00:39:07 +02:00
wm4 bb569b56de ao_coreaudio: fix switched parameters 2013-05-12 22:00:32 +02:00
wm4 e6e5a7b221 Merge branch 'audio_changes'
Conflicts:
	audio/out/ao_lavc.c
2013-05-12 21:47:55 +02:00
wm4 48f9431151 af: improve filter chain setup retry limit
af_reinit() is responsible for inserting automatic conversion filters
for channel remixing, format conversion, and resampling. We don't
require that a single filter can do all these (even though
af_lavrresample does nearly all of this, sometimes af_format has to be
used instead for format conversions). This makes setting up the chain
more complicated, and a way is needed to prevent endless appending of
conversion filters if a conversion is not possible.

Until now, this used a stupidly simple yet robust static retry limit to
detect failure. This is perfectly fine, and the limit (20) was good
enough to handle about ~5 filters. But with more filters, and if each
filter requires 3 additional conversion filters, this would fail. So
raise the limit to 4 retries per filter. This is still stupidly simple
and robust, but won't arbitrarily fail if the filter count is too large.
2013-05-12 21:45:05 +02:00
wm4 9dd9ccbd8d audio: add double sample format
To make this easier, get rid of the direct mapping of the
AF_FORMAT_BITS_MASK bit field to number of bytes. This way we can throw
away the unused AF_FORMAT_48BIT and don't have to add ..._56BIT.
2013-05-12 21:24:57 +02:00
wm4 f5aec5a2a7 ao_alsa: set fallback if format unknown
The snd_pcm_hw_params_test_format() call actually crashes in alsa-lib if
called with SND_PCM_FORMAT_UNKNOWN, so the already existing fallback
code won't work in this case.
2013-05-12 21:24:57 +02:00
wm4 ecc6e379b2 audio/out: channel map selection
Make all AOs use what has been introduced in the previous commit.

Note that even AOs which can handle all possible layouts (like ao_null)
use the new functions. This might be important if in the future
ao_select_champ() possibly honors global user options about downmixing
and so on.
2013-05-12 21:24:57 +02:00
wm4 ab8f28a672 audio: add channel map selection function
The point is selecting a minimal fallback. The AOs will call this
through the AO API, so it will be possible to add options affecting
the general channel layout selection.

It provides the following mechanism to AOs:
- forcing the correct channel order
- downmixing to stereo if no layout is available
- allow 5.1 <-> 5.1(side) fallback
- handling "unknown" channel layouts

This is quite weak and lots of code/complexity for little gain. All AOs
already made sure the channel order was correct, and the fallback is of
little value, and could perhaps be done in the frontend instead, like
stereo downmixing with --channels=2 is handled. But I'm not really sure
how this stuff should _really_ work, and the new code will hopefully
provides enough flexibility to make radical changes to channel layout
negotiation easier.
2013-05-12 21:24:57 +02:00
wm4 34a139d495 ao_pulse: move format setup code 2013-05-12 21:24:57 +02:00
wm4 5c0c141a55 af_lavrresample: avoid channel reordering with unknown layouts
If one of the input or output is an unknown layout, but the other is
known, it can still happen that channels are remixed randomly. Avoid
this by forcing default layouts in this case. (Doesn't work if the
channel counts are different.)
2013-05-12 21:24:56 +02:00
wm4 20a1d0bc5b ao_openal: use channel map instead of ALSA fixed layout
Now mpv's channel map is used to map each channel to a speaker. This
allows in theory for playback of any layout for which ao_openal
actually has a speaker defined. Also add the back-center (BC) speaker,
which allows playback of 6.0 audio. Enabling more layouts by adding
other speakers would be possible, but I'm not sure about the speaker
positions.
2013-05-12 21:24:56 +02:00
wm4 d9582ad0a4 audio/filters: add af_force
Its main purpose is for testing in case channel layout stuff breaks, in
particular in connection with old audio filters.
2013-05-12 21:24:56 +02:00
wm4 ce2515ddb8 ao: remove ao_driver.is_new field
Is unused, is completely pointless.
2013-05-12 21:24:56 +02:00
wm4 56c295e2ca ao_alsa: remove global variables 2013-05-12 21:24:56 +02:00
wm4 e1207f2ceb ao_alsa: switch to new AO API 2013-05-12 21:24:56 +02:00
eng 74487b8430 af_ladspa: code cleanup
Cleanup based on results from cppcheck-1.59
Reduce the scope of several variables
Fix memory leak
2013-05-12 21:24:56 +02:00
wm4 3b1956608d audio: print channel map additionally to channel count on terminal 2013-05-12 21:24:56 +02:00
wm4 bc03eb0295 ao_alsa: map to exact channel layout
This allows supporting 5 channel audio (which can be eother 5.0 or 4.1).

Fallback doesn't work yet. It will do nonsense if the channel layout
doesn't match perfectly, even though it's similar.
2013-05-12 21:24:56 +02:00
wm4 7828048d65 ao_alsa: move format lookup into separate function 2013-05-12 21:24:56 +02:00
wm4 c6076b5de5 ao_alsa: more reformat 2013-05-12 21:24:56 +02:00
wm4 9afad5180c af: print filter chain info on error
The filter chain was only visible with -v. Always print it if the filter
chain could not be configured.
2013-05-12 21:24:56 +02:00
wm4 d2e5b50041 ao_alsa: cosmetics, macro-fy error reporting
Add a CHECK_ALSA_ERROR macro to report ALSA errors. This is similar to
what vo_vdpau does. This removes lots of boiler plate, it almost gives
me the feeling the ao_alsa initialization code is now readable. This
change is squashed with the reformatting, because both changes are
just as noisy and useless.
2013-05-12 21:24:55 +02:00
wm4 7f0f33fc8f ao_alsa: uncrustify 2013-05-12 21:24:55 +02:00
wm4 1c601e84ff ad_lavc: force channel layout pass-through with demux_rawaudio
Using demux_rawaudio and the --rawaudio-channels option is useful for
testing channel map stuff. The libavcodec PCM decoder normalizes the
channel map to ffmpeg order, though. Prevent this by forcing the
original channel map when using the mp-pcm pseudo decoder entry (used by
demux_rawaudio and stream/tv.c only).
2013-05-12 21:24:55 +02:00
wm4 ade08d676f ao_coreaudio: switch to WAVEEXT channel order
This used ALSA order, which was not correct. Most likely this has been
wrong since forever.
2013-05-12 21:24:55 +02:00
wm4 bf014677ce ao_pulse: try to set correct channel layout
Like most other AOs, ao_pulse set the channel count only, always using a
default layout. Try to set the exact layout.

For this, we need a big lookup table to map waveex/lavc/mpv speaker
position to PulseAudio's, since PA_CHANNEL_POSITION_ is apparently not
compatible to waveext, and I haven't seen any API functions that would
help mapping them.

Completely untested. (Let's leave that to someone else...)
2013-05-12 21:24:55 +02:00
wm4 4b5cee4617 core: use channel map on demuxer level too
This helps passing the channel layout correctly from decoder to audio
filter chain. (Because that part "reuses" the demuxer level codec
parameters, which is very disgusting.)

Note that ffmpeg stuff already passed the channel layout via
mp_copy_lav_codec_headers(). So other than easier dealing with the
demuxer/decoder parameters mess, there's no real advantage to doing
this.

Make the --channels option accept a channel map. Since simple numbers
map to standard layouts with the given number of channels, this is
downwards compatible. Likewise for demux_rawaudio.
2013-05-12 21:24:55 +02:00
wm4 586b75ad08 reorder_ch: remove old channel reorder functions
This is done in af_lavrresample now, and as part of format negotiation.

Also remove the remaining reorder_channel calls. They were redundant
and did nothing.
2013-05-12 21:24:55 +02:00
wm4 408b7eecee audio: let libavresample do channel reordering 2013-05-12 21:24:55 +02:00
wm4 b20026c29b af_lavrresample: context is always allocated here 2013-05-12 21:24:55 +02:00
wm4 aea2328906 audio/out: switch to channel map
This actually breaks audio for 5/6/8 channels. There's no reordering
done yet. The actual reordering will be done inside of af_lavrresample
and has to be made part of the format negotiation.
2013-05-12 21:24:54 +02:00
wm4 37325f2796 af_pan: set unknown channel layout for output 2013-05-12 21:24:54 +02:00
wm4 7971bb87cb af: use mp_chmap for mp_audio, include channel map in format negotiation
Now af_lavrresample pretends to reorder the channels, although it
doesn't yet, and nothing sets non-standard layouts either.
2013-05-12 21:24:54 +02:00
wm4 f7a427676c audio: add some setters for mp_audio, and require filters to use them
mp_audio has some redundant fields. Setters like mp_audio_set_format()
initialize these properly.

Also move the mp_audio struct to a the file audio.c.

We can remove a mysterious line of code from af.c:

    in.format |= af_bits2fmt(in.bps * 8);

I'm not sure if this was ever actually needed, or if it was some kind of
"make it work" quick-fix that works against the way things were supposed
to work. All filters etc. now set the format correctly, so if there ever
was a need for this code, it's definitely gone.
2013-05-12 21:24:54 +02:00
wm4 0042735d7a audio: add channel map API
Unused, will be used in the following commits.

Let chmap.h define the number of maximum channels, because that is most
convenient.
2013-05-12 21:24:54 +02:00
wm4 1e37d35970 audio/filter: remove unused AF_CONTROLs
Was unused, has never been used.
2013-05-12 20:55:50 +02:00
Stefano Pigozzi afdc9c4ae2 OSX: use native Cocoa's event loop
Schedule mpv's playloop as a high frequency timer inside the main Cocoa event
loop. This has the benefit to allow accessing menus as well as resizing the
window without the playback being blocked and allows to remove countless hacks
from the code that involved manually pumping the event loop as well simulating
manually some of the Cocoa default behaviours.

A huge improvement consists in removing NSApplicationLoad. This is a C function
defined in the Cocoa header and implements a minimal OSX application under ther
hood so that you can use the Cocoa GUI toolkit from C/C++ without having to
respect the Cocoa standards in terms of application initialization. This was
bad because the behaviour implemented by NSApplicationLoad was hard to customize
and had several gotchas especially in the menu department.

mpv was changed to be just a nib-less application. All the Cocoa part is still
generated in code but the event handling is now not dissimilar to what is
present in a stock Mac application.

As a part of reviewing the initialization process, I also removed all of
`osdep/macosx_finder_args`. The useful parts of the code were moved to
`osdep/macosx_appication` which has the broaded responsibility of managing the
full lifecycle of the Cocoa application. By consequence the
`--enable-macosx-finder` configure switch was killed as well, as this feature
is always enabled.

Another change the users will notice is that when using a bundle the `--quiet`
option will be inserted much earlier in the initializaion process. This results
in mpv not spamming mpv.log anymore with all the initialization outputs.
2013-05-12 15:27:54 +02:00
Rudolf Polzer 2d8783075f encoding: fix final audio frame sync
When --ocopyts was used, the final audio frame got improper pts. Fixed
by now using the play() logic to play the final frame too.
2013-04-28 11:39:38 +02:00
wm4 071a8f50b9 options: add option to prevent decoder audio downmixing
Also rename --a52drc to --ad-lavc-ac3drc, and add --ad-lavc-o.
2013-04-13 04:21:30 +02:00
wm4 0d939a6847 af: fix negotiation endless loop
Yeah... ok.

Can be reproduced by having AF_CONTROL_CHANNELS not really set the
correct channel map.
2013-04-13 04:21:29 +02:00
wm4 fd6302631a af: streamline format negotiation
Add dummy input and output filters to remove special cases in the format
negotiation code (af_fix_format_conversion() etc.). The output of the
filter chain is now negotiated in exactly the same way as normal
filters.

Negotiate setting the sample rate in the same way as other audio
parameters. As a side effect, the resampler is inserted at the start of
the filter chain instead of the end, but that shouldn't matter much,
especially since conversion and channel mixing are conflated into the
same filter (due to libavresample's API).
2013-04-13 04:21:29 +02:00
wm4 ff6342a311 af_lavrresample: add no-detach suboption
Normally, af_lavrresample detaches itself immediately if the input and
output audio parameters are the same. no-detach prevents this.
2013-04-13 04:21:29 +02:00
wm4 abd5e8a2e7 options: remove --af-adv
Anything this option did has been removed in the preceding 3 commits.
Note that even though these options sounded like a good idea (like
setting accuracy vs. speed tradeoffs), they were not really properly
implemented.
2013-04-13 04:21:29 +02:00
wm4 08eecf070e af: remove accuracy option
All this option did was deciding whether the resample filter was to be
insert at the beginning or end of the filter chain. Always do what the
option set for accuracy did. I doubt it makes much of a difference.
libavresample does most things in just one go anyway, so it won't
matter.
2013-04-13 04:21:28 +02:00
wm4 f9a6b1c3f8 af: remove force option
Dangerous and misleading. If it turns out that this is actually needed
to make certain setups work right, it should be added back in a better
way (in a way it doesn't cause random crashes).
2013-04-13 04:21:28 +02:00
wm4 bc268b313e audio: remove float processing option
The only thing this option did was changing the behavior of af_volume.
The option decided what sample format af_volume would use, but only if
the sample format was not already float. If the option was set, it would
default to float, otherwise to S16.

Remove use of the option and all associated code, and make af_volume
always use float (unless a af_volume specific sub-option is set).

Silence maximum value tracking. This message is printed when the filter
is destroyed, and it's slightly annoying. Was enabled due to enabling
float by default.
2013-04-13 04:21:28 +02:00
wm4 41aefce730 audio: switch to libavcodec channel order, use libavresample for mixing
Switch the internal channel order to libavcodec's. If the channel number
mismatches at some point, use libavresample for up- or downmixing.
Remove the old af_pan automatic downmixing.

The libavcodec channel order should be equivalent to WAVEFORMATEX order,
at least nowadays. reorder_ch.h assumes that WAVEFORMATEX and libavcodec
might be different, but all defined channels have the same mappings.

Remove the downmixing with af_pan as well as the channel conversion with
af_channels from af.c, and prefer af_lavrresample for this. The
automatic downmixing behavior should be the same as before (if the
--channels option is set to 2, which is the default, the audio output
is forced to 2 channels, and libavresample does all downmixing).

Note that mpv still can't do channel layouts. It will pick the default
channel layout according to the channel count. This will be fixed later
by passing down the channel layout as well.

af_hrtf depends on the order of the input channels, so reorder to ALSA
(for which this code was written). This is better than changing the
filter code, which is more risky.

ao_pulse can accept waveext order directly, so set that as channel
mapping.
2013-04-13 04:21:28 +02:00
wm4 f54909d4df ao_alsa: reorder channels from internal to alsa order
Currently, internal and alsa order are exactly the same, so this will do
absolutely nothing.
2013-04-13 04:21:28 +02:00
wm4 e4da671820 af: simplification
If format negotiation fails, and additional filters are inserted to fix
this, don't try to reinitialize the filter immediately. Instead, correct
the audio format, and let the caller retry.

Add a retry counter to af_reinit() to ensure that misbehaving filters
can't put the format negotiation into an endless loop.
2013-04-13 04:21:28 +02:00
wm4 8a53b3f523 af: factor channel filter insertion
Do this just like it has been done for the format filter.
2013-04-13 04:21:27 +02:00
wm4 c866583e1e af: use af_lavrresample for format conversions, if possible
Refactor to remove the duplicated format filter insertion code. Allow
other format converting filters to be inserted on format mismatches.
af_info.test_conversion checks whether conversion between two formats
would work with the given filter; do this to avoid having to insert
multiple conversion filters at once and such things. (Although this
isn't ideal: what if we want to avoid af_format for some conversions?
What if we want to split af_format in endian-swapping filters etc.?)

Prefer af_lavrresample for conversions that it supports natively,
otherwise let af_format handle the full conversion.
2013-04-13 04:21:27 +02:00
wm4 5a958921a7 af: remove automatically inserted filters on full reinit
Make sure automatically inserted filters are removed on full reinit
(they are re-added later if they are really needed). Automatically
inserted filters were never explicitly removed, instead, it was
expected that redundant conversion filters detach themselves. This
didn't work if there were several chained format conversion filters,
e.g. s16le->floatle->s16le, which could result from repeated filter
insertion and removal. (format filters detach only if input format and
output format are the same.)

Further, the dummy filter (which exists only because af.c can't handle
an empty filter chain for some reason) could introduce bad conversions
due to how the format negotiation works. Change the code so that the
dummy filter never takes part on format negotiation. (It would be better
to fix format negotiation, but that would be much more complicated and
would involving fixing all filters.)

Simplify af_reinit() and remove the start audio filter parameter. This
means format negotiation and filter initialization is run more often,
but should be harmless.
2013-04-13 04:21:27 +02:00
wm4 0a136ece5a af_lavrresample: allow other ffmpeg sample formats for input/output
The format was locked to s16. Extend it to accept all other ffmpeg
sample formats, and even allow different in- and output formats. The
generic filter code will still insert af_format on format mismatches,
though.
2013-04-13 04:21:27 +02:00
wm4 fc24ab9298 audio/filter: replace pointless memcpys with assignments
The change in af_scaletempo actually fixes a memory leak. af->data
contained a pointer to an allocated buffer, which was overwritten
during format negotiation. Set the format explicitly instead.
2013-04-13 04:21:27 +02:00
wm4 8bf759e888 af: uncrustify 2013-04-13 04:21:27 +02:00
Stefano Pigozzi cb0b0d99a4 ad_lavc: use fmt-conversion to map sample formats 2013-04-13 04:21:27 +02:00
wm4 3097176ff1 audio/decode: remove vararg from ad_control()
This was unused and dumb. Ancient MPlayer used varargs instead of void*
arguments for control() functions, and this was the last leftover.
2013-04-12 20:35:59 +02:00
Stefano Pigozzi ed48c657ee ao_jack: fix deprecation warning
jack_port_get_total_latency is deprecated: use the "new" API based on
jack_port_get_latency_range instead.
2013-04-12 00:10:39 +02:00
wm4 62daa08d3b mplayer: keep volume persistent, even when using --volume
Consider:

    mpv --volume 10 file1.mkv file2.mkv

Before this commit, the volume was reset to 10 when playing file2.mkv.
This was inconsistent to most other options. E.g. --brightness is a
rather similar case.

In general, settings should never be reset when playing the next file,
unless the option was explicitly marked file-local. This commit
corrects the behavior of the --volume and --mute options.

File local --volume still works as expected:

    mpv --{ --volume 10 file1.mkv file2.mkv --}

This sets the volume always to 10 on playback start.

Move the m_config_leave_file_local() call down so that the mixer code
in uninit_player() can set the option volume and mute variables without
overwriting the global option values.

Another subtle issue is that we don't want to set volume if there's no
need to, which is why the user_set_volume/mute fields are introduced.
This is important because setting the volume might change the system
volume depending on other options.
2013-04-10 21:29:04 +02:00
Kovensky 16b15885ff ao_dsound: add missing include
libavutil/common.h is needed for FF_ARRAY_ELEMS.
2013-03-23 21:04:27 +01:00
Stefano Pigozzi 048ceef655 af_lavrresample: add new resampling filter to replace the old ones
Remove `af_resample` and `af_lavcresample`. The former is a mess while the
latter uses an API that was long deprecated in libavcodec and is now removed.

`af_lavrresample` rougly has the same features and structure of
`af_lavcresample`.

libswresample fallback by wm4.
2013-03-13 23:51:30 +01:00
wm4 d8bde114fd Prefix CODEC_ID_ with AV_
The old names have been deprecated a while ago, but were needed for
supporting older ffmpeg/libav versions. The deprecated identifiers
have been removed from recent Libav and FFmpeg git.

This change breaks compatibility with Libav 0.8.x and equivalent
FFmpeg releases.
2013-03-13 23:51:30 +01:00
wm4 fd8750c25b af_lavcac3enc: switch to avcodec_encode_audio2()
avcodec_encode_audio() was deprecated, and was finally removed from
Libav and FFmpeg git.

This appears to work. I get heavy A/V desync with -ao alsa and -ao pcm,
but this was already so before this change.
2013-03-13 23:51:29 +01:00
Wessel Dankers 879ebe0655 Add a --dtshd option
The spdif decoder was hardcoded to assume that the spdif output is
capable of accepting high (>1.5Mbps) bitrates. While this is true
for modern HDMI spdif interfaces, the original coax/toslink system
cannot deal with this and will fail to work.

This patch adds an option --dtshd which can be enabled if you use
a DTS-capable receiver behind a HDMI link.
2013-03-04 21:18:20 +01:00
Martin 1f7decc1a0 Rename af_volnorm to af_drc
The previous name of this filter was misleading, because it doesn’t actually
normalize volume levels. What it does is closer to performing low-quality
dynamic range compression, hence it is now called af_drc.
2013-02-12 09:53:33 +01:00
wm4 01869d1391 demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).

Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.

Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-10 17:25:57 +01:00
wm4 dd61fac943 demux_lavf, ad_lavc, vd_lavc: refactor, cleanup
Rearrange some code to make it easier readable. Remove some dead code,
and stop printing AVI headers in demux_lavf. (These are not actual AVI
headers, just for internal use.)

There should be no functional changes, other than reducing output in
verbose mode.
2013-02-10 17:25:57 +01:00
wm4 4d016a92c8 core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)

The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)

demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.

Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.

Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-10 17:25:56 +01:00
wm4 bb8da97205 dec_audio: uncrustify 2013-02-09 19:00:22 +01:00
wm4 ae070a6f1e audio/out, video/out: hide encoding VO/AO
mpv -ao help and mpv -vo help shouldn't show the encoding outputs (named
"lavc" on both cases). Also make it impossible to select these manually
when not encoding.
2013-02-06 23:04:18 +01:00
wm4 13d97077ec audio/out: prefer ao_dsound over ao_portaudio
On Linux, ao_portaudio has weird freezing issues (possibly specific to
the ALSA backend, though). Also ao_dsound is more likely to get multi-
channel audio output right, and ao_portaudio probably mangles these.
2013-02-06 23:04:18 +01:00
wm4 7a6d26370c mixer: prefer AO softvol control over volume filter
This partially reverts earlier decisions, when I thought it would
always be better to prefer the audio volume filter over the AO's,
because the AO's relies on the underlying audio-API, which could
be broken or exhibit unusual behavior (like it happened with ao_dsound).

However, since the audio buffer can be quite large (500 ms), and we
don't attempt to flush & refilter the audio on volume changes, always
prefer AO volume control (as long as the AO mixer doesn't control the
system mixer).

Also document what the mixer.c related AO fields mean (hopefully not
too brief).
2013-02-06 23:04:18 +01:00
wm4 94f72b1e59 ao_dsound: support 6.1 and 7.1 channel configurations
Instead of doing the channel reordering manually, use the existing
support in reorder_ch.c.

Untested.
2013-02-06 23:04:12 +01:00
Mad Fish 5b7327920b ao_coreaudio: use 0 as timeout for CFRunLoopRunInMode
Handle all pending events and exit instead of waiting. When there are lots of
input events (for example, scrolling with trackpad), timeout can add up
to make a huge frame delay. In my tests, if I scroll fast enough, that loop
would never exit.
2013-01-20 16:37:30 +01:00
wm4 20c9dfa616 Replace strsep() uses
This function sucks and apparently is not very portable (at least on
mingw, the configure check fails). Also remove the emulation of that
function from osdep/strsep*, and remove the configure check.
2013-01-13 17:32:39 +01:00
Uoti Urpala 82d72ef39f mixer: keep fractional part of volume setting
mixer_setvolume() accepts float values for volume, but used the
integer function av_clip() to limit range, losing the fractional part
as a side effect. Change the code to use av_clipf() instead. For most
uses this shouldn't make any real difference; actual AO volume
settings may not have that much precision anyway.
2013-01-13 13:26:21 +01:00
Uoti Urpala 3f7526d641 af_volnorm: fix output range with float input
af_volnorm can process either int16_t or float audio data. The float
version used 0 to INT_MAX as full value range, when it should be 0 to
1. This effectively disabled the filter (due to all input being
considered to fall in the silence range). Fix.

Reported by Tobias Jacobi <liquid.acid@gmx.net>.
2013-01-13 13:26:07 +01:00