Merge lp:~stellarium/stellarium/video-playback into lp:stellarium

Proposed by Alexander Wolf
Status: Merged
Merged at revision: 5374
Proposed branch: lp:~stellarium/stellarium/video-playback
Merge into: lp:stellarium
Diff against target: 555 lines (+437/-0)
8 files modified
scripts/tests/videotest.ssc (+19/-0)
src/CMakeLists.txt (+3/-0)
src/core/StelApp.cpp (+4/-0)
src/core/StelApp.hpp (+7/-0)
src/core/StelVideoMgr.cpp (+197/-0)
src/core/StelVideoMgr.hpp (+65/-0)
src/scripting/StelMainScriptAPI.cpp (+74/-0)
src/scripting/StelMainScriptAPI.hpp (+68/-0)
To merge this branch: bzr merge lp:~stellarium/stellarium/video-playback
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
Bogdan Marinov Pending
treaves Pending
Matthew Gates Pending
gzotti Pending
Review via email: mp+104440@code.launchpad.net

This proposal supersedes a proposal from 2012-04-13.

Description of the change

Sibi Antony are add the video playback feature

To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) wrote : Posted in a previous version of this proposal

I think we can merge this code

review: Approve
Revision history for this message
treaves (treaves) wrote : Posted in a previous version of this proposal

All conditional statements need to use braces.

review: Needs Fixing
Revision history for this message
Alexander Wolf (alexwolf) :
review: Approve
5296. By Alexander Wolf

sync with trunk

5297. By Alexander Wolf

