21
21
/*******************************************************************
22
22
* stream based operation
24
static int fullread(int fd,unsigned char *buf,int count)
24
static int fullread(struct reader *rds,unsigned char *buf,int count)
29
* We check against READER_ID3TAG instead of rds->filelen >= 0 because
30
* if we got the ID3 TAG we know we have the end of the file. If we
31
* don't have an ID3 TAG, then it is possible the file has grown since
32
* we started playing, so we want to keep reading from it if possible.
34
if ((rds->flags & READER_ID3TAG) && rds->filepos + count > rds->filelen)
35
count = rds->filelen - rds->filepos;
28
36
while(cnt < count) {
29
ret = read(fd,buf+cnt,count-cnt);
37
ret = read(rds->filept,buf+cnt,count-cnt);
49
static off_t stream_lseek(struct reader *rds, off_t pos, int whence)
53
ret = lseek(rds->filept, pos, whence);
40
60
static int default_init(struct reader *rds)
64
rds->filelen = get_fileinfo(rds,buf);
45
rds->filelen = get_fileinfo(rds,buf);
47
if(rds->filelen > 0) {
67
if(rds->filelen >= 0) {
48
68
if(!strncmp(buf,"TAG",3)) {
49
69
rds->flags |= READER_ID3TAG;
50
70
memcpy(rds->id3buf,buf,128);
66
86
static int stream_back_bytes(struct reader *rds,int bytes)
68
if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
88
if(stream_lseek(rds,-bytes,SEEK_CUR) < 0)
70
90
if(param.usebuffer)
96
116
bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
98
if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
118
if(stream_lseek(rds,-bytes,SEEK_CUR) < 0)
101
if(fullread(rds->filept,buf,4) != 4)
121
if(fullread(rds,buf,4) != 4)
104
124
newhead = (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + buf[3];
106
126
while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
107
if(fullread(rds->filept,buf,1) != 1)
127
if(fullread(rds,buf,1) != 1)
110
130
newhead |= buf[0];
111
131
newhead &= 0xffffffff;
114
if( lseek(rds->filept,-4,SEEK_CUR) < 0)
134
if( stream_lseek(rds,-4,SEEK_CUR) < 0)
132
152
unsigned char hbuf[4];
134
if(fullread(rds->filept,hbuf,4) != 4)
154
if(fullread(rds,hbuf,4) != 4)
137
157
*newhead = ((unsigned long) hbuf[0] << 24) |
157
177
static int stream_skip_bytes(struct reader *rds,int len)
159
if (!param.usebuffer)
160
return lseek(rds->filept,len,SEEK_CUR);
164
int ret = lseek(rds->filept,len,SEEK_CUR);
179
if (rds->filelen >= 0) {
180
int ret = stream_lseek(rds, len, SEEK_CUR);
184
} else if (len >= 0) {
188
int num = len < sizeof(buf) ? len : sizeof(buf);
189
ret = fullread(rds, buf, num);
171
199
static int stream_read_frame_body(struct reader *rds,unsigned char *buf,
186
214
static long stream_tell(struct reader *rds)
188
return lseek(rds->filept,0,SEEK_CUR);
191
219
static void stream_rewind(struct reader *rds)
193
lseek(rds->filept,0,SEEK_SET);
221
stream_lseek(rds,0,SEEK_SET);
194
222
if(param.usebuffer)
209
237
if(lseek(rds->filept,-128,SEEK_END) < 0)
211
if(fullread(rds->filept,(unsigned char *)buf,128) != 128) {
239
if(fullread(rds,(unsigned char *)buf,128) != 128) {
214
242
if(!strncmp(buf,"TAG",3)) {
456
else if (!strncmp(bs_filenam, "http://", 7))
457
filept = http_open(bs_filenam);
484
else if (!strncmp(bs_filenam, "http://", 7)) {
485
if ((filept = http_open(bs_filenam)) < 0)
459
489
#define O_BINARY (0)
461
491
else if ( (filept = open(bs_filenam, O_RDONLY|O_BINARY)) < 0) {
462
492
perror (bs_filenam);