Commit Graph

265 Commits

Author SHA1 Message Date
wm4 a6d29494ca player: print hw format on "VO: " line too
Useful for distinguishing bit depth when hardware decoding. (To the
degree it's useful to show it at all. This just brings the hardware
decoding case on the same level of showing information as the software
decode call.)
2017-01-29 12:53:58 +01:00
wm4 1b1771f2a7 video: support filtering hardware frames via libavfilter
Requires a bunch of hacks:
- we access AVFilterLink.hw_frames_ctx. This is not a public API in
  FFmpeg and Libav. Newer FFmpeg provides an accessor
  (av_buffersink_get_hw_frames_ctx), but it's not available in Libav or
  the current FFmpeg release or Libav. We need this value after filter
  graph creation, so We have no choice but to access this.
  One alternative is making filter creation and format negotiation
  fully lazy (i.e. delay it and do it as filters are output), but this
  would be a huge change.
  So for now, we knowingly violate FFmpeg's and Libav's ABI and API
  constraints because they don't provide anything better.
  On newer FFmpeg, we use the (quite ugly) accessor, though.
- mp_image_params doesn't (and can't) have a field for the frames
  context AVBufferRef. So we pass it via vf_set_proto_frame(), and even
  more hacks.
- if a filter needs a hw context, but we haven't created one yet
  (because normally we create them lazily), it will fail at init.
- we allow any hw format now, although this could go horrible wrong.

Why all this effort? We could move hw deinterlacing filters etc. to
FFmpeg, which is a very worthy goal.
2017-01-16 16:10:39 +01:00
wm4 4e25feda0d player: change aspects of cover art handling
Cover art handling is a disgusting hack that causes a mess in all
components. And this will stay this way. This is the Xth time I've
changed cover art handling, and that will probably also continue.

But change the code such that cover art is injected into the demux
packet stream, instead of having an explicit special case it in the
decoder glue code. (This is somewhat more similar to the cover art hack
in libavformat.)

To avoid that the over art picture is decoded again on each seek, we
need some additional "caching" in player/video.c. Decoding it after each
seek would work as well, but since cover art pictures can be pretty
huge, it's probably ok to invest some lines of code into caching it.

One weird thing is that the cover art packet will remain queued after
seeks, but that is probably not an issue.

In exchange, we can drop the dec_video.c code, which is pretty
convenient for one of the following commits. This code duplicates a
bunch of lower-level decode calls and does icky messing with this weird
state stuff, so I'm glad it goes away.
2017-01-10 15:43:02 +01:00
wm4 b1c0bbe8b8 video: use demuxer-signaled duration for last video frame
Helps with gif, probably does unwanted things with other formats.

This doesn't handle --end quite correctly, but this could be added
later.

Fixes #3924.
2016-12-21 18:18:24 +01:00
Douglas Christman 2aebf3e482 manpage: replace `-vo` with `--vo` 2016-12-08 18:30:50 +01:00
wm4 c4d6fcbb02 player: make sure non-video subtitle rendering is reset if video resumes
If video reaches EOF, subtitle timing will be switched to timing without
video frames. This means it calls osd_set_force_video_pts() and
overrides the PTS of whatever video frame is current (since the video
frame's PTS has nothing to do with the current playback position
anymore).

This was not reset when seeking back into video. Subtitles wouldn't show
up, or if there was a subtitle displayed, it would get stuck with it. In
particular, this could happen even if EOF was only temporary (such as
with --keep-open).

Fix this by clearing the override PTS whenever a video frame is shown.

Fixes #3770.
2016-11-18 13:02:03 +01:00
wm4 90b968a67a player: show subtitles on VO if --force-window is used
If a VO is created, but no video is playing (i.e. --force-window is
used), then until now no subtitles were shown. This is because VO
subtitle display normally depends on video frame timing. If there are no
video frames, there can be no subtitles.

Change this and add some code to handle this situation specifically. Set
a subtitle PTS manually and request VO redrawing manually, which gets
the subtitles rendered somehow.

This is kind of shaky. The subtitles are essentially sampled at
arbitrary times (such as when new audio data is decoded and pushed to
the AO, or on user interaction). To make a it slightly more consistent,
force a completely arbitrary minimum FPS of 10.

Other solutions (such as creating fake video) would be more intrusive or
would require VO-level API changes.

