File: call__example__farsight__channel__cpp.html

package info (click to toggle)
telepathy-qt4 0.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 14,260 kB
  • ctags: 12,185
  • sloc: cpp: 29,241; xml: 23,692; ansic: 16,079; sh: 10,327; python: 3,080; makefile: 1,553
file content (350 lines) | stat: -rw-r--r-- 16,080 bytes parent folder | download
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>TelepathyQt4: call/farsight-channel.cpp</title>
  <link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="1">&nbsp;&nbsp;</td>
<td class="postheader" valign="center">
<a href="index.html">
<font color="#004faf">Home</font></a>&nbsp;&middot;
<a href="classes.html">
<font color="#004faf">All Classes</font></a>&nbsp;&middot;
<a href="namespaces.html">
<font color="#004faf">All Namespaces</font></a>&nbsp;&middot;
<a href="modules.html">
<font color="#004faf">Modules</font></a>&nbsp;&middot;
<a href="functions.html">
<font color="#004faf">Functions</font></a>&nbsp;&middot;
<a href="files.html">
<font color="#004faf">Files</font></a>
</td>
</tr>
</table>
</body>
</html>
<!-- Generated by Doxygen 1.6.3 -->
<div class="contents">


<h1><a class="anchor" id="call_example_farsight_channel_cpp">call/farsight-channel.cpp </a></h1><div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * Very basic Tp-Qt &lt;-&gt; Tp-Farsight integration.</span>
<span class="comment"> *</span>
<span class="comment"> * Copyright © 2008-2009 Collabora Ltd. &lt;http://www.collabora.co.uk/&gt;</span>
<span class="comment"> * Copyright © 2009 Nokia Corporation</span>
<span class="comment"> *</span>
<span class="comment"> * This library is free software; you can redistribute it and/or</span>
<span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<span class="comment"> * License as published by the Free Software Foundation; either</span>
<span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<span class="comment"> *</span>
<span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<span class="comment"> * Lesser General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<span class="comment"> * License along with this library; if not, write to the Free Software</span>
<span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;farsight-channel.h&quot;</span>
<span class="preprocessor">#include &quot;_gen/farsight-channel.moc.hpp&quot;</span>

<span class="preprocessor">#include &quot;video-widget.h&quot;</span>

<span class="preprocessor">#include &lt;QDebug&gt;</span>

<span class="preprocessor">#include &lt;TelepathyQt4/Connection&gt;</span>
<span class="preprocessor">#include &lt;TelepathyQt4/Farsight/Channel&gt;</span>
<span class="preprocessor">#include &lt;TelepathyQt4/StreamedMediaChannel&gt;</span>

<span class="keyword">namespace </span>Tp {

<span class="keyword">struct </span>FarsightChannel::Private
{
    Private(FarsightChannel *parent, <span class="keyword">const</span> StreamedMediaChannelPtr &amp;channel);
    ~Private();

    <span class="keyword">static</span> gboolean busWatch(GstBus *bus,
            GstMessage *message, FarsightChannel::Private *<span class="keyword">self</span>);
    <span class="keyword">static</span> <span class="keywordtype">void</span> onClosed(TfChannel *tfChannel,
            FarsightChannel::Private *<span class="keyword">self</span>);
    <span class="keyword">static</span> <span class="keywordtype">void</span> onSessionCreated(TfChannel *tfChannel,
            FsConference *conference, FsParticipant *participant,
            FarsightChannel::Private *<span class="keyword">self</span>);
    <span class="keyword">static</span> <span class="keywordtype">void</span> onStreamCreated(TfChannel *tfChannel,
            TfStream *stream, FarsightChannel::Private *<span class="keyword">self</span>);
    <span class="keyword">static</span> <span class="keywordtype">void</span> onSrcPadAdded(TfStream *stream,
            GstPad *pad, FsCodec *codec, FarsightChannel::Private *<span class="keyword">self</span>);
    <span class="keyword">static</span> gboolean onRequestResource(TfStream *stream,
            guint direction, gpointer data);

    FarsightChannel *parent;
    <a class="code" href="namespaceTp.html#a7e5f9726638316266c32f3320afb1a66">StreamedMediaChannelPtr</a> channel;
    Status status;
    TfChannel *tfChannel;
    GstBus *bus;
    GstElement *pipeline;
    GstElement *audioInput;
    GstElement *audioOutput;
    GstElement *videoInput;
    GstElement *videoTee;
    VideoWidget *videoPreview;
    VideoWidget *videoOutput;
};

FarsightChannel::Private::Private(FarsightChannel *parent,
        <span class="keyword">const</span> StreamedMediaChannelPtr &amp;channel)
    : parent(parent),
      channel(channel),
      status(StatusDisconnected),
      tfChannel(0),
      bus(0),
      pipeline(0),
      audioInput(0),
      audioOutput(0),
      videoInput(0),
      videoTee(0),
      videoPreview(0),
      videoOutput(0)
{
    tfChannel = <a class="code" href="namespaceTp.html#a2c0be27185cde4e88379040b92460166">createFarsightChannel</a>(channel);
    <span class="keywordflow">if</span> (!tfChannel) {
        qWarning() &lt;&lt; <span class="stringliteral">&quot;Unable to construct TfChannel&quot;</span>;
        <span class="keywordflow">return</span>;
    }

    <span class="comment">/* Set up the telepathy farsight channel */</span>
    g_signal_connect(tfChannel, <span class="stringliteral">&quot;closed&quot;</span>,
        G_CALLBACK(&amp;FarsightChannel::Private::onClosed), <span class="keyword">this</span>);
    g_signal_connect(tfChannel, <span class="stringliteral">&quot;session-created&quot;</span>,
        G_CALLBACK(&amp;FarsightChannel::Private::onSessionCreated), <span class="keyword">this</span>);
    g_signal_connect(tfChannel, <span class="stringliteral">&quot;stream-created&quot;</span>,
        G_CALLBACK(&amp;FarsightChannel::Private::onStreamCreated), <span class="keyword">this</span>);

    pipeline = gst_pipeline_new(NULL);
    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));

    audioInput = gst_element_factory_make(<span class="stringliteral">&quot;autoaudiosrc&quot;</span>, NULL);
    gst_object_ref(audioInput);
    gst_object_sink(audioInput);

    audioOutput = gst_bin_new(<span class="stringliteral">&quot;audio-output-bin&quot;</span>);
    GstElement *resample = gst_element_factory_make(<span class="stringliteral">&quot;audioresample&quot;</span>, NULL);
    GstElement *audioSink = gst_element_factory_make(<span class="stringliteral">&quot;autoaudiosink&quot;</span>, NULL);
    gst_bin_add_many(GST_BIN(audioOutput), resample, audioSink, NULL);
    gst_element_link_many(resample, audioSink, NULL);
    GstPad *sink = gst_element_get_static_pad(resample, <span class="stringliteral">&quot;sink&quot;</span>);
    GstPad *ghost = gst_ghost_pad_new(<span class="stringliteral">&quot;sink&quot;</span>, sink);
    gst_element_add_pad(GST_ELEMENT(audioOutput), ghost);
    gst_object_unref(G_OBJECT(sink));
    gst_object_ref(audioOutput);
    gst_object_sink(audioOutput);

    videoInput = gst_bin_new(<span class="stringliteral">&quot;video-input-bin&quot;</span>);
    GstElement *scale = gst_element_factory_make(<span class="stringliteral">&quot;videoscale&quot;</span>, NULL);
    GstElement *rate = gst_element_factory_make(<span class="stringliteral">&quot;videorate&quot;</span>, NULL);
    GstElement *colorspace = gst_element_factory_make(<span class="stringliteral">&quot;ffmpegcolorspace&quot;</span>, NULL);
    GstElement *capsfilter = gst_element_factory_make(<span class="stringliteral">&quot;capsfilter&quot;</span>, NULL);
    GstCaps *caps = gst_caps_new_simple(<span class="stringliteral">&quot;video/x-raw-yuv&quot;</span>,
            <span class="stringliteral">&quot;width&quot;</span>, G_TYPE_INT, 320,
            <span class="stringliteral">&quot;height&quot;</span>, G_TYPE_INT, 240,
            NULL);
    g_object_set(G_OBJECT(capsfilter), <span class="stringliteral">&quot;caps&quot;</span>, caps, NULL);
    GstElement *videoSrc = gst_element_factory_make(<span class="stringliteral">&quot;autovideosrc&quot;</span>, NULL);
    <span class="comment">// GstElement *videoSrc = gst_element_factory_make(&quot;videotestsrc&quot;, NULL);</span>
    gst_bin_add_many(GST_BIN(videoInput), videoSrc, scale, rate,
            colorspace, capsfilter, NULL);
    gst_element_link_many(videoSrc, scale, rate, colorspace, capsfilter, NULL);
    GstPad *src = gst_element_get_static_pad(capsfilter, <span class="stringliteral">&quot;src&quot;</span>);
    ghost = gst_ghost_pad_new(<span class="stringliteral">&quot;src&quot;</span>, src);
    Q_ASSERT(gst_element_add_pad(GST_ELEMENT(videoInput), ghost));
    gst_object_unref(G_OBJECT(src));
    gst_object_ref(audioInput);
    gst_object_sink(audioInput);

    videoTee = gst_element_factory_make(<span class="stringliteral">&quot;tee&quot;</span>, NULL);
    gst_object_ref(videoTee);
    gst_object_sink(videoTee);

    videoPreview = <span class="keyword">new</span> VideoWidget(bus);
    GstElement *videoPreviewElement = videoPreview-&gt;element();

    gst_bin_add_many(GST_BIN(pipeline), videoInput, videoTee,
            videoPreviewElement, NULL);
    gst_element_link_many(videoInput, videoTee,
            videoPreviewElement, NULL);

    videoOutput = <span class="keyword">new</span> VideoWidget(bus);

    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    status = StatusConnecting;
    emit parent-&gt;statusChanged(status);
}

FarsightChannel::Private::~Private()
{
    <span class="keywordflow">if</span> (tfChannel) {
        g_object_unref(tfChannel);
        tfChannel = 0;
    }

    <span class="keywordflow">if</span> (bus) {
        g_object_unref(bus);
        bus = 0;
    }

    gst_element_set_state(pipeline, GST_STATE_NULL);

    <span class="keywordflow">if</span> (pipeline) {
        g_object_unref(pipeline);
        pipeline = 0;
    }

    <span class="keywordflow">if</span> (audioInput) {
        g_object_unref(audioInput);
        audioInput = 0;
    }

    <span class="keywordflow">if</span> (audioOutput) {
        g_object_unref(audioOutput);
        audioOutput = 0;
    }
}

gboolean FarsightChannel::Private::busWatch(GstBus *bus,
        GstMessage *message, FarsightChannel::Private *<span class="keyword">self</span>)
{
    tf_channel_bus_message(self-&gt;tfChannel, message);
    <span class="keywordflow">return</span> TRUE;
}

<span class="keywordtype">void</span> FarsightChannel::Private::onClosed(TfChannel *tfChannel,
        FarsightChannel::Private *<span class="keyword">self</span>)
{
    <span class="keyword">self</span>-&gt;status = StatusDisconnected;
    emit <span class="keyword">self</span>-&gt;parent-&gt;statusChanged(self-&gt;status);
}

<span class="keywordtype">void</span> FarsightChannel::Private::onSessionCreated(TfChannel *tfChannel,
        FsConference *conference, FsParticipant *participant,
        FarsightChannel::Private *<span class="keyword">self</span>)
{
    gst_bus_add_watch(self-&gt;bus,
            (GstBusFunc) &amp;FarsightChannel::Private::busWatch, <span class="keyword">self</span>);

    gst_bin_add(GST_BIN(self-&gt;pipeline), GST_ELEMENT(conference));
    gst_element_set_state(GST_ELEMENT(conference), GST_STATE_PLAYING);
}

