[MPlayer-cvslog] r32469 - in trunk: mencoder.c mpcommon.c mpcommon.h mplayer.c

reimar subversion at mplayerhq.hu
Sat Oct 9 17:04:50 CEST 2010


Author: reimar
Date: Sat Oct  9 17:04:50 2010
New Revision: 32469

Log:
Avoid duplicating common init code between MPlayer and mencoder.

Modified:
   trunk/mencoder.c
   trunk/mpcommon.c
   trunk/mpcommon.h
   trunk/mplayer.c

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	Sat Oct  9 16:17:06 2010	(r32468)
+++ trunk/mencoder.c	Sat Oct  9 17:04:50 2010	(r32469)
@@ -75,7 +75,6 @@
 #include "libvo/font_load.h"
 #include "libvo/sub.h"
 #include "libvo/video_out.h"
-#include "osdep/priority.h"
 #include "osdep/timer.h"
 #include "stream/stream.h"
 #include "stream/stream_bd.h"
@@ -575,7 +574,7 @@ audio_encoder_t *aencoder = NULL;
 
 user_correct_pts = 0;
 
-  mp_msg_init();
+  common_preinit();
 
   // Create the config context and register the options
   mconfig = m_config_new();
@@ -587,27 +586,11 @@ user_correct_pts = 0;
 
   print_version("MEncoder");
 
-#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
-  set_path_env();
-#endif
-
-  InitTimer();
-
-// check codec.conf
-if(!codecs_file || !parse_codec_cfg(codecs_file)){
-  if(!parse_codec_cfg(get_path("codecs.conf"))){
-    if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
-      if(!parse_codec_cfg(NULL)){
-	mencoder_exit(1,NULL);
-      }
-      mp_msg(MSGT_MENCODER,MSGL_V,MSGTR_BuiltinCodecsConf);
-    }
-  }
-}
-
  parse_cfgfiles(mconfig);
  filelist = m_config_parse_me_command_line(mconfig, argc, argv);
  if(!filelist) mencoder_exit(1, MSGTR_ErrorParsingCommandLine);
+ if (!common_init())
+   mencoder_exit(1,NULL);
 
 {
 	char *extension;
@@ -647,38 +630,6 @@ if (frameno_filename) {
   }
 }
 
-#ifdef CONFIG_PRIORITY
-  set_priority();
-#endif
-
-  if (codec_path)
-    set_codec_path(codec_path);
-
-// check font
-#ifdef CONFIG_FREETYPE
-  init_freetype();
-#endif
-#ifdef CONFIG_FONTCONFIG
-  if(font_fontconfig <= 0)
-  {
-#endif
-#ifdef CONFIG_BITMAP_FONT
-  if(font_name){
-       vo_font=read_font_desc(font_name,font_factor,verbose>1);
-       if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
-  } else {
-      // try default:
-       vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
-       if(!vo_font)
-         vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
-  }
-#endif
-#ifdef CONFIG_FONTCONFIG
-  }
-#endif
-
-  vo_init_osd();
-
   /* HACK, for some weird reason, push() has to be called twice,
      otherwise options are not saved correctly */
   m_config_push(mconfig);
@@ -687,10 +638,6 @@ play_next_file:
   m_entry_set_options(mconfig,&filelist[curfile]);
   filename = filelist[curfile].name;
 
-#ifdef CONFIG_ASS
-  ass_library = ass_init();
-#endif
-
   if(!filename){
 	mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_MissingFilename);
 	mencoder_exit(1,NULL);

Modified: trunk/mpcommon.c
==============================================================================
--- trunk/mpcommon.c	Sat Oct  9 16:17:06 2010	(r32468)
+++ trunk/mpcommon.c	Sat Oct  9 17:04:50 2010	(r32469)
@@ -20,7 +20,11 @@
 #include "stream/stream.h"
 #include "libmpdemux/demuxer.h"
 #include "libmpdemux/stheader.h"
+#include "codec-cfg.h"
+#include "osdep/timer.h"
+#include "path.h"
 #include "mplayer.h"
+#include "libvo/font_load.h"
 #include "libvo/sub.h"
 #include "libvo/video_out.h"
 #include "cpudetect.h"
