stream_env: add new stream to read from environment variables
This commit is contained in:
1 parent
6d64f2867c
commit
c22cac669e
4 files changed
+54
No files matched your search
@@ -1492,6 +1492,10 @@ PROTOCOLS
|
||||
|
||||
This will play ``video.mkv`` in the archive file ``file.zip``.
|
||||
|
||||
``env://variable``
|
||||
|
||||
Read the environment variable ``variable`` as source data.
|
||||
|
||||
PSEUDO GUI MODE
|
||||
===============
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ sources = files(
|
||||
'stream/stream_null.c',
|
||||
'stream/stream_slice.c',
|
||||
'stream/stream_bstr.c',
|
||||
'stream/stream_env.c',
|
||||
|
||||
## Subtitles
|
||||
'sub/ass_mp.c',
|
||||
|
||||
@@ -62,6 +62,7 @@ extern const stream_info_t stream_info_edl;
|
||||
extern const stream_info_t stream_info_libarchive;
|
||||
extern const stream_info_t stream_info_cb;
|
||||
extern const stream_info_t stream_info_curl;
|
||||
extern const stream_info_t stream_info_env;
|
||||
|
||||
static const stream_info_t *const stream_list[] = {
|
||||
&stream_info_mpv,
|
||||
@@ -96,6 +97,7 @@ static const stream_info_t *const stream_list[] = {
|
||||
#endif
|
||||
&stream_info_ffmpeg,
|
||||
&stream_info_ffmpeg_unsafe,
|
||||
&stream_info_env,
|
||||
};
|
||||
|
||||
// Because of guarantees documented on STREAM_BUFFER_SIZE.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of mpv.
|
||||
*
|
||||
* mpv is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* mpv 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "common/common.h"
|
||||
#include "stream_bstr.h"
|
||||
|
||||
static int open2(stream_t *stream, const struct stream_open_args *args)
|
||||
{
|
||||
bstr data = bstr0(stream->url);
|
||||
bstr_eatstart0(&data, "env://");
|
||||
|
||||
char *name = bstrdup0(stream, data);
|
||||
char *val = getenv(name);
|
||||
talloc_free(name);
|
||||
|
||||
if (!val) {
|
||||
MP_FATAL(stream, "Could not read from environment variable '%.*s'\n",
|
||||
BSTR_P(data));
|
||||
return STREAM_ERROR;
|
||||
}
|
||||
|
||||
data = bstrdup(stream, bstr0(val));
|
||||
return stream_bstr_open2(stream, args, data);
|
||||
}
|
||||
|
||||
const stream_info_t stream_info_env = {
|
||||
.name = "env",
|
||||
.open2 = open2,
|
||||
.protocols = (const char*const[]){ "env", NULL },
|
||||
.stream_origin = STREAM_ORIGIN_DIRECT,
|
||||
};
|
||||
Reference in new issue
Block a user