Commit Graph

458 Commits

Author SHA1 Message Date
wm4 300f6a3344 video: drop some more IMGFMT aliases
For vo_opengl and vo_direct3d, these are supported in a generic way.

For vf_vapoursynth, we could probably map its VSFormat struct in a
generic way, but for now do some bullshit.

vf_eq.c actually loses support for these formats. We could add generic
support too (anything that has 8 bit planes will work), but why bother.
The filter is deprecated anyway.
2017-06-29 21:30:10 +02:00
Niklas Haas 6a4ce39648 vf_format: also reset gamma-related attributes when changing gamma
This prevents nasty surprises like the sig-peak still being left at 1.0
when reinterpreting SDR as HDR, or the OOTF for HLG being left as
display-referred.
2017-06-18 20:54:44 +02:00
Niklas Haas 1f3000b03c vo_opengl: implement support for OOTFs and non-display referred content
This introduces (yet another..) mp_colorspace members, an enum `light`
(for lack of a better name) which basically tells us whether we're
dealing with scene-referred or display-referred light, but also a bit
more metadata (in which way is the scene-referred light expected to be
mapped to the display?).

The addition of this parameter accomplishes two goals:

1. Allows us to actually support HLG more-or-less correctly[1]
2. Allows people playing back direct “camera” content (e.g. v-log or
   s-log2) to treat it as scene-referred instead of display-referred

[1] Even better would be to use the display-referred OOTF instead of the
idealized OOTF, but this would require either native HLG support in
LittleCMS (unlikely) or more communication between lcms.c and
video_shaders.c than I'm remotely comfortable with

That being said, in principle we could switch our usage of the BT.1886
EOTF to the BT.709 OETF instead and treat BT.709 content as being
scene-referred under application of the 709+1886 OOTF; which moves that
particular conversion from the 3dlut to the shader code; but also allows
a) users like UliZappe to turn it off and b) supporting the full HLG
OOTF in the same framework. But I think I prefer things as they are
right now.
2017-06-18 20:54:44 +02:00
Niklas Haas c335e84230 video: refactor HDR implementation
List of changes:

1. Kill nom_peak, since it's a pointless non-field that stores nothing
   of value and is _always_ derived from ref_white anyway.

2. Kill ref_white/--target-brightness, because the only case it really
   existed for (PQ) actually doesn't need to be this general: According
   to ITU-R BT.2100, PQ *always* assumes a reference monitor with a
   white point of 100 cd/m².

3. Improve documentation and comments surrounding this stuff.
4. Clean up some of the code in general. Move stuff where it belongs.
2017-06-18 20:48:23 +02:00
wm4 c680cfd18a vf_dlopen: remove this filter
It was an attempt to move some MPlayer filters (which were removed from
mpv) to external, loadable filters. That worked well, but then the
MPlayer filters were ported to libavfilter (independently), so they're
available again. Also there is a more widely supported and more advanced
loadable filter system supported by mpv: vapoursynth.

In conclusion, vf_dlopen is not useful anymore, confusing, and requires
quite a bit of code (and probably wouldn't survive the rewrite of the
mpv video filter chain, which has to come at some point). It has some
implicit dependencies on internal conventions, like possibly the format
names dropped in the previous commit.

We also deprecated it last release. Drop it.
2017-06-18 13:55:40 +02:00
wm4 cc69650e76 af, vf: improvements to libavfilter bridge
Add the "lavfi-" prefix (details see manpage additons).

Tag the filter name as "(lavfi)" in the verbose filter list output.
2017-05-31 17:42:55 +02:00
wm4 c0ba8b520f vf.c, vf.h: change license to LGPL
Most authors have agreed. Like with vo.c, we don't take module
declarations into consideration (see 0e09533c73).

Notable issues:

115bfb9762: the author has (probably) not agreed. The vf.c changes were
removed with the removal of filter DR, though (see c54fc507da).

