comparison stream/stream.c @ 35885:3389262720da

Fix previous commit, off_t must be replaced by int64_t The commit replacing off_t by uint64_t was by accident, I meant to commit this variant. off_t must be replaced by a signed type to avoid breaking things like seeking backwards and also detecting errors from e.g. lseek without too complex hacks.
author reimar
date Sat, 16 Mar 2013 13:38:34 +0000
parents b5abdfe9bc61
children a5fd69f820f3
comparison
equal deleted inserted replaced
35884:edd8273dc025 35885:3389262720da
284 static int stream_reconnect(stream_t *s) 284 static int stream_reconnect(stream_t *s)
285 { 285 {
286 #define MAX_RECONNECT_RETRIES 5 286 #define MAX_RECONNECT_RETRIES 5
287 #define RECONNECT_SLEEP_MS 1000 287 #define RECONNECT_SLEEP_MS 1000
288 int retry = 0; 288 int retry = 0;
289 uint64_t pos = s->pos; 289 int64_t pos = s->pos;
290 // Seeking is used as a hack to make network streams 290 // Seeking is used as a hack to make network streams
291 // reopen the connection, ideally they would implement 291 // reopen the connection, ideally they would implement
292 // e.g. a STREAM_CTRL_RECONNECT to do this 292 // e.g. a STREAM_CTRL_RECONNECT to do this
293 do { 293 do {
294 if (retry >= MAX_RECONNECT_RETRIES) 294 if (retry >= MAX_RECONNECT_RETRIES)
378 s->pos += rd; 378 s->pos += rd;
379 assert(rd == len && "stream_write_buffer(): unexpected short write"); 379 assert(rd == len && "stream_write_buffer(): unexpected short write");
380 return rd; 380 return rd;
381 } 381 }
382 382
383 int stream_seek_internal(stream_t *s, uint64_t newpos) 383 int stream_seek_internal(stream_t *s, int64_t newpos)
384 { 384 {
385 if(newpos==0 || newpos!=s->pos){ 385 if(newpos==0 || newpos!=s->pos){
386 switch(s->type){ 386 switch(s->type){
387 case STREAMTYPE_STREAM: 387 case STREAMTYPE_STREAM:
388 //s->pos=newpos; // real seek 388 //s->pos=newpos; // real seek
426 // putchar('%');fflush(stdout); 426 // putchar('%');fflush(stdout);
427 } 427 }
428 return -1; 428 return -1;
429 } 429 }
430 430
431 int stream_seek_long(stream_t *s, uint64_t pos){ 431 int stream_seek_long(stream_t *s, int64_t pos){
432 int res; 432 int res;
433 uint64_t newpos=0; 433 int64_t newpos=0;
434 434
435 // if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ) printf("seek_long to 0x%X\n",(unsigned int)pos); 435 // if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ) printf("seek_long to 0x%X\n",(unsigned int)pos);
436 436
437 s->buf_pos=s->buf_len=0; 437 s->buf_pos=s->buf_len=0;
438 438
443 } 443 }
444 444
445 if(s->sector_size) 445 if(s->sector_size)
446 newpos = (pos/s->sector_size)*s->sector_size; 446 newpos = (pos/s->sector_size)*s->sector_size;
447 else 447 else
448 newpos = pos&(~((uint64_t)STREAM_BUFFER_SIZE-1)); 448 newpos = pos&(~((int64_t)STREAM_BUFFER_SIZE-1));
449 449
450 if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ){ 450 if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ){
451 mp_msg(MSGT_STREAM,MSGL_DBG3, "s->pos=%"PRIX64" newpos=%"PRIX64" new_bufpos=%"PRIX64" buflen=%X \n", 451 mp_msg(MSGT_STREAM,MSGL_DBG3, "s->pos=%"PRIX64" newpos=%"PRIX64" new_bufpos=%"PRIX64" buflen=%X \n",
452 (int64_t)s->pos,(int64_t)newpos,(int64_t)pos,s->buf_len); 452 (int64_t)s->pos,(int64_t)newpos,(int64_t)pos,s->buf_len);
453 } 453 }