Commit Graph

2451 Commits

Author SHA1 Message Date
wm4 479eb93d9e vo_opengl_cb: better underflow reporting
This applies to unexpected freezes or deadlocks, not e.g. normal
framedrops. The verbose messages also might remind an API user if the
API usage is incorrect, such as not calling mpv_opengl_cb_draw() when a
redraw request was issued.
2015-11-10 14:35:13 +01:00
wm4 9d9f863f55 vo_opengl: limit GLSL to version 3.3
Fixes custom shaders, which define their entrypoint as sample()
function.
2015-11-10 11:51:11 +01:00
Bin Jin 03bbaad686 vo_opengl: fix 10-bit video prescaling
The nnedi3 prescaler requires a normalized range to work properly,
but the original implementation did the range normalization after
the first step of the first pass. This could lead to severe quality
degradation when debanding is not enabled for NNEDI3.

Fix this issue by passing `tex_mul` into the shader code.

Fixes #2464
2015-11-09 22:48:40 +01:00
wm4 3dc0f2ecf0 vo_opengl_cb: make operation more similar to normal VOs
vo_opengl_cb is a special case, because we somehow have to render video
asynchronously, all while "trusting" the API user to do it correctly.
This didn't quite work, and a while ago a compromise using a timeout to
prevent theoretically possible deadlocks was added.

Make it even more synchronous. Basically, go all the way, and
synchronize rendering between VO and user renderer thread to the
full extent possible.

This means the silly frame queue is dropped, and we event attempt to
synchronize the GL SwapBuffer call (via mpv_opengl_cb_report_flip()).

The changes introduced with commit dc33eb56 are effectively dropped. I
don't even remember if they mattered.

In the future, we might make all VOs fetch asynchronously from a frame
queue, which would mostly remove the differences between vo_opengl and
vo_opengl_cb, but this will take a while (if it will even be done).
2015-11-09 20:51:57 +01:00
wm4 eeb5f98758 vo_opengl: handle GL_ARB_uniform_buffer_object with low GLSL versions
Why is this stupid crap being so much a pain for no reason.
2015-11-09 16:24:01 +01:00
wm4 caa497ee8a vo_opengl: fix extension name 2015-11-09 14:29:58 +01:00
wm4 930f841589 vo_opengl: simplify GLSL version detection
Pick the correct GLSL version from the GL_SHADING_LANGUAGE_VERSION
string. Might be somewhat questionable, as we expect the minor version
number not to have leading 0s.

Should help with cases when the reported GLSL version is much higher
than the equivalent of the reported GL version. This problem was
observed in combination with GL_ARB_uniform_buffer_object, which
can't be used if the declared GLSL version is too low.
2015-11-09 14:29:09 +01:00
wm4 11888a9270 vo_opengl: never load vaapi GLX interop by default
Causes more harm than it helps. Will eventually be removed.

Also rename the "reject_emulated" field to "probing" - this is more
appropriate now.
2015-11-09 11:58:38 +01:00
wm4 76e50f6a3d vo_opengl: always preload hwdec interop
Simplifies some auto detection matters.

I _still_ don't want to remove the lazy loading mechanism, because it's
still slightly useful for filters using the hwdec APIs. My main
motivation for not always preloading them is actually that libva prints
random useless crap to the terminal with no way to prevent this.
2015-11-09 11:57:11 +01:00
wm4 7d5282ea5d vo_opengl: rename "drm_egl" to "drm-egl" 2015-11-09 11:21:28 +01:00
rr- f757163058 vo_opengl: disable drm_egl autopickup 2015-11-09 11:19:56 +01:00
wm4 16cd20c46f win32: request MMCSS "Playback" profile 2015-11-08 19:33:38 +01:00
rr- 03013e0fd7 vo_drm: relicense to LGPL
Also removed authorship information (as per convention seen in other
files)
2015-11-08 15:00:15 +01:00
rr- 62f261a7b8 vo_drm: use bool rather than integer return values
Since the errors weren't used for anything other than simple
success/fail checks, I simplified things a bit.
2015-11-08 15:00:15 +01:00
rr- c3f2ef5491 vo_opengl: add DRM EGL backend
Notes:

- Unfortunately the only way to talk to EGL from within DRM I could find
  involves linking with GBM (generic buffer management for Mesa.)
  Because of this, I'm pretty sure it won't work with proprietary NVidia
  drivers, but then again, last time I checked NVidia didn't offer
  proper screen resolution for VT.

- VT switching doesn't seem to work at all. It's worth mentioning that
  using vo_drm before introduction of VT switcher had an anomaly where
  user could switch to another VT and input text to it, while video
  played on top of that VT. However, that isn't the case with drm_egl:
  I can't switch to other VT during playback like this. This makes me
  think that it's either a limitation coming from my firmware or from
  EGL/KMS itself rather than a bug with my code. Nonetheless, I still
  left (untestable) VT switching code in place, in case it's useful to
  someone else.

