2
* Copyright (C) 2008-2009 Barracuda Networks, Inc.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
#include <QStringList>
26
#include <QSharedDataPointer>
35
class RtpSessionPrivate;
36
class VideoWidgetPrivate;
37
class RtpChannelPrivate;
48
PluginResult loadPlugin(const QString &fname, const QString &resourcePath);
59
AudioIn, // microphone
64
Device(const Device &other);
66
Device & operator=(const Device &other);
80
class VideoWidget : public QWidget
85
VideoWidget(QWidget *parent = 0);
88
virtual QSize sizeHint() const;
91
virtual void paintEvent(QPaintEvent *event);
92
virtual void resizeEvent(QResizeEvent *event);
95
// check the size hint after receiving this signal
96
void videoSizeChanged();
99
Q_DISABLE_COPY(VideoWidget);
101
friend class VideoWidgetPrivate;
102
friend class RtpSession;
103
VideoWidgetPrivate *d;
111
AudioParams(const AudioParams &other);
113
AudioParams & operator=(const AudioParams &other);
115
QString codec() const;
116
int sampleRate() const;
117
int sampleSize() const;
118
int channels() const;
120
void setCodec(const QString &s);
121
void setSampleRate(int n);
122
void setSampleSize(int n);
123
void setChannels(int n);
125
bool operator==(const AudioParams &other) const;
127
inline bool operator!=(const AudioParams &other) const
129
return !(*this == other);
141
VideoParams(const VideoParams &other);
143
VideoParams & operator=(const VideoParams &other);
145
QString codec() const;
149
void setCodec(const QString &s);
150
void setSize(const QSize &s);
153
bool operator==(const VideoParams &other) const;
155
inline bool operator!=(const VideoParams &other) const
157
return !(*this == other);
165
class Features : public QObject
180
Features(QObject *parent = 0);
183
void lookup(int types = All);
184
bool waitForFinished(int msecs = -1);
186
QList<Device> audioOutputDevices();
187
QList<Device> audioInputDevices();
188
QList<Device> videoInputDevices();
190
QList<AudioParams> supportedAudioModes();
191
QList<VideoParams> supportedVideoModes();
198
friend class Private;
206
RtpPacket(const QByteArray &rawValue, int portOffset);
207
RtpPacket(const RtpPacket &other);
209
RtpPacket & operator=(const RtpPacket &other);
213
QByteArray rawValue() const;
214
int portOffset() const;
218
QSharedDataPointer<Private> d;
221
// may drop packets if not read fast enough.
222
// may queue no packets at all, if nobody is listening to readyRead.
223
class RtpChannel : public QObject
228
int packetsAvailable() const;
230
void write(const RtpPacket &rtp);
234
void packetsWritten(int count);
237
virtual void connectNotify(const char *signal);
238
virtual void disconnectNotify(const char *signal);
243
Q_DISABLE_COPY(RtpChannel);
245
friend class RtpSession;
246
friend class RtpSessionPrivate;
247
friend class RtpChannelPrivate;
248
RtpChannelPrivate *d;
251
// this class essentially follows jingle's notion of payload information,
252
// though it's not really jingle-specific and should be usable for any RTP
263
bool operator==(const Parameter &other) const;
265
inline bool operator!=(const Parameter &other) const
267
return !(*this == other);
272
PayloadInfo(const PayloadInfo &other);
274
PayloadInfo & operator=(const PayloadInfo &other);
279
QString name() const;
280
int clockrate() const;
281
int channels() const;
283
int maxptime() const;
284
QList<Parameter> parameters() const;
287
void setName(const QString &str);
288
void setClockrate(int i);
289
void setChannels(int num);
290
void setPtime(int i);
291
void setMaxptime(int i);
292
void setParameters(const QList<Parameter> ¶ms);
294
bool operator==(const PayloadInfo &other) const;
296
inline bool operator!=(const PayloadInfo &other) const
298
return !(*this == other);
306
class RtpSession : public QObject
318
RtpSession(QObject *parent = 0);
323
void setAudioOutputDevice(const QString &deviceId);
325
void setVideoOutputWidget(VideoWidget *widget);
328
void setAudioInputDevice(const QString &deviceId);
329
void setVideoInputDevice(const QString &deviceId);
330
void setFileInput(const QString &fileName);
331
void setFileDataInput(const QByteArray &fileData);
332
void setFileLoopEnabled(bool enabled);
334
void setVideoPreviewWidget(VideoWidget *widget);
337
// pass a QIODevice to record to. if a device is set before starting
338
// the session, then recording will wait until it starts.
339
// records in ogg theora+vorbis format
340
void setRecordingQIODevice(QIODevice *dev);
342
// stop recording operation. wait for stoppedRecording signal before
343
// QIODevice is released.
344
void stopRecording();
346
// set local preferences, using fuzzy *params structures.
347
void setLocalAudioPreferences(const QList<AudioParams> ¶ms);
348
void setLocalVideoPreferences(const QList<VideoParams> ¶ms);
350
void setMaximumSendingBitrate(int kbps);
352
// set remote preferences, using payloadinfo.
353
void setRemoteAudioPreferences(const QList<PayloadInfo> &info);
354
void setRemoteVideoPreferences(const QList<PayloadInfo> &info);
357
// - initiator sets local prefs / bitrate
358
// - initiator starts(), waits for started()
359
// - initiator obtains the corresponding payloadinfos and sends to
361
// - target receives payloadinfos
362
// - target sets local prefs / bitrate, and remote prefs
363
// - target starts(), waits for started()
364
// - target obtains the corresponding payloadinfos, which is mostly
365
// an intersection of initiator/target preferences, and sends to
367
// - target is ready for use
368
// - initiator receives payloadinfos, sets remote prefs, calls
369
// updatePreferences() and waits for preferencesUpdated()
370
// - initiator ready for use
372
// after starting, params getter functions will return a number
373
// of objects matching that of the local payloadinfo getters. note
374
// that these objects may not match the original local prefs
377
// you must set at least one local pref for each media type you want
378
// to support. any fields in params may be left unset, even all of
379
// them. if multiple params structs are specified for a media type,
380
// then this means configurations "in between" what is specified are
383
// note: targets should leave room in the prefs for flexibility in
384
// choosing among the initiator payloadinfos. if a target
385
// specifies exactly one params struct, and leaves no fields empty,
386
// then this will result in very strict choosing. for a given media
387
// type, targets should leave some fields blank or set at least two
390
// adding audio/video to existing session lacking it:
391
// - set new local prefs as params
392
// - call updatePreferences(), wait for preferencesUpdated()
393
// - obtain corresponding payloadinfos, send to peer
394
// - peer receives payloadinfos, sets local prefs as params, and
396
// - peer calls updatePreferences(), waits for preferencesUpdated()
397
// - peer obtains corresponding payloadinfos (intersection), and
399
// - receive payloadinfos, set remote prefs, call
400
// updatePreferences() and wait for preferencesUpdated()
402
// modifying params of existing media types:
403
// - set new local prefs as params
404
// - save original payloadinfos
405
// - call updatePreferences(), wait for preferencesUpdated()
406
// - obtain corresponding payloadinfos, and compare to original to
407
// determine what was added or removed
408
// - send adds/removes to peer
409
// - peer receives payloadinfos, sets remote prefs based on
410
// adds/removes to the original
411
// - peer calls updatePreferences(), waits for preferencesUpdated()
412
// - if there were any adds, peer obtains corresponding payloadinfos
413
// (intersection), and compares to original to determine what was
414
// agreed to be added.
415
// - peer acks back with accepted adds, or rejects
416
// - if reject is received, set original remote prefs
417
// - if accept is received, add the 'adds' to the original remote
418
// prefs and set them
419
// - call updatePreferences(), wait for preferencesUpdated()
421
// during modification, if a payloadinfo is being removed, then it
422
// is removed from both local/remote payloadinfo. if the peer
423
// transmits with the removed payload type, then it will be
424
// ignored. the local app won't transmit with a removed type.
426
// during modification, if a payloadinfo is being added, then it
427
// is added only to the local payloadinfo. the app must explicitly
428
// set remote prefs to update the remote payloadinfo (it would
429
// do this after receiving a peer ack). the app won't transmit
430
// using the added payloadinfo until the remote list is updated
431
// as appropriate (more generally, the app won't transmit using a
432
// payloadinfo that is not in the remote list).
435
// if prefs are changed after starting, this function needs to be
436
// called for them to take effect
437
void updatePreferences();
439
void transmitAudio();
440
void transmitVideo();
445
// in a correctly negotiated session, there will be an equal amount of
446
// local/remote values for each media type (during negotiation there
447
// may be a mismatch). however, the payloadinfo for each won't
448
// necessarily match exactly. for example, both sides could be
449
// using theora, but they'll almost certainly have different
451
QList<PayloadInfo> localAudioPayloadInfo() const;
452
QList<PayloadInfo> localVideoPayloadInfo() const;
453
QList<PayloadInfo> remoteAudioPayloadInfo() const;
454
QList<PayloadInfo> remoteVideoPayloadInfo() const;
456
// maps to local payloadinfo
457
QList<AudioParams> audioParams() const;
458
QList<VideoParams> videoParams() const;
460
// parameter negotiation is independent of the existence of input and
461
// output devices. you could perform a negotiation without
462
// specifying any input devices, and this just means you won't be
463
// able to transmit until you eventually do specify them. similarly,
464
// you could have specified input devices but then later removed them
465
// (by setting the device id to an empty string). the following
466
// methods can be used to know what media types you're able to send.
467
// in the case of devices, this is somewhat redundant information,
468
// but the methods are useful in the case of using a file as input,
469
// which might have varying media contained.
470
bool canTransmitAudio() const;
471
bool canTransmitVideo() const;
474
int outputVolume() const; // 0 (mute) to 100
475
void setOutputVolume(int level);
478
int inputVolume() const; // 0 (mute) to 100
479
void setInputVolume(int level);
481
Error errorCode() const;
483
RtpChannel *audioRtpChannel();
484
RtpChannel *videoRtpChannel();
488
void preferencesUpdated();
489
void audioOutputIntensityChanged(int intensity); // 0-100, -1 for no signal
490
void audioInputIntensityChanged(int intensity); // 0-100
491
void stoppedRecording();
493
void finished(); // for file playback only
497
Q_DISABLE_COPY(RtpSession);
499
friend class RtpSessionPrivate;
500
RtpSessionPrivate *d;