-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: When the app exits in a ungraceful manner and is unable to d…
…ispose of the FFmpeg process, starting a new instance of MediaToolkit will kill all previous instances of FFmpeg.
- Loading branch information
Showing
2 changed files
with
38 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
public class ExtensionAttribute : Attribute { } | ||
public class ExtensionAttribute : Attribute | ||
{ | ||
} | ||
} | ||
|
||
namespace MediaToolkit.Util | ||
{ | ||
public static class Extensions | ||
{ | ||
private const int BUFF_SIZE = 16*1024; | ||
|
||
internal static void CopyTo(this Stream input, Stream output) | ||
{ | ||
byte[] buffer = new byte[Extensions.BUFF_SIZE]; | ||
int bytesRead; | ||
|
||
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, bytesRead); } | ||
} | ||
|
||
public static string FormatInvariant(this string value, params object[] args) | ||
{ | ||
try | ||
{ | ||
return value == null ? string.Empty : string.Format(CultureInfo.InvariantCulture, value, args); | ||
return value == null | ||
? string.Empty | ||
: string.Format(CultureInfo.InvariantCulture, value, args); | ||
} | ||
catch (FormatException ex) | ||
{ | ||
catch (FormatException ex) { | ||
return value; | ||
} | ||
} | ||
|
||
internal static bool IsNullOrWhiteSpace(this string value) | ||
{ | ||
return String.IsNullOrEmpty(value) || value.Trim().Length == 0; | ||
return string.IsNullOrEmpty(value) || value.Trim() | ||
.Length == 0; | ||
} | ||
|
||
const int BUFF_SIZE = 16 * 1024; | ||
internal static void CopyTo(this Stream input, Stream output) | ||
internal static string Remove(this Enum enumerable, string text) | ||
{ | ||
byte[] buffer = new byte[BUFF_SIZE]; | ||
int bytesRead; | ||
|
||
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) | ||
{ | ||
output.Write(buffer, 0, bytesRead); | ||
} | ||
return enumerable.ToString() | ||
.Replace(text, ""); | ||
} | ||
|
||
internal static string ToLower(this Enum enumerable) | ||
{ | ||
return enumerable.ToString().ToLowerInvariant(); | ||
return enumerable.ToString() | ||
.ToLowerInvariant(); | ||
} | ||
|
||
internal static string Remove(this Enum enumerable, string text) | ||
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action) | ||
{ | ||
return enumerable.ToString().Replace(text, ""); | ||
} | ||
if (action == null) throw new ArgumentNullException("action"); | ||
|
||
//internal static bool IsNullOrWhiteSpace(this string text) | ||
//{ | ||
// return string.IsNullOrWhiteSpace(text); | ||
//} | ||
foreach (T t in collection) action(t); | ||
} | ||
} | ||
} | ||
} |