Added the ability to control playback volume from post capture
authorMohammed Sameer <msameer@foolab.org>
Tue, 17 Sep 2013 00:19:06 +0000 (03:19 +0300)
committerMohammed Sameer <msameer@foolab.org>
Tue, 17 Sep 2013 00:19:06 +0000 (03:19 +0300)
declarative/videoplayer.cpp
declarative/videoplayer.h
qml/VideoPlayerPage.qml
src/cameraresources.cpp

index 698d0ed..8ab4017 100644 (file)
@@ -29,6 +29,7 @@
 #include "qtcamviewfinderrenderer.h"
 #include <QPainter>
 #include <QMatrix4x4>
 #include "qtcamviewfinderrenderer.h"
 #include <QPainter>
 #include <QMatrix4x4>
+#include <cmath>
 
 #if defined(QT4)
 VideoPlayer::VideoPlayer(QDeclarativeItem *parent) :
 
 #if defined(QT4)
 VideoPlayer::VideoPlayer(QDeclarativeItem *parent) :
@@ -107,6 +108,7 @@ void VideoPlayer::classBegin() {
     return;
   }
 
     return;
   }
 
+  g_signal_connect (G_OBJECT (m_bin), "notify::volume", G_CALLBACK (on_volume_changed), this);
   g_object_set (m_bin, "flags", 99, NULL);
 
   GstElement *elem = gst_element_factory_make("pulsesink", "VideoPlayerPulseSink");
   g_object_set (m_bin, "flags", 99, NULL);
 
   GstElement *elem = gst_element_factory_make("pulsesink", "VideoPlayerPulseSink");
@@ -430,3 +432,29 @@ gboolean VideoPlayer::bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
 void VideoPlayer::updateRequested() {
   update();
 }
 void VideoPlayer::updateRequested() {
   update();
 }
+
+quint32 VideoPlayer::volume() {
+  double vol = 1.0;
+  g_object_get (m_bin, "volume", &vol, NULL);
+
+  qint32 res = (int)round(vol * 100.0);
+
+  return res;
+}
+
+void VideoPlayer::setVolume(quint32 volume) {
+  if (VideoPlayer::volume() != volume) {
+    double vol = volume / 100.0;
+    g_object_set (m_bin, "volume", vol, NULL);
+    emit volumeChanged();
+  }
+}
+
+void VideoPlayer::on_volume_changed(GObject *object, GParamSpec *pspec, gpointer user_data) {
+  Q_UNUSED(object);
+  Q_UNUSED(pspec);
+
+  VideoPlayer *player = (VideoPlayer *) user_data;
+
+  QMetaObject::invokeMethod(player, "volumeChanged", Qt::QueuedConnection);
+}
index d944b3b..c8aeb97 100644 (file)
@@ -47,6 +47,7 @@ class VideoPlayer : public QQuickPaintedItem {
   Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged);
   Q_PROPERTY(State state READ state NOTIFY stateChanged);
   Q_ENUMS(State);
   Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged);
   Q_PROPERTY(State state READ state NOTIFY stateChanged);
   Q_ENUMS(State);
+  Q_PROPERTY(quint32 volume READ volume WRITE setVolume NOTIFY volumeChanged);
 
 public:
 
 
 public:
 
@@ -90,6 +91,9 @@ public:
 
   State state() const;
 
 
   State state() const;
 
+  quint32 volume();
+  void setVolume(quint32 volume);
+
 signals:
   void sourceChanged();
   void cameraConfigChanged();
 signals:
   void sourceChanged();
   void cameraConfigChanged();
@@ -98,6 +102,7 @@ signals:
   void positionChanged();
   void error(const QString& message, int code, const QString& debug);
   void stateChanged();
   void positionChanged();
   void error(const QString& message, int code, const QString& debug);
   void stateChanged();
+  void volumeChanged();
 
 protected:
   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
 
 protected:
   void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
@@ -107,6 +112,7 @@ private slots:
 
 private:
   static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data);
 
 private:
   static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data);
+  static void on_volume_changed(GObject *object, GParamSpec *pspec, gpointer user_data);
 
   bool setState(const State& state);
 
 
   bool setState(const State& state);
 
index 2e310bf..8d78df3 100644 (file)
@@ -55,7 +55,44 @@ Item {
         onTriggered: toolBar.show = false
     }
 
         onTriggered: toolBar.show = false
     }
 
+    DeviceKeys {
+        id: zoomKeys
+        active: Qt.application.active && pipelineManager.scaleAcquired
+        repeat: true
+
+        onVolumeUpPressed: {
+            timer.restart()
+            video.volume = Math.min(video.volume + 2, 100)
+        }
+
+        onVolumeDownPressed: {
+            timer.restart()
+            video.volume = Math.max(video.volume - 2, 0)
+        }
+    }
+
     VideoPlayer {
     VideoPlayer {
+        Rectangle {
+            id: volumeControl
+            anchors.top: parent.top
+            anchors.left: parent.left
+            width: (parent.width * video.volume) / 100
+            color: "blue"
+            border.color: "black"
+            height: 25
+            opacity: timer.running ? 1.0 : 0.0
+
+            Behavior on opacity {
+                NumberAnimation { duration: 250 }
+            }
+
+            Timer {
+                id: timer
+                interval: 500
+                repeat: false
+            }
+        }
+
         id: video
         anchors.fill: parent
         cameraConfig: camera.cameraConfig
         id: video
         anchors.fill: parent
         cameraConfig: camera.cameraConfig
index 91b06d7..cbaed5c 100644 (file)
@@ -225,7 +225,8 @@ void CameraResourcesWorker::acquire(bool *ok, const CameraResources::Mode& mode)
     *ok = updateSet(QList<ResourcePolicy::ResourceType>()
                    << ResourcePolicy::VideoPlaybackType
                    << ResourcePolicy::AudioPlaybackType,
     *ok = updateSet(QList<ResourcePolicy::ResourceType>()
                    << ResourcePolicy::VideoPlaybackType
                    << ResourcePolicy::AudioPlaybackType,
-                   QList<ResourcePolicy::ResourceType>());
+                   QList<ResourcePolicy::ResourceType>()
+                   << ResourcePolicy::ScaleButtonType);
     break;
 
   default:
     break;
 
   default: