[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-02-20 22:42:27
Message-ID: 1235169747.073386.2444.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 929221 by gulino:

Refactoring, separating backend from previewer


 M  +1 -1      CMakeLists.txt  
 A             mplayervideobackend.cpp   [License: LGPL (v2)]
 A             mplayervideobackend.h   [License: LGPL (v2)]
 A             videobackendiface.cpp   [License: LGPL (v2)]
 A             videobackendiface.h   [License: LGPL (v2)]
 M  +16 -145   videopreview.cpp  
 M  +3 -11     videopreview.h  


--- trunk/kdereview/mplayerthumbs/src/CMakeLists.txt #929220:929221
@@ -3,7 +3,7 @@
 
 ########### next target ###############
 
-set(videopreview_PART_SRCS videopreview.cpp)
+set(videopreview_PART_SRCS videopreview.cpp  mplayervideobackend.cpp \
videobackendiface.cpp)  
 kde4_add_kcfg_files(videopreview_PART_SRCS mplayerthumbs.kcfgc)
 
--- trunk/kdereview/mplayerthumbs/src/videopreview.cpp #929220:929221
@@ -25,28 +25,25 @@
 #include <qimage.h>
 #include <QtCore/QVarLengthArray>
 
-#include <kstandarddirs.h>
 #include <kmimetype.h>
 #include <QDir>
 #include <qpainter.h>
-#include <krandomsequence.h>
 #include <qdatetime.h>
 #include <qregexp.h>
 #include "videopreview.h"
-#include <QProcess>
 #include <kdebug.h>
-#include <ktempdir.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 <unistd.h>
 
-#define DBG_AREA
-
 //#include "config.h"
 extern "C"
 {
@@ -65,49 +62,34 @@
 VideoPreview::~VideoPreview()
 {
     delete [] m_data;
-    delete tmpdir;
-    delete rand;
-    delete mplayerprocess;
 }
 
-bool VideoPreview::startAndWaitProcess(const QStringList &args) {
-    kDebug(DBG_AREA) << "videopreview: starting process with args: " << args << \
                endl;
-    mplayerprocess->start( args.join(" ") );
-    if(! mplayerprocess->waitForStarted() ) {
-        kDebug(DBG_AREA) << "videopreview: PROCESS NOT STARTED!!! exiting\n";
-        return false;
-    }
-    if(! mplayerprocess->waitForFinished() ) {
-        kDebug(DBG_AREA) << "videopreview: PROCESS DIDN'T FINISH!! exiting\n";
-        mplayerprocess->close();
-        return false;
-    }
-  kDebug() << "videopreview: process started and ended correctly\n";
-  return true;
-}
-
 bool VideoPreview::create(const QString &path, int width, int height, QImage &img)
 {
+    kDebug(DBG_AREA) << "videopreview svn\n";
     MPlayerThumbsCfg *cfg=MPlayerThumbsCfg::self();
+    VideoBackendIFace *videoBackend = new MPlayerVideoBackend(path, cfg);
+
     QFileInfo fi(path);
-    if(hasBlacklistedExtension(&fi, cfg) || ! findPlayerBin(cfg) ) {
+    if(hasBlacklistedExtension(&fi, cfg) || ! videoBackend->canPreview() ) {
       delete cfg;
+      delete videoBackend;
       return false;
     }
 
-    FileInformation fileinfo=findFileInfo(path);
+    FileInformation fileinfo=videoBackend->findFileInfo();
+
     if(! fileinfo.isValid) return false;
     fileinfo.towidth=width;
     fileinfo.toheight=height;
     QPixmap pix;
-    int flags=0;
-    flags=framerandom;
+    int flags=framerandom;
     #define LASTTRY 3
     for(int i=0; i<=LASTTRY; i++)
     {
         kDebug(DBG_AREA) << "videopreview: try " << i << endl;
-flags=((i<LASTTRY) ? flags : framestart );
-        pix=getFrame(path, flags );
+	flags=((i<LASTTRY) ? flags : framestart );
+        pix=videoBackend->getVideoFrame(flags, fileinfo);
         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 << "; " <<  @@ -115,11 +97,11 @@
             if(variance>40 || i==LASTTRY-1 ) break;
         }
     }
+
+  delete videoBackend;
+
     if(pix.isNull() )
-    {
-        tryUnlink(tmpdir);
         return false;
-    }
     /** From videocreator.cpp - xine_artsplugin
     Copyright (C) 2002 Simon MacMullen
     Copyright (C) 2003 Ewald Snel <ewald@rambo.its.tudelft.nl>
@@ -146,63 +128,9 @@
 //#endif
     img = pix.toImage();
 
-    tryUnlink(tmpdir);
     return true;
 }
 
-void VideoPreview::tryUnlink(KTempDir *dir) {
-    if(dir) dir->unlink();
-}
-
-QPixmap VideoPreview::getFrame(const QString &path, int flags)
-{
-    QStringList args;
-    kDebug(DBG_AREA) << "videopreview: using flags " << flags << endl;
-#define START ((fileinfo.seconds*15)/100)
-#define END ((fileinfo.seconds*70)/100)
-    args.clear();
-    args << playerBin << "\"" + path + "\"";
-    if(fileinfo.towidth>fileinfo.toheight) fileinfo.toheight=-2; else \
                fileinfo.towidth=-2;
-//     switch( flags ){
-//         case random
-//     }
-    if( flags & 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 & frameend )
-    {
-        kDebug(DBG_AREA) << "videopreview: frameend\n";
-        args << "-ss" << QString::number( fileinfo.seconds - 10 )
-                << "-frames" << "4";
-    } else if (flags & 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 we can't skip to a random frame, let's try playing 10 seconds.
-        args << "-frames" << QString::number( fileinfo.fps*10 );
-    }
-    KMD5 md5builder(path.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);
-    args+=customargs;
-
-    if (! startAndWaitProcess(args) ) return NULL;
-
-    kDebug(DBG_AREA) << "videopreview: temp dir '" << tmpDirPath << "'\n";
-
-    if (QDir(tmpDirPath ).entryList( QStringList("*.jpg") ).isEmpty() ) return \
                false;
-
-    QString lastframe=QDir(tmpDirPath ).entryList( QStringList("*.jpg") ).last();
-    kDebug(DBG_AREA) << "videopreview: LastFrame==" << lastframe << endl;
-    QPixmap retpix(tmpDirPath.append( lastframe ));
-    return retpix;
-}
-
 ThumbCreator::Flags VideoPreview::flags() const
 {
     return (Flags)(DrawFrame);
@@ -244,63 +172,6 @@
     return false;
 }
 
-bool VideoPreview::findPlayerBin( MPlayerThumbsCfg* cfg) {
-    playerBin=cfg->mplayerbin();
-    customargs=cfg->customargs().split(" ");
-    kDebug(DBG_AREA) << "videopreview: customargs=" << cfg->customargs() << " ;;;; " \
                << customargs << endl;
-    if(playerBin.length()) kDebug(DBG_AREA) << "videopreview: found playerbin from \
                config: " << playerBin << endl;
-    else
-    {
-        playerBin=KStandardDirs::findExe("mplayer-bin");
-        if(!playerBin.length()) playerBin=KStandardDirs::findExe("mplayer");
-        if(!playerBin.length())
-        {
-            kDebug(DBG_AREA) << "videopreview: mplayer not found, exiting. Run \
                mplayerthumbsconfig to setup mplayer path manually.\n";
-            return false;
-        }
-        kDebug(DBG_AREA) << "videopreview: found playerbin from path: " << playerBin \
                << endl;
-    }
-    return true;
-}
 
-VideoPreview::FileInformation VideoPreview::findFileInfo(QString filePath) {
-    FileInformation fileinfo;
-    fileinfo.seconds=0;
-    fileinfo.fps=0;
-    fileinfo.isValid=false;
-    tmpdir=new KTempDir();
-    if(tmpdir->name().isNull() ) return fileinfo;
-    kDebug(DBG_AREA) << "videopreview: using temp directory " << tmpdir->name() << \
                endl;
-
-    rand=new KRandomSequence(QDateTime::currentDateTime().toTime_t());
-    mplayerprocess=new QProcess();
-    KUrl furl(filePath);
-    kDebug(DBG_AREA) << "videopreview: url=" << furl << "; local:" << \
                furl.isLocalFile() << endl;
-
-
-    QStringList args;
-    args << playerBin << QString("\"" + filePath + "\"") << "-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;
-
-    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;
-    }
-    fileinfo.seconds =findInfos.cap(2).toInt();
-    fileinfo.fps=findInfos.cap(1).toInt();
-    
-    kDebug(DBG_AREA) << "videopreview: find length=" << fileinfo.seconds << ", fps=" \
                << fileinfo.fps << endl;
-    fileinfo.isValid=true;
-    return fileinfo;
-}
-
-
-
 #include "videopreview.moc"
 
--- trunk/kdereview/mplayerthumbs/src/videopreview.h #929220:929221
@@ -32,6 +32,7 @@
 class KTempDir;
 class KRandomSequence;
 #include <qobject.h>
+#define DBG_AREA 0
 
 
 class QFileInfo;
@@ -45,24 +46,15 @@
         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:
-        QPixmap getFrame(const QString &path, int flags);
         static uint imageVariance(QImage image );
-        void tryUnlink(KTempDir *dir);
     private:
         char *m_data;
         int m_dataSize;
         QPixmap m_pixmap;
-        QProcess *mplayerprocess;
-        QStringList customargs;
-        KTempDir *tmpdir;
-        KRandomSequence *rand;
-        QString playerBin;
 	bool hasBlacklistedExtension(QFileInfo *fileInfo, MPlayerThumbsCfg *cfg);
-	bool findPlayerBin(MPlayerThumbsCfg *cfg);
-        bool startAndWaitProcess(const QStringList &args);
-	FileInformation findFileInfo(QString filePath);
-        enum frameflags { framerandom=0x1, framestart=0x2, frameend=0x4 };
         FileInformation fileinfo;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic