388b6212397289a12a21a9662933493287d1df8f
[harmattan/cameraplus] / declarative / videoplayer.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef VIDEO_PLAYER_H
24 #define VIDEO_PLAYER_H
25
26 #include <QDeclarativeItem>
27 #include <gst/gst.h>
28
29 class CameraConfig;
30 class QtCamGraphicsViewfinder;
31
32 class VideoPlayer : public QDeclarativeItem {
33   Q_OBJECT
34
35   Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged);
36   Q_PROPERTY(CameraConfig *cameraConfig READ cameraConfig WRITE setCameraConfig NOTIFY cameraConfigChanged);
37   Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged);
38   Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged);
39   Q_PROPERTY(State state READ state NOTIFY stateChanged);
40   Q_ENUMS(State);
41
42 public:
43   VideoPlayer(QDeclarativeItem *parent = 0);
44   ~VideoPlayer();
45
46   virtual void componentComplete();
47   virtual void classBegin();
48
49   QUrl source() const;
50   void setSource(const QUrl& source);
51
52   CameraConfig *cameraConfig() const;
53   void setCameraConfig(CameraConfig *config);
54
55   qint64 duration() const;
56   qint64 position();
57   void setPosition(qint64 position);
58
59   Q_INVOKABLE bool pause();
60   Q_INVOKABLE bool play();
61   Q_INVOKABLE bool seek(qint64 offset);
62   Q_INVOKABLE bool stop();
63
64   typedef enum {
65     StateStopped,
66     StatePaused,
67     StatePlaying,
68   } State;
69
70   State state() const;
71
72 signals:
73   void sourceChanged();
74   void cameraConfigChanged();
75
76   void durationChanged();
77   void positionChanged();
78   void error(const QString& message, int code, const QString& debug);
79   void stateChanged();
80
81 protected:
82   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
83
84 private:
85   static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data);
86
87   bool setState(const State& state);
88
89   CameraConfig *m_config;
90   QtCamGraphicsViewfinder *m_vf;
91   QUrl m_url;
92
93   GstElement *m_bin;
94   State m_state;
95   QTimer *m_timer;
96   qint64 m_pos;
97 };
98
99 #endif /* VIDEO_PLAYER_H */