gboolean
gst_edt_pdv_sink_start (GstBaseSink * basesink)
{
  GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink);

  GST_DEBUG_OBJECT (pdvsink, "Starting");

  pdvsink->dev = pdv_open_channel ("pdv", pdvsink->unit, pdvsink->channel);
  if (pdvsink->dev == NULL) {
    GST_ELEMENT_ERROR (pdvsink, RESOURCE, OPEN_WRITE,
        ("Unable to open unit %d, channel %d", pdvsink->unit, pdvsink->channel),
        (NULL));
    return FALSE;
  }

  if (!pdv_is_simulator (pdvsink->dev)) {
    GST_ELEMENT_ERROR (pdvsink, RESOURCE, OPEN_WRITE,
        ("EDT unit is not a simulator."), (NULL));
    pdv_close (pdvsink->dev);
  }

  /* FIXME: set timeout to wait forever, shouldn't do this of course */
  edt_set_wtimeout (pdvsink->dev, 0);
  edt_set_rtimeout (pdvsink->dev, 0);

  pdv_flush_fifo (pdvsink->dev);

  /* turn off counter data so we can DMA our own image data */
  pdv_cls_set_datacnt (pdvsink->dev, 0);

  pdvsink->cur_buffer = 0;

  return TRUE;
}
Beispiel #2
0
bool edt_server::open_and_find_parameters(void)
{
  char    errstr[256];
  char    *devname = EDT_INTERFACE;
  int	  unit = 0;
  int	  channel = 0;

  // Try to open the default device name and unit
  d_pdv_p = pdv_open_channel(devname, unit, channel);
  if (d_pdv_p == NULL) {
    fprintf(stderr,"edt_server::open_and_find_parameters: Could not open camera\n");
    sprintf(errstr, "pdv_open_channel(%s%d_%d)", devname, unit, channel);
    pdv_perror(errstr);
    return false;
  }

  // Check the parameters.
  if (pdv_get_depth((PdvDev*)d_pdv_p) != 8) {
    fprintf(stderr,"edt_server::open_and_find_parameters: Can only handle 8-bit cameras\n");
    pdv_close((PdvDev*)d_pdv_p);
    d_pdv_p = NULL;
    return false;
  }
  _num_columns = pdv_get_width((PdvDev*)d_pdv_p);
  _num_rows = pdv_get_height((PdvDev*)d_pdv_p);
  _minX = _minY = 0;
  _maxX = _num_columns-1;
  _maxY = _num_rows-1;
  _binning = 1;

  // Allocate space to swap a line from the buffer
  if ( (d_swap_buffer = new vrpn_uint8[_num_columns]) == NULL) {
    fprintf(stderr,"edt_server::open_and_find_parameters: Out of memory\n");
    pdv_close((PdvDev*)d_pdv_p);
    d_pdv_p = NULL;
    return false;
  }

  /*
   * allocate buffers for optimal pdv ring buffer pipeline (reduce if
   * memory is at a premium)
   */
  pdv_multibuf((PdvDev*)d_pdv_p, d_num_buffers);

  // Clear the timeouts value.
  d_first_timeouts = d_last_timeouts = pdv_timeouts((PdvDev*)d_pdv_p);

  /*
   * prestart the first image or images outside the loop to get the
   * pipeline going. Start multiple images unless force_single set in
   * config file, since some cameras (e.g. ones that need a gap between
   * images or that take a serial command to start every image) don't
   * tolerate queueing of multiple images
   */
  if (((PdvDev*)d_pdv_p)->dd_p->force_single) {
      d_started = 1;
      pdv_start_image((PdvDev*)d_pdv_p);
  } else {
      // Request as many images as buffers, so we are always trying to
      // fill all of them.  If we have gotten all we asked for, we
      // may have missed some.
      d_started = d_num_buffers;
      pdv_start_images((PdvDev*)d_pdv_p, d_started);
  }

  // Read one frame when we start.
  _status = true;
  if (read_image_to_memory()) {
    return true;
  } else {
    pdv_close((PdvDev*)d_pdv_p);
    d_pdv_p = NULL;
    fprintf(stderr, "edt_server::open_and_find_parameters: could not read image to memory\n");
    return false;
  }
}