mirror of
https://github.com/mpv-player/mpv
synced 2024-09-09 01:16:56 +02:00
stream: fix --stream-dump dropping the file header
stream_rar.c peeks the first few bytes when trying to open, which means that opening any stream reads at least 2KB of data (internal buffer size) on opening. This broke --stream-dump, which saved only the data following this initial buffer. Hack it around by writing the current buffer to the capture file too, and move stream_capture_write() above stream_set_capture_file() for this purpose. Cleaner solutions might include: handling the terrible rar thing differently, or using the "proper" stream API for dumping. (The latter is not done, because --stream-dump shares code with the --stream-capture misfeature.) Fixes #1215.
This commit is contained in:
parent
1e919b4c12
commit
aaa29eb81e
@ -438,6 +438,16 @@ static int stream_reconnect(stream_t *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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", 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))) {
|
||||
@ -450,6 +460,8 @@ void stream_set_capture_file(stream_t *s, const char *filename)
|
||||
s->capture_file = fopen(filename, "wb");
|
||||
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", strerror(errno));
|
||||
}
|
||||
@ -457,16 +469,6 @@ void stream_set_capture_file(stream_t *s, const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
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", strerror(errno));
|
||||
stream_set_capture_file(s, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read function bypassing the local stream buffer. This will not write into
|
||||
// s->buffer, but into buf[0..len] instead.
|
||||
// Returns < 0 on error, 0 on EOF, and length of bytes read on success.
|
||||
|
Loading…
Reference in New Issue
Block a user