Commit Graph

1455 Commits

Author SHA1 Message Date
wm4 68ff8a0484 Move compat/ and bstr/ directory contents somewhere else
bstr.c doesn't really deserve its own directory, and compat had just
a few files, most of which may as well be in osdep. There isn't really
any justification for these extra directories, so get rid of them.

The compat/libav.h was empty - just delete it. We changed our approach
to API compatibility, and will likely not need it anymore.
2014-08-29 12:31:52 +02:00
wm4 a95cfac078 vo_opengl: don't pass (char*)NULL as %s printf argument
glGetString(GL_SHADING_LANGUAGE_VERSION) can return NULL; I suppose this
happens on legacy OpenGL, while all the other fields are guaranteed to
exist.
2014-08-28 01:52:15 +02:00
wm4 2c99464b47 vo_opengl: fix shader
Regression since commit f14722a4. For some reason, this worked on
nvidia, but rightfully failed on mesa.

At least in C, the ## operator indeed needs two macro arguments, and
you can't just concatenate with non-arguments.

This change will most likely fix it.

CC: @bjin
2014-08-28 00:40:37 +02:00
Bin Jin 08b5dccd12 vo_opengl: add parameter to gaussian filter
Add a new parameter 'p' to gaussian filter. The new formula used
 a different base taken from fmtconv plugin, so that the
 new parameter is exactly same as the one used in Avisynth and
 Vapoursynth.

 The new default value is 2 / log(2) * 10, with the default value it
 conforms to the original kernel taken from vector-agg.
2014-08-26 22:19:32 +02:00
Bin Jin b3e788d3f4 vo_opengl: add radius options for filters
Add two new options, make it possible for user to set the radius
for some of the filters with no fixed radius.

Also add three new filters with the new radius parameter supported.
2014-08-26 22:19:30 +02:00
Bin Jin f14722a40f vo_opengl: add cparam1 and cparam2 options
Although cscale is rarely used, it's possible that params of cscale
are accidentally set to lparam1 and lparam2, which might cause
unexpected results.
2014-08-26 22:19:27 +02:00
Bin Jin a8b67c66f2 vo_opengl: add spline64 filter kernel
The coefficients are taken from fmtconv plugin for vapoursynth:
https://github.com/vapoursynth/fmtconv/blob/master/src/fmtc/ContFirSpline64.cpp

The package is licensed under WTFPL, and it's from the same author
of Dither plugin for avisynth.
2014-08-26 22:18:55 +02:00
wm4 f7eea070f0 vo_opengl: don't cut off feature list output 2014-08-25 00:48:55 +02:00
wm4 1cedb323ad video: avoid unnecessary frame dropping
If duration<0, it means the duration is unknown. Disable framedropping,
because end_time makes no sense in this case.

Also, strictly never drop the first frame.

This fixes weird behavior with the cover-art case (for the 100th time).
2014-08-23 12:48:45 +02:00
wm4 d5fa5a96a8 video: some debugging output 2014-08-22 16:21:58 +02:00
Bin Jin 1e12afa80a vf_vapoursynth: add more VS frame properties
Add the missing frame properties in 48587e88.
2014-08-22 14:22:06 +02:00
Bin Jin 96c2021cb1 vf_vapoursynth: add display resolution support
Add two new script environment variables 'video_in_dw' and
'video_in_dh', representing the display resolution of video. Along
with video resolution, sample ratio aspect can be calculated in
scripts.

Currently it's impossible to change sample ratio aspect with single
vapoursynth filter since '_SARNum' and '_SARDen' frame properties
from output clip will be ignored. A following 'dsize' filter is
necessary for this purpose.
2014-08-22 14:22:04 +02:00
wm4 f1e78306cb vaapi: try dealing with Intel's braindamaged shit drivers
So talking to a certain Intel dev, it sounded like modern VA-API drivers
are reasonable thread-safe. But apparently that is not the case. Not at
all. So add approximate locking around all vaapi API calls.

The problem appeared once we moved decoding and display to different
threads. That means the "vaapi-copy" mode was unaffected, but decoding
with vo_vaapi or vo_opengl lead to random crashes.

Untested on real Intel hardware. With the vdpau emulation, it seems to
work fine - but actually it worked fine even before this commit, because
vdpau was written and designed not by morons, but competent people
(vdpau is guaranteed to be fully thread-safe).

There is some probability that this commit doesn't fix things entirely.
One problem is that locking might not be complete. For one, libavcodec
_also_ accesses vaapi, so we have to rely on our own guesses how and
when lavc uses vaapi (since we disable multithreading when doing hw
decoding, our guess should be relatively good, but it's still a lavc
implementation detail). One other reason that this commit might not
help is Intel's amazing potential to fuckup anything that is good and
holy.
2014-08-21 22:45:58 +02:00
wm4 7758c15e95 video: don't assume query_format is thread-safe
Although it's probably safe for most VOs, there's no guarantee.
2014-08-20 21:35:45 +02:00
Alexander Preisinger 614ff883bc wayland: replace deprecated xkbcommon functions
Available and stable since forever (xkbcommon 0.2).
2014-08-20 17:16:18 +02:00
Alexander Preisinger 759fdcb2f9 vo_wayland: fix formatting inconsistencies 2014-08-20 16:40:33 +02:00
Alexander Preisinger 3bf83f7642 vo_wayand: save the flip time in the frame handler
This value is more accurate than the default value.
2014-08-20 16:35:06 +02:00
wm4 3d968fc620 video: add VOCTRL_GET_RECENT_FLIP_TIME
This could be used by VO implementations to report a recent vsync time
to the generic VO code, which in turn will use it and the display FPS
to estimate at which point in time the next vsync will happen.
2014-08-18 23:04:31 +02:00
wm4 cd2e4db8a5 vo_opengl: add check-pattern suboption for testing
This uses glXGetVideoSyncSGI() to check how many vsyncs happened since
the last flip_page() call. It allows checking a pattern of vsync
increments of at most 2 elements. For example, to check ~24 fps playback
on a ~60 Hz monitor, this can be used:

--vo=opengl:check-pattern=[3-2]:waitvsync

Whether the reported results are accurate or just plain wrong may depend
on the driver and if the waitvsync sub-option is used. There are no
guarantees.

