Ejemplo n.º 1
0
static int enc_set_br(MSFilter *f, void *arg) {
    EncData *d=(EncData*)f->data;
    d->bitrate=*(int*)arg;

    if (d->enc) {
        ms_filter_lock(f);
        apply_bitrate(f,d->bitrate);
        if (x264_encoder_reconfig(d->enc,&d->params)!=0) {
            ms_error("x264_encoder_reconfig() failed.");
        }
        ms_filter_unlock(f);
        return 0;
    }

    if (d->bitrate>=1024000) {
        d->vsize.width = MS_VIDEO_SIZE_SVGA_W;
        d->vsize.height = MS_VIDEO_SIZE_SVGA_H;
        d->fps=25;
    } else if (d->bitrate>=512000) {
        d->vsize.width = MS_VIDEO_SIZE_VGA_W;
        d->vsize.height = MS_VIDEO_SIZE_VGA_H;
        d->fps=25;
    } else if (d->bitrate>=256000) {
        d->vsize.width = MS_VIDEO_SIZE_VGA_W;
        d->vsize.height = MS_VIDEO_SIZE_VGA_H;
        d->fps=15;
    } else if (d->bitrate>=170000) {
        d->vsize.width=MS_VIDEO_SIZE_QVGA_W;
        d->vsize.height=MS_VIDEO_SIZE_QVGA_H;
        d->fps=15;
    } else if (d->bitrate>=128000) {
        d->vsize.width=MS_VIDEO_SIZE_QCIF_W;
        d->vsize.height=MS_VIDEO_SIZE_QCIF_H;
        d->fps=10;
    } else if (d->bitrate>=64000) {
        d->vsize.width=MS_VIDEO_SIZE_QCIF_W;
        d->vsize.height=MS_VIDEO_SIZE_QCIF_H;
        d->fps=7;
    } else {
        d->vsize.width=MS_VIDEO_SIZE_QCIF_W;
        d->vsize.height=MS_VIDEO_SIZE_QCIF_H;
        d->fps=5;
    }

#if defined (ANDROID) || TARGET_OS_IPHONE==1
    d->vsize.width=MS_VIDEO_SIZE_QVGA_W;
    d->vsize.height=MS_VIDEO_SIZE_QVGA_H;
    d->fps=12;

#endif

    ms_message("bitrate requested...: %d (%d x %d)\n", d->bitrate, d->vsize.width, d->vsize.height);
    return 0;
}
Ejemplo n.º 2
0
static void enc_preprocess(MSFilter *f){
	EncData *d=(EncData*)f->data;
	x264_param_t *params=&d->params;
	
	d->packer=rfc3984_new();
	rfc3984_set_mode(d->packer,d->mode);
	rfc3984_enable_stap_a(d->packer,FALSE);
#if defined(__arm__) || defined(ANDROID)
	if (x264_param_default_preset(params,"superfast"/*"ultrafast"*/,"zerolatency")) {
		ms_error("Cannot apply default x264 configuration");
	}
#else
	x264_param_default(params);
#endif
	
	params->i_threads=ms_get_cpu_count();
	params->i_sync_lookahead=0;
	params->i_width=d->vconf.vsize.width;
	params->i_height=d->vconf.vsize.height;
	params->i_fps_num=(int)d->vconf.fps;
	params->i_fps_den=1;
	params->i_slice_max_size=ms_get_payload_max_size()-100; /*-100 security margin*/
	params->i_level_idc=13;
	
	apply_bitrate(f);

	params->rc.i_lookahead=0;
	/*enable this by config ?*/
	/*
	 params.i_keyint_max = (int)d->fps*d->keyframe_int;
	 params.i_keyint_min = (int)d->fps;
	 */
	params->b_repeat_headers=1;
	params->b_annexb=0;
	
	//these parameters must be set so that our stream is baseline
	params->analyse.b_transform_8x8 = 0;
	params->b_cabac = 0;
	params->i_cqm_preset = X264_CQM_FLAT;
	params->i_bframe = 0;
	params->analyse.i_weighted_pred = X264_WEIGHTP_NONE;
	d->enc=x264_encoder_open(params);
	if (d->enc==NULL) ms_error("Fail to create x264 encoder.");
	d->framenum=0;
	video_starter_init(&d->starter);
}
Ejemplo n.º 3
0
static int enc_set_configuration(MSFilter *f, void *arg) {
	EncData *d = (EncData *)f->data;
	const MSVideoConfiguration *vconf = (const MSVideoConfiguration *)arg;
	if (vconf != &d->vconf) memcpy(&d->vconf, vconf, sizeof(MSVideoConfiguration));

	if (d->vconf.required_bitrate > d->vconf.bitrate_limit)
		d->vconf.required_bitrate = d->vconf.bitrate_limit;
	if (d->enc) {
		ms_filter_lock(f);
		apply_bitrate(f);
		if (x264_encoder_reconfig(d->enc, &d->params) != 0) {
			ms_error("x264_encoder_reconfig() failed.");
		}
		ms_filter_unlock(f);
		return 0;
	}

	ms_message("Video configuration set: bitrate=%dbits/s, fps=%f, vsize=%dx%d", d->vconf.required_bitrate, d->vconf.fps, d->vconf.vsize.width, d->vconf.vsize.height);
	return 0;
}
Ejemplo n.º 4
0
static void enc_preprocess(MSFilter *f){
	EncData *d=(EncData*)f->data;
	x264_param_t *params=&d->params;
	
	d->packer=rfc3984_new();
	rfc3984_set_mode(d->packer,d->mode);
	rfc3984_enable_stap_a(d->packer,FALSE);
#if defined(__arm__) || defined(ANDROID)
	if (x264_param_default_preset(params,"superfast"/*"ultrafast"*/,"zerolatency")) { 
#else
		x264_param_default(params); {
#endif
		ms_error("Cannot apply default x264 configuration");
	};
	
	params->i_threads=ms_get_cpu_count();
	params->i_sync_lookahead=0;
	params->i_width=d->vconf.vsize.width;
	params->i_height=d->vconf.vsize.height;
	params->i_fps_num=(int)d->vconf.fps;
	params->i_fps_den=1;
	params->i_slice_max_size=ms_get_payload_max_size()-100; /*-100 security margin*/
	params->i_level_idc=13;
	
	apply_bitrate(f);

	params->rc.i_lookahead=0;
	/*enable this by config ?*/
	/*
	 params.i_keyint_max = (int)d->fps*d->keyframe_int;
	 params.i_keyint_min = (int)d->fps;
	 */
	params->b_repeat_headers=1;
	params->b_annexb=0;
	
	//these parameters must be set so that our stream is baseline
	params->analyse.b_transform_8x8 = 0;
	params->b_cabac = 0;
	params->i_cqm_preset = X264_CQM_FLAT;
	params->i_bframe = 0;
	params->analyse.i_weighted_pred = X264_WEIGHTP_NONE;
	d->enc=x264_encoder_open(params);
	if (d->enc==NULL) ms_error("Fail to create x264 encoder.");
	d->framenum=0;
	video_starter_init(&d->starter);
}

static void x264_nals_to_msgb(x264_nal_t *xnals, int num_nals, MSQueue * nalus){
	int i;
	mblk_t *m;
	/*int bytes;*/
	for (i=0;i<num_nals;++i){
		m=allocb(xnals[i].i_payload+10,0);
		
		memcpy(m->b_wptr,xnals[i].p_payload+4,xnals[i].i_payload-4);
		m->b_wptr+=xnals[i].i_payload-4;
		if (xnals[i].i_type==7) {
			ms_message("A SPS is being sent.");
		}else if (xnals[i].i_type==8) {
			ms_message("A PPS is being sent.");
		}
		ms_queue_put(nalus,m);
	}
}