gstqtvideosinkplugin.h 3.01 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
    Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). <qt-info@nokia.com>
    Copyright (C) 2011 Collabora Ltd. <info@collabora.com>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License version 2.1
    as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file
 *   @brief Extracted from QtGstreamer to avoid overly complex dependency
 *   @author Gus Grubba <mavlink@grubba.com>
 */

24
#pragma once
Gus Grubba's avatar
Gus Grubba committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

#include <gst/gst.h>
#include <QtGlobal>

GST_DEBUG_CATEGORY_EXTERN(gst_qt5gstvideosink_debug);
#define GST_CAT_DEFAULT gst_qt5gstvideosink_debug


#define DEFINE_TYPE_FULL(cpp_type, type_name, parent_type, additional_initializations) \
    GType cpp_type::get_type() \
    { \
        static volatile gsize gonce_data = 0; \
        if (g_once_init_enter(&gonce_data)) { \
            GType type = 0; \
            GTypeInfo info; \
            info.class_size = sizeof(cpp_type##Class); \
            info.base_init = &cpp_type::base_init; \
            info.base_finalize = NULL; \
            info.class_init = &cpp_type::class_init; \
            info.class_finalize = NULL; \
            info.class_data = NULL; \
            info.instance_size = sizeof(cpp_type); \
            info.n_preallocs = 0; \
            info.instance_init = &cpp_type::init; \
            info.value_table = 0; \
            type = g_type_register_static(parent_type, g_intern_static_string(type_name), &info, (GTypeFlags)0); \
            additional_initializations(type); \
            g_once_init_leave(&gonce_data, (gsize) type); \
        } \
        return (GType) gonce_data; \
    }

// To allow qt4 and qt5 versions of the plugin to be installed at the same time,
// use a different name for their GType, so that the glib type system can handle
// both plugins being loaded by the gstreamer registry
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
# define DEFINE_TYPE(cpp_type, parent_type) \
    DEFINE_TYPE_FULL(cpp_type, #cpp_type "_qt5", parent_type, Q_UNUSED)
# define DEFINE_TYPE_WITH_CODE(cpp_type, parent_type, additional_initializations) \
    DEFINE_TYPE_FULL(cpp_type, #cpp_type "_qt5", parent_type, additional_initializations)
#else
# define DEFINE_TYPE(cpp_type, parent_type) \
    DEFINE_TYPE_FULL(cpp_type, #cpp_type, parent_type, Q_UNUSED)
# define DEFINE_TYPE_WITH_CODE(cpp_type, parent_type, additional_initializations) \
    DEFINE_TYPE_FULL(cpp_type, #cpp_type, parent_type, additional_initializations)
#endif

inline bool qRealIsDouble() { return sizeof(qreal) == sizeof(double); }
#define G_TYPE_QREAL qRealIsDouble() ? G_TYPE_DOUBLE : G_TYPE_FLOAT