Ticket #6514: myth-direct-xv.patch

File myth-direct-xv.patch, 10.6 KB (added by anonymous, 15 years ago)

Allow Xv without XShm

  • videoout_xv.cpp

    diff -Naur libmythtv-orig/videoout_xv.cpp libmythtv/videoout_xv.cpp
    old new  
    116116      xvmc_osd_lock(false),
    117117      xvmc_tex(NULL),
    118118
    119       xv_port(-1),      xv_hue_base(0),
     119      xv_port(-1),      xv_using_shm(true), xv_hue_base(0),
    120120      xv_colorkey(0),   xv_draw_colorkey(false),
    121121      xv_chroma(0),
    122122
     
    20392039vector<unsigned char*> VideoOutputXv::CreateShmImages(uint num, bool use_xv)
    20402040{
    20412041    VERBOSE(VB_PLAYBACK, LOC +
    2042             QString("CreateShmImages(%1): video_dim: %2x%3")
    2043             .arg(num).arg(video_dim.width()).arg(video_dim.height()));
     2042            QString("CreateShmImages(%1): video_dim: %2x%3 (%4)")
     2043            .arg(num).arg(video_dim.width()).arg(video_dim.height()).arg(xv_using_shm?"Shared":"Direct"));
    20442044
    20452045    vector<unsigned char*> bufs;
    20462046    for (uint i = 0; i < num; i++)
    20472047    {
    2048         XShmSegmentInfo *info = new XShmSegmentInfo;
     2048        XShmSegmentInfo *info = 0;
    20492049        void *image = NULL;
    20502050        int size = 0;
    20512051        int desiredsize = 0;
    20522052
     2053        if (!use_xv || xv_using_shm)
     2054            info = new XShmSegmentInfo;
     2055
    20532056        X11L;
    20542057
    20552058        if (use_xv)
    20562059        {
    2057             XvImage *img =
    2058                 XvShmCreateImage(XJ_disp, xv_port, xv_chroma, 0,
    2059                                  video_dim.width(), video_dim.height(), info);
     2060            XvImage *img;
     2061            if (xv_using_shm)
     2062                img = XvShmCreateImage(XJ_disp, xv_port, xv_chroma, 0,
     2063                                      video_dim.width(), video_dim.height(), info);
     2064            else
     2065                img = XvCreateImage   (XJ_disp, xv_port, xv_chroma, 0,
     2066                                      video_dim.width(), video_dim.height());
    20602067            size = img->data_size + 64;
    20612068            image = img;
    20622069            desiredsize = video_dim.width() * video_dim.height() * 3 / 2;
     
    20682075                        "requested size.");
    20692076                XFree(image);
    20702077                image = NULL;
    2071                 delete info;
     2078                if (info != 0)
     2079                    delete info;
    20722080            }
    20732081
    20742082            if (image && (3 == img->num_planes))
    20752083            {
    2076                 XJ_shm_infos.push_back(info);
     2084                if (xv_using_shm)
     2085                    XJ_shm_infos.push_back(info);
    20772086                YUVInfo tmp(img->width, img->height, img->data_size,
    20782087                            img->pitches, img->offsets);
    20792088                if (xv_chroma == GUID_YV12_PLANAR)
     
    20912100                        "with the correct number of pixel planes.");
    20922101                XFree(image);
    20932102                image = NULL;
    2094                 delete info;
     2103                if (info != 0)
     2104                    delete info;
    20952105            }
    20962106        }
    20972107        else
     
    21282138
    21292139        if (image)
    21302140        {
    2131             XJ_shm_infos[i]->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777);
    2132             if (XJ_shm_infos[i]->shmid >= 0)
     2141            if (info != 0)
    21332142            {
    2134                 XJ_shm_infos[i]->shmaddr = (char*)
    2135                     shmat(XJ_shm_infos[i]->shmid, 0, 0);
    2136                 if (use_xv)
    2137                     ((XvImage*)image)->data = XJ_shm_infos[i]->shmaddr;
    2138                 else
    2139                     ((XImage*)image)->data = XJ_shm_infos[i]->shmaddr;
    2140                 xv_buffers[(unsigned char*) XJ_shm_infos[i]->shmaddr] = image;
    2141                 XJ_shm_infos[i]->readOnly = False;
     2143                XJ_shm_infos[i]->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777);
     2144                if (XJ_shm_infos[i]->shmid >= 0)
     2145                {
     2146                    XJ_shm_infos[i]->shmaddr = (char*)
     2147                        shmat(XJ_shm_infos[i]->shmid, 0, 0);
     2148                    if (use_xv)
     2149                        ((XvImage*)image)->data = XJ_shm_infos[i]->shmaddr;
     2150                    else
     2151                        ((XImage*)image)->data = XJ_shm_infos[i]->shmaddr;
     2152                    xv_buffers[(unsigned char*) XJ_shm_infos[i]->shmaddr] = image;
     2153                    XJ_shm_infos[i]->readOnly = False;
    21422154
    2143                 X11L;
    2144                 XShmAttach(XJ_disp, XJ_shm_infos[i]);
    2145                 XSync(XJ_disp, False); // needed for FreeBSD?
    2146                 X11U;
     2155                    X11L;
     2156                    XShmAttach(XJ_disp, XJ_shm_infos[i]);
     2157                    XSync(XJ_disp, False); // needed for FreeBSD?
     2158                    X11U;
    21472159
    2148                 // Mark for delete immediately.
    2149                 // It won't actually be removed until after we detach it.
    2150                 shmctl(XJ_shm_infos[i]->shmid, IPC_RMID, 0);
     2160                    // Mark for delete immediately.
     2161                    // It won't actually be removed until after we detach it.
     2162                    shmctl(XJ_shm_infos[i]->shmid, IPC_RMID, 0);
    21512163
    2152                 bufs.push_back((unsigned char*) XJ_shm_infos[i]->shmaddr);
     2164                    bufs.push_back((unsigned char*) XJ_shm_infos[i]->shmaddr);
     2165                }
     2166                else
     2167                {
     2168                    VERBOSE(VB_IMPORTANT, LOC_ERR +
     2169                            "CreateXvShmImages(): shmget() failed." + ENO);
     2170                    break;
     2171                }
    21532172            }
    21542173            else
    21552174            {
    2156                 VERBOSE(VB_IMPORTANT, LOC_ERR +
    2157                         "CreateXvShmImages(): shmget() failed." + ENO);
    2158                 break;
     2175                char* mbfr = (char*)malloc( ((XvImage*)image)->data_size );
     2176                if (mbfr != 0)
     2177                {
     2178                    ((XvImage*)image)->data = mbfr;
     2179                    bufs.push_back((unsigned char*)mbfr);
     2180                    xv_buffers[(unsigned char*)mbfr] = image;
     2181                }
     2182                else
     2183                {
     2184                    VERBOSE(VB_IMPORTANT, LOC_ERR +
     2185                            "CreateXvShmImages(): malloc failed.");
     2186                    break;
     2187                }
    21592188            }
    21602189        }
    21612190        else
     
    21762205        ok = CreateXvMCBuffers();
    21772206    else if (subtype == XVideo && xv_port >= 0)
    21782207    {
    2179         vector<unsigned char*> bufs =
    2180             CreateShmImages(vbuffers.allocSize(), true);
    2181 
    2182         ok = (bufs.size() >= vbuffers.allocSize()) &&
    2183             vbuffers.CreateBuffers(video_dim.width(), video_dim.height(),
     2208        vector<unsigned char*> bufs;
     2209        xv_using_shm = true;
     2210        bufs = CreateShmImages(vbuffers.allocSize(), true);
     2211        vector<XErrorEvent> errs = UninstallXErrorHandler(XJ_disp);
     2212        InstallXErrorHandler(XJ_disp);
     2213        if (bufs.size() < vbuffers.allocSize() || errs.size())
     2214        {
     2215            VERBOSE(VB_IMPORTANT, LOC + "Switch to Xv without Xshm");
     2216            DeleteBuffers(XVideo,true);
     2217            UninstallXErrorHandler(XJ_disp);
     2218            InstallXErrorHandler(XJ_disp);
     2219            xv_using_shm = false;
     2220            bufs = CreateShmImages(vbuffers.allocSize(), true);
     2221        }
     2222        if (bufs.size() >= vbuffers.allocSize())
     2223            ok = vbuffers.CreateBuffers(video_dim.width(), video_dim.height(),
    21842224                                   bufs, XJ_yuv_infos);
    2185 
     2225        else
     2226            ok = false;
    21862227        X11S(XSync(XJ_disp, False));
    21872228    }
    21882229    else if (subtype == XShm || subtype == Xlib)
     
    21992240
    22002241            X11L;
    22012242
    2202             int bytes_per_line = XJ_depth / 8 * display_visible_rect.width();
     2243            int bytes_per_line;
    22032244            int scrn = DefaultScreen(XJ_disp);
    22042245            Visual *visual = DefaultVisual(XJ_disp, scrn);
    22052246            XJ_non_xv_image = XCreateImage(XJ_disp, visual, XJ_depth,
    22062247                                           ZPixmap, /*offset*/0, /*data*/0,
    22072248                                           display_visible_rect.width(),
    22082249                                           display_visible_rect.height(),
    2209                                            /*bitmap_pad*/0,
    2210                                            bytes_per_line);
     2250                                           /*bitmap_pad*/8,0);
    22112251
    22122252            X11U;
    22132253
     
    22182258                        <<"                        "
    22192259                        <<"XJ_depth("<<XJ_depth<<") "
    22202260                        <<"WxH("<<display_visible_rect.width()
    2221                         <<"x"<<display_visible_rect.height()<<") "
    2222                         <<"bpl("<<bytes_per_line<<")");
     2261                        <<"x"<<display_visible_rect.height()<<")");
    22232262                return false;
    22242263            }
     2264            bytes_per_line = XJ_non_xv_image->bytes_per_line;
    22252265            XJ_non_xv_image->data = (char*) malloc(
    22262266                bytes_per_line * display_visible_rect.height());
    22272267        }
     
    22532293
    22542294    if (ok)
    22552295        CreatePauseFrame(subtype);
    2256 
    22572296    return ok;
    22582297}
    22592298
     
    30303069        vbuffers.LockFrame(frame, "ShowXVideo");
    30313070        int video_height = (3 != field) ?
    30323071            (video_rect.height()/2) : video_rect.height();
    3033         X11S(XvShmPutImage(XJ_disp, xv_port, XJ_curwin,
    3034                            XJ_gc, image,
    3035                            video_rect.left(), src_y,
    3036                            video_rect.width(), video_height,
    3037                            display_video_rect.left(), dest_y,
    3038                            display_video_rect.width(),
    3039                            display_video_rect.height(), False));
     3072        if (xv_using_shm)
     3073        {
     3074            X11S(XvShmPutImage(XJ_disp, xv_port, XJ_curwin,
     3075                               XJ_gc, image,
     3076                               video_rect.left(), src_y,
     3077                               video_rect.width(), video_height,
     3078                               display_video_rect.left(), dest_y,
     3079                               display_video_rect.width(),
     3080                               display_video_rect.height(), False));
     3081        }
     3082        else
     3083        {
     3084            X11S(XvPutImage   (XJ_disp, xv_port, XJ_curwin,
     3085                               XJ_gc, image,
     3086                               video_rect.left(), src_y,
     3087                               video_rect.width(), video_height,
     3088                               display_video_rect.left(), dest_y,
     3089                               display_video_rect.width(),
     3090                               display_video_rect.height() ));
     3091        }
    30403092        vbuffers.UnlockFrame(frame, "ShowXVideo");
    30413093    }
    30423094}
  • videoout_xv.h

    diff -Naur libmythtv-orig/videoout_xv.h libmythtv/videoout_xv.h
    old new  
    253253
    254254    // Basic Xv drawing info
    255255    int                  xv_port;
     256    bool                 xv_using_shm;
    256257    int                  xv_hue_base;
    257258    int                  xv_colorkey;
    258259    bool                 xv_draw_colorkey;