5#include <QtCore/qcoreapplication.h>
13 , m_ownStream(ownStream)
14 , m_currentReadResult(0)
19 this->moveToThread(stream->thread());
24 if (m_currentReadResult)
25 m_currentReadResult->Release();
27 m_stream->deleteLater();
31STDMETHODIMP MFStream::GetCapabilities(DWORD *pdwCapabilities)
35 *pdwCapabilities = MFBYTESTREAM_IS_READABLE;
36 if (!m_stream->isSequential())
37 *pdwCapabilities |= MFBYTESTREAM_IS_SEEKABLE;
41STDMETHODIMP MFStream::GetLength(QWORD *pqwLength)
45 QMutexLocker locker(&m_mutex);
46 *pqwLength = QWORD(m_stream->size());
50STDMETHODIMP MFStream::SetLength(QWORD)
55STDMETHODIMP MFStream::GetCurrentPosition(QWORD *pqwPosition)
59 QMutexLocker locker(&m_mutex);
60 *pqwPosition = m_stream->pos();
64STDMETHODIMP MFStream::SetCurrentPosition(QWORD qwPosition)
66 QMutexLocker locker(&m_mutex);
70 if (m_currentReadResult)
73 bool seekOK = m_stream->seek(qint64(qwPosition));
80STDMETHODIMP MFStream::IsEndOfStream(BOOL *pfEndOfStream)
84 QMutexLocker locker(&m_mutex);
85 *pfEndOfStream = m_stream->atEnd() ? TRUE : FALSE;
89STDMETHODIMP MFStream::Read(BYTE *pb, ULONG cb, ULONG *pcbRead)
91 QMutexLocker locker(&m_mutex);
92 qint64 read = m_stream->read((
char*)(pb), qint64(cb));
94 *pcbRead = ULONG(read);
98STDMETHODIMP MFStream::BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback,
101 if (!pCallback || !pb)
104 Q_ASSERT(m_currentReadResult == NULL);
106 AsyncReadState *state =
new (std::nothrow) AsyncReadState(pb, cb);
108 return E_OUTOFMEMORY;
110 HRESULT hr = MFCreateAsyncResult(state, pCallback, punkState, &m_currentReadResult);
115 QCoreApplication::postEvent(
this,
new QEvent(QEvent::User));
119STDMETHODIMP MFStream::EndRead(IMFAsyncResult* pResult, ULONG *pcbRead)
124 pResult->GetObject(&pUnk);
125 AsyncReadState *state =
static_cast<AsyncReadState*>(pUnk);
126 *pcbRead = state->bytesRead();
129 m_currentReadResult->Release();
130 m_currentReadResult = NULL;
135STDMETHODIMP MFStream::Write(
const BYTE *, ULONG, ULONG *)
140STDMETHODIMP MFStream::BeginWrite(
const BYTE *, ULONG ,
147STDMETHODIMP MFStream::EndWrite(IMFAsyncResult *,
153STDMETHODIMP MFStream::Seek(
154 MFBYTESTREAM_SEEK_ORIGIN SeekOrigin,
155 LONGLONG llSeekOffset,
157 QWORD *pqwCurrentPosition)
159 QMutexLocker locker(&m_mutex);
160 if (m_currentReadResult)
163 qint64 pos = qint64(llSeekOffset);
164 switch (SeekOrigin) {
168 pos += m_stream->pos();
171 bool seekOK = m_stream->seek(pos);
172 if (pqwCurrentPosition)
173 *pqwCurrentPosition = pos;
180STDMETHODIMP MFStream::Flush()
185STDMETHODIMP MFStream::Close()
187 QMutexLocker locker(&m_mutex);
193void MFStream::doRead()
198 bool readDone =
true;
199 IUnknown *pUnk = NULL;
200 HRESULT hr = m_currentReadResult->GetObject(&pUnk);
203 AsyncReadState *state =
static_cast<AsyncReadState*>(pUnk);
205 Read(state->pb(), state->cb() - state->bytesRead(), &cbRead);
208 state->setBytesRead(cbRead + state->bytesRead());
209 if (state->cb() > state->bytesRead() && !m_stream->atEnd()) {
216 m_currentReadResult->SetStatus(hr);
217 MFInvokeCallback(m_currentReadResult);
221void MFStream::customEvent(QEvent *event)
223 if (event->type() != QEvent::User) {
224 QObject::customEvent(event);
233MFStream::AsyncReadState::AsyncReadState(BYTE *pb, ULONG cb)
241BYTE* MFStream::AsyncReadState::pb()
const
246ULONG MFStream::AsyncReadState::cb()
const
251ULONG MFStream::AsyncReadState::bytesRead()
const
256void MFStream::AsyncReadState::setBytesRead(ULONG cbRead)
263#include "moc_mfstream_p.cpp"
\inmodule QtCore \reentrant
Combined button and popup list for selecting options.