diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-02-11 03:26:31 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-02-11 03:26:31 (GMT) |
commit | b2b80a93cd5ec39ce5bdcf5836e2b07ccb65389b (patch) | |
tree | 77ab8b62d7935d661c9eacf9fe69241d79491175 | |
parent | 7c8835b2dd350978ebb226c15d1a3c9d03f683e2 (diff) | |
download | Qt-b2b80a93cd5ec39ce5bdcf5836e2b07ccb65389b.zip Qt-b2b80a93cd5ec39ce5bdcf5836e2b07ccb65389b.tar.gz Qt-b2b80a93cd5ec39ce5bdcf5836e2b07ccb65389b.tar.bz2 |
Add support for reading from resource files to Direct Show media service
3 files changed, 65 insertions, 9 deletions
diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.cpp index bf83dcf..c2fb0d4 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.cpp @@ -45,6 +45,8 @@ #include "directshowmediatype.h" #include "directshowpinenum.h" +#include <QtCore/qcoreapplication.h> +#include <QtCore/qurl.h> QT_BEGIN_NAMESPACE @@ -55,15 +57,16 @@ static const GUID directshow_subtypes[] = MEDIASUBTYPE_NULL }; -DirectShowIOSource::DirectShowIOSource(QIODevice *device, DirectShowEventLoop *loop) +DirectShowIOSource::DirectShowIOSource(DirectShowEventLoop *loop) : m_ref(1) , m_state(State_Stopped) + , m_reader(0) + , m_loop(loop) , m_graph(0) , m_clock(0) , m_allocator(0) , m_peerPin(0) , m_pinId(QLatin1String("Data")) - , m_reader(device, this, loop) { QVector<AM_MEDIA_TYPE> mediaTypes; @@ -93,6 +96,15 @@ DirectShowIOSource::DirectShowIOSource(QIODevice *device, DirectShowEventLoop *l DirectShowIOSource::~DirectShowIOSource() { Q_ASSERT(m_ref == 0); + + delete m_reader; +} + +void DirectShowIOSource::setDevice(QIODevice *device) +{ + Q_ASSERT(!m_reader); + + m_reader = new DirectShowIOReader(device, this, m_loop); } void DirectShowIOSource::setAllocator(IMemAllocator *allocator) @@ -121,7 +133,7 @@ HRESULT DirectShowIOSource::QueryInterface(REFIID riid, void **ppvObject) } else if (riid == IID_IPin) { *ppvObject = static_cast<IPin *>(this); } else if (riid == IID_IAsyncReader) { - *ppvObject = static_cast<IAsyncReader *>(&m_reader); + *ppvObject = static_cast<IAsyncReader *>(m_reader); } else { *ppvObject = 0; @@ -571,12 +583,12 @@ HRESULT DirectShowIOSource::EndOfStream() HRESULT DirectShowIOSource::BeginFlush() { - return m_reader.BeginFlush(); + return m_reader->BeginFlush(); } HRESULT DirectShowIOSource::EndFlush() { - return m_reader.EndFlush(); + return m_reader->EndFlush(); } HRESULT DirectShowIOSource::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) @@ -601,3 +613,27 @@ HRESULT DirectShowIOSource::QueryDirection(PIN_DIRECTION *pPinDir) QT_END_NAMESPACE +DirectShowRcSource::DirectShowRcSource(DirectShowEventLoop *loop) + : DirectShowIOSource(loop) +{ +} + +bool DirectShowRcSource::open(const QUrl &url) +{ + m_file.moveToThread(QCoreApplication::instance()->thread()); + + m_file.setFileName(QLatin1Char(':') + url.path()); + + qDebug("qrc file %s", qPrintable(m_file.fileName())); + + if (m_file.open(QIODevice::ReadOnly)) { + qDebug("Size %d", m_file.size()); + qDebug("Sequential %d", int(m_file.isSequential())); + + setDevice(&m_file); + + return true; + } else { + return false; + } +} diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.h index a8ed56a..b626473 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowiosource.h @@ -51,7 +51,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QIODevice; +#include <QtCore/qfile.h> class DirectShowIOSource : public DirectShowMediaTypeList @@ -60,9 +60,10 @@ class DirectShowIOSource , public IPin { public: - DirectShowIOSource(QIODevice *device, DirectShowEventLoop *loop); + DirectShowIOSource(DirectShowEventLoop *loop); ~DirectShowIOSource(); + void setDevice(QIODevice *device); void setAllocator(IMemAllocator *allocator); // IUnknown @@ -126,6 +127,8 @@ private: volatile LONG m_ref; FILTER_STATE m_state; + DirectShowIOReader *m_reader; + DirectShowEventLoop *m_loop; IFilterGraph *m_graph; IReferenceClock *m_clock; IMemAllocator *m_allocator; @@ -134,8 +137,17 @@ private: QString m_filterName; const QString m_pinId; QMutex m_mutex; - DirectShowIOReader m_reader; +}; + +class DirectShowRcSource : public DirectShowIOSource +{ +public: + DirectShowRcSource(DirectShowEventLoop *loop); + + bool open(const QUrl &url); +private: + QFile m_file; }; QT_END_NAMESPACE diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp index e9bce71..6e6b2f2 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp @@ -247,6 +247,13 @@ void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) fileSource->Release(); } + } else if (url.scheme() == QLatin1String("qrc")) { + DirectShowRcSource *rcSource = new DirectShowRcSource(m_loop); + + if (rcSource->open(url) && SUCCEEDED(hr = m_graph->AddFilter(rcSource, L"Source"))) + source = rcSource; + else + rcSource->Release(); } if (!SUCCEEDED(hr)) { @@ -300,7 +307,8 @@ void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) void DirectShowPlayerService::doSetStreamSource(QMutexLocker *locker) { - IBaseFilter *source = new DirectShowIOSource(m_stream, m_loop); + DirectShowIOSource *source = new DirectShowIOSource(m_loop); + source->setDevice(m_stream); if (SUCCEEDED(m_graph->AddFilter(source, L"Source"))) { m_executedTasks = SetSource; |