qtmobility/plugins/multimedia/directshow/player/directshowioreader.h
changeset 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef DIRECTSHOWIOREADER_H
       
    43 #define DIRECTSHOWIOREADER_H
       
    44 
       
    45 #include <QtCore/qmutex.h>
       
    46 #include <QtCore/qobject.h>
       
    47 #include <QtCore/qwaitcondition.h>
       
    48 
       
    49 #include <dshow.h>
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 class QIODevice;
       
    53 QT_END_NAMESPACE
       
    54 
       
    55 class DirectShowEventLoop;
       
    56 class DirectShowIOSource;
       
    57 class DirectShowSampleRequest;
       
    58 
       
    59 class DirectShowIOReader : public QObject, public IAsyncReader
       
    60 {
       
    61     Q_OBJECT
       
    62 public:
       
    63     DirectShowIOReader(QIODevice *device, DirectShowIOSource *source, DirectShowEventLoop *loop);
       
    64     ~DirectShowIOReader();
       
    65 
       
    66     // IUnknown
       
    67     HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
       
    68     ULONG STDMETHODCALLTYPE AddRef();
       
    69     ULONG STDMETHODCALLTYPE Release();
       
    70 
       
    71     // IAsyncReader
       
    72     HRESULT STDMETHODCALLTYPE RequestAllocator(
       
    73             IMemAllocator *pPreferred, ALLOCATOR_PROPERTIES *pProps, IMemAllocator **ppActual);
       
    74 
       
    75     HRESULT STDMETHODCALLTYPE Request(IMediaSample *pSample, DWORD_PTR dwUser);
       
    76 
       
    77     HRESULT STDMETHODCALLTYPE WaitForNext(
       
    78             DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser);
       
    79 
       
    80     HRESULT STDMETHODCALLTYPE SyncReadAligned(IMediaSample *pSample);
       
    81 
       
    82     HRESULT STDMETHODCALLTYPE SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer);
       
    83 
       
    84     HRESULT STDMETHODCALLTYPE Length(LONGLONG *pTotal, LONGLONG *pAvailable);
       
    85 
       
    86     HRESULT STDMETHODCALLTYPE BeginFlush();
       
    87     HRESULT STDMETHODCALLTYPE EndFlush();
       
    88 
       
    89 protected:
       
    90     void customEvent(QEvent *event);
       
    91 
       
    92 private Q_SLOTS:
       
    93     void readyRead();
       
    94 
       
    95 private:
       
    96     HRESULT blockingRead(LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead);
       
    97     bool nonBlockingRead(
       
    98             LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead, HRESULT *result);
       
    99     void flushRequests();
       
   100 
       
   101     DirectShowIOSource *m_source;
       
   102     QIODevice *m_device;
       
   103     DirectShowEventLoop *m_loop;
       
   104     DirectShowSampleRequest *m_pendingHead;
       
   105     DirectShowSampleRequest *m_pendingTail;
       
   106     DirectShowSampleRequest *m_readyHead;
       
   107     DirectShowSampleRequest *m_readyTail;
       
   108     LONGLONG m_synchronousPosition;
       
   109     LONG m_synchronousLength;
       
   110     qint64 m_synchronousBytesRead;
       
   111     BYTE *m_synchronousBuffer;
       
   112     HRESULT m_synchronousResult;
       
   113     LONGLONG m_totalLength;
       
   114     LONGLONG m_availableLength;
       
   115     bool m_flushing;
       
   116     QMutex m_mutex;
       
   117     QWaitCondition m_wait;
       
   118 };
       
   119 
       
   120 #endif