QXmpp: QXmppRtpChannel.h Source File

QXmpp Version:0.7.5

- Main Page
- Modules
- Classes
- Files

- File List

All Classes Functions Variables Enumerations Enumerator Properties Groups
QXmppRtpChannel.h
1 /*
2 * Copyright (C) 2008-2012 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;
34 class QXmppJinglePayloadType;
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
49 quint8 version;
51 bool marker;
53 quint8 type;
55 quint32 ssrc;
57 QList<quint32> csrc;
59 quint16 sequence;
61 quint32 stamp;
63 QByteArray payload;
64 };
65
66 class QXMPP_EXPORT QXmppRtpChannel
67 {
68 public:
69 QXmppRtpChannel();
70
72 virtual void close() = 0;
73
75 virtual QIODevice::OpenMode openMode() const = 0;
76
77 QList<QXmppJinglePayloadType> localPayloadTypes();
78 void setRemotePayloadTypes(const QList<QXmppJinglePayloadType> &remotePayloadTypes);
79
80 protected:
82 virtual void payloadTypesChanged() = 0;
83
84 QList<QXmppJinglePayloadType> m_incomingPayloadTypes;
85 QList<QXmppJinglePayloadType> m_outgoingPayloadTypes;
86 bool m_outgoingPayloadNumbered;
88 };
89
96
97 class QXMPP_EXPORT QXmppRtpAudioChannel : public QIODevice, public QXmppRtpChannel
98 {
99 Q_OBJECT
100 Q_ENUMS(Tone)
101
102 public:
104 enum Tone {
105 Tone_0 = 0,
106 Tone_1,
107 Tone_2,
108 Tone_3,
109 Tone_4,
110 Tone_5,
111 Tone_6,
112 Tone_7,
113 Tone_8,
114 Tone_9,
115 Tone_Star,
116 Tone_Pound,
117 Tone_A,
118 Tone_B,
119 Tone_C,
120 Tone_D
121 };
122
123 QXmppRtpAudioChannel(QObject *parent = 0);
124 ~QXmppRtpAudioChannel();
125
126 qint64 bytesAvailable() const;
127 void close();
128 bool isSequential() const;
129 QIODevice::OpenMode openMode() const;
130 QXmppJinglePayloadType payloadType() const;
131 qint64 pos() const;
132 bool seek(qint64 pos);
133
134 signals:
136 void sendDatagram(const QByteArray &ba);
137
139 void logMessage(QXmppLogger::MessageType type, const QString &msg);
140
141 public slots:
142 void datagramReceived(const QByteArray &ba);
143 void startTone(QXmppRtpAudioChannel::Tone tone);
144 void stopTone(QXmppRtpAudioChannel::Tone tone);
145
146 protected:
148 void debug(const QString &message)
149 {
150 emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
151 }
152
153 void warning(const QString &message)
154 {
155 emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
156 }
157
158 void logReceived(const QString &message)
159 {
160 emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
161 }
162
163 void logSent(const QString &message)
164 {
165 emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
166 }
167
168 void payloadTypesChanged();
169 qint64 readData(char * data, qint64 maxSize);
170 qint64 writeData(const char * data, qint64 maxSize);
172
173 private slots:
174 void emitSignals();
175 void writeDatagram();
176
177 private:
178 friend class QXmppRtpAudioChannelPrivate;
179 QXmppRtpAudioChannelPrivate * d;
180 };
181
185
186 class QXMPP_EXPORT QXmppVideoFrame
187 {
188 public:
190 enum PixelFormat {
191 Format_Invalid = 0,
192 Format_RGB32 = 3,
193 Format_RGB24 = 4,
194 Format_YUV420P = 18,
195
196
197
198 Format_UYVY = 20,
199
200
201
202
203 Format_YUYV = 21,
204
205
206
207
208 };
209
210 QXmppVideoFrame();
211 QXmppVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
212 uchar *bits();
213 const uchar *bits() const;
214 int bytesPerLine() const;
215 int height() const;
216 bool isValid() const;
217 int mappedBytes() const;
218 PixelFormat pixelFormat() const;
219 QSize size() const;
220 int width() const;
221
222 private:
223 int m_bytesPerLine;
224 QByteArray m_data;
225 int m_height;
226 int m_mappedBytes;
227 PixelFormat m_pixelFormat;
228 int m_width;
229 };
230
231 class QXMPP_EXPORT QXmppVideoFormat
232 {
233 public:
234 int frameHeight() const {
235 return m_frameSize.height();
236 }
237
238 int frameWidth() const {
239 return m_frameSize.width();
240 }
241
242 qreal frameRate() const {
243 return m_frameRate;
244 }
245
246 void setFrameRate(qreal frameRate) {
247 m_frameRate = frameRate;
248 }
249
250 QSize frameSize() const {
251 return m_frameSize;
252 }
253
254 void setFrameSize(const QSize &frameSize) {
255 m_frameSize = frameSize;
256 }
257
258 QXmppVideoFrame::PixelFormat pixelFormat() const {
259 return m_pixelFormat;
260 }
261
262 void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) {
263 m_pixelFormat = pixelFormat;
264 }
265
266 private:
267 qreal m_frameRate;
268 QSize m_frameSize;
269 QXmppVideoFrame::PixelFormat m_pixelFormat;
270 };
271
272
276
277 class QXMPP_EXPORT QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
278 {
279 Q_OBJECT
280
281 public:
282 QXmppRtpVideoChannel(QObject *parent = 0);
283 ~QXmppRtpVideoChannel();
284
285 void close();
286 QIODevice::OpenMode openMode() const;
287
288 // incoming stream
289 QXmppVideoFormat decoderFormat() const;
290 QList<QXmppVideoFrame> readFrames();
291
292 // outgoing stream
293 QXmppVideoFormat encoderFormat() const;
294 void setEncoderFormat(const QXmppVideoFormat &format);
295 void writeFrame(const QXmppVideoFrame &frame);
296
297 signals:
299 void sendDatagram(const QByteArray &ba);
300
301 public slots:
302 void datagramReceived(const QByteArray &ba);
303
304 protected:
306 void payloadTypesChanged();
308
309 private:
310 friend class QXmppRtpVideoChannelPrivate;
311 QXmppRtpVideoChannelPrivate * d;
312 };
313
314 #endif