Example #1
0
uint16_t service_usage_query_group (enum einit_usage_query task, const struct lmodule *module, const char *service) {
 uint16_t ret = 0;
 struct stree *ha;

 if (!service) return 0;

 emutex_lock (&service_usage_mutex);
 if (task & service_add_group_provider) {
  if (!module || !module->module) {
   emutex_unlock (&service_usage_mutex);

   return 0;
  }

  if (!service_usage || !(ha = streefind (service_usage, service, tree_find_first))) {
   struct service_usage_item nitem;
   memset (&nitem, 0, sizeof (struct service_usage_item));
   nitem.provider = (struct lmodule **)setadd ((void **)nitem.provider, (void *)module, SET_NOALLOC);
   service_usage = streeadd (service_usage, service, &nitem, sizeof (struct service_usage_item), NULL);
  } else {
   struct service_usage_item *citem = (struct service_usage_item *)ha->value;

   if (citem) {
    if (!inset ((const void **)citem->provider, (void *)module, SET_NOALLOC)) {
     citem->provider = (struct lmodule **)setadd ((void **)citem->provider, (void *)module, SET_NOALLOC);
    }
   }
  }
 }
 if (task & service_set_group_providers) {
  if (!service_usage || !(ha = streefind (service_usage, service, tree_find_first))) {
   struct service_usage_item nitem;
   memset (&nitem, 0, sizeof (struct service_usage_item));
   nitem.provider = (struct lmodule **)setdup ((const void **)module, SET_NOALLOC);
   service_usage = streeadd (service_usage, service, &nitem, sizeof (struct service_usage_item), NULL);
  } else {
   struct service_usage_item *citem = (struct service_usage_item *)ha->value;

   if (citem) {
    free (citem->provider);
    citem->provider = (struct lmodule **)setdup ((const void **)module, SET_NOALLOC);
   }
  }
 }

 emutex_unlock (&service_usage_mutex);
 return ret;
}
Example #2
0
/**
 * @brief Convert a Windows style path to a file name into an Unix style one.
 *
 * @param filename pointer to the file path to be converted
 *
 * @return pointer to the converted file path
 */
static char *unix_name (char *filename)
{
    static char *unix_filename;
    LPSTR (*CDECL wine_get_unix_file_name_ptr)(LPCWSTR);
    int wchar_conv;

    if (*filename && (filename[1] == ':'))
    {
        wine_get_unix_file_name_ptr = (void *) GetProcAddress(GetModuleHandleA("KERNEL32"), "wine_get_unix_file_name");
        wchar_conv = MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, NULL, 0);

        if (wine_get_unix_file_name_ptr && wchar_conv)
        {
            WCHAR *ntpath;
            char *unix_name;

            ntpath = HeapAlloc(GetProcessHeap(), 0, sizeof(*ntpath) * (wchar_conv + 1));
            MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, ntpath, wchar_conv);
            unix_name = wine_get_unix_file_name_ptr(ntpath);
            setdup(&unix_filename, unix_name);
            filename = unix_filename;
            HeapFree(GetProcessHeap(), 0, unix_name);
            HeapFree(GetProcessHeap(), 0, ntpath);
        }
    }

    return filename;
}
Example #3
0
/**
 * @brief Set the file to be played.
 *
 * @param dir directory (optional, else NULL)
 * @param name filename
 * @param type stream type of the file
 *
 * @note All #guiInfo members associated with the file will be cleared.
 */
void uiSetFile(const char *dir, const char *name, int type)
{
    if (!dir)
        setdup(&guiInfo.Filename, name);
    else
        setddup(&guiInfo.Filename, dir, name);

    filename = guiInfo.Filename;

    if (type != SAME_STREAMTYPE) {
        guiInfo.StreamType = type;
        uiUnsetMedia(False);
    }
}
Example #4
0
struct lmodule *mod_add (void *sohandle, const struct smodule *module) {
 struct lmodule *nmod;

 nmod = ecalloc (1, sizeof (struct lmodule));

 emutex_lock (&mlist_mutex);
 nmod->next = mlist;
 mlist = nmod;
 emutex_unlock (&mlist_mutex);

