Go to the documentation of this file.00001 #pragma once
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <QtCore/Qt>
00028 #include <QtCore/QHash>
00029 #include <QtCore/QVariant>
00030
00031 namespace QStreamer
00032 {
00033 class QMediaBuffer
00034 {
00035 public:
00036 QMediaBuffer(quint64 size, quint32 type='unkn');
00037
00038 QMediaBuffer(quint8 *buffer, quint64 size, quint32 type='unkn');
00039
00040 virtual void reference();
00041
00042 virtual void release();
00043
00044 bool isValid() const;
00045
00046 quint32 type() const;
00047
00048 quint64 size() const;
00049
00050 quint64 length() const;
00051
00052 void setLength(quint64 length);
00053
00054 const quint8 *data() const;
00055
00056 quint8 *bufferStart();
00057
00058 const quint8 *bufferStart() const;
00059
00060 bool clipHead(quint64 count);
00061
00062 bool clipTail(quint64 count);
00063
00064 quint64 adjustedSize() const;
00065
00066 quint64 spaceRemaining() const;
00067
00068 void resetHead();
00069
00070 QVariant property(quint32 type) const;
00071
00072 void setProperty(quint32 type, const QVariant &value);
00073
00074 void clearProperties();
00075
00076 protected:
00077 virtual ~QMediaBuffer();
00078
00079 virtual void bufferReleased();
00080
00081 virtual void scheduleDelete();
00082
00083 private:
00084 quint32 m_referenceCounter;
00085 quint32 m_type;
00086 bool m_dataOwner;
00087 quint8 *m_data;
00088 quint8 *m_bufferStart;
00089 quint64 m_size;
00090 quint64 m_length;
00091
00092 QHash<quint32, QVariant>m_properties;
00093 };
00094
00095 inline QMediaBuffer::QMediaBuffer(quint64 size, quint32 type) :
00096 m_referenceCounter(0),
00097 m_type(type),
00098 m_size(0),
00099 m_dataOwner(true),
00100 m_data(0),
00101 m_bufferStart(0),
00102 m_length(0)
00103 {
00104 m_data = new quint8[size];
00105 if(m_data)
00106 {
00107 m_size = size;
00108 m_bufferStart = m_data;
00109 }
00110 }
00111
00112 inline QMediaBuffer::QMediaBuffer(quint8 *buffer, quint64 size, quint32 type) :
00113 m_referenceCounter(0),
00114 m_type(type),
00115 m_size(size),
00116 m_dataOwner(false),
00117 m_data(buffer),
00118 m_bufferStart(buffer),
00119 m_length(0)
00120 {
00121
00122 }
00123
00124 inline QMediaBuffer::~QMediaBuffer()
00125 {
00126 if(m_dataOwner)
00127 delete [] m_data;
00128 }
00129
00130 inline bool QMediaBuffer::isValid() const
00131 {
00132 return m_data ? true : false;
00133 }
00134
00135 inline void QMediaBuffer::reference()
00136 {
00137 m_referenceCounter++;
00138 }
00139
00140 inline void QMediaBuffer::release()
00141 {
00142 if(!m_referenceCounter)
00143 {
00144
00145 return;
00146 }
00147
00148 m_referenceCounter--;
00149 if(!m_referenceCounter)
00150 {
00151 scheduleDelete();
00152 }
00153 }
00154
00155 inline quint32 QMediaBuffer::type() const
00156 {
00157 return m_type;
00158 }
00159
00160 inline quint64 QMediaBuffer::size() const
00161 {
00162 return m_size;
00163 }
00164
00165 inline quint64 QMediaBuffer::length() const
00166 {
00167 return m_length;
00168 }
00169
00170 inline void QMediaBuffer::setLength(quint64 length)
00171 {
00172
00173 m_length = length;
00174 }
00175
00176 inline const quint8 *QMediaBuffer::data() const
00177 {
00178 return m_data;
00179 }
00180
00181 inline quint8 *QMediaBuffer::bufferStart()
00182 {
00183 return m_bufferStart;
00184 }
00185
00186 inline const quint8 *QMediaBuffer::bufferStart() const
00187 {
00188 return m_bufferStart;
00189 }
00190
00191 inline bool QMediaBuffer::clipHead(quint64 count)
00192 {
00193 if(m_length < count)
00194 {
00195
00196 return false;
00197 }
00198 m_bufferStart += count;
00199 m_length -= count;
00200 }
00201
00202 inline bool QMediaBuffer::clipTail(quint64 count)
00203 {
00204 if(m_length < count)
00205 {
00206
00207 return false;
00208 }
00209
00210 m_length -= count;
00211 }
00212
00213 inline quint64 QMediaBuffer::adjustedSize() const
00214 {
00215 return m_size - (m_bufferStart - m_data);
00216 }
00217
00218 inline quint64 QMediaBuffer::spaceRemaining() const
00219 {
00220 return adjustedSize() - m_length;
00221 }
00222
00223 inline void QMediaBuffer::resetHead()
00224 {
00225 quint64 difference = m_bufferStart - m_data;
00226 if(difference)
00227 {
00228 m_length += difference;
00229 m_bufferStart = m_data;
00230 }
00231 }
00232
00233 inline void QMediaBuffer::bufferReleased()
00234 {
00235 }
00236
00237 inline void QMediaBuffer::scheduleDelete()
00238 {
00239 delete this;
00240 }
00241
00242 inline QVariant QMediaBuffer::property(quint32 type) const
00243 {
00244 return m_properties[type];
00245 }
00246
00247 inline void QMediaBuffer::setProperty(quint32 type, const QVariant &value)
00248 {
00249 m_properties[type] = value;
00250 }
00251
00252 inline void QMediaBuffer::clearProperties()
00253 {
00254 m_properties.clear();
00255 }
00256 }