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 <gst/interfaces/propertyprobe.h>
21
#include "gsthelper.h"
23
#include <QtCore/QList>
33
* Probes a gstElement for a list of settable string-property values
35
* @return a QStringList containing a list of allwed string values for the given
38
QList<QByteArray> GstHelper::extractProperties(GstElement *elem, const QByteArray &value)
41
QList<QByteArray> list;
43
if (GST_IS_PROPERTY_PROBE(elem)) {
44
GstPropertyProbe *probe = GST_PROPERTY_PROBE(elem);
45
const GParamSpec *devspec = 0;
46
GValueArray *array = NULL;
48
if ((devspec = gst_property_probe_get_property (probe, value))) {
49
if ((array = gst_property_probe_probe_and_get_values (probe, devspec))) {
50
for (unsigned int device = 0; device < array->n_values; device++) {
51
GValue *deviceId = g_value_array_get_nth (array, device);
52
list.append(g_value_get_string(deviceId));
56
g_value_array_free (array);
63
* Sets the string value of a GstElement's property
65
* @return false if the value could not be set.
67
bool GstHelper::setProperty(GstElement *elem, const char *propertyName, const QByteArray &propertyValue)
70
Q_ASSERT(propertyName && strlen(propertyName));
72
if (GST_IS_PROPERTY_PROBE(elem) && gst_property_probe_get_property( GST_PROPERTY_PROBE( elem), propertyName ) ) {
73
g_object_set(G_OBJECT(elem), propertyName, propertyValue.constData(), (const char*)NULL);
80
* Queries an element for the value of an object property
82
QByteArray GstHelper::property(GstElement *elem, const char *propertyName)
85
Q_ASSERT(propertyName && strlen(propertyName));
88
if (GST_IS_PROPERTY_PROBE(elem) && gst_property_probe_get_property( GST_PROPERTY_PROBE(elem), propertyName)) {
90
g_object_get (G_OBJECT(elem), propertyName, &value, (const char*)NULL);
91
retVal = QByteArray(value);
98
* Queries a GstObject for it's name
100
QByteArray GstHelper::name(GstObject *obj)
105
if ((value = gst_object_get_name (obj))) {
106
retVal = QByteArray(value);
114
* Creates an instance of a playbin with "audio-src" and
115
* "video-src" ghost pads to allow redirected output streams.
117
* ### This function is probably not required now that MediaObject is based
118
* on decodebin directly.
120
GstElement* GstHelper::createPluggablePlaybin()
122
GstElement *playbin = 0;
123
//init playbin and add to our pipeline
124
playbin = gst_element_factory_make("playbin2", NULL);
126
//Create an identity element to redirect sound
127
GstElement *audioSinkBin = gst_bin_new (NULL);
128
GstElement *audioPipe = gst_element_factory_make("identity", NULL);
129
gst_bin_add(GST_BIN(audioSinkBin), audioPipe);
131
//Create a sinkpad on the identity
132
GstPad *audiopad = gst_element_get_pad (audioPipe, "sink");
133
gst_element_add_pad (audioSinkBin, gst_ghost_pad_new ("sink", audiopad));
134
gst_object_unref (audiopad);
136
//Create an "audio_src" source pad on the playbin
137
GstPad *audioPlaypad = gst_element_get_pad (audioPipe, "src");
138
gst_element_add_pad (playbin, gst_ghost_pad_new ("audio_src", audioPlaypad));
139
gst_object_unref (audioPlaypad);
141
//Done with our audio redirection
142
g_object_set (G_OBJECT(playbin), "audio-sink", audioSinkBin, (const char*)NULL);
144
// * * Redirect video to "video_src" pad : * *
146
//Create an identity element to redirect sound
147
GstElement *videoSinkBin = gst_bin_new (NULL);
148
GstElement *videoPipe = gst_element_factory_make("identity", NULL);
149
gst_bin_add(GST_BIN(videoSinkBin), videoPipe);
151
//Create a sinkpad on the identity
152
GstPad *videopad = gst_element_get_pad (videoPipe, "sink");
153
gst_element_add_pad (videoSinkBin, gst_ghost_pad_new ("sink", videopad));
154
gst_object_unref (videopad);
156
//Create an "audio_src" source pad on the playbin
157
GstPad *videoPlaypad = gst_element_get_pad (videoPipe, "src");
158
gst_element_add_pad (playbin, gst_ghost_pad_new ("video_src", videoPlaypad));
159
gst_object_unref (videoPlaypad);
161
//Done with our video redirection
162
g_object_set (G_OBJECT(playbin), "video-sink", videoSinkBin, (const char*)NULL);
167
} //namespace Gstreamer