summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-25 17:11:24 +0200
committerwm4 <wm4@nowhere>2014-10-25 17:20:18 +0200
commitaaa29eb81e0388b9173223290b6b15f619caa7ab (patch)
tree6df8dc69447a363a2d31d2203e181ef0aa346a92
parent1e919b4c124de6308528fdc7468d7212d309a1d6 (diff)
downloadmpv-aaa29eb81e0388b9173223290b6b15f619caa7ab.tar.bz2
mpv-aaa29eb81e0388b9173223290b6b15f619caa7ab.tar.xz
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.
-rw-r--r--stream/stream.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/stream/stream.c b/stream/stream.c
index e16ee966fe..e51a1666f0 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -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.