Fixes #3684.
2016-10-26 20:44:05 +02:00
Aman Gupta 183af9d72e player: speed up audio/video re-sync when there is a huge delay
when there is a huge delay between audio/video sync, it can take a
really long time to converge back. this speeds up the resync time by
increasing the max_change allowed per iteration.

Signed-off-by: wm4 <wm4@nowhere>
2016-10-21 17:11:26 +02:00
wm4 39fc5e1deb player: make --stop-screensaver runtime-changeable
Move the screensaver enable/disable determination to a central place,
and call it if the stop-screensaver property is changed.

Also, do not stop the screensaver when in idle mode (i.e. no file is
loaded).

Fixes #3615.
2016-10-02 12:33:34 +02:00
wm4 dd339b200b video: trust demuxer framerate on invalid timestamps
If the PTS goes backwards (whether it's a timestamp reset or some other
problem) would just use 0 as frame duration. (At least until the logic
for detecting divergence with the timestamps gets active.)

Trust the demuxer framerate in these cases instead, if it's available. I
think this improves behavior slightly with some broken files.
2016-09-26 17:55:00 +02:00
wm4 44a7cb7f0e player: minor changes in init code
Move the MPV_LEAK_REPORT env query to mp_create(), where it will also be
used by the client API (it might be helpful, so why not). The same
applies to MPV_VERBOSE.

The prepare_playlist() call doesn't need to be in mp_initialize() and
can just be in mp_play_files() to reduce the size of mp_initialize().

Also, remove wakeup_playloop(), which is 100% redundant with
mp_wakeup_core_cb().
2016-09-19 19:57:31 +02:00
wm4 2415b69572 player: more option/property consistency fixes
Some properties had a different type from their equivalent options (such
as mute, volume, deinterlace, edition). This wasn't really sane, as raw
option values should be always within their bounds. On the other hand,
these properties use a different type to reflect runtime limits (such as
range of available editions), or simply to improve the "UI" (you don't
want to cycle throuhg the completely useless "auto" value when cycling
the "mute" property).

Handle this by making them always return the option type, but also
allowing them to provide a "constricted" type, which is used for UI
purposes. All M_PROPERTY_GET_CONSTRICTED_TYPE changes are related to
this.

One consequence is that you can set the volume property to arbitrary
high values just like with the --volume option, but using the "add"
command it still restricts it to the --volume-max range.

Also deprecate --chapter, as it is grossly incompatible to the chapter
property. We pondered renaming it to --chapters, or introducing a more
powerful --range option, but concluded that --start --end is actually
enough.

These changes appear to take care of the last gross property/option
incompatibilities, although there might still be a few lurking.
2016-09-18 16:08:21 +02:00
wm4 03fec24e19 player: litter code with explicit wakeup calls
This does 3 kinds of changes:
- change sleeptime=x to mp_set_timeout()
- change sleeptime=0 to mp_wakeup_core() calls (to be more explicit)
- change commands etc. to call mp_wakeup_core() if they do changes that
  require the playloop to be rerun

This is preparation for the following changes. The goal is to process
client API requests without having to rerun the playloop every time. As
of this commit, the changes should not change behavior. In particular,
the playloop is still implicitly woken up on every command.
2016-09-16 14:39:45 +02:00
wm4 b8ade7c99b player, ao, vo: don't call mp_input_wakeup() directly
Currently, calling mp_input_wakeup() will wake up the core thread (also
called the playloop). This seems odd, but currently the core indeed
calls mp_input_wait() when it has nothing more to do. It's done this way
because MPlayer used input_ctx as central "mainloop".

This is probably going to change. Remove direct calls to this function,
and replace it with mp_wakeup_core() calls. ao and vo are changed to use
opaque callbacks and not use input_ctx for this purpose. Other code
already uses opaque callbacks, or has legitimate reasons to use
input_ctx directly (such as sending actual user input).
2016-09-16 14:37:48 +02:00
sda89ha9 d054a7181f player: fix average frame duration calculation 2016-09-09 19:18:08 +02:00
wm4 ea94b01e6b client API: make mpv_opengl_cb_uninit_gl() behavior slightly nicer
Instead of deselecting the video stream plainly, use the slightly more
robust error_on_track() function. Also give it an error code (although
I'm not sure if this one is confusing, it's better than the one before).
2016-09-09 12:27:41 +02:00
wm4 1393d79417 command: fix or document some property/option consistency issues
Make some existing properties behave more like options. This mostly
means they don't deny access if the associated component is not active,
but redirects to the option.

One kind of fishy change is that we apply --brightness etc. only if
they're not set to the default value. This won't necessarily work with
--vo=xv, but affects only cases where 1. the Xv adapter has been changed
to non-defaults, and 2. the user tries to reset them with mpv by passing
e.g. --brightness=0. We don't care about Xv, and the noted use-case is
dumb, so this change is acceptable.
2016-09-01 20:57:33 +02:00
wm4 d223959cda player: slightly adjust framerate guessing heuristic
Some files not only use rounded timestamps, but they also do it
incorrectly. They may jitter between up to 4 specific frame durations.
In this case, I found a file that mostly used 41ms and 42ms, but also
had 40ms and 43ms outliers (often but not always following each other).

This breaks the assumption of the framerate estimation code that the
frame duration can deviate up to 1ms. If it jitters around 4 possible
frame durations, the maximum deviation is 3ms. Increase it accordingly.

The change might make playback of "true VFR" video via display-sync mode
worse, but it's not like it was particularly good in the first place.

Also, the check whether to usen the container FPS needs to be stricter.
In the worst case, num_dur is 1, which doesn't really indicate any
evidence that the framerate is correct. Only if there are "enough"
frames the deviation check will become meaningful. 16 is an arbitrary
value that has been designated "enough" by myself.

Also otuput the frame duration values for --dump-stats.
2016-08-29 17:15:06 +02:00
wm4 93104142f4 player: log if video is considered an image
It's a heristic that can fail, so better log it.
2016-08-21 12:27:48 +02:00
wm4 5d2dfbdfca player: refresh very low framerate video on filter changes
Limit the max. time the refresh is delayed. Make it refresh at all if
image mode is enabled.

Fixes #3435.
2016-08-19 09:38:45 +02:00
wm4 4e3663a2da vf_rotate: allow arbitrary rotation
vf_rotate selects the correct filter for 90° rotation, but it can be
extended to use lavfi's vf_rotate as fallback.

See #3434.
2016-08-19 09:37:52 +02:00
wm4 7bba97b301 video: don't discard video frames after endpts
Instead of letting it keep decoding by trying to find a new frame,
"plug" the frame queue by not removing it. (Or actually, by putting
it back instead of discarding it.)

Matters for seamless looping (following commits), and possibly some
other corner cases.

The added function vf_unread_output_frame() is a bit of a sin, but still
reasonable, since its implementation is trivial.
2016-08-18 20:37:25 +02:00
wm4 f5bbb5aed2 player: add option to control duration of image display
The --image-display-duration option controls how long an image is
displayed. It's also possible to display the image forever (until manual
user interaction stops playback).

With this, the core drops the old method to "drain" video (i.e. waiting
for the last frame duration on end of playback). Instead, we reuse
MPContext.time_frame. The old mechanism was disabled for non-images
anyway.

Fixes #3425.
2016-08-17 22:46:48 +02:00
wm4 86fa1e6129 player: allow passing flags to queue_seek()
Change the last parameter from a bool to an int, which is supposed to
take bit-flags. The at this point only flag is MPSEEK_FLAG_DELAY, which
replaces the previous bool parameter. The old false parameter becomes 0,
the old true parameter becomes MPSEEK_FLAG_DELAY.

Since the old "immediate" parameter is now essentially inverted, two
coalesced immediate and delayed seeks end up as delayed instead of
immediate. This change doesn't matter, since there are no relative
immediate seeks anyway.
2016-08-15 21:07:32 +02:00
wm4 32cc190a55 player: fix display-sync timing if audio take long on resume
In display-sync mode, the very first video frame is idiotically fully
timed, even though audio has not been synced yet at this point, and the
video frame is more like a "preview" frame. But since it's fully timed,
an underflow is detected if audio takes longer than the display time of
the frame (we send the second frame only after audio is done).

The timing code will try to compensate for the determined desync, but it
really shouldn't. So explicitly discard the timing info in this specific
case. On the other hand, if the first frame still hasn't finished
display, we can pretend everything is ok.

This is a hack - ideally, we either would send a frame without timing
info (and then send it again or so when playback starts properly), or we
would add real pause support to the VO, and pause it during syncing.
2016-08-07 14:14:32 +02:00
wm4 6bb48a10db player: disable DS with spdif transcoding too
Otherwise it behaves dumb. (Although you could argue it shouldn't try to
guess whether speed changes work, but instead simply disable DS if they
don't work.)
2016-07-24 19:19:24 +02:00
wm4 8b47e5daa4 video: respect --deinterlace=auto
--deinterlace=auto is the default, and has the obscure semantics that
deinterlacing is disabled, unless the user has manually inserted a
deinterlacing filter.

While in software decoding this doesn't matter, and we will happily
insert 2 yadif filters (if the user has already added one), or not
remove the yadif filter (if deinterlacing is disabled, but the user has
added the filter manually), this is different with hardware deinterlacer
filters. These support VFCTRL_SET_DEINTERLACE for toggling deinterlacing
filtering at runtime. It exists mainly for legacy reasons, and possibly
because it makes switching deinterlacing modes more efficient. It might
also gives us an entry-point for VO deinterlacing, maybe. For whatever
reasons this mechanism exists, we still support and use it.

This commit fixes that video.c always used VFCTRL_SET_DEINTERLACE to
disable deinterlacing, even if --deinterlace=auto was set. Fix this by
checking the value of the option directly.
2016-07-12 19:37:09 +02:00
wm4 16b48a429d video: fix midstream video configuration changes
Commit 771a8bf5 added code to avoid unnecessary vf_reconfig() calls for
unrelated reasons, but forget to consider that it has to be called at
least once if the input format changes. As a consequence it got "stuck"
due to not being able to decode more frames.
2016-07-08 08:22:51 +02:00
wm4 8660b4c9f0 video: limit number of frames sent to VO to the VO requested amount
vo_frame can have more than 1 frame - the extra frames are future
references, which are sometimes useful for filtering (vo_opengl
interpolation). There's no harm in reducing the number of frames sent to
the VO requested amount of future frames, so do that.

Doesn't actually reduce the number of concurrently in use frames in
practice.
2016-07-07 16:10:13 +02:00
wm4 771a8bf5c6 video: fix deinterlace filter handling for VFCTRL_SET_DEINTERLACE filters
Some filters support VFCTRL_SET_DEINTERLACE. This affects most hardware
deinterlace filters. They can be inserted by the user manually, or auto-
inserted by vf.c itself as conversion filter (vf_d3d11vpp). In these
cases, we shouldn't insert or remove filters outselves, and instead
VFCTRL_SET_DEINTERLACE should be invoked to switch the mode.

This wasn't done correctly in the recently refactored code and could
have broken with --deinterlace. (The refactor only considered switching
via property in this case.) Fix it by making it a proper part of the
filter_reconfig() function, and making set_deinterlacing() (which is
called by the property handler) merely call filter_reconfig() in all
cases to do the real work.

We can even avoid rebuilding the filter chain - though only if no other
auto-filters are inserted. It probably also provides a slightly cleaner
way to implement functionality in the VO while still inserting video
filter fallbacks correctly if required.
2016-07-06 14:08:47 +02:00
wm4 0b1ef81498 video: fix deinterlace filter handling on pixel format changes
The test scenario at hand was hardware decoding a file with d3d11 and
with deinterlacing enabled. The file switches to a non-hardware
dedocdeable format mid-stream. This failed, because it tried to call
vf_reconfig() with the old filters inserted, with was fatal due to
vf_d3d11vpp accepting only hardware input formats.

Fix this by always strictly removing all auto-inserted filters
(including the deinterlacing one), and reconfiguring only after that.

Note that this change is good for other situations too, because we
generally don't want to use a hardware deinterlacer for software
decoding by default. They're not necessarily optimal, and VAAPI VPP even
has incomprehensible deinterlacer bugs specifically with software frames
not coming from a hardware decoder.
2016-07-06 13:38:43 +02:00
wm4 d72bcc8041 player: rewrite deinterlace filter auto-insertion
Instead of using the "vf" command code (which changes filters at runtime
on user input), use the general filter-insertion code. The latter was
added later, and is more suitable for automatically inserted filters.

The old code failed in particular when using watch-later saving, which
stored the filter list in the resume config file. If a user changed the
hardware decoding mode via command line, the stored filter chain was out
of date and could cause failure due to not working with hardware or
software decoding mode. Storing the deinterlace filter in the filter
list was unavoidable, because it was part of the user state. (The new
code only edits the actually instantiated filters.)
2016-07-05 21:10:26 +02:00
wm4 46fff8d31a video: refactor how VO exports hwdec device handles
The main change is with video/hwdec.h. mp_hwdec_info is made opaque (and
renamed to mp_hwdec_devices). Its accessors are mainly thread-safe (or
documented where not), which makes the whole thing saner and cleaner. In
particular, thread-safety rules become less subtle and more obvious.

The new internal API makes it easier to support multiple OpenGL interop
backends. (Although this is not done yet, and it's not clear whether it
ever will.)

This also removes all the API-specific fields from mp_hwdec_ctx and
replaces them with a "ctx" field. For d3d in particular, we drop the
mp_d3d_ctx struct completely, and pass the interfaces directly.

Remove the emulation checks from vaapi.c and vdpau.c; they are
pointless, and the checks that matter are done on the VO layer.

The d3d hardware decoders might slightly change behavior: dxva2-copy
will not use the VO device anymore if the VO supports proper interop.
This pretty much assumes that any in such cases the VO will not use any
form of exclusive mode, which makes using the VO device in copy mode
unnecessary.

This is a big refactor. Some things may be untested and could be broken.
2016-05-09 20:03:22 +02:00
wm4 5800d1845f player: always show the first frame in DS mode
Fixes bogus frame drop counter in cover art mode.
2016-04-24 20:14:51 +02:00
wm4 5f97bd4223 player: assume video forwards timestamps jumps only with some formats
Another crappy fix for timestamp reset issues. This time, we try to fix
files which have very weird but legitimate frame durations, such as
cdgraphics. It can have many short frames, but once in a while there are
potentially very long frames.

Fixes #3027.
2016-04-24 18:24:46 +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 d73d5327b3 player: fix breakage when combining 3D and rotate auto-filters
This would get stuck in reconfiguring the filter chain forever, because
params was mutated ("params.rotate = 0;"). This was used as input for
vf_reconfig(), but the filter chain input must always be equivalent to
the decoder output, or filter chain reconfiguration will be triggered.
The line of code to reset the rotation is from a time when this used to
work differently.

Also remove the unnecessary try_filter() parameter.
2016-03-28 19:39:33 +02:00
wm4 cdd30fd0ab player: remove auto-inserted filters before adding them again
Makes certain cases of runtime changes actually work.

Also change the label for the stereo3d filter and make it consistent
with the rotate one.
2016-03-28 19:36:11 +02: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 71fa2e6fc2 player: slightly simplify how demuxer streams are enabled/disabled
Instead of having reselect_demux_streams() look at all streams, make it
look at the current stream that is being enabled/disabled.
2016-02-25 22:44:50 +01:00
wm4 f2b039da77 audio/video: expose codec info as separate field
Preparation for the timeline rewrite. The codec will be able to change,
the stream header not.
2016-02-15 20:34:45 +01:00
wm4 f219a48dca video: remove pointless parameter indirection
This is always the same value.
2016-02-15 20:28:36 +01:00
wm4 0868546f9d player: remove dead code
Fixes CID 1350055 and CID 1350054.
2016-02-12 16:06:20 +01:00
wm4 7caecc53b0 player: fix crash if no video decoder can be initialized
Caused by the recent refactoring for complex filters.
2016-02-10 00:07:01 +01:00
wm4 b7f6dfc19a player: force refresh seek when changing audio filters
Unfortunately I see no better solution.

The refresh seek is skipped if the amount of buffered audio is not
overly huge.

Unfortunately softvol af_volume insertion still can cause this issue,
because it's outside of the normal dynamic filter chain changing code.

Move the video refresh call to reinit_video_filters() to make it more
uniform along with the audio code.
2016-02-09 22:19:01 +01:00
wm4 ffb1d7807e player: remove some further current_track dependencies
Now it's used for initialization only for audio and video.
2016-02-05 23:41:44 +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 8af70561a4 player: move audio and video decoder init to separate functions
Preparation.
2016-02-05 23:17:27 +01:00
wm4 5c8378b71a player: use different variable to indicate coverart
Slightly better.
2016-02-01 22:14:32 +01:00
wm4 ab318aeea8 audio/video: merge decoder return values
Will be helpful for the coming filter support. I planned on merging
audio/video decoding, but this will have to wait a bit longer, so only
remove the duplicate status codes.
2016-02-01 22:03:04 +01:00