[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdereview/mplayerthumbs/src
From: Marco Gulino <marco () kmobiletools ! org>
Date: 2009-04-07 9:41:57
Message-ID: 1239097317.589660.23404.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 950475 by gulino:
More refactoring, introduced the file to preview as a "PreviewingFile" \
object, moving in it some responsibilities.
M +1 -1 CMakeLists.txt
A constants.h [License: LGPL (v2)]
M +33 -37 mplayervideobackend.cpp
M +7 -4 mplayervideobackend.h
A previewingfile.cpp [License: LGPL (v2)]
A previewingfile.h [License: LGPL (v2)]
M +8 -3 videobackendiface.cpp
M +8 -9 videobackendiface.h
M +9 -33 videopreview.cpp
M +0 -6 videopreview.h
--- trunk/kdereview/mplayerthumbs/src/CMakeLists.txt #950474:950475
@@ -3,7 +3,7 @@
########### next target ###############
-set(videopreview_PART_SRCS videopreview.cpp mplayervideobackend.cpp \
videobackendiface.cpp) +set(videopreview_PART_SRCS videopreview.cpp \
mplayervideobackend.cpp videobackendiface.cpp previewingfile.cpp)
kde4_add_kcfg_files(videopreview_PART_SRCS mplayerthumbs.kcfgc)
--- trunk/kdereview/mplayerthumbs/src/mplayervideobackend.cpp \
#950474:950475 @@ -15,7 +15,7 @@
*/
#include "mplayervideobackend.h"
-
+#include "constants.h"
#include <kdebug.h>
#include <QDir>
#include <KMD5>
@@ -24,51 +24,46 @@
#include "mplayerthumbscfg.h"
#include <kstandarddirs.h>
#include <krandomsequence.h>
+#include "previewingfile.h"
-MPlayerVideoBackend::MPlayerVideoBackend(const QString& filePath, \
MPlayerThumbsCfg* cfg)
- : VideoBackendIFace(filePath, cfg)
+MPlayerVideoBackend::MPlayerVideoBackend(PreviewingFile *previewingfile, \
MPlayerThumbsCfg* cfg) + : VideoBackendIFace(previewingfile, cfg)
{
}
-VideoPreview::FileInformation MPlayerVideoBackend::findFileInfo() {
- VideoPreview::FileInformation fileinfo;
- fileinfo.seconds=0;
- fileinfo.fps=0;
- fileinfo.isValid=false;
-
+bool MPlayerVideoBackend::readStreamInformation() {
tmpdir=new KTempDir();
- if(tmpdir->name().isNull() ) return fileinfo;
+ if(tmpdir->name().isNull() ) return false;
kDebug(DBG_AREA) << "videopreview: using temp directory " << \
tmpdir->name() << endl;
rand=new KRandomSequence(QDateTime::currentDateTime().toTime_t());
mplayerprocess=new QProcess();
- KUrl furl(this->s_filePath);
+ KUrl furl( previewingFile->getFilePath() );
kDebug(DBG_AREA) << "videopreview: url=" << furl << "; local:" << \
furl.isLocalFile() << endl;
QStringList args;
- args << playerBin << QString("\"" + this->s_filePath + "\"") << \
"-nocache" << "-identify" << "-vo" << "null" << "-frames" << "0"/* << \
"-nosound" */<< "-ao" << "null"; + args << playerBin << QString("\"" + \
previewingFile->getFilePath() + "\"") << "-nocache" << "-identify" << "-vo" \
<< "null" << "-frames" << "0"/* << "-nosound" */<< "-ao" << "null"; args+= \
customargs;
kDebug(DBG_AREA) << "videopreview: starting process: --_" << " " << \
args.join(" ") << "_--\n";
- if (! startAndWaitProcess(args) ) return fileinfo;
+ if (! startAndWaitProcess(args) ) return false;
QString information=QString(mplayerprocess->readAllStandardOutput() );
QRegExp findInfos("ID_VIDEO_FPS=([\\d]*).*ID_LENGTH=([\\d]*).*");
if(findInfos.indexIn( information) == -1 )
{
kDebug(DBG_AREA) << "videopreview: No information found, \
exiting\n";
- return fileinfo;
+ return false;
}
- fileinfo.seconds =findInfos.cap(2).toInt();
- fileinfo.fps=findInfos.cap(1).toInt();
+ previewingFile->setStreamInformation(findInfos.cap(1).toInt(), \
findInfos.cap(2).toInt());
- kDebug(DBG_AREA) << "videopreview: find length=" << fileinfo.seconds \
<< ", fps=" << fileinfo.fps << endl;
- fileinfo.isValid=true;
- return fileinfo;
+ kDebug(DBG_AREA) << "videopreview: find length=" << \
previewingFile->getSecondsLength() << ", fps=" << previewingFile->getFPS() \
<< endl; + return true;
}
+
MPlayerVideoBackend::~MPlayerVideoBackend() {
delete mplayerprocess;
delete rand;
@@ -78,40 +73,41 @@
-QPixmap MPlayerVideoBackend::getVideoFrame(int flags, \
VideoPreview::FileInformation fileinfo) { +QPixmap \
MPlayerVideoBackend::getVideoFrame(int flags) { QStringList args;
kDebug(DBG_AREA) << "videopreview: using flags " << flags << endl;
-#define START ((fileinfo.seconds*15)/100)
-#define END ((fileinfo.seconds*70)/100)
+#define START ((previewingFile->getSecondsLength()*15)/100)
+#define END ((previewingFile->getSecondsLength()*70)/100)
args.clear();
- args << playerBin << "\"" + this->s_filePath + "\"";
- if(fileinfo.towidth>fileinfo.toheight) fileinfo.toheight=-2; else \
fileinfo.towidth=-2;
-// switch( flags ){
-// case random
-// }
- if( flags & VideoPreview::framerandom )
+ int scalingWidth=previewingFile->getScalingWidth();
+ int scalingHeight=previewingFile->getScalingHeight();
+ int fps=previewingFile->getFPS();
+ args << playerBin << "\"" + previewingFile->getFilePath() + "\"";
+ if(previewingFile->isWide()) scalingHeight=-2; else scalingWidth=-2;
+
+ if( flags & Preview::framerandom )
{
kDebug(DBG_AREA) << "videopreview: framerandom\n";
unsigned long start=(unsigned long)(START+(rand->getDouble() * \
(END - START) ) ); args << "-ss" << QString::number( start )
<< "-frames" << "4";
- } else if (flags & VideoPreview::frameend )
+ } else if (flags & Preview::frameend )
{
kDebug(DBG_AREA) << "videopreview: frameend\n";
- args << "-ss" << QString::number( fileinfo.seconds - 10 )
+ args << "-ss" << QString::number( \
previewingFile->getSecondsLength() - 10 ) << "-frames" << "4";
- } else if (flags & VideoPreview::framestart)
+ } else if (flags & Preview::framestart)
{
kDebug(DBG_AREA) << "videopreview: framestart\n";
- if(!fileinfo.fps) fileinfo.fps=25; // if we've not autodetected a \
fps rate, let's assume 25fps.. even if it's wrong it shouldn't hurt. + \
if(!fps) fps=25; // if we've not autodetected a fps rate, let's assume \
25fps.. even if it's wrong it shouldn't hurt.
// If we can't skip to a random frame, let's try playing 10 \
seconds.
- args << "-frames" << QString::number( fileinfo.fps*10 );
+ args << "-frames" << QString::number( fps*10 );
}
- KMD5 md5builder(this->s_filePath.toLatin1() );
+ KMD5 md5builder(previewingFile->getFilePath().toLatin1() );
QString md5file=md5builder.hexDigest().data();
QString tmpDirPath = tmpdir->name() + md5file + QDir::separator();
args << "-nocache" << "-idx" /*@TODO check if it's too slow..*/ << \
"-ao" << "null"/*"-nosound" << */<< "-speed" << "99" /*<< "-sstep" << \
"5"*/
- << "-vo" << QString("jpeg:outdir=%1").arg(tmpDirPath ) << \
"-vf" << QString("scale=%1:%2").arg(fileinfo.towidth).arg(fileinfo.toheight);
+ << "-vo" << QString("jpeg:outdir=%1").arg(tmpDirPath ) << \
"-vf" << QString("scale=%1:%2").arg(scalingWidth).arg(scalingHeight); \
args+=customargs;
if (! startAndWaitProcess(args) ) return NULL;
@@ -168,8 +164,8 @@
return true;
}
-bool MPlayerVideoBackend::canPreview() {
- return findPlayerBin();
+bool MPlayerVideoBackend::playerCannotPreview() {
+ return ! findPlayerBin();
}
--- trunk/kdereview/mplayerthumbs/src/mplayervideobackend.h #950474:950475
@@ -20,14 +20,17 @@
#include <videobackendiface.h>
class KRandomSequence;
+class KTempDir;
+class QProcess;
class MPlayerVideoBackend : public VideoBackendIFace
{
public:
- MPlayerVideoBackend(const QString &filePath, MPlayerThumbsCfg* cfg);
+ MPlayerVideoBackend(PreviewingFile *previewingFile, MPlayerThumbsCfg* \
cfg); virtual ~MPlayerVideoBackend();
- virtual VideoPreview::FileInformation findFileInfo();
- virtual QPixmap getVideoFrame(int flags, VideoPreview::FileInformation \
fileinfo);
- virtual bool canPreview();
+ virtual QPixmap getVideoFrame(int flags);
+ virtual bool playerCannotPreview();
+ virtual bool readStreamInformation();
+
private:
bool findPlayerBin();
bool startAndWaitProcess(const QStringList &args);
--- trunk/kdereview/mplayerthumbs/src/videobackendiface.cpp #950474:950475
@@ -15,14 +15,19 @@
*/
#include "videobackendiface.h"
+#include "previewingfile.h"
+#include "mplayerthumbs.h"
-VideoBackendIFace::VideoBackendIFace(const QString& filePath, \
MPlayerThumbsCfg* cfg) :
- s_filePath(filePath), mplayerThumbsConfig(cfg)
+VideoBackendIFace::VideoBackendIFace(PreviewingFile *previewingFile, \
MPlayerThumbsCfg* cfg) : + mplayerThumbsConfig(cfg)
{
-
+ this->previewingFile = previewingFile;
}
VideoBackendIFace::~VideoBackendIFace() {
}
+bool VideoBackendIFace::cannotPreview() {
+ return previewingFile->isBlacklisted( \
mplayerThumbsConfig->noextensions() ) || playerCannotPreview(); +}
--- trunk/kdereview/mplayerthumbs/src/videobackendiface.h #950474:950475
@@ -20,21 +20,20 @@
#include <QObject>
#include <QPixmap>
-#include "videopreview.h"
-
+class PreviewingFile;
+class MPlayerThumbsCfg;
class VideoBackendIFace
{
public:
- VideoBackendIFace(const QString &filePath, MPlayerThumbsCfg* cfg);
- virtual QPixmap getVideoFrame(int flags, VideoPreview::FileInformation \
fileinfo) = 0;
- virtual VideoPreview::FileInformation findFileInfo() = 0;
- virtual bool canPreview() = 0;
+ VideoBackendIFace(PreviewingFile *previewingFile, MPlayerThumbsCfg* \
cfg); + virtual QPixmap getVideoFrame(int flags) = 0;
+ bool cannotPreview();
+ virtual bool readStreamInformation() = 0;
virtual ~VideoBackendIFace();
protected:
- const QString s_filePath;
+ PreviewingFile *previewingFile;
MPlayerThumbsCfg* mplayerThumbsConfig;
-
-
+ virtual bool playerCannotPreview() = 0;
};
#endif // VIDEOBACKENDIFACE_H
--- trunk/kdereview/mplayerthumbs/src/videopreview.cpp #950474:950475
@@ -19,32 +19,23 @@
***************************************************************************/
#include "videopreview.h"
-
-#include <QFile>
+#include "constants.h"
#include <qpixmap.h>
#include <qimage.h>
#include <QtCore/QVarLengthArray>
#include <kmimetype.h>
-#include <QDir>
#include <qpainter.h>
#include <qdatetime.h>
-#include <qregexp.h>
#include "videopreview.h"
#include <kdebug.h>
-#include <kurl.h>
-#include <math.h>
-#include <QFileInfo>
-#include <kcodecs.h>
#include <kstandarddirs.h>
#include "videobackendiface.h"
#include "mplayervideobackend.h"
#include "mplayerthumbs.h"
+#include "previewingfile.h"
-#include <unistd.h>
-
-//#include "config.h"
extern "C"
{
KDE_EXPORT ThumbCreator *new_creator()
@@ -65,31 +56,26 @@
{
kDebug(DBG_AREA) << "videopreview svn\n";
MPlayerThumbsCfg *cfg=MPlayerThumbsCfg::self();
- VideoBackendIFace *videoBackend = new MPlayerVideoBackend(path, cfg);
+ PreviewingFile *previewingFile = new PreviewingFile(path, width, \
height, this); + VideoBackendIFace *videoBackend = new \
MPlayerVideoBackend(previewingFile, cfg);
- QFileInfo fi(path);
- if(hasBlacklistedExtension(&fi, cfg) || ! videoBackend->canPreview() ) \
{ + if( videoBackend->cannotPreview() || ! \
videoBackend->readStreamInformation() ) { delete cfg;
delete videoBackend;
return false;
}
- FileInformation fileinfo=videoBackend->findFileInfo();
-
- if(! fileinfo.isValid) return false;
- fileinfo.towidth=width;
- fileinfo.toheight=height;
QPixmap pix;
- int flags=framerandom;
+ int flags=Preview::framerandom;
#define LASTTRY 3
for(int i=0; i<=LASTTRY; i++)
{
kDebug(DBG_AREA) << "videopreview: try " << i << endl;
- flags=((i<LASTTRY) ? flags : framestart );
- pix=videoBackend->getVideoFrame(flags, fileinfo);
+ flags=((i<LASTTRY) ? flags : Preview::framestart );
+ pix=videoBackend->getVideoFrame(flags);
if(!pix.isNull()) {
uint variance=imageVariance(pix.toImage()/*.bits(),( (width+ \
7) & ~0x7), width, height, 1 */);
- kDebug(DBG_AREA) << "videopreview: " << \
QFileInfo(path).fileName() << " frame variance: " << variance << "; " << + \
kDebug(DBG_AREA) << "videopreview: " << previewingFile->getFilePath() << " \
frame variance: " << variance << "; " <<
((variance<=40 && ( i!=LASTTRY-1))? "!!!DROPPING!!!" : \
"GOOD :-)" ) << endl; if(variance>40 || i==LASTTRY-1 ) break;
}
@@ -158,16 +144,6 @@
return delta/STEPS;
}
-bool VideoPreview::hasBlacklistedExtension(QFileInfo* fileInfo, \
MPlayerThumbsCfg *cfg) {
- QString extension=fileInfo->suffix().trimmed();
- kDebug(DBG_AREA) << "videopreview: file extension=\"" << extension << \
"\"\n";
- if( extension.length() && !cfg->noextensions().filter(extension, \
Qt::CaseInsensitive).isEmpty() )
- {
- kDebug(DBG_AREA) << "videopreview: matched extension " << \
extension.prepend('.') << "; exiting.\n";
- return true;
- }
- return false;
-}
#include "videopreview.moc"
--- trunk/kdereview/mplayerthumbs/src/videopreview.h #950474:950475
@@ -32,9 +32,7 @@
class KTempDir;
class KRandomSequence;
#include <qobject.h>
-#define DBG_AREA 0
-
class QFileInfo;
class MPlayerThumbsCfg;
class VideoPreview : public QObject, public ThumbCreator
@@ -45,15 +43,11 @@
virtual ~VideoPreview();
virtual bool create(const QString &path, int width, int height, \
QImage &img); virtual Flags flags() const;
- struct FileInformation { int towidth; int toheight; int fps; int seconds; \
bool isValid; };
- enum frameflags { framerandom=0x1, framestart=0x2, frameend=0x4 };
protected:
static uint imageVariance(QImage image );
private:
QPixmap m_pixmap;
- bool hasBlacklistedExtension(QFileInfo *fileInfo, MPlayerThumbsCfg *cfg);
- FileInformation fileinfo;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic