Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VO xv segfaults when 4K is played #320

Closed
Nikoli opened this issue Oct 27, 2013 · 18 comments
Closed

VO xv segfaults when 4K is played #320

Nikoli opened this issue Oct 27, 2013 · 18 comments

Comments

@Nikoli
Copy link
Contributor

Nikoli commented Oct 27, 2013

For one of my systems playing 4K files causes mov segfault when vo xv is used:

$ mpv -V
mpv git-74e7043 (C) 2000-2013 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
libav library versions:
   libavutil       52.3.0
   libavcodec      54.35.0
   libavformat     54.20.3
   libswscale      2.1.1
   libavfilter     3.3.0
   libavresample   1.0.1

xf86-video-nouveau-1.0.9, mesa-9.1.6

bt:

Starting program: /usr/bin/mpv Sintel.2010.4K.DMRip.Hi444PP.x264.DTSMA.SRT-MaLLIeHbKa.mkv -vo xv
warning: Cannot call inferior functions, Linux kernel PaX protection forbids return to non-executable pages!
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x3a792d74700 (LWP 4171)]
[New Thread 0x3a79255a700 (LWP 4172)]

Program received signal SIGSEGV, Segmentation fault.
0x000003a79cd43c1b in ?? () from /lib64/libc.so.6
#0  0x000003a79cd43c1b in ?? () from /lib64/libc.so.6
No symbol table info available.
#1  0x0000005d0b646eb6 in memset (__len=2048, __ch=128, __dest=<optimized out>) at /usr/include/bits/string3.h:85
No locals.
#2  memset_pic (stride=1024, height=872, bytesPerLine=2048, fill=128, dst=<optimized out>) at video/memcpy_pic.h:67
        i = <optimized out>
#3  mp_image_clear (img=img@entry=0x3e3470a3c20, x0=x0@entry=0, y0=y0@entry=0, x1=x1@entry=4096, y1=<optimized out>) at video/mp_image.c:416
        bpp = <optimized out>
        bytes = 2048
        p = <optimized out>
        __PRETTY_FUNCTION__ = "mp_image_clear"
        area = {flags = 29441, fmt = {id = 1004, avformat = 0, name = 0x5d0b6a4ec4 "420p", flags = 29441, num_planes = 3 '\003', chroma_xs = 1 '\001', chroma_ys = 1 '\001', 
            align_x = 2 '\002', align_y = 2 '\002', bytes = "\001\001\001", bpp = "\b\b\b", plane_bits = 8 '\b', xs = "\000\001\001", ys = "\000\001\001"}, 
          imgfmt = IMGFMT_420P, num_planes = 3, chroma_x_shift = 1, chroma_y_shift = 1, w = 4096, h = 1744, display_w = 4096, display_h = 1744, planes = {0x3a790bf0000 "", 
            0x3a791032000 "\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200"..., 0x3a790f58000 "", 0x0}, stride = {2048, 1024, 
            1024, 0}, qscale = 0x0, qstride = 0, pict_type = 0, fields = 0, qscale_type = 0, chroma_width = 2048, chroma_height = 872, plane_w = {4096, 2048, 2048, 0}, 
          plane_h = {1744, 872, 872, 0}, colorspace = MP_CSP_BT_709, levels = MP_CSP_LEVELS_TV, chroma_location = MP_CHROMA_AUTO, pts = 0, refcount = 0x0, priv = 0x0}
        plane_clear = {0, 128, 128, 0}
#4  0x0000005d0b6907eb in allocate_xvimage (foo=0, vo=0x5d0bcef9f0) at video/out/vo_xv.c:528
        ctx = 0x5d0bce0640
        x11 = 0x5d0bcf46a0
        aligned_w = 4096
        img = {flags = 29441, fmt = {id = 1004, avformat = 0, name = 0x5d0b6a4ec4 "420p", flags = 29441, num_planes = 3 '\003', chroma_xs = 1 '\001', chroma_ys = 1 '\001', 
            align_x = 2 '\002', align_y = 2 '\002', bytes = "\001\001\001", bpp = "\b\b\b", plane_bits = 8 '\b', xs = "\000\001\001", ys = "\000\001\001"}, 
          imgfmt = IMGFMT_420P, num_planes = 3, chroma_x_shift = 1, chroma_y_shift = 1, w = 4096, h = 1744, display_w = 4096, display_h = 1744, planes = {0x3a790bf0000 "", 
            0x3a791032000 "\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200"..., 0x3a790f58000 "", 0x0}, stride = {2048, 1024, 
            1024, 0}, qscale = 0x0, qstride = 0, pict_type = 0, fields = 0, qscale_type = 0, chroma_width = 2048, chroma_height = 872, plane_w = {4096, 2048, 2048, 0}, 
          plane_h = {1744, 872, 872, 0}, colorspace = MP_CSP_BT_709, levels = MP_CSP_LEVELS_TV, chroma_location = MP_CHROMA_AUTO, pts = 0, refcount = 0x0, priv = 0x0}
#5  config (vo=0x5d0bcef9f0, width=<optimized out>, height=<optimized out>, d_width=<optimized out>, d_height=<optimized out>, flags=0, format=1004) at video/out/vo_xv.c:472
        x11 = 0x5d0bcf46a0
        ctx = 0x5d0bce0640
        i = <optimized out>
#6  0x0000005d0b660127 in vo_reconfig (vo=0x5d0bcef9f0, params=0x3e3470a3e10, flags=0) at video/out/vo.c:419
        d_width = 4096
        d_height = 1744
        p2 = {imgfmt = IMGFMT_420P, w = 4096, h = 1744, d_w = 4096, d_h = 1744, colorspace = MP_CSP_BT_709, colorlevels = MP_CSP_LEVELS_TV, chroma_location = MP_CHROMA_LEFT, 
          outputlevels = MP_CSP_LEVELS_AUTO}
        ret = <optimized out>
#7  0x0000005d0b64c06d in vf_reconfig_wrapper (vf=0x5d0bd0d790, p=0x3e3470a3e90, flags=0) at video/filter/vf.c:455
        params = {imgfmt = IMGFMT_420P, w = 4096, h = 1744, d_w = 4096, d_h = 1744, colorspace = MP_CSP_BT_709, colorlevels = MP_CSP_LEVELS_TV, 
          chroma_location = MP_CHROMA_LEFT, outputlevels = MP_CSP_LEVELS_AUTO}
        r = <optimized out>
#8  0x0000005d0b64c06d in vf_reconfig_wrapper (vf=0x5d0c620780, p=p@entry=0x3e3470a3f30, flags=flags@entry=0) at video/filter/vf.c:455
        params = {imgfmt = IMGFMT_420P, w = 4096, h = 1744, d_w = 4096, d_h = 1744, colorspace = MP_CSP_BT_709, colorlevels = MP_CSP_LEVELS_TV, 
          chroma_location = MP_CHROMA_LEFT, outputlevels = MP_CSP_LEVELS_AUTO}
        r = <optimized out>
#9  0x0000005d0b64954a in mpcodecs_reconfig_vo (sh=sh@entry=0x5d0ba89f40, params=params@entry=0x3e3470a3fe0) at video/decode/vd.c:148
        opts = 0x5d0ba434e0
        vf = 0x5d0c620780
        vocfg_flags = 0
        p = {imgfmt = IMGFMT_444P10_LE, w = 4096, h = 1744, d_w = 4096, d_h = 1744, colorspace = MP_CSP_BT_709, colorlevels = MP_CSP_LEVELS_TV, 
          chroma_location = MP_CHROMA_LEFT, outputlevels = MP_CSP_LEVELS_AUTO}
        flags = <optimized out>
        flip = false
        force_aspect = <optimized out>
#10 0x0000005d0b64aa15 in decode (sh=sh@entry=0x5d0ba89f40, packet=packet@entry=0x5d0c1a90f0, flags=flags@entry=0, reordered_pts=reordered_pts@entry=0x3e3470a4218, 
    out_image=out_image@entry=0x3e3470a41b0) at video/decode/vd_lavc.c:754
        got_picture = 1
        ret = <optimized out>
        ctx = 0x5d0c085a00
        pic = 0x5d0c085ae0
        avctx = <optimized out>
        pkt = {pts = -9223372036854775808, dts = -9223372036854775808, data = 0x5d0c18aad0 "", size = 206, stream_index = 0, flags = 0, side_data = 0x0, side_data_elems = 0, 
          duration = 0, destruct = 0x0, priv = 0x0, pos = -1, convergence_duration = 0}
        mpi = 0x5d0c1a84a0
        __PRETTY_FUNCTION__ = "decode"
        vo_params = {imgfmt = IMGFMT_444P10_LE, w = 4096, h = 1744, d_w = 4096, d_h = 1744, colorspace = MP_CSP_BT_709, colorlevels = MP_CSP_LEVELS_TV, 
          chroma_location = MP_CHROMA_LEFT, outputlevels = MP_CSP_LEVELS_AUTO}
#11 0x0000005d0b64ab28 in decode_with_fallback (sh=0x5d0ba89f40, packet=0x5d0c1a90f0, flags=0, reordered_pts=0x3e3470a4218) at video/decode/vd_lavc.c:774
        ctx = 0x5d0c085a00
        mpi = 0x0
        res = <optimized out>
#12 0x0000005d0b649000 in decode_video (sh_video=sh_video@entry=0x5d0ba89f40, packet=0x5d0c1a90f0, drop_frame=0, pts=0) at video/decode/dec_video.c:257
        mpi = 0x0
        opts = 0x5d0ba434e0
        prevpts = <optimized out>
#13 0x0000005d0b623b58 in update_video (endpts=-9.2233720368547758e+18, mpctx=0x5d0ba42bc0) at mpvcore/mplayer.c:2735
        pkt = <optimized out>
        framedrop_type = <optimized out>
        decoded_frame = <optimized out>
        sh_video = 0x5d0ba89f40
        video_out = 0x5d0bcef9f0
        pts = <optimized out>
        frame_time = <optimized out>
#14 run_playloop (mpctx=mpctx@entry=0x5d0ba42bc0) at mpvcore/mplayer.c:3675
        frame_time = 0
        t2 = <optimized out>
        pts_us = <optimized out>
        duration = <optimized out>
        vo = 0x5d0bcef9f0
        vsleep = <optimized out>
        sh_video = <optimized out>
        time_frame = 0
        pts2 = <optimized out>
        opts = 0x5d0ba434e0
        full_audio_buffers = false
        audio_left = false
        video_left = false
        endpts = -9.2233720368547758e+18
        end_is_chapter = false
        sleeptime = <optimized out>
        was_restart = true
        new_frame_shown = false
        buffered_audio = -1
#15 0x0000005d0b5dea94 in play_current_file (mpctx=<optimized out>) at mpvcore/mplayer.c:4656
        opts = 0x5d0ba434e0
        res = <optimized out>
        startpos = <optimized out>
        uninitialize_parts = <optimized out>
        playback_short = <optimized out>
        init_failed = <optimized out>
        playback_start = 10.080209999999999
        stream_filename = <optimized out>
#16 play_files (mpctx=<optimized out>) at mpvcore/mplayer.c:4780
        new_entry = <optimized out>
#17 mpv_main (argv=<optimized out>, argc=<optimized out>) at mpvcore/mplayer.c:5050
        mpctx = <optimized out>
        opts = <optimized out>
        r = <optimized out>
#18 main (argc=<optimized out>, argv=<optimized out>) at mpvcore/mplayer.c:5062
No locals.
A debugging session is active.

        Inferior 1 [process 4167] will be killed.

Quit anyway? (y or n)
@ghost
Copy link

ghost commented Oct 27, 2013

As determined on IRC, the segfault is because the XvShmCreateImage API function returns a smaller image than requested, which, if I read the manpage right, is not allowed. Broken driver? Broken something else? I don't know, but not our problem.

@ghost ghost closed this as completed Oct 27, 2013
@divVerent
Copy link
Member

May still be a good idea to gracefully fail then.

@Nikoli
Copy link
Contributor Author

Nikoli commented Oct 27, 2013

Gracefully failing or telling "your hardware/driver does not support playing such files with VO xv" would be a good solution.

@ghost
Copy link

ghost commented Oct 27, 2013

I don't know, that's kind of like having to check whether the pointer malloc returns is really accessible. IMO this should be fixed upstream, except I don't know who upstream is. (Mesa? Xorg? Driver developers?)

@Nikoli
Copy link
Contributor Author

Nikoli commented Oct 27, 2013

Reported upstream:
https://bugs.freedesktop.org/show_bug.cgi?id=70931

@divVerent
Copy link
Member

As for detecting it - asking as I do not see this in the backtrace yet: how
do we know a too small image was allocated?

Can we detect this from our code?

Is it worth the effort?

@ghost
Copy link

ghost commented Oct 27, 2013

It can be easily detected, because the resulting XvImage has the "real" image dimensions set.

The manpage says the real dimensions can be larger - but there's no word about them being smaller. The requested image size is way smaller than the maximal image size too.

I don't really want to add hacks for things that obviously shouldn't happen.

@divVerent
Copy link
Member

Oddly, the manpage does not say at all what should happen if the requested
size is not supported by the hardware. BadMatch or picking a "more
supported size" may both seem plausible to me.

Also, I bet it may also enlarge dimensions in some RGB situations when
requesting 1x1.

So maybe we should code defensively there... But let's wait what happens on
the upstream bug.
Am 27.10.2013 20:54 schrieb "wm4" [email protected]:

It can be easily detected, because the resulting XvImage has the "real"
image dimensions set.

The manpage says the real dimensions can be larger - but there's no word
about them being smaller. The requested image size is way smaller than the
maximal image size too.

I don't really want to add hacks for things that obviously shouldn't
happen.


Reply to this email directly or view it on GitHubhttps://issues/320#issuecomment-27177617
.

@ghost
Copy link

ghost commented Oct 27, 2013

The manpage just says: Width and height may be enlarged in some YUV formats.. Getting a larger is not a problem, we then essentially use a cropped sub-image of it. Anyway, let's hear what upstream says. If the answer is "this function returns random results which aren't even close to what the parameters request" (yep that's what happens here), then I'll change it.

@Nikoli
Copy link
Contributor Author

Nikoli commented Oct 27, 2013

Seems vlc does some checks of xvideo related driver features and shows warning when required:
http://git.videolan.org/?p=vlc.git;a=blob;f=modules/video_output/xcb/xvideo.c;h=905c2e10e863ee26553cf5a9e4efdd3b27e0935e;hb=HEAD#l338

@ghost
Copy link

ghost commented Oct 27, 2013

No idea what this is about (their idea of DR?), but just to make it clear: we do check for the max. image size.

@Nikoli
Copy link
Contributor Author

Nikoli commented Oct 28, 2013

For me vlc does show above warning: after changing vo from opengl to xv every time i try to open 4k file vlc tells that max supported resolution for xv is 2046x1744, but i try to play 4096x1744. What is mpv supposed to do when xv checks fail? Show some warning in output and skip vo? It did not do any of it. May be xv checks in mpv are different and do not fail in this case?

@ghost
Copy link

ghost commented Oct 28, 2013

Didn't you say xvinfo reported 8192x8192 as maximum image size?

@Nikoli
Copy link
Contributor Author

Nikoli commented Oct 28, 2013

