QXmpp  Version:0.4.91
 All Classes Functions Enumerations Enumerator Properties Groups
QXmppRtpChannel.h
1 /*
2  * Copyright (C) 2008-2011 The QXmpp developers
3  *
4  * Author:
5  * Jeremy LainĂ©
6  *
7  * Source:
8  * http://code.google.com/p/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 
40 
41 class QXMPP_EXPORT QXmppRtpPacket
42 {
43 public:
44  bool decode(const QByteArray &ba);
45  QByteArray encode() const;
46  QString toString() const;
47 
48  quint8 version;
49  bool marker;
50  quint8 type;
51  quint32 ssrc;
52  QList<quint32> csrc;
53  quint16 sequence;
54  quint32 stamp;
55  QByteArray payload;
56 };
57 
58 class QXMPP_EXPORT QXmppRtpChannel
59 {
60 public:
61  QXmppRtpChannel();
62 
63  virtual void close() = 0;
64  virtual QIODevice::OpenMode openMode() const = 0;
65  QList<QXmppJinglePayloadType> localPayloadTypes();
66  void setRemotePayloadTypes(const QList<QXmppJinglePayloadType> &remotePayloadTypes);
67 
68 protected:
69  virtual void payloadTypesChanged();
70 
71  QList<QXmppJinglePayloadType> m_incomingPayloadTypes;
72  QList<QXmppJinglePayloadType> m_outgoingPayloadTypes;
73  bool m_outgoingPayloadNumbered;
74 };
75 
82 
83 class QXMPP_EXPORT QXmppRtpAudioChannel : public QIODevice, public QXmppRtpChannel
84 {
85  Q_OBJECT
86  Q_ENUMS(Tone)
87 
88 public:
90  enum Tone {
91  Tone_0 = 0,
106  Tone_D
107  };
108 
109  QXmppRtpAudioChannel(QObject *parent = 0);
111 
112  QXmppJinglePayloadType payloadType() const;
113 
115  qint64 bytesAvailable() const;
116  void close();
117  bool isSequential() const;
118  QIODevice::OpenMode openMode() const;
119  qint64 pos() const;
120  bool seek(qint64 pos);
122 
123 signals:
125  void sendDatagram(const QByteArray &ba);
126 
128  void logMessage(QXmppLogger::MessageType type, const QString &msg);
129 
130 public slots:
131  void datagramReceived(const QByteArray &ba);
132  void startTone(QXmppRtpAudioChannel::Tone tone);
133  void stopTone(QXmppRtpAudioChannel::Tone tone);
134 
135 protected:
137  void debug(const QString &message)
138  {
139  emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
140  }
141 
142  void warning(const QString &message)
143  {
144  emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
145  }
146 
147  void logReceived(const QString &message)
148  {
149  emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
150  }
151 
152  void logSent(const QString &message)
153  {
154  emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
155  }
156 
157  void payloadTypesChanged();
158  qint64 readData(char * data, qint64 maxSize);
159  qint64 writeData(const char * data, qint64 maxSize);
161 
162 private slots:
163  void emitSignals();
164  void writeDatagram();
165 
166 private:
167  friend class QXmppRtpAudioChannelPrivate;
168  QXmppRtpAudioChannelPrivate * d;
169 };
170 
174 
175 class QXMPP_EXPORT QXmppVideoFrame
176 {
177 public:
178  enum PixelFormat {
179  Format_Invalid = 0,
180  Format_RGB32 = 3,
181  Format_RGB24 = 4,
182  Format_YUV420P = 18,
183  Format_UYVY = 20,
184  Format_YUYV = 21,
185  };
186 
187  QXmppVideoFrame();
188  QXmppVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
189  uchar *bits();
190  const uchar *bits() const;
191  int bytesPerLine() const;
192  int height() const;
193  bool isValid() const;
194  int mappedBytes() const;
195  PixelFormat pixelFormat() const;
196  QSize size() const;
197  int width() const;
198 
199 private:
200  int m_bytesPerLine;
201  QByteArray m_data;
202  int m_height;
203  int m_mappedBytes;
204  PixelFormat m_pixelFormat;
205  int m_width;
206 };
207 
208 class QXMPP_EXPORT QXmppVideoFormat
209 {
210 public:
211  int frameHeight() const {
212  return m_frameSize.height();
213  }
214 
215  int frameWidth() const {
216  return m_frameSize.width();
217  }
218 
219  qreal frameRate() const {
220  return m_frameRate;
221  }
222 
223  void setFrameRate(qreal frameRate) {
224  m_frameRate = frameRate;
225  }
226 
227  QSize frameSize() const {
228  return m_frameSize;
229  }
230 
231  void setFrameSize(const QSize &frameSize) {
232  m_frameSize = frameSize;
233  }
234 
235  QXmppVideoFrame::PixelFormat pixelFormat() const {
236  return m_pixelFormat;
237  }
238 
239  void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) {
240  m_pixelFormat = pixelFormat;
241  }
242 
243 private:
244  qreal m_frameRate;
245  QSize m_frameSize;
246  QXmppVideoFrame::PixelFormat m_pixelFormat;
247 };
248 
249 
253 
254 class QXMPP_EXPORT QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
255 {
256  Q_OBJECT
257 
258 public:
259  QXmppRtpVideoChannel(QObject *parent = 0);
261 
262  // incoming stream
263  QXmppVideoFormat decoderFormat() const;
264  QList<QXmppVideoFrame> readFrames();
265 
266  // outgoing stream
267  QXmppVideoFormat encoderFormat() const;
268  void setEncoderFormat(const QXmppVideoFormat &format);
269  void writeFrame(const QXmppVideoFrame &frame);
270 
271  QIODevice::OpenMode openMode() const;
272  void close();
273 
274 signals:
276  void sendDatagram(const QByteArray &ba);
277 
278 public slots:
279  void datagramReceived(const QByteArray &ba);
280 
281 protected:
283  void payloadTypesChanged();
285 
286 private:
287  friend class QXmppRtpVideoChannelPrivate;
288  QXmppRtpVideoChannelPrivate * d;
289 };
290 
291 #endif