summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
Diffstat (limited to 'stream')
-rw-r--r--stream/cache2.c2
-rw-r--r--stream/stream.c17
-rw-r--r--stream/stream.h3
3 files changed, 22 insertions, 0 deletions
diff --git a/stream/cache2.c b/stream/cache2.c
index 3aa24df64d..c4514243e1 100644
--- a/stream/cache2.c
+++ b/stream/cache2.c
@@ -508,6 +508,8 @@ int cache_stream_fill_buffer(stream_t *s){
s->buf_len=len;
s->pos+=len;
// printf("[%d]",len);fflush(stdout);
+ if (s->capture_file)
+ stream_capture_do(s);
return len;
}
diff --git a/stream/stream.c b/stream/stream.c
index 8b325a24d1..ca45f511e5 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -265,6 +265,16 @@ stream_t *open_output_stream(const char *filename, struct MPOpts *options)
//=================== STREAMER =========================
+void stream_capture_do(stream_t *s)
+{
+ 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));
+ fclose(s->capture_file);
+ s->capture_file = NULL;
+ }
+}
+
int stream_fill_buffer(stream_t *s){
int len;
// we will retry even if we already reached EOF previously.
@@ -296,6 +306,8 @@ int stream_fill_buffer(stream_t *s){
s->buf_len=len;
s->pos+=len;
// printf("[%d]",len);fflush(stdout);
+ if (s->capture_file)
+ stream_capture_do(s);
return len;
}
@@ -463,6 +475,11 @@ void free_stream(stream_t *s){
#ifdef CONFIG_STREAM_CACHE
cache_uninit(s);
#endif
+ if (s->capture_file) {
+ fclose(s->capture_file);
+ s->capture_file = NULL;
+ }
+
if(s->close) s->close(s);
if(s->fd>0){
/* on unix we define closesocket to close
diff --git a/stream/stream.h b/stream/stream.h
index bd73f6f954..8e4b260ffb 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -22,6 +22,7 @@
#include "config.h"
#include "mp_msg.h"
#include "url.h"
+#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <sys/types.h>
@@ -168,6 +169,7 @@ typedef struct stream {
streaming_ctrl_t *streaming_ctrl;
#endif
unsigned char buffer[STREAM_BUFFER_SIZE>STREAM_MAX_SECTOR_SIZE?STREAM_BUFFER_SIZE:STREAM_MAX_SECTOR_SIZE];
+ FILE *capture_file;
} stream_t;
#ifdef CONFIG_NETWORKING
@@ -176,6 +178,7 @@ typedef struct stream {
int stream_fill_buffer(stream_t *s);
int stream_seek_long(stream_t *s, off_t pos);
+void stream_capture_do(stream_t *s);
#ifdef CONFIG_STREAM_CACHE
int stream_enable_cache(stream_t *stream,int size,int min,int prefill);