comparison stream/cache2.c @ 31141:3b5e8cc5e128

Add code to wake up cache process when e.g. a seek is needed. Dramatically reduces seeking times with lavf ogg demuxer. Needs a spearate implementation for the thread-based cache implementation.
author reimar
date Sun, 23 May 2010 19:49:28 +0000
parents 5a1ab9923c3a
children 355302f83219
comparison
equal deleted inserted replaced
31140:5f59f82c599d 31141:3b5e8cc5e128
88 88
89 static int min_fill=0; 89 static int min_fill=0;
90 90
91 int cache_fill_status=0; 91 int cache_fill_status=0;
92 92
93 static void cache_wakeup(stream_t *s)
94 {
95 #if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
96 // signal process to wake up immediately
97 kill(s->cache_pid, SIGUSR1);
98 #endif
99 }
100
93 static void cache_stats(cache_vars_t *s) 101 static void cache_stats(cache_vars_t *s)
94 { 102 {
95 int newb=s->max_filepos-s->read_filepos; // new bytes in the buffer 103 int newb=s->max_filepos-s->read_filepos; // new bytes in the buffer
96 mp_msg(MSGT_CACHE,MSGL_INFO,"0x%06X [0x%06X] 0x%06X ",(int)s->min_filepos,(int)s->read_filepos,(int)s->max_filepos); 104 mp_msg(MSGT_CACHE,MSGL_INFO,"0x%06X [0x%06X] 0x%06X ",(int)s->min_filepos,(int)s->read_filepos,(int)s->max_filepos);
97 mp_msg(MSGT_CACHE,MSGL_INFO,"%3d %% (%3d%%)\n",100*newb/s->buffer_size,100*min_fill/s->buffer_size); 105 mp_msg(MSGT_CACHE,MSGL_INFO,"%3d %% (%3d%%)\n",100*newb/s->buffer_size,100*min_fill/s->buffer_size);
325 } 333 }
326 334
327 static void exit_sighandler(int x){ 335 static void exit_sighandler(int x){
328 // close stream 336 // close stream
329 exit(0); 337 exit(0);
338 }
339
340 static void dummy_sighandler(int x) {
330 } 341 }
331 342
332 /** 343 /**
333 * \return 1 on success, 0 if the function was interrupted and -1 on error 344 * \return 1 on success, 0 if the function was interrupted and -1 on error
334 */ 345 */
418 #ifdef CONFIG_GUI 429 #ifdef CONFIG_GUI
419 use_gui = 0; // mp_msg may not use gui stuff in forked code 430 use_gui = 0; // mp_msg may not use gui stuff in forked code
420 #endif 431 #endif
421 // cache thread mainloop: 432 // cache thread mainloop:
422 signal(SIGTERM,exit_sighandler); // kill 433 signal(SIGTERM,exit_sighandler); // kill
434 signal(SIGUSR1, dummy_sighandler); // wakeup
423 do { 435 do {
424 if(!cache_fill(s)){ 436 if(!cache_fill(s)){
425 usec_sleep(FILL_USLEEP_TIME); // idle 437 usec_sleep(FILL_USLEEP_TIME); // idle
426 } 438 }
427 // cache_stats(s->cache_data); 439 // cache_stats(s->cache_data);
468 mp_msg(MSGT_CACHE,MSGL_DBG2,"CACHE2_SEEK: 0x%"PRIX64" <= 0x%"PRIX64" (0x%"PRIX64") <= 0x%"PRIX64" \n",s->min_filepos,pos,s->read_filepos,s->max_filepos); 480 mp_msg(MSGT_CACHE,MSGL_DBG2,"CACHE2_SEEK: 0x%"PRIX64" <= 0x%"PRIX64" (0x%"PRIX64") <= 0x%"PRIX64" \n",s->min_filepos,pos,s->read_filepos,s->max_filepos);
469 481
470 newpos=pos/s->sector_size; newpos*=s->sector_size; // align 482 newpos=pos/s->sector_size; newpos*=s->sector_size; // align
471 stream->pos=s->read_filepos=newpos; 483 stream->pos=s->read_filepos=newpos;
472 s->eof=0; // !!!!!!! 484 s->eof=0; // !!!!!!!
485 cache_wakeup(stream);
473 486
474 cache_stream_fill_buffer(stream); 487 cache_stream_fill_buffer(stream);
475 488
476 pos-=newpos; 489 pos-=newpos;
477 if(pos>=0 && pos<=stream->buf_len){ 490 if(pos>=0 && pos<=stream->buf_len){
512 s->control = cmd; 525 s->control = cmd;
513 break; 526 break;
514 default: 527 default:
515 return STREAM_UNSUPPORTED; 528 return STREAM_UNSUPPORTED;
516 } 529 }
530 cache_wakeup(stream);
517 while (s->control != -1) 531 while (s->control != -1)
518 usec_sleep(CONTROL_SLEEP_TIME); 532 usec_sleep(CONTROL_SLEEP_TIME);
519 switch (cmd) { 533 switch (cmd) {
520 case STREAM_CTRL_GET_TIME_LENGTH: 534 case STREAM_CTRL_GET_TIME_LENGTH:
521 case STREAM_CTRL_GET_CURRENT_TIME: 535 case STREAM_CTRL_GET_CURRENT_TIME: