Ticket #6211: 0002-fixing-embed-video-on-osx-quartz-renderer-part1.patch

File 0002-fixing-embed-video-on-osx-quartz-renderer-part1.patch, 11.7 KB (added by chr, 14 years ago)
  • mythtv/libs/libmythtv/videoout_quartz.cpp

    From 99a3514072ef70c39683237664e8fffd4977590c Mon Sep 17 00:00:00 2001
    From: chris <chris@flunder.ekke.wtal>
    Date: Tue, 1 Jun 2010 00:47:48 +0200
    Subject: [PATCH 2/5] fixing embed video on osx quartz renderer part1
    
    This patch makes the quarz renderer to use of the calulations
    of VideoOutWindow::GetDisplayVideoRect() for the desired parameters
    instead repeating that code.
    However, that will break video out in a resizeable window ... a
    feature which isn't used by mythth ... it's a fullscreen application,
    isn't it?
    ---
     mythtv/libs/libmythtv/videoout_quartz.cpp |  156 +++++++++++------------------
     1 files changed, 60 insertions(+), 96 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/videoout_quartz.cpp b/mythtv/libs/libmythtv/videoout_quartz.cpp
    index 450e945..78e8f15 100644
    a b class VideoOutputQuartzView 
    8787
    8888    virtual void InputChanged(int width, int height, float aspect,
    8989                              MythCodecID av_codec_id);
    90     virtual void MoveResize(QRect newRect);
     90    virtual void MoveResize();
    9191
    9292    virtual void EmbedChanged(bool embedded);
    9393
    9494  protected:
    9595    virtual bool Begin(void);
    9696    virtual void End(void);
    97     virtual void Transform(QRect newRect);
     97    virtual void Transform();
    9898    virtual void BlankScreen(bool deferred);
    9999
    100100    // Subclasses implement the following methods:
    class VideoOutputQuartzView 
    106106    QuartzData *       parentData;    // information about video source is here
    107107
    108108    CGrafPtr           thePort;       // QuickDraw graphics port
    109     QRect              m_desired;     // Desired output size characteristics
    110109    ImageSequence      theCodec;      // QuickTime sequence ID
    111110    RgnHandle          theMask;       // clipping region
    112111
    class QuartzData 
    179178    Rect               windowBounds;      // dimensions, to restore size later
    180179    CGDirectDisplayID  screen;            // screen containing main window
    181180    float              refreshRate;       // for screen above
     181    QRect              display_rect;
    182182
    183183    // Global preferences:
    184184    bool               drawInWindow;      // Fullscreen or in GUI view?
    bool VideoOutputQuartzView::Begin(void) 
    222222        return false;
    223223    }
    224224
    225     // Set initial output size
    226     Rect portBounds;
    227     GetPortBounds(thePort, &portBounds);
    228     VERBOSE(VB_PLAYBACK, QString("%0Viewport currently %1,%2 -> %3,%4")
    229                          .arg(name).arg(portBounds.left).arg(portBounds.top)
    230                          .arg(portBounds.right).arg(portBounds.bottom));
    231     m_desired.setWidth(portBounds.right);
    232     m_desired.setHeight(portBounds.bottom);
    233225#if 0
    234226    // The clipping mask
    235227    theMask = NewRgn();
    bool VideoOutputQuartzView::Begin(void) 
    270262    viewLock.unlock();
    271263
    272264    // set transformation matrix
    273     Transform(m_desired);
     265    Transform();
    274266
    275267    return true;
    276268}
    void VideoOutputQuartzView::End(void) 
    294286}
    295287
    296288/// Build the transformation matrix to scale the video appropriately.
    297 void VideoOutputQuartzView::Transform(QRect newRect)
     289void VideoOutputQuartzView::Transform()
    298290{
    299291    MatrixRecord matrix;
    300292    SetIdentityMatrix(&matrix);
    301293
    302     int x, y, w, h, sw, sh;
    303     x = newRect.left();
    304     y = newRect.top();
    305     w = newRect.width();
    306     h = newRect.height();
    307     sw = parentData->srcWidth;
    308     sh = parentData->srcHeight;
    309 
    310     // constants for transformation operations
    311     Fixed one, zero;
    312     one  = Long2Fix(1);
    313     zero = Long2Fix(0);
    314 
    315     VERBOSE(VB_PLAYBACK, QString("%0Viewport is %1 x %2")
    316                                 .arg(name).arg(w).arg(h));
    317     VERBOSE(VB_PLAYBACK, QString("%0Image is %1 x %2")
    318                                 .arg(name).arg(sw).arg(sh));
    319 
    320     double hscale = (double) w / sw;
    321     double vscale = (double) h / sh;
    322 
    323     // cap zooming if we requested it
    324     if (!parentData->scaleUpVideo)
    325     {
    326         double maxScale = fmax(hscale, vscale);
    327         hscale /= maxScale;
    328         vscale /= maxScale;
    329     }
    330 
    331     if ((hscale < 0.99) || (hscale > 1.01) ||
    332         (vscale < 0.99) || (vscale > 1.01))
    333     {
    334         VERBOSE(VB_PLAYBACK, QString("%0Scaling to %1 x %2 of original")
    335                                     .arg(name).arg(hscale).arg(vscale));
    336         ScaleMatrix(&matrix,
    337                     X2Fix(hscale),
    338                     X2Fix(vscale),
    339                     zero, zero);
     294    Rect Rsrc, Rdst;
     295    QRect display_rect;
    340296
    341         // reset sw, sh for new apparent width/height
    342         sw = (int)(sw * hscale);
    343         sh = (int)(sh * vscale);
    344     }
     297    Rsrc.left   = 0;
     298    Rsrc.top    = 0;
     299    Rsrc.right  = parentData->srcWidth;
     300    Rsrc.bottom = parentData->srcHeight;
    345301
    346     // center image in viewport
    347     if ((h != sh) || (w != sw))
    348     {
    349         VERBOSE(VB_PLAYBACK, QString("%0Centering with %1, %2")
    350                              .arg(name).arg((w - sw)/2.0).arg((h - sh)/2.0));
    351         TranslateMatrix(&matrix, X2Fix((w - sw) / 2.0), X2Fix((h - sh) / 2.0));
    352     }
     302    display_rect= parentData->display_rect;
     303    Rdst.left   = display_rect.left();
     304    Rdst.top    = display_rect.top();
     305    Rdst.right  = display_rect.right();
     306    Rdst.bottom = display_rect.bottom();
    353307
    354 // apply the basic sizing to DVDV
    355 #ifdef USING_DVDV
    356     if (parentData->dvdv)
    357     {
    358         parentData->dvdv->MoveResize(
    359             0, 0, parentData->srcWidth, parentData->srcHeight,
    360             (int)((w - sw) / 2.0), (int)((h - sh) / 2.0), sw, sh);
    361     }
    362 #endif // USING_DVDV
    363 
    364     // apply graphics port or embedding offset
    365     if (x || y)
    366     {
    367         VERBOSE(VB_PLAYBACK, QString("%0Translating to %1, %2")
    368                                     .arg(name).arg(x).arg(y));
    369         TranslateMatrix(&matrix, Long2Fix(x), Long2Fix(y));
    370     }
    371 
    372     // Apply the transformation
     308    MapMatrix(&matrix, &Rsrc, &Rdst);
     309#if 0
     310    VERBOSE(VB_PLAYBACK, QString("%0Viewport is now %1 / %2 / %3 / %4")
     311                                .arg(name)
     312                                .arg(Rdst.left)
     313                                .arg(Rdst.top)
     314                                .arg(Rdst.right)
     315                                .arg(Rdst.bottom)
     316    );
     317#endif
    373318    viewLock.lock();
    374319    SetDSequenceMatrix(theCodec, &matrix);
    375320    viewLock.unlock();
    void VideoOutputQuartzView::BlankScreen(bool deferred) 
    388333    if (thePort)
    389334    {
    390335        SetPort(thePort);
    391 
     336#if 0
    392337        // set clipping rectangle
    393338        Rect clipRect;
    394339        if (m_desired.width() && m_desired.height())
    void VideoOutputQuartzView::BlankScreen(bool deferred) 
    402347        {
    403348            GetPortBounds(thePort, &clipRect);
    404349        }
     350#endif
     351        Rect clipRect;
     352        GetPortBounds(thePort, &clipRect);
     353
    405354        RgnHandle clipRgn = NewRgn();
    406355        RectRgn(clipRgn, &clipRect);
    407356
    void VideoOutputQuartzView::InputChanged(int width, int height, float aspect, 
    472421    Begin();
    473422}
    474423
    475 void VideoOutputQuartzView::MoveResize(QRect newRect)
     424void VideoOutputQuartzView::MoveResize()
    476425{
    477426    if (applyMoveResize)
    478         Transform(newRect);
     427        Transform();
    479428}
    480429
    481430/// Subclasses that block the main window should suspend
    class VoqvEmbedded : public VideoOutputQuartzView 
    576525    VoqvEmbedded(QuartzData *pData, int x, int y, int w, int h)
    577526    : VideoOutputQuartzView(pData)
    578527    {
    579         m_desired = QRect(x, y, w, h);
     528        // m_desired = QRect(x, y, w, h);
    580529        name = "Embedded window: ";
    581530    };
    582531
    class VoqvDock : public VideoOutputQuartzView 
    741690                    "BeginQDContextForApplicationDockTile failed");
    742691            return false;
    743692        }
     693
    744694        return true;
    745695    };
    746696
    class VoqvFloater : public VideoOutputQuartzView 
    790740            // Resize complete, reset the window drawing transformation
    791741            Rect curBounds;
    792742            GetPortBounds(thePort, &curBounds);
    793             m_desired.setWidth(curBounds.right - curBounds.left);
    794             m_desired.setHeight(curBounds.bottom - curBounds.top);
    795             SetRectRgn(theMask, m_desired.left(),  m_desired.top(),
    796                                 m_desired.width(), m_desired.height());
    797             Transform(m_desired);
     743
     744            VERBOSE(VB_IMPORTANT, "Fixme: resizing window");
     745
     746//          m_desired.setWidth(curBounds.right - curBounds.left);
     747//          m_desired.setHeight(curBounds.bottom - curBounds.top);
     748//          SetRectRgn(theMask, m_desired.left(),  m_desired.top(),
     749//                              m_desired.width(), m_desired.height());
     750            Transform();
    798751        }
    799752        resizing = startResizing;
    800753    }
    class VoqvDesktop : public VideoOutputQuartzView 
    10561009            viewLock.unlock();
    10571010            return false;
    10581011        }
     1012
    10591013        viewLock.unlock();
    10601014        ShowWindow(window);
    10611015        // don't lose focus from main window
    VideoOutputQuartz::~VideoOutputQuartz() 
    11301084
    11311085void VideoOutputQuartz::VideoAspectRatioChanged(float aspect)
    11321086{
    1133     VERBOSE(VB_PLAYBACK, (LOC + "VideoAspectRatioChanged(aspect=%1) [was %2]")
    1134                          .arg(aspect).arg(data->srcAspect));
     1087    //VERBOSE(VB_PLAYBACK, (LOC + "VideoAspectRatioChanged(aspect=%1) [was %2]")
     1088    //                     .arg(aspect).arg(data->srcAspect));
     1089    VERBOSE(VB_PLAYBACK, "QU: VideoAspectRatioChanged");
    11351090
    11361091    VideoOutput::VideoAspectRatioChanged(aspect);
    11371092
    void VideoOutputQuartz::ToggleAdjustFill(AdjustFillMode adjustFill) 
    11551110
    11561111    // We could change all the views, but the user probably only
    11571112    // wants the main one (window or fullscreen) to change.
    1158     data->views[0]->MoveResize(windows[0].GetDisplayVideoRect());
     1113    data->views[0]->MoveResize();
    11591114}
    11601115
    11611116void VideoOutputQuartz::MoveResize(void)
    void VideoOutputQuartz::MoveResize(void) 
    11641119    // the user's current aspect/fill/letterbox/zoom settings.
    11651120    VideoOutput::MoveResize();
    11661121
    1167     QRect newRect = windows[0].GetDisplayVideoRect();
     1122    const QSize video_dim = windows[0].GetVideoDim();
     1123    data->srcWidth  = video_dim.width();
     1124    data->srcHeight = video_dim.height();
     1125    data->srcAspect = windows[0].GetVideoAspect();
     1126    data->srcMode   = db_aspectoverride;
     1127    data->display_rect = windows[0].GetDisplayVideoRect();
    11681128
    11691129    vector<VideoOutputQuartzView*>::iterator it;
    11701130    for (it = data->views.begin(); it != data->views.end(); ++it)
    11711131    {
    1172         (*it)->MoveResize(newRect);
     1132        (*it)->MoveResize();
    11731133    }
    11741134}
    11751135
    bool VideoOutputQuartz::InputChanged(const QSize &input_size, 
    12241184
    12251185    data->srcWidth  = video_dim.width();
    12261186    data->srcHeight = video_dim.height();
    1227     data->srcAspect = aspect;
     1187    data->srcAspect = windows[0].GetVideoAspect();
    12281188    data->srcMode   = db_aspectoverride;
     1189    data->display_rect = windows[0].GetDisplayVideoRect();
    12291190
    12301191    CreateQuartzBuffers();
    12311192
    bool VideoOutputQuartz::Init(int width, int height, float aspect, 
    12801241    data->srcHeight = video_dim.height();
    12811242    data->srcAspect = aspect;
    12821243    data->srcMode   = db_aspectoverride;
     1244    data->display_rect = windows[0].GetDisplayVideoRect();
    12831245
    12841246    // Initialize QuickTime
    12851247    if (EnterMovies())
    void VideoOutputQuartz::EmbedInWidget(int x, int y, int w, int h) 
    16091571    VideoOutput::EmbedInWidget(x, y, w, h);
    16101572
    16111573    data->pixelLock.lock();
     1574    data->display_rect = windows[0].GetDisplayVideoRect();
    16121575
    16131576    // warn other views that embedding is starting
    16141577    vector<VideoOutputQuartzView*>::iterator it = data->views.begin();
    void VideoOutputQuartz::StopEmbedding(void) 
    16381601    VideoOutput::StopEmbedding();
    16391602
    16401603    data->pixelLock.lock();
     1604    data->display_rect = windows[0].GetDisplayVideoRect();
    16411605
    16421606    // delete embedded widget
    16431607    if (data->embeddedView)