Esempio n. 1
0
int
main(int argc, char **argv) {
	int ch;
	unsigned mode = SIO_PLAY | SIO_REC;
	struct sio_hdl *hdl;
	
	while ((ch = getopt(argc, argv, "pr")) != -1) {
		switch(ch) {
		case 'p':
			mode &= ~SIO_REC;
			break;
		case 'r':
			mode &= ~SIO_PLAY;
			break;
		default:
			usage();
			exit(1);
			break;
		}
	}
	if (mode == 0) {
		fprintf(stderr, "-p and -r flags are mutualy exclusive\n");
		exit(1);
	}
	hdl = sio_open(NULL, mode, 0);
	if (hdl == NULL) {
		fprintf(stderr, "sio_open() failed\n");
		exit(1);
	}
	if (!sio_getcap(hdl, &cap)) {
		fprintf(stderr, "sio_setcap() failed\n");
		exit(1);
	}
	cap_pr(&cap);
	sio_close(hdl);
	return 0;
}
Esempio n. 2
0
void CAESinkSNDIO::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
{
  struct sio_hdl *hdl;
  struct sio_cap cap;

  if ((hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0)) == nullptr)
  {
    CLog::Log(LOGERROR, "CAESinkSNDIO::EnumerateDevicesEx - sio_open");
    return;
  }

  if (!sio_getcap(hdl, &cap))
  {
    CLog::Log(LOGERROR, "CAESinkSNDIO::EnumerateDevicesEx - sio_getcap");
    return;
  }

  sio_close(hdl);
  hdl = nullptr;

  for (unsigned int i = 0; i < cap.nconf; i++)
  {
    CAEDeviceInfo info;
    sio_cap::sio_conf conf = cap.confs[i];

    info.m_deviceName = SIO_DEVANY;
    info.m_displayName = "sndio";
    info.m_displayNameExtra = "#" + std::to_string(i);
    info.m_deviceType = AE_DEVTYPE_PCM;
    info.m_wantsIECPassthrough = false;

    unsigned int maxchan = 0;
    for (unsigned int j = 0; j < SIO_NCHAN; j++)
    {
      if (conf.pchan & (1 << j))
        maxchan = MAX(maxchan, cap.pchan[j]);
    }

    maxchan = MIN(maxchan, nitems(channelMap));
    for (unsigned int j = 0; j < maxchan; j++)
      info.m_channels += channelMap[j];

    for (unsigned int j = 0; j < SIO_NRATE; j++)
    {
      if (conf.rate & (1 << j))
      {
        info.m_sampleRates.push_back(cap.rate[j]);
      }
    }

    for (unsigned int j = 0; j < SIO_NENC; j++)
    {
      if (conf.enc & (1 << j))
      {
        AEDataFormat format = lookupDataFormat(cap.enc[j].bits, cap.enc[j].bps, cap.enc[j].sig, cap.enc[j].le, cap.enc[j].msb);
        if (format != AE_FMT_INVALID)
          info.m_dataFormats.push_back(format);
      }
    }

    list.push_back(info);
  }
}
Esempio n. 3
0
gboolean
gst_sndio_open (struct gstsndio *sio, gint mode)
{
  GValue list = G_VALUE_INIT, item = G_VALUE_INIT;
  GstStructure *s;
  GstCaps *caps;
  struct sio_enc *enc;
  struct sio_cap cap;
  char fmt[16];
  int i, chan;

  GST_DEBUG_OBJECT (sio->obj, "open");

  sio->hdl = sio_open (sio->device, mode, 0);
  if (sio->hdl == NULL) {
    GST_ELEMENT_ERROR (sio->obj, RESOURCE, OPEN_READ_WRITE,
	("Couldn't open sndio device"), (NULL));
    return FALSE;
  }
  sio->mode = mode;

  if (!sio_getcap(sio->hdl, &cap)) {
    GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE,
	("Couldn't get device capabilities"), (NULL));
    sio_close(sio->hdl);
    sio->hdl = NULL;
    return FALSE;
  }
  if (cap.nconf == 0) {
    GST_ELEMENT_ERROR (sio, RESOURCE, OPEN_WRITE,
	("Device has empty capabilities"), (NULL));
    sio_close(sio->hdl);
    sio->hdl = NULL;
    return FALSE;
  }

  caps = gst_caps_new_empty ();
  s = gst_structure_new ("audio/x-raw", (char *)NULL, (void *)NULL);

  /*
   * scan supported rates
   */
  g_value_init (&list, GST_TYPE_LIST);
  g_value_init (&item, G_TYPE_INT);
  for (i = 0; i < SIO_NRATE; i++) {
      if ((cap.confs[0].rate & (1 << i)) == 0)
	  continue;
      g_value_set_int(&item, cap.rate[i]);
      gst_value_list_append_value (&list, &item);
  }
  gst_structure_set_value (s, "rate", &list);
  g_value_unset (&item);
  g_value_unset (&list);

  /*
   * scan supported channels
   */
  g_value_init (&list, GST_TYPE_LIST);
  g_value_init (&item, G_TYPE_INT);
  chan = (mode == SIO_PLAY) ? cap.confs[0].pchan : cap.confs[0].rchan;
  for (i = 0; i < SIO_NCHAN; i++) {
      if ((chan & (1 << i)) == 0)
	  continue;
      g_value_set_int(&item, (mode == SIO_PLAY) ? cap.pchan[i] : cap.rchan[i]);
      gst_value_list_append_value (&list, &item);
  }
  gst_structure_set_value (s, "channels", &list);
  g_value_unset (&item);
  g_value_unset (&list);

  /*
   * scan supported encodings
   */
  g_value_init (&list, GST_TYPE_LIST);
  g_value_init (&item, G_TYPE_STRING);
  for (i = 0; i < SIO_NENC; i++) {
      if ((cap.confs[0].enc & (1 << i)) == 0)
	  continue;
      enc = cap.enc + i;
      if (enc->bits % 8 != 0)
	  continue;
      if (enc->bits < enc->bps * 8 && enc->msb)
	  continue;
      if (enc->bits == enc->bps * 8) {
	  snprintf(fmt, sizeof(fmt), "%s%u%s",
		   enc->sig ? "S" : "U",
		   enc->bits,
		   enc->bps > 1 ? (enc->le ? "LE" : "BE") : "");
      } else {
	  snprintf(fmt, sizeof(fmt), "%s%u_%u%s",
		   enc->sig ? "S" : "U",
		   enc->bits,
		   enc->bps * 8,
		   enc->bps > 1 ? (enc->le ? "LE" : "BE") : "");
      }
      g_value_set_string(&item, fmt);
      gst_value_list_append_value (&list, &item);
  }
  gst_structure_set_value (s, "format", &list);
  g_value_unset (&item);
  g_value_unset (&list);

  /*
   * add the only supported layout: interleaved
   */
  g_value_init (&item, G_TYPE_STRING);
  g_value_set_string(&item, "interleaved");
  gst_structure_set_value (s, "layout", &item);
  g_value_unset (&item);

  gst_caps_append_structure (caps, s);
  sio->cur_caps = caps;
  fprintf(stderr, "caps are %s\n", gst_caps_to_string(caps));
  return TRUE;
}