Rudimentary support for recording hosted conference calls
[skype-call-recorder.git] / call.h
blobb746f46350b29e6c10e8fec8c9b03083f5884650
1 /*
2 Skype Call Recorder
3 Copyright 2008 - 2009 by jlh (jlh at gmx dot ch)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, version 3 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 The GNU General Public License version 2 is included with the source of
20 this program under the file name COPYING. You can also get a copy on
21 http://www.fsf.org/
24 #ifndef CALL_H
25 #define CALL_H
27 #include <QObject>
28 #include <QString>
29 #include <QByteArray>
30 #include <QMap>
31 #include <QSet>
32 #include <QPointer>
33 #include <QDateTime>
34 #include <QTime>
35 #include <QFile>
37 #include "common.h"
39 class QStringList;
40 class Skype;
41 class AudioFileWriter;
42 class QTcpServer;
43 class QTcpSocket;
44 class LegalInformationDialog;
46 class CallHandler;
48 typedef int CallID;
50 class AutoSync {
51 public:
52 AutoSync(int, long);
53 ~AutoSync();
54 void add(long);
55 long getSync();
56 void reset();
58 private:
59 long *delays;
60 int size;
61 int index;
62 long sum;
63 qint64 sum2;
64 long precision;
65 int suppress;
67 DISABLE_COPY_AND_ASSIGNMENT(AutoSync);
70 class Call : public QObject {
71 Q_OBJECT
72 public:
73 Call(CallHandler *, Skype *, CallID);
74 ~Call();
75 void startRecording(bool = false);
76 void stopRecording(bool = true);
77 void updateConfID();
78 bool okToDelete() const;
79 void setStatus(const QString &);
80 QString getStatus() const { return status; }
81 bool statusDone() const;
82 bool statusActive() const;
83 CallID getID() const { return id; }
84 CallID getConfID() const { return confID; }
85 void removeFile();
86 void hideConfirmation(int);
87 bool getIsRecording() const { return isRecording; }
89 signals:
90 void startedCall(int, const QString &);
91 void stoppedCall(int);
92 void startedRecording(int);
93 void stoppedRecording(int);
94 void showLegalInformation();
96 private:
97 QString constructFileName() const;
98 QString constructCommentTag() const;
99 void mixToMono(long);
100 void mixToStereo(long, int);
101 void setShouldRecord();
102 void ask();
103 void doSync(long);
105 private:
106 Skype *skype;
107 CallHandler *handler;
108 CallID id;
109 QString status;
110 QString skypeName;
111 QString displayName;
112 CallID confID;
113 AudioFileWriter *writer;
114 bool isRecording;
115 int stereo;
116 int stereoMix;
117 int shouldRecord;
118 QString fileName;
119 QPointer<QObject> confirmation;
120 QDateTime timeStartRecording;
122 QTime syncTime;
123 QFile syncFile;
124 AutoSync sync;
126 QTcpServer *serverLocal, *serverRemote;
127 QTcpSocket *socketLocal, *socketRemote;
128 QByteArray bufferLocal, bufferRemote;
130 private slots:
131 void acceptLocal();
132 void acceptRemote();
133 void readLocal();
134 void readRemote();
135 void checkConnections();
136 long padBuffers();
137 void tryToWrite(bool = false);
138 void confirmRecording();
139 void denyRecording();
141 private: // moc gets confused without this private:
142 DISABLE_COPY_AND_ASSIGNMENT(Call);
145 class CallHandler : public QObject {
146 Q_OBJECT
147 public:
148 CallHandler(QObject *, Skype *);
149 ~CallHandler();
150 void updateConfIDs();
151 bool isConferenceRecording(CallID) const;
152 void callCmd(const QStringList &);
154 signals:
155 // note that {start,stop}Recording signals are not guaranteed to always
156 // happen within a {start,stop}Call block. Especially,
157 // stoppedRecording will usually happen *after* stoppedCall
158 void startedCall(int, const QString &);
159 void stoppedCall(int);
160 void startedRecording(int);
161 void stoppedRecording(int);
163 public slots:
164 void startRecording(int);
165 void stopRecording(int);
166 void stopRecordingAndDelete(int);
168 private slots:
169 void showLegalInformation();
171 private:
172 void prune();
174 private:
175 typedef QMap<CallID, Call *> CallMap;
176 typedef QSet<CallID> CallSet;
178 CallMap calls;
179 CallSet ignore;
180 Skype *skype;
181 QPointer<LegalInformationDialog> legalInformationDialog;
183 DISABLE_COPY_AND_ASSIGNMENT(CallHandler);
186 #endif