diff options
Diffstat (limited to 'stream')
-rw-r--r-- | stream/cache2.c | 1 | ||||
-rw-r--r-- | stream/stream.c | 34 | ||||
-rw-r--r-- | stream/stream.h | 6 |
3 files changed, 41 insertions, 0 deletions
diff --git a/stream/cache2.c b/stream/cache2.c index 38c57d0af9..1337e44e37 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -593,6 +593,7 @@ int cache_stream_fill_buffer(stream_t *s){ s->buf_len=len; s->pos+=len; // printf("[%d]",len);fflush(stdout); + stream_capture_write(s); return len; } diff --git a/stream/stream.c b/stream/stream.c index 36594d8556..caf78851c3 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -41,6 +41,7 @@ #include <winsock2.h> #endif +#include "core/bstr.h" #include "core/mp_msg.h" #include "osdep/shmem.h" #include "osdep/timer.h" @@ -312,6 +313,37 @@ static int stream_reconnect(stream_t *s) return 0; } +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, "wb"); + if (s->capture_file) { + s->capture_filename = talloc_strdup(NULL, filename); + } else { + mp_tmsg(MSGT_GLOBAL, MSGL_ERR, + "Error opening capture file: %s\n", strerror(errno)); + } + } + } +} + +void stream_capture_write(stream_t *s) +{ + if (s->capture_file) { + if (fwrite(s->buffer, s->buf_len, 1, s->capture_file) < 1) { + mp_tmsg(MSGT_GLOBAL, MSGL_ERR, "Error writing capture file: %s\n", + strerror(errno)); + stream_set_capture_file(s, NULL); + } + } +} + int stream_read_internal(stream_t *s, void *buf, int len) { int orig_len = len; @@ -367,6 +399,7 @@ int stream_fill_buffer(stream_t *s) s->buf_pos = 0; s->buf_len = len; // printf("[%d]",len);fflush(stdout); + stream_capture_write(s); return len; } @@ -566,6 +599,7 @@ void free_stream(stream_t *s) #ifdef CONFIG_STREAM_CACHE cache_uninit(s); #endif + stream_set_capture_file(s, NULL); if (s->close) s->close(s); diff --git a/stream/stream.h b/stream/stream.h index df4188ed94..ad2d7dd19a 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -188,6 +188,9 @@ typedef struct stream { unsigned char buffer[STREAM_BUFFER_SIZE > STREAM_MAX_SECTOR_SIZE ? STREAM_BUFFER_SIZE : STREAM_MAX_SECTOR_SIZE]; + + FILE *capture_file; + char *capture_filename; } stream_t; #ifdef CONFIG_NETWORKING @@ -197,6 +200,9 @@ typedef struct stream { int stream_fill_buffer(stream_t *s); int stream_seek_long(stream_t *s, int64_t pos); +void stream_set_capture_file(stream_t *s, const char *filename); +void stream_capture_write(stream_t *s); + #ifdef CONFIG_STREAM_CACHE int stream_enable_cache_percent(stream_t *stream, int64_t stream_cache_size, float stream_cache_min_percent, |