Commit Graph

53 Commits

Author SHA1 Message Date
wm4 8a9b64329c Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.

There are probably more files to which this applies, but I'm being
conservative here.

A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).

common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.

codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.

From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).

misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.

screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 18:36:06 +01:00
wm4 bbb65ed84b sub: use macros to remove code duplication
Meh.
2015-12-24 17:32:10 +01:00
wm4 30074f8440 sub: merge bitmap render functions into one for each kind
Merge blend_src8_alpha and blend_src16_alpha into blend_src_alpha, and
the same for blend_const_alpha.

One thing that changes is that the vertical loop is now shared for both
code paths.

I think this is slightly easier to read, and it's a bit shorter as well.
2015-12-24 17:24:55 +01:00
wm4 a042dcc700 sub: remove "inaccurate" code path
The "accurate" one always has been enabled, and I can't find much
evidence that the "inaccurate" one is much faster on my particular
machine anyway.
2015-12-24 17:08:02 +01:00
wm4 3973a953df sub: find GBRP format automatically when rendering to RGB
This removes the need to define IMGFMT_GBRAP, which fixes compilation
with the current Libav release.

This also makes it automatically pick up a GBRP format with the same bit
width. (Unfortunately, it seems libswscale does not support conversion
to AV_PIX_FMT_GBRAP16, so our code falls back to 8 bit, removing
precision for video covered by subtitles in cases this code is used.)

Also, when the source video is e.g. 10 bit YUV, upsample to 16 bit.
Whether this is good or bad, it fixes behavior with alpha. Although I'm
not sure if the alpha range is really correct ([0,2^16-1] vs.
[0,255*256]). Keep in mind that libswscale doesn't even agree with the
way we do it.
2015-12-24 16:42:21 +01:00
wm4 6bec6ac558 sub: better alpha blending when rendering to alpha surfaces
This actually treats destination alpha correctly, and gives much better
results than before. I don't know if this is perfectly correct yet,
though. Slight difference with vo_opengl behavior suggests it might not
be.

Note that this does not affect VOs with true alpha support. vo_opengl
does not use this code at all, and does the alpha calculations in OpenGL
instead.
2015-12-24 14:43:23 +01:00
wm4 45ae0716be csputils: rename "yuv2rgb" functions
They're not necessarily restricted to YUV aka YCbCr.

vo_direct3d.c and demux_disc.c (DVD specific code) changes untested.
2015-12-09 00:23:36 +01:00
wm4 c2d0d7818f csputils: remove obscure int_bits matrix scaling
This has no reason to be there. Put the functionality into another
function instead. While we're at it, also adjust for possible accuracy
issues with high bit depth YUV (matters for rendering subtitles into
screenshots only).
2015-12-09 00:08:00 +01:00
Marcin Kurczewski f43017bfe9 Update license headers
Signed-off-by: wm4 <wm4@nowhere>
2015-04-13 12:10:01 +02:00
wm4 37a71e57d4 mp_image: remove redundant flags field
Because gcc (and clang) is a goddamn PITA and unnecessarily warns if
the universal initializer for structs is used (like mp_image x = {})
and the first member of the struct is also a struct, move the w/h
fields to the top.
2015-04-10 21:06:25 +02:00
wm4 41151122e7 mp_image: remove redundant chroma_x/y_shift fields 2015-04-10 21:02:16 +02:00
wm4 be259be15c mp_image: get rid of chroma_width/height fields
They are redundant. They were used by draw_bmp.c only, and only in a
special code path that 1. used fixed image formats, and 2. had image
sized perfectly aligned to chroma boundaries (so computing the chroma
width/height is trivial).
2015-04-09 21:11:20 +02:00
wm4 51befc9deb osd: simplify an aspect of change detection handling
There was a somewhat obscure optimization in the OSD and subtitle
rendering path: if only the position of the sub-images changed, and not
the actual image data, uploading of the image data could be skipped. In
theory, this could speed up things like scrolling subtitles.

But it turns out that even in the rare cases subtitles have such scrolls
or axis-aligned movement, modern libass rarely signals this kind of
change. Possibly this is because of sub-pixel handling and such, which
break this.