Yes, xvinfo reported 8192x8192.

@ghost
Copy link

ghost commented Oct 28, 2013

Can you paste your full xvinfo output?

@Nikoli
Copy link
Contributor Author

Nikoli commented Oct 28, 2013

X-Video Extension version 2.2
screen #0
  Adaptor #0: "Nouveau GeForce 8/9 Textured Video"
    number of ports: 32
    port base: 63
    operations supported: PutImage 
    supported visuals:
      depth 24, visualID 0x21
      depth 24, visualID 0x22
    number of attributes: 7
      "XV_SET_DEFAULTS" (range 0 to 0)
              client settable attribute
      "XV_SYNC_TO_VBLANK" (range 0 to 1)
              client settable attribute
              client gettable attribute (current value is 1)
      "XV_BRIGHTNESS" (range -1000 to 1000)
              client settable attribute
              client gettable attribute (current value is 0)
      "XV_CONTRAST" (range -1000 to 1000)
              client settable attribute
              client gettable attribute (current value is 0)
      "XV_SATURATION" (range -1000 to 1000)
              client settable attribute
              client gettable attribute (current value is 0)
      "XV_HUE" (range -1000 to 1000)
              client settable attribute
              client gettable attribute (current value is 0)
      "XV_ITURBT_709" (range 0 to 1)
              client settable attribute
              client gettable attribute (current value is 0)
    maximum XvImage size: 8192 x 8192
    Number of image formats: 4
      id: 0x32315659 (YV12)
        guid: 59563132-0000-0010-8000-00aa00389b71
        bits per pixel: 12
        number of planes: 3
        type: YUV (planar)
      id: 0x30323449 (I420)
        guid: 49343230-0000-0010-8000-00aa00389b71
        bits per pixel: 12
        number of planes: 3
        type: YUV (planar)
      id: 0x32595559 (YUY2)
        guid: 59555932-0000-0010-8000-00aa00389b71
        bits per pixel: 16
        number of planes: 1
        type: YUV (packed)
      id: 0x59565955 (UYVY)
        guid: 55595659-0000-0010-8000-00aa00389b71
        bits per pixel: 16
        number of planes: 1
        type: YUV (packed)

dequis added a commit to dequis/mpv that referenced this issue May 23, 2016
Fixes mpv-player#320 (which is closed as 'not our problem' but eh)

Relevant xorg bug: https://bugs.freedesktop.org/show_bug.cgi?id=70931

For me this happened when (accidentally) trying to play a 8460x2812 jpg
file with mpv. Like the referenced bug, xvinfo reports "maximum XvImage
size: 8192 x 8192". So the returned XvImage is 8192x2812 and memory
corruption happens.

Only after handling this BadShmSeg X11 errors are shown.
ghost pushed a commit that referenced this issue May 24, 2016
Fixes #320 (which is closed as 'not our problem' but eh)

Relevant xorg bug: https://bugs.freedesktop.org/show_bug.cgi?id=70931

For me this happened when (accidentally) trying to play a 8460x2812 jpg
file with mpv. Like the referenced bug, xvinfo reports "maximum XvImage
size: 8192 x 8192". So the returned XvImage is 8192x2812 and memory
corruption happens.

Only after handling this BadShmSeg X11 errors are shown.
@zaza42
Copy link

zaza42 commented Jun 25, 2016

Ehm. mpv had worked perfectly before this checking. It always miscalculates the correct size by 1 pixel with my buggy sis671 card. I had to remove this code to watch movies again. :-/

[vo/xv] Got XvImage with incorrect size: 1280x772 (expected 1280x771)
[vo/xv] could not allocate Xv image data
Could not initialize video chain.
[vo/xv] Got XvImage with incorrect size: 640x386 (expected 640x385)
[vo/xv] could not allocate Xv image data
Could not initialize video chain.

@ghost
Copy link

ghost commented Jun 25, 2016

Fixed via 22c76e8.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants