Exemple #1
0
bool spawner_new_c::init_runner() {
    if (!parser.get_program().length()) {
        if (base_initialized) {
            return false;
        }
        base_options = options;
        base_restrictions = restrictions;
        base_initialized = true;
        return true;
        //throw exception
    }
    runner *secure_runner_instance;
    options.session << order++ << time(NULL) << runner::get_current_time();
    options.add_arguments(parser.get_program_arguments());
    if (options.login.length())
    {
        secure_runner_instance = new delegate_runner(parser.get_program(), options, restrictions);
    }
    else
    {
        secure_runner_instance = new secure_runner(parser.get_program(), options, restrictions);
    }

    {   //if (!options.session_id.length()) {
        std::shared_ptr<output_pipe_c> output = std::make_shared<output_pipe_c>();
        std::shared_ptr<output_pipe_c> error = std::make_shared<output_pipe_c>();
        std::shared_ptr<input_pipe_c> input = std::make_shared<input_pipe_c>();
        for (uint i = 0; i < options.stdoutput.size(); ++i) {
            std::shared_ptr<output_buffer_c> buffer = create_output_buffer(options.stdoutput[i], STD_OUTPUT_PIPE);
            if (buffer) {
                output->add_output_buffer(buffer);
            }
        }
        for (uint i = 0; i < options.stderror.size(); ++i) {
            std::shared_ptr<output_buffer_c> buffer = create_output_buffer(options.stderror[i], STD_ERROR_PIPE);
            if (buffer) {
                error->add_output_buffer(buffer);
            }
        }
        for (uint i = 0; i < options.stdinput.size(); ++i) {
            std::shared_ptr<input_buffer_c> buffer = create_input_buffer(options.stdinput[i]);
            if (buffer) {
                input->add_input_buffer(buffer);
            }
        }
        secure_runner_instance->set_pipe(STD_OUTPUT_PIPE, output);
        secure_runner_instance->set_pipe(STD_ERROR_PIPE, error);
        secure_runner_instance->set_pipe(STD_INPUT_PIPE, input);
    }
    runners.push_back(secure_runner_instance);
    return true;
}
static GstFlowReturn
gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
    GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
{
  GstMsdkVPP *thiz = GST_MSDKVPP (trans);

  if (gst_base_transform_is_passthrough (trans)) {
    *outbuf_ptr = inbuf;
    return GST_FLOW_OK;
  }

  *outbuf_ptr = create_output_buffer (thiz);
  return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
}
Exemple #3
0
void __TFWT2D_TransformerRep::initialize(long nirows, long nicols)
{
  // first release any existing buffers and reset to bare state
  // this accommodates repeated initialization
  discard();
 
  // record user spec'd image sizes for future implanting
  m_nucols = nicols;
  m_nurows = nirows;
  m_nucols2 = nicols/2; // cached value
  
  // adjust user image sizes to next power of two size
  // for internal buffer and FFT sizes
  m_nicols = next_pow2(nicols);
  m_nirows = next_pow2(nirows);
  
  m_nicols2 = m_nicols/2;  // cached value
  
  // compute the useful log2 quantities for FFT
  m_clog2 = ilog2(m_nicols);
  m_rlog2 = ilog2(m_nirows);

  // check size limitations
  if(m_rlog2 < 3 || m_clog2 < 3)
    throw("TFWT2D_Transformer: Image size too small (each axis must be >= 5)");

  if(m_rlog2 > 8)
    throw("TFWT2D_Transformer: Row Size must be 256 or smaller");

  // get the FFT twiddles for the larger dimension
  m_setup = create_fftsetup(max(m_rlog2, m_clog2), RADIX_2);
  if(0 == m_setup)
    throw("TFWT2D_Transformer: unable to construct FFT twiddle table");
  
  // allocate our carefully aligned buffers
  // use fftw_malloc to get favorable alignment
  long tsize  = m_nicols * m_nirows;
  m_tsize2    = tsize/2;
  m_pkrnlmask = (DSPComplex*)must_alloc_floats(tsize);
  m_pinpbuf   = must_alloc_floats(tsize);
  m_poutbuf   = (DSPComplex**)create_output_buffer(tsize);
  
  // zero out the input buffer for kernel implant
  // as long as image size boundaries are respected
  // there will be no further need to pre-zero this buffer
  erase_floats(m_pinpbuf, 0, tsize);
}
Exemple #4
0
 /**
  * It prepare the Pipeline skeleton for execution.
  *
  * \return TODO
  */
 inline int prepare() {
     // create input FFBUFFER
     int nstages=static_cast<int>(nodes_list.size());
     for(int i=1;i<nstages;++i) {
         if (nodes_list[i]->create_input_buffer(in_buffer_entries, fixedsize)<0) {
             error("PIPE, creating input buffer for node %d\n", i);
             return -1;
         }
     }
     
     // set output buffer
     for(int i=0;i<(nstages-1);++i) {
         if (nodes_list[i]->set_output_buffer(nodes_list[i+1]->get_in_buffer())<0) {
             error("PIPE, setting output buffer to node %d\n", i);
             return -1;
         }
     }
     
     // Preparation of buffers for the accelerator
     int ret = 0;
     if (has_input_channel) {
         if (create_input_buffer(in_buffer_entries, fixedsize)<0) {
             error("PIPE, creating input buffer for the accelerator\n");
             ret=-1;
         } else {             
             if (get_out_buffer()) {
                 error("PIPE, output buffer already present for the accelerator\n");
                 ret=-1;
             } else {
                 if (create_output_buffer(out_buffer_entries,fixedsize)<0) {
                     error("PIPE, creating output buffer for the accelerator\n");
                     ret = -1;
                 }
             }
         }
     }
     prepared=true; 
     return ret;
 }
