summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin McPherson <justin.mcpherson@nokia.com>2010-02-19 07:12:33 (GMT)
committerJustin McPherson <justin.mcpherson@nokia.com>2010-02-19 07:12:33 (GMT)
commitc7632bc03c2123dcc7d2242d4782a0d8be477cdc (patch)
treecc8028022e7b4e1566d9b199982f58adbbc17412
parentf95a3014171361672c3307b8dd080e5369d6e017 (diff)
parent90b9d45d77b25769834d4b879baff13a3327f4ce (diff)
downloadQt-c7632bc03c2123dcc7d2242d4782a0d8be477cdc.zip
Qt-c7632bc03c2123dcc7d2242d4782a0d8be477cdc.tar.gz
Qt-c7632bc03c2123dcc7d2242d4782a0d8be477cdc.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt-multimedia-team
-rw-r--r--src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h5
-rw-r--r--src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm149
-rw-r--r--src/plugins/mediaservices/qt7/qt7movierenderer.h1
-rw-r--r--src/plugins/mediaservices/qt7/qt7movierenderer.mm71
-rw-r--r--src/plugins/mediaservices/qt7/qt7movievideowidget.h1
-rw-r--r--src/plugins/mediaservices/qt7/qt7movievideowidget.mm10
-rw-r--r--src/plugins/mediaservices/qt7/qt7movieviewoutput.h1
-rw-r--r--src/plugins/mediaservices/qt7/qt7movieviewoutput.mm7
-rw-r--r--src/plugins/mediaservices/qt7/qt7movieviewrenderer.h1
-rw-r--r--src/plugins/mediaservices/qt7/qt7movieviewrenderer.mm8
-rw-r--r--src/plugins/mediaservices/qt7/qt7videooutputcontrol.h2
11 files changed, 197 insertions, 59 deletions
diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h
index 2a6bab7..4742e2e 100644
--- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h
+++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h
@@ -93,6 +93,8 @@ public:
bool isSeekable() const;
qreal playbackRate() const;
+
+public slots:
void setPlaybackRate(qreal rate);
void setPosition(qint64 pos);
@@ -105,6 +107,9 @@ public:
void setMuted(bool muted);
void processEOS();
+ void processStateChange();
+ void processVolumeChange();
+ void processNaturalSizeChange();
signals:
void positionChanged(qint64 position);
diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm
index d9bb646..d1381fe 100644
--- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm
+++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm
@@ -68,6 +68,7 @@ QT_BEGIN_NAMESPACE
- (QTMovieObserver *) initWithPlayerSession:(QT7PlayerSession*)session;
- (void) setMovie:(QTMovie *)movie;
- (void) processEOS:(NSNotification *)notification;
+- (void) processStateChange:(NSNotification *)notification;
@end
@implementation QTMovieObserver
@@ -97,6 +98,15 @@ QT_BEGIN_NAMESPACE
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector(processEOS:) name: QTMovieDidEndNotification object: m_movie];
+ [[NSNotificationCenter defaultCenter] addObserver: self selector:
+ @selector(processStateChange:) name: QTMovieLoadStateDidChangeNotification object: m_movie];
+
+ [[NSNotificationCenter defaultCenter] addObserver: self selector:
+ @selector(processVolumeChange:) name: QTMovieVolumeDidChangeNotification object: m_movie];
+
+ [[NSNotificationCenter defaultCenter] addObserver: self selector:
+ @selector(processNaturalSizeChange:) name: QTMovieNaturalSizeDidChangeNotification object: m_movie];
+
[movie retain];
}
}
@@ -107,6 +117,24 @@ QT_BEGIN_NAMESPACE
m_session->processEOS();
}
+- (void) processStateChange:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ m_session->processStateChange();
+}
+
+- (void) processVolumeChange:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ m_session->processVolumeChange();
+}
+
+- (void) processNaturalSizeChange :(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ m_session->processNaturalSizeChange();
+}
+
@end
static CFStringRef qString2CFStringRef(const QString &string)
@@ -145,8 +173,6 @@ void QT7PlayerSession::setVideoOutput(QT7VideoOutput *output)
if (m_videoOutput == output)
return;
- qDebug() << "set output" << output;
-
if (m_videoOutput) {
m_videoOutput->setEnabled(false);
m_videoOutput->setMovie(0);
@@ -251,12 +277,11 @@ void QT7PlayerSession::setPosition(qint64 pos)
void QT7PlayerSession::play()
{
- m_state = QMediaPlayer::PlayingState;
-
float preferredRate = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMoviePreferredRateAttribute"] floatValue];
[(QTMovie*)m_QTMovie setRate:preferredRate*m_rate];
- emit stateChanged(m_state);
+ if (m_state != QMediaPlayer::PlayingState)
+ emit stateChanged(m_state = QMediaPlayer::PlayingState);
}
void QT7PlayerSession::pause()
@@ -327,6 +352,7 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream)
m_resources = content;
m_mediaStream = stream;
+ m_mediaStatus = QMediaPlayer::NoMedia;
QUrl url;
@@ -335,25 +361,18 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream)
else
return;
- NSError *err = 0;
- QTDataReference *dataRef = 0;
+ qDebug() << "Open media" << url;
- if ( url.scheme() == "file" ) {
- NSString *nsFileName = (NSString *)qString2CFStringRef( url.toLocalFile() );
- dataRef = [QTDataReference dataReferenceWithReferenceToFile:nsFileName];
- } else {
- NSString *urlString = (NSString *)qString2CFStringRef( url.toString() );
- NSURL *url = [NSURL URLWithString: urlString];
- dataRef = [QTDataReference dataReferenceWithReferenceToURL:url];
- }
+ NSError *err = 0;
+ NSString *urlString = (NSString *)qString2CFStringRef(url.toString());
NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:
- dataRef, QTMovieDataReferenceAttribute,
- [NSNumber numberWithBool:YES], QTMovieOpenAsyncOKAttribute,
- [NSNumber numberWithBool:YES], QTMovieIsActiveAttribute,
- [NSNumber numberWithBool:YES], QTMovieResolveDataRefsAttribute,
- [NSNumber numberWithBool:YES], QTMovieDontInteractWithUserAttribute,
- nil];
+ [NSURL URLWithString:urlString], QTMovieURLAttribute,
+ [NSNumber numberWithBool:YES], QTMovieOpenAsyncOKAttribute,
+ [NSNumber numberWithBool:YES], QTMovieIsActiveAttribute,
+ [NSNumber numberWithBool:YES], QTMovieResolveDataRefsAttribute,
+ [NSNumber numberWithBool:YES], QTMovieDontInteractWithUserAttribute,
+ nil];
m_QTMovie = [[QTMovie movieWithAttributes:attr error:&err] retain];
@@ -362,19 +381,15 @@ void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream)
m_QTMovie = 0;
QString description = QString::fromUtf8([[err localizedDescription] UTF8String]);
- qDebug() << "QT7PlayerSession::setMedia error" << description;
emit error(QMediaPlayer::FormatError, description );
} else {
[(QTMovieObserver*)m_movieObserver setMovie:(QTMovie*)m_QTMovie];
- if (m_videoOutput) {
- m_videoOutput->setEnabled(true);
+ if (m_videoOutput) {
m_videoOutput->setMovie(m_QTMovie);
+ m_videoOutput->setEnabled(true);
}
-
- emit durationChanged(duration());
- emit audioAvailableChanged(isAudioAvailable());
- emit videoAvailableChanged(isVideoAvailable());
+ processStateChange();
[(QTMovie*)m_QTMovie setMuted:m_muted];
setVolume(m_volume);
@@ -406,6 +421,84 @@ void QT7PlayerSession::processEOS()
emit mediaStatusChanged(m_mediaStatus);
}
+void QT7PlayerSession::processStateChange()
+{
+ signed long state = [[(QTMovie*)m_QTMovie attributeForKey:QTMovieLoadStateAttribute]
+ longValue];
+ qDebug() << "Moview load state changed:" << state;
+
+#ifndef QUICKTIME_C_API_AVAILABLE
+ enum {
+ kMovieLoadStateError = -1L,
+ kMovieLoadStateLoading = 1000,
+ kMovieLoadStateLoaded = 2000,
+ kMovieLoadStatePlayable = 10000,
+ kMovieLoadStatePlaythroughOK = 20000,
+ kMovieLoadStateComplete = 100000
+ };
+#endif
+
+ QMediaPlayer::MediaStatus newStatus = QMediaPlayer::NoMedia;
+ bool isPlaying = (m_state != QMediaPlayer::StoppedState);
+
+ if (state >= kMovieLoadStateComplete) {
+ newStatus = isPlaying ? QMediaPlayer::BufferedMedia : QMediaPlayer::LoadedMedia;
+ } else if (state >= kMovieLoadStatePlayable)
+ newStatus = isPlaying ? QMediaPlayer::BufferingMedia : QMediaPlayer::LoadingMedia;
+ else if (state >= kMovieLoadStateLoading)
+ newStatus = isPlaying ? QMediaPlayer::StalledMedia : QMediaPlayer::LoadingMedia;
+
+ if (state == kMovieLoadStateError) {
+ newStatus = QMediaPlayer::InvalidMedia;
+ emit error(QMediaPlayer::FormatError, tr("Playback failed"));
+ }
+
+ if (newStatus != m_mediaStatus) {
+ switch (newStatus) {
+ case QMediaPlayer::BufferedMedia:
+ case QMediaPlayer::BufferingMedia:
+ //delayed playback start is necessary for network sources
+ if (m_state == QMediaPlayer::PlayingState) {
+ QMetaObject::invokeMethod(this, "play", Qt::QueuedConnection);
+ }
+ //fall
+ case QMediaPlayer::LoadedMedia:
+ case QMediaPlayer::LoadingMedia:
+ emit durationChanged(duration());
+ emit audioAvailableChanged(isAudioAvailable());
+ emit videoAvailableChanged(isVideoAvailable());
+ break;
+ case QMediaPlayer::InvalidMedia:
+ emit stateChanged(m_state = QMediaPlayer::StoppedState);
+ default:
+ break;
+ }
+
+ emit mediaStatusChanged(m_mediaStatus = newStatus);
+ }
+}
+
+void QT7PlayerSession::processVolumeChange()
+{
+ if (!m_QTMovie)
+ return;
+
+ int newVolume = qRound(100.0f*[((QTMovie*)m_QTMovie) volume]);
+
+ if (newVolume != m_volume) {
+ emit volumeChanged(m_volume = newVolume);
+ }
+}
+
+void QT7PlayerSession::processNaturalSizeChange()
+{
+ if (m_videoOutput) {
+ NSSize size = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue];
+ qDebug() << "Native size changed:" << QSize(size.width, size.height);
+ m_videoOutput->updateNaturalSize(QSize(size.width, size.height));
+ }
+}
+
#include "moc_qt7playersession.cpp"
QT_END_NAMESPACE
diff --git a/src/plugins/mediaservices/qt7/qt7movierenderer.h b/src/plugins/mediaservices/qt7/qt7movierenderer.h
index 4543152..a547329 100644
--- a/src/plugins/mediaservices/qt7/qt7movierenderer.h
+++ b/src/plugins/mediaservices/qt7/qt7movierenderer.h
@@ -76,6 +76,7 @@ public:
void setEnabled(bool);
void setMovie(void *movie);
+ void updateNaturalSize(const QSize &newSize);
QAbstractVideoSurface *surface() const;
void setSurface(QAbstractVideoSurface *surface);
diff --git a/src/plugins/mediaservices/qt7/qt7movierenderer.mm b/src/plugins/mediaservices/qt7/qt7movierenderer.mm
index 8cb0f46..587f3b9 100644
--- a/src/plugins/mediaservices/qt7/qt7movierenderer.mm
+++ b/src/plugins/mediaservices/qt7/qt7movierenderer.mm
@@ -269,7 +269,7 @@ void QT7MovieRenderer::setupVideoOutput()
return;
}
- NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieCurrentSizeAttribute"] sizeValue];
+ NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue];
m_nativeSize = QSize(size.width, size.height);
#ifdef QUICKTIME_C_API_AVAILABLE
@@ -320,34 +320,36 @@ void QT7MovieRenderer::setupVideoOutput()
(m_usingGLContext && (m_currentGLContext != QGLContext::currentContext())) ||
(!m_usingGLContext && (m_pixelBufferContextGeometry != m_nativeSize))) {
QTVisualContextRelease(m_visualContext);
+ m_pixelBufferContextGeometry = QSize();
m_visualContext = 0;
}
}
- if (!m_visualContext) {
- if (m_usingGLContext) {
- qDebug() << "Building OpenGL visual context";
- m_currentGLContext = QGLContext::currentContext();
- if (!createGLVisualContext()) {
- qWarning() << "QT7MovieRenderer: failed to create visual context";
- return;
- }
- } else {
- qDebug() << "Building Pixel Buffer visual context";
- if (!createPixelBufferVisualContext()) {
- qWarning() << "QT7MovieRenderer: failed to create visual context";
- return;
+ if (!m_nativeSize.isEmpty()) {
+ if (!m_visualContext) {
+ if (m_usingGLContext) {
+ qDebug() << "Building OpenGL visual context" << m_nativeSize;
+ m_currentGLContext = QGLContext::currentContext();
+ if (!createGLVisualContext()) {
+ qWarning() << "QT7MovieRenderer: failed to create visual context";
+ return;
+ }
+ } else {
+ qDebug() << "Building Pixel Buffer visual context" << m_nativeSize;
+ if (!createPixelBufferVisualContext()) {
+ qWarning() << "QT7MovieRenderer: failed to create visual context";
+ return;
+ }
}
}
- }
-
- // targets a Movie to render into a visual context
- SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], m_visualContext);
+ // targets a Movie to render into a visual context
+ SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], m_visualContext);
+ m_displayLink->start();
+ }
#endif
- m_displayLink->start();
}
void QT7MovieRenderer::setEnabled(bool)
@@ -358,19 +360,30 @@ void QT7MovieRenderer::setMovie(void *movie)
{
qDebug() << "QT7MovieRenderer::setMovie" << movie;
- if (m_movie == movie)
- return;
-
+#ifdef QUICKTIME_C_API_AVAILABLE
QMutexLocker locker(&m_mutex);
-#ifdef QUICKTIME_C_API_AVAILABLE
- //ensure the old movie doesn't hold the visual context, otherwise it can't be reused
- if (m_movie && m_visualContext)
- SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], 0);
+ if (m_movie != movie) {
+ if (m_movie) {
+ //ensure the old movie doesn't hold the visual context, otherwise it can't be reused
+ SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], nil);
+ [(QTMovie*)m_movie release];
+ }
+
+ m_movie = movie;
+ [(QTMovie*)m_movie retain];
+
+ setupVideoOutput();
+ }
#endif
+}
- m_movie = movie;
- setupVideoOutput();
+void QT7MovieRenderer::updateNaturalSize(const QSize &newSize)
+{
+ if (m_nativeSize != newSize) {
+ m_nativeSize = newSize;
+ setupVideoOutput();
+ }
}
QAbstractVideoSurface *QT7MovieRenderer::surface() const
@@ -426,7 +439,7 @@ void QT7MovieRenderer::updateVideoFrame(const CVTimeStamp &ts)
CVPixelBufferRelease((CVPixelBufferRef)imageBuffer);
}
- QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_RGB32);
+ QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_RGB32);
m_surface->present(frame);
QTVisualContextTask(m_visualContext);
}
diff --git a/src/plugins/mediaservices/qt7/qt7movievideowidget.h b/src/plugins/mediaservices/qt7/qt7movievideowidget.h
index 266dad4..3acd373 100644
--- a/src/plugins/mediaservices/qt7/qt7movievideowidget.h
+++ b/src/plugins/mediaservices/qt7/qt7movievideowidget.h
@@ -74,6 +74,7 @@ public:
void setEnabled(bool);
void setMovie(void *movie);
+ void updateNaturalSize(const QSize &newSize);
QWidget *videoWidget();
diff --git a/src/plugins/mediaservices/qt7/qt7movievideowidget.mm b/src/plugins/mediaservices/qt7/qt7movievideowidget.mm
index e1e0162..6e74fcd 100644
--- a/src/plugins/mediaservices/qt7/qt7movievideowidget.mm
+++ b/src/plugins/mediaservices/qt7/qt7movievideowidget.mm
@@ -256,7 +256,7 @@ void QT7MovieVideoWidget::setupVideoOutput()
return;
}
- NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieCurrentSizeAttribute"] sizeValue];
+ NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue];
m_nativeSize = QSize(size.width, size.height);
m_videoWidget->setNativeSize(m_nativeSize);
@@ -290,6 +290,14 @@ void QT7MovieVideoWidget::setMovie(void *movie)
setupVideoOutput();
}
+void QT7MovieVideoWidget::updateNaturalSize(const QSize &newSize)
+{
+ if (m_nativeSize != newSize) {
+ m_nativeSize = newSize;
+ setupVideoOutput();
+ }
+}
+
bool QT7MovieVideoWidget::isFullScreen() const
{
return m_fullscreen;
diff --git a/src/plugins/mediaservices/qt7/qt7movieviewoutput.h b/src/plugins/mediaservices/qt7/qt7movieviewoutput.h
index 7f3ff91..30eefa7 100644
--- a/src/plugins/mediaservices/qt7/qt7movieviewoutput.h
+++ b/src/plugins/mediaservices/qt7/qt7movieviewoutput.h
@@ -65,6 +65,7 @@ public:
void setEnabled(bool);
void setMovie(void *movie);
+ void updateNaturalSize(const QSize &newSize);
WId winId() const;
void setWinId(WId id);
diff --git a/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm b/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm
index 8182797..b549487 100644
--- a/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm
+++ b/src/plugins/mediaservices/qt7/qt7movieviewoutput.mm
@@ -177,7 +177,7 @@ void QT7MovieViewOutput::setupVideoOutput()
if (m_movie == 0 || m_winId <= 0)
return;
- NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieCurrentSizeAttribute"] sizeValue];
+ NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue];
m_nativeSize = QSize(size.width, size.height);
if (!m_movieView)
@@ -201,6 +201,11 @@ void QT7MovieViewOutput::setMovie(void *movie)
setupVideoOutput();
}
+void QT7MovieViewOutput::updateNaturalSize(const QSize &newSize)
+{
+ m_nativeSize = newSize;
+}
+
WId QT7MovieViewOutput::winId() const
{
return m_winId;
diff --git a/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h b/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h
index 6f381f8..336006c 100644
--- a/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h
+++ b/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h
@@ -69,6 +69,7 @@ public:
void setEnabled(bool);
void setMovie(void *movie);
+ void updateNaturalSize(const QSize &newSize);
QAbstractVideoSurface *surface() const;
void setSurface(QAbstractVideoSurface *surface);
diff --git a/src/plugins/mediaservices/qt7/qt7movieviewrenderer.mm b/src/plugins/mediaservices/qt7/qt7movieviewrenderer.mm
index e08d0f3..342feb8 100644
--- a/src/plugins/mediaservices/qt7/qt7movieviewrenderer.mm
+++ b/src/plugins/mediaservices/qt7/qt7movieviewrenderer.mm
@@ -298,6 +298,14 @@ void QT7MovieViewRenderer::setMovie(void *movie)
setupVideoOutput();
}
+void QT7MovieViewRenderer::updateNaturalSize(const QSize &newSize)
+{
+ if (m_nativeSize != newSize) {
+ m_nativeSize = newSize;
+ setupVideoOutput();
+ }
+}
+
QAbstractVideoSurface *QT7MovieViewRenderer::surface() const
{
return m_surface;
diff --git a/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h b/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h
index 2faf6bb..2c60919 100644
--- a/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h
+++ b/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h
@@ -43,6 +43,7 @@
#define QT7VIDEOOUTPUTCONTROL_H
#include <QtCore/qobject.h>
+#include <QtCore/qsize.h>
#include <QtMultimedia/qvideooutputcontrol.h>
#include <QtMultimedia/qvideowindowcontrol.h>
@@ -68,6 +69,7 @@ public:
virtual ~QT7VideoOutput() {}
virtual void setEnabled(bool enabled) = 0;
virtual void setMovie(void *movie) = 0;
+ virtual void updateNaturalSize(const QSize &newSize) = 0;
};
class QT7VideoWindowControl : public QVideoWindowControl, public QT7VideoOutput