aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-fm
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-10-04 09:52:01 -0400
committerKen Moore <ken@ixsystems.com>2017-10-04 09:52:01 -0400
commit15d8dac497768350ea429d6c6682ed9723d0464c (patch)
treeb6238a9d934b8aca88122306fa1f90f06cc394fe /src-qt5/desktop-utils/lumina-fm
parentFinish up the auto archive/extract within lumina-archiver (with JT) (diff)
parentFurther lumina-fm changes for video thumbnails (diff)
downloadlumina-15d8dac497768350ea429d6c6682ed9723d0464c.tar.gz
lumina-15d8dac497768350ea429d6c6682ed9723d0464c.tar.bz2
lumina-15d8dac497768350ea429d6c6682ed9723d0464c.zip
Merge branch 'master' of github.com:trueos/lumina
Diffstat (limited to 'src-qt5/desktop-utils/lumina-fm')
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.cpp70
-rw-r--r--src-qt5/desktop-utils/lumina-fm/Browser.h13
-rw-r--r--src-qt5/desktop-utils/lumina-fm/lumina-fm.pro1
-rw-r--r--src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp72
-rw-r--r--src-qt5/desktop-utils/lumina-fm/widgets/vidnail.h38
5 files changed, 125 insertions, 69 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.cpp b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
index f2bdc178..211ef8d0 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.cpp
@@ -16,10 +16,13 @@
Browser::Browser(QObject *parent) : QObject(parent){
watcher = new QFileSystemWatcher(this);
connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(QString)) );
- connect(watcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(dirChanged(QString)) );
+ connect(watcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(dirChanged(QString)) );
showHidden = false;
showThumbs = false;
imageFormats = LUtils::imageExtensions(false); //lowercase suffixes
+ videoFormats = LUtils::videoExtensions(); //lowercase suffixes
+ //connect(surface, SIGNAL(frameReceived(QImage)), this, SLOT(captureFrame(QImage)));
+ //connect(player, &QMediaPlayer::mediaStatusChanged, this, [&]{ stopVideo(player, player->mediaStatus()); });
connect(this, SIGNAL(threadDone(QString, QImage)), this, SLOT(futureFinished(QString, QImage))); //will always be between different threads
}
@@ -60,21 +63,20 @@ void Browser::loadItem(QString info, Browser *obj){
file.close();
pix.loadFromData(bytes);
if(pix.width() > 256 || pix.height() > 256 ){
- pix = pix.scaled(256,256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ pix = pix.scaled(256,256, Qt::KeepAspectRatio);
}
}
}
-
- //qDebug() << " - done with item:" << info;
+ qDebug() << " - done with item:" << info;
obj->emit threadDone(info, pix);
}
-QIcon Browser::loadIcon(QString icon){
+QIcon* Browser::loadIcon(QString icon){
if(!mimeIcons.contains(icon)){
mimeIcons.insert(icon, LXDG::findIcon(icon, "unknown"));
}
- return mimeIcons[icon];
+ return &mimeIcons[icon];
}
@@ -92,24 +94,58 @@ void Browser::dirChanged(QString dir){
else if(dir.startsWith(currentDir)){ QtConcurrent::run(this, &Browser::loadItem, dir, this ); }
}
+void Browser::stopVideo(QMediaPlayer *player, QMediaPlayer::MediaStatus status) {
+ //qDebug() << status;
+ if(status == QMediaPlayer::BufferedMedia) {
+ qDebug() << "stoppingVideo" << player << player->currentMedia().canonicalUrl();
+ player->setPosition(player->duration() / 2);
+ player->pause();
+ }
+}
+
+void Browser::captureFrame(QPixmap pix, QIcon *ico) {
+ qDebug() << "grabbing frame";
+ *ico = pix.scaledToHeight(64);
+ emit frameChanged();
+}
+
void Browser::futureFinished(QString name, QImage icon){
//Note: this will be called once for every item that loads
- QIcon ico;
- //LFileInfo info(name);
+ QIcon *ico = new QIcon();
LFileInfo *info = new LFileInfo(name);
if(!icon.isNull() && showThumbs){
- //qDebug() << " -- Data:";
QPixmap pix = QPixmap::fromImage(icon);
- ico.addPixmap(pix);
- //}else if(info->isDir()){
- //qDebug() << " -- Folder:";
- //ico = loadIcon("folder");
+ ico->addPixmap(pix);
}
- if(ico.isNull()){
- //qDebug() << " -- MimeType:" << info.fileName() << info.mimetype();
- ico = loadIcon(info->iconfile());
+ if(ico->isNull()){
+ if(videoFormats.contains(name.section(".",-1).toLower())) {
+ qDebug() << "Loading Video for" << name;
+ //qDebug() << "VIDEO" << info;
+ QMediaPlayer *player = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
+ qDebug() << " - created player";
+ LVideoSurface *surface = new LVideoSurface();
+ qDebug() << " - Create objects";
+ connect(surface, &LVideoSurface::frameReceived, this, [&] (QPixmap pix) { captureFrame(pix, ico); });
+ connect(player, &QMediaPlayer::mediaStatusChanged, this, [&]{ stopVideo(player, player->mediaStatus()); });
+ player->setVideoOutput(surface);
+ player->setMuted(true);
+ player->setMedia(QUrl("file://"+info->absoluteFilePath()));
+ player->play();
+ player->pause();
+
+ QEventLoop loop;
+ connect(this, SIGNAL(frameChanged()), &loop, SLOT(quit()));
+ loop.exec();
+
+ ico->addPixmap(videoFrame);
+ //ico = loadIcon(info->iconfile());
+ delete player;
+ delete surface;
+ }else {
+ ico = loadIcon(info->iconfile());
+ }
}
- this->emit itemDataAvailable( ico, info);
+ this->emit itemDataAvailable( *ico, info);
//qDebug() << " -- done:" << name;
}
diff --git a/src-qt5/desktop-utils/lumina-fm/Browser.h b/src-qt5/desktop-utils/lumina-fm/Browser.h
index 94f6ba3f..379753ab 100644
--- a/src-qt5/desktop-utils/lumina-fm/Browser.h
+++ b/src-qt5/desktop-utils/lumina-fm/Browser.h
@@ -15,6 +15,8 @@
#include <QIcon>
//#include <QFutureWatcher>
+#include <QMediaPlayer>
+#include <LVideoSurface.h>
#include <LuminaXDG.h>
/*class FileItem{
public:
@@ -43,22 +45,23 @@ public:
private:
QString currentDir;
QFileSystemWatcher *watcher;
+ QPixmap videoFrame;
bool showHidden, showThumbs;
- QStringList imageFormats, oldFiles;
+ QStringList imageFormats, videoFormats, oldFiles;
QHash<QString, QIcon> mimeIcons; //cache for quickly re-using QIcons
void loadItem(QString info, Browser *obj); //this is the main loader class - multiple instances each run in a separate thread
- QIcon loadIcon(QString icon); //simplification for using/populating the mimIcons cache
+ QIcon* loadIcon(QString icon); //simplification for using/populating the mimIcons cache
private slots:
void fileChanged(QString); //tied into the watcher - for file change notifications
void dirChanged(QString); // tied into the watcher - for new/removed files in the current dir
-
+ void captureFrame(QPixmap, QIcon*);
+ void stopVideo(QMediaPlayer*, QMediaPlayer::MediaStatus);
void futureFinished(QString, QImage);
public slots:
void loadDirectory(QString dir = "");
-
signals:
//Main Signals
void itemRemoved(QString item); //emitted if a file was removed from the underlying
@@ -70,6 +73,8 @@ signals:
//Internal signal for the alternate threads
void threadDone(QString, QImage);
+
+ void frameChanged();
};
#endif
diff --git a/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro b/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro
index 6c340e14..6cb4a537 100644
--- a/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro
+++ b/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro
@@ -15,6 +15,7 @@ include(../../core/libLumina/LuminaXDG.pri)
include(../../core/libLumina/LuminaSingleApplication.pri)
include(../../core/libLumina/LuminaThemes.pri)
include(../../core/libLumina/ExternalProcess.pri)
+include(../../core/libLumina/LVideoSurface.pri)
SOURCES += main.cpp \
MainUI.cpp \
diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp b/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp
index ee7fb9e3..d0ecdecf 100644
--- a/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp
+++ b/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.cpp
@@ -1,33 +1,59 @@
-#include "vidnail.h"
-vidnail::vidnail(QWidget *parent) : QMainWindow(parent), mplayer(parent, QMediaPlayer::VideoSurface){ //there is no UI, so not sure how to alter the constructor
+#ifndef VIDNAIL_H
+#define VIDNAIL_H
+
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
}
-vidnail::~vidnail()
-{
+class VidNail;
-vidnail::grabvideothumbnail(){
- vsurface = new QAbstractVideoSurface();
- mplayer.setVideoOutput(vsurface);
- mplayer.setMedia($file); // video file to get thumbnail of
- imageCaptured = QPixmap();
- mplayer.setPosition(2000); // time in milliseconds
- mplayer.setMuted(true); // just to make sure no sound is emited
- mplayer.play();
+struct vFrame {
+ vFrame() : *width(0), *height(0) {}
+ vFrame(int *width, int *height : width(width), height(height) {}
+ int *width;
+ int *height;
+};
- currentFrame = frame;
- const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
- const QSize size = format.frameSize();
+public:
- this->imageFormat = imageFormat;
- QAbstractVideoSurface::start(format);
- QImage image( currentFrame.bits(), currentFrame.width(), currentFrame.height(), currentFrame.bytesPerLine(), imageFormat);
- imageCaptured = QPixmap::fromImage(image.copy(image.rect()));
+ QString getCodec();
+ void skipTo(int timeInSeconds);
+ void readVideoFrame();
+ void getScaledVideoFrame(int scaledSize, vFrame& vFrame);
-// Now do scaling with regular thumbnail process to make proper size
+ int getWidth();
+ int getHeight();
+ int getLength();
+
+ void makeThumbnail(const QString& videoFile, QImage &image);
+ void setThumbnailSize(int size);
+ void setPercentage(int percent);
+ void setTime(const QString& Time);
+
+ void writeVidNail(vFrame& frame, QImage& image);
+
+
+ private:
+ bool readVideoPacket();
+ bool getVideoPacket();
+ void scaleVideo(int scaledSize, int& scaledWidth, int& scaledHeight);
+ void createVFrame(AVFrame *vFrame, quint8 *frameBuffer, int width, int height);
+ void calculateDimensions(int size);
+ void generateThumbnail(const QString& videoFile, ImageWriter& imageWriter, QImage& image);
+ QString getMimeType(const QString& videoFile);
+ QString getExtension(const QString& videoFilename);
- mplayer.stop();
- vsurface.stop();
-}
+ private:
+ int videoStream;
+ AVFormatContext *inputVideoFormatContext;
+ AVCodecContext *inputvideoCodecContext;
+ AVCodec *inputVideoCodec;
+ AVStream *inputVideoStream;
+ AVFrame *inputVideoFrame;
+ quint8 *inputFrameBuffer;
+ AVPacket *videoPacket;
+#endif // VIDNAIL_H
diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.h b/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.h
index ad565749..e13894e1 100644
--- a/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.h
+++ b/src-qt5/desktop-utils/lumina-fm/widgets/vidnail.h
@@ -1,25 +1,13 @@
-#ifndef VIDNAIL_H
-#define VIDNAIL_H
-
-#include <QMediaPlayer>
-#include <QtMultimediaWidgets>
-#include "videowidgetsurface.h"
-#include <QPixmap>
-#include <QAbstractVideoSurface>
-#include <QImage>
-#include <QRect>
-#include <QVideoFrame>
-
-public:
-
- void grabvideothumbnail();
-
-private:
-
- QAbstractVideoSurface *vsurface;
- QImage::Format imageFormat;
- QPixmap imageCaptured;
-
-
-#endif // VIDNAIL_H
-
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2017, q5sys
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "vidnail.h"
+
+VidNail::VidNail(QObject *parent) : QObject(parent){
+}
+
+VidNail::~VidNail(){
+}
bgstack15