1
/* This file is part of the KDE project.
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include <QApplication>
19
#include "videowidget.h"
20
#include "qwidgetvideosink.h"
29
static GstVideoSinkClass* parentClass;
32
\class gstreamer::QWidgetVideoSink
36
template <VideoFormat FMT>
37
GstCaps* QWidgetVideoSink<FMT>::get_caps(GstBaseSink* sink)
44
const char* QWidgetVideoSinkClass<VideoFormat_YUV>::get_name()
46
return "QWidgetVideoSinkYUV";
50
const char* QWidgetVideoSinkClass<VideoFormat_RGB>::get_name()
52
return "QWidgetVideoSinkRGB";
55
template <VideoFormat FMT>
56
gboolean QWidgetVideoSink<FMT>::set_caps(GstBaseSink* sink, GstCaps* caps)
59
QWidgetVideoSink<FMT> *self = G_TYPE_CHECK_INSTANCE_CAST(sink, QWidgetVideoSinkClass<FMT>::get_type(), QWidgetVideoSink<FMT>);
61
data = gst_caps_get_structure(caps, 0);
63
gst_structure_get_int(data, "width", &self->width);
64
gst_structure_get_int(data, "height", &self->height);
65
gst_structure_get_int(data, "bpp", &self->bpp);
66
gst_structure_get_int(data, "depth", &self->depth);
70
template <VideoFormat FMT>
71
GstStateChangeReturn QWidgetVideoSink<FMT>::change_state(GstElement* element, GstStateChange transition)
73
return GST_ELEMENT_CLASS(parentClass)->change_state(element, transition);
76
template <VideoFormat FMT>
77
GstFlowReturn QWidgetVideoSink<FMT>::render(GstBaseSink* sink, GstBuffer* buf)
79
GstFlowReturn rc = GST_FLOW_OK;
83
QWidgetVideoSink<FMT> *self = G_TYPE_CHECK_INSTANCE_CAST(sink, QWidgetVideoSinkClass<FMT>::get_type(), QWidgetVideoSink<FMT>);
85
frame.resize(buf->size);
86
memcpy(frame.data(), buf->data, buf->size);
87
NewFrameEvent *frameEvent = new NewFrameEvent(frame, self->width, self->height);
88
QApplication::postEvent(self->renderWidget, frameEvent);
95
static GstStaticPadTemplate template_factory_yuv =
96
GST_STATIC_PAD_TEMPLATE("sink",
99
GST_STATIC_CAPS("video/x-raw-yuv, "
100
"framerate = (fraction) [ 0, MAX ], "
101
"width = (int) [ 1, MAX ], "
102
"height = (int) [ 1, MAX ],"
105
static GstStaticPadTemplate template_factory_rgb =
106
GST_STATIC_PAD_TEMPLATE("sink",
109
GST_STATIC_CAPS("video/x-raw-rgb, "
110
"framerate = (fraction) [ 0, MAX ], "
111
"width = (int) [ 1, MAX ], "
112
"height = (int) [ 1, MAX ],"
115
template <VideoFormat FMT>
116
struct template_factory;
120
struct template_factory<VideoFormat_YUV>
122
static GstStaticPadTemplate *getFactory()
124
return &template_factory_yuv;
129
struct template_factory<VideoFormat_RGB>
131
static GstStaticPadTemplate *getFactory()
133
return &template_factory_rgb;
137
template <VideoFormat FMT>
138
void QWidgetVideoSink<FMT>::base_init(gpointer g_class)
140
gst_element_class_add_pad_template(GST_ELEMENT_CLASS(g_class),
141
gst_static_pad_template_get(template_factory<FMT>::getFactory()));
144
template <VideoFormat FMT>
145
void QWidgetVideoSink<FMT>::instance_init(GTypeInstance *instance, gpointer g_class)
149
QWidgetVideoSink<FMT>* self = reinterpret_cast<QWidgetVideoSink<FMT>*>(instance);
151
self->renderWidget = 0;
158
// QWidgetVideoSinkClass
159
template <VideoFormat FMT>
160
void QWidgetVideoSinkClass<FMT>::class_init(gpointer g_class, gpointer class_data)
162
Q_UNUSED(class_data);
163
GstBaseSinkClass* gstBaseSinkClass = (GstBaseSinkClass*)g_class;
164
GstElementClass* gstElementClass = (GstElementClass*)g_class;
166
parentClass = reinterpret_cast<GstVideoSinkClass*>(g_type_class_peek_parent(g_class));
169
gstBaseSinkClass->set_caps = QWidgetVideoSink<FMT>::set_caps;
170
gstBaseSinkClass->preroll = QWidgetVideoSink<FMT>::render;
171
gstBaseSinkClass->render = QWidgetVideoSink<FMT>::render;
174
gstElementClass->change_state = QWidgetVideoSink<FMT>::change_state;
177
template <VideoFormat FMT>
178
GType QWidgetVideoSinkClass<FMT>::get_type()
180
static GType type = 0;
184
static const GTypeInfo info =
186
sizeof(QWidgetVideoSinkClass<FMT>), // class_size
187
QWidgetVideoSink<FMT>::base_init, // base init
188
NULL, // base_finalize
190
QWidgetVideoSinkClass<FMT>::class_init, // class_init
191
NULL, // class_finalize
194
sizeof(QWidgetVideoSink<FMT>), // instance_size
196
QWidgetVideoSink<FMT>::instance_init, // instance_init
200
type = g_type_register_static(GST_TYPE_VIDEO_SINK,
201
QWidgetVideoSinkClass<FMT>::get_name(),
210
return QWidgetVideoSinkClass<VideoFormat_YUV>::get_type();
215
return QWidgetVideoSinkClass<VideoFormat_RGB>::get_type();
219
} //namespace Phonon::Gstreamer