2010-01-31 00:24:23 +01:00
|
|
|
/*
|
2015-04-13 09:36:54 +02:00
|
|
|
* This file is part of mpv.
|
2010-01-31 00:24:23 +01:00
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2010-01-31 00:24:23 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-31 00:24:23 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 09:36:54 +02:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-31 00:24:23 +01:00
|
|
|
*/
|
2006-04-25 03:26:10 +02:00
|
|
|
|
2002-11-12 02:56:42 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
2011-07-27 19:59:44 +02:00
|
|
|
#include <stdbool.h>
|
2002-11-12 02:56:42 +01:00
|
|
|
|
2014-02-13 08:50:56 +01:00
|
|
|
#include "osdep/io.h"
|
2013-12-21 23:11:12 +01:00
|
|
|
#include "common/global.h"
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "common/msg.h"
|
2014-01-16 21:24:39 +01:00
|
|
|
#include "common/msg_control.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "m_option.h"
|
2002-11-12 02:56:42 +01:00
|
|
|
#include "m_config.h"
|
2013-12-21 23:11:12 +01:00
|
|
|
#include "options.h"
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "common/playlist.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "parse_commandline.h"
|
2002-11-12 02:56:42 +01:00
|
|
|
|
|
|
|
#define GLOBAL 0
|
|
|
|
#define LOCAL 1
|
|
|
|
|
2014-03-17 18:30:26 +01:00
|
|
|
#define dvd_range(a) (a >= 0 && a < 255)
|
2002-11-12 02:56:42 +01:00
|
|
|
|
|
|
|
|
2012-08-05 23:34:28 +02:00
|
|
|
struct parse_state {
|
|
|
|
struct m_config *config;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
bool no_more_opts;
|
|
|
|
bool error;
|
|
|
|
|
2012-09-21 09:22:25 +02:00
|
|
|
bool is_opt;
|
2012-08-05 23:34:28 +02:00
|
|
|
struct bstr arg;
|
|
|
|
struct bstr param;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns 0 if a valid option/file is available, <0 on error, 1 on end of args.
|
|
|
|
static int split_opt_silent(struct parse_state *p)
|
2011-07-29 06:24:09 +02:00
|
|
|
{
|
2012-08-05 23:34:28 +02:00
|
|
|
assert(!p->error);
|
|
|
|
|
2015-03-05 10:57:38 +01:00
|
|
|
if (!p->argv || !p->argv[0])
|
2012-08-05 23:34:28 +02:00
|
|
|
return 1;
|
|
|
|
|
2012-09-21 09:22:25 +02:00
|
|
|
p->is_opt = false;
|
2012-08-05 23:34:28 +02:00
|
|
|
p->arg = bstr0(p->argv[0]);
|
|
|
|
p->param = bstr0(NULL);
|
|
|
|
|
|
|
|
p->argv++;
|
|
|
|
|
|
|
|
if (p->no_more_opts || !bstr_startswith0(p->arg, "-") || p->arg.len == 1)
|
|
|
|
return 0;
|
|
|
|
|
2012-09-02 20:30:16 +02:00
|
|
|
if (bstrcmp0(p->arg, "--") == 0) {
|
|
|
|
p->no_more_opts = true;
|
|
|
|
return split_opt_silent(p);
|
|
|
|
}
|
|
|
|
|
2012-09-21 09:22:25 +02:00
|
|
|
p->is_opt = true;
|
2012-08-05 23:34:28 +02:00
|
|
|
|
2012-09-21 09:22:25 +02:00
|
|
|
if (!bstr_eatstart0(&p->arg, "--"))
|
|
|
|
bstr_eatstart0(&p->arg, "-");
|
2012-09-20 03:32:01 +02:00
|
|
|
|
2012-09-21 09:22:25 +02:00
|
|
|
bool ambiguous = !bstr_split_tok(p->arg, "=", &p->arg, &p->param);
|
2012-08-05 23:34:28 +02:00
|
|
|
|
2015-03-29 09:03:34 +02:00
|
|
|
if (!p->arg.len)
|
|
|
|
return M_OPT_INVALID;
|
|
|
|
|
2014-05-05 23:50:17 +02:00
|
|
|
bool need_param = m_config_option_requires_param(p->config, p->arg) > 0;
|
2012-08-05 23:34:28 +02:00
|
|
|
|
2014-05-05 23:50:17 +02:00
|
|
|
if (ambiguous && need_param) {
|
2015-03-05 10:57:38 +01:00
|
|
|
if (!p->argv[0])
|
2012-09-21 09:22:25 +02:00
|
|
|
return M_OPT_MISSING_PARAM;
|
2012-08-05 23:34:28 +02:00
|
|
|
p->param = bstr0(p->argv[0]);
|
|
|
|
p->argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-07-29 06:24:09 +02:00
|
|
|
}
|
|
|
|
|
2012-08-05 23:34:28 +02:00
|
|
|
// Returns true if more args, false if all parsed or an error occurred.
|
|
|
|
static bool split_opt(struct parse_state *p)
|
2011-09-01 17:32:11 +02:00
|
|
|
{
|
2012-08-05 23:34:28 +02:00
|
|
|
int r = split_opt_silent(p);
|
|
|
|
if (r >= 0)
|
|
|
|
return r == 0;
|
|
|
|
p->error = true;
|
2012-09-21 09:22:25 +02:00
|
|
|
|
2015-03-29 09:03:34 +02:00
|
|
|
MP_FATAL(p->config, "Error parsing command line option '%.*s': %s\n",
|
2013-12-21 20:08:34 +01:00
|
|
|
BSTR_P(p->arg), m_option_strerror(r));
|
2012-08-05 23:34:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-13 08:50:56 +01:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
static void process_non_option(struct playlist *files, const char *arg)
|
|
|
|
{
|
|
|
|
glob_t gg;
|
|
|
|
|
|
|
|
// Glob filenames on Windows (cmd.exe doesn't do this automatically)
|
|
|
|
if (glob(arg, 0, NULL, &gg)) {
|
|
|
|
playlist_add_file(files, arg);
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < gg.gl_pathc; i++)
|
|
|
|
playlist_add_file(files, gg.gl_pathv[i]);
|
|
|
|
|
|
|
|
globfree(&gg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void process_non_option(struct playlist *files, const char *arg)
|
|
|
|
{
|
|
|
|
playlist_add_file(files, arg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-15 16:02:52 +02:00
|
|
|
// returns M_OPT_... error code
|
|
|
|
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
2015-03-05 10:57:38 +01:00
|
|
|
struct mpv_global *global, char **argv)
|
2002-11-12 02:56:42 +01:00
|
|
|
{
|
2013-05-15 16:02:52 +02:00
|
|
|
int ret = M_OPT_UNKNOWN;
|
2011-07-29 06:24:09 +02:00
|
|
|
int mode = 0;
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
struct playlist_entry *local_start = NULL;
|
|
|
|
|
|
|
|
int local_params_count = 0;
|
|
|
|
struct playlist_param *local_params = 0;
|
2002-11-12 02:56:42 +01:00
|
|
|
|
2011-07-26 03:28:37 +02:00
|
|
|
assert(config != NULL);
|
2002-11-12 02:56:42 +01:00
|
|
|
|
2011-07-26 03:28:37 +02:00
|
|
|
mode = GLOBAL;
|
2004-11-10 17:43:40 +01:00
|
|
|
|
2015-03-06 10:53:49 +01:00
|
|
|
struct parse_state p = {config, argv};
|
2012-08-05 23:34:28 +02:00
|
|
|
while (split_opt(&p)) {
|
2012-09-21 09:22:25 +02:00
|
|
|
if (p.is_opt) {
|
2013-10-25 22:52:54 +02:00
|
|
|
int flags = M_SETOPT_FROM_CMDLINE;
|
|
|
|
if (mode == LOCAL)
|
|
|
|
flags |= M_SETOPT_BACKUP | M_SETOPT_CHECK_ONLY;
|
|
|
|
int r = m_config_set_option_ext(config, p.arg, p.param, flags);
|
2013-05-15 16:02:52 +02:00
|
|
|
if (r <= M_OPT_EXIT) {
|
|
|
|
ret = r;
|
2012-11-01 00:42:27 +01:00
|
|
|
goto err_out;
|
2013-05-15 16:02:52 +02:00
|
|
|
}
|
2012-11-01 00:42:27 +01:00
|
|
|
if (r < 0) {
|
2015-03-29 09:03:34 +02:00
|
|
|
MP_FATAL(config, "Setting command line option '--%.*s=%.*s' failed.\n",
|
2013-12-21 20:08:34 +01:00
|
|
|
BSTR_P(p.arg), BSTR_P(p.param));
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
goto err_out;
|
2011-07-26 03:28:37 +02:00
|
|
|
}
|
2002-11-12 02:56:42 +01:00
|
|
|
|
2012-08-05 23:34:28 +02:00
|
|
|
// Handle some special arguments outside option parser.
|
|
|
|
|
|
|
|
if (!bstrcmp0(p.arg, "{")) {
|
|
|
|
if (mode != GLOBAL) {
|
2013-12-21 20:08:34 +01:00
|
|
|
MP_ERR(config, "'--{' can not be nested.\n");
|
2012-08-05 23:34:28 +02:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
mode = LOCAL;
|
|
|
|
assert(!local_start);
|
|
|
|
local_start = files->last;
|
|
|
|
continue;
|
2011-07-26 03:28:37 +02:00
|
|
|
}
|
2012-08-05 23:34:28 +02:00
|
|
|
|
|
|
|
if (!bstrcmp0(p.arg, "}")) {
|
|
|
|
if (mode != LOCAL) {
|
2013-12-21 20:08:34 +01:00
|
|
|
MP_ERR(config, "Too many closing '--}'.\n");
|
2012-08-05 23:34:28 +02:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
if (local_params_count) {
|
|
|
|
// The files added between '{' and '}' are the entries from
|
|
|
|
// the entry _after_ local_start, until the end of the list.
|
|
|
|
// If local_start is NULL, the list was empty on '{', and we
|
|
|
|
// want all files in the list.
|
|
|
|
struct playlist_entry *cur
|
|
|
|
= local_start ? local_start->next : files->first;
|
|
|
|
if (!cur)
|
2013-12-21 20:08:34 +01:00
|
|
|
MP_WARN(config, "Ignored options!\n");
|
2012-08-05 23:34:28 +02:00
|
|
|
while (cur) {
|
|
|
|
playlist_entry_add_params(cur, local_params,
|
|
|
|
local_params_count);
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
}
|
2012-08-05 23:34:28 +02:00
|
|
|
local_params_count = 0;
|
|
|
|
mode = GLOBAL;
|
2013-08-02 17:59:43 +02:00
|
|
|
m_config_restore_backups(config);
|
2012-08-05 23:34:28 +02:00
|
|
|
local_start = NULL;
|
2013-02-21 22:15:26 +01:00
|
|
|
continue;
|
|
|
|
}
|
2012-08-05 23:34:28 +02:00
|
|
|
|
|
|
|
if (bstrcmp0(p.arg, "playlist") == 0) {
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
// append the playlist to the local args
|
2012-08-05 23:34:28 +02:00
|
|
|
char *param0 = bstrdup0(NULL, p.param);
|
2013-12-21 20:15:47 +01:00
|
|
|
struct playlist *pl = playlist_parse_file(param0, global);
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
talloc_free(param0);
|
2012-09-21 09:22:25 +02:00
|
|
|
if (!pl) {
|
2015-02-20 21:56:55 +01:00
|
|
|
MP_FATAL(config, "Error reading playlist '%.*s'\n",
|
|
|
|
BSTR_P(p.param));
|
2012-09-21 09:22:25 +02:00
|
|
|
goto err_out;
|
|
|
|
}
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
playlist_transfer_entries(files, pl);
|
|
|
|
talloc_free(pl);
|
2012-08-05 23:34:28 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == LOCAL) {
|
|
|
|
MP_TARRAY_APPEND(NULL, local_params, local_params_count,
|
|
|
|
(struct playlist_param) {p.arg, p.param});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// filename
|
2013-05-04 09:16:53 +02:00
|
|
|
void *tmp = talloc_new(NULL);
|
2012-08-05 23:34:28 +02:00
|
|
|
bstr file = p.arg;
|
2013-05-04 09:16:53 +02:00
|
|
|
char *file0 = bstrdup0(tmp, p.arg);
|
2011-07-26 04:58:00 +02:00
|
|
|
// expand DVD filename entries like dvd://1-3 into component titles
|
2012-08-12 18:40:21 +02:00
|
|
|
if (bstr_startswith0(file, "dvd://")) {
|
|
|
|
int offset = 6;
|
2012-08-05 23:34:28 +02:00
|
|
|
char *splitpos = strstr(file0 + offset, "-");
|
2011-07-26 03:28:37 +02:00
|
|
|
if (splitpos != NULL) {
|
2013-05-04 09:16:53 +02:00
|
|
|
char *endpos;
|
|
|
|
int start_title = strtol(file0 + offset, &endpos, 10);
|
2011-07-29 06:24:09 +02:00
|
|
|
int end_title;
|
2011-07-26 04:58:00 +02:00
|
|
|
//entries like dvd://-2 imply start at title 1
|
|
|
|
if (start_title < 0) {
|
2011-07-26 03:28:37 +02:00
|
|
|
end_title = abs(start_title);
|
|
|
|
start_title = 1;
|
|
|
|
} else
|
2013-05-04 09:16:53 +02:00
|
|
|
end_title = strtol(splitpos + 1, &endpos, 10);
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2011-07-26 03:28:37 +02:00
|
|
|
if (dvd_range(start_title) && dvd_range(end_title)
|
|
|
|
&& (start_title < end_title)) {
|
2011-07-29 06:24:09 +02:00
|
|
|
for (int j = start_title; j <= end_title; j++) {
|
2013-05-04 09:16:53 +02:00
|
|
|
char *f = talloc_asprintf(tmp, "dvd://%d%s", j,
|
|
|
|
endpos);
|
|
|
|
playlist_add_file(files, f);
|
2011-07-26 03:28:37 +02:00
|
|
|
}
|
|
|
|
} else
|
2013-12-21 20:08:34 +01:00
|
|
|
MP_ERR(config, "Invalid play entry %s\n", file0);
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2011-07-26 03:28:37 +02:00
|
|
|
} else // dvd:// or dvd://x entry
|
2012-08-05 23:34:28 +02:00
|
|
|
playlist_add_file(files, file0);
|
2014-02-13 08:50:56 +01:00
|
|
|
} else {
|
|
|
|
process_non_option(files, file0);
|
|
|
|
}
|
2013-05-04 09:16:53 +02:00
|
|
|
talloc_free(tmp);
|
2011-07-26 03:28:37 +02:00
|
|
|
}
|
|
|
|
}
|
2002-11-12 02:56:42 +01:00
|
|
|
|
2012-08-05 23:34:28 +02:00
|
|
|
if (p.error)
|
2011-07-26 03:28:37 +02:00
|
|
|
goto err_out;
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
|
|
|
|
if (mode != GLOBAL) {
|
2013-12-21 20:08:34 +01:00
|
|
|
MP_ERR(config, "Missing closing --} on command line.\n");
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2013-05-15 16:02:52 +02:00
|
|
|
ret = 0; // success
|
2002-11-12 02:56:42 +01:00
|
|
|
|
2011-07-26 03:28:37 +02:00
|
|
|
err_out:
|
mplayer: turn playtree into a list, and change per-file option handling
Summary:
- There is no playtree anymore. It's reduced to a simple list.
- Options are now always global. You can still have per-file options,
but these are optional and require special syntax.
- The slave command pt_step has been removed, and playlist_next
and playlist_prev added. (See etc/input.conf changes.)
This is a user visible incompatible change, and will break slave-mode
applications.
- The pt_clear slave command is renamed to playlist_clear.
- Playtree entries could have multiple files. This is not the case
anymore, and playlist entries have always exactly one entry. Whenever
something adds more than one file (like ASX playlists or dvd:// or
dvdnav:// on the command line), all files are added as separate
playlist entries.
Note that some of the changes are quite deep and violent. Expect
regressions.
The playlist parsing code in particular is of low quality. I didn't try
to improve it, and merely spent to least effort necessary to keep it
somehow working. (Especially ASX playlist handling.)
The playtree code was complicated and bloated. It was also barely used.
Most users don't even know that mplayer manages the playlist as tree,
or how to use it. The most obscure features was probably specifying a
tree on command line (with '{' and '}' to create/close tree nodes). It
filled the player code with complexity and confused users with weird
slave commands like pt_up.
Replace the playtree with a simple flat playlist. Playlist parsers that
actually return trees are changed to append all files to the playlist
pre-order.
It used to be the responsibility of the playtree code to change per-file
config options. Now this is done by the player core, and the playlist
code is free of such details.
Options are not per-file by default anymore. This was a very obscure and
complicated feature that confused even experienced users. Consider the
following command line:
mplayer file1.mkv file2.mkv --no-audio file3.mkv
This will disable the audio for file2.mkv only, because options are
per-file by default. To make the option affect all files, you're
supposed to put it before the first file.
This is bad, because normally you don't need per-file options. They are
very rarely needed, and the only reasonable use cases I can imagine are
use of the encode backend (mplayer encode branch), or for debugging. The
normal use case is made harder, and the feature is perceived as bug.
Even worse, correct usage is hard to explain for users.
Make all options global by default. The position of an option isn't
significant anymore (except for options that compensate each other,
consider --shuffle --no-shuffle).
One other important change is that no options are reset anymore if a
new file is started. If you change settings with slave mode commands,
they will not be changed by playing a new file. (Exceptions include
settings that are too file specific, like audio/subtitle stream
selection.)
There is still some need for per-file options. Debugging and encoding
are use cases that profit from per-file options. Per-file profiles (as
well as per-protocol and per-VO/AO options) need the implementation
related mechanisms to backup and restore options when the playback file
changes.
Simplify the save-slot stuff, which is possible because there is no
hierarchical play tree anymore. Now there's a simple backup field.
Add a way to specify per-file options on command line. Example:
mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3
will have the following options per file set:
f1.mkv, f4.mkv: -o0 -o3
f2.mkv, f3.mkv: -o0 -o3 -o1 -o2
The options --{ and --} start and end per-file options. All files inside
the { } will be affected by the options equally (similar to how global
options and multiple files are handled). When playback of a file starts,
the per-file options are set according to the command line. When
playback ends, the per-file options are restored to the values when
playback started.
2012-07-31 21:33:26 +02:00
|
|
|
talloc_free(local_params);
|
2013-08-02 17:59:43 +02:00
|
|
|
m_config_restore_backups(config);
|
2013-05-15 16:02:52 +02:00
|
|
|
return ret;
|
2002-11-12 02:56:42 +01:00
|
|
|
}
|
2011-07-26 04:58:00 +02:00
|
|
|
|
|
|
|
/* Parse some command line options early before main parsing.
|
2013-02-08 23:52:06 +01:00
|
|
|
* --no-config prevents reading configuration files (otherwise done before
|
2011-07-26 04:58:00 +02:00
|
|
|
* command line parsing), and --really-quiet suppresses messages printed
|
|
|
|
* during normal options parsing.
|
|
|
|
*/
|
2013-12-21 23:11:12 +01:00
|
|
|
void m_config_preparse_command_line(m_config_t *config, struct mpv_global *global,
|
2015-03-05 10:57:38 +01:00
|
|
|
char **argv)
|
2011-07-26 04:58:00 +02:00
|
|
|
{
|
2013-12-21 23:11:12 +01:00
|
|
|
struct MPOpts *opts = global->opts;
|
|
|
|
|
2015-03-06 10:53:49 +01:00
|
|
|
struct parse_state p = {config, argv};
|
2012-08-05 23:34:28 +02:00
|
|
|
while (split_opt_silent(&p) == 0) {
|
2012-09-21 09:22:25 +02:00
|
|
|
if (p.is_opt) {
|
2012-08-05 23:34:28 +02:00
|
|
|
// Ignore non-pre-parse options. They will be set later.
|
|
|
|
// Option parsing errors will be handled later as well.
|
2013-10-25 22:52:54 +02:00
|
|
|
int flags = M_SETOPT_FROM_CMDLINE | M_SETOPT_PRE_PARSE_ONLY;
|
|
|
|
m_config_set_option_ext(config, p.arg, p.param, flags);
|
2012-12-12 23:02:03 +01:00
|
|
|
if (bstrcmp0(p.arg, "v") == 0)
|
2013-12-21 23:11:12 +01:00
|
|
|
opts->verbose++;
|
2012-05-07 22:51:58 +02:00
|
|
|
}
|
2011-07-26 04:58:00 +02:00
|
|
|
}
|
|
|
|
|
2014-12-11 01:04:15 +01:00
|
|
|
for (int n = 0; n < config->num_opts; n++)
|
|
|
|
config->opts[n].warning_was_printed = false;
|
2011-07-26 04:58:00 +02:00
|
|
|
}
|