Commit Graph

35367 Commits

Author SHA1 Message Date
wm4 5e2c211a4e sd_lavc_conv: strip style header
Normally, libavcodec subtitle converters will output a style header like
this as part of the extradata:

    Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,1,1,0,2,10,10,10,0,0

We don't want that, so use some bruteforce to get rid of them.
2013-06-03 22:40:07 +02:00
wm4 d5520d20b2 sub: use libass even if -no-ass is used
The -no-ass option used to disable all use of libass completely. This
doesn't work this way anymore, and the text subtitle path has an
inherent dependency on libass. Currently -no-ass does 3 things:

1. Strip tags and formatting on display, and use a separate renderer for
   the result. (Which might be the terminal, or libass via OSD code.)
2. Not loading attached fonts from Matroska files.
3. Use subreader.c instead of libass for reading .ass files.

1. and 2. are ok and what the user (probably wants), but 3. doesn't
really make sense anymore. subreader.c reads .ass files just fine, but
then does some strange things to them (something about coalescing and
re-adding newlines?), leading to even more broken display with -no-ass.
Instead of fighting with subreader.c, just use libass as loader.
2013-06-03 22:40:07 +02:00
wm4 74e3ac8bf8 sd_lavc_conv: add hack if AV_CODEC_PROP_TEXT_SUB is not available
Otherwise this could happily open decoders for image subtitles or even
audio/video decoders. AV_CODEC_PROP_TEXT_SUB is a preprocessor symbol,
but it's still better to detect this properly instead of using #ifdef,
because these flags might as well be changed into enums sooner or later.
2013-06-03 22:40:06 +02:00
wm4 e42a771413 sd_ass: strip empty/whitespace lines in -no-ass mode
Will just destroy output. In some cases empty newlines might be used by
bad scripts for spacing; too bad for them.
2013-06-03 22:40:06 +02:00
wm4 6dbedd27d5 demux_lavf: always set packet duration
Makes WebVTT actually work.

Also simplify the logic for setting duration. Only the subtitle path
uses the packet duration, so the checks for STREAM_SUB as well as the
keyframe flag are redundant.

Apparently duration and convergence_duration are the same thing, but
convergence_duration was added as Matroska-specific hack to get a higher
value range (int vs. int64_t) with high resolution Matroska timebases.
For us it doesn't matter, because double floats are used for timestamps
and durations.
2013-06-03 22:40:06 +02:00
wm4 b11bd1fe5e sub: make use of libavcodec subtitle converters
This allows using some formats that were not supported until now, like
WebVTT.

We still prefer the internal subtitle reader (subreader.c), because
1. Libav, and 2. random things which we probably want to keep, such as
control over formatting, codepage stuff, or various mysterious
postprecessing done in that code.
2013-06-03 22:40:06 +02:00
wm4 e19ffa02aa sub: turn subassconvert_ functions into sub converters
This means subassconvert.c is split in sd_srt.c and sd_microdvd.c. Now
this code is involved in the sub conversion chain like sd_movtext is.
The invocation of the converter in sd_ass.c is removed.

This requires some other changes to make the new sub converter code work
with loading external subtitles. Until now, subtitles loaded via
subreader.c was assumed to be in plaintext, or for some formats, in ASS
(except in -no-ass mode). Then these were added to an ASS_Track. Change
this so that subtitles are always in their original format (as far as
decoders/converters for them are available), and turn every sub event
read by subreader.c as packet to the dec_sub.c subtitle chain.

This removes differences between external/demuxed and -ass/-no-ass code
paths further.
2013-06-03 22:40:02 +02:00
Stefano Pigozzi 72f2942dfa osx: add Apple Remote support
After killing the non functional AR support in c8fd9e5 I got much complaints so
this adds AR support back in (and it works). I am using the HIDRemote class by
Felix Schwarz and that part of the code is under the BSD license. I slightly
modified it replacing [NSApplication sharedApplication] with NSApp. The code
of the class is quite complex (probably because it had to deal with all the
edge cases with IOKit) but it works nicely as a black box.

In a later commit I'll remove the deprecation warnings caused by HIDRemote's
usage of Gestalt.

Check out `etc/input.conf` for the default bindings.

Apple Remote functionality is automatically compiled in when cocoa is enabled.
It can be disabled at runtime with the `--no-ar` option.
2013-06-03 22:35:47 +02:00
Stefano Pigozzi c39efb96d1 osx: implement media keys
Media keys are pretty handy if you use mpv as a music player (yes I'm one of
those people that do).

