Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / apps / plugins / mpegplayer / disk_buf.h
blobe16939a92ebe95d6edc9a236a96536b07d13d72d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * AV disk buffer declarations
12 * Copyright (c) 2007 Michael Sevakis
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #ifndef DISK_BUF_H
24 #define DISK_BUF_H
26 #define DISK_BUF_PAGE_SHIFT 15 /* 32KB cache lines */
27 #define DISK_BUF_PAGE_SIZE (1 << DISK_BUF_PAGE_SHIFT)
28 #define DISK_BUF_PAGE_MASK (DISK_BUF_PAGE_SIZE-1)
30 enum
32 DISK_BUF_NOTIFY_ERROR = -1,
33 DISK_BUF_NOTIFY_NULL = 0,
34 DISK_BUF_NOTIFY_OK,
35 DISK_BUF_NOTIFY_TIMEDOUT,
36 DISK_BUF_NOTIFY_PROCESS_EVENT,
37 DISK_BUF_NOTIFY_REGISTERED,
40 /** Macros to map file offsets to cached data **/
42 /* Returns a cache tag given a file offset */
43 #define MAP_OFFSET_TO_TAG(o) \
44 ((o) >> DISK_BUF_PAGE_SHIFT)
46 /* Returns the cache page number given a file offset */
47 #define MAP_OFFSET_TO_PAGE(o) \
48 (MAP_OFFSET_TO_TAG(o) % disk_buf.pgcount)
50 /* Returns the buffer offset given a file offset */
51 #define MAP_OFFSET_TO_BUFFER(o) \
52 (MAP_OFFSET_TO_PAGE(o) * DISK_BUF_PAGE_SIZE)
54 struct dbuf_range
56 uint32_t tag_start;
57 uint32_t tag_end;
58 int pg_start;
61 /* This object is an extension of the stream manager and handles some
62 * playback events as well as buffering */
63 struct disk_buf
65 unsigned int thread;
66 struct event_queue *q;
67 uint8_t *start; /* Start pointer */
68 uint8_t *end; /* End of buffer pointer less MPEG_GUARDBUF_SIZE. The
69 guard space is used to wrap data at the buffer start to
70 pass continuous data packets */
71 uint8_t *tail; /* Location of last data + 1 filled into the buffer */
72 ssize_t size; /* The buffer length _not_ including the guard space (end-start) */
73 int pgcount; /* Total number of available cached pages */
74 uint32_t *cache; /* Pointer to cache structure - allocated on buffer */
75 int in_file; /* File being read */
76 ssize_t filesize; /* Size of file in_file in bytes */
77 int file_pages; /* Number of pages in file (rounded up) */
78 off_t offset; /* Current position (random access) */
79 off_t win_left; /* Left edge of buffer window (streaming) */
80 off_t win_right; /* Right edge of buffer window (streaming) */
81 uint32_t time_last; /* Last time watermark was checked */
82 off_t pos_last; /* Last position at watermark check time */
83 ssize_t low_wm; /* The low watermark for automatic rebuffering */
84 int status; /* Status as stream */
85 int state; /* Current thread state */
86 bool need_seek; /* Need to seek because a read was not contiguous */
89 extern struct disk_buf disk_buf SHAREDBSS_ATTR;
91 static inline bool disk_buf_is_data_ready(struct stream_hdr *sh,
92 ssize_t margin)
94 /* Data window available? */
95 off_t right = sh->win_right;
97 /* Margins past end-of-file can still return true */
98 if (right > disk_buf.filesize - margin)
99 right = disk_buf.filesize - margin;
101 return sh->win_left >= disk_buf.win_left &&
102 right + margin <= disk_buf.win_right;
106 bool disk_buf_init(void);
107 void disk_buf_exit(void);
109 static inline int disk_buf_status(void)
110 { return disk_buf.status; }
112 int disk_buf_open(const char *filename);
113 void disk_buf_close(void);
114 ssize_t _disk_buf_getbuffer(size_t size, void **pp, void **pwrap,
115 size_t *sizewrap);
116 #define disk_buf_getbuffer(size, pp, pwrap, sizewrap) \
117 _disk_buf_getbuffer((size), PUN_PTR(void **, (pp)), \
118 PUN_PTR(void **, (pwrap)), (sizewrap))
119 ssize_t disk_buf_read(void *buffer, size_t size);
120 ssize_t disk_buf_lseek(off_t offset, int whence);
122 static inline off_t disk_buf_ftell(void)
123 { return disk_buf.offset; }
125 static inline ssize_t disk_buf_filesize(void)
126 { return disk_buf.filesize; }
128 ssize_t disk_buf_prepare_streaming(off_t pos, size_t len);
129 ssize_t disk_buf_set_streaming_window(off_t left, off_t right);
130 void * disk_buf_offset2ptr(off_t offset);
131 int disk_buf_check_streaming_window(off_t left, off_t right);
133 intptr_t disk_buf_send_msg(long id, intptr_t data);
134 void disk_buf_post_msg(long id, intptr_t data);
135 void disk_buf_reply_msg(intptr_t retval);
137 #endif /* DISK_BUF_H */