plugins/multimedia/gstreamer/qvideosurfacegstsink.h
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef VIDEOSURFACEGSTSINK_H
       
    43 #define VIDEOSURFACEGSTSINK_H
       
    44 
       
    45 #include <gst/video/gstvideosink.h>
       
    46 
       
    47 #include <QtCore/qlist.h>
       
    48 #include <QtCore/qmutex.h>
       
    49 #include <QtCore/qqueue.h>
       
    50 #include <QtCore/qpointer.h>
       
    51 #include <QtCore/qwaitcondition.h>
       
    52 #include <qvideosurfaceformat.h>
       
    53 #include <qvideoframe.h>
       
    54 #include <qabstractvideobuffer.h>
       
    55 
       
    56 QT_BEGIN_NAMESPACE
       
    57 class QAbstractVideoSurface;
       
    58 QT_END_NAMESPACE
       
    59 
       
    60 #if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO)
       
    61 class QGstXvImageBuffer;
       
    62 class QGstXvImageBufferPool;
       
    63 #endif
       
    64 
       
    65 class QVideoSurfaceGstDelegate : public QObject
       
    66 {
       
    67     Q_OBJECT
       
    68 public:
       
    69     QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface);
       
    70 
       
    71     QList<QVideoFrame::PixelFormat> supportedPixelFormats(
       
    72             QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
       
    73 
       
    74     QVideoSurfaceFormat surfaceFormat() const;
       
    75 
       
    76     bool start(const QVideoSurfaceFormat &format, int bytesPerLine);
       
    77     void stop();
       
    78 
       
    79     bool isActive();
       
    80 
       
    81     GstFlowReturn render(GstBuffer *buffer);
       
    82 
       
    83 private slots:
       
    84     void queuedStart();
       
    85     void queuedStop();
       
    86     void queuedRender();
       
    87 
       
    88     void supportedFormatsChanged();
       
    89 
       
    90 private:
       
    91     QPointer<QAbstractVideoSurface> m_surface;
       
    92     QList<QVideoFrame::PixelFormat> m_supportedPixelFormats;
       
    93     QList<QVideoFrame::PixelFormat> m_supportedXVideoPixelFormats;
       
    94     QMutex m_mutex;
       
    95     QWaitCondition m_setupCondition;
       
    96     QWaitCondition m_renderCondition;
       
    97     QVideoSurfaceFormat m_format;
       
    98     QVideoFrame m_frame;
       
    99     GstFlowReturn m_renderReturn;
       
   100     int m_bytesPerLine;
       
   101     bool m_started;
       
   102 };
       
   103 
       
   104 class QVideoSurfaceGstSink
       
   105 {
       
   106 public:
       
   107     GstVideoSink parent;
       
   108 
       
   109     static QVideoSurfaceGstSink *createSink(QAbstractVideoSurface *surface);
       
   110     static QVideoSurfaceFormat formatForCaps(GstCaps *caps, int *bytesPerLine = 0);
       
   111 
       
   112 private:
       
   113     static GType get_type();
       
   114     static void class_init(gpointer g_class, gpointer class_data);
       
   115     static void base_init(gpointer g_class);
       
   116     static void instance_init(GTypeInstance *instance, gpointer g_class);
       
   117 
       
   118     static void finalize(GObject *object);
       
   119 
       
   120     static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
       
   121 
       
   122     static GstCaps *get_caps(GstBaseSink *sink);
       
   123     static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
       
   124 
       
   125     static GstFlowReturn buffer_alloc(
       
   126             GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer);
       
   127 
       
   128     static gboolean start(GstBaseSink *sink);
       
   129     static gboolean stop(GstBaseSink *sink);
       
   130 
       
   131     static gboolean unlock(GstBaseSink *sink);
       
   132 
       
   133     static gboolean event(GstBaseSink *sink, GstEvent *event);
       
   134     static GstFlowReturn preroll(GstBaseSink *sink, GstBuffer *buffer);
       
   135     static GstFlowReturn render(GstBaseSink *sink, GstBuffer *buffer);
       
   136 
       
   137 private:
       
   138     QVideoSurfaceGstDelegate *delegate;
       
   139 
       
   140 #if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO)
       
   141     QGstXvImageBufferPool *pool;
       
   142 #endif
       
   143 
       
   144     GstCaps *lastRequestedCaps;
       
   145     GstCaps *lastBufferCaps;
       
   146     QVideoSurfaceFormat *lastSurfaceFormat;
       
   147 };
       
   148 
       
   149 
       
   150 class QVideoSurfaceGstSinkClass
       
   151 {
       
   152 public:
       
   153     GstVideoSinkClass parent_class;
       
   154 };
       
   155 
       
   156 #endif