As such, it's a worthless optimization and just introduces additional
complexity and subtle bugs (especially in cases libass does the
opposite: incorrectly signaling a position change only, which happened
before). Remove this optimization, and rename bitmap_pos_id to
change_id.
2015-03-18 13:15:20 +01:00
wm4 d42d60bc1e csputils: replace float[3][4] with a struct
Not being able to use the 3x3 part of the matrix was annoying, so split
it into a float[3][3] matrix and a separate float[3] constant vector.
2015-01-06 16:51:06 +01:00
wm4 5410a5b2c5 csputils: move image_params -> csp_params into a function
Although the line count increases, this is better for making sure
everything is handled consistently for all users of the mp_csp_params
stuff.

This also makes sure mp_csp_params is always initialized with
MP_CSP_PARAMS_DEFAULTS (for consistency).
2015-01-06 16:51:02 +01:00
wm4 a52ca8a2b0 csputils: get rid of mp_csp_details
It used to be central, but now it's just unneeded.
2015-01-06 16:50:58 +01:00
wm4 9a724f62ce draw_bmp: make code more obvious, remove assertion
Silences a Coverity warning.

Also, drop the assert(); although it should be pretty much guaranteed
that things happen this way, it's still a bit fuzzy.
2014-11-21 05:56:55 +01: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 5e4e248dc2 video: make mp_image use mp_image_params directly
Minor cleanup, so that we can stuff more information into
mp_image_params later.
2014-04-21 02:57:16 +02:00
wm4 0112143fda Split mpvcore/ into common/, misc/, bstr/ 2013-12-17 02:39:45 +01:00
wm4 e5311586ab Rename sub.c/.h to osd.c/.h
This was way too misleading. osd.c merely calls the subtitle renderers,
instead of actually dealing with subtitles.
2013-11-24 14:44:58 +01:00
Stefano Pigozzi 406241005e core: move contents to mpvcore (2/2)
Followup commit. Fixes all the files references.
2013-08-06 22:52:31 +02:00
wm4 7f88e36911 sws_utils: don't recursively include libswscale header
Add libswscale includes where they are actually needed instead.
2013-07-18 13:46:05 +02:00
wm4 f6a68063ba sub: don't crash on GBRP video
mp_get_yuv2rgb_coeffs() will crash if the colorspace is explicitly set
to RGB.
2013-03-28 21:46:17 +01:00
wm4 6b91ba0192 draw_bmp: use multiple bounding boxes
Seems to make it about up to 20% faster in some cases.
Slightly slower in some others.
2013-01-13 20:04:16 +01:00
wm4 03730e73dc img_convert: add sub_bitmap bounding box functions
mp_sub_bitmaps_bb is just sub_bitmaps_bb renamed/moved.
2013-01-13 20:04:16 +01:00
wm4 fb23c3a8ee draw_bmp: don't copy Y plane on up/down-sampling
Image areas with subtitles are upsampled to 4:4:4 in order to render
the subtitles (makes blending easier). Try not to copy the Y plane on
upsampling. The libswscale API requires this, but this commit works it
around by scaling the chroma planes separately as AV_PIX_FMT_GRAY8. The
Y plane is not touched at all. This is done for 420p8 only, which is the
most commonly needed case. For other formats, the old way is used.

Seems to make ASS rendering faster about 15% in the setup I tested.
2013-01-13 20:04:14 +01:00
wm4 7d15bd1488 draw_bmp: do not reallocate upsample temp image on each frame
Doesn't seem to help too much...
2013-01-13 20:04:14 +01:00
wm4 5c049bf577 draw_bmp: refactor 2013-01-13 20:04:14 +01:00
wm4 c652e3f6b1 draw_bmp: always allocate cache
Allocate it even if it's needed. The actually done work is almost the
same, except that the code is a bit simpler. May need more memory at
once for RGB subs that use more than one part, which is rare.
2013-01-13 20:04:14 +01:00
wm4 717d904bbc mp_image: add mp_image_crop()
Actually stolen from draw_bmp.c.
2013-01-13 20:04:12 +01:00
wm4 3d6d549dac vo_xv, vo_x11: simplify OSD redrawing
In order to support OSD redrawing for vo_xv and vo_x11, draw_bmp.c
included an awkward "backup" mechanism to copy and restore image
regions that have been changed by OSD/subtitles.

