source: smplayer/trunk/src/mplayeroptions.cpp

Last change on this file was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

File size: 13.4 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "subtracks.h"
20#include "deviceinfo.h"
21#include <QDir>
22#include <QDebug>
23
24void MplayerProcess::setMedia(const QString & media, bool is_playlist) {
25 if (is_playlist) arg << "-playlist";
26 arg << media;
27}
28
29void MplayerProcess::setFixedOptions() {
30 arg << "-noquiet" << "-slave" << "-identify";
31}
32
33void MplayerProcess::disableInput() {
34 arg << "-nomouseinput";
35
36#if !defined(Q_OS_WIN) && !defined(Q_OS_OS2)
37 arg << "-input" << "nodefault-bindings:conf=/dev/null";
38#endif
39}
40
41#ifdef CAPTURE_STREAM
42void MplayerProcess::setCaptureDirectory(const QString & dir) {
43 PlayerProcess::setCaptureDirectory(dir);
44 if (!capture_filename.isEmpty()) {
45 arg << "-capture" << "-dumpfile" << capture_filename;
46 }
47}
48#endif
49
50void MplayerProcess::enableScreenshots(const QString & dir, const QString & /* templ */, const QString & /* format */) {
51 QString f = "screenshot";
52 if (!dir.isEmpty()) {
53 QString d = QDir::toNativeSeparators(dir);
54 if (MplayerVersion::isMplayerAtLeast(36848)) {
55 f += "="+ d + "/shot";
56 } else {
57 // Keep compatibility with older versions
58 qDebug() << "MplayerProcess::enableScreenshots: this version of mplayer is very old";
59 qDebug() << "MplayerProcess::enableScreenshots: changing working directory to" << d;
60 setWorkingDirectory(d);
61 }
62 }
63 arg << "-vf-add" << f;
64}
65
66void MplayerProcess::setOption(const QString & option_name, const QVariant & value) {
67 if (option_name == "ao") {
68 QString ao = value.toString();
69 if (ao.contains(":")) {
70 QStringList l = DeviceInfo::extractDevice(ao);
71 qDebug() << "MplayerProcess::setOption: ao:" << l;
72 if (l.count() > 1) {
73 #ifndef Q_OS_WIN
74 if (l[0] == "alsa") {
75 ao = "alsa:device=hw=" + l[1];
76 }
77 else
78 if (l[0] == "pulse") {
79 ao = "pulse::" + l[1];
80 }
81 #else
82 if (l[0] == "dsound") {
83 ao = "dsound:device=" + l[1];
84 }
85 #endif
86 }
87 }
88 arg << "-ao" << ao + ",";
89 }
90 else
91 if (option_name == "cache") {
92 int cache = value.toInt();
93 if (cache > 31) {
94 arg << "-cache" << value.toString();
95 } else {
96 arg << "-nocache";
97 }
98 }
99 else
100 if (option_name == "cache_auto") {
101 // Nothing to do
102 }
103 else
104 if (option_name == "stop-xscreensaver") {
105 bool stop_ss = value.toBool();
106 if (stop_ss) arg << "-stop-xscreensaver"; else arg << "-nostop-xscreensaver";
107 }
108 else
109 if (option_name == "correct-pts") {
110 bool b = value.toBool();
111 if (b) arg << "-correct-pts"; else arg << "-nocorrect-pts";
112 }
113 else
114 if (option_name == "framedrop") {
115 QString o = value.toString();
116 if (o.contains("vo")) arg << "-framedrop";
117 if (o.contains("decoder")) arg << "-hardframedrop";
118 }
119 else
120 if (option_name == "osd-scale") {
121 arg << "-subfont-osd-scale" << value.toString();
122 }
123 else
124 if (option_name == "verbose") {
125 arg << "-v";
126 }
127 else
128 if (option_name == "enable_streaming_sites_support") {
129 // Not supported
130 }
131 else
132 if (option_name == "hwdec") {
133 // Not supported
134 }
135 else
136 if (option_name == "fontconfig") {
137 bool b = value.toBool();
138 if (b) arg << "-fontconfig"; else arg << "-nofontconfig";
139 }
140 else
141 if (option_name == "mute") {
142 // Not supported
143 }
144 else
145 if (option_name == "softvol") {
146 if (value.toString() != "off") {
147 int v = value.toInt();
148 if (v < 100) v = 100;
149 arg << "-softvol" << "-softvol-max" << QString::number(v);
150 }
151 }
152 else
153 if (option_name == "keepaspect" ||
154 option_name == "dr" || option_name == "double" ||
155 option_name == "fs" || option_name == "slices" ||
156 option_name == "flip-hebrew")
157 {
158 bool b = value.toBool();
159 if (b) arg << "-" + option_name; else arg << "-no" + option_name;
160 }
161 else {
162 arg << "-" + option_name;
163 if (!value.isNull()) arg << value.toString();
164 }
165}
166
167void MplayerProcess::addUserOption(const QString & option) {
168 arg << option;
169}
170
171void MplayerProcess::addVF(const QString & filter_name, const QVariant & value) {
172 QString option = value.toString();
173
174 if (filter_name == "blur" || filter_name == "sharpen") {
175 arg << "-vf-add" << "unsharp=" + option;
176 }
177 else
178 if (filter_name == "deblock") {
179 arg << "-vf-add" << "pp=" + option;
180 }
181 else
182 if (filter_name == "dering") {
183 arg << "-vf-add" << "pp=dr";
184 }
185 else
186 if (filter_name == "postprocessing") {
187 arg << "-vf-add" << "pp";
188 }
189 else
190 if (filter_name == "lb" || filter_name == "l5") {
191 arg << "-vf-add" << "pp=" + filter_name;
192 }
193 else
194 if (filter_name == "subs_on_screenshots") {
195 if (option == "ass") {
196 arg << "-vf-add" << "ass";
197 } else {
198 arg << "-vf-add" << "expand=osd=1";
199 }
200 }
201 else
202 if (filter_name == "flip") {
203 // expand + flip doesn't work well, a workaround is to add another
204 // filter between them, so that's why harddup is here
205 arg << "-vf-add" << "harddup,flip";
206 }
207 else
208 if (filter_name == "expand") {
209 arg << "-vf-add" << "expand=" + option + ",harddup";
210 // Note: on some videos (h264 for instance) the subtitles doesn't disappear,
211 // appearing the new ones on top of the old ones. It seems adding another
212 // filter after expand fixes the problem. I chose harddup 'cos I think
213 // it will be harmless in mplayer.
214 }
215 else {
216 QString s = filter_name;
217 QString option = value.toString();
218 if (!option.isEmpty()) s += "=" + option;
219 arg << "-vf-add" << s;
220 }
221}
222
223void MplayerProcess::addStereo3DFilter(const QString & in, const QString & out) {
224 QString filter = "stereo3d=" + in + ":" + out;
225 filter += ",scale"; // In my PC it doesn't work without scale :?
226 arg << "-vf-add" << filter;
227}
228
229void MplayerProcess::addAF(const QString & filter_name, const QVariant & value) {
230 QString s = filter_name;
231 if (!value.isNull()) s += "=" + value.toString();
232 arg << "-af-add" << s;
233}
234
235void MplayerProcess::quit() {
236 writeToStdin("quit");
237}
238
239void MplayerProcess::setVolume(int v) {
240 writeToStdin("volume " + QString::number(v) + " 1");
241}
242
243void MplayerProcess::setOSD(int o) {
244 writeToStdin(pausing_prefix + " osd " + QString::number(o));
245}
246
247void MplayerProcess::setAudio(int ID) {
248 writeToStdin("switch_audio " + QString::number(ID));
249}
250
251void MplayerProcess::setVideo(int ID) {
252 writeToStdin("set_property switch_video " + QString::number(ID));
253}
254
255void MplayerProcess::setSubtitle(int type, int ID) {
256 switch (type) {
257 case SubData::Vob:
258 writeToStdin( "sub_vob " + QString::number(ID) );
259 break;
260 case SubData::Sub:
261 writeToStdin( "sub_demux " + QString::number(ID) );
262 break;
263 case SubData::File:
264 writeToStdin( "sub_file " + QString::number(ID) );
265 break;
266 default: {
267 qWarning("MplayerProcess::setSubtitle: unknown type!");
268 }
269 }
270}
271
272void MplayerProcess::disableSubtitles() {
273 writeToStdin("sub_source -1");
274}
275
276void MplayerProcess::setSubtitlesVisibility(bool b) {
277 writeToStdin(QString("sub_visibility %1").arg(b ? 1 : 0));
278}
279
280void MplayerProcess::seek(double secs, int mode, bool precise) {
281 QString s = QString("seek %1 %2").arg(secs).arg(mode);
282 if (precise) s += " 1"; else s += " -1";
283 writeToStdin(s);
284}
285
286void MplayerProcess::mute(bool b) {
287 writeToStdin(pausing_prefix + " mute " + QString::number(b ? 1 : 0));
288}
289
290void MplayerProcess::setPause(bool /*b*/) {
291 writeToStdin("pause"); // pauses / unpauses
292}
293
294void MplayerProcess::frameStep() {
295 writeToStdin("frame_step");
296}
297
298void MplayerProcess::frameBackStep() {
299 qDebug("MplayerProcess::frameBackStep: function not supported by mplayer");
300 showOSDText(tr("This option is not supported by MPlayer"), 3000, 1);
301}
302
303
304void MplayerProcess::showOSDText(const QString & text, int duration, int level) {
305 QString str = QString("osd_show_text \"%1\" %2 %3").arg(text).arg(duration).arg(level);
306 if (!pausing_prefix.isEmpty()) str = pausing_prefix + " " + str;
307 writeToStdin(str);
308}
309
310void MplayerProcess::showFilenameOnOSD() {
311 QString s = "${filename}";
312
313 if (!osd_media_info.isEmpty()) s = osd_media_info;
314
315 writeToStdin("osd_show_property_text \"" + s + "\" 2000 0");
316}
317
318void MplayerProcess::showTimeOnOSD() {
319 writeToStdin("osd_show_property_text \"${time_pos} / ${length} (${percent_pos}%)\" 2000 0");
320}
321
322void MplayerProcess::setContrast(int value) {
323 writeToStdin(pausing_prefix + " contrast " + QString::number(value) + " 1");
324}
325
326void MplayerProcess::setBrightness(int value) {
327 writeToStdin(pausing_prefix + " brightness " + QString::number(value) + " 1");
328}
329
330void MplayerProcess::setHue(int value) {
331 writeToStdin(pausing_prefix + " hue " + QString::number(value) + " 1");
332}
333
334void MplayerProcess::setSaturation(int value) {
335 writeToStdin(pausing_prefix + " saturation " + QString::number(value) + " 1");
336}
337
338void MplayerProcess::setGamma(int value) {
339 writeToStdin(pausing_prefix + " gamma " + QString::number(value) + " 1");
340}
341
342void MplayerProcess::setChapter(int ID) {
343 writeToStdin("seek_chapter " + QString::number(ID) +" 1");
344}
345
346void MplayerProcess::nextChapter() {
347 writeToStdin("seek_chapter 1 0");
348}
349
350void MplayerProcess::previousChapter() {
351 writeToStdin("seek_chapter -1 0");
352}
353
354void MplayerProcess::setExternalSubtitleFile(const QString & filename) {
355 writeToStdin("sub_load \""+ filename +"\"");
356}
357
358void MplayerProcess::setSubPos(int pos) {
359 writeToStdin("sub_pos " + QString::number(pos) + " 1");
360}
361
362void MplayerProcess::setSubScale(double value) {
363 writeToStdin("sub_scale " + QString::number(value) + " 1");
364}
365
366void MplayerProcess::setSubStep(int value) {
367 writeToStdin("sub_step " + QString::number(value));
368}
369
370#ifdef MPV_SUPPORT
371void MplayerProcess::seekSub(int /*value*/) {
372 /* Not supported */
373 showOSDText(tr("This option is not supported by MPlayer"), 3000, 1);
374};
375#endif
376
377void MplayerProcess::setSubForcedOnly(bool b) {
378 writeToStdin(QString("forced_subs_only %1").arg(b ? 1 : 0));
379}
380
381void MplayerProcess::setSpeed(double value) {
382 writeToStdin("speed_set " + QString::number(value));
383}
384
385void MplayerProcess::enableKaraoke(bool b) {
386 if (b) writeToStdin("af_add karaoke"); else writeToStdin("af_del karaoke");
387}
388
389void MplayerProcess::enableExtrastereo(bool b) {
390 if (b) writeToStdin("af_add extrastereo"); else writeToStdin("af_del extrastereo");
391}
392
393void MplayerProcess::enableVolnorm(bool b, const QString & option) {
394 if (b) writeToStdin("af_add volnorm=" + option); else writeToStdin("af_del volnorm");
395}
396
397void MplayerProcess::setAudioEqualizer(const QString & values) {
398 writeToStdin("af_cmdline equalizer " + values);
399}
400
401void MplayerProcess::setAudioDelay(double delay) {
402 writeToStdin(pausing_prefix + " audio_delay " + QString::number(delay) +" 1");
403}
404
405void MplayerProcess::setSubDelay(double delay) {
406 writeToStdin(pausing_prefix + " sub_delay " + QString::number(delay) +" 1");
407}
408
409void MplayerProcess::setLoop(int v) {
410 writeToStdin(QString("loop %1 1").arg(v));
411}
412
413void MplayerProcess::setAMarker(int /*sec*/) {
414 /* Not supported */
415}
416
417void MplayerProcess::setBMarker(int /*sec*/) {
418 /* Not supported */
419}
420
421void MplayerProcess::clearABMarkers() {
422 /* Not supported */
423}
424
425void MplayerProcess::takeScreenshot(ScreenshotType t, bool /*include_subtitles*/) {
426 if (t == Single) {
427 writeToStdin(pausing_prefix + " screenshot 0");
428 } else {
429 writeToStdin("screenshot 1");
430 }
431}
432
433#ifdef CAPTURE_STREAM
434void MplayerProcess::switchCapturing() {
435 writeToStdin("capturing");
436}
437#endif
438
439void MplayerProcess::setTitle(int ID) {
440 writeToStdin("switch_title " + QString::number(ID));
441}
442
443#if DVDNAV_SUPPORT
444void MplayerProcess::discSetMousePos(int x, int y) {
445 writeToStdin(QString("set_mouse_pos %1 %2").arg(x).arg(y));
446}
447
448void MplayerProcess::discButtonPressed(const QString & button_name) {
449 writeToStdin("dvdnav " + button_name);
450}
451#endif
452
453void MplayerProcess::setAspect(double aspect) {
454 writeToStdin("switch_ratio " + QString::number(aspect));
455}
456
457void MplayerProcess::setFullscreen(bool b) {
458 writeToStdin(QString("vo_fullscreen %1").arg(b ? "1" : "0"));
459}
460
461#if PROGRAM_SWITCH
462void MplayerProcess::setTSProgram(int ID) {
463 writeToStdin("set_property switch_program " + QString::number(ID) );
464 writeToStdin("get_property switch_audio");
465 writeToStdin("get_property switch_video");
466}
467#endif
468
469void MplayerProcess::toggleDeinterlace() {
470 writeToStdin("step_property deinterlace");
471}
472
473void MplayerProcess::askForLength() {
474 writeToStdin(pausing_prefix + " get_property length");
475}
476
477void MplayerProcess::setOSDScale(double /*value*/) {
478 // not available
479 /* writeToStdin("set_property subfont-osd-scale " + QString::number(value)); */
480}
481
482void MplayerProcess::changeVF(const QString & /*filter*/, bool /*enable*/, const QVariant & /*option*/) {
483 // not supported
484}
485
486void MplayerProcess::changeStereo3DFilter(bool /*enable*/, const QString & /*in*/, const QString & /*out*/) {
487 // not supported
488}
489
490void MplayerProcess::setSubStyles(const AssStyles & styles, const QString & assStylesFile) {
491 if (assStylesFile.isEmpty()) {
492 qWarning("MplayerProcess::setSubStyles: assStylesFile is invalid");
493 return;
494 }
495
496 // Load the styles.ass file
497 if (!QFile::exists(assStylesFile)) {
498 // If file doesn't exist, create it
499 styles.exportStyles(assStylesFile);
500 }
501 if (QFile::exists(assStylesFile)) {
502 setOption("ass-styles", assStylesFile);
503 } else {
504 qWarning("MplayerProcess::setSubStyles: '%s' doesn't exist", assStylesFile.toUtf8().constData());
505 }
506}
Note: See TracBrowser for help on using the repository browser.