Exemplo n.º 1
0
/*=======================================================================================*/
int url_is_file_list(ByteIOContext *s,const char *filename)
{
	int ret;
	list_demux_t *demux;
	ByteIOContext *lio=s;
	int64_t	   *oldpos=0;
	if(!lio)
	{
		ret=url_fopen(&lio,filename,AVIO_FLAG_READ);
		if(ret!=0)
		{ 
		return AVERROR(EIO); 
		}
	}
	else{
		oldpos=url_ftell(lio);
	}
	demux=probe_demux(lio,filename);
	if(lio!=s)
	{
		url_fclose(lio);
	}
	else
	{
		url_fseek(lio, oldpos, SEEK_SET);
	}
	return demux!=NULL?100:0;
}
static int list_open_internet(ByteIOContext **pbio,struct list_mgt *mgt,const char *filename, int flags)
{
	list_demux_t *demux;
	int ret;
	ByteIOContext *bio;
	ret=url_fopen(&bio,filename,flags);
	if(ret!=0)
		{
			return AVERROR(EIO); 
		}
	demux=probe_demux(bio,filename);
	if(!demux)
	{
		ret=-1;
		goto error;
	}
	ret=demux->parser(mgt,bio);
	if(ret<=0)
	{
		ret=-1;
		goto error;
	}
	*pbio=bio;
	return 0;
error:
	if(bio)
		url_fclose(bio);
	return ret;
}
Exemplo n.º 3
0
/*=======================================================================================*/
int url_is_file_list(ByteIOContext *s, const char *filename)
{
    int ret;
    list_demux_t *demux;
    ByteIOContext *lio = s;
    int64_t    *oldpos = 0;
    if (am_getconfig_bool("media.amplayer.usedm3udemux")) {
        return 0;    /*if used m3u demux,always failed;*/
    }
    if (!lio) {
        ret = url_fopen(&lio, filename, AVIO_FLAG_READ | URL_MINI_BUFFER|URL_NO_LP_BUFFER);
        if (ret != 0) {
            return AVERROR(EIO);
        }
    } else {
        oldpos = url_ftell(lio);
    }
    demux = probe_demux(lio, filename);
    if (lio != s) {
        url_fclose(lio);
    } else {
        url_fseek(lio, oldpos, SEEK_SET);
    }
    return demux != NULL ? 100 : 0;
}
Exemplo n.º 4
0
static int list_open_internet(ByteIOContext **pbio,struct list_mgt *mgt,const char *filename, int flags)
{
	list_demux_t *demux;
	int ret;
	ByteIOContext *bio;
	char* url = filename; 
reload:
	ret=url_fopen(&bio,url,flags);
	if(ret!=0)
		{
			return AVERROR(EIO); 
		}
	mgt->location=bio->reallocation;
	if(NULL == mgt->location&&mgt->n_variants>1){//set location for multibandwidth streaming,such youtube,etc.
		mgt->location = url;
	}
	demux=probe_demux(bio,url);
	if(!demux)
	{
		ret=-1;
		goto error;
	}
	ret=demux->parser(mgt,bio);
	if(ret<=0&&mgt->n_variants ==0)
	{
		ret=-1;
		goto error;
	}else{
		if(mgt->item_num ==0&&mgt->n_variants>0){//simplely choose server,mabye need sort variants when got it from server.
			if(bio){
				url_fclose(bio);					
			}
			if(mgt->ctype ==HIGH_BANDWIDTH){
				struct variant *v =mgt->variants[mgt->n_variants-1];
				url = v->url;
				mgt->playing_variant = v;
				av_log(NULL, AV_LOG_INFO, "reload playlist,url:%s\n",url);
				goto reload;
			}else if(mgt->ctype ==LOW_BANDWIDTH){
				struct variant *v =mgt->variants[0];
				url = v->url;
				mgt->playing_variant = v;
				av_log(NULL, AV_LOG_INFO, "reload playlist,url:%s\n",url);
				goto reload;
			}else if(mgt->ctype ==MIDDLE_BANDWIDTH){
				struct variant *v = NULL;
				if(mgt->n_variants>4){
					v =mgt->variants[mgt->n_variants/2 -1];
				}else{
					v =mgt->variants[mgt->n_variants-1];
				}				
				url = v->url;
				mgt->playing_variant = v;
				av_log(NULL, AV_LOG_INFO, "reload playlist,url:%s,bandwidth:%d\n",url,mgt->playing_variant->bandwidth);
				goto reload;
			}
		}

	}
	
	*pbio=bio;
	return 0;
error:
	if(bio)
		url_fclose(bio);
	return ret;
}
Exemplo n.º 5
0
static int list_open_internet(ByteIOContext **pbio, struct list_mgt *mgt, const char *filename, int flags)
{
    list_demux_t *demux;
    int ret =0;
    ByteIOContext *bio = *pbio;
    char* url = filename;
reload:
    
    if (url_interrupt_cb()) {
         ret = -1;       
         goto error;   
    }
    
    if(bio==NULL){
        ret = avio_open_h(&bio, url, flags,mgt->ipad_ex_headers);
        //av_log(NULL,AV_LOG_INFO,"http open,return value: %d\n",ret);
        
    }else{
        avio_reset(bio,AVIO_FLAG_READ); 
        URLContext* last = (URLContext*)bio->opaque;    
	 if(last!=NULL){	
        	ret = ff_http_do_new_request(last,NULL);

	 }else{
		ret = -1;
	 }
        //av_log(NULL,AV_LOG_INFO,"do http request,return value: %d\n",ret);
    }
    
    if (ret != 0) {      
	goto error;
    }
    mgt->location = bio->reallocation;
    if (NULL == mgt->location && mgt->n_variants > 0) { //set location for multibandwidth streaming,such youtube,etc.
        mgt->location = url;
    }
    demux = probe_demux(bio, url);
    if (!demux) {
        ret = -1;       
        goto error;
    }
    ret = demux->parser(mgt, bio);
    if (ret <0 && mgt->n_variants == 0) {
        ret = -1;
        
        goto error;
    } else {
       
        if (mgt->item_num == 0 && mgt->n_variants > 0) { //simplely choose server,mabye need sort variants when got it from server.
            if (bio) {
                url_fclose(bio);
                bio = NULL;
                
            }
            
            ret = fast_sort_streams(mgt);  
            if(mgt->playing_variant==NULL||mgt->playing_variant->url==NULL||strlen(mgt->playing_variant->url)<4){
                av_log(NULL,AV_LOG_ERROR,"failed to sort or get streams\n");
                ret = -1;
                goto error;
            }
            url = mgt->playing_variant->url;           
            //av_log(NULL, AV_LOG_INFO, "[%d]reload playlist,url:%s\n", __LINE__, url);
            goto reload;           

        }

    }
    if(av_strstart(url,"shttps://", NULL)){
        //av_log(NULL,AV_LOG_INFO,"Https url only use short tcp connect\n");
        url_fclose(bio);
        bio= NULL;
    }
    *pbio = bio;
    return 0;
error:
    if (bio) {       
        url_fclose(bio);
        *pbio  = NULL;
	 mgt->cur_uio = NULL;	
    }
    return ret;
}