Skip to content

Commit

Permalink
demux_playlist: add --directory-mode=auto
Browse files Browse the repository at this point in the history
This is a more useful default with --shuffle.
  • Loading branch information
guidocella authored and Dudemanguy committed Sep 21, 2023
1 parent 27f0a35 commit 6b09525
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Interface changes
- update defaults to `--hdr-peak-decay-rate=20`, `--hdr-scene-threshold-low=1.0`,
`--hdr-scene-threshold-high=3.0`
- update defaults to `--deband-threshold=48`, `--deband-grain=32`
- add `--directory-mode=auto` and make it the default
--- mpv 0.36.0 ---
- add `--target-contrast`
- Target luminance value is now also applied when ICC profile is used.
Expand Down
5 changes: 3 additions & 2 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3985,9 +3985,10 @@ Demuxer
libarchive opens all volumes anyway when playing the main file, even though
mpv iterated no archive entries yet.

``--directory-mode=<lazy|recursive|ignore>``
``--directory-mode=<auto|lazy|recursive|ignore>``
When opening a directory, open subdirectories lazily, recursively or not at
all (default: lazy).
all. The default is ``auto``, which behaves like ``recursive`` with
``--shuffle``, and like ``lazy`` otherwise.

Input
-----
Expand Down
12 changes: 11 additions & 1 deletion demux/demux_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define PROBE_SIZE (8 * 1024)

enum dir_mode {
DIR_AUTO,
DIR_LAZY,
DIR_RECURSIVE,
DIR_IGNORE,
Expand All @@ -50,14 +51,15 @@ struct demux_playlist_opts {
struct m_sub_options demux_playlist_conf = {
.opts = (const struct m_option[]) {
{"directory-mode", OPT_CHOICE(dir_mode,
{"auto", DIR_AUTO},
{"lazy", DIR_LAZY},
{"recursive", DIR_RECURSIVE},
{"ignore", DIR_IGNORE})},
{0}
},
.size = sizeof(struct demux_playlist_opts),
.defaults = &(const struct demux_playlist_opts){
.dir_mode = DIR_LAZY,
.dir_mode = DIR_AUTO,
},
};

Expand All @@ -73,6 +75,7 @@ static bool check_mimetype(struct stream *s, const char *const *list)
}

struct pl_parser {
struct mpv_global *global;
struct mp_log *log;
struct stream *s;
char buffer[2 * 1024 * 1024];
Expand Down Expand Up @@ -434,6 +437,12 @@ static int parse_dir(struct pl_parser *p)

struct stat dir_stack[MAX_DIR_STACK];

if (p->opts->dir_mode == DIR_AUTO) {
struct MPOpts *opts = mp_get_config_group(NULL, p->global, &mp_opt_root);
p->opts->dir_mode = opts->shuffle ? DIR_RECURSIVE : DIR_LAZY;
talloc_free(opts);
}

scan_dir(p, path, dir_stack, 0);

p->add_base = false;
Expand Down Expand Up @@ -486,6 +495,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
bool force = check < DEMUX_CHECK_UNSAFE || check == DEMUX_CHECK_REQUEST;

struct pl_parser *p = talloc_zero(NULL, struct pl_parser);
p->global = demuxer->global;
p->log = demuxer->log;
p->pl = talloc_zero(p, struct playlist);
p->real_stream = demuxer->stream;
Expand Down

0 comments on commit 6b09525

Please sign in to comment.