QXmppCodec_p.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #ifndef QXMPPCODEC_H
  24. #define QXMPPCODEC_H
  25. #include <QMap>
  26. #include "QXmppGlobal.h"
  27. class QXmppRtpPacket;
  28. class QXmppVideoFormat;
  29. class QXmppVideoFrame;
  30. /// \brief The QXmppCodec class is the base class for audio codecs capable of
  31. /// encoding and decoding audio samples.
  32. ///
  33. /// Samples must be 16-bit little endian.
  34. class QXMPP_AUTOTEST_EXPORT QXmppCodec
  35. {
  36. public:
  37. virtual ~QXmppCodec();
  38. /// Reads samples from the input stream, encodes them and writes the
  39. /// encoded data to the output stream.
  40. virtual qint64 encode(QDataStream &input, QDataStream &output) = 0;
  41. /// Reads encoded data from the input stream, decodes it and writes the
  42. /// decoded samples to the output stream.
  43. virtual qint64 decode(QDataStream &input, QDataStream &output) = 0;
  44. };
  45. /// \internal
  46. ///
  47. /// The QXmppG711aCodec class represent a G.711 a-law PCM codec.
  48. class QXmppG711aCodec : public QXmppCodec
  49. {
  50. public:
  51. QXmppG711aCodec(int clockrate);
  52. qint64 encode(QDataStream &input, QDataStream &output);
  53. qint64 decode(QDataStream &input, QDataStream &output);
  54. private:
  55. int m_frequency;
  56. };
  57. /// \internal
  58. ///
  59. /// The QXmppG711uCodec class represent a G.711 u-law PCM codec.
  60. class QXmppG711uCodec : public QXmppCodec
  61. {
  62. public:
  63. QXmppG711uCodec(int clockrate);
  64. qint64 encode(QDataStream &input, QDataStream &output);
  65. qint64 decode(QDataStream &input, QDataStream &output);
  66. private:
  67. int m_frequency;
  68. };
  69. #ifdef QXMPP_USE_SPEEX
  70. typedef struct SpeexBits SpeexBits;
  71. /// \internal
  72. ///
  73. /// The QXmppSpeexCodec class represent a SPEEX codec.
  74. class QXMPP_AUTOTEST_EXPORT QXmppSpeexCodec : public QXmppCodec
  75. {
  76. public:
  77. QXmppSpeexCodec(int clockrate);
  78. ~QXmppSpeexCodec();
  79. qint64 encode(QDataStream &input, QDataStream &output);
  80. qint64 decode(QDataStream &input, QDataStream &output);
  81. private:
  82. SpeexBits *encoder_bits;
  83. void *encoder_state;
  84. SpeexBits *decoder_bits;
  85. void *decoder_state;
  86. int frame_samples;
  87. };
  88. #endif
  89. /// \brief The QXmppVideoDecoder class is the base class for video decoders.
  90. ///
  91. class QXMPP_AUTOTEST_EXPORT QXmppVideoDecoder
  92. {
  93. public:
  94. virtual ~QXmppVideoDecoder();
  95. /// Returns the format of the video stream.
  96. virtual QXmppVideoFormat format() const = 0;
  97. /// Handles an RTP \a packet and returns a list of decoded video frames.
  98. virtual QList<QXmppVideoFrame> handlePacket(const QXmppRtpPacket &packet) = 0;
  99. /// Sets the video stream's \a parameters.
  100. virtual bool setParameters(const QMap<QString, QString> &parameters) = 0;
  101. };
  102. /// \brief The QXmppVideoEncoder class is the base class for video encoders.
  103. ///
  104. class QXMPP_AUTOTEST_EXPORT QXmppVideoEncoder
  105. {
  106. public:
  107. virtual ~QXmppVideoEncoder();
  108. /// Sets the \a format of the video stream.
  109. virtual bool setFormat(const QXmppVideoFormat &format) = 0;
  110. /// Handles a video \a frame and returns a list of RTP packet payloads.
  111. virtual QList<QByteArray> handleFrame(const QXmppVideoFrame &frame) = 0;
  112. /// Returns the video stream's parameters.
  113. virtual QMap<QString, QString> parameters() const = 0;
  114. };
  115. #ifdef QXMPP_USE_THEORA
  116. class QXmppTheoraDecoderPrivate;
  117. class QXmppTheoraEncoderPrivate;
  118. class QXMPP_AUTOTEST_EXPORT QXmppTheoraDecoder : public QXmppVideoDecoder
  119. {
  120. public:
  121. QXmppTheoraDecoder();
  122. ~QXmppTheoraDecoder();
  123. QXmppVideoFormat format() const;
  124. QList<QXmppVideoFrame> handlePacket(const QXmppRtpPacket &packet);
  125. bool setParameters(const QMap<QString, QString> &parameters);
  126. private:
  127. QXmppTheoraDecoderPrivate *d;
  128. };
  129. class QXMPP_AUTOTEST_EXPORT QXmppTheoraEncoder : public QXmppVideoEncoder
  130. {
  131. public:
  132. QXmppTheoraEncoder();
  133. ~QXmppTheoraEncoder();
  134. bool setFormat(const QXmppVideoFormat &format);
  135. QList<QByteArray> handleFrame(const QXmppVideoFrame &frame);
  136. QMap<QString, QString> parameters() const;
  137. private:
  138. QXmppTheoraEncoderPrivate *d;
  139. };
  140. #endif
  141. #ifdef QXMPP_USE_VPX
  142. class QXmppVpxDecoderPrivate;
  143. class QXmppVpxEncoderPrivate;
  144. class QXMPP_AUTOTEST_EXPORT QXmppVpxDecoder : public QXmppVideoDecoder
  145. {
  146. public:
  147. QXmppVpxDecoder();
  148. ~QXmppVpxDecoder();
  149. QXmppVideoFormat format() const;
  150. QList<QXmppVideoFrame> handlePacket(const QXmppRtpPacket &packet);
  151. bool setParameters(const QMap<QString, QString> &parameters);
  152. private:
  153. QXmppVpxDecoderPrivate *d;
  154. };
  155. class QXMPP_AUTOTEST_EXPORT QXmppVpxEncoder : public QXmppVideoEncoder
  156. {
  157. public:
  158. QXmppVpxEncoder();
  159. ~QXmppVpxEncoder();
  160. bool setFormat(const QXmppVideoFormat &format);
  161. QList<QByteArray> handleFrame(const QXmppVideoFrame &frame);
  162. QMap<QString, QString> parameters() const;
  163. private:
  164. QXmppVpxEncoderPrivate *d;
  165. };
  166. #endif
  167. #endif