@@ -349,3 +353,114 @@ const m_option_t noconfig_opts[] = {
     {NULL, NULL, 0, 0, 0, 0, NULL}
 };
 
+/**
+ * Initialization code to be run at the very start, most not depend
+ * on option values.
+ */
+void common_preinit(void)
+{
+  InitTimer();
+  srand(GetTimerMS());
+
+  mp_msg_init();
+}
+
+/**
+ * Initialization code to be run after command-line parsing.
+ */
+int common_init(void)
+{
+#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
+  set_path_env();
+#endif
+#if defined(__MINGW32__) || defined(__CYGWIN__)
+#ifdef CONFIG_GUI
+    void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
+    if(runningmplayer && filename && use_gui){
+        COPYDATASTRUCT csData;
+        char file[MAX_PATH];
+        char *filepart = filename;
+        if(GetFullPathName(filename, MAX_PATH, file, &filepart)){
+            csData.dwData = 0;
+            csData.cbData = strlen(file)*2;
+            csData.lpData = file;
+            SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData);
+        }
+    }
+#endif
+
+	{
+		HMODULE kernel32 = GetModuleHandle("Kernel32.dll");
+		BOOL WINAPI (*setDEP)(DWORD) = NULL;
+		BOOL WINAPI (*setDllDir)(LPCTSTR) = NULL;
+		if (kernel32) {
+			setDEP = GetProcAddress(kernel32, "SetProcessDEPPolicy");
+			setDllDir = GetProcAddress(kernel32, "SetDllDirectoryA");
+		}
+		if (setDEP) setDEP(3);
+		if (setDllDir) setDllDir("");
+	}
+	// stop Windows from showing all kinds of annoying error dialogs
+	SetErrorMode(0x8003);
+	// request 1ms timer resolution
+	timeBeginPeriod(1);
+#endif
+
+#ifdef CONFIG_PRIORITY
+    set_priority();
+#endif
+
+  if (codec_path)
+    set_codec_path(codec_path);
+
+/* Check codecs.conf. */
+if(!codecs_file || !parse_codec_cfg(codecs_file)){
+  char *mem_ptr;
+  if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
+    if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
+      if(!parse_codec_cfg(NULL)){
+        return 0;
+      }
+      mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
+    }
+  }
+  free( mem_ptr ); // release the buffer created by get_path()
+}
+
+// check font
+#ifdef CONFIG_FREETYPE
+  init_freetype();
+#endif
+#ifdef CONFIG_FONTCONFIG
+  if(font_fontconfig <= 0)
+  {
+#endif
+#ifdef CONFIG_BITMAP_FONT
+  if(font_name){
+       vo_font=read_font_desc(font_name,font_factor,verbose>1);
+       if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,
+		filename_recode(font_name));
+  } else {
+       char *mem_ptr;
+      // try default:
+       vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
+       free(mem_ptr); // release the buffer created by get_path()
+       if(!vo_font)
+       vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
+  }
+  if (sub_font_name)
+    sub_font = read_font_desc(sub_font_name, font_factor, verbose>1);
+  else
+    sub_font = vo_font;
+#endif
+#ifdef CONFIG_FONTCONFIG
+  }
+#endif
+
+  vo_init_osd();
+
+#ifdef CONFIG_ASS
+  ass_library = ass_init();
+#endif
+  return 1;
+}

