diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-02-10 06:51:43 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-02-10 06:51:43 (GMT) |
commit | eab600d2d58a2f638636281ec5db65b4a07b890f (patch) | |
tree | a4bd707351b51cb76633798b5e2836a28ce39287 /src/plugins | |
parent | aec0628295cda95f2169e3007368797ba6585ee3 (diff) | |
download | Qt-eab600d2d58a2f638636281ec5db65b4a07b890f.zip Qt-eab600d2d58a2f638636281ec5db65b4a07b890f.tar.gz Qt-eab600d2d58a2f638636281ec5db65b4a07b890f.tar.bz2 |
Emit an error if given a QIODevice that is unusable.
Where unusable is not readable or sequential.
Diffstat (limited to 'src/plugins')
4 files changed, 69 insertions, 40 deletions
diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.cpp index a4308d7..587f4b1 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.cpp @@ -82,6 +82,7 @@ DirectShowPlayerControl::DirectShowPlayerControl(DirectShowPlayerService *servic , m_updateProperties(0) , m_state(QMediaPlayer::StoppedState) , m_status(QMediaPlayer::UnknownMediaStatus) + , m_error(QMediaPlayer::NoError) , m_streamTypes(0) , m_muteVolume(-1) , m_duration(0) @@ -240,12 +241,7 @@ void DirectShowPlayerControl::setMedia(const QMediaContent &media, QIODevice *st m_service->load(media, stream); - emit audioAvailableChanged(m_streamTypes & DirectShowPlayerService::AudioStream); - emit videoAvailableChanged(m_streamTypes & DirectShowPlayerService::VideoStream); - emit durationChanged(m_duration); - emit seekableChanged(m_seekable); - emit mediaStatusChanged(m_status); - emit stateChanged(m_state); + emitPropertyChanges(); } void DirectShowPlayerControl::play() @@ -269,33 +265,41 @@ void DirectShowPlayerControl::stop() void DirectShowPlayerControl::customEvent(QEvent *event) { if (event->type() == QEvent::Type(PropertiesChanged)) { - int properties = m_updateProperties; - m_updateProperties = 0; + emitPropertyChanges(); - if (properties & PlaybackRateProperty) - emit playbackRateChanged(m_playbackRate); + event->accept(); + } else { + QMediaPlayerControl::customEvent(event); + } +} - if (properties & StreamTypesProperty) { - emit audioAvailableChanged(m_streamTypes & DirectShowPlayerService::AudioStream); - emit videoAvailableChanged(m_streamTypes & DirectShowPlayerService::VideoStream); - } +void DirectShowPlayerControl::emitPropertyChanges() +{ + int properties = m_updateProperties; + m_updateProperties = 0; - if (properties & DurationProperty) - emit durationChanged(m_duration); + if ((properties & ErrorProperty) && m_error != QMediaPlayer::NoError) + emit error(m_error, m_errorString); - if (properties & SeekableProperty) - emit seekableChanged(m_seekable); + if (properties & PlaybackRateProperty) + emit playbackRateChanged(m_playbackRate); - if (properties & StatusProperty) - emit mediaStatusChanged(m_status); + if (properties & StreamTypesProperty) { + emit audioAvailableChanged(m_streamTypes & DirectShowPlayerService::AudioStream); + emit videoAvailableChanged(m_streamTypes & DirectShowPlayerService::VideoStream); + } - if (properties & StateProperty) - emit stateChanged(m_state); + if (properties & DurationProperty) + emit durationChanged(m_duration); - event->accept(); - } else { - QMediaPlayerControl::customEvent(event); - } + if (properties & SeekableProperty) + emit seekableChanged(m_seekable); + + if (properties & StatusProperty) + emit mediaStatusChanged(m_status); + + if (properties & StateProperty) + emit stateChanged(m_state); } void DirectShowPlayerControl::scheduleUpdate(int properties) @@ -366,4 +370,13 @@ void DirectShowPlayerControl::updateAudioOutput(IBaseFilter *filter) m_audio = com_cast<IBasicAudio>(filter); } +void DirectShowPlayerControl::updateError(QMediaPlayer::Error error, const QString &errorString) +{ + m_error = error; + m_errorString = errorString; + + if (m_error != QMediaPlayer::NoError) + scheduleUpdate(ErrorProperty); +} + QT_END_NAMESPACE diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h index af2cd3f..6706bab 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h @@ -101,8 +101,7 @@ public: void updateMediaInfo(qint64 duration, int streamTypes, bool seekable); void updatePlaybackRate(qreal rate); void updateAudioOutput(IBaseFilter *filter); - - using QMediaPlayerControl::error; + void updateError(QMediaPlayer::Error error, const QString &errorString); protected: void customEvent(QEvent *event); @@ -115,7 +114,8 @@ private: StreamTypesProperty = 0x04, DurationProperty = 0x08, PlaybackRateProperty = 0x10, - SeekableProperty = 0x20 + SeekableProperty = 0x20, + ErrorProperty = 0x40 }; enum Event @@ -124,6 +124,7 @@ private: }; void scheduleUpdate(int properties); + void emitPropertyChanges(); DirectShowPlayerService *m_service; IBasicAudio *m_audio; @@ -131,12 +132,14 @@ private: int m_updateProperties; QMediaPlayer::State m_state; QMediaPlayer::MediaStatus m_status; + QMediaPlayer::Error m_error; int m_streamTypes; int m_muteVolume; qint64 m_duration; qreal m_playbackRate; bool m_seekable; QMediaContent m_media; + QString m_errorString; }; diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp index 3c0a43a..e9bce71 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp @@ -182,6 +182,8 @@ void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream m_resources = media.resources(); m_stream = stream; + m_error = QMediaPlayer::NoError; + m_errorString = QString(); m_duration = 0; m_streamTypes = 0; m_executedTasks = 0; @@ -195,6 +197,10 @@ void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream m_graphStatus = NoMedia; m_url.clear(); + } else if (stream && (!stream->isReadable() || stream->isSequential())) { + m_pendingTasks = 0; + m_graphStatus = InvalidMedia; + m_error = QMediaPlayer::ResourceError; } else { m_graphStatus = Loading; @@ -208,6 +214,7 @@ void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream ::SetEvent(m_taskHandle); } + m_playerControl->updateError(m_error, m_errorString); m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); m_playerControl->updateState(QMediaPlayer::StoppedState); updateStatus(); @@ -273,13 +280,16 @@ void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) switch (hr) { case VFW_E_UNKNOWN_FILE_TYPE: m_error = QMediaPlayer::FormatError; + m_errorString = QString(); break; case E_OUTOFMEMORY: case VFW_E_CANNOT_LOAD_SOURCE_FILTER: case VFW_E_NOT_FOUND: m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); default: m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); qWarning("DirectShowPlayerService::doSetUrlSource: Unresolved error code %x", hr); break; } @@ -312,6 +322,7 @@ void DirectShowPlayerService::doSetStreamSource(QMutexLocker *locker) m_graphStatus = InvalidMedia; m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); } @@ -415,14 +426,17 @@ void DirectShowPlayerService::doRender(QMutexLocker *locker) if (!m_audioOutput && !m_videoOutput) { m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); } else { switch (renderHr) { case VFW_E_UNSUPPORTED_AUDIO: case VFW_E_UNSUPPORTED_VIDEO: case VFW_E_UNSUPPORTED_STREAM: m_error = QMediaPlayer::FormatError; + m_errorString = QString(); default: m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); qWarning("DirectShowPlayerService::doRender: Unresolved error code %x", renderHr); } @@ -619,6 +633,7 @@ void DirectShowPlayerService::doPlay(QMutexLocker *locker) QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange))); } else { m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); qWarning("DirectShowPlayerService::doPlay: Unresolved error code %x", hr); QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); @@ -660,6 +675,7 @@ void DirectShowPlayerService::doPause(QMutexLocker *locker) QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange))); } else { m_error = QMediaPlayer::ResourceError; + m_errorString = QString(); qWarning("DirectShowPlayerService::doPause: Unresolved error code %x", hr); QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); @@ -994,18 +1010,14 @@ void DirectShowPlayerService::customEvent(QEvent *event) updateStatus(); } else if (event->type() == QEvent::Type(Error)) { - QMediaPlayer::Error error; - { - QMutexLocker locker(&m_mutex); - error = m_error; - - if (error != QMediaPlayer::NoError) { - m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); - m_playerControl->updateState(QMediaPlayer::StoppedState); - updateStatus(); - } + QMutexLocker locker(&m_mutex); + + if (m_error != QMediaPlayer::NoError) { + m_playerControl->updateError(m_error, m_errorString); + m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); + m_playerControl->updateState(QMediaPlayer::StoppedState); + updateStatus(); } - m_playerControl->error(error, QString()); } else if (event->type() == QEvent::Type(RateChange)) { QMutexLocker locker(&m_mutex); diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h index 906d23b..f9d3232 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h @@ -205,6 +205,7 @@ private: QMediaTimeRange m_playbackRange; QUrl m_url; QMediaResourceList m_resources; + QString m_errorString; QMutex m_mutex; friend class DirectShowPlayerServiceThread; |