Replace this by a much simpler mechanism: keep a reference to the
original image, and use that to restore the Xv/X framebuffers.

In the worst case, this may increase cache pressure and memory usage,
even if no OSD or subtitles are rendered. In practice, it seems to be
always faster.
2013-01-13 20:04:12 +01:00
wm4 3791c226b7 draw_bmp: better way to find 444 format
Even though #ifdef ACCURATE is removed, the result should be about the
same. The fallback is only used by packed YUV formats (YUYV, NV12), and
doing 16 bit for them instead of 8 bit is not useful.

A side effect is that Y8 (gray) is not converted drawing subs, and for
alpha formats, the alpha plane is not removed. This means the number of
planes after upsampling can be 1-4 (1: gray, 2: gray+alpha, 3: planar,
4: planar+alpha). The code has to be adjusted accordingly to work on the
color planes only. Also remove the workaround for the chroma shift 31
hack.
2013-01-13 20:04:11 +01:00
wm4 0c5311f17c video: cleanup: replace old mp_image function names
mp_image_alloc() also changes argument order compared to alloc_mpi().
The format now comes first, then width/height.
2013-01-13 20:04:11 +01:00
wm4 ab94c64ed2 mp_image: simplify image allocation
mp_image_alloc_planes() allocated images with minimal stride, even if
the resulting stride was unaligned. It was the responsibility of
vf_get_image() to set an image's width to something larger than
required to get an aligned stride, and then crop it. Always allocate
with aligned strides instead.

Get rid of IMGFMT_IF09 special handling. This format is not used
anymore. (IF09 has 4x4 chroma sub-sampling, and that is what it was
mainly used for - this is still supported.) Get rid of swapped chroma
plane allocation. This is not used anywhere, and VOs like vo_xv,
vo_direct3d and vo_sdl do their own swapping.

Always round chroma width/height up instead of down. Consider 4:2:0 and
an uneven image size. For luma, the size was left uneven, and the chroma
size was rounded down. This doesn't make sense, because chroma would be
missing for the bottom/right border.

Remove mp_image_new_empty() and mp_image_alloc_planes(), they were not
used anymore, except in draw_bmp.c. (It's still allowed to setup
mp_images manually, you just can't allocate image data with them
anymore - this is also done in draw_bmp.c.)
2013-01-13 20:04:10 +01:00
wm4 d77d9fb933 mp_image: require using mp_image_set_size() for setting w/h
Setting the size of a mp_image must be done with mp_image_set_size()
now. Do this to guarantee that the redundant fields (like chroma_width)
are updated consistently. Replacing the redundant fields by function
calls would probably be better, but there are too many uses of them,
and is a bit less convenient.

Most code actually called mp_image_setfmt(), which did this as well.
This commit just makes things a bit more explicit.

Warning: the video filter chain still sets up mp_images manually,
and vf_get_image() is not updated.
2013-01-13 17:39:32 +01:00
Stephen Hutchinson c082240c62 video: add support for 12 and 14 bit YUV pixel formats
Based on a patch by qyot27. Add the missing parts in mp_get_chroma_shift(),
which allow allocation of such images, and which make vo_opengl
automatically accept the new formats. Change the IMGFMT_IS_YUVP16_LE/BE
macros to properly report IMGFMT_444P14 as supported: this pixel format
has the highest numerical bit width identifier (0x55), which is not
covered by the mask ~0xfc. Remove 1 bit from the mask (makes it 0xf8) so
that IMGFMT_IS_YUVP16(IMGFMT_444P14) is 1. This is slightly risky, as
the organization of the image format IDs (actually FourCCs + mplayer
internal IDs) is messy at best, but it should be ok.
2012-12-03 21:08:51 +01:00
wm4 86ad77d0db draw_bmp: add RGB rendering to fix image quality issues
As pointed out in commit ed01df, the quality loss due to frequent
conversion between RGB and YUV is too much when drawing OSD and
subtitles.

Fix this by staying in the same colorspace when drawing subtitles.
Render directly to RGB, without converting to YUV first.

The bad thing about packed RGB is that there are many pixel formats,
which would all require special code for blending. It's also completely
incompatible to planar YUV. Use planar RGB instead, which allows us to
reuse all code originally written for planar YUV. The only thing that
needs to be changed is the color conversion in the libass case. (In
exchange for simpler code, the image has to be copied, but this is
still much better than converting to YUV.)

Unfortunately, libswscale doesn't support planar RGB output. Add a hack
to sws_utils.c to handle conversion to planar RGB. In the common case,
when converting 32 bit per pixel RGB, calling swscale can be avoided
entirely.

The change in mp_image.c is needed to allocate GBRP images correctly.

(The issue with vo_x11 could be easily solved by always backing up the
same bounding box as the bitmap drawing RGB<->YUV conversion does, but
this commit is probably the better fix.)
2012-11-22 15:26:38 +01:00
wm4 ea4332daf4 vo_xv: don't require frame stepping to remove OSD or subs
In order to improve performance, vo_xv didn't create a backup of the
video frame before drawing OSD and subtitles during normal playback. It
required the frontend to do frame stepping if it wanted to redraw the
OSD, but no backup of the video frame was available. (Consider the
following use case: enable the OSD permanently with --osd-level=3, then
pause during playback and do something that shows an OSD message. The
player will advance the video by one frame at the time the new OSD
message is first drawn.)

This also meant that taking a screenshot during playback with vo_xv
would include OSD and subtitles in the resulting image.

Fix this by always creating a backup before drawing OSD or subtitles.
In order to avoid having to create a full copy of the whole image frame,
introduce a complex scheme that tries to backup only the changed
regions.

It's unclear whether the additional complexity in draw_bmp.c for
backing up only the changed areas of the frame is worth it. Possibly
a simpler implementation would suffice, such as tracking only Y ranges
of changed image data, or even just copying the full frame.

vo_xv's get_screenshot() now always creates a copy in order not to
modify the currently displayed frame.
2012-11-21 19:56:59 +01:00
wm4 4873b32c59 Rename directories, move files (step 2 of 2)
Finish renaming directories and moving files. Adjust all include
statements to make the previous commit compile.

The two commits are separate, because git is bad at tracking renames
and content changes at the same time.

Also take this as an opportunity to remove the separation between
"common" and "mplayer" sources in the Makefile. ("common" used to be
shared between mplayer and mencoder.)
2012-11-12 20:08:18 +01:00
wm4 f4069259cf draw_bmp: remove swscale bug workaround
ffmpeg ticket #1852 is fixed with 425c30dda. This didn't actually happen
in practice.
2012-11-01 02:07:46 +01:00
wm4 9ba52ea6ef screenshot, draw_bmp: use colorspace passed with mp_image
Remove the explicit struct mp_csp_details parameters from all related
functions, and use mp_image.colorspace/levels instead.
2012-11-01 02:07:45 +01:00
wm4 d072e857d7 csputils: better support for integer color values 2012-10-28 15:31:32 +01:00
wm4 65b313a8b0 draw_bmp, csputils: use function instead of macro 2012-10-28 15:31:32 +01:00
wm4 18d4eebedb draw_bmp: cosmetics, refactor
Mostly pedantic bikeshedding issues.

Move some code around, so that the sub_bitmap_to_mp_images() function
can be split into two parts. This is better than having a big function
with many input and outputs, of which only half are used in each code
path.

Also, try to make code simpler by using a mp_rect type.
2012-10-28 15:31:31 +01:00
wm4 f50d0b16e0 draw_bmp: remove CONDITIONAL2 code
This was sometimes slower, sometimes slightly faster. Remove it.
2012-10-24 23:12:26 +02:00
wm4 2afd7ebb4e options: remove subtitle related options that did nothing
Most of these cased working when the OSD was switched to libass, or
didn't do anything even before that.

Also don't recursively include subreader.h in sub.h.
2012-10-24 21:56:35 +02:00
Rudolf Polzer e1e056fe5d draw_bmp: fix IMGFMT_BGR32 use 2012-10-24 21:56:35 +02:00
wm4 4b4e4b5690 draw_bmp: fix for yuy2 format
mp_get_chroma_shift() modifies its argument even if it fails, so we have
to restore that.

mp_image didn't set chroma shifts for yuy2.
2012-10-24 21:56:34 +02:00
wm4 a4f9077f6c draw_bmp: don't try to call swscale if image format not supported
If that happens, we silently fail.
2012-10-24 21:56:34 +02:00