int64_t url_filesize(URLContext *h) { int64_t pos, size; size= url_seek(h, 0, AVSEEK_SIZE); if(size<0){ pos = url_seek(h, 0, SEEK_CUR); if ((size = url_seek(h, -1, SEEK_END)) < 0) return size; size++; url_seek(h, pos, SEEK_SET); } return size; }
static int64_t read_data_exseek(URLContext *opaque, int64_t offset, int whence) { #ifdef USED_LP_BUF URLContext *url=opaque; struct variant *v = url->priv_data; HLSContext *c = v->parent->priv_data; #else struct variant *v = opaque; HLSContext *c = v->parent->priv_data; #endif int ret=AVERROR(EPIPE);; if (whence == AVSEEK_FULLTIME) { //no support } else if (whence == AVSEEK_BUFFERED_TIME) { struct segment *seg = v->segments[v->cur_seq_no - v->start_seq_no]; int bufedtime=0; if(seg){ bufedtime=seg->seg_starttime; if(v->input) bufedtime+=seg->duration*url_seek(v->input, 0, SEEK_CUR)/url_filesize(v->input); return bufedtime; } } else if(whence == AVSEEK_TO_TIME ){ //no support } else if(whence == AVSEEK_SIZE){ //no support } return ret; }
static int seek(stream_t *s, loff_t newpos) { s->pos = newpos; if (url_seek(s->priv, s->pos, SEEK_SET) < 0) { s->eof = 1; return 0; } return 1; }
long tf_seek(struct timidity_file *tf, long offset, int whence) { long prevpos; prevpos = url_seek(tf->url, offset, whence); if(prevpos == -1) ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "Warning: Can't seek file position"); return prevpos; }
long long StreamingRingBuffer::Seek(long long pos, int whence, bool has_lock) { if (!m_context) return 0; if (url_seek(m_context, pos, whence) < 0) { ateof = true; return 0; } return pos; }
int url_connect(URLContext* uc) { int err = uc->prot->url_open(uc, uc->filename, uc->flags); if (err) return err; uc->is_connected = 1; //We must be careful here as url_seek() could be slow, for example for http if( (uc->flags & (URL_WRONLY | URL_RDWR)) || !strcmp(uc->prot->name, "file")) if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0) uc->is_streamed= 1; return 0; }
static int hls_buffering_data(AVFormatContext *s,int size){ HLSContext *c = s->priv_data; int i; int ret=-1; struct variant *var =NULL,*v; if (c && c->end_of_segment || c->first_packet) { recheck_discard_flags(s, c->first_packet); c->end_of_segment=0; c->first_packet=0; } for (i = 0; i < c->n_variants; i++) { v = c->variants[i]; if(v->needed){ var=v; break; } } if(!var) return ret; if(size<0){ struct segment *seg = NULL; int bufedtime=0; if(var->cur_seq_no>=v->start_seq_no + v->n_segments){/*bufed to the end segments.*/ seg=var->segments[var->start_seq_no+v->n_segments-1]; if(seg) bufedtime=seg->seg_starttime+seg->duration; return bufedtime; } seg=var->segments[var->cur_seq_no - var->start_seq_no]; if(seg){ int64_t pos,filesize; bufedtime=seg->seg_starttime; if(var->input ){ pos=url_seek(var->input, 0, SEEK_CUR); filesize=url_filesize(var->input); if(filesize>0 && pos<=filesize){ bufedtime+=seg->duration*pos/filesize; } } return bufedtime; } return -1; }else{ if(var->urllpbuf.lpbuf) ret=url_lp_intelligent_buffering(&var->urllpbuf,size); } return ret; }
static int64_t concat_seek(URLContext *h, int64_t pos, int whence) { int64_t result; struct concat_data *data = h->priv_data; struct concat_nodes *nodes = data->nodes; size_t i; switch (whence) { case SEEK_END: for (i = data->length - 1; i && pos < -nodes[i].size; i--) pos += nodes[i].size; break; case SEEK_CUR: /* get the absolute position */ for (i = 0; i != data->current; i++) pos += nodes[i].size; pos += url_seek(nodes[i].uc, 0, SEEK_CUR); whence = SEEK_SET; /* fall through with the absolute position */ case SEEK_SET: for (i = 0; i != data->length - 1 && pos >= nodes[i].size; i++) pos -= nodes[i].size; break; default: return AVERROR(EINVAL); } result = url_seek(nodes[i].uc, pos, whence); if (result >= 0) { data->current = i; while (i) result += nodes[--i].size; } return result; }
static bool input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence, G_GNUC_UNUSED GError **error_r) { struct input_ffmpeg *i = (struct input_ffmpeg *)is; #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) int64_t ret = avio_seek(i->h, offset, whence); #else int64_t ret = url_seek(i->h, offset, whence); #endif if (ret >= 0) { i->eof = false; return true; } else { g_set_error(error_r, ffmpeg_quark(), 0, "url_seek() failed"); return false; } }
static int concat_read(URLContext *h, unsigned char *buf, int size) { int result, total = 0; struct concat_data *data = h->priv_data; struct concat_nodes *nodes = data->nodes; size_t i = data->current; while (size > 0) { result = url_read(nodes[i].uc, buf, size); if (result < 0) return total ? total : result; if (!result) if (i + 1 == data->length || url_seek(nodes[++i].uc, 0, SEEK_SET) < 0) break; total += result; buf += result; size -= result; } data->current = i; return total; }
int url_open_protocol (URLContext **puc, struct URLProtocol *up, const char *filename, int flags) { URLContext *uc; int err; uc = av_malloc(sizeof(URLContext) + strlen(filename) + 1); if (!uc) { err = AVERROR(ENOMEM); goto fail; } #if LIBAVFORMAT_VERSION_MAJOR >= 53 uc->av_class = &urlcontext_class; #endif uc->filename = (char *) &uc[1]; strcpy(uc->filename, filename); uc->prot = up; uc->flags = flags; uc->is_streamed = 0; /* default = not streamed */ uc->max_packet_size = 0; /* default: stream file */ err = up->url_open(uc, filename, flags); if (err < 0) { av_free(uc); *puc = NULL; return err; } //We must be carefull here as url_seek() could be slow, for example for http if( (flags & (URL_WRONLY | URL_RDWR)) || !strcmp(up->name, "file")) if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0) uc->is_streamed= 1; *puc = uc; return 0; fail: *puc = NULL; return err; }