- The mode_id, connector_id and device_path should be configurable for
  power users and people who wish to watch videos on nonprimary screen.
  Unfortunately I didn't see anything that would allow OpenGL backends
  to register their own set of options. At the same time, adding them to
  global namespace is pointless.

- A few dozens of lines could be shared with vo_drm (setting up VT
  switching, most of code behind page flipping). I don't have any strong
  opinion on this.

- Sometimes I get minor visual glitches. I'm not sure if there's a race
  condition of some sort, unitialized variable (doubtful), or if it's
  buggy driver. (I'm using integrated Intel HD Graphics 4400 with Mesa)

- .config and .control are very minimal.

Signed-off-by: wm4 <wm4@nowhere>
2015-11-08 15:00:15 +01:00
rr- 67caea357c vo_drm: move initialization to drm_common
Makes KMS initialization procedures reusable so that they can be used by
the upcoming DRM EGL adapter.
2015-11-08 14:58:34 +01:00
rr- b1893d2084 vo_opengl: fix typo 2015-11-07 19:46:51 +01:00
wm4 46cee66563 vo_opengl: rename fancy-downscaling to correct-downscaling
The old name was stupid. Very stupid.
2015-11-07 17:49:14 +01:00
Avi Halachmi (:avih) 0062c98dff vo_opengl: fancy-downscaling: enable also for anamorphic clips 2015-11-07 17:44:50 +01:00
wm4 6bbb1e4cf9 x11: print Xlib errors in verbose mode if Xlib messages are silenced
Follow up to commit b984ec52.
2015-11-07 17:43:10 +01:00
wm4 b984ec52aa vo_opengl: x11: silence error messages when using legacy GL context
glXCreateContextAttribsARB() by design can throw some X11 errors. We
ignore these, but we generally still print error messages to the
terminal. This was confusing/annoying users, so silence it. The stupid
part is that the Xlib error handler is global, so we have to be slightly
careful here.
2015-11-06 21:20:23 +01:00
wm4 9693e0f57a Remove some VLAs
They are evil and should be eradicated. Some of these were pretty dumb
anyway.

There are probably some more around in platform specific code or other
code not enabled by default on Linux.
2015-11-06 21:12:20 +01:00
James Ross-Gowan 647b360a0a w32: use DisplayConfig API to retrieve correct monitor refresh rate
This is based on an older patch by James Ross-Gowan. It was rebased and
cleaned up. Also, the DWM API usage present in the older patch was
removed, because DWM reports nonsense rates at least on Windows 8.1
(they are rounded to integers, just like with the old GDI API - except
the GDI API had a good excuse, as it could report only integers).

Signed-off-by: wm4 <wm4@nowhere>
2015-11-06 19:53:18 +01:00
James Ross-Gowan 68ac45e487 w32: always get screenrc from an HMONITOR
This simplifies update_screen_rect a bit. Unless --fs-screen=all is
used, it will always get an HMONITOR and call GetMonitorInfo to
determine its dimensions. This will make it easier for the next few
commits to determine the colour profile and the refresh rate from the
HMONITOR.

There is a slight change in behaviour. When selecting a screen that is
out of range, such as --screen=9 on a machine with only two monitors,
the old code would silently select the last existing monitor. The new
code prints an error message and falls back to the default screen (same
as the Cocoa code.)

Signed-off-by: wm4 <wm4@nowhere>
2015-11-06 19:53:18 +01:00
James Ross-Gowan 9e10cd9fa1 w32: remove Win95 and NT4 monitor code
The call to EnumDisplaySettings seems to be a relic from when MPlayer
ran on systems that didn't have GetMonitorInfo or SM_CX/CYVIRTUALSCREEN.
GetMonitorInfo was loaded dynamically, so it was possible for MPlayer to
run without it and use the values returned by EnumDisplaySettings.

These are always present in modern versions of Windows, so the values
returned from EnumDisplaySettings are always overwritten. Remove the
call to EnumDisplaySettings and assume SM_CX/CYVIRTUALSCREEN is always
present.

Signed-off-by: wm4 <wm4@nowhere>
2015-11-06 19:53:18 +01:00
wm4 b2a3e877c0 video: increase avi pts buffer size
When decoding on RPI/MMAL, the buffering between decoder input and
output can be quite excessive.
2015-11-06 17:06:32 +01:00
wm4 5f89ba707d vo_opengl: simplify function loader slightly
We don't use any functions that have been deprecated in any later GL or
GLES functions. (This is a leftover of vo_opengl_old support.)
2015-11-06 14:01:01 +01:00
wm4 cfa4952f7c vo_opengl: glBindBufferBase is not part of GL 2.1/GLES 2.0
Commit 27dc834f added it as such.

Also remove the check for glUniformBlockBinding() - it's part of an
extension, and the check glGetUniformBlockIndex() already checks whether
the extension is fully available.
2015-11-06 13:59:33 +01:00
Bin Jin 27dc834f37 vo_opengl: implement NNEDI3 prescaler
Implement NNEDI3, a neural network based deinterlacer.

The shader is reimplemented in GLSL and supports both 8x4 and 8x6
sampling window now. This allows the shader to be licensed
under LGPL2.1 so that it can be used in mpv.

The current implementation supports uploading the NN weights (up to
51kb with placebo setting) in two different way, via uniform buffer
object or hard coding into shader source. UBO requires OpenGL 3.1,
which only guarantee 16kb per block. But I find that 64kb seems to be
a default setting for recent card/driver (which nnedi3 is targeting),
so I think we're fine here (with default nnedi3 setting the size of
weights is 9kb). Hard-coding into shader requires OpenGL 3.3, for the
"intBitsToFloat()" built-in function. This is necessary to precisely
represent these weights in GLSL. I tried several human readable
floating point number format (with really high precision as for
single precision float), but for some reason they are not working
nicely, bad pixels (with NaN value) could be produced with some
weights set.

We could also add support to upload these weights with texture, just
for compatibility reason (etc. upscaling a still image with a low end
graphics card). But as I tested, it's rather slow even with 1D
texture (we probably had to use 2D texture due to dimension size
limitation). Since there is always better choice to do NNEDI3
upscaling for still image (vapoursynth plugin), it's not implemented
in this commit. If this turns out to be a popular demand from the
user, it should be easy to add it later.

For those who wants to optimize the performance a bit further, the
bottleneck seems to be:
1. overhead to upload and access these weights, (in particular,
   the shader code will be regenerated for each frame, it's on CPU
   though).
2. "dot()" performance in the main loop.
3. "exp()" performance in the main loop, there are various fast
   implementation with some bit tricks (probably with the help of the
   intBitsToFloat function).

The code is tested with nvidia card and driver (355.11), on Linux.

Closes #2230
2015-11-05 17:38:20 +01:00
Bin Jin 4c43c30421 vo_opengl: add Super-xBR filter for upscaling
Add the Super-xBR filter for image doubling, and the prescaling framework
to support it.

The shader code was ported from MPDN extensions project, with
modification to process luma only.

This commit is largely inspired by code from #2266, with
`gl_transform_trans()` authored by @haasn taken directly.
2015-11-05 17:38:20 +01:00
Bin Jin 7438f208c3 vo_opengl: make image size dynamic during rendering
This commit marks the image size variables temporary, and renames them
in order to prevent any potential confusion in the future.
2015-11-05 17:38:20 +01:00
wm4 2cf9ee989c rpi: add support for codecs other than h264
FFmpeg now supports h264 and mpeg2. At least vc-1 will probably follow.
2015-11-05 17:24:35 +01:00
wm4 66ed50aa00 vo_vdpau: check VDP_RGBA_FORMAT_A8 support
Apparently not all vdpau drivers in the wild support this format (VDPAU
SUNXI can't). Revert to RGB in these cases.
2015-11-04 21:49:54 +01:00
wm4 f00edfd9c5 vo_opengl_cb: log some events
The noframe event is logged whenever there is no new frame. This can
happen due to normal redraws, but also due to video frame queue
underflow.

The mpv_opengl_cb_report_flip() API function is currently pretty
useless, because blocking on the video frame queue is more reliable and
simpler. But at least we can log the actual vsync.
2015-11-04 21:49:54 +01:00
wm4 e6a395c297 vo_opengl, vo_opengl_cb: drop unneeded vo_frame fields
next_vsync/prev_vsync was only used to retrieve the vsync duration. We
can get this in a simpler way.

This also removes the vsync duration estimation from vo_opengl_cb.c,
which is probably worthless anyway. (And once interpolation is made
display-sync only, this won't matter at all.)
2015-11-04 21:49:54 +01:00
wm4 e187de7eed vo: do not go to sleep if there's a new frame queued
This affects only the display-sync code path, as for normal timing the
wakeup_pts stuff handles proper wakeup. It's probably mostly a
theoretical issue.
2015-11-03 20:47:15 +01:00
wm4 163c6ad862 vd_lavc: make hwdec fallback more tolerant
A hw decoder might fail to decode a frame for multiple reasons, and not
always just because decoding is impossible. We can't generally
distinguish these reasons well. Make it more tolerant by accepting
failures of 3 frames, but not more. The threshold can be adjusted by the
repurposed --vd-lavc-software-fallback option.

(This behavior was suggested much earlier in some PR, but at the time
the "proper" hwdec fallback was indistinguishable from decoding error.
With the current situation, "proper" fallback is still instantious.)
2015-11-03 14:03:02 +01:00
wm4 4058b418bf vo: fix display-sync frame drop accounting again
Commit acd5816a fixed this, except when vo_opengl interpolation was
active. (And again, the old interpolation code path should be removed.)
2015-11-03 13:33:38 +01:00
wm4 1d2d649281 vdpau: fix uninit when init fails
The uninit() function was called twice if the uninit() function failed
(once by init(), once by vd_lavc.c code), which caused crashes due to
double-free. (This failure is a corner case, and all other hwdec
backends appear to handle this case gracefully.)

I do not think this code should be able to deal with uninit() being
called other than once. Guarantee that it's called exactly once.
2015-11-01 23:03:02 +01:00
wm4 8e8b420c9d vo_opengl: win32: fix cross-compilation
MXE uses an all-lowercase convention for MS headers.
2015-11-01 21:50:41 +01:00
wm4 9de8730dc9 vo_opengl: win32: always request MMCSS for DWM
Quoting MSDN: "Notifies the Desktop Window Manager (DWM) to opt in to or
out of Multimedia Class Schedule Service (MMCSS) scheduling while the
calling process is alive.". Whatever this means. (An application can
change the scheduling priority of the window manager?)

Does this improve anything? I have no idea. Certainly this is a program
that does multimedia and graphics, so we seem to be a good match for
this.

Is it bad if we enable this even while playback is inactive or paused? I
have no idea either.

Is there a magic cargo cult function that will mark our renderer thread
as multimedia thing? I have no idea. (We use a function to enable MMCSS
for our audio thread in ao_wasapi.)
2015-11-01 20:50:41 +01:00
wm4 30a6106477 vo_opengl: win32: try to enable DwmFlush by default
Enable it by default, but not unconditionally. Add an "auto" mode, which
disable DwmFlush if the compositor is (probably) inactive. Let's see how
this goes.

Since I accidentally enabled DwmFlush always by default (more or less)
in a previous commit touching this code, this is probably mostly just
cargo-culting, and it's uncertain whether it does anything.

Note that I still got bad vsync behavior when fullscreening mpv, and
making another window visible on the same screen. This happens even if
forcing DWM.
2015-11-01 20:47:57 +01:00
wm4 8581835161 vo: fix no-audio mode with interpolation enabled/display-sync disabled
Commit acd5816a broke this. It was stopping playback occasionally.
Another case where the non-display-sync interpolation mode
(in->vsync_timed==true) is causing a lot of subtle issues and will be
removed soon.
2015-11-01 14:19:22 +01:00
wm4 cdeb0e4c72 video: fix playback of pal8
PAL8 is the only format that is RGB, has only 1 component, is byte-
aligned. It was accidentally detected by the GBRP case as planar RGB.
(It would have been ok if it were gray; what ruins it is that it's
actually paletted, and the color values do not correspond to colors (but
palette entries).

Pseudo-pal formats are ok; in fact AV_PIX_FMT_GRAY is rightfully marked
as MP_IMGFLAG_YUV_P.
2015-11-01 14:11:43 +01:00
wm4 b92fd602ce vo_direct3d: fix operation
Regression since commit 93db4233. I think the bit that was forgotten
here was to remove the vo_w32_config() return value completely. The VO
failed to init because that function always returned 0. This commit
removes these bits and fixes the VO.

Fixes #2434.
2015-10-31 12:52:02 +01:00
wm4 2b6241a09a vo_opengl: add vsync-fences option
Yet another relatively useless option that tries to make OpenGL's sync
behavior somewhat sane. The results are not too encouraging. With a
value of 1, vsync jitter is gone on nVidia, but there are frame drops
(less than with glfinish). With 2, I get the usual vsync jitter _and_
frame drops.

There's still some hope that it might prevent too deep queuing with some
GPUs, I guess.

The timeout for the wait call is 1 second. The value is pretty
arbitrary; it should just not be too high to freeze the process (if
the GPU is un-nice), and not too low to trigger the timeout in normal
cases, even if the GPU load is very high. So I guess 1 second is ok
as a timeout.

The idea to use fences this way to control the queue depth was stolen
from RetroArch:

df01279cf3/gfx/drivers/gl.c (L1856)
2015-10-30 20:26:51 +01:00
wm4 93f748e77f vo_opengl: cosmetics: flip the order of 2 functions
draw_frame() is called first, then flip_page(). Order them in the order
they're called.
2015-10-30 20:26:43 +01:00
rr- 7c6d7017bd vo_drm: uninstall signal handlers after quitting 2015-10-30 20:26:37 +01:00
rr- 344b65c4db vo_drm: handle possible errors from sigaction 2015-10-30 20:26:37 +01:00
rr- 03cf69f0a8 vo_drm: check if signal already used 2015-10-30 20:26:37 +01:00