7b25afd742: the same author adds VOCTRLs for deinterlacing switching at
runtime. Put them under a HAVE_GPL ifdef just to be sure. (It looks like
we could remove the VOCTRLs immediately, as they're needed only for some
compatibility things, but no need to do that yet.)

02b199e5e9: the author had a conditional agreement to LGPL, which
doesn't allow us to change it just yet, but the code added here was
completely removed anyway. (These days, the pts is passed as mp_image
field, and put_image is gone.)

3532cd532e: same author, but code removed with DR removal.

f0626e2f8d: same author, but code was moved to mp_image.c.

e5b4b495c3: agreed to LGPLv3+ only, but the code was removed in
cfa1f9e082 anyway.

086c324692: author was not asked - minor warning fix, but no mpv
includes malloc.h anymore.

e9d0a1d609: author was not asked - removed again in 33b62af947.

c260a1139d: author could not be reached - but this code was removed when
mpv changed the image allocation code to essentially use FFmpeg's
pixdesc.
2017-05-11 15:02:58 +02:00
wm4 1143f2877a d3d11: change mp_image plane pointer semantics
Until now, the texture pointer was stored in plane 1, and the texture
array index was in plane 2. Move this down to plane 0 and plane 1. This
is to align it to the new WIP D3D11 decoding API in Libav, where we
decided that there is no reason to avoid setting plane 0, and that it
would be less weird to start at plane 0.
2017-05-04 01:13:03 +02:00
wm4 451e1f0db3 vf_lavfi, af_lavfi: remove unused/deprecated include
Looks like Libav is going to drop it, unnecessarily making compilation
fail.
2017-04-05 16:12:47 +02:00
wm4 400a7c409f vf: fix another broken case of conversion filter auto-insertion
If the VO doesn't support a format output by vf_lavfi, no conversion
filter was inserted, and filter chain creation failed.

This is because vf_lavfi doesn't properly follow the format negotiation
model, which means the format negotiation pass does not catch all cases
where conversion is needed. Specifically, vf_lavfi supports that all
output formats are supported for any given input format, but then does
not actually call vf_next_query_format() in reconfig() to check which
format it uses, but outputs whatever it gets from libavfilter.

I think this is ok to avoid excessive complexity in vf_lavfi.c, but it
also means adding more kludges to vf.c. I justify this (and the code
duplication) with the idea that the current filter chain code will die
anyway at some point.

The .log field additions for c->first/c->last are strictly speaking not
needed, but useful for debugging.
2017-04-05 11:06:25 +02:00
wm4 31611fc46b video: support positional arguments for automatic lavfi option bridge
Now e.g. --vf=pad=1000:1000 works.

All in all pretty ugly and hacky. Just look away.
2017-04-03 18:12:42 +02:00
wm4 d4c1ddd6b1 video: add automatic libavfilter bridge to option parsing
Now you can for example do "--vf=hue=h=60" - there is no "hue" filter in
mpv, so libavfilter's will be used.

This has certain caveats (see manpage).

The point of this is providing a relatively smooth transition path to
removing our own filter stuff.
2017-04-02 18:47:36 +02:00
wm4 3a9e661e92 video: deprecate almost all video filters
The plan is to nuke the custom filter chain completely. It's not clear
what will happen to the still needed builtin filters (mostly hardware
deinterlacing and vf_vapoursynth). Most likely we'll replace them with
different filter chain concept (whose main purpose will be providing
builtin things and bridging to libavfilter).

The undocumented "warn" options are there to disable deprecation
warnings when the player inserts filter automatically.

The same will be done to audio filters, at a later point.
2017-04-02 18:00:16 +02:00
wm4 7d424b4ce4 command: add better runtime filter toggling method
Basically, see the example in input.rst.

This is better than the "old" vf-toggle method, because it doesn't
require the user to duplicate the filter string in mpv.conf and
input.conf.

