Merge pull request #681 from abeloin/ffmpeg-new

Changed OS and Machine arch detection for ffmpeg
pull/702/head
Luke 11 years ago
commit e0f644b4ad

@ -1,6 +1,8 @@
using System; using System;
#if __MonoCS__ #if __MonoCS__
using System.Runtime.InteropServices; using Mono.Unix.Native;
using System.Text.RegularExpressions;
using System.IO;
#endif #endif
namespace MediaBrowser.ServerApplication.FFMpeg namespace MediaBrowser.ServerApplication.FFMpeg
@ -41,7 +43,9 @@ namespace MediaBrowser.ServerApplication.FFMpeg
#if __MonoCS__ #if __MonoCS__
case PlatformID.Unix: case PlatformID.Unix:
if (IsRunningOnMac()) if (PlatformDetection.IsMac)
{
if (PlatformDetection.IsX86_64)
{ {
switch (arg) switch (arg)
{ {
@ -56,13 +60,31 @@ namespace MediaBrowser.ServerApplication.FFMpeg
} }
break; break;
} }
else }
if (PlatformDetection.IsLinux)
{
if (PlatformDetection.IsX86)
{
switch (arg)
{
case "Version":
return "linux_x86_20140118";
case "FFMpegFilename":
return "ffmpeg";
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
return "gz";
}
break;
}
else if (PlatformDetection.IsX86_64)
{ {
// Linux // Linux on x86 or x86_64
switch (arg) switch (arg)
{ {
case "Version": case "Version":
return "20140104"; return "linux_x86_64_20140118";
case "FFMpegFilename": case "FFMpegFilename":
return "ffmpeg"; return "ffmpeg";
case "FFProbeFilename": case "FFProbeFilename":
@ -72,6 +94,9 @@ namespace MediaBrowser.ServerApplication.FFMpeg
} }
break; break;
} }
}
// Unsupported Unix platform
return "";
#endif #endif
} }
return ""; return "";
@ -92,52 +117,81 @@ namespace MediaBrowser.ServerApplication.FFMpeg
#if __MonoCS__ #if __MonoCS__
case PlatformID.Unix: case PlatformID.Unix:
if (IsRunningOnMac()) if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
{ {
// Mac OS X Intel 64bit
return new[] return new[]
{ {
"https://copy.com/IB0W4efS6t9A/ffall-2.1.1.tar.gz?download=1" "https://copy.com/IB0W4efS6t9A/ffall-2.1.1.tar.gz?download=1"
}; };
} }
else
if (PlatformDetection.IsLinux)
{
if (PlatformDetection.IsX86)
{ {
// Linux
return new[] return new[]
{ {
"http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.2014-01-04.tar.gz", "http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.2014-01-18.tar.gz",
"https://www.dropbox.com/s/b7nkg71sil812hp/ffmpeg.static.32bit.2014-01-04.tar.gz?dl=1" "https://www.dropbox.com/s/b7nkg71sil812hp/ffmpeg.static.32bit.2014-01-04.tar.gz?dl=1"
}; };
} }
#endif
if (PlatformDetection.IsX86_64)
{
return new[]
{
"http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.2014-01-18.tar.gz"
};
} }
}
//No Unix version available
return new string[] {};
#endif
}
return new string[] {}; return new string[] {};
} }
}
#if __MonoCS__ #if __MonoCS__
// From mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUI.cs public static class PlatformDetection
[DllImport ("libc")] {
static extern int uname (IntPtr buf); public readonly static bool IsWindows;
public readonly static bool IsMac;
public readonly static bool IsLinux;
public readonly static bool IsX86;
public readonly static bool IsX86_64;
public readonly static bool IsArm;
static PlatformDetection ()
{
IsWindows = Path.DirectorySeparatorChar == '\\';
static bool IsRunningOnMac() //Don't call uname on windows
if (!IsWindows)
{ {
IntPtr buf = IntPtr.Zero; Utsname uname;
try { var callResult = Syscall.uname(out uname);
buf = Marshal.AllocHGlobal (8192); if (callResult == 0)
// This is a hacktastic way of getting sysname from uname () {
if (uname (buf) == 0) { IsMac = uname.sysname == "Darwin";
string os = Marshal.PtrToStringAnsi (buf); IsLinux = !IsMac && uname.sysname == "Linux";
if (os == "Darwin")
return true; Regex archX86 = new Regex("(i|I)[3-6]86");
IsX86 = archX86.IsMatch(uname.machine);
IsX86_64 = !IsX86 && uname.machine == "x86_64";
IsArm = !IsX86 && !IsX86 && uname.machine.StartsWith("arm");
} }
} catch {
} finally {
if (buf != IntPtr.Zero)
Marshal.FreeHGlobal (buf);
} }
return false; else
{
if (System.Environment.Is64BitOperatingSystem)
IsX86_64 = true;
else
IsX86 = true;
} }
#endif
} }
}
#endif
} }

Loading…
Cancel
Save