Commit Graph

5465 Commits

Author SHA1 Message Date
wm4 a3824d508e video: print filter chain in verbose mode
Somewhat useful to see where filters are auto-inserted and which formats
they take.
2013-01-14 19:19:23 +01:00
wm4 8f5ef883c1 img_format: do not mark hwaccel formats as planar yuv formats 2013-01-14 18:37:17 +01:00
wm4 f0a08a9fdf gl_common: move things used by vo_opengl_old.c only to vo_opengl_old.c
Having this in gl_common is confusing.
2013-01-13 23:30:13 +01:00
wm4 4056765643 vd_lavc: remove -lavdopts vstats suboption
This printed per-frame statistics into a file, like bitrate or frame
type. Not very useful and accesses obscure AVCodecContext fields
(danger of deprecation/breakage), so get rid of it.
2013-01-13 23:30:12 +01:00
wm4 8e172afc8f vd_lavc: remove lowres decoding
This was a "broken misfeature" according to Libav developers. It wasn't
implemented for modern codecs (like h264), and has been removed from
Libav a while ago (the AVCodecContext field has been marked as
deprecated and its value is ignored). FFmpeg still supports it, but
isn't much useful due to aforementioned reasons.

Remove the code to enable it.
2013-01-13 23:29:30 +01:00
Rudolf Polzer aaa27ead86 vo_x11: use two buffers like Xv 2013-01-13 22:36:42 +01:00
Rudolf Polzer 4044754d24 vo_x11, vo_xv: XShmCompletion event support
This fixes OSD flicker with vo_xv at high frame rates.
2013-01-13 22:36:42 +01:00
wm4 9f27ebbe63 vo_direct3d: remove 2ch hack for 10 bit playback
This was an awkward hack that attempted to avoid the use of 16 bit
textures, while still allowing rendering 10-16 bit YUV formats. The
idea was that even if the hardware doesn't support 16 bit textures,
an A8L8 textures could be used to convert 10 bit (etc.) to 8 bit in
the shader, instead of doing this on the CPU.

This was an experiment, disabled by default, and was (probably) rarely
used. I've never heard of this being used successfully. Remove it.
2013-01-13 20:04:14 +01:00
wm4 dd89c542e3 vo_sdl: avoid copying just for taking screenshots
Use reference counting instead.
2013-01-13 20:04:14 +01:00
wm4 bd6470ec6a vd_lavc: prefer AVFrame over AVCodecContext fields
This is more correct. Not all frame specific fields are in AVFrame,
such as colorspace and color_range, and these are still queried
through the decoder context.
2013-01-13 20:04:13 +01:00
wm4 1800761a65 mp_image: remove mp_image.bpp
This field contained the "average" bit depth per pixel. It serves no
purpose anymore. Remove it.

Only vo_opengl_old still uses this in order to allocate a buffer that is
shared between all planes.
2013-01-13 20:04:13 +01:00
wm4 61e59cd92c imgfmt: add more ffmpeg pixel formats
Most of these probably don't have much actual use, but at least allow
images of these formats to be handed to swscale, should any decoder
output them.
2013-01-13 20:04:13 +01:00
wm4 4950513ffe img_format: change meaning of MP_IMGFLAG_PLANAR
This used to mean that there is more than one plane. This is not very
useful: IMGFMT_Y8 was not considered planar, but it's just a Y plane,
and could be treated the same as actual planar formats. On the other
hand, IMGFMT_NV12 is partially packed, and usually requires special
handling, but was considered planar.

Change its meaning. Now the flag is set if the format has a separate
plane for each component. IMGFMT_Y8 is now planar, IMGFMT_NV12 is not.
As an odd special case, IMGFMT_MONO (1 bit per pixel) is like a planar
RGB format with a single plane.
2013-01-13 20:04:13 +01:00
wm4 4b8122faa7 vf_sub: allow more formats, simplify code
In theory, vf_sub could take any format supported by swscale. But to be
sure that it's reasonably fast, only 420P was allowed. However, other
similar 8 bit planar formats will be just as fast and there's no reason
to exclude them. Even for completely different formats there doesn't
seem to be any significant advantage to force vf_sub to convert to a
simpler/more common format.
2013-01-13 20:04:13 +01:00
wm4 c3788543f5 vf_expand: support more image formats
This did random things with some image formats, including 10 bit
formats. Fixes the mp_image_clear() function too.

This still has some caveats:
- doesn't clear alpha to opaque (too hard with packed RGB, and is rarely
  needed)
- sets luma to 0 for mpeg-range YUV, instead of the lowest possible
  value (e.g. 16 for 8 bit)
2013-01-13 20:04:13 +01:00
wm4 e16fab8822 vf_rotate: support more image formats 2013-01-13 20:04:13 +01:00
wm4 54dffdbbe6 vf_softpulldown: reject unsupported image formats, fix code duplication
Not really tested.
2013-01-13 20:04:13 +01:00
wm4 a26d602024 vf_yadif: Y8 is not supported
Crashes.
2013-01-13 20:04:13 +01:00
wm4 8d6a66892e vf_swapuv: support more image formats 2013-01-13 20:04:13 +01:00
wm4 d88baf0754 vf_pullup: remove check for MP_IMGFLAG_PLANAR
It supports 420p only, so the check is useless.
2013-01-13 20:04:12 +01:00
wm4 c70cb26a1e vf_phase: reject unsupported image formats
Also don't use MP_IMGFLAG_PLANAR.
2013-01-13 20:04:12 +01:00
wm4 92a1b6fa21 vf_mirror: rewrite
Properly handle odd image sizes. Probably makes it work with more image
formats.
2013-01-13 20:04:12 +01:00
wm4 e0d028e89b vf_gradfun: does not work with NV pixel formats 2013-01-13 20:04:12 +01:00
wm4 036d38580a vf_flip: make it work with more image formats 2013-01-13 20:04:12 +01:00
wm4 ba2e20414a vf_divtc: reduce code duplication 2013-01-13 20:04:12 +01:00
wm4 f282d0b290 vf_crop: make it work with more image formats 2013-01-13 20:04:12 +01:00
wm4 926c6631ff vf: add vf_rescale_dsize()
Needed because mplayer* basically tracks DAR, which makes it harder for
filters which want to keep the SAR.

The contents of this function are duplicated in a few filters, and will
be used instead of custom code as the filters are updated later.
2013-01-13 20:04:12 +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 ded932dbd4 vo_image: render subs
This makes it behave like vo_lavc.

Unfortunately, the code for setting up the OSD dimensions (mp_osd_res)
is copied from vo_lavc, but it doesn't look like something that should
be factored out.
2013-01-13 20:04:12 +01:00
wm4 5e8b3e74ec vo_xv: fix OSD redrawing flicker
redraw_frame() copied the image into the currently visible buffer. This
resulted in flicker when doing heavy OSD redrawing (like changing the
subtitle size to something absurdly large).

Use the same logic as draw_image instead.
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 1c65428d6f sub: do not copy the target image if there is no OSD/subs
It's not easy to tell whether the OSD/subs are empty, or if something is
drawn. In general you have to use osd_draw() with a custom callback. If
nothing is visible, the callback is never invoked. (The actual reason
why this is so "hard" is the implementation of osd_libass.c, which
doesn't allow separating rendering and drawing of OSD elements, because
all OSD elements share the same ASS_Renderer.)

To simplify avoiding copies, make osd_draw_on_image() instead of the
caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(),
which works like osd_draw_on_image(), but gets the new image allocation
from an image pool. This is supposed to be an optimization, because it
reduces the frequency of large allocations/deallocations for image data.

The result of this is that the frequency of copies needed in conjunction
with vf_sub, screenshots, and vo_lavc (encoding) should be reduced.
vf_sub now always does true pass-through if no subs are shown.

Drop the pts check from vf_sub. This didn't make much sense.
2013-01-13 20:04:12 +01:00
wm4 233cc15be9 vo_lavc: use reference counting
Helps avoiding additional copies.
2013-01-13 20:04:11 +01:00
wm4 5830d639b8 video: remove img_format compat hacks
Remove the strange things the old mp_image_setfmt() code did to the
image format parameters. This includes setting chroma shift to 31 for
gray (Y8) formats and more.

Y8 + vo_opengl_old didn't actually work for unknown reasons (regression
in this branch). Fix this. The difference is that Y8 is now interpreted
as gray RGB (LUMINANCE texture) instead of involving YUV (and levels)
conversion.

Get rid of distinguishing RGB and BGR. There wasn't really any good
reason for this.

Remove mp_get_chroma_shift() and IMGFMT_IS_YUVP16*(). mp_imgfmt_desc
gives the same information and more.
2013-01-13 20:04:11 +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 8751a0e261 video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)

Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.

Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)

The TV code has not been tested.

Some corrective changes regarding endian and other image format flags
creep in.
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 15c7f7a339 video: cleanup: move and rename vf_mpi_clear and vf_clone_attributes
These functions weren't specific to video filters and were misplaced
in vf.c. Move them to mp_image.c.

Fix the big endian test in vf_mpi_clear/mp_image_clear, which has been
messed up in 74df1d.
2013-01-13 20:04:11 +01:00
wm4 aa6ba6372c mp_image: change how palette is handled
According to DOCS/OUTDATED-tech/colorspaces.txt, the following formats
are supposed to be palettized:

    IMGFMT_BGR8
    IMGFMT_RGB8,
    IMGFMT_BGR4_CHAR
    IMGFMT_RGB4_CHAR
    IMGFMT_BGR4
    IMGFMT_RGB4

Of these, only BGR8 and RGB8 are actually treated as palettized in some
way. ffmpeg has only one palettized format (AV_PIX_FMT_PAL8), and
IMGFMT_BGR8 was inconsistently mapped to packed non-palettized RGB
formats too (AV_PIX_FMT_BGR8). Moreover, vf_scale.c contained messy
hacks to generate a palette when AV_PIX_FMT_BGR8 is output. (libswscale
does not support AV_PIX_FMT_PAL8 output in the first place.)