 nmod->sohandle = sohandle;
 nmod->module = module;
 emutex_init (&nmod->mutex, NULL);
 emutex_init (&nmod->imutex, NULL);

 if (module->si.provides || module->si.requires || module->si.after || module->si.before) {
  nmod->si = ecalloc (1, sizeof (struct service_information));

  if (module->si.provides)
   nmod->si->provides = (char **)setdup((const void **)module->si.provides, SET_TYPE_STRING);
  if (module->si.requires)
   nmod->si->requires = (char **)setdup((const void **)module->si.requires, SET_TYPE_STRING);
  if (module->si.after)
   nmod->si->after = (char **)setdup((const void **)module->si.after, SET_TYPE_STRING);
  if (module->si.before)
   nmod->si->before = (char **)setdup((const void **)module->si.before, SET_TYPE_STRING);
 } else
  nmod->si = NULL;


 if (module->configure) module->configure (nmod);
 if (nmod->scanmodules) nmod->scanmodules(mlist);

 nmod = mod_update (nmod);

 return nmod;
}
Example #5
0
/**
 * @brief Convert a Windows style device name into an Unix style one.
 *
 * @param device pointer to the device name to be converted
 *
 * @return pointer to the converted device name
 */
static char *unix_device (char *device)
{
    static char *unix_devname;
    HANDLE mgr;
    DWORD size = 1024;

    mgr = CreateFileW(MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);

    if (mgr != INVALID_HANDLE_VALUE)
    {
        struct mountmgr_unix_drive input;
        struct mountmgr_unix_drive *data;

        data = HeapAlloc(GetProcessHeap(), 0, size);

        if (data)
        {
            memset(&input, 0, sizeof(input));
            input.letter = *device;

            if (DeviceIoControl(mgr, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE, &input, sizeof(input), data, size, NULL, NULL))
            {
                if (data->device_offset)
                {
                    setdup(&unix_devname, (char *) data + data->device_offset);
                    device = unix_devname;
                }
            }

            HeapFree(GetProcessHeap(), 0, data);
        }

        CloseHandle(mgr);
    }

    return device;
}
Example #6
0
void uiSetFileName(char *dir, char *name, int type)
{
    if(!name) return;
    if(!dir)
        setdup(&guiInfo.Filename, name);
    else
        setddup(&guiInfo.Filename, dir, name);

    filename = guiInfo.Filename;
#ifdef __WINE__
    // When the GUI receives the files to be played in guiPlaylistInitialize()
    // and guiPlaylistAdd(), it calls import_file_into_gui() where the call of
    // Wine's GetFullPathName() converts each file name into the Windows style
    // (C:\path\to\file), which needs to be reconverted for MPlayer, so that
    // it will find the filename in the Linux filesystem.
    filename = unix_name(filename);
#endif

    if (type != SAME_STREAMTYPE)
        guiInfo.StreamType = type;

    nfree(guiInfo.AudioFilename);
    nfree(guiInfo.SubtitleFilename);
}
Example #7
0
int main(int argc, char **argv, char **environ) {
#else
int main(int argc, char **argv) {
#endif
 int i, ret = EXIT_SUCCESS;
 pid_t pid = getpid(), wpid = 0;
 char **ipccommands = NULL;
 int pthread_errno;
 FILE *commandpipe_in, *commandpipe_out;
 int commandpipe[2];
 int debugsocket[2];
 char need_recovery = 0;
 char debug = 0;
 int debugme_pipe = 0;
 char crash_threshold = 5;
 char *einit_crash_data = NULL;

 boottime = time(NULL);

 uname (&osinfo);
 config_configure();

// initialise subsystems
 ipc_configure(NULL);

// is this the system's init-process?
 isinit = getpid() == 1;

 event_listen (einit_event_subsystem_core, core_einit_event_handler);
 event_listen (einit_event_subsystem_timer, core_timer_event_handler);

 if (argv) einit_argv = (char **)setdup ((const void **)argv, SET_TYPE_STRING);

/* check command line arguments */
 for (i = 1; i < argc; i++) {
  if (argv[i][0] == '-')
   switch (argv[i][1]) {
    case 'c':
     if ((++i) < argc)
      einit_default_startup_configuration_files[0] = argv[i];
     else
      return print_usage_info ();
     break;
    case 'h':
     return print_usage_info ();
     break;
    case 'v':
     eputs("eINIT " EINIT_VERSION_LITERAL "\n", stdout);
     return 0;
    case 'L':
     eputs("eINIT " EINIT_VERSION_LITERAL
          "\nThis Program is Free Software, released under the terms of this (BSD) License:\n"
          "--------------------------------------------------------------------------------\n"
          "Copyright (c) 2006, 2007, Magnus Deininger\n"
          BSDLICENSE "\n", stdout);
     return 0;
    case '-':
     if (strmatch(argv[i], "--check-configuration") || strmatch(argv[i], "--checkup") || strmatch(argv[i], "--wtf")) {
      ipccommands = (char **)setadd ((void **)ipccommands, "examine configuration", SET_TYPE_STRING);
     } else if (strmatch(argv[i], "--help"))
      return print_usage_info ();
     else if (strmatch(argv[i], "--ipc-command") && argv[i+1])
      ipccommands = (char **)setadd ((void **)ipccommands, (void *)argv[i+1], SET_TYPE_STRING);
     else if (strmatch(argv[i], "--override-init-check"))
      initoverride = 1;
     else if (strmatch(argv[i], "--sandbox")) {
      einit_default_startup_configuration_files[0] = "lib/einit/einit.xml";
      coremode = einit_mode_sandbox;
      need_recovery = 1;
     } else if (strmatch(argv[i], "--metadaemon")) {
      coremode = einit_mode_metadaemon;
     } else if (strmatch(argv[i], "--bootstrap-modules")) {
      bootstrapmodulepath = argv[i+1];
     } else if (strmatch(argv[i], "--debugme")) {
      debugme_pipe = parse_integer (argv[i+1]);
      i++;
      initoverride = 1;
     } else if (strmatch(argv[i], "--debug")) {
      debug = 1;
     }

     break;
   }
 }

/* check environment */
 if (environ) {
  uint32_t e = 0;
  for (e = 0; environ[e]; e++) {
   char *ed = estrdup (environ[e]);
   char *lp = strchr (ed, '=');

   *lp = 0;
   lp++;

   if (strmatch (ed, "softlevel")) {
    einit_startup_mode_switches = str2set (':', lp);
   } if (strmatch (ed, "mode")) {
/* override default mode-switches with the ones in the environment variable mode= */
    einit_startup_mode_switches = str2set (':', lp);
   } else if (strmatch (ed, "einit")) {
/* override default configuration files and/or mode-switches with the ones in the variable einit= */
    char **tmpstrset = str2set (',', lp);
    uint32_t rx = 0;

    for (rx = 0; tmpstrset[rx]; rx++) {
     char **atom = str2set (':', tmpstrset[rx]);

     if (strmatch (atom[0], "file")) {
/* specify configuration files */
      einit_startup_configuration_files = (char **)setdup ((const void **)atom, SET_TYPE_STRING);
      einit_startup_configuration_files = (char **)strsetdel (einit_startup_configuration_files, (void *)"file");
     } else if (strmatch (atom[0], "mode")) {
/* specify mode-switches */
      einit_startup_mode_switches = (char **)setdup ((const void **)atom, SET_TYPE_STRING);
      einit_startup_mode_switches = (char **)strsetdel (einit_startup_mode_switches, (void *)"mode");
     } else if (strmatch (atom[0], "stfu")) {
      einit_quietness = 3;
     } else if (strmatch (atom[0], "silent")) {
      einit_quietness = 2;
     } else if (strmatch (atom[0], "quiet")) {
      einit_quietness = 1;
     }

     free (atom);
    }

    free (tmpstrset);
   }

   free (ed);
  }

  einit_initial_environment = (char **)setdup ((const void **)environ, SET_TYPE_STRING);
 }

 if (!einit_startup_mode_switches) einit_startup_mode_switches = einit_default_startup_mode_switches;
 if (!einit_startup_configuration_files) einit_startup_configuration_files = einit_default_startup_configuration_files;

 respawn:

 pipe (commandpipe);

 fcntl (commandpipe[1], F_SETFD, FD_CLOEXEC);

 socketpair (AF_UNIX, SOCK_STREAM, 0, debugsocket);
 fcntl (debugsocket[0], F_SETFD, FD_CLOEXEC);
 fcntl (debugsocket[1], F_SETFD, FD_CLOEXEC);

 if (!debug) {
  fcntl (commandpipe[0], F_SETFD, FD_CLOEXEC);
  commandpipe_in = fdopen (commandpipe[0], "r");
 }
 commandpipe_out = fdopen (commandpipe[1], "w");

 if (!initoverride && ((pid == 1) || ((coremode & einit_mode_sandbox) && !ipccommands))) {
// if (pid == 1) {
  initoverride = 1;
#if 0
#ifdef LINUX
  if ((einit_sub = syscall(__NR_clone, CLONE_PTRACE | SIGCHLD, 0, NULL, NULL, NULL)) < 0) {
   bitch (bitch_stdio, errno, "Could not fork()");
   eputs (" !! Haven't been able to fork a secondary worker process. This is VERY bad, you will get a lot of zombie processes! (provided that things work at all)\n", stderr);
  }
#else
#endif
#endif
  if ((einit_sub = fork()) < 0) {
   bitch (bitch_stdio, errno, "Could not fork()");
   eputs (" !! Haven't been able to fork a secondary worker process. This is VERY bad, you will get a lot of zombie processes! (provided that things work at all)\n", stderr);
  }
 }

 if (einit_sub) {
/* PID==1 part */
  int rstatus;
  struct sigaction action;

/* signal handlers */
  action.sa_sigaction = einit_sigint;
  sigemptyset(&(action.sa_mask));
  action.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
  if ( sigaction (SIGINT, &action, NULL) ) bitch (bitch_stdio, 0, "calling sigaction() failed.");

/* ignore sigpipe */
  action.sa_sigaction = (void (*)(int, siginfo_t *, void *))SIG_IGN;

  if ( sigaction (SIGPIPE, &action, NULL) ) bitch (bitch_stdio, 0, "calling sigaction() failed.");

  close (debugsocket[1]);
  if (einit_crash_data) {
   free (einit_crash_data);
   einit_crash_data = NULL;
  }

  while (1) {
   wpid = waitpid(-1, &rstatus, 0); /* this ought to wait for ANY process */

   if (wpid == einit_sub) {
//    goto respawn; /* try to recover by re-booting */
    if (!debug) if (commandpipe_in) fclose (commandpipe_in);
    if (commandpipe_out) fclose (commandpipe_out);

    if (WIFEXITED(rstatus) && (WEXITSTATUS(rstatus) != einit_exit_status_die_respawn)) {
     fprintf (stderr, "eINIT has quit properly.\n");

     if (!(coremode & einit_mode_sandbox)) {
      if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_halt) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "h", NULL);
      } else if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_reboot) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "r", NULL);
      } else if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_kexec) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "k", NULL);
      }
     }

     exit (EXIT_SUCCESS);
    }

    int n = 5;
    fprintf (stderr, "The secondary eINIT process has died, waiting a while before respawning.\n");
    if ((einit_crash_data = readfd (debugsocket[0]))) {
     fprintf (stderr, " > neat, received crash data\n");
    }
    while ((n = sleep (n)));
    fprintf (stderr, "Respawning secondary eINIT process.\n");

    if (crash_threshold) crash_threshold--;
    else debug = 1;
    need_recovery = 1;
    initoverride = 0;

    close (debugsocket[0]);

    goto respawn;
   } else {
    if (commandpipe_out) {
     if (WIFEXITED(rstatus)) {
      fprintf (commandpipe_out, "pid %i terminated\n\n", wpid);
     } else {
      fprintf (commandpipe_out, "pid %i died\n\n", wpid);
     }
     fflush (commandpipe_out);
    }
   }
  }
 } else {
  enable_core_dumps ();

  close (debugsocket[0]);
  sched_trace_target = debugsocket[1];

  if (debug) {
   char **xargv = (char **)setdup ((const void **)argv, SET_TYPE_STRING);
   char tbuffer[BUFFERSIZE];
   struct stat st;
   char have_valgrind = 0;
   char have_gdb = 0;

   fputs ("eINIT needs to be debugged, starting in debugger mode\n.", stderr);

   xargv = (char **)setadd ((void **)xargv, (void *)"--debugme", SET_TYPE_STRING);
   snprintf (tbuffer, BUFFERSIZE, "%i", commandpipe[0]);
   xargv = (char **)setadd ((void **)xargv, (void *)tbuffer, SET_TYPE_STRING);

   xargv = strsetdel (xargv, "--debug"); // don't keep the --debug flag

   if (!stat ("/usr/bin/valgrind", &st)) have_valgrind = 1;
   if (!stat ("/usr/bin/gdb", &st)) have_gdb = 1;

   if (have_valgrind) {
    char **nargv = NULL;
    uint32_t i = 1;

#ifdef LINUX
    if (!(coremode & einit_mode_sandbox)) {
     mount ("proc", "/proc", "proc", 0, NULL);
     mount ("sys", "/sys", "sysfs", 0, NULL);

     system ("mount / -o remount,rw");
    }
#endif

    nargv = (char **)setadd ((void **)nargv, "/usr/bin/valgrind", SET_TYPE_STRING);
    nargv = (char **)setadd ((void **)nargv, "--log-file=/einit.valgrind", SET_TYPE_STRING);
    nargv = (char **)setadd ((void **)nargv, (coremode & einit_mode_sandbox) ? "sbin/einit" : "/sbin/einit", SET_TYPE_STRING);

    for (; xargv[i]; i++) {
     nargv = (char **)setadd ((void **)nargv, xargv[i], SET_TYPE_STRING);
    }

    execv ("/usr/bin/valgrind", nargv);
   } else {
    execv ((coremode & einit_mode_sandbox) ? "sbin/einit" : "/sbin/einit", xargv);
   }
  }

  if (debugme_pipe) { // commandpipe[0]
   fcntl (commandpipe[0], F_SETFD, FD_CLOEXEC);
   commandpipe_in = fdopen (debugme_pipe, "r");
  }

/* actual system initialisation */
  struct einit_event cev = evstaticinit(einit_core_update_configuration);

  if (ipccommands && (coremode != einit_mode_sandbox)) {
   coremode = einit_mode_ipconly;
  }

  eprintf (stderr, "eINIT " EINIT_VERSION_LITERAL ": Initialising: %s\n", osinfo.sysname);

  if ((pthread_errno = pthread_attr_init (&thread_attribute_detached))) {
   bitch(bitch_epthreads, pthread_errno, "pthread_attr_init() failed.");

   if (einit_initial_environment) free (einit_initial_environment);
   return -1;
  } else {
   if ((pthread_errno = pthread_attr_setdetachstate (&thread_attribute_detached, PTHREAD_CREATE_DETACHED))) {
    bitch(bitch_epthreads, pthread_errno, "pthread_attr_setdetachstate() failed.");
   }
  }

  if ((pthread_errno = pthread_key_create(&einit_function_macro_key, NULL))) {
   bitch(bitch_epthreads, pthread_errno, "pthread_key_create(einit_function_macro_key) failed.");

   if (einit_initial_environment) free (einit_initial_environment);
   return -1;
  }

/* this should be a good place to initialise internal modules */
   if (coremodules) {
    uint32_t cp = 0;

    eputs (" >> initialising in-core modules:", stderr);

    for (; coremodules[cp]; cp++) {
     struct lmodule *lmm;
     eprintf (stderr, " [%s]", (*coremodules[cp])->rid);
     lmm = mod_add(NULL, (*coremodules[cp]));

     lmm->source = estrdup("core");
    }

    eputs (" OK\n", stderr);
   }

/* emit events to read configuration files */
  if (einit_startup_configuration_files) {
   uint32_t rx = 0;
   for (; einit_startup_configuration_files[rx]; rx++) {
    cev.string = einit_startup_configuration_files[rx];
    event_emit (&cev, einit_event_flag_broadcast);
   }

   if (einit_startup_configuration_files != einit_default_startup_configuration_files) {
    free (einit_startup_configuration_files);
   }
  }

  cev.string = NULL;
  cev.type = einit_core_configuration_update;

// make sure we keep updating until everything is sorted out
  while (cev.type == einit_core_configuration_update) {
//   notice (2, "stuff changed, updating configuration.");

   cev.type = einit_core_update_configuration;
   event_emit (&cev, einit_event_flag_broadcast);
  }
  evstaticdestroy(cev);

  if (ipccommands) {
   uint32_t rx = 0;
   for (; ipccommands[rx]; rx++) {
    ret = ipc_process (ipccommands[rx], stdout);
   }

//   if (gmode == EINIT_GMODE_SANDBOX)
//    cleanup ();

   free (ipccommands);
   if (einit_initial_environment) free (einit_initial_environment);
   return ret;
  } else if ((coremode == einit_mode_init) && !isinit && !initoverride) {
   eputs ("WARNING: eINIT is configured to run as init, but is not the init-process (pid=1) and the --override-init-check flag was not specified.\nexiting...\n\n", stderr);
   exit (EXIT_FAILURE);
  } else {
/* actual init code */
   uint32_t e = 0;

   nice (einit_core_niceness_increment);

   if (need_recovery) {
    notice (1, "need to recover from something...");

    struct einit_event eml = evstaticinit(einit_core_recover);
    event_emit (&eml, einit_event_flag_broadcast);
    evstaticdestroy(eml);
   }

   if (einit_crash_data) {
    notice (1, "submitting crash data...");

    struct einit_event eml = evstaticinit(einit_core_crash_data);
    eml.string = einit_crash_data;
    event_emit (&eml, einit_event_flag_broadcast);
    evstaticdestroy(eml);

    free (einit_crash_data);
    einit_crash_data = NULL;
   }

   {
    notice (3, "running early bootup code...");

    struct einit_event eml = evstaticinit(einit_boot_early);
    event_emit (&eml, einit_event_flag_broadcast | einit_event_flag_spawn_thread_multi_wait);
    evstaticdestroy(eml);
   }

   notice (2, "scheduling startup switches.\n");

   for (e = 0; einit_startup_mode_switches[e]; e++) {
    struct einit_event ee = evstaticinit(einit_core_switch_mode);

    ee.string = einit_startup_mode_switches[e];
    event_emit (&ee, einit_event_flag_broadcast | einit_event_flag_spawn_thread | einit_event_flag_duplicate);
    evstaticdestroy(ee);
   }

   struct einit_event eml = evstaticinit(einit_core_main_loop_reached);
   eml.file = commandpipe_in;
   event_emit (&eml, einit_event_flag_broadcast);
   evstaticdestroy(eml);
  }

  if (einit_initial_environment) free (einit_initial_environment);
  return ret;
 }

/* this should never be reached... */
 if (einit_initial_environment) free (einit_initial_environment);
 return 0;
}
Example #8
0
/**
 * @brief Initialize and start the GUI.
 */
void guiInit(void)
{
    char **argvf;
    int ret;
    plItem *playlist;

    mp_msg(MSGT_GPLAYER, MSGL_V, "GUI init.\n");

    /* check options */

    if (!cdrom_device)
        cdrom_device = strdup(DEFAULT_CDROM_DEVICE);
    if (!dvd_device)
        dvd_device = strdup(DEFAULT_DVD_DEVICE);
#ifdef CONFIG_DXR3
    if (!gtkDXR3Device)
        gtkDXR3Device = strdup("/dev/em8300-0");
#endif

    if (stream_cache_size > 0) {
        gtkCacheOn   = True;
        gtkCacheSize = stream_cache_size;
    } else if (stream_cache_size == 0)
        gtkCacheOn = False;

    if (autosync && (autosync != gtkAutoSync)) {
        gtkAutoSyncOn = True;
        gtkAutoSync   = autosync;
    }

    gtkASS.enabled       = ass_enabled;
    gtkASS.use_margins   = ass_use_margins;
    gtkASS.top_margin    = ass_top_margin;
    gtkASS.bottom_margin = ass_bottom_margin;

    argvf = get_vf("rotate");
    guiInfo.Rotation = (argvf && argvf[1] ? atoi(argvf[1]) : -1);

    /* initialize graphical user interfaces */

    wsInit(mDisplay);
    gtkInit(mDisplayName);

    /* load skin */

    skinDirInHome = get_path("skins");
    skinDirInData = MPLAYER_DATADIR "/skins";

    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] skin directory #1: %s\n", skinDirInHome);
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] skin directory #2: %s\n", skinDirInData);

    if (!skinName)
        skinName = strdup("default");

    ret = skinRead(skinName);

    if (ret == -1 && strcmp(skinName, "default") != 0) {
        mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_GUI_MSG_SkinCfgSelectedNotFound, skinName);

        skinName = strdup("default");
        ret      = skinRead(skinName);
    }

    switch (ret) {
    case -1:
        gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_GUI_MSG_SkinCfgNotFound, skinName);
        mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);

    case -2:
        gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_GUI_MSG_SkinCfgError, skinName);
        mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
    }

    /* initialize windows */

    if (gui_save_pos) {
        if (gui_main_pos_x != -3)
            guiApp.main.x = gui_main_pos_x;
        if (gui_main_pos_y != -3)
            guiApp.main.y = gui_main_pos_y;
        if (gui_video_pos_x != -3)
            guiApp.video.x = gui_video_pos_x;
        if (gui_video_pos_y != -3)
            guiApp.video.y = gui_video_pos_y;
    }

    if (WinID > 0) {
        guiApp.videoWindow.Parent = WinID;
        guiApp.video.x = 0;
        guiApp.video.y = 0;
    }

    if (guiWinID >= 0)
        guiApp.mainWindow.Parent = guiWinID;

    uiMainInit();      // main window must be first!
    uiVideoInit();     // video window must be second!
    uiPlaybarInit();
    uiMenuInit();

    WinID = (Window)guiApp.videoWindow.WindowID;

    btnValue(evSetVolume, &guiInfo.Volume);
    btnValue(evSetBalance, &guiInfo.Balance);
    btnValue(evSetMoviePosition, &guiInfo.Position);

    if (guiInfo.Position)
        uiEvent(evSetMoviePosition, guiInfo.Position);

    wsWindowVisibility(&guiApp.mainWindow, wsShowWindow);

    if (gtkShowVideoWindow) {
        wsWindowVisibility(&guiApp.videoWindow, wsShowWindow);

        guiInfo.VideoWindow = True;

        if (gtkLoadFullscreen)
            uiFullScreen();
    } else
        wsWindowBackground(&guiApp.videoWindow, 0, 0, 0);

    if (gtkLoadFullscreen)
        btnSet(evFullScreen, btnPressed);

    guiInfo.Playing = GUI_STOP;

    playlist = listMgr(PLAYLIST_ITEM_GET_CURR, 0);

    if (playlist && !filename) {
        uiSetFile(playlist->path, playlist->name, STREAMTYPE_FILE);
        guiInfo.Tracks = (uintptr_t)listMgr(PLAYLIST_ITEM_GET_POS, 0);
        guiInfo.Track  = 1;
        filename       = NULL; // don't start playing
    }

    if (subdata)
        setdup(&guiInfo.SubtitleFilename, subdata->filename);

    orig_fontconfig = font_fontconfig;
    set_fontconfig();

    guiInitialized = True;
}
Example #9
0
void mplayer(int what, float value, void *data)
{
    af_stream_t *afilter;
    equalizer_t *eq = (equalizer_t *)data;

    switch (what) {
    /* subtitle */

    case MPLAYER_SET_FONT_FACTOR:
        font_factor = value;
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_SET_FONT_OUTLINE:
        subtitle_font_thickness = 8.0 * value / 100.0;   // transform 0..100 to 0..8
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_SET_FONT_BLUR:
        subtitle_font_radius = 8.0 * value / 100.0;      // transform 0..100 to 0..8
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_SET_FONT_TEXTSCALE:
        text_font_scale_factor = value;
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_SET_FONT_OSDSCALE:
        osd_font_scale_factor = value;
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_SET_FONT_ENCODING:
        nfree(subtitle_font_encoding);
        subtitle_font_encoding = gstrdup(data);
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_SET_FONT_AUTOSCALE:
        subtitle_autoscale = (int)value;
        mplayer(MPLAYER_LOAD_FONT, 0, 0);
        break;

    case MPLAYER_LOAD_FONT:
#ifdef CONFIG_FREETYPE
        set_fontconfig();

        force_load_font = 1;
#else
        free_font_desc(vo_font);

        if (font_name) {
            vo_font = read_font_desc(font_name, font_factor, 0);

            if (!vo_font)
                gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_CantLoadFont, font_name);
        } else {
            char *fname = get_path("font/font.desc");

            setdup(&font_name, fname);
            free(fname);
            vo_font = read_font_desc(font_name, font_factor, 0);

            if (!vo_font) {
                setdup(&font_name, MPLAYER_DATADIR "/font/font.desc");
                vo_font = read_font_desc(font_name, font_factor, 0);
            }
        }
#endif
        break;

    case MPLAYER_SET_SUB_ENCODING:
        nfree(sub_cp);
        sub_cp = gstrdup(data);
        break;

    case MPLAYER_SET_EXTRA_STEREO:
        gtkAOExtraStereoMul = value;
        afilter = mpctx_get_afilter(guiInfo.mpcontext);
        if (afilter)
            af_control_any_rev(afilter, AF_CONTROL_ES_MUL | AF_CONTROL_SET, &gtkAOExtraStereoMul);
        break;

    case MPLAYER_SET_PANSCAN:
    {
        mp_cmd_t *mp_cmd;

        mp_cmd       = calloc(1, sizeof(*mp_cmd));
        mp_cmd->id   = MP_CMD_PANSCAN;
        mp_cmd->name = strdup("panscan");
        mp_cmd->args[0].v.f = value;
        mp_cmd->args[1].v.i = 1;
        mp_input_queue_cmd(mp_cmd);
    }
    break;

    case MPLAYER_SET_AUTO_QUALITY:
        auto_quality = (int)value;
        break;

    /* set equalizers */

    case MPLAYER_SET_CONTRAST:
        if (guiInfo.sh_video)
            set_video_colors(guiInfo.sh_video, "contrast", value);
        break;

    case MPLAYER_SET_BRIGHTNESS:
        if (guiInfo.sh_video)
            set_video_colors(guiInfo.sh_video, "brightness", value);
        break;

    case MPLAYER_SET_HUE:
        if (guiInfo.sh_video)
            set_video_colors(guiInfo.sh_video, "hue", value);
        break;

    case MPLAYER_SET_SATURATION:
        if (guiInfo.sh_video)
            set_video_colors(guiInfo.sh_video, "saturation", value);
        break;

    case MPLAYER_SET_EQUALIZER:
    {
        af_control_ext_t tmp;

        afilter = mpctx_get_afilter(guiInfo.mpcontext);

        if (eq) {
            gtkEquChannels[eq->channel][eq->band] = eq->gain;
            tmp.ch  = eq->channel;
            tmp.arg = gtkEquChannels[eq->channel];

            if (afilter)
                af_control_any_rev(afilter, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &tmp);
        } else {
            unsigned int i;

            memset(gtkEquChannels, 0, sizeof(gtkEquChannels));

            if (afilter) {
                for (i = 0; i < FF_ARRAY_ELEMS(gtkEquChannels); i++) {
                    tmp.ch  = i;
                    tmp.arg = gtkEquChannels[i];
                    af_control_any_rev(afilter, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &tmp);
                }
            }
        }

        break;
    }

    case MPLAYER_EXIT_GUI:
        exit_player_with_rc((enum exit_reason)value, (enum exit_reason)value >= EXIT_ERROR);
        break;
    }
}