QXmpp  Version:1.2.0
QXmppRtpChannel.h
1 /*
2  * Copyright (C) 2008-2020 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 "QXmppJingleIq.h"
28 #include "QXmppLogger.h"
29 
30 #include <QIODevice>
31 #include <QSize>
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 
79 public:
81  enum Tone {
82  Tone_0 = 0,
97  Tone_D
98  };
99  Q_ENUM(Tone)
100 
101  QXmppRtpAudioChannel(QObject *parent = nullptr);
102  ~QXmppRtpAudioChannel() override;
103 
104  qint64 bytesAvailable() const override;
105  void close() override;
106  bool isSequential() const override;
107  QIODevice::OpenMode openMode() const override;
108  QXmppJinglePayloadType payloadType() const;
109  qint64 pos() const override;
110  bool seek(qint64 pos) override;
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() override;
147  qint64 readData(char *data, qint64 maxSize) override;
148  qint64 writeData(const char *data, qint64 maxSize) override;
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), m_frameSize(QSize(320, 240)), m_pixelFormat(QXmppVideoFrame::Format_YUYV)
214  {
215  }
216 
217  int frameHeight() const
218  {
219  return m_frameSize.height();
220  }
221 
222  int frameWidth() const
223  {
224  return m_frameSize.width();
225  }
226 
227  qreal frameRate() const
228  {
229  return m_frameRate;
230  }
231 
232  void setFrameRate(qreal frameRate)
233  {
234  m_frameRate = frameRate;
235  }
236 
237  QSize frameSize() const
238  {
239  return m_frameSize;
240  }
241 
242  void setFrameSize(const QSize &frameSize)
243  {
244  m_frameSize = frameSize;
245  }
246 
247  QXmppVideoFrame::PixelFormat pixelFormat() const
248  {
249  return m_pixelFormat;
250  }
251 
252  void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat)
253  {
254  m_pixelFormat = pixelFormat;
255  }
256 
257 private:
258  qreal m_frameRate;
259  QSize m_frameSize;
260  QXmppVideoFrame::PixelFormat m_pixelFormat;
261 };
262 
266 
267 class QXMPP_EXPORT QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
268 {
269  Q_OBJECT
270 
271 public:
272  QXmppRtpVideoChannel(QObject *parent = nullptr);
273  ~QXmppRtpVideoChannel() override;
274 
275  void close() override;
276  QIODevice::OpenMode openMode() const override;
277 
278  // incoming stream
279  QXmppVideoFormat decoderFormat() const;
280  QList<QXmppVideoFrame> readFrames();
281 
282  // outgoing stream
283  QXmppVideoFormat encoderFormat() const;
284  void setEncoderFormat(const QXmppVideoFormat &format);
285  void writeFrame(const QXmppVideoFrame &frame);
286 
287 signals:
289  void sendDatagram(const QByteArray &ba);
290 
291 public slots:
292  void datagramReceived(const QByteArray &ba);
293 
294 protected:
296  void payloadTypesChanged() override;
298 
299 private:
300  friend class QXmppRtpVideoChannelPrivate;
301  QXmppRtpVideoChannelPrivate *d;
302 };
303 
304 #endif
QXmppLogger::DebugMessage
Debugging message.
Definition: QXmppLogger.h:70
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:90
QXmppLogger::MessageType
MessageType
This enum describes a type of log message.
Definition: QXmppLogger.h:68
QXmppRtpAudioChannel::Tone_A
Tone for the A key.
Definition: QXmppRtpChannel.h:94
QXmppLogger::ReceivedMessage
Message received from server.
Definition: QXmppLogger.h:73
QXmppLogger::SentMessage
Message sent to server.
Definition: QXmppLogger.h:74
QXmppRtpAudioChannel::Tone_B
Tone for the B key.
Definition: QXmppRtpChannel.h:95
QXmppRtpAudioChannel::Tone_1
Tone for the 1 key.
Definition: QXmppRtpChannel.h:83
QXmppRtpVideoChannel
The QXmppRtpVideoChannel class represents an RTP video channel to a remote party.
Definition: QXmppRtpChannel.h:267
QXmppRtpAudioChannel::Tone_5
Tone for the 5 key.
Definition: QXmppRtpChannel.h:87
QXmppRtpAudioChannel::Tone_9
Tone for the 9 key.
Definition: QXmppRtpChannel.h:91
QXmppRtpAudioChannel::Tone_2
Tone for the 2 key.
Definition: QXmppRtpChannel.h:84
QXmppRtpAudioChannel::Tone_4
Tone for the 4 key.
Definition: QXmppRtpChannel.h:86
QXmppRtpAudioChannel::Tone_3
Tone for the 3 key.
Definition: QXmppRtpChannel.h:85
QXmppRtpAudioChannel::Tone_Pound
Tone for the # key.
Definition: QXmppRtpChannel.h:93
QXmppVideoFrame::PixelFormat
PixelFormat
This enum describes a pixel format.
Definition: QXmppRtpChannel.h:168
QXmppLogger::WarningMessage
Warning message.
Definition: QXmppLogger.h:72
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:96
QXmppRtpAudioChannel::Tone
Tone
This enum is used to describe a DTMF tone.
Definition: QXmppRtpChannel.h:81
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:123
QXmppRtpAudioChannel::Tone_Star
Tone for the * key.
Definition: QXmppRtpChannel.h:92
QXmppRtpAudioChannel::Tone_7
Tone for the 7 key.
Definition: QXmppRtpChannel.h:89
QXmppRtpAudioChannel::Tone_6
Tone for the 6 key.
Definition: QXmppRtpChannel.h:88
QXmppRtpAudioChannel
The QXmppRtpAudioChannel class represents an RTP audio channel to a remote party.
Definition: QXmppRtpChannel.h:75