Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.47 KB | None | 0 0
  1. diff --git a/harbour-advanced-camera.pro b/harbour-advanced-camera.pro
  2. index 536a25a..337222a 100644
  3. --- a/harbour-advanced-camera.pro
  4. +++ b/harbour-advanced-camera.pro
  5. @@ -25,7 +25,8 @@ SOURCES += src/harbour-advanced-camera.cpp \
  6. src/focusmodel.cpp \
  7. src/flashmodel.cpp \
  8. src/fsoperations.cpp \
  9. - src/resourcehandler.cpp
  10. + src/resourcehandler.cpp \
  11. + src/framegrabber.cpp
  12.  
  13. DISTFILES += rpm/harbour-advanced-camera.changes.in \
  14. rpm/harbour-advanced-camera.changes.run.in \
  15. @@ -70,6 +71,7 @@ HEADERS += \
  16. src/focusmodel.h \
  17. src/flashmodel.h \
  18. src/fsoperations.h \
  19. - src/resourcehandler.h
  20. + src/resourcehandler.h \
  21. + src/framegrabber.h
  22.  
  23. LIBS += -ldl
  24. diff --git a/qml/pages/GalleryUI.qml b/qml/pages/GalleryUI.qml
  25. index 67ce167..7f5e33f 100644
  26. --- a/qml/pages/GalleryUI.qml
  27. +++ b/qml/pages/GalleryUI.qml
  28. @@ -8,7 +8,7 @@ import "../components/"
  29. Page {
  30. id: galleryPage
  31.  
  32. - property var fileList: ({})
  33. + property ListModel fileList
  34. property alias showButtons: btnClose.visible
  35.  
  36. // The effective value will be restricted by ApplicationWindow.allowedOrientations
  37. @@ -147,7 +147,7 @@ Page {
  38.  
  39. onClicked: {
  40. pageStack.push(Qt.resolvedUrl("VideoPlayer.qml"),
  41. - { videoFile: filePath },
  42. + { videoFile: filePath, fileList: fileList },
  43. PageStackAction.Immediate);
  44. }
  45. }
  46. diff --git a/qml/pages/VideoPlayer.qml b/qml/pages/VideoPlayer.qml
  47. index 1548682..fc52103 100644
  48. --- a/qml/pages/VideoPlayer.qml
  49. +++ b/qml/pages/VideoPlayer.qml
  50. @@ -1,11 +1,14 @@
  51. import QtQuick 2.0
  52. import Sailfish.Silica 1.0
  53. import QtMultimedia 5.6
  54. +import uk.co.piggz.harbour_advanced_camera 1.0
  55. import "../components/"
  56.  
  57. Page {
  58. id: videoPage
  59.  
  60. + property ListModel fileList
  61. +
  62. // The effective value will be restricted by ApplicationWindow.allowedOrientations
  63. allowedOrientations: Orientation.All
  64.  
  65. @@ -33,12 +36,32 @@ Page {
  66. }
  67. }
  68.  
  69. + FrameGrabber {
  70. + id: frameGrabber
  71. +
  72. + source: null
  73. +
  74. + onSnapshotTaken: {
  75. + console.log("FrameGrabber: finished!");
  76. + source = null;
  77. + //var path = fsOperations.writableLocation("image") + "/AdvancedCam/PIC_" + Qt.formatDateTime(new Date(), "yyyyMMdd_hhmmss") + ".jpg"
  78. + //if (img.save(path))
  79. + //{
  80. + console.log("Snapshot taken:", snapshotPath);
  81. + fileList.append({ filePath: snapshotPath, isVideo: false });
  82. + //}
  83. + //else
  84. + // console.log("Snapshot error!");
  85. + }
  86. + }
  87. +
  88. VideoOutput {
  89. id: video
  90.  
  91. anchors.fill: parent
  92. source: player
  93. fillMode: VideoOutput.PreserveAspectFit
  94. + //filters: [ frameGrabber ]
  95.  
  96. MouseArea {
  97. anchors.fill: parent
  98. @@ -48,6 +71,14 @@ Page {
  99. }
  100. }
  101.  
  102. + Rectangle {
  103. + id: rectFlash
  104. + anchors.fill: parent
  105. + opacity: 0
  106. +
  107. + NumberAnimation on opacity {id:animFlash; from: 1.0; to: 0.0; duration: 200 }
  108. + }
  109. +
  110. Item {
  111. id: itemsControls
  112. anchors.fill: parent
  113. @@ -96,6 +127,26 @@ Page {
  114. }
  115. }
  116.  
  117. + RoundButton {
  118. + id: btnSnapshot
  119. +
  120. + enabled: controlsOpacity > 0
  121. + icon.source: "image://theme/icon-m-camera"
  122. + size: Theme.itemSizeMedium
  123. +
  124. + anchors {
  125. + verticalCenter: parent.verticalCenter
  126. + right: parent.right
  127. + rightMargin: Theme.paddingMedium
  128. + }
  129. +
  130. + onClicked: {
  131. + console.log("Snapshot button clicked!");
  132. + animFlash.start();
  133. + frameGrabber.source = player;
  134. + }
  135. + }
  136. +
  137. Row {
  138. id: rowBottomVideo
  139.  
  140. @@ -131,4 +182,8 @@ Page {
  141. }
  142. }
  143. }
  144. +
  145. + FSOperations {
  146. + id: fsOperations
  147. + }
  148. }
  149. diff --git a/src/framegrabber.cpp b/src/framegrabber.cpp
  150. new file mode 100644
  151. index 0000000..d8f5a41
  152. --- /dev/null
  153. +++ b/src/framegrabber.cpp
  154. @@ -0,0 +1,92 @@
  155. +#include "framegrabber.h"
  156. +#include "fsoperations.h"
  157. +#include <QDate>
  158. +#include <QDebug>
  159. +#include <QImage>
  160. +#include <QMediaPlayer>
  161. +
  162. +FrameGrabber::FrameGrabber(QObject *parent)
  163. + : QVideoProbe(parent), m_source(nullptr)
  164. +{
  165. + connect(this, &QVideoProbe::videoFrameProbed, this, &FrameGrabber::emitVideoFrameProbed);
  166. +}
  167. +
  168. +bool FrameGrabber::setSource(QObject* sourceObj)
  169. +{
  170. + qDebug() << "FrameGrabber: setSource" << sourceObj;
  171. + m_source = sourceObj;
  172. + if (m_source != nullptr)
  173. + {
  174. + QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(sourceObj->property("mediaObject"));
  175. + return QVideoProbe::setSource(player);
  176. + }
  177. + return QVideoProbe::setSource((QMediaRecorder*)0);
  178. +}
  179. +
  180. +void FrameGrabber::emitVideoFrameProbed(const QVideoFrame &buffer)
  181. +{
  182. + if (buffer.isValid())
  183. + {
  184. + //qDebug() << "FrameGrabber: emitVideoFrameProbed is valid";
  185. + QImage img;
  186. + QVideoFrame frame(buffer);
  187. + frame.map(QAbstractVideoBuffer::ReadOnly);
  188. + QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat());
  189. + FSOperations fs;
  190. + QDateTime date = QDateTime::currentDateTime();
  191. + QString path = fs.writableLocation("image") + "/AdvancedCam/PIC_" + date.toString("yyyyMMdd_hhmmss") + ".jpg";
  192. + qDebug() << "Snapshot path:" << path;
  193. + if (format != QImage::Format_Invalid)
  194. + {
  195. + qDebug() << "FrameGrabber: format OK...";
  196. + img = QImage(frame.bits(), frame.width(), frame.height(), format);
  197. + }
  198. + else
  199. + {
  200. + qDebug() << "FrameGrabber: format invalid!" << frame.mappedBytes() << "bytes...";
  201. + img = QImage::fromData(frame.bits(), frame.mappedBytes());
  202. + }
  203. + frame.unmap();
  204. + if (img.save(path))
  205. + emit snapshotTaken(path);
  206. + else
  207. + qWarning() << "FrameGrabber: unable to save image!";
  208. + setSource((QObject*)0);
  209. + }
  210. +}
  211. +/*
  212. +FrameGrabberRunnable::FrameGrabberRunnable(FrameGrabber *filter) :
  213. + m_filter(filter)
  214. +{
  215. + qDebug() << "FrameGrabber constructor !";
  216. +}
  217. +
  218. +QVideoFilterRunnable *FrameGrabber::createFilterRunnable()
  219. +{
  220. + qDebug() << "FrameGrabber::createFilterRunnable() !!!";
  221. + return new FrameGrabberRunnable(this);
  222. +}
  223. +
  224. +QVideoFrame FrameGrabberRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surface, RunFlags flags)
  225. +{
  226. + Q_UNUSED(surface);
  227. + Q_UNUSED(flags);
  228. +
  229. + qDebug() << "FrameGrabberRunnable::run() !!!";
  230. + if (!input->isValid() ||
  231. + (input->handleType() != QAbstractVideoBuffer::NoHandle && input->handleType() != QAbstractVideoBuffer::GLTextureHandle))
  232. + {
  233. + qWarning("Invalid input format");
  234. + return QVideoFrame();
  235. + }
  236. +
  237. + QImage img;
  238. + QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(input->pixelFormat());
  239. + if (format != QImage::Format_Invalid)
  240. + img = QImage(input->bits(), input->width(), input->height(), format);
  241. + else
  242. + img = QImage::fromData(input->bits(), input->mappedBytes());
  243. + emit m_filter->finished(new QImage(img));
  244. + return *input;
  245. +}
  246. +*/
  247. diff --git a/src/framegrabber.h b/src/framegrabber.h
  248. new file mode 100644
  249. index 0000000..a82cc71
  250. --- /dev/null
  251. +++ b/src/framegrabber.h
  252. @@ -0,0 +1,54 @@
  253. +#ifndef FRAMEGRABBER_H
  254. +#define FRAMEGRABBER_H
  255. +
  256. +#include <QVideoProbe>
  257. +
  258. +class FrameGrabber : public QVideoProbe
  259. +{
  260. + Q_OBJECT
  261. + Q_PROPERTY(QObject* source READ source WRITE setSource)
  262. + Q_PROPERTY(bool active READ isActive)
  263. +public:
  264. + explicit FrameGrabber(QObject *parent = 0);
  265. + QObject* source() { return m_source; }
  266. + bool setSource(QObject *);
  267. + //void setActive(bool);
  268. +signals:
  269. + //void flush();
  270. + //void snapshotTaken(const QImage &image);
  271. + void snapshotTaken(const QString &snapshotPath);
  272. +private slots:
  273. + void emitVideoFrameProbed(const QVideoFrame &frame);
  274. +private:
  275. + QObject *m_source;
  276. + bool m_active;
  277. +};
  278. +
  279. +/***
  280. +#include <QAbstractVideoFilter>
  281. +
  282. +class FrameGrabber : public QAbstractVideoFilter
  283. +{
  284. + Q_OBJECT
  285. +public:
  286. + QVideoFilterRunnable *createFilterRunnable() Q_DECL_OVERRIDE ;
  287. +
  288. +signals:
  289. + void finished(QImage *result);
  290. +
  291. +private:
  292. + friend class FrameGrabberRunnable;
  293. +};
  294. +
  295. +class FrameGrabberRunnable : public QVideoFilterRunnable
  296. +{
  297. +public:
  298. + FrameGrabberRunnable(FrameGrabber *filter);
  299. + QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) Q_DECL_OVERRIDE ;
  300. +
  301. +private:
  302. + FrameGrabber *m_filter;
  303. +};
  304. +***/
  305. +
  306. +#endif // FRAMEGRABBER_H
  307. diff --git a/src/harbour-advanced-camera.cpp b/src/harbour-advanced-camera.cpp
  308. index d2b675a..0e52b33 100644
  309. --- a/src/harbour-advanced-camera.cpp
  310. +++ b/src/harbour-advanced-camera.cpp
  311. @@ -17,6 +17,7 @@
  312. #include "flashmodel.h"
  313. #include "fsoperations.h"
  314. #include "resourcehandler.h"
  315. +#include "framegrabber.h"
  316.  
  317. int main(int argc, char *argv[])
  318. {
  319. @@ -40,6 +41,7 @@ int main(int argc, char *argv[])
  320. qmlRegisterType<FocusModel>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FocusModel");
  321. qmlRegisterType<FlashModel>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FlashModel");
  322. qmlRegisterType<FSOperations>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FSOperations");
  323. + qmlRegisterType<FrameGrabber>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FrameGrabber");
  324.  
  325. ResolutionModel resolutionModel;
  326. QSortFilterProxyModel sortedResolutionModel;
  327. diff --git a/translations/harbour-advanced-camera-fr.ts b/translations/harbour-advanced-camera-fr.ts
  328. index a8ca50e..ce9332b 100644
  329. --- a/translations/harbour-advanced-camera-fr.ts
  330. +++ b/translations/harbour-advanced-camera-fr.ts
  331. @@ -296,7 +296,7 @@
  332. <context>
  333. <name>GalleryUI</name>
  334. <message>
  335. - <location filename="../qml/pages/GalleryUI.qml" line="79"/>
  336. + <location filename="../qml/pages/GalleryUI.qml" line="80"/>
  337. <source>Deleting %1</source>
  338. <translation type="unfinished"></translation>
  339. </message>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement