Commit Graph

230 Commits

Author SHA1 Message Date
wm4 77e1e8e38e audio: refactor mixer code and delete mixer.c
mixer.c didn't really deserve to be separate anymore, as half of its
contents were unnecessary glue code after recent changes. It also
created a weird split between audio.c and af.c due to the fact that
mixer.c could insert audio filters. With the code being in audio.c
directly, together with other code that unserts filters during runtime,
it will be possible to cleanup this code a bit and make it work like the
video filter code.

As part of this change, make the balance code work like the volume code,
and add an option to back the current balance value. Also, since the
balance semantics are unexpected for most users (panning between the
audio channels, instead of just changing the relative volume), and there
are some other volumes, formally deprecate both the old property and the
new option.
2016-07-17 19:21:28 +02:00
wm4 0fe62bc1d2 player: it's not --force-seeking but --force-seekable
Oops. Fuck.
2016-07-06 00:11:57 +02:00
wm4 69d5be1ee9 player: remove unused return value 2016-06-08 12:04:56 +02:00
wm4 bd9bba40ee player: tell user about --force-seeking if demuxer is not seekable
This comes up often, see e.g. #3220. The issue is that if the stream
input is not seekable, the demuxer is marked as not seekable. But if the
stream cache is enabled, the file still _might_ be seekable to a degree.
We recently disabled seeking in this mode because it can cause very
weird issues, mostly because if stream-layer seeking fails, the demuxers
will arbitrarily misbehave. On the other hand, it can work if the seek
is within the cached range, which is why the user can still enable it
with --force-seeking. There is a weird trade-off between allowing this
and not crapping up too easily, so just informing the user about the
possibility seems best.
2016-06-08 12:02:06 +02:00
Niklas Haas 5b5db336e9 build: silence -Wunused-result
For clang, it's enough to just put (void) around usages we are
intentionally ignoring the result of.

Since GCC does not seem to want to respect this decision, we are forced
to disable the warning globally.
2016-06-07 14:12:33 +02:00
wm4 af0a8d7478 player: restore usual seeking behavior
Commit 786f37ae accidentally changed seeking behavior such that
continuous seeking (holding the seek button down) would use the previous
seek target timestamp, instead of the new video timestamp. (This is for
the default mode, seeking to keyframes.)

The result is that the movement on the seekbar is smooth, but the way
the video updates is awkward. Some might actually prefer the new
behavior (and some players effectively show similar bahavior), but I
don't. So restore the old behavior.

This is done in two steps:

First: strictly wait for the entire seek process to finish, which will
effectively make the seeking code pick up the new video timestamp
correctly.

This would play audio immediately, which would result in noise during
continuous seeking, which leads to second: explicitly abort the playback
restarting process if this case is detected, and never play audio.
2016-05-09 22:54:49 +02:00
wm4 5df4ee55f1 player: strictly wait until done when backstepping
This fixes backstepping getting "stuck" when e.g. holding down a key
bound to the backstep command. The reason is that even if the backstep
itself is finished, the next backstep might not take the new video PTS
as reference if the hr-seek itself isn't finished yet.

The intention of not waiting for the hr-seek to finish was faster
backstepping by possibly skipping audio decoding. But it probably
doesn't matter enough to make the rest of the code more complex.
2016-04-27 17:02:00 +02:00
wm4 786f37ae1c player: cleaner determination of current playback PTS
In particular, this won't overwrite the playback PTS in coverart mode,
which actually fixes relative seeks.
2016-04-23 18:55:24 +02:00
wm4 abb3f80998 player: eagerly redraw OSD when seeking with coverart 2016-04-23 16:39:46 +02:00
wm4 834a236514 player: force wakeup on playback restart
Just a theoretical issue, most likely.
2016-04-20 13:11:11 +02:00
wm4 61ac156d47 player: reduce some timer calls 2016-04-20 10:50:22 +02:00
wm4 8dbc93a94c player: minor simplification to buffering property updates
Strictly schedule an update in regular intervals as long as either
stream cache or demuxer are prefetching. Don't update just always
because the stream cache is enabled ("idle != -1") or cache-related
properties are observed (mp_client_event_is_registered()).

Also, the "idle" variable was awkard; get rid of it with equivalent
code.
2016-04-20 10:41:09 +02:00
wm4 8db9206c54 player: simplify an aspect of buffering determination
Calculate the buffering percentage in the same code which determines
whether the player is or should be buffering. In particular it can't
happen that percentage and buffering state are slightly out of sync due
to calling DEMUXER_CTRL_GET_READER_STATE and reusing it with the
previously determined buffering state.

Now it's also easier to guarantee that the buffering state is updated
properly.

Add some more verbose output as well.

(Damn I hate this code, why did I write it?)
2016-04-19 22:01:30 +02:00
wm4 382bafcb13 player: loop on end of file if ab-loop-b is unset
Possibly slightly more useful/intuitive.
2016-04-18 21:33:19 +02:00
wm4 57506b27ed cache: use a single STREAM_CTRL for various cache info
Instead of having a separate for each, which also requires separate
additional caching in the demuxer. (The demuxer adds an indirection,
since STREAM_CTRLs are not thread-safe.)

Since this includes the cache speed, this should fix #3003.
2016-03-29 11:29:52 +02:00
wm4 9001083685 player: simplify mp_seek() 2016-02-28 20:01:29 +01:00
wm4 92ba630796 demux: remove relative seeking
Ever since a change in mplayer2 or so, relative seeks were translated to
absolute seeks before sending them to the demuxer in most cases. The
only exception in current mpv is DVD seeking.

Remove the SEEK_ABSOLUTE flag; it's not the implied default. SEEK_FACTOR
is kept, because it's sometimes slightly useful for seeking in things
like transport streams. (And maybe mkv files without duration set?)

DVD seeking is terrible because DVD and libdvdnav are terrible, but
mostly because libdvdnav is terrible. libdvdnav does not expose seeking
with seek tables. (Although I know xbmc/kodi use an undocumented API
that is not declared in the headers by dladdr()ing it - I think the
function is dvdnav_jump_to_sector_by_time().) With the current mpv
policy if not giving a shit about DVD, just revert our half-working seek
hacks and always use dvdnav_time_search(). Relative seeking might get
stuck sometimes; in this case --hr-seek=always is recommended.
2016-02-28 19:28:34 +01:00
wm4 49660bcc3e player: minor simplification
No need to pass endpts down in such a dumb way.

Also remove an outdated comment somewhere.
2016-02-27 20:03:15 +01:00
wm4 b4bbfea71d player: fix --force-window behavior
_Of course_ the previous commit broke --force-window behavior (like it
does every single time I touch it).

vo_has_frame() gets cleared after a seek, so e.g. stopping playback of a
file and going to the next by keeping the seek key down will enter a
short moment without video at the end of the first file, which will set
the stalled_video variable to true. Prevent it by using the indication
whether the window was properly created (which is probably exactly what
we want here).

This function is also responsible for destroying the window when needed,
and obviously we should never do that while video is active. (This is
the actual bug, although the other change in this commit already hides
the common breakage it caused.)
2016-02-25 11:21:54 +01:00
wm4 174ca8b172 player: honor --force-window if video is selected, but inactive
If a video track is selected, but no video is decoded from it (mostly
with broken files), then create the window anyway.
2016-02-24 22:19:00 +01:00
wm4 ae55896f42 player: remove old timeline/ordered chapters support 2016-02-15 21:03:51 +01:00
wm4 c0de087ba1 player: add complex filter graph support
See --lavfi-complex option.

This is still quite rough. There's no support for dynamic configuration
of any kind. There are probably corner cases where playback might freeze
or burn 100% CPU (due to dataflow problems when interaction with
libavfilter).

Future possible plans might include:
- freely switch tracks by providing some sort of default track graph
  label
- automatically enabling audio visualization
- automatically mix audio or stack video when multiple tracks are
  selected at once (similar to how multiple sub tracks can be selected)
2016-02-05 23:19:56 +01:00
wm4 7bb9203f7f player: refactor: eliminate MPContext.d_audio 2016-01-22 00:25:44 +01:00
wm4 8a9b64329c Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.

There are probably more files to which this applies, but I'm being
conservative here.

A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).

common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.

codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.

From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).

misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.

screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 18:36:06 +01:00
wm4 4195a345a5 player: refactor: eliminate MPContext.d_video
Eventually we want the VO be driven by a A->V filter, so a decoder
doesn't even have to exist. Some features definitely require a decoder
though (like reporting the decoder in use, hardware decoding, etc.), so
for each thing which accessed d_video, it has to be redecided if and how
it can access decoder state.

At least the "framedrop" property slightly changes semantics: you can
now always set this property, even if no video is active.

Some untested changes in this commit, but our bio-based distributed
test suite has to take care of this.
2016-01-17 18:38:07 +01:00
wm4 004bc95263 player: refactor: eliminate MPContext.d_sub
The same is going to happen to d_video and d_audio later.
2016-01-17 16:57:22 +01:00
wm4 e420464ba6 player: simplify backstepping
Basically reimplement it. The old implementation was quite stupid, and
was probably done this way because video filtering and output used to be
way less decoupled. Now we can reimplement it in a very simple way: when
backstepping, seek to current time, but keep the last frame that was
supposed to be discarded when reaching the target time. When the seek
finishes, prepend the saved frame to the video frame queue.

A disadvantage is that the new implementation fails to skip over
timeline boundaries (ordered chapters etc.), but this never worked
properly anyway. It's possible that this will be fixed some time in the
future.
2016-01-12 23:49:00 +01:00
wm4 6fc0fe4426 player: handle hrseek framedrop correctly
This was non-sense and checked the option instead of the actual flag.
Possibly could lead to incorrect hr-seeks.
2016-01-12 23:48:28 +01:00
Dmitrij D. Czarkoff ea442fa047 mpv_talloc.h: rename from talloc.h
This change helps avoiding conflict with talloc.h from libtalloc.
2016-01-11 21:05:55 +01:00
wm4 8135838018 player: eliminate demux_get_next_pts()
This slightly changes behavior when seeking with external audio/subtitle
tracks if transport streams and mpeg files are played, as well as
behavior when seeking with such external tracks.

get_main_demux_pts() is evil because it always blocks on the demuxer (if
there isn't already a packet queued). Thus it could lock up the player,
which is a shame because all other possible causes have been removed.

The reduced "precision" when seeking in the ts/mpeg cases (where
SEEK_FACTOR is used, resulting in byte seeks instead of timestamp seeks)
might lead to issues. We should probably drop this heuristic. (It was
introduced because there is no other way to seek in files with PTS
resets with libavformat, but its value is still questionable.)
2016-01-11 20:36:23 +01:00
wm4 b47bf06f97 sub: change how subtitles are read
Slightly change how it is decided when a new packet should be read.
Switch to demux_read_packet_async(), and let the player "wait properly"
until required subtitle packets arrive, instead of blocking everything.
Move distinguishing the cases of passive and active reading into the
demuxer, where it belongs.
2015-12-29 01:35:52 +01:00
wm4 0a0bb9059f video: switch from using display aspect to sample aspect
MPlayer traditionally always used the display aspect ratio, e.g. 16:9,
while FFmpeg uses the sample (aka pixel) aspect ratio.

Both have a bunch of advantages and disadvantages. Actually, it seems
using sample aspect ratio is generally nicer. The main reason for the
change is making mpv closer to how FFmpeg works in order to make life
easier. It's also nice that everything uses integer fractions instead
of floats now (except --video-aspect option/property).

Note that there is at least 1 user-visible change: vf_dsize now does
not set the display size, only the display aspect ratio. This is
because the image_params d_w/d_h fields did not just set the display
aspect, but also the size (except in encoding mode).
2015-12-19 20:45:36 +01:00
wm4 76fcef618b player: make timeline switching slightly nicer
But not much.
2015-11-18 20:58:07 +01:00
wm4 85450d06a1 player: use demuxer ts offset to simplify timeline ts handling
Use the demux_set_ts_offset() added in the previous commit to base each
timeline segment to use timestamps according to its relative position
within the overall timeline. As a consequence we don't need to care
about these timestamps anymore, and everything becomes simpler.

(Another minor but delicious nugget of sanity.)
2015-11-16 23:17:33 +01:00
wm4 70df1608d6 player: handle rebasing start time differently
Most of this is explained in the DOCS additions.

This gives us slightly more sanity, because there is less interaction
between the various parts. The goal is getting rid of the video_offset
entirely.

The simplification extends to the user API. In particular, we don't need
to fix missing parts in the API, such as the lack for a seek command
that seeks relatively to the start time. All these things are now
transparent.

(If someone really wants to know the real timestamps/start time, new
properties would have to be added.)
2015-11-16 22:47:17 +01:00
wm4 d32c4c75ef player: refactor display-sync frame duration calculations
Get rid of get_past_frame_durations(), which was a bit too messy. Add
a past_frames array, which contains the same information in a more
reasonable way. This also means that we can get the exact current and
past frame durations without going through awful stuff. (The main
problem is that vo_pts_history contains future frames as well, which is
needed for frame backstepping etc., but gets in the way here.)

Also disable the automatic disabling of display-sync if the frame
duration changes, and extend the frame durations allowed for display
sync. To allow arbitrarily high durations, vo.c needs to be changed
to pause and potentially redraw OSD while showing a single frame, so
they're still limited.

In an attempt to deal with VFR, calculate the overall speed using the
average FPS. The frame scheduling itself does not use the average FPS,
but the duration of the current frame. This does not work too well,
but provides a good base for further improvements.

Where this commit actually helps a lot is dealing with rounded
timestamps, e.g. if the container framerate is wrong or unknown, or
if the muxer wrote incorrectly rounded timestamps. While the rounding
errors apparently can't be get rid of completely in the general case,
this is still much better than e.g. disabling display-sync completely
just because some frame durations go out of bounds.
2015-11-13 22:45:40 +01:00
wm4 8d414e2fe7 command: make time properties unavailable if timestamp is unknown
Let's hope this doesn't confuse client API users too much. It's still
the best solution to get rid of corner cases where it actually return
the wrong timestamp on start, and then suddenly jump.
2015-10-16 16:16:10 +02:00
wm4 291f301c10 video/out: remove an unused parameter
This parameter has been unused for years (the last flag was removed in
commit d658b115). Get rid of it.

This affects the general VO API, as well as the vo_opengl backend API,
so it touches a lot of files.

The VOFLAGs are still used to control OpenGL context creation, so move
them to the OpenGL backend code.
2015-10-03 18:20:16 +02:00
wm4 ab7ac46bcc player: some more --force-window fixes
Sigh... After the recent changes, another regression appeared. This
time, the VO window wasn't cleared when changing from video to a non-
video file (such as audio-only with no cover art). Fix this by properly
taking the handle_force_window() bool parameter into account.

Also, the info message could be printed twice, which is harmless but
ugly. So just remove the message.

Also, do some more minor cleanups (like fixing the comment, which was
completely outdated).
2015-09-21 21:22:20 +02:00
wm4 7a19eb490e player: do not destroy VO prematurely when initializing playback
If --force-window wasn't used, this would destroy the VO while a file
is still being loaded, resulting in flicker and other interruptions
when switching from one playlist entry to another. Recent regression.

The condition used here is pretty tricky, but it boils down to that it
should trigger either in idle mode, or when loading has been fully done
(at these points we definitely know whether the VO will be needed).
2015-09-20 23:13:27 +02:00
wm4 2f4e01e772 player: make force-window in auto-profiles actually work
The previous commit was incomplete (and I didn't notice due to a broken
test procedure).

The annoying part is that actually creating the VO was separate; redo
this and merge the code for this into handle_force_window() as well.
This will also make implementing proper reaction to runtime option
changes easier. (Only the part for actually listening to option changes
is missing.)
2015-09-20 17:58:02 +02:00
wm4 2e3ce738f5 player: return better guess for playback time during seeks
Always compute the estimated absolute time of the seek target, and
display this as playback time during seeks.

Improves behavior with e.g. .ts files, for which we try to avoid seeks
by timestamp.
2015-08-21 15:37:07 +02:00
wm4 147f4956d3 player: deliver IDLE event after uninitializing state
A client API user might count on the fact that audio and video outputs
have already been uninitialized. (They remain uninitialized before
entering idle mode in order to allow smooth transition to the next
playlist entry.) Since event delivery is asynchronous, this has to
happen after actually doing the uninitialization, or the client will
essentially run into a race condition.
2015-08-20 15:25:32 +02:00
wm4 828881816a demux: remove redundant demux_chapter.name field
Instead, force everyone to use the metadata struct and set a "title"
field. This is only a problem for the timeline producers, which set up
chapters manually. (They do this because a timeline is a separate
struct.)

This fixes the behavior of the chapter-metadata property, which never
returned a "title" property for e.g. ordered chapters.
2015-08-12 11:11:23 +02:00
wm4 60794e2359 player: raise maximum idle time
No reason to wake up every other minute.
2015-08-07 02:41:02 +02:00
wm4 f792f56440 player: remove higher-level remains of DVD/BD menu support
Nobody wanted to restore this, so it gets the boot.

If anyone still wants to volunteer to restore menu support, this would
be welcome. (I might even try it myself if I feel masochistic and like
wasting a lot of time for nothing.) But if it does get restored, it
should be done differently. There were many stupid things about how it
was done. For example, it somehow tried to pull mp_nav_events through
all the layers (including needing to "buffer" them in the demuxer),
which was needlessly complicated. It could be done simpler.

This code was already inactive, so this commit actually changes nothing.
Also keep in mind that normal DVD/BD playback still works.
2015-08-03 23:49:14 +02:00
wm4 0d35c78a6c player: put --term-playing-msg in a separate log category
Fixes #1983.
2015-07-13 13:06:09 +02:00
wm4 4e76782630 player: refactor chapter seek code
mp_seek_chapter() had only 1 caller. Also the code was rather
roundabout; the entire function can be compressed to 5 lines of code.
(The new code is functionally the same - "mpctx->last_chapter_seek =
-2;" was effectively a dead assingment.)
2015-07-10 12:11:14 +02:00
wm4 15581f2209 player: never overwrite stop_play field
This is a real pain: if a quit command is received, it's set to PT_QUIT.
And then other code could overwrite it, making it not quit. The annoying
bit is that stop_play is written and read in many places. Just not
overwriting it unconditionally seems to be the best course of action.
2015-07-08 21:31:31 +02:00
wm4 ff9c597fbf player: increase tick event update frequency
500ms is a bit too high. Change it to 50ms. This improves client API
(and Lua) playback state update frequency.

Updating absolutely every time the audio PTS changes would be possible,
but is not helpful. Audio samplerates are high to trigger a wakeup
feedback loop, so the process would waste CPU time on updating the
playback position all the time.

(If a client application wants to ensure smooth update of the playback
position, it should update the position manually using a timer and by
reading the property - the application can make a much better decision
at how often the playback has to happen.)
2015-06-23 19:23:11 +02:00