This option is undocumented, and may be removed again in the near or
distant future.
2014-08-18 23:04:31 +02:00
wm4 aaadcef52f video: dump vsync phase into stats file
For debugging (drawing fun plots with TOOLS/stats-conv.py).

Also move last_flip under the correct comment: it's not protected by the
lock, and can be accessed by the VO thread only.
2014-08-18 23:04:28 +02:00
wm4 7520d39e8b vaapi: we need more surfaces
Playing with high framedrop could make it run out of surfaces. In
theory, we wouldn't need an additional surface, if we could just clear
the vo_vaapi internal surface - but doing so would probably be a pain,
so I don't care.
2014-08-18 22:59:01 +02:00
Alexander Preisinger 752dce9284 wayland: dynamically report display fps
Only reports the most recently entered output if the window is displayed on
2 or more outputs. Should be changed to the lowest fps of all outputs the
window is visible. Until no one complains this will have to wait.

Look for the VO framedropping for more information on this topic.
2014-08-18 22:00:39 +02:00
wm4 1e04c474ab x11: listen to xrandr events
If the Xrandr configuration changes, re-read it. So if you change
display modes or screen configuration, it will update the framedrop
refresh rate accordingly.

This passes the rootwin to XRRSelectInput(), which may or may not be
allowed. But it works, and the documentation (which is worse than used
toilet paper, great job Xorg) doesn't forbid it, or in fact say anything
about what the window parameter is even used for.
2014-08-17 15:39:18 +02:00
wm4 3778e63330 x11: fix xrandr conditional compilation
Oops.

Fixes #1020.
2014-08-17 04:35:24 +02:00
wm4 513779d3b8 video: make vo_opengl the default over vo_vdpau
Nvidia's vdpau implementation is pretty good, but other factors make it
much less attractive for use as default VO. For example, Mesa often has
low quality drivers (mess up things with the presentation queue and the
vdpau API time source). Intel ruins things completely, and we're likely
to run on emulation via OpenGL. Compositing has unknown effects (to me
anyway), but appears to reduce the vdpau advantages.

One important reason to prefer vo_vdpau was that it could do proper
framedropping. Framedropping got fixed for the other VOs, so this reason
is going away.
2014-08-17 02:54:50 +02:00
wm4 5b64f5ad35 video: take refresh rate changes into account
This works only on X11, and only if the refresh rate changes due to the
window being moved to another screen (detected by us). It doesn't
include system screen reconfiguration yet.

This calls VOCTRL_GET_DISPLAY_FPS on every frame, which makes me uneasy.
It means extra thread communication with the win32 and Cocoa backends.
On the other hand, a frame doesn't happen _that_ often, and the
communication should still be pretty cheap and fast, so it's probably
ok.

Also needs some extra fuzz for vo_vdpau.c, because that does everything
differently.
2014-08-17 02:50:59 +02:00
wm4 4822056db7 x11: fix memory leaks
Oh, we have to free this stuff. OK.
2014-08-17 02:47:44 +02:00
wm4 f8f3a1b4a1 build: drop check for XF86keysym.h
This is always included in the Xorg development headers. Strictly
speaking it's not necessarily available with other X implementations,
but these are hopefully all dead.
2014-08-16 21:57:51 +02:00
wm4 fe782a6e95 x11: use xrandr to retrieve display refresh rate
Drop use of the ancient XF86VM, and use the slightly less ancient Xrandr
extension to retrieve the refresh rate. Xrandr has the advantage that it
supports multiple monitors (at least the modern version of it).

For now, we don't attempt any dynamic reconfiguration. We don't request
and listen to Xrandr events, and we don't notify the VO code of changes
in the refresh rate. (The later works by assuming that X coordinates map
directly to Xrandr coordinates, which probably is wrong with compositing
window manager, at least if these use complicated transformations. But I
know of no API to handle this.)

It would be nice to drop use of the Xinerama extension too, but
unfortunately, at least one EWMH feature uses Xinerama screen numbers,
and I don't know how that maps to Xrandr outputs.
2014-08-16 21:56:22 +02:00
wm4 a4cfab7ee0 vo_wayland: fix redrawing logic
I must have broken it some time ago. The error case dealing with an
unavailable backbuffer was broken, and didn't handle memory management
correctly.
2014-08-16 17:09:59 +02:00
wm4 4f984b987c video: add --display-fps switch to control framedrop FPS
Since the display FPS is currently detected on X11 only (and even there
it's known to be wrong on certain setups), it seems like a good idea to
make this user-configurable.
2014-08-16 00:05:02 +02:00
wm4 72ee9bb56c vo_opengl: optional support for using GLX_SGI_video_sync
I'm not sure about the merit, though it does print nice numbers if debug
output is enabled.

Basically, this tries to achieve similar results as the glFinish()
business, but again it entirely depends on the drivers whether this
does anything meaningful, or whether it's actively harmful.
2014-08-15 23:36:13 +02:00
wm4 db65151890 gl_common: add SGI_video_sync extension 2014-08-15 23:36:10 +02:00
wm4 4a297554bc vo_opengl: if glfinish is used, also call it after swappping
It seems that at least on nvidia systems with composting disabled, we
can get it to block deterministically on the actual vsync event, which
should improve framedropping.
2014-08-15 23:36:02 +02:00
wm4 543ba6c114 video: add VO framedropping mode
This mostly uses the same idea as with vo_vdpau.c, but much simplified.

On X11, it tries to get the display framerate with XF86VM, and limits
the frequency of new video frames against it. Note that this is an old
extension, and is confirmed not to work correctly with multi-monitor
setups. But we're using it because it was already around (it is also
used by vo_vdpau).

This attempts to predict the next vsync event by using the time of the
last frame and the display FPS. Even if that goes completely wrong,
the results are still relatively good.

On other systems, or if the X11 code doesn't return a display FPS, a
framerate of 1000 is assumed. This is infinite for all practical
purposes, and means that only frames which are definitely too late are
dropped. This probably has worse results, but is still useful.

"--framedrop=yes" is basically replaced with "--framedrop=decoder". The
old framedropping mode is kept around, and should perhaps be improved.
Dropping on the decoder level is still useful if decoding itself is too
slow.
2014-08-15 23:33:33 +02:00
wm4 22a9529012 vo: eliminate a redundant variable
Originally, I probably had plans to allow NULL images to handle things
like the last frame case, but that idea was dropped later.
2014-08-15 23:32:45 +02:00
wm4 51a7070e26 vo: remove unused libavutil include 2014-08-14 19:29:02 +02:00
wm4 de399278fc vo: fix mingw compilation 2014-08-14 01:30:20 +02:00
Alexander Preisinger 69a160f187 wayland: pointer interface is created after theme
Just always load the theme. It gets freed properly and dosn't bother anyone.

Fixes #1012.

CC: @mpv-player/stable
2014-08-13 22:34:18 +02:00
Alessandro Ghedini 2607d6e419 vdpau: correctly mark invalid mixer as such on vdp_video_mixer_create() failure
Otherwise vdp_video_mixer_destroy() would later fail when called on an invalid
video mixer handle. With mesa r600 vdpau driver, this would cause a segfault.
2014-08-13 17:57:19 +02:00
wm4 9ed9c68fda vo_vdpau: fix screenshots with anamorphic video
Fixes #1007.

CC: @mpv-player/stable
2014-08-13 00:52:05 +02:00
wm4 f6f93b6336 x11: vdpau GLX interop needs X11 threads
Xlib is not thread-safe. Or actually it is, but it's an incomprehensible
hack that was added later, and which needs to be acitvated manually
(this makes no sense). And it appears that the vdpau accesses X from the
decoder thread if GLX interop is used (and not in any other situations -
this doesn't make too much sense either).

So, just call the magic function that enables Xlib thread-safety.
2014-08-13 00:26:13 +02:00
wm4 5ed7bc6321 video: fix and simplify video format changes and last frame display
The previous commit broke these things, and fixing them is separate in
this commit in order to reduce the volume of changes.

Move the image queue from the VO to the playback core. The image queue
is a remnant of the old way how vdpau was implemented, and increasingly
became more and more an artifact. In the end, it did only one thing:
computing the duration of the current frame. This was done by taking the
PTS difference between the current and the future frame. We keep this,
but by moving it out of the VO, we don't have to special-case format
changes anymore. This simplifies the code a lot.

Since we need the queue to compute the duration only, a queue size
larger than 2 makes no sense, and we can hardcode that.

Also change how the last frame is handled. The last frame is a bit of a
problem, because video timing works by showing one frame after another,
which makes it a special case. Make the VO provide a function to notify
us when the frame is done, instead. The frame duration is used for that.

This is not perfect. For example, changing playback speed during the
last frame doesn't update the end time. Pausing will not stop the clock
that times the last frame. But I don't think this matters for such a
corner case.
2014-08-12 23:24:08 +02:00
wm4 df58e82237 video: move display and timing to a separate thread
The VO is run inside its own thread. It also does most of video timing.
The playloop hands the image data and a realtime timestamp to the VO,
and the VO does the rest.

In particular, this allows the playloop to do other things, instead of
blocking for video redraw. But if anything accesses the VO during video
timing, it will block.

This also fixes vo_sdl.c event handling; but that is only a side-effect,
since reimplementing the broken way would require more effort.

Also drop --softsleep. In theory, this option helps if the kernel's
sleeping mechanism is too inaccurate for video timing. In practice, I
haven't ever encountered a situation where it helps, and it just burns
CPU cycles. On the other hand it's probably actively harmful, because
it prevents the libavcodec decoder threads from doing real work.

Side note:

Originally, I intended that multiple frames can be queued to the VO. But
this is not done, due to problems with OSD and other certain features.
OSD in particular is simply designed in a way that it can be neither
timed nor copied, so you do have to render it into the video frame
before you can draw the next frame. (Subtitles have no such restriction.
sd_lavc was even updated to fix this.) It seems the right solution to
queuing multiple VO frames is rendering on VO-backed framebuffers, like
vo_vdpau.c does. This requires VO driver support, and is out of scope
of this commit.

As consequence, the VO has a queue size of 1. The existing video queue
is just needed to compute frame duration, and will be moved out in the
next commit.
2014-08-12 23:24:08 +02:00
wm4 b8f025a58a video: don't keep multiple pointers to hwdec info struct
This makes a certain corner case simpler at a later point.
2014-08-11 23:09:39 +02:00
wm4 056622c33e vaapi: fix uninitialized value read
Found with valgrind. This is somewhat terrifying, because the VA-API API
function is supposed to fill these values, and we access them only if
the API functions return success. So this shouldn't have happened.
2014-08-11 21:57:41 +02:00
wm4 beceb2fedc vf_vapoursynth: print more diagnostics on error 2014-08-11 21:57:15 +02:00
wm4 33a8e2a9ad vdpau: allocate surfaces by age
Whether this helps is probably questionable and depends on the GPU. But
the vaapi code does it too.
2014-08-11 14:03:53 +02:00
wm4 f5257e2c7d vo_sdl: fix redrawing issue
vo_sdl.c has broken event handling and just polls. The polling time was
quite low, so the playloop OSD redrawing heuristic inhibited redraws,
which made the window appear frozen when paused.
2014-08-10 13:24:29 +02:00
wm4 8dfe0c73c9 video: remove "hard" framedrop mode
Completely useless, and could accidentally be enabled by cycling
framedrop modes. Just get rid of it.

But still allow triggering the old code with --vd-lavc-framedrop, in
case someone asks for it. If nobody does, this new option will be
removed eventually.
2014-08-09 00:35:35 +02:00
wm4 19fd67096b vo_direct3d: allow resizing before video init
This can just happen in the time between VO creation, and the first call
to vo_reconfig. It seems the recent threading changes exposed this bug.

Fixes #986.
2014-08-06 20:30:47 +02:00
wm4 77ad49411a win32: never call GetClientRect(0, ...)
Sometimes GetClientRect() appeared to fail during init, and since we
don't check GetClientRect() calls (because they're on our own window,
and logically can never fail), bogus resizes were triggered. This could
cause vo_direct3d to fail initialization.

The reason was that w32->window was set to 0 during early window
initialization: CreateWindow*() can send messages to the new window,
even though it hasn't returned yet. This means w32->window is not yet
set to our window handle, and functions in WndProc may accidentally pass
hwnd=0 to win32 API functions.

Fix it by initializing w32->window on opportunity. This also means we
always strictly expect that the WndProc is used with our own window
only.
2014-08-06 20:30:47 +02:00
Alexander Preisinger 6ec39b4641 wayland: remove redundant line 2014-08-06 12:58:39 +02:00
Alexander Preisinger f175f2c38f wayland: changes for nested compositors
Adds necessary checks for nested compositors which only have limited
interfaces. Might also be useful for other minimal compositors.
2014-08-06 12:55:51 +02:00
FRAU KOUJIRO b8a431c892 cocoa: macosx_application needs cocoa-application 2014-08-06 09:31:59 +02:00
FRAU KOUJIRO 0be25a8dbf cocoa: move handleFilesArray: to macosx_events 2014-08-06 09:31:58 +02:00
wm4 ff6c387a73 win32: fix build 2014-08-05 23:43:40 +02:00
wm4 210c83ab31 win32: create OpenGL context on the GUI thread
This fixes the fullscreen issues on Intel for me. I'm baffled by it and
don't understand why this suddenly works. Intel drivers being shit?
Windows being shit? HWND or HDC being only 97% thread-safe instead of
98%? Me missing something subtle that is not documented anywhere?

Who knows.

Now instead of creating the HDC and OpenGL context on the renderer
thread, they're created on the GUI thread. The renderer thread will
then only call wglMakeCurrent, SwapBuffers, and OpenGL standard
functions.

Probably fixes github issue #968.
2014-08-05 20:02:23 +02:00
wm4 afcbee8305 win32: cleanup OpenGL context creation
Might handle some corner cases better. In particular, always call
wglMakeCurrent() with non-NULL HDC argument.
2014-08-05 19:59:32 +02:00
wm4 d634f7b01a vdpau: don't crash on flipped images
It seems the vdpau API does not support these.

Do a semi-expensive emulation of it. On the other hand, it's not like
this is a commonly-used feature. (It might be better to make --vf=flip
always copy instead of flipping it via pointer tricks - but everything
allows flipped images, and even decoders or libavfilter filters could
output them.)
2014-08-05 00:18:57 +02:00
Michael Forney 618361c697 gl_wayland: Don't try to resize the egl_window before it exists
If the compositor sends a configure event immediately after a window is
created (for example, if it implements tiling window management), mpv
will attempt to call wl_egl_window_resize before it has actually created
the egl_window, causing a crash.
2014-08-04 09:50:24 +02:00
wm4 d68a759fa4 Improve setting AVOptions
Use OPT_KEYVALUELIST() for all places where AVOptions are directly set
from mpv command line options. This allows escaping values, better
diagnostics (also no more "pal"), and somehow reduces code size.

Remove the old crappy option parser (av_opts.c).
2014-08-02 03:12:33 +02:00
wm4 aa46968ed0 win32: fix assertion failure
If OpenGL 3.x doesn't work, the fallback to legacy GL will call the
function to create the DC again, and it will assert. Just make it not
to, and also simplify the code a bit.

Fixes #974.
2014-08-01 23:03:52 +02:00
Stefano Pigozzi 6aac17cebb vda: only support the new hwaccel 1.2 API (remove old code)
Since the new hwaccel API is now merged in ffmpeg's stable release, we can
finally remove support for the old API.

I pretty much kept lu_zero's new code unchanged and just added some error
printing (that we had with the old glue code) to make the life of our users
less miserable.
2014-08-01 10:38:18 +02:00
wm4 f8ab732ac3 video/filter: add vf_buffer
Mostly useful for debugging.
2014-07-30 23:29:00 +02:00
wm4 fa34b4920a vdpau: don't upload video images in advance
With software decoding, images were uploaded to vdpau surfaces as they
were queued to the VO. This makes it slightly more complicated
(especially later on), and has no advantages - so stop doing it.

The only reason why this was done explicitly was due to attempts to keep
the code equivalent (instead of risking performance regressions). The
original code did this naturally for certain reasons, but now that we
can measure that it has no advantages and just requires extra code, we
can just drop it.
2014-07-29 00:21:02 +02:00
wm4 26bfcc9c82 vo_x11: fix build with older Libav versions
Why does this happen everytime...
2014-07-28 21:48:43 +02:00
Niklas Haas d0a8b571c9 video: add a default color space for files with no video
Usually mp_image_params_guess_csp takes care of finding *some* default
for a video channel, but files with no video (or with extremely broken
configurations) end up leaving the colorspace information as
MP_CSP_PRIM_AUTO, which has no associated primaries.

As a result of this, color managed OSD messages could not display
because they were being color managed to match the (non-existing/absurd)
video channel. With this change, such non-spaces will have BT.709
primaries as far as color management and the OSD is concerned.

This fixes #961.

CC: @mpv-player/stable

Signed-off-by: wm4 <wm4@nowhere>
2014-07-28 21:24:44 +02:00
wm4 4c533fbb16 vo: remove vo_mouse_movement() wrapper
So that VO backends don't have to access the VO just for that.
2014-07-27 21:53:29 +02:00
wm4 89391e7c94 vo: different hack for VOs which need to mangle mouse input
Follow up on commit 760548da. Mouse handling is a bit confusing, because
there are at least 3 coordinate systems associated with it, and it
should be cleaned up. But that is hard, so just apply a hack which gets
the currently-annoying issue (VO backends needing access to the VO) out
of the way.
2014-07-27 21:33:11 +02:00
wm4 025431a7ae win32: remove minor non-sense
This is done in the wrong thread. Was harmless and had no effect at all.
2014-07-26 23:19:43 +02:00
wm4 97a82bcd56 win32: move window handling to a separate thread
The windows message loop now runs in a separate thread. Rendering,
such as with Direct3D or OpenGL, still happens in the main thread.

In particular, this should prevent the video from freezing if the
window is dragged. (The reason was that the message dispatcher won't
return while the dragging is active, so mpv couldn't update the
video at all.)

This is pretty "rough" and just hacked in, and there's no API yet to
make this easier for other backends. It will be cleaned up later
once we're sure that it works, or when we know how exactly it should
work. One oddity is that OpenGL is actually completely managed in the
renderer thread, while e.g. Cocoa (which has its own threading code)
creates the context in the GUI thread, and then lets the renderer
thread access it.