drop videotest.flv file

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'scripts/tests/videotest.ssc'
2--- scripts/tests/videotest.ssc 1970-01-01 00:00:00 +0000
3+++ scripts/tests/videotest.ssc 2012-06-02 18:10:26 +0000
4@@ -0,0 +1,19 @@
5+// Name: Video Test
6+// Author: Alexander Wolf
7+// License: Public Domain
8+// Description: This script plays several formats of video file.
9+// Note that video support is a build-time option and
10+// may not be supported for the version of Stellarium
11+// which you have. Also, different playforms may
12+// support different video formats.
13+//
14+
15+core.loadVideo("tests/videotest.flv", "flv", 100, 70, true, 0.5);
16+
17+lab = LabelMgr.labelScreen("Playing video file...", 100, 20, true, 20, "#ff0000");
18+core.playVideo("flv");
19+core.wait(182);
20+LabelMgr.deleteLabel(lab);
21+core.wait(0.4);
22+
23+core.dropVideo("flv");
24
25=== modified file 'src/CMakeLists.txt'
26--- src/CMakeLists.txt 2012-04-24 14:53:02 +0000
27+++ src/CMakeLists.txt 2012-06-02 18:10:26 +0000
28@@ -38,6 +38,8 @@
29 SET(stellarium_lib_SRCS
30 core/StelAudioMgr.hpp
31 core/StelAudioMgr.cpp
32+ core/StelVideoMgr.hpp
33+ core/StelVideoMgr.cpp
34 core/StelGeodesicGrid.cpp
35 core/StelGeodesicGrid.hpp
36 core/StelMovementMgr.cpp
37@@ -335,6 +337,7 @@
38 # that is, all the headers with SIGNAL/SLOTS/PLUGIN_INTERFACE etc..
39 SET(stellarium_MOC_HDRS
40 core/StelAudioMgr.hpp
41+ core/StelVideoMgr.hpp
42 core/StelModuleMgr.hpp
43 core/StelObjectMgr.hpp
44 core/StelObserver.hpp
45
46=== modified file 'src/core/StelApp.cpp'
47--- src/core/StelApp.cpp 2012-03-22 06:18:01 +0000
48+++ src/core/StelApp.cpp 2012-06-02 18:10:26 +0000
49@@ -44,6 +44,7 @@
50 #include "StelJsonParser.hpp"
51 #include "StelSkyLayerMgr.hpp"
52 #include "StelAudioMgr.hpp"
53+#include "StelVideoMgr.hpp"
54 #include "StelGuiBase.hpp"
55 #include "StelPainter.hpp"
56
57@@ -292,6 +293,9 @@
58 // Init audio manager
59 audioMgr = new StelAudioMgr();
60
61+ // Init video manager
62+ videoMgr = new StelVideoMgr();
63+
64 // Constellations
65 ConstellationMgr* asterisms = new ConstellationMgr(hip_stars);
66 asterisms->init();
67
68=== modified file 'src/core/StelApp.hpp'
69--- src/core/StelApp.hpp 2012-02-17 18:12:37 +0000
70+++ src/core/StelApp.hpp 2012-06-02 18:10:26 +0000
71@@ -38,6 +38,7 @@
72 class StelLocationMgr;
73 class StelSkyLayerMgr;
74 class StelAudioMgr;
75+class StelVideoMgr;
76 class StelGuiBase;
77
78 //! @class StelApp
79@@ -109,6 +110,9 @@
80 //! Get the audio manager
81 StelAudioMgr* getStelAudioMgr() {return audioMgr;}
82
83+ //! Get the video manager
84+ StelVideoMgr* getStelVideoMgr() {return videoMgr;}
85+
86 //! Get the core of the program.
87 //! It is the one which provide the projection, navigation and tone converter.
88 //! @return the StelCore instance of the program
89@@ -226,6 +230,9 @@
90 // The audio manager. Must execute in the main thread.
91 StelAudioMgr* audioMgr;
92
93+ // The video manager. Must execute in the main thread.
94+ StelVideoMgr* videoMgr;
95+
96 StelSkyLayerMgr* skyImageMgr;
97
98 StelGuiBase* stelGui;
99
100=== added file 'src/core/StelVideoMgr.cpp'
101--- src/core/StelVideoMgr.cpp 1970-01-01 00:00:00 +0000
102+++ src/core/StelVideoMgr.cpp 2012-06-02 18:10:26 +0000
103@@ -0,0 +1,197 @@
104+/*
105+ * Copyright (C) 2012 Sibi Antony
106+ *
107+ * This program is free software; you can redistribute it and/or
108+ * modify it under the terms of the GNU General Public License
109+ * as published by the Free Software Foundation; either version 2
110+ * of the License, or (at your option) any later version.
111+ *
112+ * This program is distributed in the hope that it will be useful,
113+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
114+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
115+ * GNU General Public License for more details.
116+ *
117+ * You should have received a copy of the GNU General Public License
118+ * along with this program; if not, write to the Free Software
119+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
120+ */
121+
122+#include "StelVideoMgr.hpp"
123+#include "StelMainGraphicsView.hpp"
124+#include <QDebug>
125+
126+
127+StelVideoMgr::StelVideoMgr()
128+{
129+}
130+
131+#ifdef HAVE_QT_PHONON
132+StelVideoMgr::~StelVideoMgr()
133+{
134+ foreach(QString id, videoObjects.keys())
135+ {
136+ dropVideo(id);
137+ }
138+}
139+
140+void StelVideoMgr::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha)
141+{
142+ if (videoObjects.contains(id))
143+ {
144+ qWarning() << "[StelVideoMgr] Video object with ID" << id << "already exists, dropping it";
145+ dropVideo(id);
146+ }
147+
148+ videoObjects[id] = new VideoPlayer;
149+ videoObjects[id]->widget = new QWidget();
150+ videoObjects[id]->player = new Phonon::VideoPlayer(Phonon::VideoCategory, videoObjects[id]->widget);
151+
152+ videoObjects[id]->player->load(Phonon::MediaSource(filename));
153+ videoObjects[id]->pWidget =
154+ StelMainGraphicsView::getInstance().scene()->addWidget(videoObjects[id]->widget, Qt::FramelessWindowHint);
155+
156+ videoObjects[id]->pWidget->setPos(x, y);
157+ videoObjects[id]->pWidget->setOpacity(alpha);
158+ videoObjects[id]->pWidget->setVisible(show);
159+ videoObjects[id]->player->show();
160+
161+}
162+
163+void StelVideoMgr::playVideo(const QString& id)
164+{
165+ if (videoObjects.contains(id))
166+ {
167+ if (videoObjects[id]->player!=NULL)
168+ {
169+ // if already playing, stop and play from the start
170+ if (videoObjects[id]->player->isPlaying() == true)
171+ {
172+ videoObjects[id]->player->stop();
173+ }
174+
175+ // otherwise just play it
176+ videoObjects[id]->player->play();
177+ }
178+ }
179+}
180+
181+void StelVideoMgr::pauseVideo(const QString& id)
182+{
183+ if (videoObjects.contains(id))
184+ {
185+ if (videoObjects[id]->player!=NULL)
186+ {
187+ videoObjects[id]->player->pause();
188+ }
189+ }
190+}
191+
192+void StelVideoMgr::stopVideo(const QString& id)
193+{
194+ if (videoObjects.contains(id))
195+ {
196+ if (videoObjects[id]->player!=NULL)
197+ {
198+ videoObjects[id]->player->stop();
199+ }
200+ }
201+}
202+
203+void StelVideoMgr::seekVideo(const QString& id, qint64 ms)
204+{
205+ if (videoObjects.contains(id))
206+ {
207+ if (videoObjects[id]->player!=NULL)
208+ {
209+ if (videoObjects[id]->player->mediaObject()->isSeekable())
210+ {
211+ videoObjects[id]->player->seek(ms);
212+ // Seek capability depends on the backend used.
213+ }
214+ else
215+ {
216+ qDebug() << "[StelVideoMgr] Cannot seek media source.";
217+ }
218+ }
219+ }
220+}
221+
222+void StelVideoMgr::dropVideo(const QString& id)
223+{
224+ if (!videoObjects.contains(id))
225+ return;
226+ if (videoObjects[id]->player!=NULL)
227+ {
228+ videoObjects[id]->player->stop();
229+ delete videoObjects[id]->player;
230+ delete videoObjects[id]->pWidget;
231+ delete videoObjects[id];
232+
233+ videoObjects.remove(id);
234+ }
235+}
236+
237+void StelVideoMgr::setVideoXY(const QString& id, float x, float y)
238+{
239+ if (videoObjects.contains(id))
240+ {
241+ if (videoObjects[id]->pWidget!=NULL)
242+ {
243+ videoObjects[id]->pWidget->setPos(x, y);
244+ }
245+ }
246+
247+}
248+
249+void StelVideoMgr::setVideoAlpha(const QString& id, float alpha)
250+{
251+ if (videoObjects.contains(id))
252+ {
253+ if (videoObjects[id]->pWidget!=NULL)
254+ {
255+ videoObjects[id]->pWidget->setOpacity(alpha);
256+ }
257+ }
258+}
259+
260+void StelVideoMgr::resizeVideo(const QString& id, float w, float h)
261+{
262+ if (videoObjects.contains(id))
263+ {
264+ if (videoObjects[id]->pWidget!=NULL)
265+ {
266+ videoObjects[id]->pWidget->resize(w, h);
267+ videoObjects[id]->player->resize(w, h);
268+ }
269+ }
270+}
271+
272+void StelVideoMgr::showVideo(const QString& id, bool show)
273+{
274+ if (videoObjects.contains(id))
275+ {
276+ if (videoObjects[id]->pWidget!=NULL)
277+ {
278+ videoObjects[id]->pWidget->setVisible(show);
279+ }
280+ }
281+}
282+
283+#else // HAVE_QT_PHONON
284+void StelVideoMgr::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha)
285+{
286+ qWarning() << "[StelVideoMgr] This build of Stellarium does not support video - cannot load video" << filename << id << x << y << show << alpha;
287+}
288+StelVideoMgr::~StelVideoMgr() {;}
289+void StelVideoMgr::playVideo(const QString&) {;}
290+void StelVideoMgr::pauseVideo(const QString&) {;}
291+void StelVideoMgr::stopVideo(const QString&) {;}
292+void StelVideoMgr::dropVideo(const QString&) {;}
293+void StelVideoMgr::seekVideo(const QString&, qint64) {;}
294+void StelVideoMgr::setVideoXY(const QString&, float, float) {;}
295+void StelVideoMgr::setVideoAlpha(const QString&, float) {;}
296+void StelVideoMgr::resizeVideo(const QString&, float, float) {;}
297+void StelVideoMgr::showVideo(const QString&, bool) {;}
298+#endif // HAVE_QT_PHONON
299+
300+
301
302=== added file 'src/core/StelVideoMgr.hpp'
303--- src/core/StelVideoMgr.hpp 1970-01-01 00:00:00 +0000
304+++ src/core/StelVideoMgr.hpp 2012-06-02 18:10:26 +0000
305@@ -0,0 +1,65 @@
306+/*
307+ * Copyright (C) 2012 Sibi Antony
308+ *
309+ * This program is free software; you can redistribute it and/or
310+ * modify it under the terms of the GNU General Public License
311+ * as published by the Free Software Foundation; either version 2
312+ * of the License, or (at your option) any later version.
313+ *
314+ * This program is distributed in the hope that it will be useful,
315+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
316+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
317+ * GNU General Public License for more details.
318+ *
319+ * You should have received a copy of the GNU General Public License
320+ * along with this program; if not, write to the Free Software
321+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
322+ */
323+
324+#ifndef _STELVIDEOMGR_HPP_
325+#define _STELVIDEOMGR_HPP_
326+
327+#ifdef HAVE_QT_PHONON
328+#include <phonon/videoplayer.h>
329+#include <phonon/videowidget.h>
330+#include <phonon/mediaobject.h>
331+#endif
332+
333+#include <QObject>
334+#include <QMap>
335+#include <QString>
336+#include <QGraphicsProxyWidget>
337+
338+class StelVideoMgr : public QObject
339+{
340+ Q_OBJECT
341+
342+public:
343+ StelVideoMgr();
344+ ~StelVideoMgr();
345+
346+public slots:
347+ void loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha);
348+ void playVideo(const QString& id);
349+ void pauseVideo(const QString& id);
350+ void stopVideo(const QString& id);
351+ void dropVideo(const QString& id);
352+ void seekVideo(const QString& id, qint64 ms);
353+ void setVideoXY(const QString& id, float x, float y);
354+ void setVideoAlpha(const QString& id, float alpha);
355+ void resizeVideo(const QString& id, float w, float h);
356+ void showVideo(const QString& id, bool show);
357+
358+private:
359+#ifdef HAVE_QT_PHONON
360+ typedef struct {
361+ QWidget *widget;
362+ Phonon::VideoPlayer *player;
363+ QGraphicsProxyWidget *pWidget;
364+ } VideoPlayer;
365+ QMap<QString, VideoPlayer*> videoObjects;
366+#endif
367+
368+};
369+
370+#endif // _STELVIDEOMGR_HPP_
371
372=== modified file 'src/scripting/StelMainScriptAPI.cpp'
373--- src/scripting/StelMainScriptAPI.cpp 2012-02-20 06:15:32 +0000
374+++ src/scripting/StelMainScriptAPI.cpp 2012-06-02 18:10:26 +0000
375@@ -33,6 +33,7 @@
376 #include "StarMgr.hpp"
377 #include "StelApp.hpp"
378 #include "StelAudioMgr.hpp"
379+#include "StelVideoMgr.hpp"
380 #include "StelCore.hpp"
381 #include "StelFileMgr.hpp"
382 #include "StelLocation.hpp"
383@@ -76,6 +77,18 @@
384 connect(this, SIGNAL(requestPauseSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(pauseSound(const QString&)));
385 connect(this, SIGNAL(requestStopSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(stopSound(const QString&)));
386 connect(this, SIGNAL(requestDropSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(dropSound(const QString&)));
387+
388+ connect(this, SIGNAL(requestLoadVideo(const QString&, const QString&, float, float, bool, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(loadVideo(const QString&, const QString&, float, float, bool, float)));
389+ connect(this, SIGNAL(requestPlayVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(playVideo(const QString&)));
390+ connect(this, SIGNAL(requestPauseVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(pauseVideo(const QString&)));
391+ connect(this, SIGNAL(requestStopVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(stopVideo(const QString&)));
392+ connect(this, SIGNAL(requestDropVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(dropVideo(const QString&)));
393+ connect(this, SIGNAL(requestSeekVideo(const QString&, qint64)), StelApp::getInstance().getStelVideoMgr(), SLOT(seekVideo(const QString&, qint64)));
394+ connect(this, SIGNAL(requestSetVideoXY(const QString&, float, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(setVideoXY(const QString&, float, float)));
395+ connect(this, SIGNAL(requestSetVideoAlpha(const QString&, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(setVideoAlpha(const QString&, float)));
396+ connect(this, SIGNAL(requestResizeVideo(const QString&, float, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(resizeVideo(const QString&, float, float)));
397+ connect(this, SIGNAL(requestShowVideo(const QString&, bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(showVideo(const QString&, bool)));
398+
399 connect(this, SIGNAL(requestExit()), this->parent(), SLOT(stopScript()));
400 connect(this, SIGNAL(requestSetNightMode(bool)), &StelApp::getInstance(), SLOT(setVisionModeNight(bool)));
401 connect(this, SIGNAL(requestSetProjectionMode(QString)), StelApp::getInstance().getCore(), SLOT(setCurrentProjectionTypeKey(QString)));
402@@ -385,6 +398,67 @@
403 emit(requestDropSound(id));
404 }
405
406+void StelMainScriptAPI::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha)
407+{
408+ QString path;
409+ try
410+ {
411+ path = StelFileMgr::findFile("scripts/" + filename);
412+ }
413+ catch(std::runtime_error& e)
414+ {
415+ qWarning() << "cannot play video" << filename << ":" << e.what();
416+ return;
417+ }
418+
419+ emit(requestLoadVideo(path, id, x, y, show, alpha));
420+}
421+
422+void StelMainScriptAPI::playVideo(const QString& id)
423+{
424+ emit(requestPlayVideo(id));
425+}
426+
427+void StelMainScriptAPI::pauseVideo(const QString& id)
428+{
429+ emit(requestPauseVideo(id));
430+}
431+
432+void StelMainScriptAPI::stopVideo(const QString& id)
433+{
434+ emit(requestStopVideo(id));
435+}
436+
437+void StelMainScriptAPI::dropVideo(const QString& id)
438+{
439+ emit(requestDropVideo(id));
440+}
441+
442+void StelMainScriptAPI::seekVideo(const QString& id, qint64 ms)
443+{
444+ emit(requestSeekVideo(id, ms));
445+}
446+
447+void StelMainScriptAPI::setVideoXY(const QString& id, float x, float y)
448+{
449+ emit(requestSetVideoXY(id, x, y));
450+}
451+
452+void StelMainScriptAPI::setVideoAlpha(const QString& id, float alpha)
453+{
454+ emit(requestSetVideoAlpha(id, alpha));
455+}
456+
457+void StelMainScriptAPI::resizeVideo(const QString& id, float w, float h)
458+{
459+ emit(requestResizeVideo(id, w, h));
460+}
461+
462+void StelMainScriptAPI::showVideo(const QString& id, bool show)
463+{
464+ emit(requestShowVideo(id, show));
465+}
466+
467 int StelMainScriptAPI::getScreenWidth()
468 {
469 return StelMainGraphicsView::getInstance().size().width();
470
471=== modified file 'src/scripting/StelMainScriptAPI.hpp'
472--- src/scripting/StelMainScriptAPI.hpp 2012-01-11 10:50:37 +0000
473+++ src/scripting/StelMainScriptAPI.hpp 2012-06-02 18:10:26 +0000
474@@ -386,6 +386,63 @@
475 //! @param id the identifier used when loadSound was called
476 void dropSound(const QString& id);
477
478+ //! Load a video from a file.
479+ //! @param filename the name of the file to load.
480+ //! @param id the identifier which will be used to refer to the video
481+ //! when calling playVideo, pauseVideo, stopVideo and dropVideo.
482+ //! @param x the x-coordinate for the video widget.
483+ //! @param y the y-coordinate for the video widget.
484+ //! @param show the visibility state for the video.
485+ //! @param alpha the initial alpha value of the video.
486+ void loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha);
487+
488+ //! Play a video which has previously been loaded with loadVideo
489+ //! @param id the identifier used when loadVideo was called
490+ void playVideo(const QString& id);
491+
492+ //! Pause a video which is playing. Subsequent playVideo calls will
493+ //! resume playing from the position in the file when it was paused.
494+ //! @param id the identifier used when loadVideo was called
495+ void pauseVideo(const QString& id);
496+
497+ //! Stop a video from playing. This resets the position in the
498+ //! video to the start so that subsequent playVideo calls will
499+ //! start from the beginning.
500+ //! @param id the identifier used when loadVideo was called
501+ void stopVideo(const QString& id);
502+
503+ //! Drop a video from memory. You should do this before the end
504+ //! of your script.
505+ //! @param id the identifier used when loadVideo was called
506+ void dropVideo(const QString& id);
507+
508+ //! Seeks a video to the requested time.
509+ //! @param id the identifier used when loadVideo was called
510+ //! @param ms the time in milliseconds from the start of the media.
511+ void seekVideo(const QString& id, qint64 ms);
512+
513+ //! Sets the position of the video widget.
514+ //! @param id the identifier used when loadVideo was called
515+ //! @param x the new x-coordinate for the video.
516+ //! @param y the new y-coordinate for the video.
517+ void setVideoXY(const QString& id, float x, float y);
518+
519+ //! Set the alpha value of a video when visible.
520+ //! @param id the identifier used when loadVideo was called
521+ //! @param alpha the new alpha value to set.
522+ void setVideoAlpha(const QString& id, float alpha);
523+
524+ //! Resize the video widget to the specified width, height.
525+ //! @param id the identifier used when loadVideo was called
526+ //! @param w the new width for the widget.
527+ //! @param h the new height for the widget.
528+ void resizeVideo(const QString& id, float w, float h);
529+
530+ //! Set the visibility state of a video.
531+ //! @param id the identifier used when loadVideo was called
532+ //! @param show the new visible state of the video.
533+ void showVideo(const QString& id, bool show);
534+
535 //! Get the screen width in pixels.
536 //! @return The screen width in pixels
537 int getScreenWidth();
538@@ -452,6 +509,17 @@
539 void requestPauseSound(const QString& id);
540 void requestStopSound(const QString& id);
541 void requestDropSound(const QString& id);
542+ void requestLoadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha);
543+ void requestPlayVideo(const QString& id);
544+ void requestPauseVideo(const QString& id);
545+ void requestStopVideo(const QString& id);
546+ void requestDropVideo(const QString& id);
547+ void requestSeekVideo(const QString& id, qint64 ms);
548+ void requestSetVideoXY(const QString& id, float x, float y);
549+ void requestSetVideoAlpha(const QString& id, float alpha);
550+ void requestResizeVideo(const QString& id, float w, float h);
551+ void requestShowVideo(const QString& id, bool show);
552+
553 void requestSetNightMode(bool b);
554 void requestSetProjectionMode(QString id);
555 void requestSetSkyCulture(QString id);