source: smplayer/trunk/src/videopreview/async.diff@ 119

Last change on this file since 119 was 113, checked in by Silvan Scherrer, 15 years ago

Smplayer: eol-style 2nd part

  • Property svn:eol-style set to LF
File size: 7.6 KB
  • videopreview/main.cpp

     
    4747        */
    4848        //vp.setAspectRatio( 2.35 );
    4949
     50#if VIDEOPREVIEW_ASYNC
     51        if (vp.showConfigDialog()) {
     52                vp.createThumbnails();
     53                return a.exec();
     54        }
     55#else
    5056        if ( (vp.showConfigDialog()) && (vp.createThumbnails()) ) {
    5157                vp.show();
    5258                vp.adjustWindowSize();
    5359                return a.exec();
    5460        }
    55 
     61#endif
    5662        return 0;
    5763}
  • videopreview/videopreview.cpp

     
    105105        my_layout->addWidget(button_box);
    106106        setLayout(my_layout);
    107107
     108#if VIDEOPREVIEW_ASYNC
     109        process = new QProcess(this);
     110        connect( process, SIGNAL(finished(int, QProcess::ExitStatus)),
     111             this, SLOT(processFinished(int, QProcess::ExitStatus)) );
    108112
     113        connect( this, SIGNAL(finishedOk()), this, SLOT(workFinishedOK()) );
     114        connect( this, SIGNAL(finishedWithError()), this, SLOT(workFinishedWithError()) );
     115#endif
     116
    109117        QList<QByteArray> r_formats = QImageReader::supportedImageFormats();
    110118        QString read_formats;
    111119        for (int n=0; n < r_formats.count(); n++) {
     
    156164                return "00000005.jpg";
    157165}
    158166
     167#if VIDEOPREVIEW_ASYNC
     168void VideoPreview::createThumbnails() {
     169    clearThumbnails();
     170    error_message.clear();
     171
     172        // Initalization
     173        VideoInfo i = getInfo(mplayer_bin, prop.input_video);
     174        int length = i.length;
     175
     176        if (length == 0) {
     177                if (error_message.isEmpty()) error_message = tr("The length of the video is 0");
     178                emit finishedWithError();
     179                return;
     180        }
     181
     182        // Create a temporary directory
     183        QDir d(QDir::tempPath());
     184        if (!d.exists(output_dir)) {
     185                if (!d.mkpath(output_dir)) {
     186                        qDebug("VideoPreview::extractImages: error: can't create '%s'", full_output_dir.toUtf8().constData());
     187                        error_message = tr("The temporary directory (%1) can't be created").arg(full_output_dir);
     188                        emit finishedWithError();
     189                        return;
     190                }
     191        }
     192
     193        displayVideoInfo(i);
     194
     195        // Let's begin
     196        run.thumbnail_width = 0;
     197
     198        run.num_pictures = prop.n_cols * prop.n_rows;
     199        length -= prop.initial_step;
     200        run.s_step = length / run.num_pictures;
     201
     202        run.current_time = prop.initial_step;
     203
     204        canceled = false;
     205        progress->setLabelText(tr("Creating thumbnails..."));
     206        progress->setRange(0, run.num_pictures-1);
     207
     208        run.current_picture = 0;
     209        progress->setValue( run.current_picture);
     210
     211        if (!runMplayer(run.current_time)) {
     212                emit finishedWithError();
     213        }
     214}
     215
     216void VideoPreview::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
     217        qDebug("VideoPreview::processFinished");
     218
     219        if (exitStatus != QProcess::NormalExit) {
     220                emit finishedWithError();
     221                return;
     222        }
     223
     224        // Continue processing
     225        QString frame_picture = full_output_dir + "/" + framePicture();
     226        if (!QFile::exists(frame_picture)) {
     227                error_message = tr("The file %1 doesn't exist").arg(frame_picture);
     228                emit finishedWithError();
     229                return;
     230        }
     231
     232#if RENAME_PICTURES
     233        QDir d(QDir::tempPath());
     234        QString extension = (extractFormat()==PNG) ? "png" : "jpg";
     235        QString output_file = output_dir + QString("/picture_%1.%2").arg(run.current_time, 8, 10, QLatin1Char('0')).arg(extension);
     236        d.rename(output_dir + "/" + framePicture(), output_file);
     237#else
     238        QString output_file = output_dir + "/" + framePicture();
     239#endif
     240
     241        if (!addPicture(QDir::tempPath() +"/"+ output_file, run.current_picture, run.current_time)) {
     242                emit finishedWithError();
     243                return;
     244        }
     245
     246        run.current_time += run.s_step;
     247
     248        if (canceled) {
     249                emit finishedOk();
     250                return;
     251        }
     252
     253        // Next picture
     254        run.current_picture++;
     255
     256        if (run.current_picture >= run.num_pictures) {
     257                emit finishedOk();
     258                return;
     259        }
     260
     261        progress->setValue( run.current_picture);
     262
     263        if (!runMplayer(run.current_time)) {
     264                emit finishedWithError();
     265        }       
     266}
     267
     268void VideoPreview::workFinishedOK() {
     269        qDebug("VideoPreview::workFinishedOK");
     270
     271        show();
     272        adjustWindowSize();
     273
     274        cleanDir(full_output_dir);
     275}
     276
     277void VideoPreview::workFinishedWithError() {
     278        qDebug("VideoPreview::workFinishedWithError");
     279
     280        if (!error_message.isEmpty()) {
     281                QMessageBox::critical(this, tr("Error"),
     282                              tr("The following error has occurred while creating the thumbnails:")+"\n"+ error_message );
     283        }
     284
     285        cleanDir(full_output_dir);
     286
     287        close();
     288}
     289
     290
     291#else // VIDEOPREVIEW_ASYNC
     292
    159293bool VideoPreview::createThumbnails() {
    160294        clearThumbnails();
    161295        error_message.clear();
     
    244378
    245379        return true;
    246380}
     381#endif // VIDEOPREVIEW_ASYNC
    247382
    248383bool VideoPreview::runMplayer(int seek) {
    249384        QStringList args;
     
    283418        for (int n = 0; n < args.count(); n++) command = command + args[n] + " ";
    284419        qDebug("VideoPreview::runMplayer: command: %s", command.toUtf8().constData());
    285420
     421#if VIDEOPREVIEW_ASYNC
     422        #ifdef CD_TO_TEMP_DIR
     423        process->setWorkingDirectory(full_output_dir);
     424        qDebug("VideoPreview::runMplayer: changing working directory of the process to '%s'", full_output_dir.toUtf8().constData());
     425        #endif
     426        process->start(mplayer_bin, args);
     427        if (!process->waitForStarted()) {
     428                qDebug("VideoPreview::runMplayer: error running process");
     429                error_message = tr("The mplayer process didn't run");
     430                return false;
     431        }
     432#else // VIDEOPREVIEW_ASYNC
    286433        QProcess p;
    287434        #ifdef CD_TO_TEMP_DIR
    288435        p.setWorkingDirectory(full_output_dir);
     
    294441                error_message = tr("The mplayer process didn't run");
    295442                return false;
    296443        }
     444#endif // VIDEOPREVIEW_ASYNC
    297445
    298446        return true;
    299447}
  • videopreview/videopreview.h

     
    1919#ifndef _VIDEOPREVIEW_H_
    2020#define _VIDEOPREVIEW_H_
    2121
     22#define VIDEOPREVIEW_ASYNC 0
     23
    2224#include <QWidget>
    2325#include <QString>
    2426#include <QList>
    2527
     28#if VIDEOPREVIEW_ASYNC
     29#include <QProcess>
     30#endif
     31
    2632class QProgressDialog;
    2733class QGridLayout;
    2834class QLabel;
     
    9096        void setExtractFormat( ExtractFormat format ) { prop.extract_format = format; };
    9197        ExtractFormat extractFormat() { return prop.extract_format; };
    9298
     99#if VIDEOPREVIEW_ASYNC
     100        void createThumbnails();
     101#else
    93102        bool createThumbnails();
     103#endif
    94104
    95105        bool showConfigDialog();
    96106
     
    106116        void cancelPressed();
    107117        void saveImage();
    108118
     119#if VIDEOPREVIEW_ASYNC
     120        void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
     121        void workFinishedOK();
     122        void workFinishedWithError();
     123
    109124protected:
     125        QProcess * process;
     126
     127signals:
     128        void finishedOk();
     129        void finishedWithError();
     130#endif
     131
     132protected:
     133#if !VIDEOPREVIEW_ASYNC
    110134        bool extractImages();
     135#endif
    111136        bool runMplayer(int seek);
    112137        bool addPicture(const QString & filename, int num, int time);
    113138        void displayVideoInfo(const VideoInfo & i);
     
    144169                ExtractFormat extract_format;
    145170        } prop;
    146171
     172#if VIDEOPREVIEW_ASYNC
    147173        struct {
    148174                int thumbnail_width;
     175                int num_pictures;
     176                int s_step;
     177                int current_time;
     178                int current_picture;
    149179        } run;
     180#else
     181        struct {
     182                int thumbnail_width;
     183        } run;
     184#endif
    150185
    151186        QString last_directory;
    152187        QString error_message;
  • basegui.cpp

     
    40224022
    40234023        video_preview->setMplayerPath(pref->mplayer_bin);
    40244024
     4025#if VIDEOPREVIEW_ASYNC
     4026        if (video_preview->showConfigDialog()) {
     4027                video_preview->createThumbnails();
     4028        }
     4029#else
    40254030        if ( (video_preview->showConfigDialog()) && (video_preview->createThumbnails()) ) {
    40264031                video_preview->show();
    40274032                video_preview->adjustWindowSize();
    40284033        }
     4034#endif
    40294035}
    40304036
    40314037QNetworkProxy BaseGui::userProxy() {
Note: See TracBrowser for help on using the repository browser.