/* XXX: use llseek */
static int64_t list_seek(URLContext *h, int64_t pos, int whence)
{
	struct list_mgt *mgt = h->priv_data;
	struct list_item *item,*item1;
	if (whence == AVSEEK_BUFFERED_TIME)
	{
		int64_t buffed_time=0;
		if(mgt->current_item && mgt->current_item->duration>0){
			//av_log(NULL, AV_LOG_INFO, "list_seek uui=%ld,size=%lld\n",mgt->cur_uio,url_fsize(mgt->cur_uio));
			if(mgt->cur_uio && url_fsize(mgt->cur_uio)>0)
{
				//av_log(NULL, AV_LOG_INFO, "list_seek start_time=%ld,pos=%lld\n",mgt->current_item->start_time,url_buffed_pos(mgt->cur_uio));
				buffed_time=mgt->current_item->start_time+url_buffed_pos(mgt->cur_uio)*mgt->current_item->duration/url_fsize(mgt->cur_uio);
			}
			else{
				buffed_time=mgt->current_item->start_time;
			}
		}
		av_log(NULL, AV_LOG_INFO, "list current buffed_time=%lld\n",buffed_time);
		return buffed_time;
	}
	
	av_log(NULL, AV_LOG_INFO, "list_seek pos=%lld,whence=%x\n",pos,whence);
	if (whence == AVSEEK_SIZE)
        return mgt->file_size;
	if (whence == AVSEEK_FULLTIME)
	{
		if(mgt->have_list_end)
			return mgt->full_time;
		else
			return -1;
	}
	
	if(whence == AVSEEK_TO_TIME && pos>=0 && pos<mgt->full_time)
	{
		av_log(NULL, AV_LOG_INFO, "list_seek to Time =%lld,whence=%x\n",pos,whence);
		for(item=mgt->item_list;item;item=item->next)
		{
			if(item->start_time<=pos && pos <item->start_time+item->duration)
			{	
				if(mgt->cur_uio)
					url_fclose(mgt->cur_uio);
				mgt->cur_uio=NULL;
				mgt->current_item=item;
				av_log(NULL, AV_LOG_INFO, "list_seek to item->file =%s\n",item->file);
				return item->start_time;/*pos=0;*/
			}
		}
	}
	av_log(NULL, AV_LOG_INFO, "list_seek failed\n");
	return -1;
Пример #2
0
/* XXX: use llseek */
static int64_t list_seek(URLContext *h, int64_t pos, int whence)
{
	struct list_mgt *mgt = h->priv_data;
	URLContext *subh;
	struct list_mgt *submgt;
	struct list_item *item,*item1;	
	struct list_item *cur_item;
	int fulltime;

	if (!h->support_time_seek) {
		if(!mgt->have_list_end && mgt->have_sub_list && mgt->cur_uio){
			if(mgt->cur_uio->support_time_seek){
				h->support_time_seek = 1;
				av_log(NULL, AV_LOG_INFO, "sub list support seek\n");
			}
		}		
	}
	if (whence == AVSEEK_BUFFERED_TIME)
	{
		int64_t buffed_time=0;
		if(mgt->current_item ){
			//av_log(NULL, AV_LOG_INFO, "list_seek uui=%ld,size=%lld\n",mgt->cur_uio,url_fsize(mgt->cur_uio));
			if(mgt->cur_uio && url_fsize(mgt->cur_uio)>0 && mgt->current_item->duration>=0){
				//av_log(NULL, AV_LOG_INFO, "list_seek start_time=%ld,pos=%lld\n",mgt->current_item->start_time,url_buffed_pos(mgt->cur_uio));
				buffed_time=mgt->current_item->start_time+url_buffed_pos(mgt->cur_uio)*mgt->current_item->duration/url_fsize(mgt->cur_uio);
			}
			else{
				buffed_time=mgt->current_item->start_time;
				if(mgt->current_item && (mgt->current_item->flags & ENDLIST_FLAG))
					buffed_time=mgt->full_time;/*read to end list, show full bufferd*/
			}
		}
		//av_log(NULL, AV_LOG_INFO, "list current buffed_time=%lld\n",buffed_time);
		return buffed_time;
	}
	
	if (whence == AVSEEK_SIZE)
        return mgt->file_size;
	av_log(NULL, AV_LOG_INFO, "list_seek pos=%lld,whence=%x\n",pos,whence);
	if (whence == AVSEEK_FULLTIME)
	{
		if(mgt->have_list_end){
			av_log(NULL, AV_LOG_INFO, "return mgt->full_timet=%d\n",mgt->full_time);
			return mgt->full_time;
		}else if(mgt->have_sub_list && mgt->cur_uio){
				subh = mgt->cur_uio->opaque;
				av_log(NULL, AV_LOG_INFO, "seek sub file for fulltime\n");
				return list_seek(subh,pos, whence);
		}else
			return -1;
	}
	
	if(whence == AVSEEK_TO_TIME)
	{
		av_log(NULL, AV_LOG_INFO, "list_seek to Time =%lld,whence=%x,have sublist:%d\n",pos,whence,mgt->have_sub_list);
		if (!mgt->have_sub_list) {
			if(pos>=0 && pos<mgt->full_time) {

				for(item=mgt->item_list;item;item=item->next)
				{
					
					if(item->start_time<=pos && pos <item->start_time+item->duration)
					{	
						if(mgt->cur_uio){
							
							url_fclose(mgt->cur_uio);

						}
						
						mgt->cur_uio=NULL;
						mgt->current_item=item;
						av_log(NULL, AV_LOG_INFO, "list_seek to item->file =%s\n",item->file);
						return item->start_time;/*pos=0;*/
					}
				}
			}
		} else {
		    if(!mgt->cur_uio){
   				av_log(NULL, AV_LOG_ERROR, "byteio already close, seek failed!\n");
		        return -1;
		    }
			subh = mgt->cur_uio->opaque;	
			submgt = subh->priv_data;
			if(subh && submgt) {
				av_log(NULL, AV_LOG_INFO, "have sub list, go2 low level, location=%s\n",submgt->location);
				return list_seek(subh, pos, whence);
			}
		}
	}
	av_log(NULL, AV_LOG_INFO, "list_seek failed\n");
	return -1;
}