player: remove --stream-capture option/property

This was excessively useless, and I want my time back that was needed to
explain users why they don't want to use it.

It captured the byte stream only, and even for types of streams it was
designed for (like transport streams), it was rather questionable.

As part of the removal, un-inline demux_run_on_thread() (which has only
1 call-site now), and sort of reimplement --stream-dump to write the
data directly instead of using the removed capture code.

(--stream-dump is also very useless, and I struggled coming up with an
explanation for it in the manpage.)
This commit is contained in:
wm4 2017-01-21 17:19:01 +01:00
parent 085dfdea32
commit 73858bb0cc
12 changed files with 40 additions and 121 deletions

View File

@ -31,6 +31,7 @@ Interface changes
- "drop-frame-count" to "decoder-frame-drop-count"
- "vo-drop-frame-count" to "frame-drop-count"
The old names still work, but are deprecated.
- remove the --stream-capture option and property. No replacement.
--- mpv 0.23.0 ---
- remove deprecated vf_vdpaurb (use "--hwdec=vdpau-copy" instead)
- the following properties now have new semantics:

View File

@ -1552,10 +1552,6 @@ Property list
This property is experimental and might be removed in the future.
``stream-capture`` (RW)
A filename, see ``--stream-capture``. Setting this will start capture using
the given filename. Setting it to an empty string will stop it.
``tv-brightness``, ``tv-contrast``, ``tv-saturation``, ``tv-hue`` (RW)
TV stuff.

View File

@ -4745,21 +4745,10 @@ Miscellaneous
Input file type for ``mf://`` (available: jpeg, png, tga, sgi). By default,
this is guessed from the file extension.
``--stream-capture=<filename>``
Allows capturing the primary stream (not additional audio tracks or other
kind of streams) into the given file. Capturing can also be started and
stopped by changing the filename with the ``stream-capture`` property.
Generally this will not produce usable results for anything else than MPEG
or raw streams, unless capturing includes the file headers and is not
interrupted. Note that, due to cache latencies, captured data may begin and
end somewhat delayed compared to what you see displayed.
The destination file is always appended. (Before mpv 0.8.0, the file was
overwritten.)
``--stream-dump=<filename>``
Same as ``--stream-capture``, but do not start playback. Instead, the entire
file is dumped.
``--stream-dump=<destination-filename>``
Instead of playing a file, read its byte stream and write it to the given
destination file. The destination is overwritten. Can be useful to test
network-related behavior.
``--stream-lavf-o=opt1=value1,opt2=value2,...``
Set AVOptions on streams opened with libavformat. Unknown or misspelled

View File

