ReactOS  0.4.14-dev-115-g4576127
reader.h
Go to the documentation of this file.
1 /*
2  reader: reading input data
3 
4  copyright ?-2007 by the mpg123 project - free software under the terms of the LGPL 2.1
5  see COPYING and AUTHORS files in distribution or http://mpg123.org
6  initially written by Thomas Orgis (after code from Michael Hipp)
7 */
8 
9 #ifndef MPG123_READER_H
10 #define MPG123_READER_H
11 
12 #include "config.h"
13 #include "mpg123.h"
14 
15 #ifndef NO_FEEDER
16 struct buffy
17 {
18  unsigned char *data;
21  struct buffy *next;
22 };
23 
24 
26 {
27  struct buffy* first; /* The beginning of the chain. */
28  struct buffy* last; /* The end... of the chain. */
29  ssize_t size; /* Aggregated size of all buffies. */
30  /* These positions are relative to buffer chain beginning. */
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. */
37  size_t pool_fill; /* That many buffers are there. */
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. */
49 size_t bc_fill(struct bufferchain *bc);
50 
51 #endif
52 
54 {
55  off_t filelen; /* total file length or total buffer size */
56  off_t filepos; /* position in file or position in buffer chain */
57  int filept;
58  /* Custom opaque I/O handle from the client. */
59  void *iohandle;
60  int flags;
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);
69  off_t (*r_lseek_handle)(void *handle, off_t offset, int whence);
70  /* An optional cleaner for the handle on closing the stream. */
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);
74  off_t (*lseek)(int fd, off_t offset, int whence);
75  /* Buffered readers want that abstracted, set internally. */
76  ssize_t (*fullread)(mpg123_handle *, unsigned char *, ssize_t);
77 #ifndef NO_FEEDER
78  struct bufferchain buffer; /* Not dynamically allocated, these few struct bytes aren't worth the trouble. */
79 #endif
80 };
81 
82 /* start to use off_t to properly do LFS in future ... used to be long */
83 struct reader
84 {
87  ssize_t (*fullread) (mpg123_handle *, unsigned char *, ssize_t);
88  int (*head_read) (mpg123_handle *, unsigned long *newhead); /* succ: TRUE, else <= 0 (FALSE or READER_MORE) */
89  int (*head_shift) (mpg123_handle *, unsigned long *head); /* succ: TRUE, else <= 0 (FALSE or READER_MORE) */
90  off_t (*skip_bytes) (mpg123_handle *, off_t len); /* succ: >=0, else error or READER_MORE */
91  int (*read_frame_body)(mpg123_handle *, unsigned char *, int size);
97 };
98 
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. */
102 int open_stream_handle(mpg123_handle *, void *iohandle);
103 
104 /* feed based operation has some specials */
105 int open_feed(mpg123_handle *);
106 /* externally called function, returns 0 on success, -1 on error */
107 int feed_more(mpg123_handle *fr, const unsigned char *in, long count);
108 void feed_forget(mpg123_handle *fr); /* forget the data that has been read (free some buffers) */
109 off_t feed_set_pos(mpg123_handle *fr, off_t pos); /* Set position (inside available data if possible), return wanted byte offset of next feed. */
110 
111 void open_bad(mpg123_handle *);
112 
113 #define READER_FD_OPENED 0x1
114 #define READER_ID3TAG 0x2
115 #define READER_SEEKABLE 0x4
116 #define READER_BUFFERED 0x8
117 #define READER_NONBLOCK 0x20
118 #define READER_HANDLEIO 0x40
119 
120 #define READER_STREAM 0
121 #define READER_ICY_STREAM 1
122 #define READER_FEED 2
123 /* These two add a little buffering to enable small seeks for peek ahead. */
124 #define READER_BUF_STREAM 3
125 #define READER_BUF_ICY_STREAM 4
126 
127 #ifdef READ_SYSTEM
128 #define READER_SYSTEM 5
129 #define READERS 6
130 #else
131 #define READERS 5
132 #endif
133 
134 #define READER_ERROR MPG123_ERR
135 #define READER_MORE MPG123_NEED_MORE
136 
137 #endif
int filept
Definition: reader.h:57
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
int(* head_read)(mpg123_handle *, unsigned long *newhead)
Definition: reader.h:88
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
off_t fileoff
Definition: reader.h:34
int open_feed(mpg123_handle *)
Definition: readers.c:1118
LPBATCH_CONTEXT bc
Definition: batch.c:66
struct outqueuenode * head
Definition: adnsresfilter.c:66
int open_stream(mpg123_handle *, const char *path, int fd)
Definition: readers.c:1167
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
ssize_t(* fdread)(mpg123_handle *, void *, size_t)
Definition: reader.h:62
ssize_t size
Definition: reader.h:29
off_t(* skip_bytes)(mpg123_handle *, off_t len)
Definition: reader.h:90
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned char * data
Definition: reader.h:18
__kernel_off_t off_t
Definition: linux.h:201
GLintptr offset
Definition: glext.h:5920
GLuint buffer
Definition: glext.h:5915
struct buffy * first
Definition: reader.h:27
static int fd
Definition: io.c:51
#define ssize_t
Definition: config.h:469
ssize_t pos
Definition: reader.h:31
void bc_cleanup(struct bufferchain *)
Definition: readers.c:515
struct buffy * last
Definition: reader.h:28
int(* back_bytes)(mpg123_handle *, off_t bytes)
Definition: reader.h:92
ssize_t realsize
Definition: reader.h:20
size_t pool_size
Definition: reader.h:36
void(* forget)(mpg123_handle *)
Definition: reader.h:96
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
off_t(* tell)(mpg123_handle *)
Definition: reader.h:94
void(* cleanup_handle)(void *handle)
Definition: reader.h:71
void * iohandle
Definition: reader.h:59
ssize_t(* fullread)(mpg123_handle *, unsigned char *, ssize_t)
Definition: reader.h:87
ssize_t(* r_read)(int fd, void *buf, size_t count)
Definition: reader.h:64
size_t bc_fill(struct bufferchain *bc)
Definition: readers.c:504
void(* close)(mpg123_handle *)
Definition: reader.h:86
#define off_t
Definition: dosfsck.h:5
void feed_forget(mpg123_handle *fr)
__kernel_size_t size_t
Definition: linux.h:237
int(* seek_frame)(mpg123_handle *, off_t num)
Definition: reader.h:93
GLsizeiptr size
Definition: glext.h:5919
void bc_prepare(struct bufferchain *, size_t pool_size, size_t bufblock)
Definition: readers.c:496
GLuint GLuint num
Definition: glext.h:9618
ssize_t size
Definition: reader.h:19
int flags
Definition: reader.h:60
int feed_more(mpg123_handle *fr, const unsigned char *in, long count)
Definition: readers.c:760
off_t feed_set_pos(mpg123_handle *fr, off_t pos)
Definition: readers.c:810
size_t pool_fill
Definition: reader.h:37
ssize_t firstpos
Definition: reader.h:32
off_t(* r_lseek_handle)(void *handle, off_t offset, int whence)
Definition: reader.h:69
GLenum GLsizei len
Definition: glext.h:6722
int ssize_t
Definition: rosdhcp.h:48
off_t(* lseek)(int fd, off_t offset, int whence)
Definition: reader.h:74
ssize_t(* read)(int fd, void *buf, size_t count)
Definition: reader.h:73
struct buffy * next
Definition: reader.h:21
GLuint in
Definition: glext.h:9616
struct buffy * pool
Definition: reader.h:39
int(* init)(mpg123_handle *)
Definition: reader.h:85
Definition: services.c:325
off_t filelen
Definition: reader.h:55
int open_stream_handle(mpg123_handle *, void *iohandle)
Definition: readers.c:1198
void open_bad(mpg123_handle *)
Definition: readers.c:1104
Definition: reader.h:16
void bc_poolsize(struct bufferchain *, size_t pool_size, size_t bufblock)
Definition: readers.c:509
Definition: reader.h:83
off_t(* r_lseek)(int fd, off_t offset, int whence)
Definition: reader.h:65
int(* head_shift)(mpg123_handle *, unsigned long *head)
Definition: reader.h:89
off_t filepos
Definition: reader.h:56
ssize_t(* r_read_handle)(void *handle, void *buf, size_t count)
Definition: reader.h:68
void(* rewind)(mpg123_handle *)
Definition: reader.h:95
ssize_t(* fullread)(mpg123_handle *, unsigned char *, ssize_t)
Definition: reader.h:76
size_t bufblock
Definition: reader.h:35
int(* read_frame_body)(mpg123_handle *, unsigned char *, int size)
Definition: reader.h:91
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
long timeout_sec
Definition: reader.h:61