Get rid of all of this, and introduce IMGFMT_PAL8, which directly maps
to AV_PIX_FMT_PAL8. Remove the palette creation code from vf_scale.c.
IMGFMT_BGR8 maps to AV_PIX_FMT_RGB8 (don't ask me why it's swapped),
without any palette use. Enabling it in vo_x11 or using it as vf_scale
input seems to give correct results.
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 00653a3eb0 video: use libavutil pixel format descriptors
Replace the internal pixel format stuff with code that queries the
libavutil list of pixel format descriptors.

Trying to map IMGFMT_IS_RGB() etc. turned out extremely hacky.
2013-01-13 20:04:10 +01:00
wm4 6e0b730044 vf_screenshot: simplify
Instead of using a callback to "capture" the image next time the filter
function is called, do it the other way around: on every filter
invocation, create a reference to the image, and return it if a
screenshot is requested. This also fixes the 1-frame delay when taking
screenshots with the filter.

This also allows simplifying screenshot.c.
2013-01-13 20:04:10 +01:00
wm4 b7cacf9165 video/out: replace VFCAP_TIMER with vo->untimed, fix vo_image and vo_lavc
VFCAP_TIMER disables any additional waiting done by mpv in the
playloop. Remove VFCAP_TIMER, but re-use the idea for vo_image and
vo_lavc.

This means --untimed doesn't have to be passed when using --vo=image.
2013-01-13 20:04:10 +01:00
wm4 1f32250629 vd_lavc: make non-reference frames writeable
This allows avoiding a copy.

The logic about using the AVFrame.reference field if buffer hints are
not available is similar to mplayer-svn's direct rendering code. This is
needed because h264 decoding doesn't set buffer hints.

<wm4> michaelni: couldn't it set buffer hints from AVFrame.reference then?
<michaelni> i see no reason ATM why that wouldnt be possible

OK...
2013-01-13 20:04:10 +01:00
wm4 1b9d4a771a video: remove things related to old DR code
Remove mp_image.width/height. The w/h members are the ones to use.
width/height were used internally by vf_get_image(), and sometimes for
other purposes.

Remove some image flags, most of which are now useless or completely
unused. This includes VFCAP_ACCEPT_STRIDE: the vf_expand insertion in
vf.c does nothing.

Remove some other unused mp_image fields.

Some rather messy changes in vo_opengl[_old] to get rid of legacy
mp_image flags and fields. This is left from when vo_gl supported DR.
2013-01-13 20:04:10 +01:00
wm4 c54fc507da video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().

Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).

Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.

Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2013-01-13 20:04:10 +01:00
wm4 1c412169ac vo_caca: accept any stride for output image
Similar to previous commit.
2013-01-13 17:39:32 +01:00
wm4 4570a04a17 vo_corevideo: use stride
The code was entirely correct, as the VO doesn't report VFCAP_ACCEPT_STRIDE
in query_format. Add stride capability in preparation for changing the
video chain: soon all VOs will have to support arbitrary strides.
2013-01-13 17:39:32 +01:00
wm4 f4a95058c7 vo_corevideo: correct stride usage
The code assumed mp_image_alloc() would allocate an image large enough
for corevideo's stride, which doesn't have to be the case. If
corevideo's stride was larger than the stride of mp_image, the memcpy()
would write beyond the mp_image allocation.

This probably didn't actually happen, but fix the code to be more
correct anyway.
2013-01-13 17:39:32 +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
wm4 1568161aad mp_image_pool: add pool to avoid frequent image reallocations
Refcounting will conceptually allocate and free images all the time
when using the filter chain. Add a pool that makes these reallocations
cheap.

This only affects the image data, not mp_image structs and similar small
allocations. Small allocations are always fast with reasonable memory
managers, while large image data will trigger mmap/munmap calls each
time.
2013-01-13 17:39:32 +01:00
wm4 881f82dd33 vd_lavc: use refcounting
Note that if the codec doesn't support DR1, the image has to be copied.
There is no other way to guarantee that the image will be valid after
decoding the next image.

The only important codec that doesn't support DR1 yet is rawvideo. It's
likely that ffmpeg/Libav will fix this at some time. For now, this
decoder uses an evil hack and puts pointers to the packet data into the
returned frame. This means the image will actually get invalid as soon
as the corresponding video packet is free'd, so copying the image is the
only reasonable thing anyway.
2013-01-13 17:39:32 +01:00
wm4 65a0b5fdc6 mp_image: refcounting helpers 2013-01-13 17:39:32 +01:00
wm4 a8e69707f7 vd_lavc: add DR1 support
Replace libavcodec's native buffer allocation with code taken from
ffplay/ffmpeg's libavfilter support. The code in lavc_dr1.c is directly
copied from cmdutils.c. Note that this is quite arcane code, which
contains some workarounds for decoder bugs and the like. This is not
really a maintainance burden, since fixes from ffmpeg can be directly
applied to the code in lavc_dr1.c.

It's unknown why libavcodec doesn't provide such a function directly.
avcodec_default_get_buffer() can't be reused for various reasons.
There's some hope that the work known as The Evil Plan [1] will make
custom get_buffer implementations unneeded.

The DR1 support as of this commit does nothing. A future commit will
use it to implement ref-counting for mp_image (similar to how AVFrame
will be ref-counted with The Evil Plan.)

