Commit Graph

40620 Commits

Author SHA1 Message Date
wm4 32b56c56ba ipc: put playback core to sleep while dequeuing commands
Happens to fix #1581 due to an unfortunate interaction with the way the
VO does not react to commands for a while if a video frame is queued.
Slightly improves other situations as well, if the client spams mpv with
commands during playback.
2015-02-13 21:25:09 +01:00
wm4 f9f2e1cc4e demux: hack for instant stream switching
This removes the delay when switching audio tracks in mkv or mp4 files.
Other formats are not enabled, because it's not clear whether the
demuxers fulfill the requirements listed in demux.h. (Many formats
definitely do not with libavformat.)

Background:

The demuxer packet cache buffers a certain amount of packets. This
includes only packets from selected streams. We discard packets from
other streams for various reasons. This introduces a problem: switching
to a different audio track introduces a delay. The delay is as big as
the demuxer packet cache buffer, because while the file was read ahead
to fill the packet buffer, the process of reading packets also discarded
all packets from the previously not selected audio stream. Once the
remaining packet buffer has been played, new audio packets are available
and you hear audio again.

We could probably just not discard packets from unselected streams. But
this would require additional memory and CPU resources, and also it's
hard to tell when packets from unused streams should be discarded (we
don't want to keep them forever; it'd be a memory leak).

We could also issue a player hr-seek to the current playback position,
which would solve the problem in 1 line of code or so. But this can be
rather slow.

So what we do in this commit instead is: we just seek back to the
position where our current packet buffer starts, and start demuxing from
this position again. This way we can get the "past" packets for the
newly selected stream. For streams which were already selected the
packets are simply discarded until the previous position is reached
again.

That latter part is the hard part. We really want to skip packets
exactly until the position where we left off previously, or we will skip
packets or feed packets to the decoder twice. If we assume that the
demuxer is deterministic (returns exactly the same packets after a seek
to a previous position), then we can try to check whether it's the same
packet as the one at the end of the packet buffer. If it is, we know
that the packet after it is where we left off last time.

Unfortunately, this is not very robust, and maybe it can't be made
robust. Currently we use the demux_packet.pos field as unique packet
ID - which works fine in some scenarios, but will break in arbitrary
ways if the basic requirement to the demuxer (as listed in the demux.h
additions) are broken. Thus, this is enabled only for the internal mkv
demuxer and the libavformat mp4 demuxer.

(libavformat mkv does not work, because the packet positions are not
unique. Probably could be fixed upstream, but it's not clear whether
it's a bug or a feature.)
2015-02-13 21:17:17 +01:00
wm4 11bd80b31e demux_mkv: return unique file positions for all packets
Until now, some packets could return the same file position if they were
split off from a Matroska-level packet. This was perfectly fine, because
the file position isn't used for anything overly important (it uses it
to estimate playback position if no other information is available). The
following commit will use the demux_packet.pos field as unique ID (as a
simplification), so make the demuxer export more finegrained
information.

Also, the last_filepos field didn't have to be global, at least not
anymore.
2015-02-13 21:17:07 +01:00
Stefano Pigozzi 3931544ef3 vo_opengl: fix smoothmotion coefficient calculation
Using prev_pts as the start of the scale was plain wrong. Change it to
prev_vsync.
2015-02-13 20:39:53 +01:00
wm4 9e14042e57 cocoa: fix exiting the command line player
Commit e920a00eb assumed that terminate_cocoa_application() actually
would exit. But apparently that is not always the case; e.g. mpv --help
will just hang. The old code had a dummy exit(0), which was apparently
actually called. Fix by explicitly exiting if mpv_main() returns and
terminate_cocoa_application() does nothing.
2015-02-13 10:47:07 +01:00
wm4 96547a810e encoding: fixed-vo option was removed 2015-02-13 00:18:54 +01:00
wm4 aee0978d50 player: add a --loop=force mode
Requested. See manpage additions.

This also makes the magical loop_times constants slightly saner, but
shouldn't change the semantics of any existing --loop option values.
2015-02-12 22:41:45 +01:00
wm4 c59a4f12db osx: move code to unset input context to the right place
Setting the input context is always called, both in cplayer and libmpv,
and under HAVE_COCOA. Unsetting the input context was done only the
cplayer uninit call. Also it was under HAVE_COCOA_APPLICATION, so it was
not unset in libmpv (dangling pointer).
2015-02-12 21:18:23 +01:00
wm4 b8de478f51 osx: move cocoa specific call out of common code
This is almost equivalent, and gets rid of the ifdef.
2015-02-12 21:18:12 +01:00
wm4 e920a00eba player: drop explicit exit() calls
The code in main.c calls exit() explicitly, but the code is actually
easier to follow by simply exiting from main() instead. The exit() call
in av_log.c happens only on severely broken builds, so replace it with
abort().

