improve session states, add dialing sound, improve error reporting
[makneto-zunavac1.git] / src / backend / voip / callchannelhandler_p.h
blobb44d16d4d287e270cfcb4a8e70f2a07a45016ec7
1 /*
2 Copyright (C) 2010 Collabora Ltd. <info@collabora.co.uk>
3 @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
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
7 by the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef CALLCHANNELHANDLER_P_H
19 #define CALLCHANNELHANDLER_P_H
21 #include <QMutex>
23 #include <QGst/GhostPad>
24 #include <QGst/Pipeline>
25 #include <QGst/StreamVolume>
26 #include <QGst/ColorBalance>
27 #include <QGst/Ui/VideoWidget>
29 #include <TelepathyQt4/Contact>
30 #include <TelepathyQt4/StreamedMediaChannel>
32 #include "callchannelhandler.h"
34 class ParticipantData;
37 //BEGIN Ugly forward declarations
39 /* These declarations are copied here instead of including the proper headers,
40 * because the proper headers also include too many unrelated stuff and we have
41 * to depend on many useless (at build time) external libraries (such as dbus-glib,
42 * libxml2, gstreamer) for no good reason.
45 typedef unsigned long GType;
46 typedef int gboolean;
47 typedef char gchar;
48 typedef struct _GList GList;
49 typedef struct _TfChannel TfChannel;
51 extern "C" {
52 GType fs_codec_list_get_type(void);
53 GList *fs_codec_list_from_keyfile(const gchar *filename, GError **error);
54 gboolean tf_channel_bus_message(TfChannel *channel, GstMessage *message);
57 namespace Tp {
58 Q_DECL_IMPORT TfChannel *createFarsightChannel(const StreamedMediaChannelPtr &channel);
60 //END Ugly forward declarations
63 namespace MaknetoBackend {
65 class CallChannelHandlerPrivate : public QObject {
67 Q_OBJECT
68 public:
69 enum Who {
70 Myself = 0, RemoteContact = 1
72 enum GstQueueLeaky {
73 GST_QUEUE_NO_LEAK = 0,
74 GST_QUEUE_LEAK_UPSTREAM = 1,
75 GST_QUEUE_LEAK_DOWNSTREAM = 2
78 inline CallChannelHandlerPrivate(CallChannelHandler *qq) : QObject(), q(qq) {
80 void init(const Tp::StreamedMediaChannelPtr & channel);
81 void accept();
82 ~CallChannelHandlerPrivate();
84 inline Tp::StreamedMediaChannelPtr channel() const {
85 return m_channel;
88 inline QList<CallParticipant*> participants() const {
89 return m_participants.values();
91 Tp::ContactPtr contactOfParticipant(Who who) const;
93 private
94 Q_SLOTS:
95 void onChannelInvalidated(Tp::DBusProxy *proxy,
96 const QString & errorName,
97 const QString & errorMessage);
99 private:
100 void onBusMessage(const QGst::MessagePtr & message);
101 bool tryStopElements(bool audio, QGst::BinPtr &bin, QGst::ElementPtr & element, Who who);
102 bool tryStopElement(const QGst::ElementPtr &element, QGst::BinPtr bin = QGst::BinPtr());
104 // -- from TfChannel signals
105 void onTfChannelClosed();
106 void onSessionCreated(QGst::ElementPtr & conference);
107 void onStreamCreated(const QGlib::ObjectPtr & stream);
108 GList *onStreamGetCodecConfig();
110 // -- from TfStream signals
111 void onSrcPadAdded(const QGlib::ObjectPtr & stream, QGst::PadPtr & src);
112 bool onRequestResource(const QGlib::ObjectPtr & stream, uint direction);
113 void onFreeResource(const QGlib::ObjectPtr & stream, uint direction);
114 void onStreamClosed(const QGlib::ObjectPtr & stream);
116 bool createAudioBin(QExplicitlySharedDataPointer<ParticipantData> & data);
117 bool createVideoBin(QExplicitlySharedDataPointer<ParticipantData> & data, bool isVideoSrc);
119 // *** data ***
121 CallChannelHandler *q;
122 Tp::StreamedMediaChannelPtr m_channel;
124 QMap<Who, CallParticipant*> m_participants;
125 QExplicitlySharedDataPointer<ParticipantData> m_participantData[2];
127 QGst::PipelinePtr m_pipeline;
128 QGst::ElementPtr m_audioInputDevice;
129 QGst::ElementPtr m_videoInputDevice;
130 QGst::ElementPtr m_audioOutputDevice;
132 QGlib::ObjectPtr m_tfChannel;
133 QGst::ElementPtr m_conference;
136 class ParticipantData : public QSharedData {
137 public:
139 inline ParticipantData() //just for being able to construct the array above without initialization
140 : handlerPriv(NULL), who(CallChannelHandlerPrivate::Myself) {
143 inline ParticipantData(CallChannelHandlerPrivate *h, CallChannelHandlerPrivate::Who w)
144 : handlerPriv(h), who(w) {
147 QGst::BinPtr audioBin;
148 QGst::BinPtr videoBin;
149 QGst::StreamVolumePtr volumeControl;
150 QGst::ColorBalancePtr colorBalanceControl;
151 QGst::ElementPtr videoOutElemPtr;
152 //QWeakPointer<QGst::Ui::VideoWidget> videoWidget;
153 CallChannelHandlerPrivate *handlerPriv;
154 CallChannelHandlerPrivate::Who who;
156 QGst::PadPtr preparedPad;
157 QMutex mutex;
162 #endif