summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapivideosink.c
blob: 7ba672039a2940d0099157e1c9ae9c07e5fe5c5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 *  gstvaapivideosink.c - VA sink interface
 *
 *  gstreamer-vaapi (C) 2010-2011 Splitted-Desktop Systems
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
 *
 *  This library 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 library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

/**
 * SECTION:gstvaapivideosink
 * @short_description: An interface for implementing VA-API sink elements
 */

#include "config.h"
#include "gstvaapivideosink.h"

static void
gst_vaapi_video_sink_base_init(gpointer g_class)
{
    static gboolean is_initialized = FALSE;

    if (!is_initialized) {
        is_initialized = TRUE;
    }
}

GType
gst_vaapi_video_sink_get_type(void)
{
    static GType iface_type = 0;

    if (G_UNLIKELY(!iface_type)) {
        static const GTypeInfo info = {
            sizeof(GstVaapiVideoSinkInterface),
            gst_vaapi_video_sink_base_init,     /* base_init */
            NULL,                               /* base_finalize */
        };

        iface_type = g_type_register_static(
            G_TYPE_INTERFACE,
            "GstVaapiVideoSink",
            &info,
            0
        );
    }
    return iface_type;
}

/**
 * gst_vaapi_video_sink_get_display:
 * @sink: a #GstElement
 *
 * Returns the #GstVaapiDisplay created by the VA-API @sink element.
 *
 * Return value: the #GstVaapiDisplay created by the @sink element
 */
GstVaapiDisplay *
gst_vaapi_video_sink_get_display(GstVaapiVideoSink *sink)
{
    g_return_val_if_fail(GST_VAAPI_IS_VIDEO_SINK(sink), NULL);

    return GST_VAAPI_VIDEO_SINK_GET_INTERFACE(sink)->get_display(sink);
}

/**
 * gst_vaapi_video_sink_lookup:
 * @element: a #GstElement
 *
 * Traverses the whole downstream elements chain and finds a suitable
 * #GstVaapiDisplay. This is a helper function for intermediate VA-API
 * elements that don't create a #GstVaapiDisplay but require one.
 * e.g. the `vaapiconvert' element.
 *
 * Return value: the #GstVaapiDisplay created by a downstream sink
 * element, or %NULL if none was found
 */
GstVaapiVideoSink *
gst_vaapi_video_sink_lookup(GstElement *element)
{
    GstVaapiVideoSink *sink = NULL;
    GstPad *pad, *peer;

    g_return_val_if_fail(GST_IS_ELEMENT(element), NULL);

    while (!sink) {
        pad = gst_element_get_static_pad(element, "src");
        if (!pad)
            break;

        peer = gst_pad_get_peer(pad);
        g_object_unref(pad);
        if (!peer)
            break;

        element = gst_pad_get_parent_element(peer);
        g_object_unref(peer);
        if (!element)
            break;

        if (GST_VAAPI_IS_VIDEO_SINK(element))
            sink = GST_VAAPI_VIDEO_SINK(element);
        g_object_unref(element);
    }
    return sink;
}