One strange issue is that we now have to stop WM_CLOSE from actually
closing the window. Instead, we wait until the playloop handles the
close command, and requests the VO to shutdown. This is done mainly
because closing the window apparently destroys it, and then WM_USER
can't be handled anymore - which means the playloop has no way to
wakeup the GUI thread. It seems you can't really win here... maybe
there's a better way to have a thread receive messages with and
without a window, but I didn't find one yet.

Dragging the window (by clicking into the middle of it) behaves
strangely in wine, but didn't before the change. Reason unknown.
2014-07-26 20:36:46 +02:00
wm4 760548da28 vo: hack to avoid threading issues with mouse input
VO backends which are or will run in their own thread have a problem
with vo_mouse_movement() calling vo_control(). Restrict this to VOs
which actually need this.
2014-07-26 20:31:26 +02:00
wm4 3f268cc4f2 win32: use gcc TLS instead of WM_NCCREATE tricks for window context
win32 does not provide a proper per-window context pointer. Although it
does allow passing a user-chosen value to WM_CREATE/WM_NCCREATE, this
is not enough - the first message doesn't even have to be WM_NCCREATE.
This gets us in trouble later on, so go the easy route and just use a
TLS variable.

__thread is gcc specific, but Windows is a very "special" platform
anyway. We support only MinGW and Cygwin on it, so who cares. (C11
standardizes __thread as _Thread_local; we can use that later.)
2014-07-26 20:30:52 +02:00
wm4 8ed6d298c5 win32: make a flag explicit
This shouldn't change anything. But it's worth making this explicit,
since it's very subtle and unintuitive: if the X parameter is the
magic value CW_USEDEFAULT, then the Y parameter is used as nCmdShow
parameter to ShowWindow(). And in our case, this is SW_HIDE (0),
because we want to create a hidden window.
2014-07-26 20:29:18 +02:00
wm4 9969694ece win32: simplify some --wid embedding code
This looked a bit overcomplicated. We don't care about the window
position (it should always be 0/0, unless the parent program moved it,
which it shouldn't). We don't care about the global on-screen position.
Also, we will just retrieve a WM_SIZE message if our window is resized,
and we don't need to update it manually.

The only thing we have to do is making sure our window fills the parent
window completely.
2014-07-26 20:28:36 +02:00
wm4 9a3f1f24ca win32: don't use CS_OWNDC
CS_OWNDC will make GetDC() always return the same HDC. This might
become a problem when OpenGL rendering and window management are
on different threads. Although I'm not too sure about this; our
code never requests a HDC outside of the OpenGL backend, and it
depends on whether win32 will internally request DCs. But in any
case, this seems to be cleaner.

Move the GL pixelformat setup code to gl_w32.c, where it's actually
needed. This also fixes that SetPixelFormat() should be called only
once, and not every time video params change.
2014-07-26 20:28:01 +02:00
wm4 7f0d9a95fa win32: remove worthless doxygen comments
These mostly describe self-explanatory things, and fail to explain
actually tricky things. Which means you just waste your time reading
this, and have to figure it out from the code anyway.
2014-07-26 20:27:57 +02:00
wm4 b3169390f5 win32: make private struct private, refactor
Preparation for moving win32 windowing to a separate thread.

The codesize is reduced a bit, because some small functions are
inlined, which reduces noise.

The main change is that now most functions use the private struct
directly, instead of accessing it indirectly through vo->w32.
Accesses to vo are minimalized.

The final goal is adding some sort of new windowing backend API. It
would be cleaner to use that as context pointer for all functions
(like struct vo was previously used), but since this is work in
progress, we just go with this commit.
2014-07-26 20:27:03 +02:00
Stefano Pigozzi c76958d20c cocoa: don't send messages to uninitialized gl contexts
This should fix some crashes where we sent makeCurrentContext to a context that
was being freed from another thread.

/cc @mpv-player/stable
2014-07-19 12:01:53 +02:00
Stefano Pigozzi 135ba132a8 cocoa: fix regression preventing window resize
I introduced this bug in b5bbb49. Sorry!
This could fix #943 and #930 even though I can't reproduce those specific bugs.
2014-07-15 21:33:19 +02:00
Stefano Pigozzi ac71cb8611 cocoa: fix compilation on OS X 10.8 2014-07-14 07:21:44 +02:00
wm4 417ffa8b40 Remove some mp_msg calls with no trailing \n
The final goal is all mp_msg calls produce complete lines. We want this
because otherwise, race conditions could corrupt the terminal output,
and it's inconvenient for the client API too. This commit works towards
this goal. There's still code that has this not fixed yet, though.
2014-07-13 20:12:13 +02:00
wm4 e1f2540ede video/out: use strcmp() instead of strcasecmp() for equalizers
This makes it more consistent with the more important VOs.
2014-07-10 08:27:15 +02:00
wm4 1a1e631ccd build: deal with endian mess
There is no standard mechanism for detecting endianess. Doing it at
compile time in a portable way is probably hard. Doing it properly
with a configure check is probably hard too. Using the endian
definitions in <sys/types.h> (usually includes <endian.h>, which is
not available everywhere) works under circumstances, but the previous
commit broke it on OSX.

Ideally all code should be endian dependent, but that is not possible
due to the dependencies (such as FFmpeg, some video output APIs, some
audio output APIs).

Create a header osdep/endian.h, which contains various fallbacks.
Note that the last fallback uses libavutil; however, it's not clear
whether AV_HAVE_BIGENDIAN is a public symbol, or whether including
<libavutil/bswap.h> really makes it visible. And in fact we don't want
to pollute the namespace with libavutil definitions either. Thus it's
only the last fallback.
2014-07-10 00:58:56 +02:00
Stefano Pigozzi 609187082f cocoa: simplify logic that returns used bits per color 2014-07-08 22:06:57 +02:00
Stefano Pigozzi b5bbb49a1a cocoa: move CGL context creation to gl_cocoa
This approach is similar to what other vo_opengl backends do. It can also be
used in the future to create another cocoa backend that renders offscreen
with IOSurfaces or FBOs.
2014-07-08 21:06:57 +02:00
wm4 6fcb34d887 vf_vapoursynth: reset error state on seeking
When seeking, we violently destroy the filter, because vapoursynth has
no proper API for terminating a video with unknown frame count. This
looks like an error to vapoursynth, and the error is returned via the
frame callbacks. The bug is that we remember this error state across
reinitialization, so on the first filter call after reinitialization, we
thought filtering the current frame failed. This caused a shift by 1
frame on each seek.

CC: @mpv-player/stable
2014-07-05 17:07:16 +02:00
wm4 338004bcfc dvd, bluray, cdda: add demux_disc containing all related hacks
DVD and Bluray (and to some extent cdda) require awful hacks all over
the codebase to make them work. The main reason is that they act like
container, but are entirely implemented on the stream layer. The raw
mpeg data resulting from these streams must be "extended" with the
container-like metadata transported via STREAM_CTRLs. The result were
hacks all over demux.c and some higher-level parts.

Add a "disc" pseudo-demuxer, and move all these hacks and special-cases
to it.
2014-07-05 17:07:15 +02:00
wm4 4a5cfb4323 x11: avoid obscure behavior when --wid is partially garbage
Cast away the "extra" bits (since apparently Window/XID is always
32 bit unsigned). This is not striclty needed, because you're not
supposed to pass garbage to --wid, just because the upper bits are
possibly not interpreted. But if you do so, this change increases
consistency in behavior and removes a strange behavior that was
thought to be a bug.

Also see github issue #906.
2014-07-04 02:23:05 +02:00
wm4 6d38ad1410 x11: clear window only on initial map
Apparently clearing on every map can cause problems with vdpau when
switching virtual desktops and such. This was observed with at least
XMonad and nvidia-340.17. It's not observed on some other setups without
XMonad.

It's not clear why this happens. Normally, the window background is not
saved, so clearing should have no additional affect. It's a complete
mystery. Possible, the use of legacy X drawing commands (used to clear
the window) interferes with vdpau operation in non-trivial ways.

Work this around by clearing on initial map only. This probably only
hides the underlying issue, but good enough.

Closes #897.

CC: @mpv-player/stable
2014-07-02 02:07:06 +02:00
wm4 9a210ca2d5 Audit and replace all ctype.h uses
Something like "char *s = ...; isdigit(s[0]);" triggers undefined
behavior, because char can be signed, and thus s[0] can be a negative
value. The is*() functions require unsigned char _or_ EOF. EOF is a
special value outside of unsigned char range, thus the argument to the
is*() functions can't be a char.

This undefined behavior can actually trigger crashes if the
implementation of these functions e.g. uses lookup tables, which are
then indexed with out-of-range values.

Replace all <ctype.h> uses with our own custom mp_is*() functions added
with misc/ctype.h. As a bonus, these functions are locale-independent.
(Although currently, we _require_ C locale for other reasons.)
2014-07-01 23:11:08 +02:00
Niklas Haas 856b57e418 vo_opengl: Make approx-gamma affect OSD/sub
Close #837

Signed-off-by: wm4 <wm4@nowhere>
2014-06-22 19:07:02 +02:00
Niklas Haas 664f8e9832 video: Include better heuristics for guessing primaries
These consult the vertical resolution, matching against 576 for
PAL and 480/486 for NTSC. The documentation has also been updated.

Signed-off-by: wm4 <wm4@nowhere>
2014-06-22 19:05:43 +02:00
Niklas Haas fbd35caef8 video: Refactor rendering intent for DCP XYZ and :srgb
Notably, we now conform to SMPTE 428-1-2006 when decoding XYZ12 input,
and we can support rendering intents other than colorimetric when
converting between BT.709 and BT.2020, like with :srgb or :icc-profile.
2014-06-22 19:02:06 +02:00
Niklas Haas 7f3ea12802 video: Better support for XYZ input
With this change, XYZ input is directly converted to the output
colorspace wherever possible, and to the colorspace specified by the
tags and/or --primaries option, otherwise.

This commit also restructures some of the CMS code in gl_video.c to
hopefully make it clearer which decision is being done where and why.
2014-06-22 19:02:06 +02:00
Niklas Haas 17762a1919 video: Generate an accurate CMS matrix instead of hard-coding
This also avoids an extra matrix multiplication when using :srgb, making
that path both more efficient and also eliminating more hard-coded
values.

In addition, the previously hard-coded XYZ to RGB matrix will be
dynamically generated.
2014-06-22 19:02:06 +02:00
Niklas Haas 204fed4d5b video: Support BT.2020 constant luminance system
Signed-off-by: wm4 <wm4@nowhere>
2014-06-22 19:02:00 +02:00
Niklas Haas ef6db24366 options: Expose --colormatrix-primaries to the user
Signed-off-by: wm4 <wm4@nowhere>
2014-06-22 19:01:25 +02:00
Niklas Haas 70f50ddc5e video: Add support for non-BT.709 primaries
This add support for reading primary information from lavc, categorized
into BT.601-525, BT.601-625, BT.709 and BT.2020; and passes it on to the
vo. In vo_opengl, we always generate the 3dlut against the wider BT.2020
and transform our source into this colorspace in the shader.
2014-06-22 19:00:38 +02:00
Niklas Haas 86d3d11a68 video: Add BT.2020-NCL colorspace and transfer function
Source: http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2020-0-201208-I!!PDF-E.pdf
2014-06-22 19:00:38 +02:00
wm4 b443f8471f vo_xv: de-ancient some help messages
One message pointed to a removed file, so just get rid of the messages.
They were helpful in the earlier 2000s, but now they're just confusing.
2014-06-21 20:41:07 +02:00
wm4 745889c68c vo_vaapi: fix reference counting when using software decoding
Recent regression.
2014-06-20 19:20:59 +02:00
Marcoen Hirschberg c4f518f132 vf_dlopen: fix the order of the arguments to mp_image_alloc 2014-06-19 23:07:02 +02:00
wm4 d9b1661895 vo_wayland: fix clearing the screen on reconfig
Do this simply by clearing the mapped buffer on every draw_image() call
without an actual video frame. (Maybe this is a bit expensive, but at
least not more expensive than regular video display.)
2014-06-18 20:22:10 +02:00
wm4 fc59a765eb vo_sdl: fix clearing the screen on reconfig
Clear the texture on reconfig(). (We could probably also do this simpler
with a flag, but this is actually less complicated - except that we move
the code to "map" a texture to a separate function.)
2014-06-18 20:21:07 +02:00
wm4 9accfe0426 video/out: fix redrawing with no video frame for some VOs
With the change to merge osd drawing into video frame drawing, some
bogus logic got in: they skipped drawing the OSD if no video frame is
available. This broke --no-video --force-window mode.
2014-06-18 20:04:59 +02:00
wm4 504f67a759 vo_opengl: fix regression with opengl:pbo
In the pbo case, mpi was reassigned to a stack pointer, and later
deallocated. Just change the code so it doesn't need to be reassigned.
2014-06-18 15:55:01 +02:00
wm4 8161d45408 gl_video: fix refcounting 2014-06-18 02:13:38 +02:00
wm4 a28e2a7432 video: correct spelling: mp_image_params_equals -> mp_image_params_equal
The type is struct mp_image_params, so the "params" should have a "s".
"equals" shouldn't, because it's plural for 2 params. Important.
2014-06-17 23:30:27 +02:00
wm4 efa6b09b65 video: remove redundant function
mp_image_params_from_image() is now trivial and can be removed.
2014-06-17 23:26:53 +02:00
wm4 90cd5aa8c8 vo: make draw_image and vo_queue_image transfer image ownership
Basically a cosmetic change. This is probably more intuitive.
2014-06-17 23:05:50 +02:00
wm4 d107cae0e7 video: check image parameters
Make sure every video filter has valid parameters for input and output.
(This also ensures we don't take possibly invalid decoder output, or
feed invalid decodr/filter output to VOs.)

Also, the updated image size check now (almost) works like the
corresponding check in FFmpeg.
2014-06-17 22:44:13 +02:00
wm4 72aac9ae8a video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)

