static int list_open(URLContext *h, const char *filename, int flags)
{
	struct list_mgt *mgt;
	int ret;
	ByteIOContext *bio;
	mgt=av_malloc(sizeof(struct list_mgt));
	if(!mgt)
		return AVERROR(ENOMEM);
	memset(mgt,0,sizeof(*mgt));
	mgt->filename=filename+5;
	mgt->flags=flags;
	if((ret=list_open_internet(&bio,mgt,mgt->filename,flags| URL_MINI_BUFFER | URL_NO_LP_BUFFER))!=0)
	{
		av_free(mgt);
		return ret;
	}
	lp_lock_init(&mgt->mutex,NULL);
	mgt->current_item=mgt->item_list;
	mgt->cur_uio=NULL;
 	h->is_streamed=1;
	h->is_slowmedia=1;
	if(mgt->full_time>0 && mgt->have_list_end)
		h->support_time_seek=1;
	h->priv_data = mgt;
	
	url_fclose(bio);
	return 0;
}
int am_config_init(void)
{
    lp_lock_init(&config_lock, NULL);
    lp_lock(&config_lock);
    //can do more init here.
    memset(amconfigs, 0, sizeof(amconfigs));
    amconfig_inited = 1;
    lp_unlock(&config_lock);
    return 0;
}
Пример #3
0
static int list_open(URLContext *h, const char *filename, int flags)
{
	struct list_mgt *mgt;
	int ret;
	ByteIOContext *bio;
	mgt=av_malloc(sizeof(struct list_mgt));
	if(!mgt)
		return AVERROR(ENOMEM);
	memset(mgt,0,sizeof(struct list_mgt));
	mgt->key_tmp = NULL;
	mgt->seq = -1;
	mgt->cur_seq_no = -1;
	mgt->filename=filename+5;
	mgt->flags=flags;
	mgt->jump_item_num = 0;
	if((ret=list_open_internet(&bio,mgt,mgt->filename,flags| URL_MINI_BUFFER | URL_NO_LP_BUFFER))!=0)
	{
		av_free(mgt);
		return ret;
	}
	lp_lock_init(&mgt->mutex,NULL);
	if(!mgt->have_list_end && (!mgt->have_sub_list)&&(mgt->target_duration<5)){
		struct list_item *item=mgt->item_list;
		int itemindex=mgt->item_num/2+1;/*for live streaming ,choose the middle item.*/
		while(itemindex-->0 && item!=NULL)
			item=item->next;
		mgt->current_item=item;
	}else
		mgt->current_item=mgt->item_list;	
	mgt->cur_uio=NULL;
 	h->is_streamed=1;
	h->is_slowmedia=1;
	if(mgt->full_time>0 && mgt->have_list_end)
		h->support_time_seek=1;
	h->priv_data = mgt;
	
	url_fclose(bio);
	return 0;
}
Пример #4
0
int url_lpopen(URLContext *s,int size)
{
	url_lpbuf_t *lp;
	int blocksize=32*1024;
	int ret;
	float value=0.0;
	int bufsize=0;

	if(size==0){
		//size=am_getconfig_float("libplayer.ffmpeg.lpbufsizemax",&value);
		//if(size<=0)
			size=IO_LP_BUFFER_SIZE;
	}
	lp_bprint( AV_LOG_INFO,"url_lpopen=%d\n",size);
	if(!s)
		return -1;
		lp_bprint( AV_LOG_INFO,"url_lpopen2=%d\n",size);
	//ret=am_getconfig_float("libplayer.ffmpeg.lpbufblocksize",&value);
	//if(ret>=0 && value>=32){
	//	blocksize=(int)value;
	//}	
	lp_sprint( AV_LOG_INFO,"lpbuffer block size=%d\n",blocksize);
	lp=av_mallocz(sizeof(url_lpbuf_t));
	if(!lp)
		return AVERROR(ENOMEM);
	lp->buffer=av_malloc(size);
	if(!lp->buffer)
	{
		int failedsize=size/2;/*if no memory used 1/2 size */
		//ret=am_getconfig_float("libplayer.ffmpeg.lpbuffaildsize",&value);
		//if(ret>=0 && value>=1024){
		//	failedsize=(int)value;
		//}
		lp_sprint( AV_LOG_INFO,"malloc buf failed,used failed size=%d\n",failedsize);

		lp->buffer=av_malloc(failedsize);	
		while(!lp->buffer){
			failedsize=failedsize/2;
			if(failedsize<16*1024)/*do't malloc too small size failed size*/
				return AVERROR(ENOMEM);
			lp->buffer=av_malloc(failedsize);
		}
		bufsize=failedsize;
	}else{
		bufsize=size;
	}
	lp_sprint( AV_LOG_INFO,"url_lpopen used lp buf size=%d\n",bufsize);
	s->lpbuf=lp;
	lp->buffer_size=bufsize;
	lp->rp=lp->buffer;
	lp->wp=lp->buffer;
	lp->buffer_end=lp->buffer+bufsize;
	lp->valid_data_size=0;
	lp->pos=0;
	lp->block_read_size=FFMIN(blocksize,bufsize>>4);
	lp_lock_init(&lp->mutex,NULL);
	lp->file_size=url_lpseek(s,0,AVSEEK_SIZE);
	lp->cache_enable=0;
	lp->cache_id=aviolp_cache_open(s->filename,url_filesize(s));
	lp->dbg_cnt=0;
	if(lp->cache_id!=0)
		lp->cache_enable=1;
	lp_bprint( AV_LOG_INFO,"url_lpopen4%d\n",bufsize);
	return 0;
}
Пример #5
0
int url_lpopen(URLContext *s,int size)
{
	url_lpbuf_t *lp;
	int blocksize=32*1024;
	int ret;
	float value=0.0;
	int bufsize=0;
	
	if(size==0){
		ret=am_getconfig_float("libplayer.ffmpeg.lpbufsizemax",&value);
		if(ret<0 || value < 1024*32){
			if(am_getconfig_bool_def("media.amplayer.low_ram",0)){
				size=IO_LP_BUFFER_SIZE/8;
			}else{
			    size=IO_LP_BUFFER_SIZE;
			}
		}else{
			size=(int)value;
		}
	}
	lp_bprint( AV_LOG_INFO,"url_lpopen=%d\n",size);
	if(!s)
		return -1;
		lp_bprint( AV_LOG_INFO,"url_lpopen2=%d\n",size);
	ret=am_getconfig_float("libplayer.ffmpeg.lpbufblocksize",&value);
	if(ret>=0 && value>=32){
		blocksize=(int)value;
	}	
	lp_sprint( AV_LOG_INFO,"lpbuffer block size=%d\n",blocksize);
	lp=av_mallocz(sizeof(url_lpbuf_t));
	if(!lp)
		return AVERROR(ENOMEM);
	lp->buffer=av_malloc(size);
	if(!lp->buffer)
	{
		int failedsize=size/2;/*if no memory used 1/2 size */
		ret=am_getconfig_float("libplayer.ffmpeg.lpbuffaildsize",&value);
		if(ret>=0 && value>=1024){
			failedsize=(int)value;
		}
		lp_sprint( AV_LOG_INFO,"malloc buf failed,used failed size=%d\n",failedsize);
		lp->buffer=av_malloc(failedsize);	
		while(!lp->buffer){
			failedsize=failedsize/2;
			if(failedsize<16*1024){/*do't malloc too small size failed size*/
				av_free(lp);
				return AVERROR(ENOMEM);
			}
			lp->buffer=av_malloc(failedsize);
		}
		bufsize=failedsize;
	}else{
		bufsize=size;
	}
	lp_sprint( AV_LOG_INFO,"url_lpopen used lp buf size=%d\n",bufsize);
	s->lpbuf=lp;
	lp->buffer_size=bufsize;
	lp->rp=lp->buffer;
	lp->wp=lp->buffer;
	lp->buffer_end=lp->buffer+bufsize;
	lp->valid_data_size=0;
	lp->pos=0;
	lp->block_read_size=FFMIN(blocksize,bufsize>>4);
	lp_lock_init(&lp->mutex,NULL);
	lp->file_size=url_lpseek(s,0,AVSEEK_SIZE);
	lp->cache_enable=0;
	lp->cache_id=aviolp_cache_open(s->filename,url_lpseek(s,0,AVSEEK_SIZE));
	lp->dbg_cnt=0;
	ret=am_getconfig_float("libplayer.ffmpeg.lpbufmaxbuflv",&value);
		if(ret<0)
			lp->max_forword_level=1;
		else{
			lp->max_forword_level=value;
		}
	
	if(lp->cache_id!=0)
		lp->cache_enable=1;
	lp_bprint( AV_LOG_INFO,"url_lpopen4%d\n",bufsize);

	ret=am_getconfig_float("libplayer.ffmpeg.maxreadseek",&value);
	if(ret>=0 && value>=0)
	{
		lp->max_read_seek=value;
	}else
	{
		lp->max_read_seek=DEF_MAX_READ_SEEK;
	}
	return 0;
}
Пример #6
0
static int list_open(URLContext *h, const char *filename, int flags)
{
    struct list_mgt *mgt;
    int ret;   
    mgt = av_malloc(sizeof(struct list_mgt));
    if (!mgt) {
        return AVERROR(ENOMEM);
    }
    memset(mgt, 0, sizeof(struct list_mgt));
    mgt->key_tmp = NULL;
    mgt->start_seq = -1;
    mgt->next_seq = -1;
    mgt->filename = filename + 5;
    mgt->flags = flags;
    mgt->next_index = 0;
    mgt->playing_item_index = 0;
    mgt->playing_item_seq = 0;
    mgt->strategy_up_counts = 0;
    mgt->strategy_down_counts = 0;
    mgt->listclose = 0;
    mgt->cmf_item_index = 0;
    mgt->cur_uio = NULL;
    mgt->codec_buf_level=-1;
    mgt->switch_down_num = 0;
    mgt->switch_up_num = 0;
    mgt->debug_level = (int)get_adaptation_ex_para(4);
    char headers[1024];
    char sess_id[40];
    memset(headers, 0, sizeof(headers));
    memset(sess_id, 0, sizeof(sess_id));
    generate_segment_session_id(sess_id, 37);
    snprintf(headers, sizeof(headers),
             "Connection: keep-alive\r\n"
             /*"Range: bytes=0- \r\n"*/
             "X-Playback-Session-Id: %s\r\n%s", sess_id,h!=NULL&&h->headers!=NULL?h->headers:"");
    //av_log(NULL, AV_LOG_INFO, "Generate ipad http request headers,\r\n%s\n", headers);
    mgt->ipad_ex_headers = strndup(headers, 1024);
   
    memset(headers, 0, sizeof(headers));
    generate_playback_session_id(sess_id, 37);
    snprintf(headers, sizeof(headers),
             /*"Connection: keep-alive\r\n"*/
             "X-Playback-Session-Id: %s\r\n%s", sess_id,h!=NULL&&h->headers!=NULL?h->headers:"");
    //av_log(NULL, AV_LOG_INFO, "Generate ipad http request media headers,\r\n%s\n", headers);
    
    mgt->ipad_req_media_headers = strndup(headers, 1024);

    gListMgt = mgt;
    if ((ret = list_open_internet(&mgt->cur_uio, mgt, mgt->filename, flags | URL_MINI_BUFFER | URL_NO_LP_BUFFER)) != 0) {
        av_free(mgt);
        return ret;
    }
    lp_lock_init(&mgt->mutex, NULL);
	
    float value = 0.0;
    ret = am_getconfig_float("libplayer.hls.stpos", &value);
    if (ret < 0 || value <= 0) {	
        if (!mgt->have_list_end) {
            int itemindex =0;
            if(mgt->item_num<10&&mgt->target_duration<5){
                itemindex = mgt->item_num / 2+1; /*for live streaming ,choose the middle item.*/

            }else if(mgt->item_num>=10){
                itemindex = mgt->item_num-3; //last item
            }else if(mgt->item_num<10&&mgt->target_duration>5){
                itemindex =  mgt->item_num -1;               
            }
            mgt->current_item = list_find_item_by_index(mgt,itemindex-1);
        } else {
            mgt->current_item = mgt->item_list;
        }		
    }else{
    	mgt->current_item = list_find_item_by_index(mgt,(int)value-1);
    }	
   
    h->is_streamed = 1;
    h->is_slowmedia = 1;
    if (mgt->full_time > 0 && mgt->have_list_end) {
        h->support_time_seek = 1;
    }
    h->priv_data = mgt;
    mgt->cache_http_handle = NULL;
    
    ret = CacheHttp_Open(&mgt->cache_http_handle,mgt->ipad_req_media_headers);
    if(mgt->debug_level>0){
        hls_base_info_dump(mgt);
    }
  

    return 0;
}