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