<span class="keywordtype">void</span> FarsightChannel::Private::onStreamCreated(TfChannel *tfChannel,
        TfStream *stream, FarsightChannel::Private *<span class="keyword">self</span>)
{
    guint media_type;
    GstPad *sink;

    g_signal_connect(stream, <span class="stringliteral">&quot;src-pad-added&quot;</span>,
        G_CALLBACK(&amp;FarsightChannel::Private::onSrcPadAdded), <span class="keyword">self</span>);
    g_signal_connect(stream, <span class="stringliteral">&quot;request-resource&quot;</span>,
        G_CALLBACK(&amp;FarsightChannel::Private::onRequestResource), NULL);

    g_object_get(stream, <span class="stringliteral">&quot;media-type&quot;</span>, &amp;media_type,
            <span class="stringliteral">&quot;sink-pad&quot;</span>, &amp;sink, NULL);

    GstPad *pad;
    <span class="keywordflow">switch</span> (media_type) {
    <span class="keywordflow">case</span> TP_MEDIA_STREAM_TYPE_AUDIO:
        gst_bin_add(GST_BIN(self-&gt;pipeline), self-&gt;audioInput);
        gst_element_set_state(self-&gt;audioInput, GST_STATE_PLAYING);

        pad = gst_element_get_static_pad(self-&gt;audioInput, <span class="stringliteral">&quot;src&quot;</span>);
        gst_pad_link(pad, sink);
        <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> TP_MEDIA_STREAM_TYPE_VIDEO:
        pad = gst_element_get_request_pad(self-&gt;videoTee, <span class="stringliteral">&quot;src%d&quot;</span>);
        gst_pad_link(pad, sink);
        <span class="keywordflow">break</span>;
    <span class="keywordflow">default</span>:
        Q_ASSERT(<span class="keyword">false</span>);
    }

    gst_object_unref(sink);
}

<span class="keywordtype">void</span> FarsightChannel::Private::onSrcPadAdded(TfStream *stream,
        GstPad *src, FsCodec *codec, FarsightChannel::Private *<span class="keyword">self</span>)
{
    guint media_type;

    g_object_get(stream, <span class="stringliteral">&quot;media-type&quot;</span>, &amp;media_type, NULL);

    GstPad *pad;
    GstElement *element = 0;

    <span class="keywordflow">switch</span> (media_type) {
    <span class="keywordflow">case</span> TP_MEDIA_STREAM_TYPE_AUDIO:
        element = <span class="keyword">self</span>-&gt;audioOutput;
        g_object_ref(element);
        <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> TP_MEDIA_STREAM_TYPE_VIDEO:
        element = <span class="keyword">self</span>-&gt;videoOutput-&gt;element();
        <span class="keywordflow">break</span>;
    <span class="keywordflow">default</span>:
        Q_ASSERT(<span class="keyword">false</span>);
    }

    gst_bin_add(GST_BIN(self-&gt;pipeline), element);

    pad = gst_element_get_static_pad(element, <span class="stringliteral">&quot;sink&quot;</span>);
    gst_element_set_state(element, GST_STATE_PLAYING);

    gst_pad_link(src, pad);

    <span class="keyword">self</span>-&gt;status = StatusConnected;
    emit <span class="keyword">self</span>-&gt;parent-&gt;statusChanged(self-&gt;status);
}

gboolean FarsightChannel::Private::onRequestResource(TfStream *stream,
        guint direction, gpointer data)
{
    <span class="keywordflow">return</span> TRUE;
}

FarsightChannel::FarsightChannel(<span class="keyword">const</span> <a class="code" href="namespaceTp.html#a7e5f9726638316266c32f3320afb1a66">StreamedMediaChannelPtr</a> &amp;channel,
        QObject *parent)
    : QObject(parent),
      mPriv(new Private(this, channel))
{
}

FarsightChannel::~FarsightChannel()
{
    <span class="keyword">delete</span> mPriv;
}

VideoWidget *FarsightChannel::videoPreview()<span class="keyword"> const</span>
<span class="keyword"></span>{
    <span class="keywordflow">return</span> mPriv-&gt;videoPreview;
}

VideoWidget *FarsightChannel::videoWidget()<span class="keyword"> const</span>
<span class="keyword"></span>{
    <span class="keywordflow">return</span> mPriv-&gt;videoOutput;
}

} <span class="comment">// Tp</span>
</pre></div> </div>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008-2010 Collabora Ltd. and Nokia Corporation</td>
<td width="30%" align="right"><div align="right">Telepathy-Qt4 0.3.6</div></td>
</tr></table></div></address>
</body>
</html>