1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSOUNDQSS_QWS_H
43 #define QSOUNDQSS_QWS_H
44 
45 #include <QtCore/qglobal.h>
46 
47 #ifndef QT_NO_SOUND
48 
49 #include <QtNetwork/qtcpserver.h>
50 #include <QtNetwork/qtcpsocket.h>
51 #include <QtGui/qwssocket_qws.h>
52 
53 QT_BEGIN_HEADER
54 
55 QT_BEGIN_NAMESPACE
56 
QT_MODULE(Gui)57 QT_MODULE(Gui)
58 
59 #if defined(QT_NO_NETWORK) || defined(QT_NO_DNS)
60 #define QT_NO_QWS_SOUNDSERVER
61 #endif
62 
63 #ifndef Q_OS_MAC
64 
65 class QWSSoundServerPrivate;
66 
67 class Q_GUI_EXPORT QWSSoundServer : public QObject {
68     Q_OBJECT
69 public:
70     explicit QWSSoundServer(QObject *parent=0);
71     ~QWSSoundServer();
72     void playFile( int id, const QString& filename );
73     void stopFile( int id );
74     void pauseFile( int id );
75     void resumeFile( int id );
76 
77 Q_SIGNALS:
78     void soundCompleted( int );
79 
80 private Q_SLOTS:
81     void translateSoundCompleted( int, int );
82 
83 private:
84     QWSSoundServerPrivate* d;
85 };
86 
87 #ifndef QT_NO_QWS_SOUNDSERVER
88 class Q_GUI_EXPORT QWSSoundClient : public QWSSocket {
89     Q_OBJECT
90 public:
91 
92     enum SoundFlags {
93 	Priority = 0x01,
94 	Streaming = 0x02  // currently ignored, but but could set up so both Raw and non raw can be done streaming or not.
95     };
96     enum DeviceErrors {
97 	ErrOpeningAudioDevice = 0x01,
98 	ErrOpeningFile = 0x02,
99 	ErrReadingFile = 0x04
100     };
101     explicit QWSSoundClient(QObject* parent=0);
102     ~QWSSoundClient( );
103     void reconnect();
104     void play( int id, const QString& filename );
105     void play( int id, const QString& filename, int volume, int flags = 0 );
106     void playRaw( int id, const QString&, int, int, int, int flags = 0 );
107 
108     void pause( int id );
109     void stop( int id );
110     void resume( int id );
111     void setVolume( int id, int left, int right );
112     void setMute( int id, bool m );
113 
114     // to be used by server only, to protect phone conversation/rings.
115     void playPriorityOnly(bool);
116 
117     // If silent, tell sound server to release audio device
118     // Otherwise, allow sound server to regain audio device
119     void setSilent(bool);
120 
121 Q_SIGNALS:
122     void soundCompleted(int);
123     void deviceReady(int id);
124     void deviceError(int id, QWSSoundClient::DeviceErrors);
125 
126 private Q_SLOTS:
127     void tryReadCommand();
128     void emitConnectionRefused();
129 
130 private:
131     void sendServerMessage(QString msg);
132 };
133 
134 class QWSSoundServerSocket : public QWSServerSocket {
135     Q_OBJECT
136 
137 public:
138     explicit QWSSoundServerSocket(QObject *parent=0);
139 public Q_SLOTS:
140     void newConnection();
141 
142 #ifdef QT3_SUPPORT
143 public:
144     QT3_SUPPORT_CONSTRUCTOR QWSSoundServerSocket(QObject *parent, const char *name);
145 #endif
146 
147 Q_SIGNALS:
148     void playFile(int, int, const QString&);
149     void playFile(int, int, const QString&, int, int);
150     void playRawFile(int, int, const QString&, int, int, int, int);
151     void pauseFile(int, int);
152     void stopFile(int, int);
153     void resumeFile(int, int);
154     void setVolume(int, int, int, int);
155     void setMute(int, int, bool);
156 
157     void stopAll(int);
158 
159     void playPriorityOnly(bool);
160 
161     void setSilent(bool);
162 
163     void soundFileCompleted(int, int);
164     void deviceReady(int, int);
165     void deviceError(int, int, int);
166 };
167 #endif
168 
169 #endif // Q_OS_MAC
170 
171 QT_END_NAMESPACE
172 
173 QT_END_HEADER
174 
175 #endif // QT_NO_SOUND
176 
177 #endif // QSOUNDQSS_QWS_H
178