Ticket #4046: 4046-v1.patch

File 4046-v1.patch, 38.6 KB (added by danielk, 17 years ago)

Attempts to locate surface with XVideo picture controls and verifies that they exist before attempting to modify them. (Has not been tested with working XVideo picture controls yet!)

  • libs/libmythtv/util-xv.cpp

     
    8181    return str;
    8282}
    8383
    84 int colorkey_supported(Display *disp, int port)
     84bool xv_is_attrib_supported(
     85    Display *disp, int port, const char *name,
     86    int *current_value, int *min_value, int *max_value)
    8587{
    8688    Atom xv_atom;
    87     int colorkey = 0;
     89    XvAttribute *attributes;
     90    int attrib_count;
    8891    int ret;
    89     xv_atom = XInternAtom(disp, "XV_COLORKEY", true);
    90     if (xv_atom != None)
     92
     93    int dummy;
     94    int *xv_val = (current_value) ? current_value : &dummy;
     95
     96    X11S(attributes = XvQueryPortAttributes(disp, port, &attrib_count));
     97    for (int i = (attributes) ? 0 : attrib_count; i < attrib_count; i++)
    9198    {
    92         ret = XvGetPortAttribute(disp, port, xv_atom, &colorkey);
    93         if (ret != Success)
    94             colorkey = 0;
     99        if (strcmp(attributes[i].name, name))
     100            continue;
     101
     102        if (min_value)
     103            *min_value = attributes[i].min_value;
     104
     105        if (max_value)
     106            *max_value = attributes[i].max_value;
     107
     108        X11S(xv_atom = XInternAtom(disp, name, False));
     109        if (None == xv_atom)
     110            continue;
     111
     112        X11S(ret = XvGetPortAttribute(disp, port, xv_atom, xv_val));
     113        if (Success == ret)
     114        {
     115            X11S(XFree(attributes));
     116            return true;
     117        }
    95118    }
    96     return colorkey;
     119
     120    if (attributes)
     121        X11S(XFree(attributes));
     122
     123    return false;
    97124}
     125
     126bool xv_set_attrib(Display *disp, int port, const char *name, int val)
     127{
     128    Atom xv_atom;
     129    X11S(xv_atom = XInternAtom(disp, name, False));
     130    if (xv_atom == None)
     131        return false;
     132
     133    int ret;
     134    X11S(ret = XvSetPortAttribute(disp, port, xv_atom, val));
     135    if (Success != ret)
     136        return false;
     137
     138    return true;
     139}
     140
     141bool xv_get_attrib(Display *disp, int port, const char *name, int &val)
     142{
     143    Atom xv_atom;
     144    X11S(xv_atom = XInternAtom(disp, name, False));
     145    if (xv_atom == None)
     146        return false;
     147
     148    int ret;
     149    X11S(ret = XvGetPortAttribute(disp, port, xv_atom, &val));
     150    if (Success != ret)
     151        return false;
     152
     153    return true;
     154}
  • libs/libmythtv/tv_play.h

     
    399399    int     fftime;
    400400    int     rewtime;
    401401    int     jumptime;
    402     bool    db_use_picture_attr;
    403402    bool    smartChannelChange;
    404403    bool    MuteIndividualChannels;
    405404    bool    arrowAccel;
  • libs/libmythtv/openglvideo.h

     
    9090    void SetVideoResize(const QRect &rect);
    9191    void DisableVideoResize(void);
    9292    int SetPictureAttribute(PictureAttribute attributeType, int newValue);
     93    PictureAttributeSupported GetSupportedPictureAttributes(void) const;
    9394
    9495  private:
    9596    void Teardown(void);
     
    182183    void SetVideoResize(const QRect&) { }
    183184    void DisableVideoResize(void) { }
    184185    int SetPictureAttribute(PictureAttribute, int) { return -1; }
     186    PictureAttributeSupported GetSupportedPictureAttributes(void) const
     187        { return kPictureAttributeSupported_None; }
    185188};
    186189
    187190#endif // !USING_OPENGL_VIDEO
  • libs/libmythtv/openglvideo.cpp

     
    11441144    return ret;
    11451145}
    11461146
     1147PictureAttributeSupported
     1148OpenGLVideo::GetSupportedPictureAttributes(void) const
     1149{
     1150    return (!useColourControl) ?
     1151        kPictureAttributeSupported_None :
     1152        (PictureAttributeSupported)
     1153        (kPictureAttributeSupported_Brightness |
     1154         kPictureAttributeSupported_Contrast |
     1155         kPictureAttributeSupported_Colour);
     1156}
     1157
    11471158// locking ok
    11481159void OpenGLVideo::SetTextureFilters(vector<GLuint> *textures, int filt)
    11491160{
  • libs/libmythtv/util-xv.h

     
    2424extern bool has_open_xv_port(int port);
    2525extern uint cnt_open_xv_port(void);
    2626extern QString xvflags2str(int flags);
    27 extern int colorkey_supported(Display *disp, int port);
     27extern bool xv_is_attrib_supported(
     28    Display *disp, int port, const char *name,
     29    int *current_value = NULL, int *min_val = NULL, int *max_val = NULL);
     30extern bool xv_set_attrib(Display *disp, int port, const char *name, int val);
     31extern bool xv_get_attrib(Display *disp, int port, const char *name, int &val);
    2832
     33
    2934#endif // _UTIL_XV_H_
  • libs/libmythtv/tv_play.cpp

     
    594594    baseFilters         += gContext->GetSetting("CustomFilters");
    595595    db_time_format       = gContext->GetSetting("TimeFormat", "h:mm AP");
    596596    db_short_date_format = gContext->GetSetting("ShortDateFormat", "M/d");
    597     db_use_picture_attr  = gContext->GetNumSetting(
    598                             "UseOutputPictureControls", 0);
    599597    smartChannelChange   = gContext->GetNumSetting("SmartChannelChange", 0);
    600598    MuteIndividualChannels=gContext->GetNumSetting("IndividualMuteControl", 0);
    601599    arrowAccel           = gContext->GetNumSetting("UseArrowAccels", 1);
     
    60076005    }
    60086006}
    60096007
     6008static PictureAttribute next(
     6009    PictureAdjustType type, NuppelVideoPlayer *nvp, PictureAttribute attr)
     6010{
     6011    uint sup = kPictureAttributeSupported_None;
     6012    if ((kAdjustingPicture_Playback == type) && nvp && nvp->getVideoOutput())
     6013    {
     6014        sup = nvp->getVideoOutput()->GetSupportedPictureAttributes();
     6015        if (nvp->getAudioOutput())
     6016            sup |= kPictureAttributeSupported_Volume;
     6017    }
     6018    else if (kAdjustingPicture_Channel == type)
     6019    {
     6020        sup = (kPictureAttributeSupported_Brightness |
     6021               kPictureAttributeSupported_Contrast |
     6022               kPictureAttributeSupported_Colour |
     6023               kPictureAttributeSupported_Hue);
     6024    }
     6025    else if (kAdjustingPicture_Recording == type)
     6026    {
     6027        sup = (kPictureAttributeSupported_Brightness |
     6028               kPictureAttributeSupported_Contrast |
     6029               kPictureAttributeSupported_Colour |
     6030               kPictureAttributeSupported_Hue);
     6031    }
     6032
     6033    return next((PictureAttributeSupported)sup, attr);
     6034}
     6035
    60106036void TV::DoTogglePictureAttribute(PictureAdjustType type)
    60116037{
    6012     if (!db_use_picture_attr && kAdjustingPicture_Playback == type)
     6038    PictureAttribute attr = next(type, nvp, adjustingPictureAttribute);
     6039    if (kPictureAttribute_None == attr)
    60136040        return;
    60146041
    6015     adjustingPicture = type;
     6042    adjustingPicture          = type;
     6043    adjustingPictureAttribute = attr;
    60166044
    6017     adjustingPictureAttribute = (PictureAttribute)
    6018         ((int) adjustingPictureAttribute + 1);
    6019     if ((adjustingPictureAttribute >= kPictureAttribute_MAX) ||
    6020         ((type >= kAdjustingPicture_Channel) &&
    6021          (adjustingPictureAttribute > kPictureAttribute_Hue)))
    6022     {
    6023         adjustingPictureAttribute = kPictureAttribute_MIN;
    6024     }
    6025 
    6026     PictureAttribute attr = adjustingPictureAttribute;
    60276045    QString title = toTitleString(type);
    60286046
    60296047    if (!GetOSD())
     
    68506868                                     (sel) ? 1 : 0, NULL, "ADJUSTFILLGROUP");
    68516869    }
    68526870
    6853     if (db_use_picture_attr)
     6871    uint sup = kPictureAttributeSupported_None;
     6872    if (nvp && nvp->getVideoOutput())
     6873        sup = nvp->getVideoOutput()->GetSupportedPictureAttributes();
     6874    item = NULL;
     6875    for (int i = kPictureAttribute_MIN; i < kPictureAttribute_MAX; i++)
    68546876    {
    6855         item = new OSDGenericTree(treeMenu, tr("Adjust Picture"));
    6856         subitem = new OSDGenericTree(item, tr("Brightness"),
    6857                                      "TOGGLEPICCONTROLS" +
    6858                                      QString("%1")
    6859                                      .arg(kPictureAttribute_Brightness));
    6860         subitem = new OSDGenericTree(item, tr("Contrast"),
    6861                                      "TOGGLEPICCONTROLS" +
    6862                                      QString("%1")
    6863                                      .arg(kPictureAttribute_Contrast));
    6864         subitem = new OSDGenericTree(item, tr("Colour"),
    6865                                      "TOGGLEPICCONTROLS" +
    6866                                      QString("%1")
    6867                                      .arg(kPictureAttribute_Colour));
    6868         subitem = new OSDGenericTree(item, tr("Hue"),
    6869                                      "TOGGLEPICCONTROLS" +
    6870                                      QString("%1")
    6871                                      .arg(kPictureAttribute_Hue));
     6877        if (toMask((PictureAttribute)i) & sup)
     6878        {
     6879            if (!item)
     6880                item = new OSDGenericTree(treeMenu, tr("Adjust Picture"));
     6881            subitem = new OSDGenericTree(
     6882                item, toString((PictureAttribute) i),
     6883                QString("TOGGLEPICCONTROLS%1").arg(i));
     6884        }
    68726885    }
    68736886
    68746887    item = new OSDGenericTree(treeMenu, tr("Manual Zoom Mode"),
  • libs/libmythtv/videoouttypes.h

     
    6868    kPictureAttribute_MAX
    6969} PictureAttribute;
    7070
     71typedef enum PictureAttributeSupported
     72{
     73    kPictureAttributeSupported_None       = 0x00,
     74    kPictureAttributeSupported_Brightness = 0x01,
     75    kPictureAttributeSupported_Contrast   = 0x02,
     76    kPictureAttributeSupported_Colour     = 0x04,
     77    kPictureAttributeSupported_Hue        = 0x08,
     78    kPictureAttributeSupported_Volume     = 0x10,
     79} PictureAttributeSupported;
     80
    7181inline bool is_interlaced(FrameScanType scan)
    7282{
    7383    return (kScan_Interlaced == scan) || (kScan_Intr2ndField == scan);
     
    212222    return QDeepCopy<QString>(ret);
    213223}
    214224
     225inline QString toXVString(PictureAttribute pictureattribute)
     226{
     227    QString ret = QString::null;
     228    switch (pictureattribute)
     229    {
     230      case kPictureAttribute_None: break;
     231      case kPictureAttribute_Brightness:
     232          ret = "XV_BRIGHTNESS"; break;
     233      case kPictureAttribute_Contrast:
     234          ret = "XV_CONTRAST";   break;
     235      case kPictureAttribute_Colour:
     236          ret = "XV_SATURATION";     break;
     237      case kPictureAttribute_Hue:
     238          ret = "XV_HUE";        break;
     239      case kPictureAttribute_Volume:
     240      case kPictureAttribute_MAX: break;
     241    }
     242
     243    if (ret.isEmpty())
     244        return QString::null;
     245
     246    return QDeepCopy<QString>(ret);
     247}
     248
     249inline QString toString(PictureAttributeSupported supported)
     250{
     251    QString ret = "";
     252
     253    if (kPictureAttributeSupported_Brightness & supported)
     254        ret += "Brightness, ";
     255    if (kPictureAttributeSupported_Contrast & supported)
     256        ret += "Contrast, ";
     257    if (kPictureAttributeSupported_Colour & supported)
     258        ret += "Colour, ";
     259    if (kPictureAttributeSupported_Hue & supported)
     260        ret += "Hue, ";
     261    if (kPictureAttributeSupported_Volume & supported)
     262        ret += "Volume, ";
     263
     264    return (ret.isEmpty()) ? "" : ret.left(ret.length() - 2);
     265}
     266
     267inline PictureAttributeSupported toMask(PictureAttribute pictureattribute)
     268{
     269    PictureAttributeSupported ret = kPictureAttributeSupported_None;
     270    switch (pictureattribute)
     271    {
     272        case kPictureAttribute_None: break;
     273        case kPictureAttribute_Brightness:
     274            ret = kPictureAttributeSupported_Brightness; break;
     275        case kPictureAttribute_Contrast:
     276            ret = kPictureAttributeSupported_Contrast; break;
     277        case kPictureAttribute_Colour:
     278            ret = kPictureAttributeSupported_Colour; break;
     279        case kPictureAttribute_Hue:
     280            ret = kPictureAttributeSupported_Hue; break;
     281        case kPictureAttribute_Volume:
     282            ret = kPictureAttributeSupported_Volume; break;
     283        case kPictureAttribute_MAX: break;
     284    }
     285    return ret;
     286}
     287
     288inline PictureAttribute next(PictureAttributeSupported supported,
     289                             PictureAttribute          attribute)
     290{
     291    int i = ((int) attribute + 1) % (int) kPictureAttribute_MAX;
     292    for (int j = 0; j < kPictureAttribute_MAX;
     293         (i = (i+1) % kPictureAttribute_MAX), j++)
     294    {
     295        if (toMask((PictureAttribute) i) & supported)
     296            return (PictureAttribute) i;
     297    }
     298    return kPictureAttribute_None;
     299}
     300
    215301#endif // _VIDEOOUT_TYPES_H_
  • libs/libmythtv/videooutbase.cpp

     
    243243    db_pip_location(kPIPTopLeft),       db_pip_size(26),
    244244    db_aspectoverride(kAspect_Off),     db_adjustfill(kAdjustFill_Off),
    245245    db_deint_filtername(QString::null),
     246    db_use_picture_controls(false),
    246247    db_vdisp_profile(new VideoDisplayProfile()),
    247248
    248249    // Manual Zoom
     
    283284    // Various state variables
    284285    embedding(false),                   needrepaint(false),
    285286    allowpreviewepg(true),              errored(false),
    286     framesPlayed(0), db_scaling_allowed(true)
     287    framesPlayed(0), db_scaling_allowed(true),
     288    supported_attributes(kPictureAttributeSupported_None)
    287289{
    288290    db_display_dim = QSize(gContext->GetNumSetting("DisplaySizeWidth",  0),
    289291                           gContext->GetNumSetting("DisplaySizeHeight", 0));
     
    309311        gContext->GetNumSetting("AspectOverride",      0);
    310312    db_adjustfill = (AdjustFillMode)
    311313        gContext->GetNumSetting("AdjustFill",          0);
     314
     315    db_use_picture_controls =
     316        gContext->GetNumSetting("UseOutputPictureControls", 0);
    312317}
    313318
    314319/**
  • libs/libmythtv/videoout_xv.h

     
    8787    void DrawUnusedRects(bool sync = true);
    8888    void UpdatePauseFrame(void);
    8989    int  SetPictureAttribute(PictureAttribute attribute, int newValue);
     90    void InitPictureAttributes(void);
    9091
    9192    int  GetRefreshRate(void);
    9293
     
    201202    VOSType              video_output_subtype;
    202203    DisplayRes          *display_res;
    203204    QMutex               global_lock;
    204     bool                 use_picture_controls;
    205205    bool                 use_i420_hack_for_broken_driver;
    206206
    207207    // Basic X11 info
     
    256256    int                  xv_chroma;
    257257    buffer_map_t         xv_buffers;
    258258    bool                 xv_need_bobdeint_repaint;
     259    QMap<PictureAttribute,int> xv_attribute_min;
     260    QMap<PictureAttribute,int> xv_attribute_max;
    259261
    260262    // OpenGL drawing info
    261263    QMutex               gl_context_lock;
  • libs/libmythtv/videoout_xv.cpp

     
    101101    : VideoOutput(),
    102102      myth_codec_id(codec_id), video_output_subtype(XVUnknown),
    103103      display_res(NULL), global_lock(true),
    104       use_picture_controls(false),
    105104      use_i420_hack_for_broken_driver(false),
    106105
    107106      XJ_root(0),  XJ_win(0), XJ_curwin(0), XJ_gc(0), XJ_screen(NULL),
     
    548547            .arg(display_aspect));
    549548}
    550549
     550class XvAttributes
     551{
     552  public:
     553    XvAttributes() :
     554        description(QString::null), xv_flags(0), feature_flags(0) {}
     555    XvAttributes(const QString &a, uint b, uint c) :
     556        description(QDeepCopy<QString>(a)), xv_flags(b), feature_flags(c) {}
     557
     558  public:
     559    QString description;
     560    uint    xv_flags;
     561    uint    feature_flags;
     562
     563    static const uint kFeatureNone      = 0x0000;
     564    static const uint kFeatureXvMC      = 0x0001;
     565    static const uint kFeatureVLD       = 0x0002;
     566    static const uint kFeatureIDCT      = 0x0004;
     567    static const uint kFeatureChromakey = 0x0008;
     568    static const uint kFeaturePicCtrl   = 0x0010;
     569};
     570
    551571/**
    552572 * Internal function used to grab a XVideo port with the desired properties.
    553573 *
     
    560580                                      XvMCSurfaceInfo* xvmc_surf_info,
    561581                                      QString *adaptor_name)
    562582{
    563     uint neededFlags[] = { XvInputMask,
    564                            XvInputMask,
    565                            XvInputMask,
    566                            XvInputMask | XvImageMask };
    567     bool useXVMC[] = { true,  true,  true,  false };
    568     bool useVLD[]  = { true,  false, false, false };
    569     bool useIDCT[] = { false, true,  false, false };
    570 
    571583    // avoid compiler warnings
    572     (void)width; (void)height; (void)xvmc_chroma; (void)xvmc_surf_info;
    573     (void)useVLD[0]; (void)useIDCT[0];
     584    (void)xvmc_chroma; (void)xvmc_surf_info;
    574585
    575     QString msg[] =
    576     {
    577         "XvMC surface found with VLD support on port %1",
    578         "XvMC surface found with IDCT support on port %1",
    579         "XvMC surface found with MC support on port %1",
    580         "XVideo surface found on port %1"
    581     };
    582 
    583586    if (adaptor_name)
    584587        *adaptor_name = QString::null;
    585588
     589    // figure out what basic kind of surface we want..
     590    int stream_type = 0;
     591    bool need_mc   = false, need_idct = false;
     592    bool need_vld  = false, need_xv   = false;
     593    switch (mcodecid)
     594    {
     595        case kCodec_MPEG1_XVMC: stream_type = 1; need_mc   = true; break;
     596        case kCodec_MPEG2_XVMC: stream_type = 2; need_mc   = true; break;
     597        case kCodec_H263_XVMC:  stream_type = 3; need_mc   = true; break;
     598        case kCodec_MPEG4_XVMC: stream_type = 4; need_mc   = true; break;
     599
     600        case kCodec_MPEG1_IDCT: stream_type = 1; need_idct = true; break;
     601        case kCodec_MPEG2_IDCT: stream_type = 2; need_idct = true; break;
     602        case kCodec_H263_IDCT:  stream_type = 3; need_idct = true; break;
     603        case kCodec_MPEG4_IDCT: stream_type = 4; need_idct = true; break;
     604
     605        case kCodec_MPEG1_VLD:  stream_type = 1; need_vld  = true; break;
     606        case kCodec_MPEG2_VLD:  stream_type = 2; need_vld  = true; break;
     607        case kCodec_H263_VLD:   stream_type = 3; need_vld  = true; break;
     608        case kCodec_MPEG4_VLD:  stream_type = 4; need_vld  = true; break;
     609
     610        default:
     611            need_xv = true;
     612            break;
     613    }
     614
     615    // create list of requirements to check in order..
     616    vector<XvAttributes> req;
     617    if (need_vld)
     618    {
     619        req.push_back(XvAttributes(
     620                          "XvMC surface found with VLD support on port %1",
     621                          XvInputMask, XvAttributes::kFeatureXvMC |
     622                          XvAttributes::kFeatureVLD));
     623    }
     624
     625    if (need_idct)
     626    {
     627        req.push_back(XvAttributes(
     628                          "XvMC surface found with IDCT support on port %1",
     629                          XvInputMask, XvAttributes::kFeatureXvMC |
     630                          XvAttributes::kFeatureIDCT));
     631    }
     632
     633    if (need_mc)
     634    {
     635        req.push_back(XvAttributes(
     636                          "XvMC surface found with MC support on port %1",
     637                          XvInputMask, XvAttributes::kFeatureXvMC));
     638    }
     639 
     640    if (need_xv)
     641    {
     642        req.push_back(XvAttributes(
     643                          "XVideo surface found on port %1",
     644                          XvInputMask | XvImageMask,
     645                          XvAttributes::kFeatureNone));
     646    }
     647
     648    // try to get an adapter with picture attributes
     649    if (true)
     650    {
     651        uint end = req.size();
     652        for (uint i = 0; i < end; i++)
     653        {
     654            req.push_back(req[i]);
     655            req[i].feature_flags |=  XvAttributes::kFeaturePicCtrl;
     656        }
     657    }
     658
     659    // figure out if we want chromakeying..
     660    VideoDisplayProfile vdp;
     661    vdp.SetInput(QSize(width, height));
     662    bool check_for_colorkey = (vdp.GetOSDRenderer() == "chromakey");
     663
     664    // if we want colorkey capability try to get an adapter with them
     665    if (check_for_colorkey)
     666    {
     667        uint end = req.size();
     668        for (uint i = 0; i < end; i++)
     669        {
     670            req.push_back(req[i]);
     671            req[i].feature_flags |= XvAttributes::kFeatureChromakey;
     672        }
     673    }
     674
    586675    // get the list of Xv ports
    587676    XvAdaptorInfo *ai = NULL;
    588677    uint p_num_adaptors = 0;
     
    596685        return -1;
    597686    }
    598687
    599     // find an Xv port
    600     int port = -1, stream_type = 0;
    601     uint begin = 0, end = 4;
    602     switch (mcodecid)
    603     {
    604         case kCodec_MPEG1_XVMC: (stream_type = 1),(begin = 2),(end = 3); break;
    605         case kCodec_MPEG2_XVMC: (stream_type = 2),(begin = 2),(end = 3); break;
    606         case kCodec_H263_XVMC:  (stream_type = 3),(begin = 2),(end = 3); break;
    607         case kCodec_MPEG4_XVMC: (stream_type = 4),(begin = 2),(end = 3); break;
    608 
    609         case kCodec_MPEG1_IDCT: (stream_type = 1),(begin = 1),(end = 2); break;
    610         case kCodec_MPEG2_IDCT: (stream_type = 2),(begin = 1),(end = 2); break;
    611         case kCodec_H263_IDCT:  (stream_type = 3),(begin = 1),(end = 2); break;
    612         case kCodec_MPEG4_IDCT: (stream_type = 4),(begin = 1),(end = 2); break;
    613 
    614         case kCodec_MPEG1_VLD:  (stream_type = 1),(begin = 0),(end = 1); break;
    615         case kCodec_MPEG2_VLD:  (stream_type = 2),(begin = 0),(end = 1); break;
    616         case kCodec_H263_VLD:   (stream_type = 3),(begin = 0),(end = 1); break;
    617         case kCodec_MPEG4_VLD:  (stream_type = 4),(begin = 0),(end = 1); break;
    618 
    619         default:
    620             begin = 3; end = 4;
    621             break;
    622     }
    623 
    624688    QString lastAdaptorName = QString::null;
     689    int port = -1;
    625690
    626     VideoDisplayProfile vdp;
    627     vdp.SetInput(QSize(width, height));
    628     QString osdtype = vdp.GetOSDRenderer();
    629     bool check_for_colorkey = (osdtype == "chromakey");
    630     for (uint j = begin; j < end; ++j)
     691    // find an Xv port
     692    for (uint j = 0; j < req.size(); ++j)
    631693    {
    632         VERBOSE(VB_PLAYBACK, LOC + QString("@ j=%1 Looking for flag[s]: %2")
    633                 .arg(j).arg(xvflags2str(neededFlags[j])));
     694        VERBOSE(VB_PLAYBACK, LOC + QString("@ j=%1 Looking for flag[s]: %2 %3")
     695                .arg(j).arg(xvflags2str(req[j].xv_flags))
     696                .arg(req[j].feature_flags,0,16));
    634697
    635698        for (int i = 0; i < (int)p_num_adaptors && (port == -1); ++i)
    636699        {
     
    639702                    QString("Adaptor#%1: %2 has flag[s]: %3")
    640703                    .arg(i).arg(lastAdaptorName).arg(xvflags2str(ai[i].type)));
    641704
    642             if ((ai[i].type & neededFlags[j]) != neededFlags[j])
     705            if ((ai[i].type & req[j].xv_flags) != req[j].xv_flags)
     706            {
     707                VERBOSE(VB_PLAYBACK, LOC + "Missing XVideo flags, rejecting.");
    643708                continue;
     709            }
     710            else
     711                VERBOSE(VB_PLAYBACK, LOC + "Has XVideo flags...");
    644712
    645713            const XvPortID firstPort = ai[i].base_id;
    646714            const XvPortID lastPort = ai[i].base_id + ai[i].num_ports - 1;
    647715            XvPortID p = 0;
    648716
    649             if (check_for_colorkey)
     717            if ((req[j].feature_flags & XvAttributes::kFeaturePicCtrl) &&
     718                (!xv_is_attrib_supported(disp, firstPort, "XV_BRIGHTNESS")))
    650719            {
    651                 int colorkey = 0;
    652                 X11S(colorkey = colorkey_supported(disp, firstPort));
    653                 if (!colorkey)
    654                 {
    655                     if (i == ((int)p_num_adaptors - 1))
    656                     {
    657                         VERBOSE(VB_PLAYBACK, LOC +
    658                             "Failed to find XV_COLORKEY support. "
    659                                     "Disabling XV_COLORKEY check");
    660                         check_for_colorkey = false;
    661                         i = -1;
    662                     }
    663                     continue;
    664                 }
     720                VERBOSE(VB_PLAYBACK, LOC +
     721                        "Missing XV_BRIGHTNESS, rejecting.");
     722                continue;
    665723            }
     724            else if (req[j].feature_flags & XvAttributes::kFeaturePicCtrl)
     725                VERBOSE(VB_PLAYBACK, LOC + "Has XV_BRIGHTNESS...");
    666726
    667             if (useXVMC[j])
     727            if ((req[j].feature_flags & XvAttributes::kFeatureChromakey) &&
     728                (!xv_is_attrib_supported(disp, firstPort, "XV_COLORKEY")))
    668729            {
     730                VERBOSE(VB_PLAYBACK, LOC +
     731                        "Missing XV_COLORKEY, rejecting.");
     732                continue;
     733            }
     734            else if (req[j].feature_flags & XvAttributes::kFeatureChromakey)
     735                VERBOSE(VB_PLAYBACK, LOC + "Has XV_COLORKEY...");
     736
     737            VERBOSE(VB_PLAYBACK, LOC + "Here...");
     738
     739            if (req[j].feature_flags & XvAttributes::kFeatureXvMC)
     740            {
    669741#ifdef USING_XVMC
    670742                int surfNum;
    671                 XvMCSurfaceTypes::find(width, height, xvmc_chroma,
    672                                        useVLD[j], useIDCT[j], stream_type,
    673                                        0, 0,
    674                                        disp, firstPort, lastPort,
    675                                        p, surfNum);
     743                XvMCSurfaceTypes::find(
     744                    width, height, xvmc_chroma,
     745                    req[j].feature_flags & XvAttributes::kFeatureVLD,
     746                    req[j].feature_flags & XvAttributes::kFeatureIDCT,
     747                    stream_type,
     748                    0, 0,
     749                    disp, firstPort, lastPort,
     750                    p, surfNum);
     751
    676752                if (surfNum<0)
    677753                    continue;
    678754
     
    718794        }
    719795        if (port != -1)
    720796        {
    721             VERBOSE(VB_PLAYBACK, LOC + msg[j].arg(port));
     797            VERBOSE(VB_PLAYBACK, LOC + req[j].description.arg(port));
    722798            break;
    723799        }
    724800    }
     
    866942        gl_context->Show();
    867943        gl_context->MakeCurrent(true);
    868944        gl_videochain = new OpenGLVideo();
    869         ok = gl_videochain->Init(gl_context, use_picture_controls,
     945        ok = gl_videochain->Init(gl_context, db_use_picture_controls,
    870946                                 true, video_dim,
    871947                                 display_visible_rect,
    872948                                 display_video_rect, video_rect, true);
     
    14551531        db_vdisp_profile->SetVideoRenderer(renderer);
    14561532    }
    14571533
    1458     // This needs to be here because OpenGL needs it in InitVideoBuffers()..
    1459     use_picture_controls =
    1460         gContext->GetNumSetting("UseOutputPictureControls", 0);
    1461 
    14621534    // Create video buffers
    14631535    bool use_xv     = (renderer.left(2) == "xv");
    14641536    bool use_shm    = (renderer == "xshm");
     
    14891561        XV_INIT_FATAL_ERROR_TEST(!ok, "Failed to get any video output (nCK)");
    14901562    }
    14911563
    1492     // The OpenGL video output method always allows picture controls.
    1493     // The XVideo output methods sometimes allow the picture to
    1494     // be adjusted, if the chroma keying color can be discovered.
    1495     use_picture_controls &=
    1496         (VideoOutputSubType() >= XVideo && xv_colorkey) ||
    1497         (VideoOutputSubType() == OpenGL);
    1498 
    1499     if (use_picture_controls)
     1564    // Initialize the picture controls if we need to..
     1565    if (db_use_picture_controls)
    15001566        InitPictureAttributes();
    15011567
    15021568    return true;
     
    15631629 */
    15641630void VideoOutputXv::InitColorKey(bool turnoffautopaint)
    15651631{
    1566     int ret = Success, xv_val=0;
     1632    static const char *attr_autopaint = "XV_AUTOPAINT_COLORKEY";
     1633    int xv_val=0;
     1634
     1635    // handle autopaint.. Normally we try to disable it so that bob-deint
     1636    // doesn't actually bob up the top and bottom borders up and down...
    15671637    xv_draw_colorkey = true;
    1568     xv_colorkey = 0; // set to invalid value as a sentinel
    1569 
    1570     Atom xv_atom;
    1571     XvAttribute *attributes;
    1572     int attrib_count;
    1573 
    1574     X11S(attributes = XvQueryPortAttributes(XJ_disp, xv_port, &attrib_count));
    1575     for (int i = (attributes) ? 0 : attrib_count; i < attrib_count; i++)
     1638    if (xv_is_attrib_supported(XJ_disp, xv_port, attr_autopaint, &xv_val))
    15761639    {
    1577         if (!strcmp(attributes[i].name, "XV_AUTOPAINT_COLORKEY"))
     1640        if (turnoffautopaint && xv_val)
    15781641        {
    1579             X11S(xv_atom = XInternAtom(XJ_disp, "XV_AUTOPAINT_COLORKEY", False));
    1580             if (xv_atom == None)
    1581                 continue;
     1642            xv_set_attrib(XJ_disp, xv_port, attr_autopaint, 0);
     1643            if (!xv_get_attrib(XJ_disp, xv_port, attr_autopaint, xv_val) ||
     1644                xv_val)
     1645            {
     1646                VERBOSE(VB_IMPORTANT, "Failed to disable autopaint");
     1647                xv_draw_colorkey = false;
     1648            }
     1649        }
     1650        else if (!turnoffautopaint && !xv_val)
     1651        {
     1652            xv_set_attrib(XJ_disp, xv_port, attr_autopaint, 1);
     1653            if (!xv_get_attrib(XJ_disp, xv_port, attr_autopaint, xv_val) ||
     1654                !xv_val)
     1655            {
     1656                VERBOSE(VB_IMPORTANT, "Failed to enable autopaint");
     1657            }
     1658        }
     1659        else if (!turnoffautopaint && xv_val)
     1660        {
     1661            xv_draw_colorkey = false;
     1662        }
     1663    }
    15821664
    1583             X11L;
    1584             if (turnoffautopaint)
    1585                 ret = XvSetPortAttribute(XJ_disp, xv_port, xv_atom, 0);
    1586             else
    1587                 ret = XvSetPortAttribute(XJ_disp, xv_port, xv_atom, 1);
     1665    // Check that we have a colorkey attribute and make sure it is not
     1666    // the same color as the MythTV letterboxing (currently Black).
     1667    // This avoids avoid bob-deint actually bobbing the borders of
     1668    // the video up and down..
     1669    int letterbox_color = 0;
     1670    static const char *attr_chroma = "XV_COLORKEY";
     1671    if (!xv_is_attrib_supported(XJ_disp, xv_port, attr_chroma, &xv_colorkey))
     1672    {
     1673        // set to MythTV letterbox color as a sentinel
     1674        xv_colorkey = letterbox_color;
     1675    }
     1676    else if (xv_colorkey == letterbox_color)
     1677    {
     1678        // if it is a valid attribute and set to the letterbox color, change it
     1679        xv_set_attrib(XJ_disp, xv_port, attr_chroma, 1);
    15881680
    1589             ret = XvGetPortAttribute(XJ_disp, xv_port, xv_atom, &xv_val);
    1590             // turn of colorkey drawing if autopaint is on
    1591             if (Success == ret && xv_val)
    1592                 xv_draw_colorkey = false;
    1593             X11U;
     1681        if (xv_get_attrib(XJ_disp, xv_port, attr_chroma, xv_val) &&
     1682            xv_val != letterbox_color)
     1683        {
     1684            xv_colorkey = xv_val;
    15941685        }
    15951686    }
    1596     if (attributes)
    1597         X11S(XFree(attributes));
    15981687
    1599     if (!xv_draw_colorkey)
    1600         return;
    1601 
    1602     QString msg = LOC + "Chromakeying not possible with this XVideo port.";
    1603     X11S(xv_colorkey = colorkey_supported(XJ_disp, xv_port));
    1604     if (!xv_colorkey)
     1688    if (xv_colorkey == letterbox_color)
    16051689    {
    1606         VERBOSE(VB_PLAYBACK, msg);
    1607         return;
     1690        VERBOSE(VB_PLAYBACK, LOC +
     1691                "Chromakeying not possible with this XVideo port.");
    16081692    }
    16091693}
    16101694
     
    30203104    {
    30213105        VERBOSE(VB_PLAYBACK, LOC + "Initialise PiP.");
    30223106        gl_pipchain = new OpenGLVideo();
    3023         bool success = gl_pipchain->Init(gl_context, use_picture_controls,
     3107        bool success = gl_pipchain->Init(gl_context, db_use_picture_controls,
    30243108                     true, QSize(pipVideoWidth, pipVideoHeight),
    30253109                     position, position,
    30263110                     QRect(0, 0, pipVideoWidth, pipVideoHeight), false);
     
    30403124        VERBOSE(VB_PLAYBACK, LOC + "Re-initialise PiP.");
    30413125
    30423126        bool success = gl_pipchain->ReInit(
    3043             gl_context, use_picture_controls,
     3127            gl_context, db_use_picture_controls,
    30443128            true, QSize(pipVideoWidth, pipVideoHeight),
    30453129            position, position,
    30463130            QRect(0, 0, pipVideoWidth, pipVideoHeight), false);
     
    36933777int VideoOutputXv::SetPictureAttribute(
    36943778    PictureAttribute attribute, int newValue)
    36953779{
    3696     if (!use_picture_controls)
     3780    if (!supported_attributes)
    36973781        return -1;
    36983782
    36993783    if (VideoOutputSubType() == OpenGL)
     
    37053789        return newValue;
    37063790    }
    37073791
    3708     QString  attrName = QString::null;
    3709     int      valAdj   = 0;
     3792    QString attrName = toXVString(attribute);
     3793    int valAdj = (kPictureAttribute_Hue == attribute) ? xv_hue_base : 0;
    37103794
    3711     if (kPictureAttribute_Brightness == attribute)
    3712         attrName = "XV_BRIGHTNESS";
    3713     else if (kPictureAttribute_Contrast == attribute)
    3714         attrName = "XV_CONTRAST";
    3715     else if (kPictureAttribute_Colour == attribute)
    3716         attrName = "XV_SATURATION";
    3717     else if (kPictureAttribute_Hue == attribute)
    3718     {
    3719         attrName = "XV_HUE";
    3720         valAdj   = xv_hue_base;
    3721     }
    3722 
    37233795    if (attrName.isEmpty())
    37243796        return -1;
    37253797
     3798    if (0 == ((1<<((int)attribute)) & supported_attributes))
     3799        return -1;
     3800
    37263801    newValue = min(max(newValue, 0), 100);
    37273802
    3728     Atom attributeAtom = None;
    3729     X11S(attributeAtom = XInternAtom(XJ_disp, attrName.ascii(), False));
    3730     if (attributeAtom == None)
    3731         return -1;
     3803    int port_min = xv_attribute_min[attribute];
     3804    int port_max = xv_attribute_max[attribute];
     3805    int range    = port_max - port_min;
     3806   
     3807    int tmpval2 = (newValue + valAdj) % 100;
     3808    int tmpval3 = (int) roundf(range * 0.01f * tmpval2);
     3809    int value   = min(tmpval3 + port_min, port_max);
    37323810
    3733     XvAttribute *attributes = NULL;
    3734     int howmany;
    3735     X11S(attributes = XvQueryPortAttributes(XJ_disp, xv_port, &howmany));
    3736     if (!attributes)
    3737         return -1;
     3811    xv_set_attrib(XJ_disp, xv_port, attrName.ascii(), value);
    37383812
    3739     bool value_set = false;
    3740     for (int i = 0; i < howmany; i++)
     3813#ifdef USING_XVMC
     3814    // Needed for VIA XvMC to commit change immediately.
     3815    if (video_output_subtype > XVideo)
    37413816    {
    3742         if (attrName != attributes[i].name)
    3743             continue;
     3817        Atom xv_atom;
     3818        X11S(xv_atom = XInternAtom(XJ_disp, attrName.ascii(), False));
     3819        if (xv_atom != None)
     3820            X11S(XvMCSetAttribute(XJ_disp, xvmc_ctx, xv_atom, value));
     3821    }
     3822#endif
    37443823
    3745         int port_min = attributes[i].min_value;
    3746         int port_max = attributes[i].max_value;
    3747         int range    = port_max - port_min;
     3824    SetPictureAttributeDBValue(attribute, newValue);
     3825    return newValue;
     3826}
    37483827
    3749         int tmpval2 = (newValue + valAdj) % 100;
    3750         int tmpval3 = (int) roundf(range * 0.01f * tmpval2);
    3751         int value   = min(tmpval3 + port_min, port_max);
    3752         value_set = true;
     3828void VideoOutputXv::InitPictureAttributes(void)
     3829{
     3830    supported_attributes = kPictureAttributeSupported_None;
    37533831
    3754         X11L;
    3755         XvSetPortAttribute(XJ_disp, xv_port, attributeAtom, value);
    3756 #ifdef USING_XVMC
    3757         // Needed for VIA XvMC to commit change immediately.
    3758         if (video_output_subtype > XVideo)
    3759             XvMCSetAttribute(XJ_disp, xvmc_ctx, attributeAtom, value);
    3760 #endif
    3761         X11U;
    3762         break;
     3832    if (VideoOutputSubType() == OpenGL)
     3833    {
     3834        supported_attributes = gl_videochain->GetSupportedPictureAttributes();
    37633835    }
     3836    else if (VideoOutputSubType() >= XVideo)
     3837    {
     3838        int val, min_val, max_val;
     3839        for (uint i = 0; i < kPictureAttribute_MAX; i++)
     3840        {
     3841            QString attrName = toXVString((PictureAttribute)i);
     3842            if (attrName.isEmpty())
     3843                continue;
    37643844
    3765     X11S(XFree(attributes));
     3845            if (xv_is_attrib_supported(XJ_disp, xv_port, attrName.ascii(),
     3846                                       &val, &min_val, &max_val))
     3847            {
     3848                supported_attributes = (PictureAttributeSupported)
     3849                    (supported_attributes | toMask((PictureAttribute)i));
     3850                xv_attribute_min[(PictureAttribute)i] = min_val;
     3851                xv_attribute_max[(PictureAttribute)i] = max_val;
     3852            }
     3853        }
     3854    }
     3855    else
     3856    {
     3857        return;
     3858    }
    37663859
    3767     if (!value_set)
    3768         return -1;
     3860    VERBOSE(VB_PLAYBACK, LOC + QString("PictureAttributes: 0x%1")
     3861            .arg(toString(supported_attributes)));
    37693862
    3770     SetPictureAttributeDBValue(attribute, newValue);
    3771     return newValue;
     3863    VideoOutput::InitPictureAttributes();
    37723864}
    37733865
    37743866void VideoOutputXv::CheckFrameStates(void)
  • libs/libmythtv/videooutbase.h

     
    106106    /// \brief Tells video output that a full repaint is needed.
    107107    void ExposeEvent(void) { needrepaint = true; }
    108108
     109    PictureAttributeSupported GetSupportedPictureAttributes(void) const
     110        { return supported_attributes; }
    109111    int         ChangePictureAttribute(PictureAttribute, bool direction);
    110112    virtual int SetPictureAttribute(PictureAttribute, int newValue);
    111113    int         GetPictureAttribute(PictureAttribute) const;
    112     void        InitPictureAttributes(void);
     114    virtual void InitPictureAttributes(void);
    113115
    114116    bool AllowPreviewEPG(void) { return allowpreviewepg; }
    115117
     
    243245    float   db_scale_vert;    ///< Vertical Overscan/Underscan percentage
    244246    PIPLocation db_pip_location;
    245247    int     db_pip_size;      ///< percentage of full window to use for PiP
    246 
    247248    typedef QMap<PictureAttribute,int> PictureSettingMap;
    248249    PictureSettingMap  db_pict_attr; ///< Picture settings
    249250    AspectOverrideMode db_aspectoverride;
    250251    AdjustFillMode     db_adjustfill;
    251252    QString db_deint_filtername;
     253    bool    db_use_picture_controls;
    252254
    253255    VideoDisplayProfile *db_vdisp_profile;
    254256
     
    315317    bool    errored;
    316318    long long framesPlayed;
    317319    bool    db_scaling_allowed; ///< disable this to prevent overscan/underscan
     320    PictureAttributeSupported supported_attributes;
    318321};
    319322
    320323#endif
  • programs/mythfrontend/globalsettings.cpp

     
    17831783    return gc;
    17841784}
    17851785
    1786 #ifdef USING_XV
    17871786static HostCheckBox *UsePicControls()
    17881787{
    17891788    HostCheckBox *gc = new HostCheckBox("UseOutputPictureControls");
    1790     gc->setLabel(QObject::tr("Use Xv picture controls"));
     1789    gc->setLabel(QObject::tr("Enable picture controls"));
    17911790    gc->setValue(false);
    1792     gc->setHelpText(QObject::tr("If enabled, Xv picture controls (brightness, "
    1793                     "contrast, etc.) are used during playback. These are "
    1794                     "independent of the Video4Linux controls used for "
    1795                     "recording. The Xv controls may not work properly on "
    1796                     "some systems."));
     1791    gc->setHelpText(
     1792        QObject::tr(
     1793            "If enabled, MythTV attempts to initialize picture controls "
     1794            "(brightness, contrast, etc.) that are applied during playback."));
    17971795    return gc;
    17981796}
    1799 #endif
    18001797
    18011798static HostCheckBox *AudioNagSetting()
    18021799{
     
    43564353#ifdef USING_OPENGL_VSYNC
    43574354    general1->addChild(UseOpenGLVSync());
    43584355#endif // USING_OPENGL_VSYNC
    4359 #ifdef USING_XV
    43604356    general1->addChild(UsePicControls());
    4361 #endif // USING_XV
    43624357    addChild(general1);
    43634358
    43644359    VerticalConfigurationGroup* general2 =