17#ifdef HAVE_SYS_SELECT_H
18#include <sys/select.h>
74 tv.tv_sec = fr->
rdat.timeout_sec;
98 if(
NOQUIET)
error(
"mpg123 programmer error: I don't do ICY on seekable streams.");
115 unsigned char temp_buff;
122 cut_pos = fr->
icy.next;
137 debug1(
"another try... still %li left", (
long)fr->
icy.next);
145 ret = fr->
rdat.fdread(fr,&temp_buff,1);
149 debug2(
"got meta-size byte: %u, at filepos %li", temp_buff, (
long)fr->
rdat.filepos );
152 if((meta_size = ((
size_t) temp_buff) * 16))
157 meta_buff =
malloc(meta_size+1);
158 if(meta_buff !=
NULL)
168 meta_buff[meta_size] = 0;
172 fr->
icy.data = meta_buff;
174 debug2(
"icy-meta: %s size: %d bytes", fr->
icy.data, (
int)meta_size);
178 if(
NOQUIET)
error1(
"cannot allocate memory for meta_buff (%lu bytes) ... trying to skip the metadata!", (
unsigned long)meta_size);
179 fr->
rd->skip_bytes(fr, meta_size);
182 fr->
icy.next = fr->
icy.interval;
198#define icy_fullread NULL
251 if(fr->
rdat.cleanup_handle !=
NULL) fr->
rdat.cleanup_handle(fr->
rdat.iohandle);
276 if(fr->
num >= newframe || fr->
num < preframe)
278 to_skip = seek_to - fr->
rd->tell(fr);
279 if(fr->
rd->skip_bytes(fr, to_skip) != seek_to)
282 debug2(
"going to %lu; just got %lu", (
long unsigned)newframe, (
long unsigned)preframe);
283 fr->
num = preframe-1;
285 while(fr->
num < newframe)
291 debug1(
"arrived at %lu", (
long unsigned)fr->
num);
305 unsigned char hbuf[4];
306 int ret = fr->
rd->fullread(fr,hbuf,4);
310 *newhead = ((
unsigned long) hbuf[0] << 24) |
311 ((
unsigned long) hbuf[1] << 16) |
312 ((
unsigned long) hbuf[2] << 8) |
313 (
unsigned long) hbuf[3];
322 int ret = fr->
rd->fullread(fr,&hbuf,1);
342 unsigned char buf[1024];
349 else if(
ret == 0)
break;
352 return fr->
rd->tell(fr);
357 if(fr->
rdat.buffer.pos >= -
len)
360 return fr->
rd->tell(fr);
399 fr->
rdat.filepos = fr->
rdat.buffer.fileoff+fr->
rdat.buffer.pos;
402 return fr->
rdat.filepos;
412 fr->
rdat.buffer.fileoff = fr->
rdat.filepos;
418 fr->
rdat.buffer.pos = 0;
419 fr->
rdat.buffer.firstpos = 0;
420 fr->
rdat.filepos = fr->
rdat.buffer.fileoff;
436 debug(
"cannot seek to end");
438 }
else if(
len >= 128)
442 debug(
"cannot seek to END-128");
445 if(fr->
rd->fullread(fr,(
unsigned char *)fr->
id3buf,128) != 128)
447 debug(
"cannot read ID3v1?!");
453 debug(
"stream too short for ID3");
458 debug(
"cannot seek back");
472 struct buffy *newbuf;
518 return (
size_t)(
bc->size -
bc->pos);
523 bc->pool_size = pool_size;
524 bc->bufblock = bufblock;
542 bc->pool =
buf->next;
557 if(
bc->pool_fill <
bc->pool_size)
559 buf->next =
bc->pool;
570 while(
bc->pool_fill >
bc->pool_size)
574 bc->pool =
buf->next;
580 while(
bc->pool_fill <
bc->pool_size)
587 buf->next =
bc->pool;
599 bc->last =
bc->first;
612 bc->first =
buf->next;
622 struct buffy *newbuf;
623 if(
size < 1)
return -1;
626 if(newbuf ==
NULL)
return -2;
628 if(
bc->last !=
NULL)
bc->last->next = newbuf;
629 else if(
bc->first ==
NULL)
bc->first = newbuf;
647 if(
bc->last !=
NULL &&
bc->last->size <
bc->last->realsize)
649 part =
bc->last->realsize -
bc->last->size;
654 bc->last->size += part;
671 debug3(
"hit end, back to beginning (%li - %li < %li)", (
long)
bc->size, (
long)
bc->pos, (
long)
bc->size);
673 bc->pos =
bc->firstpos;
699 debug3(
"copying %liB from %p+%li",(
long)
chunk,
b->data, (
long)loff);
709 debug2(
"got %li bytes, pos advanced to %li", (
long)gotcount, (
long)
bc->pos);
739 if(
b)
debug2(
"bc_forget: block %lu pos %lu", (
unsigned long)
b->size, (
unsigned long)
bc->pos);
740 else debug(
"forget with nothing there!");
742 while(
b !=
NULL &&
bc->pos >=
b->size)
746 bc->fileoff +=
b->size;
750 debug5(
"bc_forget: forgot %p with %lu, pos=%li, size=%li, fileoff=%li", (
void*)
b->data, (
long)
b->size, (
long)
bc->pos, (
long)
bc->size, (
long)
bc->fileoff);
756 bc->firstpos =
bc->pos;
765 fr->
rdat.filelen = 0;
766 fr->
rdat.filepos = 0;
784 (
unsigned long)fr->
rdat.buffer.last->size, (
unsigned long)fr->
rdat.buffer.size);
792 else return gotcount;
802 return fr->
rdat.buffer.fileoff+
res;
819 fr->
rdat.filepos = fr->
rdat.buffer.fileoff + fr->
rdat.buffer.pos;
829 return bc->fileoff+
bc->size;
850 unsigned char readbuf[4096];
855 ssize_t got = fr->
rdat.fullread(fr, readbuf,
sizeof(readbuf));
862 if(
VERBOSE3)
debug1(
"buffered_fullread: buffering %li bytes from stream (if > 0)", (
long)got);
870 if(got <
sizeof(readbuf))
881 mdebug(
"buffered_fullread: got %zd", gotcount);
883 else return gotcount;
902#define bugger_off { mh->err = MPG123_NO_READER; return MPG123_ERR; }
916#define READER_STREAM 0
917#define READER_ICY_STREAM 1
919#define READER_BUF_STREAM 3
920#define READER_BUF_ICY_STREAM 4
952#define feed_init NULL
953#define feed_read NULL
954#define buffered_fullread NULL
955#define feed_seek_frame NULL
956#define feed_back_bytes NULL
957#define feed_skip_bytes NULL
958#define buffered_forget NULL
1039 if(fr->
p.timeout > 0)
1045 error(
"Timeout reading does not work with user-provided"
1046 " read function. Implement it yourself!" );
1049 flags = fcntl(fr->
rdat.filept, F_GETFL);
1052 fr->
rdat.fdread = timeout_read;
1053 fr->
rdat.timeout_sec = fr->
p.timeout;
1068 fr->
rdat.filepos = 0;
1076 if(fr->
rdat.filelen >= 0)
1078 debug(
"seekable stream");
1091 error(
"Buffered readers not supported in this build.");
1097 debug(
"switching to buffered stream reader");
1104 debug(
"switching to buffered ICY stream reader");
1111 if(
NOQUIET)
error(
"mpg123 Programmer's fault: invalid reader");
1115 fr->
rdat.filelen = 0;
1134 mh->
rdat.filelen = -1;
1139 debug(
"feed reader");
1142 error(
"Buffered readers not supported in this build.");
1147 if(fr->
p.icy_interval > 0)
1149 if(
NOQUIET)
error(
"Feed reader cannot do ICY parsing!");
1157 if(fr->
rd->init(fr) < 0)
return -1;
1159 debug(
"feed reader init successful");
1168 if(fr->
p.icy_interval > 0)
1170 debug(
"ICY reader");
1171 fr->
icy.interval = fr->
p.icy_interval;
1172 fr->
icy.next = fr->
icy.interval;
1179 debug(
"stream reader");
1182 if(fr->
rd->init(fr) < 0)
return -1;
1189 int filept_opened = 1;
1200 #define O_BINARY (0)
1210 fr->
rdat.filelen = -1;
1211 fr->
rdat.filept = filept;
1221 fr->
rdat.filelen = -1;
1222 fr->
rdat.filept = -1;
1223 fr->
rdat.iohandle = iohandle;
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
static unsigned char bytes[4]
struct outqueuenode * head
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
GLuint GLuint GLsizei count
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define open_stream_handle
#define memcpy(s1, s2, n)
static UINT PSTR DWORD UINT * need
const char * strerror(int err)
static unsigned __int64 next
static ssize_t feed_read(mpg123_handle *fr, unsigned char *out, ssize_t count)
static int generic_head_read(mpg123_handle *fr, unsigned long *newhead)
static struct buffy * bc_alloc(struct bufferchain *bc, size_t size)
static void stream_rewind(mpg123_handle *fr)
static ssize_t bc_need_more(struct bufferchain *bc)
static ssize_t plain_read(mpg123_handle *fr, void *buf, size_t count)
static off_t nix_lseek(int fd, off_t offset, int whence)
static off_t generic_tell(mpg123_handle *fr)
static int feed_init(mpg123_handle *fr)
static ssize_t bc_seekback(struct bufferchain *bc, ssize_t count)
static int stream_back_bytes(mpg123_handle *fr, off_t bytes)
static off_t get_fileinfo(mpg123_handle *)
static off_t io_seek(struct reader_data *rdat, off_t offset, int whence)
static ssize_t unsigned long *newhead static bugger_off int off_t len static bugger_off int off_t bytes static bugger_off int bad_seek_frame(mpg123_handle *mh, off_t num) bugger_off static off_t bad_tell(mpg123_handle *mh) bugger_off static void bad_rewind(mpg123_handle *mh)
static int feed_seek_frame(mpg123_handle *fr, off_t num)
static int bc_append(struct bufferchain *bc, ssize_t size)
static ssize_t buffered_fullread(mpg123_handle *fr, unsigned char *out, ssize_t count)
#define READER_BUF_ICY_STREAM
#define READER_ICY_STREAM
static struct buffy * buffy_new(size_t size, size_t minsize)
static int bc_add(struct bufferchain *bc, const unsigned char *data, ssize_t size)
static off_t posix_lseek(int fd, off_t offset, int whence)
static off_t stream_lseek(mpg123_handle *fr, off_t pos, int whence)
static ssize_t icy_fullread(mpg123_handle *fr, unsigned char *buf, ssize_t count)
static void bc_free(struct bufferchain *bc, struct buffy *buf)
static ssize_t bc_skip(struct bufferchain *bc, ssize_t count)
static off_t feed_skip_bytes(mpg123_handle *fr, off_t len)
static ssize_t unsigned long *newhead static bugger_off int off_t len static bugger_off int bad_read_frame_body(mpg123_handle *mh, unsigned char *data, int size) bugger_off static int bad_back_bytes(mpg123_handle *mh
static int stream_seek_frame(mpg123_handle *fr, off_t newframe)
static ssize_t posix_read(int fd, void *buf, size_t count)
static void bc_init(struct bufferchain *bc)
static ssize_t unsigned long *newhead static bugger_off int bad_head_shift(mpg123_handle *mh, unsigned long *head) bugger_off static off_t bad_skip_bytes(mpg123_handle *mh
static int generic_read_frame_body(mpg123_handle *fr, unsigned char *buf, int size)
static struct reader bad_reader
static int bc_fill_pool(struct bufferchain *bc)
static void buffy_del_chain(struct buffy *buf)
static void buffered_forget(mpg123_handle *fr)
static int bad_init(mpg123_handle *mh) bugger_off static void bad_close(mpg123_handle *mh)
static struct reader readers[]
static ssize_t plain_fullread(mpg123_handle *fr, unsigned char *buf, ssize_t count)
static off_t stream_skip_bytes(mpg123_handle *fr, off_t len)
static void bc_reset(struct bufferchain *bc)
static void buffy_del(struct buffy *buf)
static ssize_t bc_give(struct bufferchain *bc, unsigned char *out, ssize_t size)
static int open_finish(mpg123_handle *fr)
static int generic_head_shift(mpg123_handle *fr, unsigned long *head)
static int feed_back_bytes(mpg123_handle *fr, off_t bytes)
static ssize_t io_read(struct reader_data *rdat, void *buf, size_t count)
static void stream_close(mpg123_handle *fr)
#define READER_BUF_STREAM
static void bc_forget(struct bufferchain *bc)
static ssize_t bad_fullread(mpg123_handle *mh, unsigned char *data, ssize_t count) bugger_off static int bad_head_read(mpg123_handle *mh
static int default_init(mpg123_handle *fr)
#define debug5(s, a, b, c, d, e)
#define debug4(s, a, b, c, d)
#define debug3(s, a, b, c)
struct mpg123_pars_struct p
unsigned char id3buf[128]
ssize_t(* r_read_handle)(void *handle, void *buf, size_t count)
ssize_t(* read)(int fd, void *buf, size_t count)
off_t(* lseek)(int fd, off_t offset, int whence)
off_t(* r_lseek_handle)(void *handle, off_t offset, int whence)
ssize_t(* fullread)(mpg123_handle *, unsigned char *, ssize_t)
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out