qtmobility/plugins/multimedia/directshow/player/directshowiosource.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    43 
    43 
    44 #include "directshowglobal.h"
    44 #include "directshowglobal.h"
    45 #include "directshowmediatype.h"
    45 #include "directshowmediatype.h"
    46 #include "directshowpinenum.h"
    46 #include "directshowpinenum.h"
    47 
    47 
       
    48 #include <QtCore/qcoreapplication.h>
       
    49 #include <QtCore/qurl.h>
    48 
    50 
    49 static const GUID directshow_subtypes[] =
    51 static const GUID directshow_subtypes[] =
    50 {
    52 {
    51     MEDIASUBTYPE_Avi,
    53     MEDIASUBTYPE_Avi,
    52     MEDIASUBTYPE_WAVE,
    54     MEDIASUBTYPE_WAVE,
    53     MEDIASUBTYPE_NULL
    55     MEDIASUBTYPE_NULL
    54 };
    56 };
    55 
    57 
    56 DirectShowIOSource::DirectShowIOSource(QIODevice *device, DirectShowEventLoop *loop)
    58 DirectShowIOSource::DirectShowIOSource(DirectShowEventLoop *loop)
    57     : m_ref(1)
    59     : m_ref(1)
    58     , m_state(State_Stopped)
    60     , m_state(State_Stopped)
       
    61     , m_reader(0)
       
    62     , m_loop(loop)
    59     , m_graph(0)
    63     , m_graph(0)
    60     , m_clock(0)
    64     , m_clock(0)
    61     , m_allocator(0)
    65     , m_allocator(0)
    62     , m_peerPin(0)
    66     , m_peerPin(0)
    63     , m_pinId(QLatin1String("Data"))
    67     , m_pinId(QLatin1String("Data"))
    64     , m_reader(device, this, loop)
       
    65 {
    68 {
    66     QVector<AM_MEDIA_TYPE> mediaTypes;
    69     QVector<AM_MEDIA_TYPE> mediaTypes;
    67 
    70 
    68     AM_MEDIA_TYPE type =
    71     AM_MEDIA_TYPE type =
    69     {
    72     {
    89 }
    92 }
    90 
    93 
    91 DirectShowIOSource::~DirectShowIOSource()
    94 DirectShowIOSource::~DirectShowIOSource()
    92 {
    95 {
    93     Q_ASSERT(m_ref == 0);
    96     Q_ASSERT(m_ref == 0);
       
    97 
       
    98     delete m_reader;
       
    99 }
       
   100 
       
   101 void DirectShowIOSource::setDevice(QIODevice *device)
       
   102 {
       
   103     Q_ASSERT(!m_reader);
       
   104 
       
   105     m_reader = new DirectShowIOReader(device, this, m_loop);
    94 }
   106 }
    95 
   107 
    96 void DirectShowIOSource::setAllocator(IMemAllocator *allocator)
   108 void DirectShowIOSource::setAllocator(IMemAllocator *allocator)
    97 {
   109 {
    98     if (m_allocator)
   110     if (m_allocator)
   105 }
   117 }
   106 
   118 
   107 // IUnknown
   119 // IUnknown
   108 HRESULT DirectShowIOSource::QueryInterface(REFIID riid, void **ppvObject)
   120 HRESULT DirectShowIOSource::QueryInterface(REFIID riid, void **ppvObject)
   109 {
   121 {
       
   122     // 2dd74950-a890-11d1-abe8-00a0c905f375
       
   123     static const GUID iid_IAmFilterMiscFlags = {
       
   124         0x2dd74950, 0xa890, 0x11d1, {0xab, 0xe8, 0x00, 0xa0, 0xc9, 0x05, 0xf3, 0x75}};
       
   125 
   110     if (!ppvObject) {
   126     if (!ppvObject) {
   111         return E_POINTER;
   127         return E_POINTER;
   112     } else if (riid == IID_IUnknown
   128     } else if (riid == IID_IUnknown
   113             || riid == IID_IPersist
   129             || riid == IID_IPersist
   114             || riid == IID_IMediaFilter
   130             || riid == IID_IMediaFilter
   115             || riid == IID_IBaseFilter) {
   131             || riid == IID_IBaseFilter) {
   116         *ppvObject = static_cast<IBaseFilter *>(this);
   132         *ppvObject = static_cast<IBaseFilter *>(this);
   117     } else if (riid == IID_IAMFilterMiscFlags) {
   133     } else if (riid == iid_IAmFilterMiscFlags) {
   118         *ppvObject = static_cast<IAMFilterMiscFlags *>(this);
   134         *ppvObject = static_cast<IAMFilterMiscFlags *>(this);
   119     } else if (riid == IID_IPin) {
   135     } else if (riid == IID_IPin) {
   120         *ppvObject = static_cast<IPin *>(this);
   136         *ppvObject = static_cast<IPin *>(this);
   121     } else if (riid == IID_IAsyncReader) {
   137     } else if (riid == IID_IAsyncReader) {
   122         *ppvObject = static_cast<IAsyncReader *>(&m_reader);
   138         *ppvObject = static_cast<IAsyncReader *>(m_reader);
   123     } else {
   139     } else {
   124         *ppvObject = 0;
   140         *ppvObject = 0;
   125 
   141 
   126         return E_NOINTERFACE;
   142         return E_NOINTERFACE;
   127     }
   143     }
   398             m_allocator = 0;
   414             m_allocator = 0;
   399         }
   415         }
   400     } else if (!m_allocator) {
   416     } else if (!m_allocator) {
   401         hr = VFW_E_NO_TRANSPORT;
   417         hr = VFW_E_NO_TRANSPORT;
   402 
   418 
   403         if (IMemInputPin *memPin = com_cast<IMemInputPin>(pin)) {
   419         if (IMemInputPin *memPin = com_cast<IMemInputPin>(pin, IID_IMemInputPin)) {
   404             if ((m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator))) {
   420             if ((m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator, IID_IMemAllocator))) {
   405                 ALLOCATOR_PROPERTIES properties;
   421                 ALLOCATOR_PROPERTIES properties;
   406                 if (memPin->GetAllocatorRequirements(&properties) == S_OK
   422                 if (memPin->GetAllocatorRequirements(&properties) == S_OK
   407                         || m_allocator->GetProperties(&properties) == S_OK) {
   423                         || m_allocator->GetProperties(&properties) == S_OK) {
   408                     if (properties.cbAlign == 0)
   424                     if (properties.cbAlign == 0)
   409                         properties.cbAlign = 1;
   425                         properties.cbAlign = 1;
   567     return S_OK;
   583     return S_OK;
   568 }
   584 }
   569 
   585 
   570 HRESULT DirectShowIOSource::BeginFlush()
   586 HRESULT DirectShowIOSource::BeginFlush()
   571 {
   587 {
   572     return m_reader.BeginFlush();
   588     return m_reader->BeginFlush();
   573 }
   589 }
   574 
   590 
   575 HRESULT DirectShowIOSource::EndFlush()
   591 HRESULT DirectShowIOSource::EndFlush()
   576 {
   592 {
   577     return m_reader.EndFlush();
   593     return m_reader->EndFlush();
   578 }
   594 }
   579 
   595 
   580 HRESULT DirectShowIOSource::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
   596 HRESULT DirectShowIOSource::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
   581 {
   597 {
   582     Q_UNUSED(tStart);
   598     Q_UNUSED(tStart);
   595 
   611 
   596         return S_OK;
   612         return S_OK;
   597     }
   613     }
   598 }
   614 }
   599 
   615 
       
   616 DirectShowRcSource::DirectShowRcSource(DirectShowEventLoop *loop)
       
   617     : DirectShowIOSource(loop)
       
   618 {
       
   619 }
       
   620 
       
   621 bool DirectShowRcSource::open(const QUrl &url)
       
   622 {
       
   623     m_file.moveToThread(QCoreApplication::instance()->thread());
       
   624 
       
   625     m_file.setFileName(QLatin1Char(':') + url.path());
       
   626 
       
   627     qDebug("qrc file %s", qPrintable(m_file.fileName()));
       
   628 
       
   629     if (m_file.open(QIODevice::ReadOnly)) {
       
   630         qDebug("Size %d", m_file.size());
       
   631         qDebug("Sequential %d", int(m_file.isSequential()));
       
   632 
       
   633         setDevice(&m_file);
       
   634 
       
   635         return true;
       
   636     } else {
       
   637         return false;
       
   638     }
       
   639 }