(Shuts up rpmlint warnings.)
2015-02-12 17:28:22 +01:00
wm4 e01750020d ao_pulse: listen for hotplug events
This requires jumping through multiple hoops on fire. Since the
PulseAudio API is virtually undocumented, I'm not sure if this is
correct either. We only react to sink events, and only to the NEW/REMOVE
events. CHANGE events are ignored, because PulseAudio fires them far too
often - even if the system is completely idle! If pa_sink_info.name can
change, we're in trouble. pa_sink_info.description is not so important,
but it'd also be a bit un-nice if it can change, and we don't update it.

The weird way how the actual AO and the hotplug context share the same
struct (ao) comes in handy here, although context_success_cb() still had
to be duplicated from success_cb() - the unused argument has a different
type.
2015-02-12 17:18:43 +01:00
wm4 f061befb33 audio: add device change notification for hotplugging
Not very important for the command line player; but GUI applications
will want to know about this.

This only adds the internal API; support for specific audio outputs
comes later.

This reuses the ao struct as context for the hotplug event listener,
similar to how the "old" device listing API did. This is probably a bit
unclean and confusing. One argument got reusing it is that otherwise
rewriting parts of ao_pulse would be required (because the PulseAudio
API requires so damn much boilerplate). Another is that --ao-defaults is
applied to the hotplug dummy ao struct, which automatically applies such
defaults even to the hotplug context.

Notification works through the property observation mechanism in the
client API. The notification chain is a bit complicated: the AO notifies
the player, which in turn notifies the clients, which in turn will
actually retrieve the device list. (It still has the advantage that it's
slightly cleaner, since the AO stuff doesn't need to know about client
API issues.)

The weird handling of atomic flags in ao.c is because we still don't
require real atomics from the compiler. Otherwise we'd just use atomic
bitwise operations.
2015-02-12 17:17:41 +01:00
wm4 c152c59084 ao: set correct client name when listing devices
This is a small oversight. The client name (as set on command line
options or, more importantly, the client API) was not set when listing
devices e.g. via the "audio-device-list" property.

Might or might not fix #1578.

Also adjust the log level for an unrelated message.
2015-02-12 13:54:02 +01:00
wm4 545a0e59df sd_ass: fix some corner cases in tag stripping
This behavior is implied by VSFilter.
2015-02-12 12:19:39 +01:00
wm4 7bbc617019 Revert "player: make --force-window create the window immediately on start"
This reverts commit acc5e8f574.

As expected, some didn't like this. Others won't like this revert.
Whatever.

See #1561.

This should go into mpv 0.8.0 before it's released.
2015-02-12 12:01:12 +01:00
wm4 1d9134d044 player: use af_scaletempo when slowing down audio too
In my opinion the artifacts created by af_scaletempo on extreme slowdown
(50% or so) are too bothersome - but users disagree. So use
af_scaletempo on any speed changes, not just on speedup.
2015-02-12 11:58:35 +01:00
wm4 5c5e38fc0e vf_lavfi: drop useless option from wrapper filters
Filters which merely wrap libavfilter (for user-compatibility) like
vf_gradfun had a "lavfi-enable" suboption, which could disable
libavfilter usage. Since none of these filters has an internal
implementation anymore, this was completely useless.
2015-02-12 11:53:40 +01:00
Martin Herkt a17ea73636 af_rubberband: actually fix deadlock
371e5d0 missed this one
2015-02-12 10:15:12 +01:00
wm4 371e5d0665 af_rubberband: fix filter error deadlock
rubberband_available() can return a negative value, which we assigned to
a size_t variable, leading to the frame allocation to fail. This could
spam "Error filtering frame.". (That it spams this instead of exiting
should probably also be considered a bug.)

At least in the realtime mode and in our case, a negative return value
should not have any different meaning from a 0 return value, in
particular because we call rubberband_get_samples_required() or set the
"final" parameter for rubberband_process() to continue/stop processing.
2015-02-12 09:47:01 +01:00
Martin Herkt 2dc49ea866 af_rubberband: change defaults
After some testing, I am fairly convinced that these defaults sound
better than the previous settings. This also eliminates some issue
with random crackling and noise.