Modified: trunk/mpcommon.h
==============================================================================
--- trunk/mpcommon.h	Sat Oct  9 16:17:06 2010	(r32468)
+++ trunk/mpcommon.h	Sat Oct  9 17:04:50 2010	(r32469)
@@ -68,4 +68,7 @@ void update_teletext(struct sh_video *sh
 int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
 void set_osd_subtitle(subtitle *subs);
 
+void common_preinit(void);
+int common_init(void);
+
 #endif /* MPLAYER_MPCOMMON_H */

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Sat Oct  9 16:17:06 2010	(r32468)
+++ trunk/mplayer.c	Sat Oct  9 17:04:50 2010	(r32469)
@@ -114,7 +114,6 @@
 #include "mpcommon.h"
 #include "mplayer.h"
 #include "osdep/getch2.h"
-#include "osdep/priority.h"
 #include "osdep/timer.h"
 #include "parser-cfg.h"
 #include "parser-mpcmd.h"
@@ -2734,8 +2733,6 @@ static int seek(MPContext *mpctx, double
 int main(int argc,char* argv[]){
 
 
-char * mem_ptr;
-
 // movie info:
 
 /* Flag indicating whether MPlayer should exit without playing anything. */
@@ -2744,10 +2741,7 @@ int i;
 
 int gui_no_filename=0;
 
-  InitTimer();
-  srand(GetTimerMS());
-
-  mp_msg_init();
+  common_preinit();
 
   // Create the config context and register the options
   mconfig = m_config_new();
@@ -2758,10 +2752,6 @@ int gui_no_filename=0;
   // Preparse the command line
   m_config_preparse_command_line(mconfig,argc,argv);
 
-#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
-  set_path_env();
-#endif
-
 #ifdef CONFIG_TV
   stream_tv_defaults.immediate = 1;
 #endif
@@ -2805,46 +2795,8 @@ int gui_no_filename=0;
     }
 
   print_version("MPlayer");
-
-#if defined(__MINGW32__) || defined(__CYGWIN__)
-#ifdef CONFIG_GUI
-    void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
-    if(runningmplayer && filename && use_gui){
-        COPYDATASTRUCT csData;
-        char file[MAX_PATH];
-        char *filepart = filename;
-        if(GetFullPathName(filename, MAX_PATH, file, &filepart)){
-            csData.dwData = 0;
-            csData.cbData = strlen(file)*2;
-            csData.lpData = file;
-            SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData);
-        }
-    }
-#endif
-
-	{
-		HMODULE kernel32 = GetModuleHandle("Kernel32.dll");
-		BOOL WINAPI (*setDEP)(DWORD) = NULL;
-		BOOL WINAPI (*setDllDir)(LPCTSTR) = NULL;
-		if (kernel32) {
-			setDEP = GetProcAddress(kernel32, "SetProcessDEPPolicy");
-			setDllDir = GetProcAddress(kernel32, "SetDllDirectoryA");
-		}
-		if (setDEP) setDEP(3);
-		if (setDllDir) setDllDir("");
-	}
-	// stop Windows from showing all kinds of annoying error dialogs
-	SetErrorMode(0x8003);
-	// request 1ms timer resolution
-	timeBeginPeriod(1);
-#endif
-
-#ifdef CONFIG_PRIORITY
-    set_priority();
-#endif
-
-  if (codec_path)
-    set_codec_path(codec_path);
+    if (!common_init())
+        exit_player_with_rc(EXIT_NONE, 0);
 
 #ifndef CONFIG_GUI
     if(use_gui){
@@ -2885,19 +2837,6 @@ int gui_no_filename=0;
       opt_exit = 1;
     }
 
-/* Check codecs.conf. */
-if(!codecs_file || !parse_codec_cfg(codecs_file)){
-  if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){
-    if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
-      if(!parse_codec_cfg(NULL)){
-        exit_player_with_rc(EXIT_NONE, 0);
-      }
-      mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);
-    }
-  }
-  free( mem_ptr ); // release the buffer created by get_path()
-}
-
     if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
       mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
       mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n");
@@ -2974,41 +2913,6 @@ if(!codecs_file || !parse_codec_cfg(code
 
 //------ load global data first ------
 
-// check font
-#ifdef CONFIG_FREETYPE
-  init_freetype();
-#endif
-#ifdef CONFIG_FONTCONFIG
-  if(font_fontconfig <= 0)
-  {
-#endif
-#ifdef CONFIG_BITMAP_FONT
-  if(font_name){
-       vo_font=read_font_desc(font_name,font_factor,verbose>1);
-       if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,
-		filename_recode(font_name));
-  } else {
-      // try default:
-       vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
-       free(mem_ptr); // release the buffer created by get_path()
-       if(!vo_font)
-       vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
-  }
-  if (sub_font_name)
-    sub_font = read_font_desc(sub_font_name, font_factor, verbose>1);
-  else
-    sub_font = vo_font;
-#endif
-#ifdef CONFIG_FONTCONFIG
-  }
-#endif
-
-  vo_init_osd();
-
-#ifdef CONFIG_ASS
-  ass_library = ass_init();
-#endif
-
 #ifdef HAVE_RTC
   if(!nortc)
   {


More information about the MPlayer-cvslog mailing list