But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.

Functions whose return values changed semantics:

  mp_image_alloc
  mp_image_new_copy
  mp_image_new_ref
  mp_image_make_writeable
  mp_image_setrefp
  mp_image_to_av_frame_and_unref
  mp_image_from_av_frame
  mp_image_new_external_ref
  mp_image_new_custom_ref
  mp_image_pool_make_writeable
  mp_image_pool_get
  mp_image_pool_new_copy
  mp_vdpau_mixed_frame_create
  vf_alloc_out_image
  vf_make_out_image_writeable
  glGetWindowScreenshot
2014-06-17 22:43:43 +02:00
wm4 973c1fa570 gl_lcms: use thread-safe lcms API, require lcms2 2.6
The error log callback was not thread-safe and not library-safe. And
apparently there were some other details that made it not library-safe,
such as a global lcms plugin registry.

Switch the the thread-safe API provided by lcms2 starting with 2.6.
Remove our approximate thread-safety hacks.

Note that lcms basically provides 2 APIs now, the old functions, and
the thread-safe alternatives whose names end with THR. Some functions
don't change, because they already have a context of some sort. Care
must be taken not to accidentally use old APIs.
2014-06-16 18:02:52 +02:00
wm4 eca0fcb77a vo_opengl: simplify redraw callback OSD handling
OSD used to be not thread-safe at all, so a track was used to get it
redrawn. This mostly reverts commit 6a2a8880, because OSD not being
thread-safe was the non-trivial part of it.

Mostly untested, because this code path is used on OSX only, and I don't
have OSX.
2014-06-16 01:00:59 +02:00
wm4 716285782d video/out: change aspects of OSD handling
Let the VOs draw the OSD on their own, instead of making OSD drawing a
separate VO driver call. Further, let it be the VOs responsibility to
request subtitles with the correct PTS. We also basically allow the VO
to request OSD/subtitles at any time.

OSX changes untested.
2014-06-15 20:53:15 +02:00
wm4 d88aca6fb2 vo_vaapi: fix a crash on the init error handling path
No X display or libva can't be initialized -> crash.
2014-06-15 16:58:31 +02:00
Alexander Preisinger 73121dbcc1 wayland: move subsurfaces to wayland vo
Subsurfaces are only used by the wayland vo. Thats why it makes sense to move
all osd and subsurface specific parts to the vo_wayland.c

Also destroy the subsurfaces and subcompositor properly.
2014-06-15 14:46:27 +02:00
Alexander Preisinger f14b45588e wayland: attach NULL surface on osd creation
When using the EGL output the subsurfaces have no buffer attached and the size
seems to be infinite. Fix this by attaching a NULL buffer.

Fixes #846
2014-06-15 14:27:12 +02:00
Stefano Pigozzi f645e8921c cocoa: add fallback for automatic GPU switching
Not all the hardware supports kCGLPFASupportsAutomaticGraphicsSwitching
(apparently all Mid-2010 and before MacBooks do not work with it), so fallback
to not asking for this attribute in the GL pixel format.
2014-06-15 08:20:06 +02:00
Stefano Pigozzi 1927f4535c cocoa: allow automatic gpu switching
Fixes #820
2014-06-15 08:19:55 +02:00
Stefano Pigozzi c3d17ece7b cocoa: switch to CGL APIs for GL context creation
CGL APIs are lower level thus giving us better control and more options for
the context creation.
2014-06-15 08:18:48 +02:00
wm4 a9fd52e493 gl_w32: remove unused variable 2014-06-14 19:17:25 +02:00
wm4 f193d25844 video: cosmetics: reformat image format names table 2014-06-14 10:06:23 +02:00
wm4 a9538e17ad video: synchronize mpv rgb pixel format names with ffmpeg names
This affects packed RGB formats up to 16 bits per pixel. The old mplayer
names used LSB-to-MSB order, while FFmpeg (and some other libraries) use
MSB-to-LSB.

Nothing should change with this commit, i.e. no bit order or endian bugs
should be added or fixed. In some cases, the name stays the same, even
though the byte order changes, e.g. RGB8->BGR8 and BGR8->RGB8, and this
affects the user-visible names too; this might cause confusion.
2014-06-14 10:03:04 +02:00
wm4 6ab72f9760 video: automatically strip "le" and "be" suffix from pixle format names
These suffixes are annoying when they're redundant, so strip them
automatically. On little endian machines, always strip the "le" suffix,
and on big endian machines vice versa (although I don't think anyone
ever tried to run mpv on a big endian machine).

Since pixel format strings are returned by a certain function and we
can't just change static strings, use a trick to pass a stack buffer
transparently. But this also means the string can't be permanently
stored by the caller, so vf_dlopen.c has to be updated. There seems
to be no other case where this is done, though.
2014-06-14 09:58:48 +02:00
wm4 6a4a5595d8 options: remove OPT_FLAG_CONSTANTS
This means use of the min/max fields can be dropped for the flag option
type, which makes some things slightly easier. I'm also not sure if the
client API handled the case of flag not being 0 or 1 correctly, and this
change gets rid of this concern.
2014-06-13 02:10:45 +02:00
wm4 a7a14be088 vd_lavc: use option parser for skip suboptions 2014-06-13 02:03:45 +02:00
wm4 14983eb37d vd_lavc: make option struct local
Removes specifics from options.h and options.c, and puts everything into
vd_lavc.c.
2014-06-11 01:36:11 +02:00
wm4 e34e1080d2 vf_noise: remove global variables 2014-06-11 00:39:14 +02:00
wm4 e9391e5827 vf_divtc: remove a global variable 2014-06-11 00:39:14 +02:00
wm4 99f5fef0ea Add more const
While I'm not very fond of "const", it's important for declarations
(it decides whether a symbol is emitted in a read-only or read/write
section). Fix all these cases, so we have writeable global data only
when we really need.
2014-06-11 00:39:14 +02:00
wm4 ad4b7a8c96 vo_caca: remove global variables
The shit I put up with...
2014-06-11 00:39:13 +02:00
wm4 fd5207f56d options: remove global variables for swscale options; rename them
Additionally to removing the global variables, this makes the options
more uniform. --ssf-... becomes --sws-..., and --sws becomes --sws-
scaler. For --sws-scaler, use choices instead of magic integer values.
2014-06-11 00:39:13 +02:00
wm4 e1d846263a video: fix another cover art corner case
Playing a video and then an audio file with cover art kept displaying
the last frame of the video. This was because the hasframe flag was set,
perhaps due to redrawing the last video frame before the cover art image
is decoded.
2014-06-09 01:21:08 +02:00
wm4 79e76abb4d x11: cleanup motif hints handling
It seems we can't really get rid of this. There are no other hints to
remove decorations that work across all reasonable WMs, so we're stuck
with the ugly motif stuff.

But at least we can make the code for it less ugly.
2014-06-06 18:45:38 +02:00
wm4 80907d007b filter_kernels: fix nearest scaler
The previous commit assumed the filter would be 1x1 (then constant
weight is correct) - but our code in fact uses at least a 2x2 filter. A
1x1 filter would generally be useless, except for nearest scaling - so
it didn't exist.

Insteasd of adding such a 1x1 filter, just turn the nearest weight
function into a scare function, which should take care of the issue.
2014-06-04 00:23:31 +02:00
lucy a3b466e88d filter_kernels: add nearest neighbour scaling
This is useful for playing content containing pixel art that hasn't been
pre-scaled, such as TASVideos' high quality encodes. The implementation is
lifted from <https://code.google.com/p/glumpy/source/browse/glumpy/image/filter.py#413>.
2014-06-03 23:00:24 +02:00
wm4 58b070d178 wayland: remove stub for unimplemented function 2014-06-02 20:20:35 +02:00
wm4 ae09c0d8eb vo: correctly initialize parameters in corner cases 2014-06-01 17:24:19 +02:00
wm4 498c997474 player: hide audio/video codec and file format messages
None of these are very important usually. For error analysis, the plain
log is useless anyway, and this information is still printed with "-v".
2014-05-31 22:07:36 +02:00
wm4 5567aa131b gl_common: remove dlsym() fallback
See previous commits.
2014-05-31 22:02:35 +02:00
wm4 caf35e695f gl_wayland: remove probably unneeded workaround
This would imply eglGetProcAddress() doesn't work correctly, but using
dlsym() does. For now get rid of it - it won't work in libmpv, and we'll
probably need a better workaround if it's still broken.

This code was in the initial wayland commit.
2014-05-31 22:00:06 +02:00
wm4 c42ac83c7c gl_x11: remove workaround for PPC OSX 10.4
Added in 2010 with commit 4a8486f8 (svn commit 30994). I doubt anyone
still uses X11 on OSX, and we probably don't support 10.4 either.
2014-05-31 21:56:45 +02:00
wm4 8178b80748 gl_x11: always require some GLX API functions, avoid dlsym()
The functions glXGetProcAddressARB() and glXQueryExtensionsString() were
loaded using dlsym(). This could fail when compiling to libmpv, because
then dlopen(NULL, ...) will look in the main program's list of
libraries, and the libGL linked to libmpv is never considered. (Don't
know if this somehow could be worked around.) The result is that using
vo_opengl with libmpv can fail.

Avoid this by not using dlsym(). glXGetProcAddressARB() was already used
directly in the same file, and that never caused any problems. (Still
add it to the configure test.) glXQueryExtensionsString() is documented
as added in GLX 1.1 - that's ancient.
2014-05-31 21:53:04 +02:00
Marcoen Hirschberg ecea66e8dc vd_lavc: set video bitrate if available
Set the bitrate of dec_video if it is available in avcodec.
2014-05-28 21:38:20 +02:00
Marcoen Hirschberg 434242adb5 audio: rename i_bps to 'bitrate' to avoid confusion
Since i_bps now contains bits/sec, rename it to reflect this change.
2014-05-28 21:37:50 +02:00
Marcoen Hirschberg 6e58b20cce audio: change values from bytes-per-second to bits-per-second
The i_bps members of the sh_audio and dev_video structs are mostly used
for displaying the average audio and video bitrates. Keeping them in
bits-per-second avoids truncating them to bytes-per-second and changing
them back lateron.
2014-05-28 21:37:44 +02:00
wm4 b442b522f6 vaapi: fix destruction with --hwdec=haapi-copy
This is incomplete; the video chain will still hold some vaapi objects
after destroying the decoder and thus the vaapi context. This is very
bad. Fixing it would require something like refcounting the vaapi
context, but I don't really want to.
2014-05-28 02:08:45 +02:00