qtmobility/plugins/multimedia/gstreamer/qgstreamervideooverlay.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    48 
    48 
    49 QGstreamerVideoOverlay::QGstreamerVideoOverlay(QObject *parent)
    49 QGstreamerVideoOverlay::QGstreamerVideoOverlay(QObject *parent)
    50     : QVideoWindowControl(parent)
    50     : QVideoWindowControl(parent)
    51     , m_surface(new QX11VideoSurface)
    51     , m_surface(new QX11VideoSurface)
    52     , m_videoSink(reinterpret_cast<GstElement*>(QVideoSurfaceGstSink::createSink(m_surface)))
    52     , m_videoSink(reinterpret_cast<GstElement*>(QVideoSurfaceGstSink::createSink(m_surface)))
    53     , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
    53     , m_aspectRatioMode(Qt::KeepAspectRatio)
    54     , m_fullScreen(false)
    54     , m_fullScreen(false)
    55 {
    55 {
    56     if (m_videoSink) {
    56     if (m_videoSink) {
    57         gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership
    57         gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership
    58         gst_object_sink(GST_OBJECT(m_videoSink));
    58         gst_object_sink(GST_OBJECT(m_videoSink));
    90     m_displayRect = rect;
    90     m_displayRect = rect;
    91 
    91 
    92     setScaledDisplayRect();
    92     setScaledDisplayRect();
    93 }
    93 }
    94 
    94 
    95 QVideoWidget::AspectRatioMode QGstreamerVideoOverlay::aspectRatioMode() const
    95 Qt::AspectRatioMode QGstreamerVideoOverlay::aspectRatioMode() const
    96 {
    96 {
    97     return m_aspectRatioMode;
    97     return m_aspectRatioMode;
    98 }
    98 }
    99 
    99 
   100 void QGstreamerVideoOverlay::setAspectRatioMode(QVideoWidget::AspectRatioMode mode)
   100 void QGstreamerVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode)
   101 {
   101 {
   102     m_aspectRatioMode = mode;
   102     m_aspectRatioMode = mode;
   103 
   103 
   104     setScaledDisplayRect();
   104     setScaledDisplayRect();
   105 }
   105 }
   188     emit nativeSizeChanged();
   188     emit nativeSizeChanged();
   189 }
   189 }
   190 
   190 
   191 void QGstreamerVideoOverlay::setScaledDisplayRect()
   191 void QGstreamerVideoOverlay::setScaledDisplayRect()
   192 {
   192 {
       
   193     QRect formatViewport = m_surface->surfaceFormat().viewport();
       
   194 
   193     switch (m_aspectRatioMode) {
   195     switch (m_aspectRatioMode) {
   194     case QVideoWidget::KeepAspectRatio:
   196     case Qt::KeepAspectRatio:
   195         {
   197         {
   196             QSize size = m_surface->surfaceFormat().viewport().size();
   198             QSize size = formatViewport.size();
   197 
       
   198             size.scale(m_displayRect.size(), Qt::KeepAspectRatio);
   199             size.scale(m_displayRect.size(), Qt::KeepAspectRatio);
   199 
   200 
   200             QRect rect(QPoint(0, 0), size);
   201             QRect rect(QPoint(0, 0), size);
   201             rect.moveCenter(m_displayRect.center());
   202             rect.moveCenter(m_displayRect.center());
   202 
   203 
   203             m_surface->setDisplayRect(rect);
   204             m_surface->setDisplayRect(rect);
       
   205             m_surface->setViewport(formatViewport);
   204         }
   206         }
   205         break;
   207         break;
   206     case QVideoWidget::IgnoreAspectRatio:
   208     case Qt::IgnoreAspectRatio:
   207         m_surface->setDisplayRect(m_displayRect);
   209         m_surface->setDisplayRect(m_displayRect);
       
   210         m_surface->setViewport(formatViewport);
       
   211         break;
       
   212     case Qt::KeepAspectRatioByExpanding:
       
   213         {
       
   214             QSize size = m_displayRect.size();
       
   215             size.scale(formatViewport.size(), Qt::KeepAspectRatio);
       
   216 
       
   217             QRect viewport(QPoint(0, 0), size);
       
   218             viewport.moveCenter(formatViewport.center());
       
   219 
       
   220             m_surface->setDisplayRect(m_displayRect);
       
   221             m_surface->setViewport(viewport);
       
   222         }
   208         break;
   223         break;
   209     };
   224     };
   210 }
   225 }