KVIrc 5.2.4
Developer APIs
DccVoiceWindow.h
Go to the documentation of this file.
1#ifndef _VOICE_H_
2#define _VOICE_H_
3//=============================================================================
4//
5// File : DccVoiceWindow.h
6// Creation date : Thu Aug 23 04:08:10 2001 GMT by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
27#include "DccVoiceCodec.h"
28#include "DccDescriptor.h"
29#include "DccThread.h"
30#include "DccWindow.h"
31
32#include "KviWindow.h"
33#include "KviDataBuffer.h"
34#include "kvi_sockettype.h"
35#include "KviTalHBox.h"
36#include "KviError.h"
37
38#include <QLabel>
39#include <QToolButton>
40#include <QTimer>
41
42class QSlider;
43class DccMarshal;
44
45#ifndef _DCC_VOICE_CPP_
46extern bool kvi_dcc_voice_is_valid_codec(const char * codecName);
47#endif
48
49#define KVI_DCC_VOICE_THREAD_ACTION_START_RECORDING 0
50#define KVI_DCC_VOICE_THREAD_ACTION_STOP_RECORDING 1
51#define KVI_DCC_VOICE_THREAD_ACTION_START_PLAYING 2
52#define KVI_DCC_VOICE_THREAD_ACTION_STOP_PLAYING 3
53
62
64{
65 friend class DccVoiceWindow;
66
67public:
70
71protected:
72 // bool m_bUseGsm;
86 // unsigned int m_uSleepTime;
88 // stuff protected by the mutex:
91
92protected:
93 bool checkSoundcard();
94 bool openSoundcardWithDuplexOption(int openMode, int failMode);
95 bool openSoundcard(int mode);
98 void closeSoundcard();
99 bool readWriteStep();
100 bool soundStep();
101 void startRecording();
102 void stopRecording();
103 void startPlaying();
104 void stopPlaying();
105 virtual void run();
106};
107
109{
110 Q_OBJECT
111public:
112 DccVoiceWindow(DccDescriptor * dcc, const char * name);
114
115protected:
122 QToolButton * m_pTalkButton;
124 QString m_szTarget;
126
127protected:
128 void focusInEvent(QFocusEvent *) override;
129 const QString & target() override;
130 void fillCaptionBuffers() override;
131 QPixmap * myIconPtr() override;
132 void resizeEvent(QResizeEvent * e) override;
133 QSize sizeHint() const override;
134 bool event(QEvent * e) override;
135 void getBaseLogFileName(QString & buffer) override;
136 void startTalking();
137 void stopTalking();
138 void startConnection();
139 int getMixerVolume(void) const;
140protected slots:
142 void connected();
143 void updateInfo();
144 void startOrStopTalking(bool bStart);
145 void setMixerVolume(int);
147 // void stopTalking();
148};
149
150#if 0
151
152/*
153
154//
155// CODEC DEFINITION
156//
157
158 Sample rate = samples/sec (ex. 8000)
159 Sample size = bits (ex. 16 bits)
160 Sample endianness = le/be
161
162 Sample compressor = name
163
164 <rate>:<bits>:<endianness>:<compressor>
165
166 8000:16:le:null
167 8000:16:le:gsm
168 8000:16:le:adpcm
169
170class KviVoiceParty
171{
172public:
173 KviVoiceParty(const QString &szNick,const QString &szIp,unsigned short uPort);
174 ~KviVoiceParty();
175protected:
176 QString m_szIp;
177 unsigned short m_uPort;
178 QString m_szNick;
179 KviPointerList<KviVoiceParty> * m_pChildrenTree;
180public:
181 const QString & ip(){ return m_szIp; };
182 unsigned short port(){ return m_uPort; };
183 const QString & nick(){ return m_szNick; };
184 void addChild(KviVoiceParty * pChild);
185};
186
187
188KviVoiceParty::KviVoiceParty(const QString &szNick,const QString &szIp,unsigned short uPort)
189: m_szIp(szIp), m_uPort(uPort), m_szNick(szNick)
190{
191 m_pChildrenTree = nullptr;
192}
193
194KviVoiceParty::~KviVoiceParty()
195{
196 if(m_pChildrenTree)delete m_pChildrenTree;
197}
198
199void KviVoiceParty::addChild(KviVoiceParty * pChild)
200{
201 if(!m_pChildrenTree)
202 {
203 m_pChildrenTree = new KviPointerList<KviVoiceParty>;
204 m_pChildrenTree->setAutoDelete(true);
205 }
206 m_pChildrenTree->append(pChild);
207}
208
209class KviVoiceAudioEncoder
210{
211public:
212 KviVoiceAudioEncoder();
213 ~KviVoiceAudioEncoder();
214public:
215
216};
217
218class KviVoiceAudioDecoder
219{
220public:
221 KviVoiceAudioDecoder();
222 ~KviVoiceAudioDecoder();
223};
224
225class KviVoiceLink
226{
227public:
228 KviVoiceLink(KviVoiceParty * pRemoteParty);
229 ~KviVoiceLink();
230protected:
231 QString m_szId;
232 KviVoiceParty * m_pRemoteParty;
233 KviVoiceAudioEncoder * m_pAudioEncoder;
234 KviVoiceAudioDecoder * m_pAudioDecoder;
235public:
236 const QStirng & id(){ return m_szId; };
237 KviVoiceParty * remoteParty(){ return m_pRemoteParty; };
238};
239
240KviVoiceLink::KviVoiceLink(KviVoiceParty * pRemoteParty)
241{
242 KviQString::sprintf("%Q:%u",&(pRemoteParty->nick()),pRemoteParty->port());
243 m_pRemoteParty = pRemoteParty;
244 m_pAudioEncoder = nullptr;
245 m_pAudioDecoder = nullptr;
246}
247
248KviVoiceLink::~KviVoiceLink()
249{
250 delete m_pRemoteParty;
251 if(m_pAudioEncoder)delete m_pAudioEncoder;
252 if(m_pAudioDecoder)delete m_pAudioDecoder;
253}
254
255class KviVoice_r8000s16eL_to_r8000s16eB_Transformer
256{
257
258}
259
260class KviVoice_r8000s16eB_to_r8000s16eL_Transformer
261{
262
263}
264
265class KviVoice_r11025s16eL_to_r11025s16eB_Transformer
266{
267
268}
269
270class KviVoice_r11025s16eB_to_r11025s16eL_Transformer
271{
272
273}
274
275class KviVoice_r11025s16eL_to_r8000s16eL_Transformer
276{
277
278}
279
280class KviVoice_r11025s16eL_to_r8000s16eB_Transformer
281{
282
283}
284
285class KviVoice_r11025s16eB_to_r8000s16eL_Transformer
286{
287
288}
289
290class KviVoice_r8000s16eL_to_r11025s16eL_Transformer
291{
292
293}
294
295class KviVoice_r8000s16eL_to_r11025s16eB_Transformer
296{
297
298}
299
300class KviVoice_r8000s16eB_to_r11025s16eL_Transformer
301{
302
303}
304
305
306
307class KviVoiceConference
308{
309public:
310 KviVoiceConference();
311 ~KviVoiceConference();
312public:
313 KviPointerList<KviVoiceLink> * m_pLinks;
314 KviPointerHashTable<QString,KviVoiceLink> *
315 SOCKET m_hUdpSocket;
316 QString m_szLastError;
317
318 unsigned int m_uLocalAudioSampleRate; // samples/sec
319 unsigned int m_uLocalAudioSampleSize; // bits
320 unsigned int m_uLocalAudioEndianness; // 0 = le, 1 = be
321
322public:
323 void conferenceThread();
324protected:
325 void conferenceThreadMain();
326 bool setupUdpSocket();
327};
328
329KviVoiceConference::KviVoiceConference()
330{
331 m_pLinks = new KviPointerList<KviVoiceLink>;
332 m_pLinks->setAutoDelete(true);
333}
334
335KviVoiceConference::~KviVoiceConference()
336{
337 delete m_pLinks;
338}
339
340bool KviVoiceConference::setupUdpSocket()
341{
342 return true;
343}
344
345void KviVoiceConference::shutdownUdpSocket()
346{
347}
348
349void KviVoiceConference::conferenceThreadMain()
350{
351 for(;;)
352 {
353 readAndDecompressIncomingDataForEveryLink();
354
355 mixIncomingDataToASingleStream();
356 playIncomingDataSingleStream();
357
358 readLocalAudioStream();
359
360 foreach(link)
361 {
362 mixLocalAndOtherIncomingDataStreams()
363 compressAndSendOtherIncomingDataStreams()
364 }
365
366 }
367}
368
369void KviVoiceConference::conferenceThread()
370{
371 if(!setupUdpSocket())return;
372
373 conferenceThreadMain();
374
375 shutdownUdpSocket();
376}
377
378
379*/
380
381//
382// DCC VOICE NG proto
383//
384
385//
386// TCP control connection
387// --> HELLO: DccVoice protocol header
388// <-- HELLO: DccVoice protocol header
389// --> IACCEPT: Codec-description|CodecId,Codec-description|CodecID,Codec... (in order of preference)
390// <-- IACCEPT: Codec-description|CodecID,Codec-description|CodecId,Codec... (in order of preference)
391// --> MYADDRESS
392// <-- MYADDRESS
393// --> YOURIDIS: <local id for the remote end> (CID)
394// <-- YOURIDIS: <local id for the remote end> (CID)
395
396// Audio is sent in blocks broken in chunks broken in udp packets
397// Each block is a set of consecutive audio chunks that theoretically
398// should be played consecutively.
399// Each packet in a chunk has an ordinal
400// Chunks must be relatively short in order
401// to allow a remote end that looses a packet to
402// synchronize after a short period of time
403// The maximum number of packets in a chunk is 65535 (but a chunk should be no more than 24-32 KBytes in size
404// and in general they should be as small as possible, even one packet per chunk, if the codec allows it)
405// Each chunk should be encoded independently of the others
406// We can switch codec at each chunk (but not at each packet)
407// When some packets are lost we loose the entire chunk
408// A block is completely synchronized in time (unless we loose some chunks: in that case
409// we may decide to synchronize with silence or insert a glitch...)
410// Decoding never depends on the future
411
412// Each packet should be decompressable (eventually dependently on the previous in the chunk)
413// but playable independently
414
415// start UDP stream
416
417// UDP Packet format:
418
419// <magic byte>: byte
420// <magic byte>: byte
421// <local id>: word
422// <payload len>: word
423// <payload>
424
425
426// Payload format:
427
428// <codec id>: word
429// <ordinal in a chunk>: word (0 = beginning of a chunk)
430
431// read raw audio data at sample rate X, sample size Y
432// multiplex data always at this sample rate and sample size
433
434#endif
435
436#endif //_VOICE_H_
bool kvi_dcc_voice_is_valid_codec(const char *codecName)
Definition DccVoiceWindow.cpp:89
Error List.
Class for horizontal box.
Contains the KviWindow class.
Definition DccDescriptor.h:34
Definition DccMarshal.h:57
Definition DccThread.h:56
Definition DccVoiceCodec.h:36
Definition DccVoiceWindow.h:64
KviDataBuffer m_inFrameBuffer
Definition DccVoiceWindow.h:77
~DccVoiceThread()
Definition DccVoiceWindow.cpp:135
bool openSoundcard(int mode)
Definition DccVoiceWindow.cpp:182
int m_soundFdMode
Definition DccVoiceWindow.h:75
bool m_bPlaying
Definition DccVoiceWindow.h:80
virtual void run()
Definition DccVoiceWindow.cpp:631
void stopRecording()
Definition DccVoiceWindow.cpp:579
KviDataBuffer m_inSignalBuffer
Definition DccVoiceWindow.h:78
int m_iOutputBufferSize
Definition DccVoiceWindow.h:90
int m_iLastSignalBufferSize
Definition DccVoiceWindow.h:84
void stopPlaying()
Definition DccVoiceWindow.cpp:614
int m_soundFd
Definition DccVoiceWindow.h:74
bool readWriteStep()
Definition DccVoiceWindow.cpp:312
bool openSoundcardWithDuplexOption(int openMode, int failMode)
Definition DccVoiceWindow.cpp:254
void closeSoundcard()
Definition DccVoiceWindow.cpp:300
bool m_bRecording
Definition DccVoiceWindow.h:81
void startPlaying()
Definition DccVoiceWindow.cpp:597
bool openSoundcardForReading()
Definition DccVoiceWindow.cpp:245
KviDataBuffer m_outSignalBuffer
Definition DccVoiceWindow.h:79
long m_iLastSignalBufferTime
Definition DccVoiceWindow.h:85
int m_iInputBufferSize
Definition DccVoiceWindow.h:89
bool checkSoundcard()
Definition DccVoiceWindow.cpp:144
bool m_bRecordingRequestPending
Definition DccVoiceWindow.h:82
KviDataBuffer m_outFrameBuffer
Definition DccVoiceWindow.h:76
bool soundStep()
Definition DccVoiceWindow.cpp:379
bool m_bSoundcardChecked
Definition DccVoiceWindow.h:83
KviMutex * m_pInfoMutex
Definition DccVoiceWindow.h:87
void startRecording()
Definition DccVoiceWindow.cpp:556
KviDccVoiceThreadOptions * m_pOpt
Definition DccVoiceWindow.h:73
bool openSoundcardForWriting()
Definition DccVoiceWindow.cpp:236
Definition DccVoiceWindow.h:109
QLabel * m_pOutputLabel
Definition DccVoiceWindow.h:119
KviTalHBox * m_pHBox
Definition DccVoiceWindow.h:116
void updateInfo()
Definition DccVoiceWindow.cpp:919
int getMixerVolume(void) const
Definition DccVoiceWindow.cpp:1017
void fillCaptionBuffers() override
Definition DccVoiceWindow.cpp:846
void startConnection()
Definition DccVoiceWindow.cpp:778
QLabel * m_pInputLabel
Definition DccVoiceWindow.h:118
QString m_szTarget
Definition DccVoiceWindow.h:124
~DccVoiceWindow()
Definition DccVoiceWindow.cpp:763
void getBaseLogFileName(QString &buffer) override
Definition DccVoiceWindow.cpp:841
void resizeEvent(QResizeEvent *e) override
Definition DccVoiceWindow.cpp:934
QPixmap * myIconPtr() override
Definition DccVoiceWindow.cpp:855
QToolButton * m_pTalkButton
Definition DccVoiceWindow.h:122
QTimer * m_pUpdateTimer
Definition DccVoiceWindow.h:123
void focusInEvent(QFocusEvent *) override
Definition DccVoiceWindow.cpp:1071
QLabel * m_pPlayingLabel
Definition DccVoiceWindow.h:121
void handleMarshalError(KviError::Code eError)
Definition DccVoiceWindow.cpp:949
void startOrStopTalking(bool bStart)
Definition DccVoiceWindow.cpp:1009
void connected()
Definition DccVoiceWindow.cpp:959
void connectionInProgress()
Definition DccVoiceWindow.cpp:798
QSize sizeHint() const override
Definition DccVoiceWindow.cpp:941
bool event(QEvent *e) override
Definition DccVoiceWindow.cpp:860
void stopTalking()
Definition DccVoiceWindow.cpp:995
DccVoiceThread * m_pSlaveThread
Definition DccVoiceWindow.h:125
void setMixerVolume(int)
Definition DccVoiceWindow.cpp:1048
const QString & target() override
Definition DccVoiceWindow.cpp:833
void startTalking()
Definition DccVoiceWindow.cpp:1002
QSlider * m_pVolumeSlider
Definition DccVoiceWindow.h:117
QLabel * m_pRecordingLabel
Definition DccVoiceWindow.h:120
Definition DccWindow.h:35
Definition KviCString.h:102
Definition KviDataBuffer.h:31
Definition KviThread.h:147
Toolkit Abstraction Layer: hbox class.
Definition KviTalHBox.h:44
Base class for all windows in KVIrc.
Definition KviWindow.h:75
#define e
Definition detector.cpp:70
int kvi_socket_t
Definition kvi_sockettype.h:40
Code
Contains all error codes.
Definition KviError.h:48
Definition DccVoiceWindow.h:55
int iSampleRate
Definition DccVoiceWindow.h:58
int iPreBufferSize
Definition DccVoiceWindow.h:57
bool bForceHalfDuplex
Definition DccVoiceWindow.h:56
DccVoiceCodec * pCodec
Definition DccVoiceWindow.h:60
KviCString szSoundDevice
Definition DccVoiceWindow.h:59