QXmpp  Version:0.9.1
QXmppRtpChannel.h
1 /*
2  * Copyright (C) 2008-2014 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  int frameHeight() const {
213  return m_frameSize.height();
214  }
215 
216  int frameWidth() const {
217  return m_frameSize.width();
218  }
219 
220  qreal frameRate() const {
221  return m_frameRate;
222  }
223 
224  void setFrameRate(qreal frameRate) {
225  m_frameRate = frameRate;
226  }
227 
228  QSize frameSize() const {
229  return m_frameSize;
230  }
231 
232  void setFrameSize(const QSize &frameSize) {
233  m_frameSize = frameSize;
234  }
235 
236  QXmppVideoFrame::PixelFormat pixelFormat() const {
237  return m_pixelFormat;
238  }
239 
240  void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) {
241  m_pixelFormat = pixelFormat;
242  }
243 
244 private:
245  qreal m_frameRate;
246  QSize m_frameSize;
247  QXmppVideoFrame::PixelFormat m_pixelFormat;
248 };
249 
250 
254 
255 class QXMPP_EXPORT QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
256 {
257  Q_OBJECT
258 
259 public:
260  QXmppRtpVideoChannel(QObject *parent = 0);
262 
263  void close();
264  QIODevice::OpenMode openMode() const;
265 
266  // incoming stream
267  QXmppVideoFormat decoderFormat() const;
268  QList<QXmppVideoFrame> readFrames();
269 
270  // outgoing stream
271  QXmppVideoFormat encoderFormat() const;
272  void setEncoderFormat(const QXmppVideoFormat &format);
273  void writeFrame(const QXmppVideoFrame &frame);
274 
275 signals:
277  void sendDatagram(const QByteArray &ba);
278 
279 public slots:
280  void datagramReceived(const QByteArray &ba);
281 
282 protected:
284  void payloadTypesChanged();
286 
287 private:
288  friend class QXmppRtpVideoChannelPrivate;
289  QXmppRtpVideoChannelPrivate * d;
290 };
291 
292 #endif
Tone for the 7 key.
Definition: QXmppRtpChannel.h:90
Tone for the 6 key.
Definition: QXmppRtpChannel.h:89
Tone for the B key.
Definition: QXmppRtpChannel.h:96
Tone for the A key.
Definition: QXmppRtpChannel.h:95
Tone
This enum is used to describe a DTMF tone.
Definition: QXmppRtpChannel.h:82
Tone for the 8 key.
Definition: QXmppRtpChannel.h:91
The QXmppJinglePayloadType class represents a payload type as specified by XEP-0167: Jingle RTP Sessi...
Definition: QXmppJingleIq.h:37
Message received from server.
Definition: QXmppLogger.h:71
Tone for the 1 key.
Definition: QXmppRtpChannel.h:84
Debugging message.
Definition: QXmppLogger.h:68
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:111
Tone for the 3 key.
Definition: QXmppRtpChannel.h:86
Tone for the 4 key.
Definition: QXmppRtpChannel.h:87
Tone for the 5 key.
Definition: QXmppRtpChannel.h:88
Tone for the # key.
Definition: QXmppRtpChannel.h:94
Warning message.
Definition: QXmppLogger.h:70
Tone for the 9 key.
Definition: QXmppRtpChannel.h:92
Message sent to server.
Definition: QXmppLogger.h:72
The QXmppRtpAudioChannel class represents an RTP audio channel to a remote party. ...
Definition: QXmppRtpChannel.h:75
Tone for the 2 key.
Definition: QXmppRtpChannel.h:85
MessageType
This enum describes a type of log message.
Definition: QXmppLogger.h:65
Tone for the * key.
Definition: QXmppRtpChannel.h:93
PixelFormat
This enum describes a pixel format.
Definition: QXmppRtpChannel.h:168
The QXmppRtpVideoChannel class represents an RTP video channel to a remote party. ...
Definition: QXmppRtpChannel.h:255
The QXmppVideoFrame class provides a representation of a frame of video data.
Definition: QXmppRtpChannel.h:164
Tone for the C key.
Definition: QXmppRtpChannel.h:97