[1] http://lists.libav.org/pipermail/libav-devel/2012-December/039781.html
2013-01-13 17:39:32 +01:00
wm4 58d196c07e video: different way to enable hardware decoding, add software fallback
Deprecate the hardware specific video codec entries (like ffh264vdpau).
Replace them with the --hwdec switch, which requests that a specific
hardware decoding API should be used. The codecs.conf entries will be
removed at a later time, but for now they are useful for testing and
compatibility.

Instead of --vc=ffh264vdpau, --hwdec=vdpau should be used.

Add a fallback if hardware decoding fails. Most hardware decoders
(including vdpau) support only a subset of h264, and having such a
fallback is supposed to enable a better user experience.
2013-01-13 17:39:32 +01:00
wm4 dab286a159 vd_lavc: remove codec DR
This was buggy and didn't even work in the simplest cases. It was
disabled when multithreading was used, and always disabled for h264.

A better alternative (reference counting) will be added later.

Hardware decoding still uses the ffmpeg DR mechanism, but has been
decoupled from mpv's DR in the previous commit.
2013-01-13 17:39:32 +01:00
wm4 2d8fb838d7 video: make vdpau hardware decoding not use DR code path
vdpau hardware decoding used the DR (direct rendering) path to let the
decoder query a surface from the VO. Special-case the HW decoding path
instead, to make it separate from DR.
2013-01-13 17:39:32 +01:00
wm4 0d1aca1289 vd_lavc: do not mutate global threads option
This mutated the variable for the thread count option
(lavc_param->threads) on decoder initialization. This didn't have any
practical relevance, unless formats supporting hardware video decoding
and other formats were played in the same mpv instance. In this case,
hardware decoding would set threads to 1, and all files played after
that would use only one thread as well even with software decoding.

Remove XvMC leftover (CODEC_CAP_HWACCEL).
2013-01-13 17:39:31 +01:00
wm4 fcd6e74e48 vd_lavc: cosmetics: move debugging code out of the way
Relatively useless statistics printing code was stuffed directly into
the middle of the central decode() function. Move it away.
2013-01-13 17:39:31 +01:00
wm4 06ccd9f671 video: simplify decoder pixel format handling
Simplify the decoder pixel format handling by making it handle only
the case vd_lavc needs: a video stream always decodes to a single
pixel format.

Remove the handling for multiple pixel formats, and remove the
codecs.conf pixel format declarations that are left.

Remove the handling of "ambiguous" pixel formats like YV12 vs. I420 (via
VDCTRL_QUERY_FORMAT etc.). This is only a problem if the video chain
supports I420, but not YV12, which doesn't seem to be the case anywhere,
and in fact would not have any advantage.

Make the "flip" flag a global per-codec flag, rather than a pixel format
specific flag. (Some ffmpeg decoders still return a flipped image, so
this has to be done manually.) Also fix handling of the flip operation:
do not overwrite the global flip option, and make the --flip option
invert the codec flip option rather than overriding it.
2013-01-13 17:39:31 +01:00
wm4 42e0afe641 vo_direct3d: simplify 2013-01-13 17:39:31 +01:00
wm4 49e7f5ba42 vo_xv: simplify
We can do this because slice support has been removed.
2013-01-13 17:39:31 +01:00
wm4 23ab098969 video: remove slice based filtering and video output
Slices allowed filtering or drawing video in horizontal bands or
blocks. This allowed working on the video in smaller units. In theory,
this could bring a performance win by lowering cache pressure, as you
didn't have to keep the whole video frame in cache while filtering,
only the slice.

In practice, the slice code path was barely used for the following
reasons:
- Multithreaded decoding with ffmpeg didn't use slices. The ffmpeg
  slice callback was disabled, because it can be called from another
  thread, and the mplayer video chain is not thread-safe.
- There was nothing that would turn "full" images into appropriate
  slices, so slices were rarely used.
- Most filters didn't actually support slices.

On the other hand, supporting slices lead to code duplication and more
complex code in general. I made some experiments and didn't find any
actual measurable performance improvements when using slices. Even
ffmpeg removed slices based filtering from libavfilter in favor of
simpler code.

The most broken thing about the slices code path is that slices can't
be queued, like it is done for images in vo.c.
2013-01-13 17:39:31 +01:00
wm4 cfa1f9e082 video: make vdpau hardware decoding not use slices code path
For some reason, libavcodec abuses the slices rendering code path for
hardware decoding: in that case, the only purpose of the draw callback
is to pass a vdpau video surface object to video output. (It is unclear
to me why this had to use the slices code, instead of just returning an
AVFrame with the required vdpau state.)

Make this code separate within mpv, so that the internal slices code
path is not used for hardware decoding. Pass the vdpau state with
VOCTRL_HWDEC_DECODER_RENDER instead.

Remove the mencoder specific VOCTRLs.
2013-01-13 17:39:31 +01:00
wm4 58d3469fd6 video/out: replace VOCTRL_QUERY_FORMAT with vo_driver.query_format 2013-01-13 17:39:31 +01:00
wm4 191bcbd1f2 video/out: make draw_image mandatory, remove VOCTRL_DRAW_IMAGE
Remove VOCTRL_DRAW_IMAGE and always set vo_driver.draw_image in VOs.
Make draw_image mandatory: change some VOs (like vo_x11) to support it,
and remove the image-to-slices fallback in vf_vo.

