Пример #1
0
static int rtmp_http_send_cmd(URLContext *h, const char *cmd)
{
    RTMP_HTTPContext *rt = h->priv_data;
    char uri[2048];
    uint8_t c;
    int ret;

    ff_url_join(uri, sizeof(uri), "http", NULL, rt->host, rt->port,
                "/%s/%s/%d", cmd, rt->client_id, rt->seq++);

    av_opt_set_bin(rt->stream->priv_data, "post_data", rt->out_data,
                   rt->out_size, 0);

    /* send a new request to the server */
    if ((ret = ff_http_do_new_request(rt->stream, uri)) < 0)
        return ret;

    /* re-init output buffer */
    rt->out_size = 0;

    /* read the first byte which contains the polling interval */
    if ((ret = ffurl_read(rt->stream, &c, 1)) < 0)
        return ret;

    /* re-init the number of bytes read */
    rt->nb_bytes_read = 0;

    return ret;
}
Пример #2
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;
}