summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-01-04 19:31:08 +0100
committerwm4 <wm4@nowhere>2020-01-04 19:31:08 +0100
commit4419d29bb07ada6b8c7c6a0b281feca7e06aff09 (patch)
treea70b96e1b39b56b3d7d432498a919d53d44faecc /stream
parent04bde06095215f27cef0be01ce4d831ab2719591 (diff)
downloadmpv-4419d29bb07ada6b8c7c6a0b281feca7e06aff09.tar.bz2
mpv-4419d29bb07ada6b8c7c6a0b281feca7e06aff09.tar.xz
stream_libarchive: remove unnecessary string list of volumes
Just add the entries as volumes directly.
Diffstat (limited to 'stream')
-rw-r--r--stream/stream_libarchive.c59
1 files changed, 25 insertions, 34 deletions
diff --git a/stream/stream_libarchive.c b/stream/stream_libarchive.c
index 781b34ad0d..08675794ca 100644
--- a/stream/stream_libarchive.c
+++ b/stream/stream_libarchive.c
@@ -171,6 +171,20 @@ void mp_archive_free(struct mp_archive *mpa)
talloc_free(mpa);
}
+static bool add_volume(struct mp_archive *mpa, struct stream *src,
+ const char* url, int index)
+{
+ struct mp_archive_volume *vol = talloc_zero(mpa, struct mp_archive_volume);
+ vol->index = index;
+ vol->mpa = mpa;
+ vol->src = src;
+ vol->url = talloc_strdup(vol, url);
+ locale_t oldlocale = uselocale(mpa->locale);
+ bool res = archive_read_append_callback_data(mpa->arch, vol) == ARCHIVE_OK;
+ uselocale(oldlocale);
+ return res;
+}
+
static char *standard_volume_url(void *ctx, const char *format,
struct bstr base, int index)
{
@@ -203,11 +217,9 @@ static const struct file_pattern patterns[] = {
{ NULL, NULL, NULL, 0, 0 },
};
-static char **find_volumes(struct stream *primary_stream)
+static bool find_volumes(struct mp_archive *mpa)
{
- char **res = talloc_new(NULL);
- int num = 0;
- struct bstr primary_url = bstr0(primary_stream->url);
+ struct bstr primary_url = bstr0(mpa->primary_src->url);
const struct file_pattern *pattern = patterns;
while (pattern->match) {
@@ -217,32 +229,17 @@ static char **find_volumes(struct stream *primary_stream)
}
if (!pattern->match)
- goto done;
+ return true;
struct bstr base = bstr_splice(primary_url, 0, -(int)strlen(pattern->match));
for (int i = pattern->start; i <= pattern->stop; i++) {
- char* url = pattern->volume_url(res, pattern->format, base, i);
- MP_TARRAY_APPEND(res, res, num, url);
- }
-
-done:
- MP_TARRAY_APPEND(res, res, num, NULL);
- return res;
-}
+ char* url = pattern->volume_url(mpa, pattern->format, base, i);
+ if (!add_volume(mpa, NULL, url, i + 1))
+ return false;
+ }
-static bool add_volume(struct mp_log *log, struct mp_archive *mpa,
- struct stream *src, const char* url, int index)
-{
- struct mp_archive_volume *vol = talloc_zero(mpa, struct mp_archive_volume);
- vol->index = index;
- vol->mpa = mpa;
- vol->src = src;
- vol->url = talloc_strdup(vol, url);
- locale_t oldlocale = uselocale(mpa->locale);
- bool res = archive_read_append_callback_data(mpa->arch, vol) == ARCHIVE_OK;
- uselocale(oldlocale);
- return res;
+ return true;
}
struct mp_archive *mp_archive_new(struct mp_log *log, struct stream *src,
@@ -263,18 +260,12 @@ struct mp_archive *mp_archive_new(struct mp_log *log, struct stream *src,
mpa->num_volumes = max_volumes ? max_volumes : INT_MAX;
// first volume is the primary stream
- if (!add_volume(log, mpa, src, src->url, 0))
+ if (!add_volume(mpa, src, src->url, 0))
goto err;
// try to open other volumes
- char** volumes = find_volumes(src);
- for (int i = 0; volumes[i]; i++) {
- if (!add_volume(log, mpa, NULL, volumes[i], i + 1)) {
- talloc_free(volumes);
- goto err;
- }
- }
- talloc_free(volumes);
+ if (!find_volumes(mpa))
+ goto err;
locale_t oldlocale = uselocale(mpa->locale);