Classified ads
audiomixer.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 AUDIO_MIXER_H
22 #define AUDIO_MIXER_H
23 
24 #include <QObject>
25 #include <QByteArray>
26 #include <QQueue>
27 #include "../util/hash.h"
28 
29 class Model ;
30 
45 class AudioMixer : public QObject {
46  Q_OBJECT
47 
48 public:
52  AudioMixer(Model& aModel) ;
53  ~AudioMixer() ;
54 
64  void insertStream (quint32 aCallId,
65  quint32 aStartingSeq,
66  bool aIsLocallyCaptured,
67  const Hash& aOriginatingNode ) ;
72  void removeStream (quint32 aCallId) ;
73 signals:
75  void frameReadyForLocalSpeaker(const QByteArray& aFrame) ;
77  void frameReadyForRemoteSend(quint32 aCallId,
78  quint32 aSeqNo,
79  const QByteArray& aFrame,
80  Hash aForNode ) ;
81 public slots:
98  void insertCapturedAudioFrame ( const QByteArray& aFrame,
99  quint32 aSeqNo,
100  float aVolumeLevel);
101 
122  void insertReceivedAudioFrame ( quint32 aCallId,
123  quint32 aSeqNo,
124  const QByteArray& aFrame,
125  Hash aOriginatingNode );
126 
127 private: // methods
133  void tryMixFrames(quint32 aCallId,
134  quint32 aSeqNo) ;
139  void configureMixedStreams() ;
146  void doInsertAudioFrame ( const QByteArray& aFrame,
147  bool aIsLocallyCaptured,
148  quint32 aSeqNo,
149  quint32 aCallId,
150  float aVolumeLevel,
151  Hash &aOriginatingNode );
152 
153 private: // members
159  typedef struct AudioFrameStruct {
160  quint32 iCallId ;
161  quint32 iSeqNo ;
163  QByteArray iFrame ;
164  float iVolumeLevel ;
165  } AudioFrame ;
166  typedef struct AudioStreamMetadata {
167  quint32 iCallId ;
168  quint32 iStartingSeq ;
175  quint32 iMaxSeqSeen;
184  QList<QQueue<AudioFrame> > iAudioDataBuffer ;
186  QList<AudioFrameMetadata> iStreams ;
192 } ;
193 #endif
void insertReceivedAudioFrame(quint32 aCallId, quint32 aSeqNo, const QByteArray &aFrame, Hash aOriginatingNode)
Hash iNode
Definition: audiomixer.h:176
float iVolumeLevel
Definition: audiomixer.h:164
struct AudioMixer::AudioFrameStruct AudioFrame
Class for mixing together 0-n audio streams.
Definition: audiomixer.h:45
Definition: audiomixer.h:159
QList< int > iIndexesToMixForRemoteOutput
Definition: audiomixer.h:190
AudioMixer(Model &aModel)
void insertCapturedAudioFrame(const QByteArray &aFrame, quint32 aSeqNo, float aVolumeLevel)
Hash is class that carries 160-bit digest.
Definition: hash.h:38
void doInsertAudioFrame(const QByteArray &aFrame, bool aIsLocallyCaptured, quint32 aSeqNo, quint32 aCallId, float aVolumeLevel, Hash &aOriginatingNode)
QList< QQueue< AudioFrame > > iAudioDataBuffer
Definition: audiomixer.h:184
void configureMixedStreams()
struct AudioMixer::AudioStreamMetadata AudioFrameMetadata
bool iIsLocallyCaptured
Definition: audiomixer.h:177
quint32 iSeqNo
Definition: audiomixer.h:161
QList< int > iIndexesToMixForLocalSpeaker
Definition: audiomixer.h:188
quint32 iMaxSeqSeen
Definition: audiomixer.h:175
Model & iModel
Definition: audiomixer.h:191
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
void frameReadyForLocalSpeaker(const QByteArray &aFrame)
Definition: audiomixer.h:166
void frameReadyForRemoteSend(quint32 aCallId, quint32 aSeqNo, const QByteArray &aFrame, Hash aForNode)
QList< AudioFrameMetadata > iStreams
Definition: audiomixer.h:186
quint32 iCallId
Definition: audiomixer.h:160
void tryMixFrames(quint32 aCallId, quint32 aSeqNo)
quint32 iStartingSeq
Definition: audiomixer.h:168
void removeStream(quint32 aCallId)
QByteArray iFrame
Definition: audiomixer.h:163
void insertStream(quint32 aCallId, quint32 aStartingSeq, bool aIsLocallyCaptured, const Hash &aOriginatingNode)
bool iIsLocallyCaptured
Definition: audiomixer.h:162
quint32 iCallId
Definition: audiomixer.h:167