These are the bindings (which lead to the same behaviour as iTunes):
  * NX_KEYTYPE_PLAY   -> MP_KEY_PLAY
  * NX_KEYTYPE_FAST   -> MP_KEY_NEXT
  * NX_KEYTYPE_REWIND -> MP_KEY_PREV

I just handled these ones as the volume one would be pretty invasive. I could
maybe change it to increase the application's volume instead of system volume
only when mpv is frontmost (iTunes does this), but some users would probably
hate it.
2013-06-03 22:31:14 +02:00
Stefano Pigozzi d67b687530 macosx_events: send all queued events
Seeking feels a little faster or it may be self suggestion. There's really no
reason to just send only one event at a time.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi f0d2120347 osx: cocoa_common: use default wakeup period
Now that Cocoa's input handling is done on a separate thread from the playloop
it is ridicolously simple to have longer asynchronous sleeps when paused.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi f13f0db33a osx: create macosx_events to deal with keyDown events
On OSX with Cocoa enabled keyDown events are now handled with
addLocalMonitorForEventsMatchingMask:handler:. This allows to respond to
events even when there is no VO initialized but the GUI is focused.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi 63e2a21c64 osx_common: remove outdated ifdeffery
It was definining keycodes not defined in OS X < 10.5.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi 037c0f190b travis: run travis on 'ci' branch
We will use the 'ci' branch to do test builds of big features before they
are merged into master.

[ci skip]
2013-06-03 21:34:41 +02:00
wm4 14dd951548 sub: split subassconvert.c into sd_microdvd.c and sd_srt.c 2013-06-03 02:09:07 +02:00
wm4 3000df35d3 sub: basic subtitle converters
Add a basic infrastructure for subtitle converters. These converters
work sort-of like decoders, except that they produce packets instead
of subtitle bitmaps. They are put in front of actual decoders.

Start with sd_movtext. 4 lines of code are blown up to a 55 lines file,
but fortunately this is not going to be that bad for the following
converters.
2013-06-03 02:09:07 +02:00
wm4 4a1f9bdc66 input.conf: fix comment 2013-06-03 00:15:25 +02:00
wm4 66be276f69 gl_video: reduce output with -v, skip useless header parts
Originally, the header wasn't supposed to contain random compatibility
stuff, but now all that is printed with -v. Add a hack to skip it and
to reduce the noise.
2013-06-03 00:05:07 +02:00
wm4 87c549ffae gl_video: explicitly clamp colormatrix output
This could lead to quite visible artifacts when using an appropriate ICC
and float FBOs. The float FBOs allow storing out of range values, and my
guess is that the rest of the precessing chain elevated these out of
range values, resulting in artifacts.
2013-06-03 00:00:14 +02:00
wm4 07fc939544 m_option: fix -vo opengl lscale validation
OPT_STRING_VALIDATE actually did nothing. This made -vo opengl crash or
misbehave when passing an invalid value for the lscale, cscale or 3dlut-
size (the only users for this option type).

The code added with this commit was either blatantly forgotten with the
commit introducing this option type, or somehow lost.
2013-06-03 00:00:11 +02:00
wm4 e9af899237 demux: fix "-demuxer mpegps", don't force demuxer in stream_dvd
Internally, stream_dvd.c returned DEMUXER_TYPE_MPEG_PS, and the same
value was hardcoded to enforced usage of demux_lavf in demux.c. But
"-demuxer mpegps" basically did the same, so that switch was broken
for this format. Undo this and don't request a demuxer in stream_dvd.c.
demux_lavf.c is (probably) good enough to probe correctly with DVD.
Otherwise, we'd actually have to do something completely different to
force the libavformat demuxer.
2013-06-02 23:57:41 +02:00
Stefano Pigozzi 57571b5da3 cocoa_common: autohide dock/menubar on fs only if on same screen
Autohide the menubar and/or dock only if they are present in the screen the
player is going to go fullscreen into. I thought the GUI would handle this for
me when I switched 0057aa476 but lack of hardware to test made me embarass
myself yet again.

I reimplemented this feature with nicer code and behaviour. The code checks
separately wether to hide menubar and dock separatly, while the old code used
a single check possibly hiding stuff without need.

Added the key checks as a some category additions to NSScreen for readability.
2013-06-01 22:52:21 +02:00
wm4 02ce316ade sub: refactor
Make the sub decoder stuff independent from sh_sub (except for
initialization of course). Sub decoders now access a struct sd only,
instead of getting access to sh_sub. The glue code in dec_sub.c is
similarily independent from osd.

Some simplifications are made. For example, the switch_id stuff is
unneeded: the frontend code just has to make sure to call osd_changed()
any time subtitles are switched.

This is also preparation for introducing subtitle converters. It's much
cleaner to completely separate demuxer header/renderer glue/decoders
for this purpose, especially since sub converters might completely
change how demuxer headers have to be interpreted.

Also pass data as demux_packets. Currently, this doesn't help much, but
libavcodec converters might need scary stuff like packet side data, so
it's perhaps better to go with passing packets.
2013-06-01 19:44:16 +02:00
wm4 27d383918a core: add demux_sub pseudo demuxer
Subtitle files are opened in mplayer.c, not using the demuxer
infrastructure in general. Pretend that this is not the case (outside of
the loading code) by opening a pseudo demuxer that does nothing. One
advantage is that the initialization code is now the same, and there's
no confusion about what the difference between track->stream,
track->sh_sub and mpctx->sh_sub is supposed to be.

This is a bit stupid, and it would be much better if there were proper
subtitle demuxers (there are many in recent FFmpeg, but not Libav). So
for now this is just a transition to a more proper architecture. Look
at demux_sub like an artifical limb: it's ugly, but don't hate it - it
helps you to get on with your life.
2013-06-01 19:43:11 +02:00
wm4 f7b9b92179 sub: various minor subtitle related changes
Just pushing some code around.
2013-06-01 19:42:00 +02:00
Stefano Pigozzi f4dcb93be1 cocoa_common: don't autohide mouse on mousedown
Previews code allowed to click the same spot for a long time and the cursor
would autohide. No more!
2013-06-01 17:58:08 +02:00
Stefano Pigozzi db7835f5d7 cocoa_common: avoid window creation with VOFLAG_HIDDEN
This takes an approach similar to the wayland OpenGL backend. VOFLAG_HIDDEN
flag semantics doesn't mean "hide the window" but is simply ever used only to
do detection of available OpenGL extensions. On OSX it's possibile to
accomplish this task just by creating the OpenGL context without attaching
it to a drawable.
2013-06-01 12:12:17 +02:00
Stefano Pigozzi 109158603d cocoa_common: dehack mouse autohide by clipping view bounds to visible screen
This prevents the mouse to autohide when hovering the dock/menubar without any
particular hack and seems to finally cover all edge cases.
2013-06-01 02:10:41 +02:00
Stefano Pigozzi 25ae58fbbe cocoa_common: fix mouse autohide on MenuBar/Dock interaction
This is needed after last commit. A bug within a bug (yo dawg)! Serious
explaination in the source code comment so that it's not forgotten.
2013-05-31 14:16:27 +02:00
Stefano Pigozzi 2c4f5b75c0 cocoa_common: fix empty window when going fs on different screen
Using `enterFullScreenMode:withOptions:` with a screen handle than the current
screen doesn't hide the current window in the current screen. This is a bug in
Cocoa (preparing an isolated test case and sending the rdar later).

To work around this, manually hide/show the window that the toolkit should
hide/show for us.
2013-05-31 12:58:54 +02:00
Stefano Pigozzi 76f6df6be0 demux_mkv: clang: fix -Wunused-function
This was introduced with c0db930d.
2013-05-30 23:15:24 +02:00
Stefano Pigozzi bf21ed0102 cocoa_common: fix mouse hiding outside of player view
This bug was the result of crappy position detection in the previous code
combined with the commits moving autohide delay out of the cocoa backend and
into the core.

The hit detection was improved and now takes also account of interactions with
the Dock and Menubar. Moreover VOCTRL_SET_CURSOR_VISIBILITY now has an effect
only if the mouse position matches with this improved hit detection. This means
that both interaction with the Dock and Menubar are considered as well as
moving the mouse inside another screen.
2013-05-30 23:03:21 +02:00
Stefano Pigozzi 68c3e2aabb cocoa_common: refactor fullscreen code for readability
Break up the code into several methods and reduce code duplication. Also add
comments to make the intention of all this clearer.
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 0aac8bc5ad cocoa_common: fix native-fs state saving
`opts->fs = VO_FALSE` was forgotten
2013-05-30 23:03:20 +02:00
Stefano Pigozzi a31422bbfe macosx_application: refactor psn matching code
Objective-C is shorter / more readable than snprintf.
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 8b40494e93 macosx_application: refactor filename escape
Use Objective-C's new literal syntax to make the code simpler.
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 3789e1bebf cocoa_common: fix a bug in window initialization error
We didn't bail out soon enough. Bug was introduced by 134f3e97.
2013-05-30 23:02:56 +02:00
Stefano Pigozzi 1d11db6596 macosx_application: use @autoreleasepool
I don't even want to know how this worked. It scares me a lot.
2013-05-30 23:01:12 +02:00
Stefano Pigozzi 0057aa4769 cocoa_common: use cocoa APIs to go fullscreen
This removes a bit of ugly code and bookeeping which is never bad. `drawRect`
needs to guard against different window instances since in fullscreen the view
is wrapped in a fullscreen window provided by the toolkit (a instance of
NSFullScreenWindow to be precise).

