bool udpipe_service::handle_rest_process(microrestd::rest_request& req) { string error; auto rest_id = get_rest_model_id(req); auto model = load_rest_model(rest_id, error); if (!model) return req.respond_error(error); auto& data = get_data(req, error); if (!error.empty()) return req.respond_error(error); bool tokenizer = false; unique_ptr<input_format> input(get_input_format(req, model, tokenizer, error)); if (!input) return req.respond_error(error); auto& tagger = get_tagger(req, model, error); if (!error.empty()) return req.respond_error(error); auto& parser = get_parser(req, model, error); if (!error.empty()) return req.respond_error(error); unique_ptr<output_format> output(get_output_format(req, error)); if (!output) return req.respond_error(error); // Try loading the input if tokenizer is not used if (!tokenizer) { input->set_text(data); sentence s; while (input->next_sentence(s, error)) {} if (!error.empty()) return req.respond_error(error.insert(0, "Cannot read input data: ").append("\n")); } input->set_text(data); class generator : public rest_response_generator { public: generator(const model_info* model, input_format* input, const string& tagger, const string& parser, output_format* output) : rest_response_generator(model), input(input), tagger(tagger), parser(parser), output(output) {} bool generate() { if (!input->next_sentence(s, error)) { output->finish_document(os); json.value(os.str(), true); os.str(string()); json.finish(true); return false; } if (tagger != "none") model->model->tag(s, tagger, error); if (parser != "none") model->model->parse(s, parser, error); output->write_sentence(s, os); json.value(os.str(), true); os.str(string()); return true; } private: sentence s; string error; ostringstream os; unique_ptr<input_format> input; const string& tagger; const string& parser; unique_ptr<output_format> output; }; return req.respond(generator::mime, new generator(model, input.release(), tagger, parser, output.release())); }
/*for decoder input processing 1. output window should 1:1 as source frame size 2. keep the frame ratio 3. input format should be YUV420 , output format should be YUV444 */ int vm_ge2d_pre_process(vframe_t* vf, ge2d_context_t *context,config_para_ex_t* ge2d_config) { int ret; int src_top ,src_left ,src_width, src_height; canvas_t cs0,cs1,cs2,cd; int current_mirror = camera_mirror_flag; display_frame_t input_frame={0}; ret = get_input_frame(&input_frame , vf); src_top = input_frame.content_top ; src_left = input_frame.content_left ; src_width = input_frame.content_width ; src_height = input_frame.content_height; if(test_zoom){ test_zoom = 0; printk("top is %d , left is %d , width is %d , height is %d\n",input_frame.content_top ,input_frame.content_left,input_frame.content_width,input_frame.content_height); } /* data operating. */ ge2d_config->alu_const_color= 0;//0x000000ff; ge2d_config->bitmask_en = 0; ge2d_config->src1_gb_alpha = 0;//0xff; ge2d_config->dst_xy_swap = 0; canvas_read(vf->canvas0Addr&0xff,&cs0); canvas_read((vf->canvas0Addr>>8)&0xff,&cs1); canvas_read((vf->canvas0Addr>>16)&0xff,&cs2); ge2d_config->src_planes[0].addr = cs0.addr; ge2d_config->src_planes[0].w = cs0.width; ge2d_config->src_planes[0].h = cs0.height; ge2d_config->src_planes[1].addr = cs1.addr; ge2d_config->src_planes[1].w = cs1.width; ge2d_config->src_planes[1].h = cs1.height; ge2d_config->src_planes[2].addr = cs2.addr; ge2d_config->src_planes[2].w = cs2.width; ge2d_config->src_planes[2].h = cs2.height; canvas_read(output_para.index&0xff,&cd); ge2d_config->dst_planes[0].addr = cd.addr; ge2d_config->dst_planes[0].w = cd.width; ge2d_config->dst_planes[0].h = cd.height; ge2d_config->src_key.key_enable = 0; ge2d_config->src_key.key_mask = 0; ge2d_config->src_key.key_mode = 0; ge2d_config->src_para.canvas_index=vf->canvas0Addr; ge2d_config->src_para.mem_type = CANVAS_TYPE_INVALID; ge2d_config->src_para.format = get_input_format(vf); ge2d_config->src_para.fill_color_en = 0; ge2d_config->src_para.fill_mode = 0; ge2d_config->src_para.x_rev = 0; ge2d_config->src_para.y_rev = 0; ge2d_config->src_para.color = 0xffffffff; ge2d_config->src_para.top = 0; ge2d_config->src_para.left = 0; ge2d_config->src_para.width = vf->width; ge2d_config->src_para.height = vf->height; // printk("vf_width is %d , vf_height is %d \n",vf->width ,vf->height); ge2d_config->src2_para.mem_type = CANVAS_TYPE_INVALID; ge2d_config->dst_para.canvas_index=output_para.index&0xff; ge2d_config->dst_para.mem_type = CANVAS_TYPE_INVALID; ge2d_config->dst_para.format = get_output_format(output_para.v4l2_format)|GE2D_LITTLE_ENDIAN; ge2d_config->dst_para.fill_color_en = 0; ge2d_config->dst_para.fill_mode = 0; ge2d_config->dst_para.x_rev = 0; ge2d_config->dst_para.y_rev = 0; ge2d_config->dst_para.color = 0; ge2d_config->dst_para.top = 0; ge2d_config->dst_para.left = 0; ge2d_config->dst_para.width = output_para.width; ge2d_config->dst_para.height = output_para.height; if(current_mirror==1){ ge2d_config->dst_para.x_rev = 1; ge2d_config->dst_para.y_rev = 0; }else if(current_mirror==2){ ge2d_config->dst_para.x_rev = 0; ge2d_config->dst_para.y_rev = 1; }else{ ge2d_config->dst_para.x_rev = 0; ge2d_config->dst_para.y_rev = 0; } // printk("output_width is %d , output_height is %d \n",output_para.width ,output_para.height); if(ge2d_context_config_ex(context,ge2d_config)<0) { printk("++ge2d configing error.\n"); return -1; } stretchblt_noalpha(context,src_left ,src_top ,src_width, src_height,0,0,output_para.width,output_para.height); /* for cr of yuv420p or yuv420sp. */ if(output_para.v4l2_format==V4L2_PIX_FMT_YUV420) { /* for cb. */ canvas_read((output_para.index>>8)&0xff,&cd); ge2d_config->dst_planes[0].addr = cd.addr; ge2d_config->dst_planes[0].w = cd.width; ge2d_config->dst_planes[0].h = cd.height; ge2d_config->dst_para.canvas_index=(output_para.index>>8)&0xff; ge2d_config->dst_para.format=GE2D_FORMAT_S8_CB|GE2D_LITTLE_ENDIAN; ge2d_config->dst_para.width = output_para.width/2; ge2d_config->dst_para.height = output_para.height/2; if(current_mirror==1){ ge2d_config->dst_para.x_rev = 1; ge2d_config->dst_para.y_rev = 0; }else if(current_mirror==2){ ge2d_config->dst_para.x_rev = 0; ge2d_config->dst_para.y_rev = 1; }else{ ge2d_config->dst_para.x_rev = 0; ge2d_config->dst_para.y_rev = 0; } if(ge2d_context_config_ex(context,ge2d_config)<0) { printk("++ge2d configing error.\n"); return -1; } stretchblt_noalpha(context,src_left ,src_top ,src_width, src_height,0,0,ge2d_config->dst_para.width,ge2d_config->dst_para.height); } else if (output_para.v4l2_format==V4L2_PIX_FMT_NV12||