int cache_stream_seek_long(stream_t *stream,off_t pos){ cache_vars_t* s; off_t newpos; if(!stream->cache_pid) return stream_seek_long(stream,pos); s=stream->cache_data; // s->seek_lock=1; 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); newpos=pos/s->sector_size; newpos*=s->sector_size; // align stream->pos=s->read_filepos=newpos; s->eof=0; // !!!!!!! cache_wakeup(stream); cache_stream_fill_buffer(stream); pos-=newpos; if(pos>=0 && pos<=stream->buf_len){ stream->buf_pos=pos; // byte position in sector return 1; } // stream->buf_pos=stream->buf_len=0; // return 1; mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%"PRIX64" !\n",(int64_t)(pos+newpos)); return 0; }
int cache_do_control(stream_t *stream, int cmd, void *arg) { int sleep_count = 0; cache_vars_t* s = stream->cache_data; switch (cmd) { case STREAM_CTRL_SEEK_TO_TIME: s->control_double_arg = *(double *)arg; s->control = cmd; break; case STREAM_CTRL_SEEK_TO_CHAPTER: case STREAM_CTRL_SET_ANGLE: s->control_uint_arg = *(unsigned *)arg; s->control = cmd; break; // the core might call these every frame, they are too slow for this... case STREAM_CTRL_GET_TIME_LENGTH: // case STREAM_CTRL_GET_CURRENT_TIME: *(double *)arg = s->stream_time_length; return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_ASPECT_RATIO: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: case -2: s->control = cmd; break; default: return STREAM_UNSUPPORTED; } cache_wakeup(stream); while (s->control != -1) { if (sleep_count++ == 1000) mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not responding!\n"); if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { s->eof = 1; return STREAM_UNSUPPORTED; } } switch (cmd) { case STREAM_CTRL_GET_TIME_LENGTH: case STREAM_CTRL_GET_CURRENT_TIME: case STREAM_CTRL_GET_ASPECT_RATIO: *(double *)arg = s->control_double_arg; break; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: *(unsigned *)arg = s->control_uint_arg; break; case STREAM_CTRL_SEEK_TO_CHAPTER: case STREAM_CTRL_SEEK_TO_TIME: case STREAM_CTRL_SET_ANGLE: if (s->control_res != STREAM_UNSUPPORTED) stream->pos = s->read_filepos = s->control_new_pos; break; } return s->control_res; }
int cache_do_control(stream_t *stream, int cmd, void *arg) { int sleep_count = 0; int pos_change = 0; cache_vars_t* s = stream->cache_data; switch (cmd) { case STREAM_CTRL_SEEK_TO_TIME: s->control_double_arg = *(double *)arg; s->control = cmd; pos_change = 1; break; case STREAM_CTRL_SEEK_TO_CHAPTER: case STREAM_CTRL_SET_ANGLE: s->control_uint_arg = *(unsigned *)arg; s->control = cmd; pos_change = 1; break; // the core might call these every frame, so cache them... case STREAM_CTRL_GET_TIME_LENGTH: *(double *)arg = s->stream_time_length; return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED; case STREAM_CTRL_GET_CURRENT_TIME: *(double *)arg = s->stream_time_pos; return s->stream_time_pos != MP_NOPTS_VALUE ? STREAM_OK : STREAM_UNSUPPORTED; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_ASPECT_RATIO: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: case -2: s->control = cmd; break; default: return STREAM_UNSUPPORTED; } cache_wakeup(stream); while (s->control != -1) { if (sleep_count++ == 1000) mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not responding! [performance issue]\n"); if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { s->eof = 1; return STREAM_UNSUPPORTED; } } // to avoid unnecessary differences with non-cache behaviour, // do this also on failure. if (pos_change) { stream->pos = s->read_filepos; stream->eof = s->eof; } if (s->control_res != STREAM_OK) return s->control_res; switch (cmd) { case STREAM_CTRL_GET_TIME_LENGTH: case STREAM_CTRL_GET_CURRENT_TIME: case STREAM_CTRL_GET_ASPECT_RATIO: *(double *)arg = s->control_double_arg; break; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: *(unsigned *)arg = s->control_uint_arg; break; } return s->control_res; }
int cache_do_control(stream_t *stream, int cmd, void *arg) { int sleep_count = 0; int pos_change = 0; cache_vars_t* s = stream->cache_data; switch (cmd) { case STREAM_CTRL_SEEK_TO_TIME: s->control_double_arg = *(double *)arg; s->control = cmd; pos_change = 1; break; case STREAM_CTRL_SEEK_TO_CHAPTER: case STREAM_CTRL_SET_ANGLE: s->control_uint_arg = *(unsigned *)arg; s->control = cmd; pos_change = 1; break; // the core might call these every frame, so cache them... case STREAM_CTRL_GET_TIME_LENGTH: *(double *)arg = s->stream_time_length; return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED; case STREAM_CTRL_GET_CURRENT_TIME: *(double *)arg = s->stream_time_pos; return s->stream_time_pos != MP_NOPTS_VALUE ? STREAM_OK : STREAM_UNSUPPORTED; case STREAM_CTRL_GET_LANG: s->control_lang_arg = *(struct stream_lang_req *)arg; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_ASPECT_RATIO: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: case STREAM_CTRL_GET_SIZE: case -2: s->control = cmd; break; default: return STREAM_UNSUPPORTED; } cache_wakeup(stream); while (s->control != -1) { if (sleep_count++ == 1000) mp_msg(MSGT_CACHE, MSGL_WARN, "Cache not responding! [performance issue]\n"); if (stream_check_interrupt(CONTROL_SLEEP_TIME)) { s->eof = 1; return STREAM_UNSUPPORTED; } } if (s->control_res != STREAM_OK) return s->control_res; // We cannot do this on failure, since this would cause the // stream position to jump when e.g. STREAM_CTRL_SEEK_TO_TIME // is unsupported - but in that case we need the old value // to do the fallback seek. // This unfortunately can lead to slightly different behaviour // with and without cache if the protocol changes pos even // when an error happened. if (pos_change) { stream->pos = s->read_filepos; stream->eof = s->eof; } switch (cmd) { case STREAM_CTRL_GET_TIME_LENGTH: case STREAM_CTRL_GET_CURRENT_TIME: case STREAM_CTRL_GET_ASPECT_RATIO: *(double *)arg = s->control_double_arg; break; case STREAM_CTRL_GET_NUM_CHAPTERS: case STREAM_CTRL_GET_CURRENT_CHAPTER: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: *(unsigned *)arg = s->control_uint_arg; break; case STREAM_CTRL_GET_SIZE: *(off_t *)arg = s->control_uint_arg; break; case STREAM_CTRL_GET_LANG: *(struct stream_lang_req *)arg = s->control_lang_arg; break; } return s->control_res; }