GstCaps *
gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps)
{
  GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink);
  gint width, height, depth;
  GstVideoFormat format;
  GstVideoInfo vinfo;

  if (!pdvsink->dev) {
    return gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
            (pdvsink)));
  }

  gst_video_info_init (&vinfo);
  width = pdv_get_width (pdvsink->dev);
  height = pdv_get_height (pdvsink->dev);
  depth = pdv_get_depth (pdvsink->dev);

  switch (depth) {
    case 8:
      format = GST_VIDEO_FORMAT_GRAY8;
      break;
    case 16:
      /* TODO: will this be host order or always one of BE/LE? */
      format = GST_VIDEO_FORMAT_GRAY16_BE;
      break;
    default:
      format = GST_VIDEO_FORMAT_UNKNOWN;
  }
  gst_video_info_set_format (&vinfo, format, width, height);

  /* TODO: handle filter_caps */
  return gst_video_info_to_caps (&vinfo);
}
Exemple #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;
  }
}