Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/harbour-advanced-camera.pro b/harbour-advanced-camera.pro
- index 536a25a..337222a 100644
- --- a/harbour-advanced-camera.pro
- +++ b/harbour-advanced-camera.pro
- @@ -25,7 +25,8 @@ SOURCES += src/harbour-advanced-camera.cpp \
- src/focusmodel.cpp \
- src/flashmodel.cpp \
- src/fsoperations.cpp \
- - src/resourcehandler.cpp
- + src/resourcehandler.cpp \
- + src/framegrabber.cpp
- DISTFILES += rpm/harbour-advanced-camera.changes.in \
- rpm/harbour-advanced-camera.changes.run.in \
- @@ -70,6 +71,7 @@ HEADERS += \
- src/focusmodel.h \
- src/flashmodel.h \
- src/fsoperations.h \
- - src/resourcehandler.h
- + src/resourcehandler.h \
- + src/framegrabber.h
- LIBS += -ldl
- diff --git a/qml/pages/GalleryUI.qml b/qml/pages/GalleryUI.qml
- index 67ce167..7f5e33f 100644
- --- a/qml/pages/GalleryUI.qml
- +++ b/qml/pages/GalleryUI.qml
- @@ -8,7 +8,7 @@ import "../components/"
- Page {
- id: galleryPage
- - property var fileList: ({})
- + property ListModel fileList
- property alias showButtons: btnClose.visible
- // The effective value will be restricted by ApplicationWindow.allowedOrientations
- @@ -147,7 +147,7 @@ Page {
- onClicked: {
- pageStack.push(Qt.resolvedUrl("VideoPlayer.qml"),
- - { videoFile: filePath },
- + { videoFile: filePath, fileList: fileList },
- PageStackAction.Immediate);
- }
- }
- diff --git a/qml/pages/VideoPlayer.qml b/qml/pages/VideoPlayer.qml
- index 1548682..fc52103 100644
- --- a/qml/pages/VideoPlayer.qml
- +++ b/qml/pages/VideoPlayer.qml
- @@ -1,11 +1,14 @@
- import QtQuick 2.0
- import Sailfish.Silica 1.0
- import QtMultimedia 5.6
- +import uk.co.piggz.harbour_advanced_camera 1.0
- import "../components/"
- Page {
- id: videoPage
- + property ListModel fileList
- +
- // The effective value will be restricted by ApplicationWindow.allowedOrientations
- allowedOrientations: Orientation.All
- @@ -33,12 +36,32 @@ Page {
- }
- }
- + FrameGrabber {
- + id: frameGrabber
- +
- + source: null
- +
- + onSnapshotTaken: {
- + console.log("FrameGrabber: finished!");
- + source = null;
- + //var path = fsOperations.writableLocation("image") + "/AdvancedCam/PIC_" + Qt.formatDateTime(new Date(), "yyyyMMdd_hhmmss") + ".jpg"
- + //if (img.save(path))
- + //{
- + console.log("Snapshot taken:", snapshotPath);
- + fileList.append({ filePath: snapshotPath, isVideo: false });
- + //}
- + //else
- + // console.log("Snapshot error!");
- + }
- + }
- +
- VideoOutput {
- id: video
- anchors.fill: parent
- source: player
- fillMode: VideoOutput.PreserveAspectFit
- + //filters: [ frameGrabber ]
- MouseArea {
- anchors.fill: parent
- @@ -48,6 +71,14 @@ Page {
- }
- }
- + Rectangle {
- + id: rectFlash
- + anchors.fill: parent
- + opacity: 0
- +
- + NumberAnimation on opacity {id:animFlash; from: 1.0; to: 0.0; duration: 200 }
- + }
- +
- Item {
- id: itemsControls
- anchors.fill: parent
- @@ -96,6 +127,26 @@ Page {
- }
- }
- + RoundButton {
- + id: btnSnapshot
- +
- + enabled: controlsOpacity > 0
- + icon.source: "image://theme/icon-m-camera"
- + size: Theme.itemSizeMedium
- +
- + anchors {
- + verticalCenter: parent.verticalCenter
- + right: parent.right
- + rightMargin: Theme.paddingMedium
- + }
- +
- + onClicked: {
- + console.log("Snapshot button clicked!");
- + animFlash.start();
- + frameGrabber.source = player;
- + }
- + }
- +
- Row {
- id: rowBottomVideo
- @@ -131,4 +182,8 @@ Page {
- }
- }
- }
- +
- + FSOperations {
- + id: fsOperations
- + }
- }
- diff --git a/src/framegrabber.cpp b/src/framegrabber.cpp
- new file mode 100644
- index 0000000..d8f5a41
- --- /dev/null
- +++ b/src/framegrabber.cpp
- @@ -0,0 +1,92 @@
- +#include "framegrabber.h"
- +#include "fsoperations.h"
- +#include <QDate>
- +#include <QDebug>
- +#include <QImage>
- +#include <QMediaPlayer>
- +
- +FrameGrabber::FrameGrabber(QObject *parent)
- + : QVideoProbe(parent), m_source(nullptr)
- +{
- + connect(this, &QVideoProbe::videoFrameProbed, this, &FrameGrabber::emitVideoFrameProbed);
- +}
- +
- +bool FrameGrabber::setSource(QObject* sourceObj)
- +{
- + qDebug() << "FrameGrabber: setSource" << sourceObj;
- + m_source = sourceObj;
- + if (m_source != nullptr)
- + {
- + QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(sourceObj->property("mediaObject"));
- + return QVideoProbe::setSource(player);
- + }
- + return QVideoProbe::setSource((QMediaRecorder*)0);
- +}
- +
- +void FrameGrabber::emitVideoFrameProbed(const QVideoFrame &buffer)
- +{
- + if (buffer.isValid())
- + {
- + //qDebug() << "FrameGrabber: emitVideoFrameProbed is valid";
- + QImage img;
- + QVideoFrame frame(buffer);
- + frame.map(QAbstractVideoBuffer::ReadOnly);
- + QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat());
- + FSOperations fs;
- + QDateTime date = QDateTime::currentDateTime();
- + QString path = fs.writableLocation("image") + "/AdvancedCam/PIC_" + date.toString("yyyyMMdd_hhmmss") + ".jpg";
- + qDebug() << "Snapshot path:" << path;
- + if (format != QImage::Format_Invalid)
- + {
- + qDebug() << "FrameGrabber: format OK...";
- + img = QImage(frame.bits(), frame.width(), frame.height(), format);
- + }
- + else
- + {
- + qDebug() << "FrameGrabber: format invalid!" << frame.mappedBytes() << "bytes...";
- + img = QImage::fromData(frame.bits(), frame.mappedBytes());
- + }
- + frame.unmap();
- + if (img.save(path))
- + emit snapshotTaken(path);
- + else
- + qWarning() << "FrameGrabber: unable to save image!";
- + setSource((QObject*)0);
- + }
- +}
- +/*
- +FrameGrabberRunnable::FrameGrabberRunnable(FrameGrabber *filter) :
- + m_filter(filter)
- +{
- + qDebug() << "FrameGrabber constructor !";
- +}
- +
- +QVideoFilterRunnable *FrameGrabber::createFilterRunnable()
- +{
- + qDebug() << "FrameGrabber::createFilterRunnable() !!!";
- + return new FrameGrabberRunnable(this);
- +}
- +
- +QVideoFrame FrameGrabberRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surface, RunFlags flags)
- +{
- + Q_UNUSED(surface);
- + Q_UNUSED(flags);
- +
- + qDebug() << "FrameGrabberRunnable::run() !!!";
- + if (!input->isValid() ||
- + (input->handleType() != QAbstractVideoBuffer::NoHandle && input->handleType() != QAbstractVideoBuffer::GLTextureHandle))
- + {
- + qWarning("Invalid input format");
- + return QVideoFrame();
- + }
- +
- + QImage img;
- + QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(input->pixelFormat());
- + if (format != QImage::Format_Invalid)
- + img = QImage(input->bits(), input->width(), input->height(), format);
- + else
- + img = QImage::fromData(input->bits(), input->mappedBytes());
- + emit m_filter->finished(new QImage(img));
- + return *input;
- +}
- +*/
- diff --git a/src/framegrabber.h b/src/framegrabber.h
- new file mode 100644
- index 0000000..a82cc71
- --- /dev/null
- +++ b/src/framegrabber.h
- @@ -0,0 +1,54 @@
- +#ifndef FRAMEGRABBER_H
- +#define FRAMEGRABBER_H
- +
- +#include <QVideoProbe>
- +
- +class FrameGrabber : public QVideoProbe
- +{
- + Q_OBJECT
- + Q_PROPERTY(QObject* source READ source WRITE setSource)
- + Q_PROPERTY(bool active READ isActive)
- +public:
- + explicit FrameGrabber(QObject *parent = 0);
- + QObject* source() { return m_source; }
- + bool setSource(QObject *);
- + //void setActive(bool);
- +signals:
- + //void flush();
- + //void snapshotTaken(const QImage &image);
- + void snapshotTaken(const QString &snapshotPath);
- +private slots:
- + void emitVideoFrameProbed(const QVideoFrame &frame);
- +private:
- + QObject *m_source;
- + bool m_active;
- +};
- +
- +/***
- +#include <QAbstractVideoFilter>
- +
- +class FrameGrabber : public QAbstractVideoFilter
- +{
- + Q_OBJECT
- +public:
- + QVideoFilterRunnable *createFilterRunnable() Q_DECL_OVERRIDE ;
- +
- +signals:
- + void finished(QImage *result);
- +
- +private:
- + friend class FrameGrabberRunnable;
- +};
- +
- +class FrameGrabberRunnable : public QVideoFilterRunnable
- +{
- +public:
- + FrameGrabberRunnable(FrameGrabber *filter);
- + QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) Q_DECL_OVERRIDE ;
- +
- +private:
- + FrameGrabber *m_filter;
- +};
- +***/
- +
- +#endif // FRAMEGRABBER_H
- diff --git a/src/harbour-advanced-camera.cpp b/src/harbour-advanced-camera.cpp
- index d2b675a..0e52b33 100644
- --- a/src/harbour-advanced-camera.cpp
- +++ b/src/harbour-advanced-camera.cpp
- @@ -17,6 +17,7 @@
- #include "flashmodel.h"
- #include "fsoperations.h"
- #include "resourcehandler.h"
- +#include "framegrabber.h"
- int main(int argc, char *argv[])
- {
- @@ -40,6 +41,7 @@ int main(int argc, char *argv[])
- qmlRegisterType<FocusModel>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FocusModel");
- qmlRegisterType<FlashModel>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FlashModel");
- qmlRegisterType<FSOperations>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FSOperations");
- + qmlRegisterType<FrameGrabber>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FrameGrabber");
- ResolutionModel resolutionModel;
- QSortFilterProxyModel sortedResolutionModel;
- diff --git a/translations/harbour-advanced-camera-fr.ts b/translations/harbour-advanced-camera-fr.ts
- index a8ca50e..ce9332b 100644
- --- a/translations/harbour-advanced-camera-fr.ts
- +++ b/translations/harbour-advanced-camera-fr.ts
- @@ -296,7 +296,7 @@
- <context>
- <name>GalleryUI</name>
- <message>
- - <location filename="../qml/pages/GalleryUI.qml" line="79"/>
- + <location filename="../qml/pages/GalleryUI.qml" line="80"/>
- <source>Deleting %1</source>
- <translation type="unfinished"></translation>
- </message>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement