qtmobility/plugins/multimedia/gstreamer/qvideosurfacegstsink.h
changeset 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 <QtMultimedia/qvideosurfaceformat.h>
       
    53 #include <QtMultimedia/qvideoframe.h>
       
    54 #include <QtMultimedia/qabstractvideobuffer.h>
       
    55 
       
    56 QT_BEGIN_NAMESPACE
       
    57 class QAbstractVideoSurface;
       
    58 QT_END_NAMESPACE
       
    59 
       
    60 class QGstXvImageBuffer;
       
    61 class QGstXvImageBufferPool;
       
    62 
       
    63 class QVideoSurfaceGstDelegate : public QObject
       
    64 {
       
    65     Q_OBJECT
       
    66 public:
       
    67     QVideoSurfaceGstDelegate(QAbstractVideoSurface *surface);
       
    68 
       
    69     QList<QVideoFrame::PixelFormat> supportedPixelFormats(
       
    70             QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
       
    71 
       
    72     QVideoSurfaceFormat surfaceFormat() const;
       
    73 
       
    74     bool start(const QVideoSurfaceFormat &format, int bytesPerLine);
       
    75     void stop();
       
    76 
       
    77     bool isActive();
       
    78 
       
    79     GstFlowReturn render(GstBuffer *buffer);
       
    80 
       
    81 private slots:
       
    82     void queuedStart();
       
    83     void queuedStop();
       
    84     void queuedRender();
       
    85 
       
    86     void supportedFormatsChanged();
       
    87 
       
    88 private:
       
    89     QPointer<QAbstractVideoSurface> m_surface;
       
    90     QList<QVideoFrame::PixelFormat> m_supportedPixelFormats;
       
    91     QMutex m_mutex;
       
    92     QWaitCondition m_setupCondition;
       
    93     QWaitCondition m_renderCondition;
       
    94     QVideoSurfaceFormat m_format;
       
    95     QVideoFrame m_frame;
       
    96     GstFlowReturn m_renderReturn;
       
    97     int m_bytesPerLine;
       
    98     bool m_started;
       
    99 };
       
   100 
       
   101 class QVideoSurfaceGstSink
       
   102 {
       
   103 public:
       
   104     GstVideoSink parent;
       
   105 
       
   106     static QVideoSurfaceGstSink *createSink(QAbstractVideoSurface *surface);
       
   107     static QVideoSurfaceFormat formatForCaps(GstCaps *caps, int *bytesPerLine = 0);
       
   108 
       
   109 private:
       
   110     static GType get_type();
       
   111     static void class_init(gpointer g_class, gpointer class_data);
       
   112     static void base_init(gpointer g_class);
       
   113     static void instance_init(GTypeInstance *instance, gpointer g_class);
       
   114 
       
   115     static void finalize(GObject *object);
       
   116 
       
   117     static GstStateChangeReturn change_state(GstElement *element, GstStateChange transition);
       
   118 
       
   119     static GstCaps *get_caps(GstBaseSink *sink);
       
   120     static gboolean set_caps(GstBaseSink *sink, GstCaps *caps);
       
   121 
       
   122     static GstFlowReturn buffer_alloc(
       
   123             GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps, GstBuffer **buffer);
       
   124 
       
   125     static gboolean start(GstBaseSink *sink);
       
   126     static gboolean stop(GstBaseSink *sink);
       
   127 
       
   128     static gboolean unlock(GstBaseSink *sink);
       
   129 
       
   130     static gboolean event(GstBaseSink *sink, GstEvent *event);
       
   131     static GstFlowReturn preroll(GstBaseSink *sink, GstBuffer *buffer);
       
   132     static GstFlowReturn render(GstBaseSink *sink, GstBuffer *buffer);
       
   133 
       
   134 private:
       
   135     QVideoSurfaceGstDelegate *delegate;
       
   136     QGstXvImageBufferPool *pool;
       
   137     GstCaps *lastRequestedCaps;
       
   138     GstCaps *lastBufferCaps;
       
   139     QVideoSurfaceFormat *lastSurfaceFormat;
       
   140 };
       
   141 
       
   142 
       
   143 class QVideoSurfaceGstSinkClass
       
   144 {
       
   145 public:
       
   146     GstVideoSinkClass parent_class;
       
   147 };
       
   148 
       
   149 #endif