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

Last change on this file 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
RevLine 
[93]1Index: videopreview/main.cpp
2===================================================================
3--- videopreview/main.cpp (revisión: 2543)
4+++ videopreview/main.cpp (copia de trabajo)
5@@ -47,11 +47,17 @@
6 */
7 //vp.setAspectRatio( 2.35 );
8
9+#if VIDEOPREVIEW_ASYNC
10+ if (vp.showConfigDialog()) {
11+ vp.createThumbnails();
12+ return a.exec();
13+ }
14+#else
15 if ( (vp.showConfigDialog()) && (vp.createThumbnails()) ) {
16 vp.show();
17 vp.adjustWindowSize();
18 return a.exec();
19 }
20-
21+#endif
22 return 0;
23 }
24Index: videopreview/videopreview.cpp
25===================================================================
26--- videopreview/videopreview.cpp (revisión: 2543)
27+++ videopreview/videopreview.cpp (copia de trabajo)
28@@ -105,7 +105,15 @@
29 my_layout->addWidget(button_box);
30 setLayout(my_layout);
31
32+#if VIDEOPREVIEW_ASYNC
33+ process = new QProcess(this);
34+ connect( process, SIGNAL(finished(int, QProcess::ExitStatus)),
35+ this, SLOT(processFinished(int, QProcess::ExitStatus)) );
36
37+ connect( this, SIGNAL(finishedOk()), this, SLOT(workFinishedOK()) );
38+ connect( this, SIGNAL(finishedWithError()), this, SLOT(workFinishedWithError()) );
39+#endif
40+
41 QList<QByteArray> r_formats = QImageReader::supportedImageFormats();
42 QString read_formats;
43 for (int n=0; n < r_formats.count(); n++) {
44@@ -156,6 +164,132 @@
45 return "00000005.jpg";
46 }
47
48+#if VIDEOPREVIEW_ASYNC
49+void VideoPreview::createThumbnails() {
50+ clearThumbnails();
51+ error_message.clear();
52+
53+ // Initalization
54+ VideoInfo i = getInfo(mplayer_bin, prop.input_video);
55+ int length = i.length;
56+
57+ if (length == 0) {
58+ if (error_message.isEmpty()) error_message = tr("The length of the video is 0");
59+ emit finishedWithError();
60+ return;
61+ }
62+
63+ // Create a temporary directory
64+ QDir d(QDir::tempPath());
65+ if (!d.exists(output_dir)) {
66+ if (!d.mkpath(output_dir)) {
67+ qDebug("VideoPreview::extractImages: error: can't create '%s'", full_output_dir.toUtf8().constData());
68+ error_message = tr("The temporary directory (%1) can't be created").arg(full_output_dir);
69+ emit finishedWithError();
70+ return;
71+ }
72+ }
73+
74+ displayVideoInfo(i);
75+
76+ // Let's begin
77+ run.thumbnail_width = 0;
78+
79+ run.num_pictures = prop.n_cols * prop.n_rows;
80+ length -= prop.initial_step;
81+ run.s_step = length / run.num_pictures;
82+
83+ run.current_time = prop.initial_step;
84+
85+ canceled = false;
86+ progress->setLabelText(tr("Creating thumbnails..."));
87+ progress->setRange(0, run.num_pictures-1);
88+
89+ run.current_picture = 0;
90+ progress->setValue( run.current_picture);
91+
92+ if (!runMplayer(run.current_time)) {
93+ emit finishedWithError();
94+ }
95+}
96+
97+void VideoPreview::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
98+ qDebug("VideoPreview::processFinished");
99+
100+ if (exitStatus != QProcess::NormalExit) {
101+ emit finishedWithError();
102+ return;
103+ }
104+
105+ // Continue processing
106+ QString frame_picture = full_output_dir + "/" + framePicture();
107+ if (!QFile::exists(frame_picture)) {
108+ error_message = tr("The file %1 doesn't exist").arg(frame_picture);
109+ emit finishedWithError();
110+ return;
111+ }
112+
113+#if RENAME_PICTURES
114+ QDir d(QDir::tempPath());
115+ QString extension = (extractFormat()==PNG) ? "png" : "jpg";
116+ QString output_file = output_dir + QString("/picture_%1.%2").arg(run.current_time, 8, 10, QLatin1Char('0')).arg(extension);
117+ d.rename(output_dir + "/" + framePicture(), output_file);
118+#else
119+ QString output_file = output_dir + "/" + framePicture();
120+#endif
121+
122+ if (!addPicture(QDir::tempPath() +"/"+ output_file, run.current_picture, run.current_time)) {
123+ emit finishedWithError();
124+ return;
125+ }
126+
127+ run.current_time += run.s_step;
128+
129+ if (canceled) {
130+ emit finishedOk();
131+ return;
132+ }
133+
134+ // Next picture
135+ run.current_picture++;
136+
137+ if (run.current_picture >= run.num_pictures) {
138+ emit finishedOk();
139+ return;
140+ }
141+
142+ progress->setValue( run.current_picture);
143+
144+ if (!runMplayer(run.current_time)) {
145+ emit finishedWithError();
146+ }
147+}
148+
149+void VideoPreview::workFinishedOK() {
150+ qDebug("VideoPreview::workFinishedOK");
151+
152+ show();
153+ adjustWindowSize();
154+
155+ cleanDir(full_output_dir);
156+}
157+
158+void VideoPreview::workFinishedWithError() {
159+ qDebug("VideoPreview::workFinishedWithError");
160+
161+ if (!error_message.isEmpty()) {
162+ QMessageBox::critical(this, tr("Error"),
163+ tr("The following error has occurred while creating the thumbnails:")+"\n"+ error_message );
164+ }
165+
166+ cleanDir(full_output_dir);
167+
168+ close();
169+}
170+
171+
172+#else // VIDEOPREVIEW_ASYNC
173+
174 bool VideoPreview::createThumbnails() {
175 clearThumbnails();
176 error_message.clear();
177@@ -244,6 +378,7 @@
178
179 return true;
180 }
181+#endif // VIDEOPREVIEW_ASYNC
182
183 bool VideoPreview::runMplayer(int seek) {
184 QStringList args;
185@@ -283,6 +418,18 @@
186 for (int n = 0; n < args.count(); n++) command = command + args[n] + " ";
187 qDebug("VideoPreview::runMplayer: command: %s", command.toUtf8().constData());
188
189+#if VIDEOPREVIEW_ASYNC
190+ #ifdef CD_TO_TEMP_DIR
191+ process->setWorkingDirectory(full_output_dir);
192+ qDebug("VideoPreview::runMplayer: changing working directory of the process to '%s'", full_output_dir.toUtf8().constData());
193+ #endif
194+ process->start(mplayer_bin, args);
195+ if (!process->waitForStarted()) {
196+ qDebug("VideoPreview::runMplayer: error running process");
197+ error_message = tr("The mplayer process didn't run");
198+ return false;
199+ }
200+#else // VIDEOPREVIEW_ASYNC
201 QProcess p;
202 #ifdef CD_TO_TEMP_DIR
203 p.setWorkingDirectory(full_output_dir);
204@@ -294,6 +441,7 @@
205 error_message = tr("The mplayer process didn't run");
206 return false;
207 }
208+#endif // VIDEOPREVIEW_ASYNC
209
210 return true;
211 }
212Index: videopreview/videopreview.h
213===================================================================
214--- videopreview/videopreview.h (revisión: 2543)
215+++ videopreview/videopreview.h (copia de trabajo)
216@@ -19,10 +19,16 @@
217 #ifndef _VIDEOPREVIEW_H_
218 #define _VIDEOPREVIEW_H_
219
220+#define VIDEOPREVIEW_ASYNC 0
221+
222 #include <QWidget>
223 #include <QString>
224 #include <QList>
225
226+#if VIDEOPREVIEW_ASYNC
227+#include <QProcess>
228+#endif
229+
230 class QProgressDialog;
231 class QGridLayout;
232 class QLabel;
233@@ -90,7 +96,11 @@
234 void setExtractFormat( ExtractFormat format ) { prop.extract_format = format; };
235 ExtractFormat extractFormat() { return prop.extract_format; };
236
237+#if VIDEOPREVIEW_ASYNC
238+ void createThumbnails();
239+#else
240 bool createThumbnails();
241+#endif
242
243 bool showConfigDialog();
244
245@@ -106,8 +116,23 @@
246 void cancelPressed();
247 void saveImage();
248
249+#if VIDEOPREVIEW_ASYNC
250+ void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
251+ void workFinishedOK();
252+ void workFinishedWithError();
253+
254 protected:
255+ QProcess * process;
256+
257+signals:
258+ void finishedOk();
259+ void finishedWithError();
260+#endif
261+
262+protected:
263+#if !VIDEOPREVIEW_ASYNC
264 bool extractImages();
265+#endif
266 bool runMplayer(int seek);
267 bool addPicture(const QString & filename, int num, int time);
268 void displayVideoInfo(const VideoInfo & i);
269@@ -144,9 +169,19 @@
270 ExtractFormat extract_format;
271 } prop;
272
273+#if VIDEOPREVIEW_ASYNC
274 struct {
275 int thumbnail_width;
276+ int num_pictures;
277+ int s_step;
278+ int current_time;
279+ int current_picture;
280 } run;
281+#else
282+ struct {
283+ int thumbnail_width;
284+ } run;
285+#endif
286
287 QString last_directory;
288 QString error_message;
289Index: basegui.cpp
290===================================================================
291--- basegui.cpp (revisión: 2543)
292+++ basegui.cpp (copia de trabajo)
293@@ -4022,10 +4022,16 @@
294
295 video_preview->setMplayerPath(pref->mplayer_bin);
296
297+#if VIDEOPREVIEW_ASYNC
298+ if (video_preview->showConfigDialog()) {
299+ video_preview->createThumbnails();
300+ }
301+#else
302 if ( (video_preview->showConfigDialog()) && (video_preview->createThumbnails()) ) {
303 video_preview->show();
304 video_preview->adjustWindowSize();
305 }
306+#endif
307 }
308
309 QNetworkProxy BaseGui::userProxy() {
Note: See TracBrowser for help on using the repository browser.