Please consider a donation to the Higher Intellect project. See https://preterhuman.net/donate.php or the Donate to Higher Intellect page for more info.

Testij.c

From Higher Intellect Vintage Wiki
Jump to navigation Jump to search
/*
   testij.c - test device-independent input jacks for VL
*/

#include "ij.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>

/* Utility Routines ---------------------------------------------------- */

void vlerror_exit(char *format, ...)
{
  va_list ap;
  
  va_start(ap, format);
  vfprintf( stderr, format, ap );
  va_end(ap);

  if (vlErrno != 0)
    fprintf( stderr, " (vlErrno=%s)", vlStrError(vlErrno) );

  fprintf( stderr, "\n" );
  exit(2);
}

/* main ------------------------------------------------------------- */

int trypath2(VLServer svr, IJhandle h, int idx, 
             int *ret_idx, int *ret_node_number,
             VLNode drain_node)
{
  int node_number = ijGetNodeNumber(h, idx);
  VLDev device = ijGetVLDev(h);
  VLNode source_node = vlGetNode(svr, VL_SRC, VL_VIDEO, node_number);
  VLPath path = vlCreatePath(svr, device, source_node, drain_node);

  if (node_number < 0 || source_node < 0 || path < 0) 
    return FALSE;
  
  if (vlSetupPaths(svr, (VLPathList)&path, 1, VL_SHARE, VL_SHARE) < 0)
    { vlDestroyPath(svr, path); return FALSE; }

  if (ijConfigurePath(h, idx, 
                      source_node, drain_node, path, 
                      node_number, ret_idx))
    { vlDestroyPath(svr, path); return FALSE; }
  
  if (ret_node_number) *ret_node_number = node_number;

  vlDestroyPath(svr, path);
  return TRUE;
}

int trypath(VLServer svr, IJhandle h, int idx, 
            VLNode drain_node)
{
  int ret_idx;
  int ret_node_number;

  if (!trypath2(svr, h, idx, &ret_idx, &ret_node_number, drain_node))
    {
      if (idx == VL_ANY)
        printf("XXX attempt to open default jack on device [%s] FAILED\n",
               ijGetDeviceName(h));
      else
        printf("XXX attempt to open jack %d on device [%s] FAILED\n",
               idx, ijGetDeviceName(h));
      return FALSE;
    }
  else
    {
      if (idx == VL_ANY)
        printf("    opening default jack ");
      else
        printf("    opening jack %d ", idx);
      printf(": idx=%d, node_number=%d\n",
             ret_idx, ret_node_number);
      return TRUE;
    }
}

void main(int argc, char **argv)
{
  int dv, j;
  VLDevList devlist;
  IJhandle h;
  VLServer vlServer;
  VLNode drain_node;

  if (NULL == (vlServer=vlOpenVideo("")))
    vlerror_exit("error opening video");
      
  if (vlGetDeviceList(vlServer, &devlist) < 0)
    vlerror_exit("error getting device list");
  
  printf("\n=== Printing VL names of devices:\n");

  for (dv=0; dv < (int)devlist.numDevices; dv++)
    printf("the device with VLDev %d is called [%s]\n",  
           devlist.devices[dv].dev,
           devlist.devices[dv].name);

  printf("\n=== Printing jacks for all devices:\n");

  {
    for (dv=0; dv < (int)devlist.numDevices; dv++)
      {
        VLDev dev = devlist.devices[dv].dev;
        
        printf("--- opening device with VLDev %d (%s)\n", dev, 
               devlist.devices[dv].name);
        if ((drain_node = vlGetNode(vlServer, VL_DRN, VL_MEM, VL_ANY)) < 0)
          vlerror_exit("error getting memory drain node");
        if (NULL == (h = ijOpenHandle(vlServer, dev, drain_node)))
          vlerror_exit("error opening specific ij handle");
        printf("--- this device is really: [%s]\n", ijGetDeviceName(h));
        assert(ijGetVLDev(h) == dev);
        
        for(j=0; j < ijGetNumJacks(h); j++)
          {
            printf("ij jack number %d is [%s]\n", j, ijGetJackName(h, j));
            trypath(vlServer, h, j, drain_node);
          }
        
        printf("ij default jack is:\n");
        trypath(vlServer, h, VL_ANY, drain_node);
        
        ijCloseHandle(h);
      }
  }
  
  printf("\n=== Finding the default device:\n");

  /* print default device */
  {
    if ((drain_node = vlGetNode(vlServer, VL_DRN, VL_MEM, VL_ANY)) < 0)
      vlerror_exit("error getting memory drain node");
    if (NULL == (h = ijOpenHandle(vlServer, VL_ANY, drain_node)))
      vlerror_exit("error opening VL_ANY ij handle");
    
    printf("The default device is VLDev %d ", ijGetVLDev(h));
    for (dv=0; dv < (int)devlist.numDevices; dv++)
      if (devlist.devices[dv].dev == ijGetVLDev(h))
        {
          printf("(%s)\n", devlist.devices[dv].name);
          break;
        }
    assert(dv != (int)devlist.numDevices);
    
    ijCloseHandle(h);
  }

  vlCloseVideo(vlServer);
}