QXmpp  Version:1.0.0
QXmppRtpChannel.h
1 /*
2  * Copyright (C) 2008-2019 The QXmpp developers
3  *
4  * Author:
5  * Jeremy LainĂ©
6  *
7  * Source:
8  * https://github.com/qxmpp-project/qxmpp
9  *
10  * This file is a part of QXmpp library.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  */
23 
24 #ifndef QXMPPRTPCHANNEL_H
25 #define QXMPPRTPCHANNEL_H
26 
27 #include <QIODevice>
28 #include <QSize>
29 
30 #include "QXmppJingleIq.h"
31 #include "QXmppLogger.h"
32 
33 class QXmppCodec;
35 class QXmppRtpAudioChannelPrivate;
36 class QXmppRtpVideoChannelPrivate;
37 
38 class QXMPP_EXPORT QXmppRtpChannel
39 {
40 public:
41  QXmppRtpChannel();
42 
44  virtual void close() = 0;
45 
47  virtual QIODevice::OpenMode openMode() const = 0;
48 
49  QList<QXmppJinglePayloadType> localPayloadTypes();
50  void setRemotePayloadTypes(const QList<QXmppJinglePayloadType> &remotePayloadTypes);
51 
52  quint32 localSsrc() const;
53  void setLocalSsrc(quint32 ssrc);
54 
55 protected:
57  virtual void payloadTypesChanged() = 0;
58 
59  QList<QXmppJinglePayloadType> m_incomingPayloadTypes;
60  QList<QXmppJinglePayloadType> m_outgoingPayloadTypes;
61  bool m_outgoingPayloadNumbered;
63 
64 private:
65  quint32 m_outgoingSsrc;
66 };
67 
74 
75 class QXMPP_EXPORT QXmppRtpAudioChannel : public QIODevice, public QXmppRtpChannel
76 {
77  Q_OBJECT
78  Q_ENUMS(Tone)
79 
80 public:
82  enum Tone {
83  Tone_0 = 0,
98  Tone_D
99  };
100 
101  QXmppRtpAudioChannel(QObject *parent = 0);
103 
104  qint64 bytesAvailable() const;
105  void close();
106  bool isSequential() const;
107  QIODevice::OpenMode openMode() const;
108  QXmppJinglePayloadType payloadType() const;
109  qint64 pos() const;
110  bool seek(qint64 pos);
111 
112 signals:
114  void sendDatagram(const QByteArray &ba);
115 
117  void logMessage(QXmppLogger::MessageType type, const QString &msg);
118 
119 public slots:
120  void datagramReceived(const QByteArray &ba);
121  void startTone(QXmppRtpAudioChannel::Tone tone);
122  void stopTone(QXmppRtpAudioChannel::Tone tone);
123 
124 protected:
126  void debug(const QString &message)
127  {
128  emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
129  }
130 
131  void warning(const QString &message)
132  {
133  emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
134  }
135 
136  void logReceived(const QString &message)
137  {
138  emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
139  }
140 
141  void logSent(const QString &message)
142  {
143  emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
144  }
145 
146  void payloadTypesChanged();
147  qint64 readData(char * data, qint64 maxSize);
148  qint64 writeData(const char * data, qint64 maxSize);
150 
151 private slots:
152  void emitSignals();
153  void writeDatagram();
154 
155 private:
156  friend class QXmppRtpAudioChannelPrivate;
157  QXmppRtpAudioChannelPrivate * d;
158 };
159 
163 
164 class QXMPP_EXPORT QXmppVideoFrame
165 {
166 public:
168  enum PixelFormat {
169  Format_Invalid = 0,
170  Format_RGB32 = 3,
171  Format_RGB24 = 4,
172  Format_YUV420P = 18,
173  Format_UYVY = 20,
177  Format_YUYV = 21
182  };
187 
188  QXmppVideoFrame();
189  QXmppVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
190  uchar *bits();
191  const uchar *bits() const;
192  int bytesPerLine() const;
193  int height() const;
194  bool isValid() const;
195  int mappedBytes() const;
196  PixelFormat pixelFormat() const;
197  QSize size() const;
198  int width() const;
199 
200 private:
201  int m_bytesPerLine;
202  QByteArray m_data;
203  int m_height;
204  int m_mappedBytes;
205  PixelFormat m_pixelFormat;
206  int m_width;
207 };
208 
209 class QXMPP_EXPORT QXmppVideoFormat
210 {
211 public:
212  QXmppVideoFormat()
213  : m_frameRate(15.0)
214  , m_frameSize(QSize(320, 240))
215  , m_pixelFormat(QXmppVideoFrame::Format_YUYV)
216  {}
217 
218  int frameHeight() const {
219  return m_frameSize.height();
220  }
221 
222  int frameWidth() const {
223  return m_frameSize.width();
224  }
225 
226  qreal frameRate() const {
227  return m_frameRate;
228  }
229 
230  void setFrameRate(qreal frameRate) {
231  m_frameRate = frameRate;
232  }
233 
234  QSize frameSize() const {
235  return m_frameSize;
236  }
237 
238  void setFrameSize(const QSize &frameSize) {
239  m_frameSize = frameSize;
240  }
241 
242  QXmppVideoFrame::PixelFormat pixelFormat() const {
243  return m_pixelFormat;
244  }
245 
246  void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) {
247  m_pixelFormat = pixelFormat;
248  }
249 
250 private:
251  qreal m_frameRate;
252  QSize m_frameSize;
253  QXmppVideoFrame::PixelFormat m_pixelFormat;
254 };
255 
256 
260 
261 class QXMPP_EXPORT QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
262 {
263  Q_OBJECT
264 
265 public:
266  QXmppRtpVideoChannel(QObject *parent = 0);
268 
269  void close();
270  QIODevice::OpenMode openMode() const;
271 
272  // incoming stream
273  QXmppVideoFormat decoderFormat() const;
274  QList<QXmppVideoFrame> readFrames();
275 
276  // outgoing stream
277  QXmppVideoFormat encoderFormat() const;
278  void setEncoderFormat(const QXmppVideoFormat &format);
279  void writeFrame(const QXmppVideoFrame &frame);
280 
281 signals:
283  void sendDatagram(const QByteArray &ba);
284 
285 public slots:
286  void datagramReceived(const QByteArray &ba);
287 
288 protected:
290  void payloadTypesChanged();
292 
293 private:
294  friend class QXmppRtpVideoChannelPrivate;
295  QXmppRtpVideoChannelPrivate * d;
296 };
297 
298 #endif
QXmppLogger::DebugMessage
Debugging message.
Definition: QXmppLogger.h:68
QXmppJinglePayloadType
The QXmppJinglePayloadType class represents a payload type as specified by XEP-0167: Jingle RTP Sessi...
Definition: QXmppJingleIq.h:40
QXmppRtpAudioChannel::Tone_8
Tone for the 8 key.
Definition: QXmppRtpChannel.h:91
QXmppLogger::MessageType
MessageType
This enum describes a type of log message.
Definition: QXmppLogger.h:65
QXmppRtpAudioChannel::Tone_A
Tone for the A key.
Definition: QXmppRtpChannel.h:95
QXmppLogger::ReceivedMessage
Message received from server.
Definition: QXmppLogger.h:71
QXmppLogger::SentMessage
Message sent to server.
Definition: QXmppLogger.h:72
QXmppRtpAudioChannel::Tone_B
Tone for the B key.
Definition: QXmppRtpChannel.h:96
QXmppRtpAudioChannel::Tone_1
Tone for the 1 key.
Definition: QXmppRtpChannel.h:84
QXmppRtpVideoChannel
The QXmppRtpVideoChannel class represents an RTP video channel to a remote party.
Definition: QXmppRtpChannel.h:261
QXmppRtpAudioChannel::Tone_5
Tone for the 5 key.
Definition: QXmppRtpChannel.h:88
QXmppRtpAudioChannel::Tone_9
Tone for the 9 key.
Definition: QXmppRtpChannel.h:92
QXmppRtpAudioChannel::Tone_2
Tone for the 2 key.
Definition: QXmppRtpChannel.h:85
QXmppRtpAudioChannel::Tone_4
Tone for the 4 key.
Definition: QXmppRtpChannel.h:87
QXmppRtpAudioChannel::Tone_3
Tone for the 3 key.
Definition: QXmppRtpChannel.h:86
QXmppRtpAudioChannel::Tone_Pound
Tone for the # key.
Definition: QXmppRtpChannel.h:94
QXmppVideoFrame::PixelFormat
PixelFormat
This enum describes a pixel format.
Definition: QXmppRtpChannel.h:168
QXmppLogger::WarningMessage
Warning message.
Definition: QXmppLogger.h:70
QXmppVideoFrame
The QXmppVideoFrame class provides a representation of a frame of video data.
Definition: QXmppRtpChannel.h:164
QXmppRtpAudioChannel::Tone_C
Tone for the C key.
Definition: QXmppRtpChannel.h:97
QXmppRtpAudioChannel::Tone
Tone
This enum is used to describe a DTMF tone.
Definition: QXmppRtpChannel.h:82
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:111
QXmppRtpAudioChannel::Tone_Star
Tone for the * key.
Definition: QXmppRtpChannel.h:93
QXmppRtpAudioChannel::Tone_7
Tone for the 7 key.
Definition: QXmppRtpChannel.h:90
QXmppRtpAudioChannel::Tone_6
Tone for the 6 key.
Definition: QXmppRtpChannel.h:89
QXmppRtpAudioChannel
The QXmppRtpAudioChannel class represents an RTP audio channel to a remote party.
Definition: QXmppRtpChannel.h:75