Also remove the `stretch` option since it has no effect in
realtime mode.
2015-02-12 00:58:40 +01:00
wm4 6299da2047 af_rubberband: fix breakage
The previous commit on this filter accidentally removed the
RubberBandOptionProcessRealTime option. Without it, the lib prints a
warning and passes the audio through.

Also add the RubberBandOptionSmoothingOn option back. Though for some
reason the output sounds still very wrong.
2015-02-11 21:32:01 +01:00
wm4 2522bff565 video/filters: simplify libavfilter bridge
Remove the confusing crap that allowed a filter using the libavfilter
bridge to be compiled without libavfilter. Instead, compile the wrappers
only if libavfilter is enabled at compile time.

The only filter which still requires it is vf_stereo3d (unfortunately).
Special-case this one. (The whole filter and how it interacts with lavfi
is pure braindeath anyway.)
2015-02-11 17:35:58 +01:00
wm4 73d23a9405 vf_noise: remove internal implementation
It requires libavfilter now, just like many other filters. Not sure if
it even makes sense to keep this wrapper.
2015-02-11 17:20:22 +01:00
wm4 df5548a754 af_rubberband: make all librubberband options configurable
librubberband exports a big load of options. Normally, the default
settings (whether they're librubberband defaults or our defaults) should
be sufficient, but since I'm not so sure about this, making it
configurable allows others to figure it out for me.
2015-02-11 17:11:05 +01:00
wm4 6f24a61d84 af_rubberband: attempt to fix audio position calculation
The problem here is that librubberband can buffer an arbitrary amount
of data, but at the same time doesn't provide a way to query how much
data is buffered. So we keep track of this manually, assuming that
librubberband tries to reach the requested time ratio for input and
output (which is probably true).

The disadvantage is that rounding errors could accumulate over time.
(Maybe it should try to round towards keeping the time ratio.)
2015-02-11 16:32:40 +01:00
wm4 76501f4f57 af_rubberband: always calculate and set delay
Basically, add an if and reindent the block instead of exiting early.
2015-02-11 16:32:40 +01:00
wm4 d85aa35ffb af: account for queued frames in audio position calculation
af_rubberband exposed this issue.
2015-02-11 16:32:40 +01:00
wm4 8c055f873f af_rubberband: improve EOF handling
In theory it could happen that draining on EOF happens incrementally,
and then the unconditional reset could have dropped the remaining
buffered audio.
2015-02-11 16:31:35 +01:00
wm4 cf881396b5 dvb_tune: fix invalid syntax
Oops.
2015-02-11 11:36:14 +01:00
wm4 67aeccc254 audio: fix pool allocation
It reallocated the pool on every request, making the pool completely
useless. Oops.
2015-02-11 11:36:07 +01:00
wm4 b6ab34fc98 af_rubberband: pitch correction with librubberband
If "--af=rubberband" is used, librubberband will be used to speed up or
slow down audio with pitch correction.

This still has some problems: the audio delay is not calculated
correctly, so the audio position jitters around by a few milliseconds.
This will probably ruin video timing.
2015-02-11 00:29:12 +01:00
wm4 abbaaaa6e7 player: skip audio filter reinit on some types of speed changes
This avoids potentially dropping some small amount of audio data
buffered in filters.

Reinit can be skipped only if the filter is af_scaletempo (which maps to
AF_CONTROL_SET_PLAYBACK_SPEED). The other case using af_lavrresample is
much more complicated due to filter chain politics.

Also, changing speed between 1.0 and something higher typically inserts
or removes the filter, so this obviously requires reinitialization. It
can be prevented by forcing the filter with --af=scaletempo.
2015-02-10 22:48:15 +01:00
wm4 81d8c5d519 af_scaletempo: allow changing speed at runtime without reinit
Staring at the code a bit, it turns out that changing speed without
losing state is quite easy. The initialization code is big and
complicated, but most of it is specific only to the configured audio
format, not the speed.

Refactor the code so that changing speed at runtime could work. (It's
not actually used yet - the player code still does a complete reinit.
This will be fixed in the next commit.)

The "if (s->speed_tempo == s->speed_pitch)" looks a bit strange, but
does the same thing as the code did before: speed can be changed only if
exactly one flag is set. If both are set or none, speed can't be
changed.
2015-02-10 22:34:07 +01:00
wm4 2a3d19a9df af_scaletempo: drop detaching or skipping init on speed=1
This code skipped initialization if no speed/pitch change was to be
applied.

It also didn't force conversion of the audio to a supported format,
which is probably the most important case in context of compatibility.
With this change applied, af_scaletempo will always force format
conversion.

To make the change less disruptive, make the filter detach if
unconvertable formats are used. Some users use spdif and also have
"af=scaletempo" in their config, so better not completely break this.

In the case the filter was added with the "speed=both" suboption, the
filter also detached itself in this case; but it's an obscure case, so I
don't care about that.
2015-02-10 22:14:26 +01:00
wm4 30f3f9fcda manpage: fix af_scaletempo suggested commands 2015-02-10 20:43:59 +01:00
wm4 e66836db60 manpage: ipc: suggest --idle 2015-02-09 20:49:35 +01:00
wm4 5595251447 win32: fix/change application name
Pointed out in #935 (again).
2015-02-09 20:44:09 +01:00
wm4 2187323e58 README: mention some more deps 2015-02-09 20:41:25 +01:00
wm4 4b447c71fe README: movie -> media
Requested in #935.
2015-02-08 15:19:49 +01:00
wm4 0ab1509f14 vo: minor simplification
Whatever.
2015-02-07 21:14:43 +01:00
wm4 75edecb526 vo_vdpau: minor simplification
No change in behavior.
2015-02-07 21:14:12 +01:00
wm4 62b0f64c24 Revert "vo_opengl: disable alpha by default"
This reverts commit a33b46194c.

It turns out FFmpeg really considers this a bug, and fixed it by making
the decoder output the correct pixel format.

Fixes #1565. Reverts the fix #1528, though it should work fine with
a recent git master FFmpeg.
2015-02-06 23:23:27 +01:00
wm4 be5994a781 video: work around libswscale for PNG pixel formats
The intention is that we can test vo_opengl with high bit depth PNGs
better. This throws libswscale completely out of the loop, which before
was needed in order to convert from big endian to little endian.

Also apply a minimal cleanup to fmt-conversion.c (unrelated).
2015-02-06 23:22:16 +01:00
wm4 5de29b860b stream: get rid of remaining uses of the end_pos field
Most things stopped using this field for better support of growing
files. Go through the trouble to repalce the remaining uses, so it can
be removed.

Also move the "streaming" field; saves 4 bytes (wow!).
2015-02-06 21:43:52 +01:00
wm4 347cf97231 stream: minor cleanups
Fix return types and return values to make them more consistent. Some
reformatting and making code more concise.

In stream_reconnect(), avoid the additional mp_cancel_test() call by
moving the "connection lost" message below the mp_cancel_wait() call,
which effectively leads to the same behavior when the stream was already
canceled. (The goal is not to show the message in this case.)

Merge stream_seek_long() into stream_seek(). It was the only caller.

Always clear the eof flag on seeks.

Reduce access to stream internals in cache.c and stream_lavf.c.
2015-02-06 21:43:52 +01:00
wm4 45e214d7ae stream: slightly improve reconnect behavior
Wait for a longer time between reconnects. Introdeuce and use
mp_cancel_wait(), so that quitting is still immediate.
2015-02-06 19:19:15 +01:00
wm4 e14d09c8a6 stream_lavf: fix build with Libav
The API function used is FFmpeg-only.

Sigh...
2015-02-06 18:02:37 +01:00
wm4 f3ae845fd2 options: add --network-timeout
Not quite sure if this actually works as intended.

Fixes #1566.
2015-02-06 17:01:35 +01:00
wm4 ffe894ec0a options: change --msg-level option
Make it accept "," as separator, instead of only ":". Do this by using
the key-value-list parser. Before this, the option was stored as a
string, with the option parser verifying that the option value as
correct. Now it's stored pre-parsed, although the log levels still
require separate verification and parsing-on-use to some degree (which
is why the msg-level option type doesn't go away).

Because the internal type changes, the client API "native" type also
changes. This could be prevented with some more effort, but I don't
think it's worth it - if MPV_FORMAT_STRING is used, it still works the
same, just with a different separator on read accesses.
2015-02-06 16:48:52 +01:00
wm4 1a38741dce options: allow ":" as separator in key-value lists
Before this, unquoted occurrences of ":" lead to parsing errors. There's
no reason to reject it, especially since the traditional MPlayer syntax
uses ":" as separator. (Which is also the reason why ":" was rejected
before: the parser shares this code for handling splitting/quoting, and
we merely checked explicitly whether the option was split on ",".)
2015-02-06 15:42:12 +01:00