Classified ads
voicecallengine.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2015.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef VOICECALL_ENG_H
22 #define VOICECALL_ENG_H
23 #include <QString>
24 #include <QList>
25 #include <QAbstractTableModel>
26 #include <QPair>
27 #include "../datamodel/model.h"
28 #include "../datamodel/voicecall.h"
29 #include "../call/audiodecoder.h"
30 #include "../call/audioencoder.h"
31 #include "mvoicecallengine.h"
32 
33 class AudioMixer ;
34 class AudioEncoder ;
35 class AudioSource ;
36 class AudioPlayer ;
37 
54 class VoiceCallEngine : public QAbstractTableModel,
55  public MVoiceCallEngine {
56  Q_OBJECT
57 public:
58 
64  VoiceCallEngine(MController& aController,
65  Model& aModel ) ;
70 
74  virtual void installObserver(MCallStatusObserver* aObserver) ;
75 
79  virtual void removeObserver(MCallStatusObserver* aObserver) ;
80 
95  virtual void insertCallData(quint32 aCallId,
96  quint32 aSeqNo,
97  PayloadType aPayloadType,
98  const QByteArray& aPayload,
99  Hash& aSendingNode) ;
100 
130  virtual void insertCallStatusData(const VoiceCall& aCallStatus,
131  const Hash& aSendingNode) ;
135  virtual QList<quint32> onGoingCalls() const ;
139  virtual CallState callStatus(quint32 aCallId) const ;
143  virtual void closeCall(quint32 aCallId) ;
147  virtual void acceptCall(quint32 aCallId) ;
158  QString excuseForCallCreation(const Hash& aOperator,
159  const Hash& aNode = KNullHash ) const ;
164  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const ;
169  virtual int columnCount(const QModelIndex & parent = QModelIndex()) const ;
174  virtual QVariant data(const QModelIndex & index,
175  int role = Qt::DisplayRole) const ;
180  virtual QVariant headerData ( int section,
181  Qt::Orientation orientation,
182  int role = Qt::DisplayRole ) const ;
183 
184 public slots:
190  const Hash aHashOfAttemptedNode );
191 
199  void audioFrameEncoded ( quint32 aCallId,
200  quint32 aSeqNo,
201  const QByteArray& aEncodedVoice,
202  Hash aForNode ) ;
203 
216  void frameReady ( quint32 aCallId,
217  quint32 aSeqNo,
218  const QByteArray& aRawAudio,
219  Hash aForNode ) ;
220 
230  void processCallData() ;
234  void setInputLevel(float aInputLevel) ;
238  void setOutputLevel(float aOutputLevel) ;
239 signals:
240  void error(QTcpSocket::SocketError socketError);
242  void callStateChanged(quint32 aCallId,
245  void startProcessCallData() ;
249  void inputLevel(float aInputLevel) ;
253  void outputLevel(float aOutputLevel) ;
254 private:
255  class VoiceCallExtension ;
256  // methods
268  void sendCallStatusUpdates(quint32 aCallId,
269  CallState aState ) ;
274  Hash callPeerFingerPrint(const VoiceCall& aCall) const ;
276  void addCallToArray(VoiceCallExtension& aCall) ;
277  void sendCallStatusUpdateToRemote(const VoiceCall& aCall,bool aDoSign=true) ;
278  QString callStatusString(const VoiceCallExtension& aCall) const ;
282  bool checkForNodeValidity(const VoiceCall& aCallStatus,
283  const Hash& aSendingNode) const ;
295  bool setupAudioOutput(VoiceCallExtension& aCall) ;
299  bool addCallToMixer(const VoiceCallExtension& aCall) ;
303  bool removeCallFromMixer(const VoiceCallExtension& aCall) ;
304 private: // data
310  public:
312  VoiceCallExtension(const VoiceCall& aInitialData) :
313  iDecoder(NULL),
314  iEncoder(NULL) {
315  fromJSon(aInitialData.asJSon()) ;
316  }
318  if ( iDecoder ) {
319  iDecoder->deleteLater() ;
320  iDecoder = NULL ;
321  }
322  if ( iEncoder ) {
323  iEncoder->deleteLater() ;
324  iEncoder = NULL ;
325  }
326  }
345  } ;
348  QList<MCallStatusObserver*> iCallObservers ;
349  QList<VoiceCallExtension> iOnGoingCalls ;
359  QList<QPair<VoiceCall, Hash> > iCallDataPendingProcessing ;
360 } ;
361 #endif
AudioEncoder * iEncoder
Definition: voicecallengine.h:344
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
class for de-compressing audio received from network
Definition: audiodecoder.h:33
opposite of audiosink.
Definition: audiosource.h:41
AudioSource * iAudioSource
Definition: voicecallengine.h:357
void processCallData()
Pure-virtual interface for voice call engine.
Definition: mvoicecallengine.h:33
Hash callPeerFingerPrint(const VoiceCall &aCall) const
CallState iOnGoingCallState
Definition: voicecallengine.h:328
QString excuseForCallCreation(const Hash &aOperator, const Hash &aNode=KNullHash) const
void startProcessCallData()
void callStateChanged(quint32 aCallId, VoiceCallEngine::CallState aState)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void setOutputLevel(float aOutputLevel)
VoiceCallEngine(MController &aController, Model &aModel)
QString iPeerNodeAddress
Definition: voicecallengine.h:332
virtual void insertCallStatusData(const VoiceCall &aCallStatus, const Hash &aSendingNode)
Class for playback of audio stream, via speaker or other audio dev.
Definition: audioplayer.h:38
Class for mixing together 0-n audio streams.
Definition: audiomixer.h:45
void addCallToArray(VoiceCallExtension &aCall)
virtual void removeObserver(MCallStatusObserver *aObserver)
virtual void closeCall(quint32 aCallId)
MController & iController
Definition: voicecallengine.h:346
class for compressing audio to be sent over network
Definition: audioencoder.h:35
AudioDecoder * iDecoder
Definition: voicecallengine.h:338
bool removeCallFromMixer(const VoiceCallExtension &aCall)
Carrier-class handling audio negotiation setup and data.
Definition: voicecall.h:40
void removeCallFromArray(VoiceCallExtension &aCall)
void sendCallStatusUpdateToRemote(const VoiceCall &aCall, bool aDoSign=true)
Hash is class that carries 160-bit digest.
Definition: hash.h:38
QByteArray asJSon() const
ConnectionState
Definition: connection.h:47
QString iPeerOperatorHash
Definition: voicecallengine.h:330
~VoiceCallExtension()
Definition: voicecallengine.h:317
virtual void acceptCall(quint32 aCallId)
void frameReady(quint32 aCallId, quint32 aSeqNo, const QByteArray &aRawAudio, Hash aForNode)
AudioMixer * iMixer
Definition: voicecallengine.h:356
bool setupNewIncomingCall(VoiceCallExtension &aCall)
virtual void installObserver(MCallStatusObserver *aObserver)
void error(QTcpSocket::SocketError socketError)
virtual CallState callStatus(quint32 aCallId) const
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
PayloadType
Definition: mvoicecallengine.h:63
QList< VoiceCallExtension > iOnGoingCalls
Definition: voicecallengine.h:349
Hash KNullHash
bool addCallToMixer(const VoiceCallExtension &aCall)
bool fromJSon(const QByteArray &aJSonBytes)
Model & iModel
Definition: voicecallengine.h:347
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
Definition: mvoicecallengine.h:52
virtual QList< quint32 > onGoingCalls() const
CallState
Definition: mvoicecallengine.h:38
void setInputLevel(float aInputLevel)
bool setupNewOutgoingCall(VoiceCallExtension &aCall)
void inputLevel(float aInputLevel)
VoiceCallExtension(const VoiceCall &aInitialData)
Definition: voicecallengine.h:312
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
void nodeConnectionAttemptStatus(Connection::ConnectionState aStatus, const Hash aHashOfAttemptedNode)
QString callStatusString(const VoiceCallExtension &aCall) const
QList< QPair< VoiceCall, Hash > > iCallDataPendingProcessing
Definition: voicecallengine.h:359
AudioPlayer * iAudioPlayer
Definition: voicecallengine.h:358
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
QList< MCallStatusObserver * > iCallObservers
Definition: voicecallengine.h:348
bool setupAudioOutput(VoiceCallExtension &aCall)
void outputLevel(float aOutputLevel)
virtual void insertCallData(quint32 aCallId, quint32 aSeqNo, PayloadType aPayloadType, const QByteArray &aPayload, Hash &aSendingNode)
bool checkForNodeValidity(const VoiceCall &aCallStatus, const Hash &aSendingNode) const
Definition: voicecallengine.h:309
void sendCallStatusUpdates(quint32 aCallId, CallState aState)
Network-related logic for handling voice channel between nodes.
Definition: voicecallengine.h:54
void audioFrameEncoded(quint32 aCallId, quint32 aSeqNo, const QByteArray &aEncodedVoice, Hash aForNode)
bool setupLocalAudioCapture(VoiceCallExtension &aCall)