summaryrefslogtreecommitdiffstats
path: root/stream/stream.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-24 18:49:09 +0200
committerwm4 <wm4@nowhere>2013-06-16 22:05:09 +0200
commit7c4202b863752e5903c76231420d9b391a0961e1 (patch)
tree4d3764b375bed6c60685b3bbd9a1fdeee5d40dcb /stream/stream.h
parent27b633671f01a0f97518459717d273f45358bfb0 (diff)
downloadmpv-7c4202b863752e5903c76231420d9b391a0961e1.tar.bz2
mpv-7c4202b863752e5903c76231420d9b391a0961e1.tar.xz
cache: make the stream cache a proper stream that wraps other streams
Before this commit, the cache was franken-hacked on top of the stream API. You had to use special functions (like cache_stream_fill_buffer() instead of stream_fill_buffer()), which would access the stream in a cached manner. The whole idea about the previous design was that the cache runs in a thread or in a forked process, while the cache awa functions made sure the stream instance looked consistent to the user. If you used the normal functions instead of the special ones while the cache was running, you were out of luck. Make it a bit more reasonable by turning the cache into a stream on its own. This makes it behave exactly like a normal stream. The stream callbacks call into the original (uncached) stream to do work. No special cache functions or redirections are needed. The only different thing about cache streams is that they are created by special functions, instead of being part of the auto_open_streams[] array. To make things simpler, remove the threading implementation, which was messed into the code. The threading code could perhaps be kept, but I don't really want to have to worry about this special case. A proper threaded implementation will be added later. Remove the cache enabling code from stream_radio.c. Since enabling the cache involves replacing the old stream with a new one, the code as-is can't be kept. It would be easily possible to enable the cache by requesting a cache size (which is also much simpler). But nobody uses stream_radio.c and I can't even test this thing, and the cache is probably not really important for it either.
Diffstat (limited to 'stream/stream.h')
-rw-r--r--stream/stream.h44
1 files changed, 17 insertions, 27 deletions
diff --git a/stream/stream.h b/stream/stream.h
index 4ae0e1e6a0..43ed6280bf 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -53,6 +53,7 @@
#define STREAMTYPE_RADIO 19
#define STREAMTYPE_BLURAY 20
#define STREAMTYPE_AVDEVICE 21
+#define STREAMTYPE_CACHE 22
#define STREAM_BUFFER_SIZE 2048
#define STREAM_MAX_SECTOR_SIZE (8 * 1024)
@@ -167,7 +168,8 @@ typedef struct stream {
int fd; // file descriptor, see man open(2)
int type; // see STREAMTYPE_*
- int flags;
+ int uncached_type; // like (uncached_stream ? uncached_stream->type : type)
+ int flags; // MP_STREAM_SEEK_* or'ed flags
int sector_size; // sector size (seek will be aligned on this size if non 0)
int read_chunk; // maximum amount of data to read at once to limit latency (0 for default)
unsigned int buf_pos, buf_len;
@@ -176,9 +178,6 @@ typedef struct stream {
int mode; //STREAM_READ or STREAM_WRITE
bool streaming; // known to be a network stream if true
int cache_size; // cache size in KB to use if enabled
- bool cached; // cache active
- unsigned int cache_pid;
- void *cache_data;
void *priv; // used for DVD, TV, RTSP etc
char *url; // strdup() of filename/url
char *mime_type; // when HTTP streaming is used
@@ -191,6 +190,8 @@ typedef struct stream {
FILE *capture_file;
char *capture_filename;
+
+ struct stream *uncached_stream;
} stream_t;
#ifdef CONFIG_NETWORKING
@@ -198,36 +199,26 @@ typedef struct stream {
#endif
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,
+int stream_enable_cache_percent(stream_t **stream, int64_t stream_cache_size,
float stream_cache_min_percent,
float stream_cache_seek_min_percent);
-int stream_enable_cache(stream_t *stream, int64_t size, int64_t min,
- int64_t prefill);
-int cache_stream_fill_buffer(stream_t *s);
-int cache_stream_seek_long(stream_t *s, int64_t pos);
-#else
-// no cache, define wrappers:
-#define cache_stream_fill_buffer(x) stream_fill_buffer(x)
-#define cache_stream_seek_long(x, y) stream_seek_long(x, y)
-#define stream_enable_cache(x, y, z, w) 1
-#define stream_enable_cache_percent(x, y, z, w) 1
-#endif
+int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
+ int64_t seek_limit);
+
+// Internal
+int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size,
+ int64_t min, int64_t seek_limit);
+
int stream_write_buffer(stream_t *s, unsigned char *buf, int len);
inline static int stream_read_char(stream_t *s)
{
return (s->buf_pos < s->buf_len) ? s->buffer[s->buf_pos++] :
- (cache_stream_fill_buffer(s) ? s->buffer[s->buf_pos++] : -256);
-// if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
-// stream_fill_buffer(s);
-// if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
-// return 0; // EOF
+ (stream_fill_buffer(s) ? s->buffer[s->buf_pos++] : -256);
}
inline static unsigned int stream_read_word(stream_t *s)
@@ -333,10 +324,9 @@ void stream_set_interrupt_callback(int (*cb)(struct input_ctx *, int),
/// Call the interrupt checking callback if there is one and
/// wait for time milliseconds
int stream_check_interrupt(int time);
-/// Internal read function bypassing the stream buffer
-int stream_read_internal(stream_t *s, void *buf, int len);
-/// Internal seek function bypassing the stream buffer
-int stream_seek_internal(stream_t *s, int64_t newpos);
+
+int stream_read_unbuffered(stream_t *s, void *buf, int len);
+int stream_seek_unbuffered(stream_t *s, int64_t newpos);
bool stream_manages_timeline(stream_t *s);