Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m3u: introduce EXT-MPV to allow specifying per-file parameters #12806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions common/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,29 @@
#include "demux/demux.h"
#include "stream/stream.h"

struct playlist_entry *playlist_entry_new(const char *filename)
struct playlist_entry *playlist_entry_new_uninitialized()
{
struct playlist_entry *e = talloc_zero(NULL, struct playlist_entry);
char *local_filename = mp_file_url_to_filename(e, bstr0(filename));
e->filename = local_filename ? local_filename : talloc_strdup(e, filename);
e->filename = NULL;
e->stream_flags = STREAM_ORIGIN_DIRECT;
e->original_index = -1;
return e;
}

struct playlist_entry *playlist_entry_init_filename(struct playlist_entry *e, const char *filename)
{
assert(e->filename == NULL);
char *local_filename = mp_file_url_to_filename(e, bstr0(filename));
e->filename = local_filename ? local_filename : talloc_strdup(e, filename);
return e;
}

struct playlist_entry *playlist_entry_new(const char *filename)
{
struct playlist_entry *e = playlist_entry_new_uninitialized();
return playlist_entry_init_filename(e, filename);
}

void playlist_entry_add_param(struct playlist_entry *e, bstr name, bstr value)
{
struct playlist_param p = {bstrdup(e, name), bstrdup(e, value)};
Expand Down
2 changes: 2 additions & 0 deletions common/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void playlist_entry_add_params(struct playlist_entry *e,
struct playlist_param *params,
int params_count);

struct playlist_entry *playlist_entry_new_uninitialized(void);
struct playlist_entry *playlist_entry_init_filename(struct playlist_entry *e, const char *filename);
struct playlist_entry *playlist_entry_new(const char *filename);

void playlist_add(struct playlist *pl, struct playlist_entry *add);
Expand Down
21 changes: 14 additions & 7 deletions demux/demux_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,37 @@ static int parse_m3u(struct pl_parser *p)
return 0;
}

char *title = NULL;
struct playlist_entry *e = playlist_entry_new_uninitialized();
while (line.len || !pl_eof(p)) {
bstr line_dup = line;
if (bstr_eatstart0(&line_dup, "#EXTINF:")) {
bstr duration, btitle;
if (bstr_split_tok(line_dup, ",", &duration, &btitle) && btitle.len) {
talloc_free(title);
title = bstrto0(NULL, btitle);
e->title = talloc_steal(e, bstrto0(NULL, btitle));
}
} else if (bstr_startswith0(line_dup, "#EXT-X-")) {
p->format = "hls";
} else if (bstr_eatstart0(&line_dup, "#EXT-MPV:")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be #EXT-X-MPV, X denotes that extension is not standard

bstr key, value;
if (bstr_split_tok(line_dup, "=", &key, &value) && value.len) {
playlist_entry_add_param(e, key, value);
}
} else if (line_dup.len > 0 && !bstr_startswith0(line_dup, "#")) {
char *fn = bstrto0(NULL, line_dup);
struct playlist_entry *e = playlist_entry_new(fn);
playlist_entry_init_filename(e, fn);
talloc_free(fn);
e->title = talloc_steal(e, title);
title = NULL;
playlist_add(p->pl, e);
e = playlist_entry_new_uninitialized();
}
pl_free_line(p, line);
line = pl_get_line(p);
}
pl_free_line(p, line);
talloc_free(title);

if (e->filename == NULL) {
playlist_entry_unref(e);
}

return 0;
}

Expand Down