static GstFlowReturn
gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
    GstBuffer * outbuf)
{
  GstMsdkVPP *thiz = GST_MSDKVPP (trans);
  GstClockTime timestamp;
  GstFlowReturn ret = GST_FLOW_OK;
  mfxSession session;
  mfxSyncPoint sync_point = NULL;
  mfxStatus status;
  MsdkSurface *in_surface = NULL;
  MsdkSurface *out_surface = NULL;

  timestamp = GST_BUFFER_TIMESTAMP (inbuf);

  in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
  if (!in_surface)
    return GST_FLOW_ERROR;

  if (gst_msdk_is_msdk_buffer (outbuf)) {
    out_surface = g_slice_new0 (MsdkSurface);
    out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
  } else {
    GST_ERROR ("Failed to get msdk outsurface!");
    return GST_FLOW_ERROR;
  }

  session = gst_msdk_context_get_session (thiz->context);

  /* outer loop is for handling FrameRate Control and deinterlace use cases */
  do {
    for (;;) {
      status =
          MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
          out_surface->surface, NULL, &sync_point);
      if (status != MFX_WRN_DEVICE_BUSY)
        break;
      /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
      g_usleep (1000);
    };

    if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
        && status != MFX_ERR_MORE_SURFACE)
      goto vpp_error;

    /* No output generated */
    if (status == MFX_ERR_MORE_DATA)
      goto error_more_data;

    if (sync_point)
      MFXVideoCORE_SyncOperation (session, sync_point, 10000);

    /* More than one output buffers are generated */
    if (status == MFX_ERR_MORE_SURFACE) {
      GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
      GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
      timestamp += thiz->buffer_duration;
      ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
      if (ret != GST_FLOW_OK)
        goto error_push_buffer;
      outbuf = create_output_buffer (thiz);
    } else {
      GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
      GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
    }
  } while (status == MFX_ERR_MORE_SURFACE);

  free_msdk_surface (in_surface);
  return ret;

vpp_error:
  GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
  free_msdk_surface (in_surface);
  free_msdk_surface (out_surface);
  return GST_FLOW_ERROR;

error_more_data:
  GST_WARNING_OBJECT (thiz,
      "MSDK Requries additional input for processing, "
      "Retruning FLOW_DROPPED since no output buffer was generated");
  free_msdk_surface (in_surface);
  return GST_BASE_TRANSFORM_FLOW_DROPPED;

error_push_buffer:
  {
    free_msdk_surface (in_surface);
    free_msdk_surface (out_surface);
    GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
        gst_flow_get_name (ret));
    return ret;
  }
}
static GstFlowReturn
gst_mfxpostproc_transform (GstBaseTransform * trans, GstBuffer * inbuf,
    GstBuffer * outbuf)
{
  GstMfxPostproc *const vpp = GST_MFXPOSTPROC (trans);
  GstMfxVideoMeta *inbuf_meta, *outbuf_meta;
  GstMfxSurface *surface, *out_surface;
  GstMfxFilterStatus status = GST_MFX_FILTER_STATUS_SUCCESS;
  GstFlowReturn ret = GST_FLOW_OK;
  GstBuffer *buf = NULL;
  GstMfxRectangle *crop_rect = NULL;
  GstClockTime timestamp;

  timestamp = GST_BUFFER_TIMESTAMP (inbuf);

  ret = gst_mfx_plugin_base_get_input_buffer (GST_MFX_PLUGIN_BASE (vpp),
          inbuf, &buf);
  if (GST_FLOW_OK != ret)
    return ret;

  inbuf_meta = gst_buffer_get_mfx_video_meta (buf);
  surface = gst_mfx_video_meta_get_surface (inbuf_meta);
  if (!surface)
    goto error_create_surface;

  do {
    if (vpp->flags & GST_MFX_POSTPROC_FLAG_FRC) {
      if (GST_MFX_FILTER_STATUS_ERROR_MORE_SURFACE != status)
        gst_buffer_replace (&buf, NULL);
      buf = create_output_buffer (vpp);
      if (!buf)
        goto error_create_buffer;
    }

    status = gst_mfx_filter_process (vpp->filter, surface, &out_surface);
    if (GST_MFX_FILTER_STATUS_SUCCESS != status
        && GST_MFX_FILTER_STATUS_ERROR_MORE_SURFACE != status
        && GST_MFX_FILTER_STATUS_ERROR_MORE_DATA != status)
      goto error_process_vpp;

    if (GST_MFX_FILTER_STATUS_ERROR_MORE_SURFACE == status)
      outbuf_meta = gst_buffer_get_mfx_video_meta (buf);
    else
      outbuf_meta = gst_buffer_get_mfx_video_meta (outbuf);

    if (!outbuf_meta)
      goto error_create_meta;

    gst_mfx_video_meta_set_surface (outbuf_meta, out_surface);
    crop_rect = gst_mfx_surface_get_crop_rect (out_surface);
    if (crop_rect) {
      GstVideoCropMeta *const crop_meta =
          gst_buffer_add_video_crop_meta (outbuf);
      if (crop_meta) {
        crop_meta->x = crop_rect->x;
        crop_meta->y = crop_rect->y;
        crop_meta->width = crop_rect->width;
        crop_meta->height = crop_rect->height;
      }
    }

    if (GST_MFX_FILTER_STATUS_ERROR_MORE_DATA == status) {
      gst_buffer_unref (buf);
      return GST_BASE_TRANSFORM_FLOW_DROPPED;
    }

    if (GST_MFX_FILTER_STATUS_ERROR_MORE_SURFACE == status) {
      GST_BUFFER_TIMESTAMP (buf) = timestamp;
      GST_BUFFER_DURATION (buf) = vpp->field_duration;
      timestamp += vpp->field_duration;
      ret = gst_pad_push (trans->srcpad, buf);
    }
    else {
      if (vpp->flags & GST_MFX_POSTPROC_FLAG_FRC) {
        GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
        GST_BUFFER_DURATION (outbuf) = vpp->field_duration;
      }
      else {
        gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
      }
    }
  } while (GST_MFX_FILTER_STATUS_ERROR_MORE_SURFACE == status
           && GST_FLOW_OK == ret);

  gst_mfx_surface_dequeue(surface);

#if GST_CHECK_VERSION(1,8,0)
  gst_mfx_plugin_base_export_dma_buffer (GST_MFX_PLUGIN_BASE (vpp), outbuf);
#endif // GST_CHECK_VERSION

  gst_buffer_unref (buf);
  return ret;
  /* ERRORS */
error_create_buffer:
  {
    GST_ERROR ("failed to output buffer");
    gst_buffer_unref (buf);
    return GST_FLOW_ERROR;
  }
error_create_meta:
  {
    GST_ERROR ("failed to create new output buffer meta");
    gst_buffer_unref (buf);
    return GST_FLOW_ERROR;
  }
error_create_surface:
  {
    GST_ERROR ("failed to create surface surface from buffer");
    gst_buffer_unref (buf);
    return GST_FLOW_ERROR;
  }
error_process_vpp:
  {
    GST_ERROR ("failed to apply VPP (error %d)", status);
    gst_buffer_unref (buf);
    return GST_FLOW_ERROR;
  }
}
Exemple #7
0
int main(int argc, char *argv[]){
	Spawn *player;
	InterfaceData idata = {0, NULL, -1, NULL, 1};
	SDL_Event event;
	int num_tiles = OUTPUT_IN_GLYPHS_X * OUTPUT_IN_GLYPHS_Y, i;
	
	/*SDL anmachen*/
    if(SDL_Init(SDL_INIT_VIDEO))
        return EXIT_FAILURE;
    SDL_EnableKeyRepeat(200, 50);
    
    /*Karte laden*/
    if(argc==2)
        map=load_map(argv[1]);
    else{
        fprintf(stderr,"Kartennamen angeben\n");
        return EXIT_FAILURE;
    }
    if(map == NULL) {
        fprintf(stderr,"Fehler beim Laden der Karte\n");
        return EXIT_FAILURE;
    }
    
    player = get_player_spawn(map);
    if(player==NULL){
        fprintf(stderr, "Kein Spieler auf der Karte\n");
        return EXIT_FAILURE;
    }
    
    /*Map zeichnen*/
    
    /* Ausgabepuffer initialisieren */
    buf = (BufferTile*)ex_malloc(sizeof(BufferTile) * num_tiles);
    for(i = 0; i < num_tiles; ++i) {
        BufferTile bt = {' ', 0x00000000};
        buf[i] = bt;
    }
    
    output_init(OUTPUT_IN_GLYPHS_X, OUTPUT_IN_GLYPHS_Y, map->name);
    
    explore_area(player, map);
    create_output_buffer(map, buf, num_tiles);
    get_interface_data(map, &idata);
    output_draw(buf, num_tiles, &idata);
    
    /*Eingabeloop*/
    int quit=0;
    KeyAction current_action = INVALID;
    while(SDL_WaitEvent(&event)){
        if(event.type == SDL_KEYDOWN) {
            current_action = get_action(event.key.keysym.sym);
            /*bei Escape beenden*/
            if(event.key.keysym.sym == SDLK_ESCAPE){
                quit=1;
                break;
            }
            if(current_action != INVALID) {
                process_event(current_action, map);
            }
            create_output_buffer(map, buf, num_tiles);
            get_interface_data(map, &idata);
            output_draw(buf, num_tiles, &idata);
        } else if(event.type == SDL_QUIT) {
            quit=1;
            break;
        }
        SDL_Delay(1);
        /*Affe tot => Klappe zu*/
        if(player->hp<=0){
            game_over(0);
            break;
        }
        /* Ende erreicht */
        if(map->finished) {
            game_over(1);
            break;
        }
    }
    if(!quit){
        while(SDL_WaitEvent(&event)){
            /*bei Escape beenden*/
            if(event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) {
                break;
            }
            SDL_Delay(1);
        }
    }
    free(buf);
    flush_map(map);
    free(idata.message); free(idata.item_name);
    
    output_close();
    SDL_Quit();
    return EXIT_SUCCESS;
}