Some aspects of this changes are untested, so enjoy your alpha testing.
2017-03-25 17:07:40 +01:00
Philip Sequeira a2a5fa4545 options: add M_OPT_FILE to some more file options
(Helps shell completion.)
2017-03-06 15:41:06 +01:00
wm4 97403839e5 vf_vavpp: fix first-field mode
It didn't deinterlace at all. Oops.
2017-02-28 00:57:51 +01:00
wm4 75fc2bee1e vf_vavpp: add advanced deint bug compatibility for Intel vaapi drivers
I'm not sure what's going on here, but it appears kodi switches forward
and backwards references for advanced VPP deinterlacing modes. This in
turn makes deinterlacing with these modes apparently work. If you don't
switch the directions, you get a stuttering mess.

As far as the libva trace dump is concerned, this makes mpv's libva
deinterlacing API use behave like kodi's, and appears to reproduce
smooth video with advanced libva deinterlacing enabled.

I'm hearing that Mesa actually does it correctly, and I'm not sure what
will happen there. For now, passing "reversal-bug=no" as sub-option to
the vavpp filter will undo this behavior.
2017-02-28 00:57:51 +01:00
wm4 d015aab428 vf_vavpp: minor fixes
Fully initialize two structs (not doing so may or may not have been a
bug).

Actually destroy the VABufferID we create (moderate memory leak).
2017-02-28 00:57:51 +01:00
wm4 9714e04e94 vf_vavpp: always limit forward/backward surfaces to requested number
Don't give the driver more forward/backward refernces than it requested
in num_forward_references/num_backward_references. This shouldn't
matter, I'm just trying to play it safe.
2017-02-27 14:19:41 +01:00
wm4 e9cda168c0 vf_vavpp: remove apparently broken change-detection
This is probably wrong. Just don't bother with it. The only potentially
negative effect is from calling vaQueryVideoProcPipelineCaps() every
frame.
2017-02-27 14:18:04 +01:00
wm4 39adaf3dcc vf_lavfi: don't crash with VOs without hardware decoding support
When playing with VOs which do not provide mp_hwdec_ctx, vf->hwdec_devs
will remain NULL. This would make it crash on hwdec_devices_get_first(),
even if no hardware decoding or filters using hardware decoding were
involved.

Fixes #4064.
2017-01-25 08:32:35 +01:00
wm4 b14fac9afa build: replace some FFmpeg API checks with version checks
The FFmpeg versions we support all have the APIs we were checking for.
Only Libav missed them. Simplify this by explicitly checking for FFmpeg
in the code, instead of trying to detect the presence of the API.
2017-01-24 08:11:42 +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 91fb7078e2 vf_lavfi: switch to AVBufferSrcParameters
Instead of using the awful older "API" that passed the parameters
formatted as string. AVBufferSrcParameters is also a prerequisite for
hardware frame filtering support.
2017-01-16 16:10:39 +01:00
wm4 e48f1f31cb vf_lavfi: remove pixel format whitelist
Pointless now.
2017-01-13 18:43:35 +01:00
wm4 43386a7c92 af_lavfi, vf_lavfi: work around recent libavfilter EOF bug
Looks quite like a bug. If you have a filter chain with only the
dynaudnorm filter, and send call av_buffersrc_add_frame(s, NULL), then
subsequent av_buffersink_get_frame() calls will return EAGAIN instead of
EOF.

This was apparently caused by a recent change in FFmpeg.

Some other circumstances (which I didn't fully analyze and which is due
to the playloop's absurd temporary-EOF behavior on seeks) then led the
decoder loop to send data again, but since libavfilter was stuck in the
EOF state now, it could never recover. It kept sending new input (due to
missing output), until the demuxer refused to return more audio packets.
Each time a filter error was printed.

Fortunately, it's pretty easy to workaround. We just mark the p->eof
flag as we send an EOF frame to libavfilter. The p->eof flag is used
only to recover from temporary EOF: it resets the filter if new data is
available again. We don't care much about av_buffersink_get_frame()
returning a broken EAGAIN state in this situation and essentially ignore
it, meaning if we get EAGAIN after sending EOF, we assume effectively
that EOF was fully reached.
2017-01-02 18:13:08 +01:00
wm4 07b6969ba4 vf_vdpaurb: remove this filter
Was deprecated, superseded by --hwdec=vdpau-copy.
2016-11-22 15:54:44 +01:00
wm4 5da510b5fc vf_vdpaurb: deprecate this filter 2016-10-20 16:45:48 +02:00
James Ross-Gowan 3751065f97 win32: build with -DINITGUID
We always want to use __declspec(selectany) to declare GUIDs, but
manually including <initguid.h> in every file that used GUIDs was
error-prone. Since all <initguid.h> does is define INITGUID and include
<guiddef.h>, we can remove all references to <initguid.h> and just
compile with -DINITGUID to get the same effect.

Also, this partially reverts 622bcb0 by re-adding libuuid.a to the
build, since apparently some GUIDs (such as GUID_NULL) are not declared
in the source file, even when INITGUID is set.
2016-09-28 21:38:52 +10:00
wm4 4fa6bcbb90 m_config: add helper function for initializing af/ao/vf/vo suboptions
Normally I'd prefer a bunch of smaller functions with fewer parameters
over a single function with a lot of parameters. But future changes will
require messing with the parameters in a slightly more complex way, so a
combined function will be needed anyway. The now-unused "global"
parameter is required for later as well.
2016-09-02 14:49:34 +02:00
wm4 af1379c43d options: make mp_vo_opts options an actual sub-option group
Just a minor refactor along the planned option change. This commit will
make it easier to update (i.e. copy) the VO options without copying
_all_ options. For now, behavior should be equivalent, though.

(The VO options were put into a separate struct quite early - when all
global variables were removed from the source code. It wasn't clear
whether the separate struct would have any actual purpose, but it seems
it will now. Awesome, huh.)
2016-08-30 23:50:57 +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 ea18cb99ba vf_vavpp: get rid of mp_refqueue_is_interlaced()
This makes the difference between passing VA_FRAME_PICTURE or
VA_BOTTOM_FIELD for progressive frames (that should be force-
deinterlaced) to VAProcPipelineParameterBuffer.flags. VA-VPP doesn't
really seem to care, and we can get rid of mp_refqueue_is_interlaced()
entirely. It could be argued it's better to pass field flags instead of
the progressive flag.
2016-07-15 20:37:46 +02:00
wm4 c5361d12d8 vf_d3d11vpp: fix interlaced-only=no mode
"Real" frame flag vs. what we pretend it to be. It always used the real
flag, and thus never deinterlaced unflagged frames, even if the
suboption was set to "no".
2016-07-15 20:21:03 +02:00
wm4 358932a109 vf_d3d11vpp: add video processor selection
Unfortunately completely useless. I still don't know how to force a
video processor to use a specific algorithm, if it's even possible.
2016-07-15 19:48:58 +02:00
wm4 6d83455a95 vd_d3d11vpp: remove nonsensical flush call
I made this call up because I sort of thought this makes senssssse. I'm
now convinced that it does not, and even is actively harmful. I'm still
quite in the dark how the DirectD 11 video API is supposed to work with
synchronization, but at least for normal graphics this call would not
make much sense.
2016-07-08 19:34:24 +02:00
wm4 5d2f1da7c5 vf, af: print filter labels in verbose mode 2016-07-06 14:13:03 +02:00
wm4 08cd50b84b vf: mark filter chain as uninitialized when mutating it
Sounds fair. Can be used to determine if the filter chain was mutated at
all, and avoiding unconditional reinit if it wasn't.
2016-07-06 13:47:58 +02:00
wm4 fc76966d9e vf: don't clobber input params on reconfigure failure
I think this is more robust, and future commits will rely on it.
2016-07-06 13:27:20 +02:00
wm4 7cd1a3c766 vf_d3d11vpp: fix output image format if not doing any filtering
For example it should be set to IMGFMT_D3D11NV12 if it isn't already.
Otherwise, an assertion in vf.c could trigger.

This probably couldn't be provoked yet.
2016-07-04 11:54:02 +02:00
Niklas Haas 923e3c7b20 vo_opengl: generalize HDR tone mapping mechanism
This involves multiple changes:

1. Brightness metadata is split into nominal peak and signal peak.

For a quick and dirty explanation: nominal peak is the brightest value
that your color space can represent (i.e. the brightness of an encoded
1.0), and signal peak is the brightest value that actually occurs in
the video (i.e. the brightest thing that's displayed).

2. vo_opengl uses a new decision logic to figure out the right nom_peak
and sig_peak for all situations. It also does a better job of picking
the right target gamut/colorspace to use for the OSD. (Which still is
and still should be treated as sRGB). This change in logic also
fixes #3293 en passant.

3. Since it was growing rapidly, the logic for auto-guessing / inferring
the right colorimetry configuration (in pass_colormanage) was split from
the logic for actually performing the adaptation (now pass_color_map).

Right now, the new logic doesn't do a whole lot since HDR metadata is
still ignored (but not for long).
2016-07-03 19:42:52 +02:00
Niklas Haas d81fb97f45 mp_image: split colorimetry metadata into its own struct
This has two reasons:

1. I tend to add new fields to this metadata, and every time I've done
so I've consistently forgotten to update all of the dozens of places in
which this colorimetry metadata might end up getting used. While most
usages don't really care about most of the metadata, sometimes the
intend was simply to “copy” the colorimetry metadata from one struct to
another. With this being inside a substruct, those lines of code can now
simply read a.color = b.color without having to care about added or
removed fields.

2. It makes the type definitions nicer for upcoming refactors.

In going through all of the usages, I also expanded a few where I felt
that omitting the “young” fields was a bug.
2016-07-03 19:42:52 +02:00
wm4 6f9973618c vf_vdpaurb: use new common nv12 download code
See previous commit. (The mixing case was never supported, so this has
equivalent functionality.)

This also implicitly fixes a bug: the old code allocated image data for
the cropped surface size only, which means the
video_surface_get_bits_y_cb_cr call could write beyond the allocated
image memory.
2016-06-21 21:44:13 +02:00
wm4 9bac0ea421 vf_vdpaurb: fix operation
The hw_subfmt field remained set, while it has to be unset for non-hwdec
formats.
2016-06-20 19:10:58 +02:00
wm4 7be37337f4 vo_opengl: vdpau interop without RGB conversion
Until now, we've always converted vdpau video surfaces to RGB, and then
mapped the resulting RGB texture. Change this so that the surface is
mapped as NV12 plane textures.

The reason this wasn't done until now is because vdpau surfaces are
mapped in an "interlaced" way as separate fields, even for progressive
video. This requires messy reinterleraving. It turns out that even
though it's an extra processing step, the result can be faster than
going through the video mixer for RGB conversion.

Other than some potential speed-gain, doing this has multiple other
advantages. We can apply our own color conversion, which is important in
more complex cases. We can correctly apply debanding and potentially
other processing that requires chroma-specific or in-YUV handling.

If deinterlacing is enabled, this switches back to the old RGB
conversion method. Until we have at least a primitive deinterlacer in
vo_opengl, this will stay this way. The d3d11 and vaapi code paths are
similar. (Of course these don't require any crazy field reinterleaving.)
2016-06-19 19:58:40 +02:00
wm4 754ad1d730 refqueue: free referenced images on free
Otherwise stale references will survive forever. Could leak hardware
video surfaces.

In particular, the mpv vdpau code crashed with an assertion when exiting
after toggling deinterlacing, because not all references were released.
2016-06-19 19:52:49 +02:00
wm4 a6074a3375 vf_d3d11vpp: flush device context only when using shared textures
Reduces interference with pass-through case, where this is not needed.
2016-06-16 17:29:53 +02:00
wm4 36f8d41702 vf_d3d11vpp: make missing deinterlacing caps non-fatal
Instead, warn.
2016-06-16 17:17:54 +02:00
wm4 1878a4655d vf_d3d11vpp: log some video processor creation parameters 2016-06-16 16:34:51 +02:00