@ -1398,12 +1398,6 @@ struct demuxer *demux_open_url(const char *url,
cancel, global);
if (!s)
return NULL;
if (params->allow_capture) {
char *f;
mp_read_option_raw(global, "stream-capture", &m_option_type_string, &f);
stream_set_capture_file(s, f);
talloc_free(f);
}
if (!params->disable_cache)
stream_enable_cache_defaults(&s);
struct demuxer *d = demux_open(s, params, global);
@ -1740,6 +1734,7 @@ static void thread_demux_control(void *p)
int demux_control(demuxer_t *demuxer, int cmd, void *arg)
{
struct demux_internal *in = demuxer->in;
assert(demuxer == in->d_user);
if (in->threading) {
pthread_mutex_lock(&in->lock);
@ -1751,7 +1746,20 @@ int demux_control(demuxer_t *demuxer, int cmd, void *arg)
int r = 0;
struct demux_control_args args = {demuxer, cmd, arg, &r};
demux_run_on_thread(demuxer, thread_demux_control, &args);
if (in->threading) {
MP_VERBOSE(in, "blocking on demuxer thread\n");
pthread_mutex_lock(&in->lock);
while (in->run_fn)
pthread_cond_wait(&in->wakeup, &in->lock);
in->run_fn = thread_demux_control;
in->run_fn_arg = &args;
pthread_cond_signal(&in->wakeup);
while (in->run_fn)
pthread_cond_wait(&in->wakeup, &in->lock);
pthread_mutex_unlock(&in->lock);
} else {
thread_demux_control(&args);
}
return r;
}
@ -1763,27 +1771,6 @@ int demux_stream_control(demuxer_t *demuxer, int ctrl, void *arg)
return c.res;
}
void demux_run_on_thread(struct demuxer *demuxer, void (*fn)(void *), void *ctx)
{
struct demux_internal *in = demuxer->in;
assert(demuxer == in->d_user);
if (in->threading) {
MP_VERBOSE(in, "blocking on demuxer thread\n");
pthread_mutex_lock(&in->lock);
while (in->run_fn)
pthread_cond_wait(&in->wakeup, &in->lock);
in->run_fn = fn;
in->run_fn_arg = ctx;
pthread_cond_signal(&in->wakeup);
while (in->run_fn)
pthread_cond_wait(&in->wakeup, &in->lock);
pthread_mutex_unlock(&in->lock);
} else {
fn(ctx);
}
}
bool demux_cancel_test(struct demuxer *demuxer)
{
return mp_cancel_test(demuxer->stream->cancel);

View File

@ -165,7 +165,6 @@ struct demuxer_params {
bool initial_readahead;
// -- demux_open_url() only
int stream_flags;
bool allow_capture;
bool disable_cache;
// result
bool demuxer_failed;
@ -288,8 +287,6 @@ double demuxer_get_time_length(struct demuxer *demuxer);
int demux_stream_control(demuxer_t *demuxer, int ctrl, void *arg);
void demux_run_on_thread(struct demuxer *demuxer, void (*fn)(void *), void *ctx);
void demux_changed(demuxer_t *demuxer, int events);
void demux_update(demuxer_t *demuxer);

View File

@ -590,7 +590,6 @@ const m_option_t mp_opts[] = {
OPT_FLAG("untimed", untimed, 0),
OPT_STRING("stream-capture", stream_capture, M_OPT_FILE),
OPT_STRING("stream-dump", stream_dump, M_OPT_FILE),
OPT_FLAG("stop-playback-on-init-failure", stop_playback_on_init_failure, 0),
@ -713,7 +712,8 @@ const m_option_t mp_opts[] = {
OPT_REPLACED("ass", "sub-ass"),
OPT_REPLACED("audiofile", "audio-file"),
OPT_REMOVED("benchmark", "use --untimed (no stats)"),
OPT_REMOVED("capture", "use --stream-capture=<filename>"),
OPT_REMOVED("capture", NULL),
OPT_REMOVED("stream-capture", NULL),
OPT_REMOVED("channels", "use --audio-channels (changed semantics)"),
OPT_REPLACED("cursor-autohide-delay", "cursor-autohide"),
OPT_REPLACED("delay", "audio-delay"),

View File

@ -136,7 +136,6 @@ typedef struct MPOpts {
int video_osd;
int untimed;
char *stream_capture;
char *stream_dump;
int stop_playback_on_init_failure;
int loop_times;

View File

@ -515,29 +515,6 @@ static int mp_property_stream_path(void *ctx, struct m_property *prop,
return m_property_strdup_ro(action, arg, mpctx->demuxer->filename);
}
struct change_stream_capture_args {
char *filename;
struct demuxer *demux;
};
static void do_change_stream_capture(void *p)
{
struct change_stream_capture_args *args = p;
stream_set_capture_file(args->demux->stream, args->filename);
}
static int mp_property_stream_capture(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (mpctx->demuxer && action == M_PROPERTY_SET) {
struct change_stream_capture_args args = {*(char **)arg, mpctx->demuxer};
demux_run_on_thread(mpctx->demuxer, do_change_stream_capture, &args);
// fall through to mp_property_generic_option
}
return mp_property_generic_option(mpctx, prop, action, arg);
}
/// Demuxer name (RO)
static int mp_property_demuxer(void *ctx, struct m_property *prop,
int action, void *arg)
@ -3789,7 +3766,6 @@ static const struct m_property mp_properties_base[] = {
{"path", mp_property_path},
{"media-title", mp_property_media_title},
{"stream-path", mp_property_stream_path},
{"stream-capture", mp_property_stream_capture},
{"current-demuxer", mp_property_demuxer},
{"file-format", mp_property_file_format},
{"stream-pos", mp_property_stream_pos},

View File

@ -796,7 +796,6 @@ static void *open_demux_thread(void *ctx)
struct demuxer_params p = {
.force_format = mpctx->open_format,
.allow_capture = true,
.stream_flags = mpctx->open_url_flags,
.initial_readahead = true,
};

View File

@ -17,6 +17,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <errno.h>
#include <assert.h>
#include "config.h"
@ -212,21 +213,34 @@ int stream_dump(struct MPContext *mpctx, const char *source_filename)
int64_t size = stream_get_size(stream);
stream_set_capture_file(stream, opts->stream_dump);
FILE *dest = fopen(opts->stream_dump, "wb");
if (!dest) {
MP_ERR(mpctx, "Error opening dump file: %s\n", mp_strerror(errno));
return -1;
}
while (mpctx->stop_play == KEEP_PLAYING && !stream->eof) {
bool ok = true;
while (mpctx->stop_play == KEEP_PLAYING && ok) {
if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) {
uint64_t pos = stream->pos;
MP_MSG(mpctx, MSGL_STATUS, "Dumping %lld/%lld...",
(long long int)pos, (long long int)size);
}
stream_fill_buffer(stream);
bstr data = stream_peek(stream, STREAM_MAX_BUFFER_SIZE);
if (data.len == 0) {
ok &= stream->eof;
break;
}
ok &= fwrite(data.start, data.len, 1, dest) == 1;
stream_skip(stream, data.len);
mp_wakeup_core(mpctx); // don't actually sleep
mp_idle(mpctx); // but process input
}
ok &= fclose(dest) == 0;
free_stream(stream);
return 0;
return ok ? 0 : -1;
}
void merge_playlist_files(struct playlist *pl)

View File

@ -353,37 +353,6 @@ static bool stream_reconnect(stream_t *s)
return false;
}
static void stream_capture_write(stream_t *s, void *buf, size_t len)
{
if (s->capture_file && len > 0) {
if (fwrite(buf, len, 1, s->capture_file) < 1) {
MP_ERR(s, "Error writing capture file: %s\n", mp_strerror(errno));
stream_set_capture_file(s, NULL);
}
}
}
void stream_set_capture_file(stream_t *s, const char *filename)
{
if (!bstr_equals(bstr0(s->capture_filename), bstr0(filename))) {
if (s->capture_file)
fclose(s->capture_file);
talloc_free(s->capture_filename);
s->capture_file = NULL;
s->capture_filename = NULL;
if (filename) {
s->capture_file = fopen(filename, "ab");
if (s->capture_file) {
s->capture_filename = talloc_strdup(NULL, filename);
if (s->buf_pos < s->buf_len)
stream_capture_write(s, s->buffer, s->buf_len);
} else {
MP_ERR(s, "Error opening capture file: %s\n", mp_strerror(errno));
}
}
}
}
// Read function bypassing the local stream buffer. This will not write into
// s->buffer, but into buf[0..len] instead.
// Returns 0 on error or EOF, and length of bytes read on success.
@ -412,7 +381,6 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len)
// When reading succeeded we are obviously not at eof.
s->eof = 0;
s->pos += len;
stream_capture_write(s, buf, len);
return len;
}
@ -647,8 +615,6 @@ void free_stream(stream_t *s)
if (!s)
return;
stream_set_capture_file(s, NULL);
if (s->close)
s->close(s);
free_stream(s->uncached_stream);

View File

@ -203,9 +203,6 @@ typedef struct stream {
struct mp_cancel *cancel; // cancellation notification
FILE *capture_file;
char *capture_filename;
struct stream *uncached_stream; // underlying stream for cache wrapper
// Includes additional padding in case sizes get rounded up by sector size.
@ -214,8 +211,6 @@ typedef struct stream {
int stream_fill_buffer(stream_t *s);
void stream_set_capture_file(stream_t *s, const char *filename);
struct mp_cache_opts;
bool stream_wants_cache(stream_t *stream, struct mp_cache_opts *opts);
int stream_enable_cache_defaults(stream_t **stream);