static int
vencoder_init(void *arg) {
	int iid;
	char *pipefmt = (char*) arg;
	struct RTSPConf *rtspconf = rtspconf_global();
	//
	if(rtspconf == NULL) {
		ga_error("video encoder: no configuration found\n");
		return -1;
	}
	if(vencoder_initialized != 0)
		return 0;
	//
	for(iid = 0; iid < video_source_channels(); iid++) {
		char pipename[64];
		int outputW, outputH;
		pipeline *pipe;
		//
		_sps[iid] = _pps[iid] = NULL;
		_spslen[iid] = _ppslen[iid] = 0;
		snprintf(pipename, sizeof(pipename), pipefmt, iid);
		outputW = video_source_out_width(iid);
		outputH = video_source_out_height(iid);
		if((pipe = pipeline::lookup(pipename)) == NULL) {
			ga_error("video encoder: pipe %s is not found\n", pipename);
			goto init_failed;
		}
		ga_error("video encoder: video source #%d from '%s' (%dx%d).\n",
			iid, pipe->name(), outputW, outputH, iid);
		//
		if(vpu_encoder_init(&vpu[iid], outputW, outputH, rtspconf->video_fps, 1,
				ga_conf_mapreadint("video-specific", "b") / 1000,
				ga_conf_mapreadint("video-specific", "g")) < 0)
			goto init_failed;
	}
	vencoder_initialized = 1;
	ga_error("video encoder: initialized (%d channels).\n", iid);
	return 0;
init_failed:
	vencoder_deinit(NULL);
	return -1;
}
int encoderInit(struct encoderInstance *encInst, struct mediaBuffer *enc_dst)
{
	struct encoder_info *enc = &encInst->enc;
	enc->enc_picwidth = encInst->width;
	enc->enc_picheight = encInst->height;
	enc->src_picwidth = encInst->width;
	enc->src_picheight = encInst->height;
	enc->enc_fps = encInst->fps;
	enc->enc_bit_rate = encInst->bitRate;
	enc->gop_size = encInst->gopSize;
	enc->color_space = encInst->colorSpace;

	if (strcmp(encInst->encoderName, "") == 0)
		strcpy(enc->encoder_name,"Encoder");
	else
		strcpy(enc->encoder_name,encInst->encoderName);

	if (vpu_encoder_init(enc, enc_dst) < 0)
		return -1;
	else
		return 0;
}