Remove vo_driver.is_new. This member indicated whether draw_image is
supported unconditionally, which is now always the case.

draw_image_pts is a hack until the video filter chain is changed to
include the PTS as field in mp_image. Then vo_vdpau and vo_lavc will
be changed to use draw_image.
2013-01-13 17:39:31 +01:00
wm4 fe6c93eab8 configure: remove check for .align semantics
The check determined whether the argument for .align is in bytes, or
log2(bytes). Apparently it's always in bytes for ELF i386 systems, and
this check is used for x86 inline assembler only. Even if this
assumption should be wrong, it likely won't cause much damage: the
existing code uses it only in the form ".align 4", which means in the
worst case it will try to align to 16 bytes, which doesn't cause any
problems (unless the object file format does not support such a high
alignment).

Update the filters that used this.

Quoting the GNU as manual:

For other systems, including ppc, i386 using a.out format, arm and
strongarm, it is the number of low-order zero bits the location counter
must have after advancement. For example `.align 3' advances the
location counter until it a multiple of 8. If the location counter is
already a multiple of 8, no change is needed.
2013-01-13 14:10:43 +01:00
Rudolf Polzer 3996e8882d vo_sdl: fix for rename of a function in SDL2's interface 2013-01-12 21:15:53 +01:00
Rudolf Polzer 6c79888f7d vo_sdl: add a "sw" flag like in opengl
Also, rework the renderer creation for the flag being generally
effective even if the "SW renderer" is detected only after creating a
context.
2013-01-10 12:34:40 +01:00
wm4 413b2e3b0f vo_xv: fix compilation when shared memory header files are not available
This is an extremely obscure situation, but can actually happen
on OpenBSD.
2013-01-06 21:44:15 +01:00
Stefano Pigozzi 59868da7a1 cocoa_common: add support for `--no-border`
Draw a window with style NSBorderlessWindow when the user uses `--no-border`.
2012-12-31 14:20:49 +01:00
Rudolf Polzer 56e18d99aa vo_sdl: support -geometry properly
Now the x and y origin options (-geometry WxH+X+Y) are supported too.
2012-12-31 08:44:53 +01:00
Rudolf Polzer a313af3d02 vo_sdl: some OSD optimizations
The premultiplied-alpha hack is changed:

- The first stage now uses a colormod of black with an unmodified
  texture. This saves on applying the AND mask of 0xFF000000 to keep
  alpha only.

- The second stage no longer uses an AND mask, but only an OR mask of
  0xFF000000 to cancel out alpha.

- The texture uploads are no longer done using SDL_LockTexture,
  SDL_ConvertPixels, SDL_UnlockTexture when the mpv pixel format matches
  the OSD's pixel format. Instead, SDL_UploadTexture is used, which
  saves a copy when using the "opengl" renderer.
2012-12-28 14:27:12 +01:00
wm4 973f34bb56 vf_scale: prefer 420P10 -> YV12 instead of 444P
Strictly speaking, 444P is higher quality than YV12, but doing this is
not very useful when playing 10 bit video with -vo opengl-old on a GPU
that doesn't support 16 bit textures.
2012-12-28 14:23:29 +01:00
wm4 d78bde15ab vo_opengl_old: reject 9-15 bit formats if textures have less than 16 bit
For 9-15 bit material, cutting off the lower bits leads to significant
quality reduction, because these formats leave the most significant bits
unused (e.g. 10 bit padded to 16 bit, transferred as 8 bit -> only
2 bits left). 16 bit formats still can be played like this, as cutting
the lower bits merely reduces quality in this case.

This problem was encountered with the following GPU/driver combination:

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) 915GM x86/MMX/SSE2
OpenGL version string: 1.4 Mesa 9.0.1

It appears 16 bit support is rather common on GPUs, so testing the
actual texture depth wasn't needed until now. (There are some other Mesa
GPU/driver combinations which support 16 bit only when using RG textures
instead of LUMINANCE_ALPHA. This is due to OpenGL driver bugs.)
2012-12-28 14:23:29 +01:00
wm4 1e56e68701 gl_common: properly reject old OpenGL versions
The extension checking logic was broken, which reported OpenGL 3 if the
OpenGL .so exported OpenGL 3-only symbols, even if the reported OpenGL
version is below 3.0. Fix it and simplify the code a bit. Also never
fail hard if required functions are not found. The caller should check
the capability flags instead. Give up on the idea that we should print
a warning if essential functions are not found (makes loading of ancient
legacy-only extensions easier).

This was experienced with the following version strings:

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) 915GM x86/MMX/SSE2
OpenGL version string: 1.4 Mesa 9.0.1

(Possibly reports a very old version because it has no GLSL support,
and thus isn't even GL 2.0 compliant.)
2012-12-28 14:23:29 +01:00
nand b32f2ef0d3 vo_opengl: use more precise gamma for BT.709 with color management
Change from gamma 2.2 to the slightly more precise 1/0.45 as per BT.709.

https://www.itu.int/rec/R-REC-BT.709-5-200204-I/en mentions a value of
γ=0.45 for the conceptual non-linear precorrection of video signals.

This is approximately the inverse of 2.22, and not 2.20 as the code had
been using until now.
2012-12-28 13:43:24 +01:00
Rudolf Polzer 6be50fa773 sdl, encode_lavc: fix copyright headers
Some of them had changes in 2012; extend their header.

Fix project name.
2012-12-28 11:41:30 +01:00
Rudolf Polzer 73900ca1c3 vdpau: silence a clang warning
It's just some braces...
2012-12-28 10:46:02 +01:00
Rudolf Polzer c3cc38e4c4 vo/ao: SDL 1.2+ audio driver, SDL 2.0+ accelerated video driver
This mainly serves as a fallback for platforms where nothing better is
available; also as a debugging help. Both the audio and video driver are
not first class - the audio driver lacks delay detection, and the video
driver only supports a single YUV color space.

Configure options: --disable-sdl2 to disable SDL 2.0+ detection,
--disable-sdl to disable SDL 1.2+ detection. Both options need to be
specified to turn off SDL support entirely.
2012-12-28 08:40:28 +01:00
Rudolf Polzer e830b00458 vf_scale: support more pixel formats
The RGBA, ARGB, BGRA, ABGR were previously not always supported,
depending on system endianness.
2012-12-28 08:31:58 +01:00
Rudolf Polzer 7d0a20954f core: make WAKEUP_PERIOD overridable by the vo
This is better than having just the operating system type decide the
wakeup period, as e.g. when compiling for Win32/cygwin, a wakeup period
of 0.5 would work perfectly fine.

Instead, the default wakeup period is now only decided by availability
of a working select() system call (which is the case on cygwin but not
mingw and MSVC) AND a vo that can provide an event file descriptor or a
similar hack (vo_corevideo). vos that cannot do either need polling for
event handling and now can set the wakeup period to 0.02 in the vo code.
2012-12-19 12:58:52 +01:00
wm4 5f999d94df video: silence warnings for missing libavutils pixel formats
Using vf_screenshot on Libav printed useless/misleading error messages
when playing 10 bit h264 with a VO that supports 8 bit yuv420p only:

    Unsupported format 444p14le
    Unsupported format 444p14be
    ...

The cause of this is that vf_scale is inserted to handle the format
conversion, and tries to find a pixel format with best quality. This
includes the 14 bit and 12 bit formats, which don't exist on Libav.
vf_screenshot tries to query whether Libav's libswscale supports it,
resulting in these error messages. (In theory, vf_scale is missing this
check, but it doesn't matter in practice.)

Since this warning is rather useless anyway, because all input video
comes from libavcodec, and only the conversion into the other could
possibly fail. Silence the warning by raising it to verbose message
level.

Closes #7.
2012-12-14 21:34:56 +01:00
wm4 c3f8c9a58e options: move -ass-bottom-margin/-ass-top-margin options to vf_sub
These options might be useful sometimes, but they are not that
important, and work with vf_sub only. Make them vf_sub sub-options.
2012-12-12 23:35:34 +01:00
wm4 69e1338834 vf_sub: fix aspect ratio when using margins 2012-12-12 23:35:24 +01:00
wm4 6c1c04ba21 Fix compilation with Libav
Libav doesn't have 12/14 bit planar formats.
2012-12-04 09:22:57 +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 3b4682183c vo_xv: try harder to get correctly aligned pointers/strides
To get guaranteed alignment for the chroma planes with typical YV12
playback, we have to double the alignment on the image width, as the
chroma planes have half the image width.

Clear the image with black instead of green to hide scaling artifacts
on the right border of the screen.

(It might be possible to create the image layout ourselves by not
calling XvShmCreateImage(), and filling in our own image width and exact
strides, but that's probably too risky: the Xv client library sends an
X protocol request to query the real image dimension and strides. It is
unknown to me whether X servers or drivers would generally accept an
image with mismatching parameters, even if the image is conceptually
valid.)

Allocate the image with av_malloc() in the non-SHM case. I suspect the
non-SHM case doesn't matter much, though.
2012-12-03 21:08:51 +01:00
Stefano Pigozzi 54d998d5e7 osx_common: Avoid deprecated Gestalt calls
Gestalt is deprecated since 10.8. Change the code to read the OS version from
a system plist file.

As mentioned http://stackoverflow.com/a/11072974/499456 Apple engineers are
suggesting this plist reading approach.
2012-12-02 10:42:46 +01:00
wm4 24bfa82a91 sub: reimplement -spugauss as --sub-gauss
Apparently the -spugauss option was popular. The code originally
implementing this is gone (scaler stuff in spudec.c). Reimplement it
using libswscale to scale and blur image subtitles if the --sub-gauss
option is set.

The code does some rather lazy padding to allow the blur to spread
pixels past the original image bounding box. (This problem exists with
normal bilinear scaling too, but is barely noticable.)

Technically, this doesn't just blur subtitles, but anything RGBA (or
indexed) that enters the OSD rendering path. But only image subtitles
produce these OSD formats currently, so no explicit check is done to
prevent blurring in other cases.
2012-11-25 23:40:07 +01:00
wm4 2bd7f980ac memcpy_pic: kill useless/dangerous optimization
The memcpy_pic() function had a rather dangerous optimization: when the
limit2width flag was not set, it was allowed to overwrite the data
between the last pixel of a line and the first pixel of the next line
(i.e. write over the stride padding). That was also the reason why there
are so many whacky names for this function (memcpy_pic, my_memcpy_pic,
memcpy_pic2).

Kill this optimization, and never overwrite the stride padding. The code
doing this can still be used if there's no stride padding at all,
though.

Also use the name memcpy_pic for the proper function. Now it should be
rather clear that my_memcpy_pic and memcpy_pic2 are compatibility
aliases. They should go away over the time.
2012-11-25 23:40:07 +01:00
wm4 4c21ad1f55 sws_utils: remove unused helper
sws_getContextFromCmdLine_hq() was used by the screenshot code, which
now uses mp_image_swscale().

Also move the mp_sws_set_colorspace() declaration from sws_utils.h to
vf_scale.c.
2012-11-24 21:27:34 +01:00
wm4 74f416fd2d vo_xv: allocate Xv images with aligned stride
This is required, as the Xv image is directly used for rendering OSD and
taking screenshots. These involve libswscale, which wants aligned
strides.

There doesn't seem to be an easy way to request aligned strides from Xv.
Simply request an image with an aligned width, which usually results in
an aligned stride. The padding border remains invisible.

One caveat is that if padding is added, there might be scaling artifacts
on the right pixel border of the screen. This is at least the case with
nvidia binary drivers. Since we consider vo_xv a sensible choice only on
crappy/slow hardware, performance is more important than quality.
2012-11-22 19:54:06 +01:00
wm4 1d3179a5f1 mp_image: make alloc_mpi() always allocate with aligned stride
By "design", mplayer normally allocates aligned images only inside the
filter chain, via the vf_get_image() function. This function pads the
width of the requested image if a stride is allowed, sets that new width
before calling mp_image_alloc_planes().

However, newer code wants aligned images as well (basically to satisfy
libswscale). This affects all uses of alloc_mpi(). To get aligned
strides, simply change alloc_mpi() to request an aligned width.

Remove the old hack in mp_image_alloc_planes(), which special cases some
image formats to be allocated with aligned strides.

This is a temporary hack until mp_image_alloc_planes() is revised.
2012-11-22 19:22:38 +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 10a1ae7b72 screenshot: add subs even with vf_screenshot
Until now, screenshots with the video filter didn't add subs (unclear
whether that was an oversight or feature). Fix this and make behavior
when taking screenshots with vf_screenshot more consistent with VO
screenshots.

The change in vf_screenshot is needed, because add_subs() checks this
flag to decide whether it's allowed to mutate the image.

This commit has another user visible side effect. When taking a
screenshot each frame (using the "each-frame" mode of the screenshot
command), a normal screenshot command will stop the each-frame mode.
2012-11-21 19:58:51 +01:00
wm4 4b91861b67 video: fix bogus uses of mp_image.w/width
mp_image has this confusing distinction between the w/h and width/height
fields. w/h are the actual width and height, while width/height have a
very special meaning inside the video filter code: it's the actually
allocated width, which is also used for stride padding.

Screenshot related code abused the w/h fields to store the aspect
corrected size. Some code confused the role of w/h and width/height.

Fix these issues. For aspect corrected size, display_w/h are used, while
width/height should never be used outside vf.c internals and related
code.

This also fixes an actual bug when taking screenshots of anamorphic
video with vf_screenshot, as well as using vo_image with such videos.
2012-11-21 19:58:51 +01:00
wm4 ed01dfeff3 vo_x11: don't require framestepping to update OSD
The OSD couldn't be updated at all without frame stepping. This made the
VO unusable (In fact, vo_x11 should never be used, but it's provided as
fail-safe fallback). Implement VOCTRL_REDRAW_FRAME to deal with this.

Unfortunately, this exposes issues with draw_bmp's subtitle rendering:
areas that are not covered by subtitles at all are changed as well. The
"backup" mechanism provided by draw_bmp doesn't copy these areas, which
turns up as quite visible artifacts. (These are included when taking
screenshots too.)
2012-11-21 19:58:16 +01:00
wm4 4757f9d0ce vo_x11: add screenshot support
Although vo_x11 shouldn't be used, it's a good thing to have screenshot
support in absolutely all interactive VOs. (Except vo_caca, but that is
literally a joke.)
2012-11-21 19:56:59 +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
Stefano Pigozzi 9125ba0a4f cocoa_common: create window in the correct screen 2012-11-21 13:42:55 +01:00
wm4 670a4a85a9 gl_common: improve Mesa compatibility for GL3 context creation
Don't request CONTEXT_FORWARD_COMPATIBLE when creating a GL3 context on
X11. This improves compatibility with some Mesa drivers.

Setting this bit was originally intended to make the code compatible
to newer (future, possibly not yet existing) OpenGL implementations.
These implementations wouldn't have to support deprecated legacy GL
features, which we know that we don't use, and could return a context
with a higher OpenGL version than requested.

In practice, this didn't work out. CONTEXT_FORWARD_COMPATIBLE requires
the driver to explicitly disable deprecated functionality. If it doesn't
do that, it has to reject context creation with that flag set. And it
turns out there are Mesa drivers which suffer from this caveat. See [1].

This probably also means that a GL application with a fixed set of
required GL features (such as a subset of GL 3.2 core, like vo_opengl.c)
may need to probe several GL versions if drivers really start dropping
legacy GL.

On Windows, CONTEXT_FORWARD_COMPATIBLE is still set. It is not known
if this is ideal, but fortunately there is no Mesa on Windows.

CONTEXT_CORE_PROFILE is still always set. For requested GL versions
lower than 3.2, this flag is ignored. Should we requires higher versions
later, we want it to be set, so don't remove it.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=57241
2012-11-20 18:00:16 +01:00
wm4 dcd2435e79 vf_softpulldown: fix possible regression
The lines added with this commit were accidentally removed in commit
a0d759, which was a pure cleanup commit merged from mplayer-svn. The
difference between mplayer-svn and the mplayer2 base is that this
filter has been made PTS aware in mplayer2.

Also remove the redundant initialization of vf->priv->state.
2012-11-20 18:00:15 +01:00
wm4 2628ff6224 options: remove --display
Was used to set the X11 display. XDisplayName(NULL) does the same,
using the DISPLAY environment variable instead.
2012-11-16 21:21:15 +01:00
wm4 1fa1ff7880 video/filter: rename vf_eq2 to vf_eq
vf_eq was deleted earlier, which makes the name vf_eq2 even more
awkward.
2012-11-16 21:21:14 +01:00
wm4 11ec5f19f2 vo_opengl: remove osdcolor suboption
This wasn't actually used since the old gray-alpha OSD rendering has
been removed. Removing the documentation for the vo_opengl_old osdcolor
suboption was forgotten as well.
2012-11-16 21:21:14 +01:00
wm4 53ee9aa6ae options, vo_x11: remove -zoom option, make it default
The -zoom option enabled scaling with vo_x11. Remove the -zoom option,
and make its behavior default. Since vo_x11 has to use libswscale for
colorspace conversion anyway, which doesn't do actual extra scaling when
vo_x11 is run in windowed mode, there should be no speed difference with
this change.

The code removed from vf_scale attempted to scale the video to d_width/
d_height, which matters for anamorphic video and the --xy option only.
vo_x11 can handle these natively. The only case for which the removed
vf_scale code could matter is encoding with vo_lavc, but since that
didn't set VOFLAG_SWSCALE, nothing actually changes.
2012-11-16 21:21:14 +01:00
wm4 e5f7976000 video: add IMGFMT_Y16/PIX_FMT_GRAY16
This pixel format is sometimes used with yuv4mpeg.

vo_direct3d used its own IMGFMT_Y16 internally for some reason.

vo_opengl, vo_opengl_old, and vo_direct3d should be able to display
this pixel format natively.
2012-11-14 11:50:02 +01:00
wm4 9fc682d46f Improve compatibility with Libav 0.8.4 and ffmpeg 0.11.2
Libav 0.8.4 is ridiculously old (in relative terms), so I don't know
how many things are broken silently.

Encoding is disabled, because the required API hasn't been added yet.
(On the other hand, the old API can't be used in newer versions.)

This should improve compatibility with ffmpeg 0.11.2 as well, which
didn't define AV_CODEC_ID_SUBRIP yet.
2012-11-14 11:45:52 +01:00
Stefano Pigozzi bec630c347 clang: fix all warnings except deprecations 2012-11-13 22:19:18 +01:00
Rudolf Polzer 9203f06cf3 vf_dlopen: fix a typo in zeroing memory (thanks, pigoz)
Accidentally had put the & inside the sizeof call too. Typing too fast.
2012-11-13 09:52:53 +01:00
wm4 90784dfc9d win32: remove pointless get/release DC wrappers 2012-11-12 20:10:42 +01:00
wm4 46cf722d80 Add missing compat/libav.h includes
For avcodec_free_frame().
2012-11-12 20:08:24 +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 d4bdd0473d Rename directories, move files (step 1 of 2) (does not compile)
Tis drops the silly lib prefixes, and attempts to organize the tree in
a more logical way. Make the top-level directory less cluttered as
well.

Renames the following directories:
    libaf -> audio/filter
    libao2 -> audio/out
    libvo -> video/out
    libmpdemux -> demux

Split libmpcodecs:
    vf* -> video/filter
    vd*, dec_video.* -> video/decode
    mp_image*, img_format*, ... -> video/
    ad*, dec_audio.* -> audio/decode

libaf/format.* is moved to audio/ - this is similar to how mp_image.*
is located in video/.

Move most top-level .c/.h files to core. (talloc.c/.h is left on top-
level, because it's external.) Park some of the more annoying files
in compat/. Some of these are relicts from the time mplayer used
ffmpeg internals.

sub/ is not split, because it's too much of a mess (subtitle code is
mixed with OSD display and rendering).

Maybe the organization of core is not ideal: it mixes playback core
(like mplayer.c) and utility helpers (like bstr.c/h). Should the need
arise, the playback core will be moved somewhere else, while core
contains all helper and common code.
2012-11-12 20:06:14 +01:00