2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2006-04-25 01:26:10 +00:00
|
|
|
|
2002-11-12 01:56:42 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
2011-07-27 17:59:44 +00:00
|
|
|
#include <stdbool.h>
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2013-12-21 22:11:12 +00:00
|
|
|
#include "common/global.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2014-01-16 20:24:39 +00:00
|
|
|
#include "common/msg_control.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "m_option.h"
|
2002-11-12 01:56:42 +00:00
|
|
|
#include "m_config.h"
|
2013-12-21 22:11:12 +00:00
|
|
|
#include "options.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/playlist.h"
|
|
|
|
#include "common/playlist_parser.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "parse_commandline.h"
|
2002-11-12 01:56:42 +00:00
|
|
|
|
|
|
|
#define GLOBAL 0
|
|
|
|
#define LOCAL 1
|
|
|
|
|
2011-07-26 01:28:37 +00:00
|
|
|
#define dvd_range(a) (a > 0 && a < 256)
|
2002-11-12 01:56:42 +00:00
|
|
|
|
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
struct parse_state {
|
|
|
|
struct m_config *config;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
bool no_more_opts;
|
|
|
|
bool error;
|
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
bool is_opt;
|
2012-08-05 21:34:28 +00: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 04:24:09 +00:00
|
|
|
{
|
2012-08-05 21:34:28 +00:00
|
|
|
assert(!p->error);
|
|
|
|
|
|
|
|
if (p->argc < 1)
|
|
|
|
return 1;
|
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
p->is_opt = false;
|
2012-08-05 21:34:28 +00:00
|
|
|
p->arg = bstr0(p->argv[0]);
|
|
|
|
p->param = bstr0(NULL);
|
|
|
|
|
|
|
|
p->argc--;
|
|
|
|
p->argv++;
|
|
|
|
|
|
|
|
if (p->no_more_opts || !bstr_startswith0(p->arg, "-") || p->arg.len == 1)
|
|
|
|
return 0;
|
|
|
|
|
2012-09-02 18:30:16 +00:00
|
|
|
if (bstrcmp0(p->arg, "--") == 0) {
|
|
|
|
p->no_more_opts = true;
|
|
|
|
return split_opt_silent(p);
|
|
|
|
}
|
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
p->is_opt = true;
|
2012-08-05 21:34:28 +00:00
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
if (!bstr_eatstart0(&p->arg, "--"))
|
|
|
|
bstr_eatstart0(&p->arg, "-");
|
2012-09-20 01:32:01 +00:00
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
bool ambiguous = !bstr_split_tok(p->arg, "=", &p->arg, &p->param);
|
2012-08-05 21:34:28 +00:00
|
|
|
|
options: change handling of "no-" options yet again
Commit 4a40eed "options: change handling of "no-" options" generally
improved the handling of automatically added negation options
(recognizing "--no-opt", even though only "--opt" is declared in the
option list).
Unfortunately, one corner case was missed, which broke the option
"--input=no-default-bindings" (other suboptions, e.g. VO suboptions,
were not affected, and this is the only option where this mattered).
Instead of increasing the complexity further, use a completely different
approach: add the "--no-" options at runtime, and make them behave like
real options. This approach could be considered slightly less elegant,
because the code now has to worry about some option implementation
details rather than leaving it to the parser, but all in all the new
code is simpler and there are less weird corner cases to worry about.
2013-02-16 18:57:57 +00:00
|
|
|
int r = m_config_option_requires_param(p->config, p->arg);
|
2012-09-21 07:22:25 +00:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2012-08-05 21:34:28 +00:00
|
|
|
|
2012-09-21 07:22:25 +00:00
|
|
|
if (ambiguous && r > 0) {
|
2012-08-05 21:34:28 +00:00
|
|
|
if (p->argc < 1)
|
2012-09-21 07:22:25 +00:00
|
|
|
return M_OPT_MISSING_PARAM;
|
2012-08-05 21:34:28 +00:00
|
|
|
p->param = bstr0(p->argv[0]);
|
|
|
|
p->argc--;
|
|
|
|
p->argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-07-29 04:24:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 21:34:28 +00: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 15:32:11 +00:00
|
|
|
{
|
2012-08-05 21:34:28 +00:00
|
|
|
int r = split_opt_silent(p);
|
|
|
|
if (r >= 0)
|
|
|
|
return r == 0;
|
|
|
|
p->error = true;
|
2012-09-21 07:22:25 +00:00
|
|
|
|
2013-12-21 19:08:34 +00:00
|
|
|
MP_FATAL(p->config, "Error parsing commandline option %.*s: %s\n",
|
|
|
|
BSTR_P(p->arg), m_option_strerror(r));
|
2012-08-05 21:34:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-15 14:02:52 +00:00
|
|
|
// returns M_OPT_... error code
|
|
|
|
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
2013-12-21 19:08:34 +00:00
|
|
|
struct mpv_global *global,
|
2013-05-15 14:02:52 +00:00
|
|
|
int argc, char **argv)
|
2002-11-12 01:56:42 +00:00
|
|
|
{
|
2013-05-15 14:02:52 +00:00
|
|
|
int ret = M_OPT_UNKNOWN;
|
2011-07-29 04:24:09 +00: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 19:33:26 +00:00
|
|
|
struct playlist_entry *local_start = NULL;
|
|
|
|
|
|
|
|
int local_params_count = 0;
|
|
|
|
struct playlist_param *local_params = 0;
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-26 01:28:37 +00:00
|
|
|
assert(config != NULL);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-26 01:28:37 +00:00
|
|
|
mode = GLOBAL;
|
2004-11-10 16:43:40 +00:00
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
struct parse_state p = {config, argc, argv};
|
|
|
|
while (split_opt(&p)) {
|
2012-09-21 07:22:25 +00:00
|
|
|
if (p.is_opt) {
|
2013-10-25 20:52:54 +00: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 14:02:52 +00:00
|
|
|
if (r <= M_OPT_EXIT) {
|
|
|
|
ret = r;
|
2012-10-31 23:42:27 +00:00
|
|
|
goto err_out;
|
2013-05-15 14:02:52 +00:00
|
|
|
}
|
2012-10-31 23:42:27 +00:00
|
|
|
if (r < 0) {
|
2013-12-21 19:08:34 +00:00
|
|
|
MP_FATAL(config, "Setting commandline option --%.*s=%.*s failed.\n",
|
|
|
|
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 19:33:26 +00:00
|
|
|
goto err_out;
|
2011-07-26 01:28:37 +00:00
|
|
|
}
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
// Handle some special arguments outside option parser.
|
|
|
|
|
|
|
|
if (!bstrcmp0(p.arg, "{")) {
|
|
|
|
if (mode != GLOBAL) {
|
2013-12-21 19:08:34 +00:00
|
|
|
MP_ERR(config, "'--{' can not be nested.\n");
|
2012-08-05 21:34:28 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
mode = LOCAL;
|
|
|
|
assert(!local_start);
|
|
|
|
local_start = files->last;
|
|
|
|
continue;
|
2011-07-26 01:28:37 +00:00
|
|
|
}
|
2012-08-05 21:34:28 +00:00
|
|
|
|
|
|
|
if (!bstrcmp0(p.arg, "}")) {
|
|
|
|
if (mode != LOCAL) {
|
2013-12-21 19:08:34 +00:00
|
|
|
MP_ERR(config, "Too many closing '--}'.\n");
|
2012-08-05 21:34:28 +00: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 19:08:34 +00:00
|
|
|
MP_WARN(config, "Ignored options!\n");
|
2012-08-05 21:34:28 +00: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 19:33:26 +00:00
|
|
|
}
|
2012-08-05 21:34:28 +00:00
|
|
|
local_params_count = 0;
|
|
|
|
mode = GLOBAL;
|
2013-08-02 15:59:43 +00:00
|
|
|
m_config_restore_backups(config);
|
2012-08-05 21:34:28 +00:00
|
|
|
local_start = NULL;
|
2013-02-21 21:15:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-08-05 21:34:28 +00: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 19:33:26 +00:00
|
|
|
// append the playlist to the local args
|
2012-08-05 21:34:28 +00:00
|
|
|
char *param0 = bstrdup0(NULL, p.param);
|
2013-12-21 19:15:47 +00: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 19:33:26 +00:00
|
|
|
talloc_free(param0);
|
2012-09-21 07:22:25 +00:00
|
|
|
if (!pl) {
|
2013-12-21 19:08:34 +00:00
|
|
|
MP_FATAL(config, "Error reading playlist '%.*s'", BSTR_P(p.param));
|
2012-09-21 07:22:25 +00: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 19:33:26 +00:00
|
|
|
playlist_transfer_entries(files, pl);
|
|
|
|
talloc_free(pl);
|
2012-08-05 21:34:28 +00: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 07:16:53 +00:00
|
|
|
void *tmp = talloc_new(NULL);
|
2012-08-05 21:34:28 +00:00
|
|
|
bstr file = p.arg;
|
2013-05-04 07:16:53 +00:00
|
|
|
char *file0 = bstrdup0(tmp, p.arg);
|
2011-07-26 02:58:00 +00:00
|
|
|
// expand DVD filename entries like dvd://1-3 into component titles
|
2012-08-12 16:40:21 +00:00
|
|
|
if (bstr_startswith0(file, "dvd://")) {
|
|
|
|
int offset = 6;
|
2012-08-05 21:34:28 +00:00
|
|
|
char *splitpos = strstr(file0 + offset, "-");
|
2011-07-26 01:28:37 +00:00
|
|
|
if (splitpos != NULL) {
|
2013-05-04 07:16:53 +00:00
|
|
|
char *endpos;
|
|
|
|
int start_title = strtol(file0 + offset, &endpos, 10);
|
2011-07-29 04:24:09 +00:00
|
|
|
int end_title;
|
2011-07-26 02:58:00 +00:00
|
|
|
//entries like dvd://-2 imply start at title 1
|
|
|
|
if (start_title < 0) {
|
2011-07-26 01:28:37 +00:00
|
|
|
end_title = abs(start_title);
|
|
|
|
start_title = 1;
|
|
|
|
} else
|
2013-05-04 07:16:53 +00:00
|
|
|
end_title = strtol(splitpos + 1, &endpos, 10);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-26 01:28:37 +00:00
|
|
|
if (dvd_range(start_title) && dvd_range(end_title)
|
|
|
|
&& (start_title < end_title)) {
|
2011-07-29 04:24:09 +00:00
|
|
|
for (int j = start_title; j <= end_title; j++) {
|
2013-05-04 07:16:53 +00:00
|
|
|
char *f = talloc_asprintf(tmp, "dvd://%d%s", j,
|
|
|
|
endpos);
|
|
|
|
playlist_add_file(files, f);
|
2011-07-26 01:28:37 +00:00
|
|
|
}
|
|
|
|
} else
|
2013-12-21 19:08:34 +00:00
|
|
|
MP_ERR(config, "Invalid play entry %s\n", file0);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-26 01:28:37 +00:00
|
|
|
} else // dvd:// or dvd://x entry
|
2012-08-05 21:34:28 +00:00
|
|
|
playlist_add_file(files, file0);
|
2011-07-26 01:28:37 +00:00
|
|
|
} else
|
2012-08-05 21:34:28 +00:00
|
|
|
playlist_add_file(files, file0);
|
2013-05-04 07:16:53 +00:00
|
|
|
talloc_free(tmp);
|
2004-06-07 18:58:08 +00:00
|
|
|
|
2011-07-26 01:28:37 +00:00
|
|
|
// Lock stdin if it will be used as input
|
2012-08-05 21:34:28 +00:00
|
|
|
if (bstrcmp0(file, "-") == 0)
|
|
|
|
m_config_set_option0(config, "consolecontrols", "no");
|
2011-07-26 01:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
if (p.error)
|
2011-07-26 01:28:37 +00: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 19:33:26 +00:00
|
|
|
|
|
|
|
if (mode != GLOBAL) {
|
2013-12-21 19:08:34 +00: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 19:33:26 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2013-05-15 14:02:52 +00:00
|
|
|
ret = 0; // success
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-26 01:28:37 +00: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 19:33:26 +00:00
|
|
|
talloc_free(local_params);
|
2013-08-02 15:59:43 +00:00
|
|
|
m_config_restore_backups(config);
|
2013-05-15 14:02:52 +00:00
|
|
|
return ret;
|
2002-11-12 01:56:42 +00:00
|
|
|
}
|
2011-07-26 02:58:00 +00:00
|
|
|
|
|
|
|
/* Parse some command line options early before main parsing.
|
2013-02-08 22:52:06 +00:00
|
|
|
* --no-config prevents reading configuration files (otherwise done before
|
2011-07-26 02:58:00 +00:00
|
|
|
* command line parsing), and --really-quiet suppresses messages printed
|
|
|
|
* during normal options parsing.
|
|
|
|
*/
|
2013-12-21 22:11:12 +00:00
|
|
|
void m_config_preparse_command_line(m_config_t *config, struct mpv_global *global,
|
|
|
|
int argc, char **argv)
|
2011-07-26 02:58:00 +00:00
|
|
|
{
|
2013-12-21 22:11:12 +00:00
|
|
|
struct MPOpts *opts = global->opts;
|
|
|
|
|
2011-07-26 02:58:00 +00:00
|
|
|
// Hack to shut up parser error messages
|
2013-12-21 22:11:12 +00:00
|
|
|
mp_msg_mute(global, true);
|
2011-07-26 02:58:00 +00:00
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
struct parse_state p = {config, argc, argv};
|
|
|
|
while (split_opt_silent(&p) == 0) {
|
2012-09-21 07:22:25 +00:00
|
|
|
if (p.is_opt) {
|
2012-08-05 21:34:28 +00:00
|
|
|
// Ignore non-pre-parse options. They will be set later.
|
|
|
|
// Option parsing errors will be handled later as well.
|
2013-10-25 20:52:54 +00: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 22:02:03 +00:00
|
|
|
if (bstrcmp0(p.arg, "v") == 0)
|
2013-12-21 22:11:12 +00:00
|
|
|
opts->verbose++;
|
2012-05-07 20:51:58 +00:00
|
|
|
}
|
2011-07-26 02:58:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 22:11:12 +00:00
|
|
|
mp_msg_mute(global, false);
|
2011-07-26 02:58:00 +00:00
|
|
|
}
|