The event handling was moved to the view so that it can still get all the
events when in the fullscreen window. Ideally these should be moved to
some NSResponder subclass within macosx_application and made available even
when no window is present. I refrained from this because "small steps".
2013-05-30 23:01:12 +02:00
Stefano Pigozzi 3396e0565b macosx_application: move escape_loadfile_name in this file
This allows to move back osx_common to raw C.
2013-05-30 23:01:12 +02:00
Stefano Pigozzi 14ff6bbf7c cocoa_common: use better power management activity description
Now one might actually undestand why this power management assertion is used
in the first place.
2013-05-30 23:01:12 +02:00
Stefano Pigozzi ae1fa639e0 osx: remove compatibility conditionals for 10.6
At this point 10.6 is pretty old and we don't want to supporting old platforms.
I'm killing all the 10.6 compatibility code before doing more refactorings.

Next commits will also use newer Objective-C syntax such as literals and
@autoreleasepool.
2013-05-30 22:57:35 +02:00
wm4 28116b8a79 sub: remove some global variables 2013-05-30 22:44:18 +02:00
wm4 fd02f0f4d8 options: add --no-sub-visibility for symmetry
Not really useful, but for symmetry with the sub-visibility property
(mapped to the 'v' key by default).
2013-05-30 22:41:24 +02:00
wm4 f429b4eaa8 spudec: restore --sub-forced-only support
This was broken with 84829a4 "Merge branch 'osd_changes' into master".
The new OSD/subtitle code never respected the --sub-forced-only option,
and the old code containing the code for this was removed in fd5c4a1.
2013-05-30 22:40:32 +02:00
wm4 2684280643 sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.

Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.

One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.

Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.

There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.

As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-05-30 22:40:32 +02:00
wm4 724f576211 sub: use DVD PTS fallback code in normal sub decoding path
It appears demux_mpg doesn't output timestamps for subtitles. The vobsub
code handled this by doing its own PTS calculations. This code is absent
from the normal subtitle decoder path. Copy this code into the normal
path, so that we can unify the subtitle decoder paths in a later commit.

Decoding subtitles with sd_lavc when playing DVD with demux_mpg still
doesn't work.
2013-05-30 22:20:03 +02:00
wm4 38bd757e4f sub: remove check_duplicate_plaintext_event()
This was once needed to handle subtitle packages coming from a demuxer,
where seeking back might repeat previous events. This doesn't happen
anymore, and this code is used to convert complete files. So if there
are any duplicate lines, they must have been duplicated in the file,
and the old subtitle renderer would have shown them twice as well.

Today checking for duplicate events happens in sd_ass.c (and has been
for a while). There's no reason to keep this code, and it actually
causes trouble. Loading big subtitle files is extremely slow because
this makes adding n subtitles O(n^2).
2013-05-30 22:20:02 +02:00
wm4 b44202b69f sub: redo how -no-ass is handled
The -no-ass switch used to disable any use of libass for text subtitles.
This is not really the case anymore, because libass is now always
involved when rendering text. The only remaining use of -no-ass is
disabling styling or showing subtitles on the terminal. On the other
hand, the old subtitle rendering path is a big reason why the subtitle
code is still a big mess with an awful number of obscure special cases.

In order to simplify it, remove the old subtitle rendering code, and
always go through sd_ass.c. Basically, we use ASS_Track as central data
structure for storing text subtitles instead of struct sub_data. This
also makes libass mandatory for all text subs, even if they are printed
to the terminal in -no-video mode. (We could add something like sd_text
to avoid this, but it's not worth the trouble.)

struct sub_data and subreader.c are still around, even its ASS/SSA
reader. But struct sub_data is freed right after converting it to
ASS_Track. The internal ASS reader actually can handle some obscure
cases libass can't, like files encoded in UTF-16.
2013-05-30 22:20:02 +02:00
wm4 f7ad81c0f5 demux_mkv: replace awkward goto by function call
Requires reindenting a large code block to minimize random control flow.
2013-05-30 19:59:03 +02:00