Browse Source

vidprocess

fly 2 years ago
parent
commit
99796816ee
5 changed files with 104 additions and 58 deletions
  1. 2 2
      clone&pull tool.bat
  2. 2 0
      src/Publish.ps1
  3. 3 0
      src/WingCloudServer.csproj
  4. 96 55
      src/WingServer.cs
  5. 1 1
      src/appsettings.json

+ 2 - 2
clone&pull tool.bat

@@ -35,7 +35,7 @@ if %pullnum% equ 0 (
 		)
 		cd ..
 	)
-	if %pullnum% lss 13 (
+	if %pullnum% lss 14 (
 		goto MsgClone
 	)
 ) 
@@ -73,7 +73,7 @@ if not exist WingInterfaceLibrary (git clone http://git.ius.plus:88/Project-Wing
 if not exist WingCloudServer (git clone http://git.ius.plus:88/Project-Wing/WingCloudServer.git && echo;)
 if not exist WingDeviceService (git clone http://git.ius.plus:88/Project-Wing/WingDeviceService.git && echo;)
 if not exist WingNotificationModule (git clone http://git.ius.plus/Project-Wing/WingNotificationModule.git && echo;)
-
+if not exist WingVidProcessService (git clone http://git.ius.plus/arthur.wu/WingVidProcessService.git && echo;)
 echo Finished!
 pause>nul
 exit

+ 2 - 0
src/Publish.ps1

@@ -54,6 +54,8 @@ BuildService "WingStorageModule" 1
 
 BuildService "WingDeviceService" 1 0 "../../WingDeviceService"
 
+BuildService "VidProcessService" 1 0 "../../WingVidProcessService/VidProcessService"
+
 BuildService "WingRemedicalModule" 1
 
 BuildService "WingNotificationModule" 1 0 "../../WingNotificationModule"

+ 3 - 0
src/WingCloudServer.csproj

@@ -40,6 +40,9 @@
     </None>
     <None Update="Tools\win\win_mongod.exe">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+     <None Update="Tools\win\ffmpeg.exe">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
     <None Update="Tools\win\win_ServerReboot.exe">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+ 96 - 55
src/WingServer.cs

@@ -14,18 +14,18 @@ namespace WingCloudServer
 {
     internal class WingServer
     {
-         private JsonRpcServer _rpcHttpServer;
+        private JsonRpcServer _rpcHttpServer;
         private JsonRpcServer _rpcInProcessServer;
         private JsonRpcInProcessEngine _inProcessEngine;
         public WingServer(int port)
         {
             JsonRpcLite.Log.Logger.DebugMode = Logger.Debug;
             JsonRpcLite.Log.Logger.Writer = new JsonRpcLiteLogWrite();
-            
+
             _rpcInProcessServer = new JsonRpcServer();
             _inProcessEngine = new JsonRpcInProcessEngine();
             _rpcInProcessServer.UseEngine(_inProcessEngine);
-           
+
             _rpcHttpServer = new JsonRpcServer();
             var jsonRpcHttpServerEngine = new JsonRpcHttpServerEngine($"http://*:{port}/");
             _rpcHttpServer.UseEngine(jsonRpcHttpServerEngine);
@@ -34,13 +34,14 @@ namespace WingCloudServer
         /// <summary>
         /// Start server to load all service
         /// </summary>
-        internal void Start(){            
-            
+        internal void Start()
+        {
+
             InitializeServices();
             _rpcInProcessServer.Start();
             _rpcHttpServer.Start();
-        }       
-              
+        }
+
         /// <summary>
         /// Stop server
         /// </summary>
@@ -48,48 +49,48 @@ namespace WingCloudServer
         {
             //TODO dispose service
             _rpcHttpServer.Stop();
-            _rpcInProcessServer.Stop();            
+            _rpcInProcessServer.Stop();
         }
 
         void InitializeServices()
-        {               
+        {
             //initiaize rpc client pool
             var remoteRpcHttpServices = LoadRemoteServiceConfig();//new RemoteServiceInfo[0]; //TODO from settings
             var rpcClientPool = new JsonRpcClientPool(_inProcessEngine);
-            rpcClientPool.Initialize(remoteRpcHttpServices.ToArray());  
+            rpcClientPool.Initialize(remoteRpcHttpServices.ToArray());
 
-            var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services"); 
-            var inProcessServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services","InProcess").Value;
-            var inProcessServices = inProcessServicesString.Split(','); 
-            var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services","JsonRpcHttp").Value;
-            var rpcHttpServices = rpcHttpServicesString.Split(','); 
+            var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services");
+            var inProcessServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "InProcess").Value;
+            var inProcessServices = inProcessServicesString.Split(',');
+            var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "JsonRpcHttp").Value;
+            var rpcHttpServices = rpcHttpServicesString.Split(',');
             if (!Directory.Exists(folder))
             {
                 throw new NotSupportedException($"Folder {folder} not exist");
             }
-          
+
             //InProcess service load and register to InPrcess rpc server
-            var rpcServices =  new Dictionary<Type, object>();
+            var rpcServices = new Dictionary<Type, object>();
             foreach (var service in inProcessServices)
-            {                
+            {
                 var wingServiceType = LoadService(folder, service);
                 var instance = Activator.CreateInstance(wingServiceType);
-                rpcServices.Add(wingServiceType, instance);                
+                rpcServices.Add(wingServiceType, instance);
                 var interfaces = wingServiceType.GetInterfaces();
-                foreach(var serviceInterface in interfaces)
-                {    
-                    if (serviceInterface ==  typeof(IDisposable))                     
+                foreach (var serviceInterface in interfaces)
+                {
+                    if (serviceInterface == typeof(IDisposable))
                     {
                         continue;
                     }
-                    if (serviceInterface ==  typeof(IJsonRpcService))
-                    {      
-                       continue;
+                    if (serviceInterface == typeof(IJsonRpcService))
+                    {
+                        continue;
                     }
-                    Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc InProcess Server");                  
-                    _rpcInProcessServer.RegisterService(serviceInterface, instance); 
-                         
-                }                
+                    Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc InProcess Server");
+                    _rpcInProcessServer.RegisterService(serviceInterface, instance);
+
+                }
             }
 
             //Rpc http service load and register to rpc http server
@@ -97,32 +98,35 @@ namespace WingCloudServer
             {
                 var wingServiceType = LoadService(folder, service);
                 var instance = Activator.CreateInstance(wingServiceType);
-                rpcServices.Add(wingServiceType, instance);                                          
+                rpcServices.Add(wingServiceType, instance);
                 var interfaces = wingServiceType.GetInterfaces();
-                foreach(var serviceInterface in interfaces)
-                {       
-                    if (serviceInterface ==  typeof(IDisposable))                
+                foreach (var serviceInterface in interfaces)
+                {
+                    if (serviceInterface == typeof(IDisposable))
                     {
                         continue;
-                    }             
-                    if (serviceInterface ==  typeof(IJsonRpcService))
-                    {       
-                         continue;
                     }
-                    Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc Http Server");                        
-                    _rpcHttpServer.RegisterService(serviceInterface, instance);         
-                                
-                }       
+                    if (serviceInterface == typeof(IJsonRpcService))
+                    {
+                        continue;
+                    }
+                    Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc Http Server");
+                    _rpcHttpServer.RegisterService(serviceInterface, instance);
+
+                }
             }
 
             //load services
-            foreach(var service in rpcServices)
+            foreach (var service in rpcServices)
             {
-                var method =  service.Key.GetMethod("Load");
-                method.Invoke(service.Value, new object[] { rpcClientPool});     
+                var method = service.Key.GetMethod("Load");
+                method.Invoke(service.Value, new object[] { rpcClientPool });
             }
+
+            //load extdll
+            InitSkiaSharp();
         }
-        
+
         private Type LoadService(string folder, object serviceName)
         {
             var file = Path.Combine(folder, $"{serviceName}.dll");
@@ -130,10 +134,10 @@ namespace WingCloudServer
             {
                 throw new NotSupportedException($"File {file} not exist");
             }
-            var assemblyLoader = new  AssemblyLoader();
+            var assemblyLoader = new AssemblyLoader();
             var assembly = assemblyLoader.LoadAssemblyDependencies(file);
-            var types = assembly.GetTypes();                
-            var wingServiceType = types.FirstOrDefault(x=>typeof(JsonRpcService).IsAssignableFrom(x) && x.IsClass && !x.IsAbstract);
+            var types = assembly.GetTypes();
+            var wingServiceType = types.FirstOrDefault(x => typeof(JsonRpcService).IsAssignableFrom(x) && x.IsClass && !x.IsAbstract);
             if (wingServiceType == null)
             {
                 throw new NotImplementedException($"WingService not find in {file}");
@@ -149,7 +153,7 @@ namespace WingCloudServer
         private Dictionary<string, List<string>> GetServiceByModuleName(string defaultInterfaceName = "WingInterfaceLibrary", string defaultInterfaceFolder = "Interface")
         {
             var dic = new Dictionary<string, List<string>>();
-            var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies"); 
+            var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies");
             if (!Directory.Exists(folder))
             {
                 throw new NotSupportedException($"Folder {folder} not exist");
@@ -161,7 +165,7 @@ namespace WingCloudServer
             }
             var assemblyLoader = new AssemblyLoader();
             var assembly = assemblyLoader.LoadAssemblyDependencies(file);
-            var types = assembly.GetTypes(); 
+            var types = assembly.GetTypes();
             var namespaceStr = $"{defaultInterfaceName}.{defaultInterfaceFolder}";
             foreach (var item in types)
             {
@@ -181,11 +185,11 @@ namespace WingCloudServer
                         }
                         else
                         {
-                            dic.Add(desc, new List<string> () { item.Name });
+                            dic.Add(desc, new List<string>() { item.Name });
                         }
                     }
                 }
-            }     
+            }
             return dic;
         }
 
@@ -197,12 +201,12 @@ namespace WingCloudServer
         {
             List<RemoteServiceInfo> resList = new List<RemoteServiceInfo>();
             var remoteStr = ConfigurationManager.GetParammeter<StringParameter>("Services", "Remote").Value;
-            var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services","JsonRpcHttp").Value;
+            var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "JsonRpcHttp").Value;
             if (!string.IsNullOrEmpty(remoteStr) && remoteStr.Split(',').Length > 0)
             {
                 var dic = GetServiceByModuleName();
                 var list = remoteStr.Split(',');
-                foreach(var serviceInfo in list)
+                foreach (var serviceInfo in list)
                 {
                     var remoteArray = serviceInfo.Split('|');
                     if (remoteArray != null && remoteArray.Length > 1)
@@ -227,6 +231,43 @@ namespace WingCloudServer
             return resList;
         }
 
+        /// <summary>
+        /// 初始化SkiaSharp
+        /// </summary>
+        private void InitSkiaSharp()
+        {
+            try
+            {
+                var dllsRootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "runtimes");
+                var skiaSharpPath = "";
+                var libSkiaSharpDest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies", "libSkiaSharp.dll");
+                switch (Environment.OSVersion.Platform)
+                {
+                    case PlatformID.Win32NT:
+                        if (Environment.Is64BitProcess)
+                        {
+                            skiaSharpPath = Path.Combine(dllsRootPath, "win-x64", "native", "libSkiaSharp.dll");
+                        }
+                        else
+                        {
+                            skiaSharpPath = Path.Combine(dllsRootPath, "win-x86", "native", "libSkiaSharp.dll");
+                        }
+                        break;
+                    case PlatformID.MacOSX:
+                        skiaSharpPath = Path.Combine(dllsRootPath, "osx", "native", "libSkiaSharp.dylib");
+                        libSkiaSharpDest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies", "libSkiaSharp.dylib");
+                        break;
+                    default:
+                        break;
+                }
+                File.Copy(skiaSharpPath, libSkiaSharpDest, true);
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineError($"InitSkiaSharp error:{ex}");
+            }
+        }
+
         private class JsonRpcLiteLogWrite : JsonRpcLite.Log.ILogWriter
         {
             public void WriteDebug(string message)
@@ -254,5 +295,5 @@ namespace WingCloudServer
                 Logger.WriteLineWarn(message);
             }
         }
-    }          
+    }
 }

+ 1 - 1
src/appsettings.json

@@ -11,7 +11,7 @@
   },
   "Services":{
     "InProcess":"WingEmailModule,WingMongoDBModule,WingSessionModule,WingSMSModule,WingNotificationModule",
-    "JsonRpcHttp":"WingManagementModule,WingStorageModule,WingUserModule,WingDeviceService,WingRemedicalModule",
+    "JsonRpcHttp":"WingManagementModule,WingStorageModule,WingUserModule,WingDeviceService,WingRemedicalModule,VidProcessService",
     "Remote": "WingUserModule|http://192.168.6.91,WingDeviceService|http://192.168.6.91"
   },
   "ServerHosts":{