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 "mvoicecallengine.h"
31 
32 class AudioMixer ;
33 class AudioEncoder ;
34 class AudioSource ;
35 class AudioPlayer ;
36 
53 class VoiceCallEngine : public QAbstractTableModel,
54  public MVoiceCallEngine {
55  Q_OBJECT
56 public:
57 
63  VoiceCallEngine(MController& aController,
64  Model& aModel ) ;
69 
73  virtual void installObserver(MCallStatusObserver* aObserver) ;
74 
78  virtual void removeObserver(MCallStatusObserver* aObserver) ;
79 
94  virtual void insertCallData(quint32 aCallId,
95  quint32 aSeqNo,
96  PayloadType aPayloadType,
97  const QByteArray& aPayload,
98  const Hash& aSendingNode) ;
99 
129  virtual void insertCallStatusData(const VoiceCall& aCallStatus,
130  const Hash& aSendingNode) ;
134  virtual QList<quint32> onGoingCalls() const ;
138  virtual CallState callStatus(quint32 aCallId) const ;
142  virtual void closeCall(quint32 aCallId) ;
146  virtual void acceptCall(quint32 aCallId) ;
157  QString excuseForCallCreation(const Hash& aOperator,
158  const Hash& aNode = KNullHash ) const ;
163  virtual int rowCount(const QModelIndex & parent = QModelIndex()) const ;
168  virtual int columnCount(const QModelIndex & parent = QModelIndex()) const ;
173  virtual QVariant data(const QModelIndex & index,
174  int role = Qt::DisplayRole) const ;
179  virtual QVariant headerData ( int section,
180  Qt::Orientation orientation,
181  int role = Qt::DisplayRole ) const ;
182 
183 public slots:
189  const Hash aHashOfAttemptedNode );
190 
198  void audioFrameEncoded ( quint32 aCallId,
199  quint32 aSeqNo,
200  const QByteArray& aEncodedVoice ) ;
210  void processCallData() ;
214  void setInputLevel(float aInputLevel) ;
218  void setOutputLevel(float aOutputLevel) ;
219 signals:
220  void error(QTcpSocket::SocketError socketError);
222  void callStateChanged(quint32 aCallId,
225  void startProcessCallData() ;
229  void inputLevel(float aInputLevel) ;
233  void outputLevel(float aOutputLevel) ;
234 private:
235  class VoiceCallExtension ;
236  // methods
248  void sendCallStatusUpdates(quint32 aCallId,
249  CallState aState ) ;
254  Hash callPeerFingerPrint(const VoiceCall& aCall) const ;
256  void addCallToArray(VoiceCallExtension& aCall) ;
257  void sendCallStatusUpdateToRemote(const VoiceCall& aCall,bool aDoSign=true) ;
258  QString callStatusString(const VoiceCallExtension& aCall) const ;
262  bool checkForNodeValidity(const VoiceCall& aCallStatus,
263  const Hash& aSendingNode) const ;
275  bool setupAudioOutput(VoiceCallExtension& aCall) ;
279  bool addCallToMixer(const VoiceCallExtension& aCall) ;
283  bool removeCallFromMixer(const VoiceCallExtension& aCall) ;
284 private: // data
290  public:
292  VoiceCallExtension(const VoiceCall& aInitialData) :
293  iDecoder(NULL) {
294  fromJSon(aInitialData.asJSon()) ;
295  }
297  if ( iDecoder ) {
298  iDecoder->deleteLater() ;
299  iDecoder = NULL ;
300  }
301  }
314  } ;
317  QList<MCallStatusObserver*> iCallObservers ;
318  QList<VoiceCallExtension> iOnGoingCalls ;
334  QList<QPair<VoiceCall, Hash> > iCallDataPendingProcessing ;
335 } ;
336 #endif
class for de-compressing audio received from network
Definition: audiodecoder.h:32
opposite of audiosink.
Definition: audiosource.h:41
AudioSource * iAudioSource
Definition: voicecallengine.h:332
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void processCallData()
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Pure-virtual interface for voice call engine.
Definition: mvoicecallengine.h:33
CallState iOnGoingCallState
Definition: voicecallengine.h:303
void startProcessCallData()
void callStateChanged(quint32 aCallId, VoiceCallEngine::CallState aState)
virtual CallState callStatus(quint32 aCallId) const
void setOutputLevel(float aOutputLevel)
VoiceCallEngine(MController &aController, Model &aModel)
QString iPeerNodeAddress
Definition: voicecallengine.h:307
virtual void insertCallStatusData(const VoiceCall &aCallStatus, const Hash &aSendingNode)
QByteArray asJSon() const
QString excuseForCallCreation(const Hash &aOperator, const Hash &aNode=KNullHash) const
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:44
void addCallToArray(VoiceCallExtension &aCall)
virtual void removeObserver(MCallStatusObserver *aObserver)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
void audioFrameEncoded(quint32 aCallId, quint32 aSeqNo, const QByteArray &aEncodedVoice)
virtual void closeCall(quint32 aCallId)
MController & iController
Definition: voicecallengine.h:315
class for compressing audio to be sent over network
Definition: audioencoder.h:34
AudioDecoder * iDecoder
Definition: voicecallengine.h:313
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
virtual void insertCallData(quint32 aCallId, quint32 aSeqNo, PayloadType aPayloadType, const QByteArray &aPayload, const Hash &aSendingNode)
ConnectionState
Definition: connection.h:47
QString iPeerOperatorHash
Definition: voicecallengine.h:305
~VoiceCallExtension()
Definition: voicecallengine.h:296
virtual void acceptCall(quint32 aCallId)
AudioMixer * iMixer
Definition: voicecallengine.h:325
bool setupNewIncomingCall(VoiceCallExtension &aCall)
virtual void installObserver(MCallStatusObserver *aObserver)
AudioEncoder * iEncoder
Definition: voicecallengine.h:331
void error(QTcpSocket::SocketError socketError)
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:43
Hash callPeerFingerPrint(const VoiceCall &aCall) const
PayloadType
Definition: mvoicecallengine.h:63
QList< VoiceCallExtension > iOnGoingCalls
Definition: voicecallengine.h:318
Hash KNullHash
bool addCallToMixer(const VoiceCallExtension &aCall)
bool fromJSon(const QByteArray &aJSonBytes)
virtual QList< quint32 > onGoingCalls() const
Model & iModel
Definition: voicecallengine.h:316
M of the MVC pattern. Handles permanent storage.
Definition: model.h:48
Definition: mvoicecallengine.h:52
CallState
Definition: mvoicecallengine.h:38
void setInputLevel(float aInputLevel)
bool setupNewOutgoingCall(VoiceCallExtension &aCall)
void inputLevel(float aInputLevel)
VoiceCallExtension(const VoiceCall &aInitialData)
Definition: voicecallengine.h:292
void nodeConnectionAttemptStatus(Connection::ConnectionState aStatus, const Hash aHashOfAttemptedNode)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QList< QPair< VoiceCall, Hash > > iCallDataPendingProcessing
Definition: voicecallengine.h:334
AudioPlayer * iAudioPlayer
Definition: voicecallengine.h:333
bool checkForNodeValidity(const VoiceCall &aCallStatus, const Hash &aSendingNode) const
QList< MCallStatusObserver * > iCallObservers
Definition: voicecallengine.h:317
bool setupAudioOutput(VoiceCallExtension &aCall)
QString callStatusString(const VoiceCallExtension &aCall) const
void outputLevel(float aOutputLevel)
Definition: voicecallengine.h:289
void sendCallStatusUpdates(quint32 aCallId, CallState aState)
Network-related logic for handling voice channel between nodes.
Definition: voicecallengine.h:53
bool setupLocalAudioCapture(VoiceCallExtension &aCall)