Ejemplo n.º 1
0
static int cec_process_command_as(const char* data)
{
  if (strncmp(data, "as", 2) == 0)
  {
    g_iface.set_active_source(g_iface.connection, g_config.deviceTypes.types[0]);
    // wait for the source switch to finish for 15 seconds tops
    if (g_bSingleCommand)
    {
      int isactive = 0;
      int timeout = 15;
      while (timeout-- > 0)
      {
        isactive = g_iface.is_libcec_active_source(g_iface.connection);
        if (!isactive)
          sleep(1);
      }
    }
    return 1;
  }

  return 0;
}
Ejemplo n.º 2
0
void cec_init() {
  libcecc_reset_configuration(&g_config);
  g_config.clientVersion = LIBCEC_VERSION_CURRENT;
  g_config.bActivateSource = 0;
  g_callbacks.CBCecKeyPress = &on_cec_keypress;
  g_config.callbacks = &g_callbacks;
  snprintf(g_config.strDeviceName, sizeof(g_config.strDeviceName), "Moonlight");
  g_config.callbacks = &g_callbacks;
  g_config.deviceTypes.types[0] = CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
  
  if (libcecc_initialise(&g_config, &g_iface, NULL) != 1) {
    fprintf(stderr, "Failed to initialize libcec interface\n");
    fflush(stderr);
    return;
  }
  
  g_iface.init_video_standalone(g_iface.connection);
  
  cec_adapter devices[10];
  int8_t iDevicesFound = g_iface.find_adapters(g_iface.connection, devices, sizeof(devices) / sizeof(devices), NULL);
  
  if (iDevicesFound <= 0) {
    fprintf(stderr, "No CEC devices found\n");
    fflush(stderr);
    libcecc_destroy(&g_iface);
    return;
  }
  
  strcpy(g_strPort, devices[0].comm);
  if (!g_iface.open(g_iface.connection, g_strPort, 5000)) {
    fprintf(stderr, "Unable to open the device on port %s\n", g_strPort);
    fflush(stderr);
    libcecc_destroy(&g_iface);
    return;
  }
  
  g_iface.set_active_source(g_iface.connection, g_config.deviceTypes.types[0]);
}