Rev 1905 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1905 | Rev 3960 | ||
---|---|---|---|
Line 10... | Line 10... | ||
10 | #define MPG123_READER_H |
10 | #define MPG123_READER_H |
Line 11... | Line 11... | ||
11 | 11 | ||
12 | #include "config.h" |
12 | #include "config.h" |
Line -... | Line 13... | ||
- | 13 | #include "mpg123.h" |
|
13 | #include "mpg123.h" |
14 | |
14 | 15 | #ifndef NO_FEEDER |
|
15 | struct buffy |
16 | struct buffy |
16 | { |
17 | { |
- | 18 | unsigned char *data; |
|
17 | unsigned char *data; |
19 | ssize_t size; |
18 | ssize_t size; |
20 | ssize_t realsize; |
Line -... | Line 21... | ||
- | 21 | struct buffy *next; |
|
19 | struct buffy *next; |
22 | }; |
20 | }; |
23 | |
21 | 24 | ||
22 | struct bufferchain |
25 | struct bufferchain |
23 | { |
26 | { |
24 | struct buffy* first; /* The beginning of the chain. */ |
27 | struct buffy* first; /* The beginning of the chain. */ |
25 | struct buffy* last; /* The end... of the chain. */ |
28 | struct buffy* last; /* The end... of the chain. */ |
26 | ssize_t size; /* Aggregated size of all buffies. */ |
29 | ssize_t size; /* Aggregated size of all buffies. */ |
27 | /* These positions are relative to buffer chain beginning. */ |
30 | /* These positions are relative to buffer chain beginning. */ |
28 | ssize_t pos; /* Position in whole chain. */ |
31 | ssize_t pos; /* Position in whole chain. */ |
- | 32 | ssize_t firstpos; /* The point of return on non-forget() */ |
|
- | 33 | /* The "real" filepos is fileoff + pos. */ |
|
- | 34 | off_t fileoff; /* Beginning of chain is at this file offset. */ |
|
- | 35 | size_t bufblock; /* Default (minimal) size of buffers. */ |
|
- | 36 | size_t pool_size; /* Keep that many buffers in storage. */ |
|
29 | ssize_t firstpos; /* The point of return on non-forget() */ |
37 | size_t pool_fill; /* That many buffers are there. */ |
Line -... | Line 38... | ||
- | 38 | /* A pool of buffers to re-use, if activated. It's a linked list that is worked on from the front. */ |
|
- | 39 | struct buffy *pool; |
|
- | 40 | }; |
|
- | 41 | ||
- | 42 | /* Call this before any buffer chain use (even bc_init()). */ |
|
- | 43 | void bc_prepare(struct bufferchain *, size_t pool_size, size_t bufblock); |
|
- | 44 | /* Free persistent data in the buffer chain, after bc_reset(). */ |
|
- | 45 | void bc_cleanup(struct bufferchain *); |
|
- | 46 | /* Change pool size. This does not actually allocate/free anything on itself, just instructs later operations to free less / allocate more buffers. */ |
|
- | 47 | void bc_poolsize(struct bufferchain *, size_t pool_size, size_t bufblock); |
|
- | 48 | /* Return available byte count in the buffer. */ |
|
30 | /* The "real" filepos is fileoff + pos. */ |
49 | size_t bc_fill(struct bufferchain *bc); |
31 | off_t fileoff; /* Beginning of chain is at this file offset. */ |
50 | |
32 | }; |
51 | #endif |
33 | 52 | ||
34 | struct reader_data |
53 | struct reader_data |
- | 54 | { |
|
- | 55 | off_t filelen; /* total file length or total buffer size */ |
|
35 | { |
56 | off_t filepos; /* position in file or position in buffer chain */ |
36 | off_t filelen; /* total file length or total buffer size */ |
- | |
37 | off_t filepos; /* position in file or position in buffer chain */ |
57 | int filept; |
38 | int filept; |
- | |
39 | int flags; |
58 | /* Custom opaque I/O handle from the client. */ |
40 | #ifndef WIN32 |
59 | void *iohandle; |
41 | long timeout_sec; |
- | |
42 | #endif |
60 | int flags; |
43 | ssize_t (*fdread) (mpg123_handle *, void *, size_t); |
61 | long timeout_sec; |
- | 62 | ssize_t (*fdread) (mpg123_handle *, void *, size_t); |
|
- | 63 | /* User can replace the read and lseek functions. The r_* are the stored replacement functions or NULL. */ |
|
- | 64 | ssize_t (*r_read) (int fd, void *buf, size_t count); |
|
- | 65 | off_t (*r_lseek)(int fd, off_t offset, int whence); |
|
- | 66 | /* These are custom I/O routines for opaque user handles. |
|
- | 67 | They get picked if there's some iohandle set. */ |
|
- | 68 | ssize_t (*r_read_handle) (void *handle, void *buf, size_t count); |
|
44 | /* User can replace the read and lseek functions. The r_* are the stored replacement functions or NULL, |
69 | off_t (*r_lseek_handle)(void *handle, off_t offset, int whence); |
45 | The second two pointers are the actual workers (default map to POSIX read/lseek). */ |
70 | /* An optional cleaner for the handle on closing the stream. */ |
46 | ssize_t (*r_read) (int fd, void *buf, size_t count); |
71 | void (*cleanup_handle)(void *handle); |
47 | off_t (*r_lseek)(int fd, off_t offset, int whence); |
72 | /* These two pointers are the actual workers (default map to POSIX read/lseek). */ |
- | 73 | ssize_t (*read) (int fd, void *buf, size_t count); |
|
48 | ssize_t (*read) (int fd, void *buf, size_t count); |
74 | off_t (*lseek)(int fd, off_t offset, int whence); |
- | 75 | /* Buffered readers want that abstracted, set internally. */ |
|
49 | off_t (*lseek)(int fd, off_t offset, int whence); |
76 | ssize_t (*fullread)(mpg123_handle *, unsigned char *, ssize_t); |
Line 50... | Line 77... | ||
50 | /* Buffered readers want that abstracted, set internally. */ |
77 | #ifndef NO_FEEDER |
51 | ssize_t (*fullread)(mpg123_handle *, unsigned char *, ssize_t); |
78 | struct bufferchain buffer; /* Not dynamically allocated, these few struct bytes aren't worth the trouble. */ |
52 | struct bufferchain buffer; /* Not dynamically allocated, these few struct bytes aren't worth the trouble. */ |
79 | #endif |
Line 69... | Line 96... | ||
69 | void (*forget) (mpg123_handle *); |
96 | void (*forget) (mpg123_handle *); |
70 | }; |
97 | }; |
Line 71... | Line 98... | ||
71 | 98 | ||
72 | /* Open a file by path or use an opened file descriptor. */ |
99 | /* Open a file by path or use an opened file descriptor. */ |
- | 100 | int open_stream(mpg123_handle *, const char *path, int fd); |
|
- | 101 | /* Open an external handle. */ |
|
Line 73... | Line 102... | ||
73 | int open_stream(mpg123_handle *, const char *path, int fd); |
102 | int open_stream_handle(mpg123_handle *, void *iohandle); |
74 | 103 | ||
75 | /* feed based operation has some specials */ |
104 | /* feed based operation has some specials */ |
76 | int open_feed(mpg123_handle *); |
105 | int open_feed(mpg123_handle *); |
Line 84... | Line 113... | ||
84 | #define READER_FD_OPENED 0x1 |
113 | #define READER_FD_OPENED 0x1 |
85 | #define READER_ID3TAG 0x2 |
114 | #define READER_ID3TAG 0x2 |
86 | #define READER_SEEKABLE 0x4 |
115 | #define READER_SEEKABLE 0x4 |
87 | #define READER_BUFFERED 0x8 |
116 | #define READER_BUFFERED 0x8 |
88 | #define READER_NONBLOCK 0x20 |
117 | #define READER_NONBLOCK 0x20 |
- | 118 | #define READER_HANDLEIO 0x40 |
|
Line 89... | Line 119... | ||
89 | 119 | ||
90 | #define READER_STREAM 0 |
120 | #define READER_STREAM 0 |
91 | #define READER_ICY_STREAM 1 |
121 | #define READER_ICY_STREAM 1 |
92 | #define READER_FEED 2 |
122 | #define READER_FEED 2 |