Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Adding .NET Core projects
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Apr 18, 2017
1 parent 0cc9b3f commit 9d322f9
Show file tree
Hide file tree
Showing 24 changed files with 1,170 additions and 219 deletions.
108 changes: 108 additions & 0 deletions .paket/Paket.Restore.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Mark that this target file has been loaded. -->
<IsPaketRestoreTargetsFileLoaded>true</IsPaketRestoreTargetsFileLoaded>
<PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
<MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
<MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>
<!-- Paket command -->
<PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket.exe')">$(PaketRootPath)paket.exe</PaketExePath>
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)paket.exe</PaketExePath>
<PaketCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
<PaketCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</PaketCommand>
</PropertyGroup>

<Target Name="PaketRestore" BeforeTargets="_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" >

<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" ' />

<PropertyGroup>
<PaketReferencesFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references</PaketReferencesFilePath>
</PropertyGroup>

<ReadLinesFromFile File="$(PaketReferencesFilePath)" >
<Output TaskParameter="Lines" ItemName="PaketReferencesFileLines"/>
</ReadLinesFromFile>

<ItemGroup Condition=" '@(PaketReferencesFileLines)' != '' " >
<PaketReferencesFileLinesInfo Include="@(PaketReferencesFileLines)" >
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
</PaketReferencesFileLinesInfo>
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<RestoreConfigFile>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).NuGet.Config</RestoreConfigFile>
</PropertyGroup>

</Target>

<Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" >
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
</Target>

<Target Name="PaketOverrideNuspec" AfterTargets="GenerateNuspec" >
<PropertyGroup>
<PaketReferencesFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references</PaketReferencesFilePath>
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>

<ItemGroup>
<_NuspecFiles Include="$(BaseIntermediateOutputPath)*.nuspec"/>
</ItemGroup>

<Exec Command='$(PaketCommand) fix-nuspec file "@(_NuspecFiles)" references-file "$(PaketReferencesFilePath)" ' />

<ConvertToAbsolutePath Condition="@(_NuspecFiles) != ''" Paths="@(_NuspecFiles)">
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" />
</ConvertToAbsolutePath>

<!-- Call Pack -->
<PackTask PackItem="$(PackProjectInputFile)"
PackageFiles="@(_PackageFiles)"
PackageFilesToExclude="@(_PackageFilesToExclude)"
PackageVersion="$(PackageVersion)"
PackageId="$(PackageId)"
Title="$(Title)"
Authors="$(Authors)"
Description="$(Description)"
Copyright="$(Copyright)"
RequireLicenseAcceptance="$(PackageRequireLicenseAcceptance)"
LicenseUrl="$(PackageLicenseUrl)"
ProjectUrl="$(PackageProjectUrl)"
IconUrl="$(PackageIconUrl)"
ReleaseNotes="$(PackageReleaseNotes)"
Tags="$(PackageTags)"
TargetPathsToAssemblies="@(_TargetPathsToAssemblies->'%(FinalOutputPath)')"
TargetPathsToSymbols="@(_TargetPathsToSymbols)"
TargetFrameworks="@(_TargetFrameworks)"
AssemblyName="$(AssemblyName)"
PackageOutputPath="$(PackageOutputAbsolutePath)"
IncludeSymbols="$(IncludeSymbols)"
IncludeSource="$(IncludeSource)"
PackageTypes="$(PackageType)"
IsTool="$(IsTool)"
RepositoryUrl="$(RepositoryUrl)"
RepositoryType="$(RepositoryType)"
SourceFiles="@(_SourceFiles->Distinct())"
NoPackageAnalysis="$(NoPackageAnalysis)"
MinClientVersion="$(MinClientVersion)"
Serviceable="$(Serviceable)"
AssemblyReferences="@(_References)"
ContinuePackingAfterGeneratingNuspec="$(ContinuePackingAfterGeneratingNuspec)"
NuspecOutputPath="$(BaseIntermediateOutputPath)"
IncludeBuildOutput="$(IncludeBuildOutput)"
BuildOutputFolder="$(BuildOutputTargetFolder)"
ContentTargetFolders="$(ContentTargetFolders)"
RestoreOutputPath="$(RestoreOutputAbsolutePath)"
NuspecFile="$(NuspecFileAbsolutePath)"
NuspecBasePath="$(NuspecBasePath)"
NuspecProperties="$(NuspecProperties)"/>
</Target>

</Project>
59 changes: 37 additions & 22 deletions MMALSharp.Common/Handlers/StreamCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ namespace MMALSharp.Handlers
/// </summary>
public abstract class StreamCaptureHandler : ICaptureHandler
{
/// <summary>
/// A Stream instance that we can process image data to
/// </summary>
protected Stream CurrentStream { get; set; }
public List<Tuple<string, string, string>> ProcessedStreams { get; set; } = new List<Tuple<string, string, string>>();

/// <summary>
/// A list of FileStreams that have been processed by this capture handler
/// </summary>
public List<Tuple<string, string, string>> ProcessedFiles { get; set; } = new List<Tuple<string, string, string>>();

/// <summary>
/// The total size of data that has been processed by this capture handler
/// </summary>
protected int Processed { get; set; }

/// <summary>
/// The directory
/// </summary>
protected string Directory { get; set; }
protected string Extension { get; set; }

Expand All @@ -27,6 +42,9 @@ public StreamCaptureHandler(string directory, string extension)
System.IO.Directory.CreateDirectory(this.Directory);
}

/// <summary>
/// Creates a new File (FileStream), assigns it to the Stream instance of this class and disposes of any existing stream.
/// </summary>
public void NewFile()
{
if (this.CurrentStream != null)
Expand All @@ -35,6 +53,10 @@ public void NewFile()
this.CurrentStream = File.Create(this.Directory + "/" + DateTime.Now.ToString("dd-MMM-yy HH-mm-ss") + "." + this.Extension);
}

/// <summary>
/// Processes the data passed into this method to this class' Stream instance.
/// </summary>
/// <param name="data">The image data</param>
public void Process(byte[] data)
{
this.Processed += data.Length;
Expand All @@ -46,11 +68,18 @@ public void Process(byte[] data)

}

/// <summary>
/// Allows us to do any further processing once the capture method has completed.
/// </summary>
public void PostProcess()
{
try
{
this.ProcessedStreams.Add(new Tuple<string, string, string> (this.GetDirectory(), this.GetFilename(), this.GetExtension()));
{
if (this.CurrentStream.GetType() == typeof(FileStream))
{
this.ProcessedFiles.Add(new Tuple<string, string, string>(this.Directory, this.GetFilename(), this.Extension));
}

Console.WriteLine(string.Format("Successfully processed {0}", Helpers.ConvertBytesToMegabytes(this.Processed)));
}
catch(Exception e)
Expand All @@ -59,25 +88,11 @@ public void PostProcess()
Console.WriteLine(e.Message);
}
}

public string GetDirectory()
{
if(this.CurrentStream.GetType() == typeof(FileStream))
{
return Path.GetDirectoryName(((FileStream)this.CurrentStream).Name);
}
return null;
}

private string GetExtension()
{
if (this.CurrentStream.GetType() == typeof(FileStream))
{
return Path.GetExtension(((FileStream)this.CurrentStream).Name);
}
return null;
}


/// <summary>
/// Gets the filename that a FileStream points to
/// </summary>
/// <returns>The filename</returns>
private string GetFilename()
{
if (this.CurrentStream.GetType() == typeof(FileStream))
Expand Down
9 changes: 1 addition & 8 deletions MMALSharp.Common/Handlers/VideoStreamCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ public class VideoStreamCaptureHandler : StreamCaptureHandler
{
public VideoStreamCaptureHandler(string directory, string extension) : base(directory, extension) { }

public bool CanSplit()
{
if (this.CurrentStream.GetType() == typeof(FileStream))
return true;
return false;
}

public void Split()
{
if (this.CanSplit())
if (this.CurrentStream.GetType() == typeof(FileStream))
{
this.NewFile();
}
Expand Down
37 changes: 29 additions & 8 deletions MMALSharp.FFmpeg/Handlers/FFmpegCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,31 @@ public class FFmpegCaptureHandler : ICaptureHandler
{
public Process MyProcess { get; set; }

public FFmpegCaptureHandler(string streamName, string streamUrl, int framerate)
/// <summary>
/// Streams video from the standard output stream via FFmpeg to an RTMP server.
/// </summary>
/// <param name="streamName">The meta name of the stream</param>
/// <param name="streamUrl">The url of your RTMP server - the url to stream to.</param>
/// <returns></returns>
public static FFmpegCaptureHandler RTMPStreamer(string streamName, string streamUrl)
{
return new FFmpegCaptureHandler(string.Format("-re -i - -c:v copy -an -f flv -metadata streamName={0} {1}", streamName, streamUrl));
}

/// <summary>
/// Records video from the standard output stream via FFmpeg into a video file that can be opened without explicit command line flags.
/// </summary>
/// <param name="directory">The directory to store the output video file</param>
/// <param name="extension">The extension of the video file</param>
/// <returns></returns>
public static FFmpegCaptureHandler TakeVideoMultiplex(string directory, string extension)
{
System.IO.Directory.CreateDirectory(directory);

return new FFmpegCaptureHandler(string.Format("-re -i - -c:v copy {0}/out.{1}", directory.TrimEnd(), extension.TrimStart('.')));
}

public FFmpegCaptureHandler(string argument)
{
this.MyProcess = new Process();

Expand Down Expand Up @@ -46,7 +70,7 @@ public FFmpegCaptureHandler(string streamName, string streamUrl, int framerate)
}
};

this.MyProcess.StartInfo.Arguments = string.Format("-i - -c:v copy -an -r {0} -f flv -metadata streamName={1} {2}", framerate, streamName, streamUrl);
this.MyProcess.StartInfo.Arguments = argument;
this.MyProcess.Start();
this.MyProcess.BeginOutputReadLine();
this.MyProcess.BeginErrorReadLine();
Expand All @@ -69,10 +93,7 @@ public string GetDirectory()
throw new NotImplementedException();
}

public void PostProcess()
{

}
public void PostProcess() { }

public void Process(byte[] data)
{
Expand All @@ -83,7 +104,7 @@ public void Process(byte[] data)
}
catch
{
this.MyProcess.Close();
this.MyProcess.Kill();
throw;
}
}
Expand All @@ -95,7 +116,7 @@ public void Split()

public void Dispose()
{
this.MyProcess.Close();
this.MyProcess.Kill();
}

}
Expand Down
8 changes: 4 additions & 4 deletions MMALSharp.FFmpeg/VideoUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public static void ImagesToVideo(this ImageStreamCaptureHandler result, string t
process.StartInfo.FileName = "ffmpeg";


if (result.ProcessedStreams.Count == 0)
if (result.ProcessedFiles.Count == 0)
return;

//Create temporary directory and copy all files in the capture handler to it.
var tempDirectory = result.ProcessedStreams.FirstOrDefault().Item1.TrimEnd('/') + "/mmalsharptemp/";
var extension = result.ProcessedStreams.FirstOrDefault().Item3;
var tempDirectory = result.ProcessedFiles.FirstOrDefault().Item1.TrimEnd('/') + "/mmalsharptemp/";
var extension = result.ProcessedFiles.FirstOrDefault().Item3;
try
{
System.IO.Directory.CreateDirectory(tempDirectory);

foreach (var tuple in result.ProcessedStreams)
foreach (var tuple in result.ProcessedFiles)
{
System.IO.File.Copy(tuple.Item1.TrimEnd('/') + "/" + tuple.Item2.TrimEnd('.') + tuple.Item3, tempDirectory + tuple.Item2.TrimEnd('.') + tuple.Item3);
}
Expand Down
33 changes: 31 additions & 2 deletions MMALSharp.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26403.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharp", "MMALSharp\MMALSharp.csproj", "{5B03E4B4-13AA-4EC8-8FD3-9DAA176EAA70}"
ProjectSection(ProjectDependencies) = postProject
Expand All @@ -21,6 +21,19 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharp.FFmpeg", "MMALSha
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharp.Common", "MMALSharp.Common\MMALSharp.Common.csproj", "{D8CA0BC9-CA3B-4EC1-9898-542A6F5346F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharpCore", "MMALSharpCore\MMALSharpCore.csproj", "{B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharpCore.Common", "MMALSharpCore.Common\MMALSharpCore.Common.csproj", "{0DBA7A53-6D52-4825-93CC-BBE785A02DBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharpCore.FFmpeg", "MMALSharpCore.FFmpeg\MMALSharpCore.FFmpeg.csproj", "{0A2AAF93-A749-4C04-BA0F-AA7F19E428C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMALSharpCoreExample", "MMALSharpCoreExample\MMALSharpCoreExample.csproj", "{630219BA-72E1-41A9-8AA7-24D4E0DD7BA1}"
ProjectSection(ProjectDependencies) = postProject
{B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1} = {B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1}
{0DBA7A53-6D52-4825-93CC-BBE785A02DBB} = {0DBA7A53-6D52-4825-93CC-BBE785A02DBB}
{0A2AAF93-A749-4C04-BA0F-AA7F19E428C8} = {0A2AAF93-A749-4C04-BA0F-AA7F19E428C8}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +56,22 @@ Global
{D8CA0BC9-CA3B-4EC1-9898-542A6F5346F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8CA0BC9-CA3B-4EC1-9898-542A6F5346F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8CA0BC9-CA3B-4EC1-9898-542A6F5346F8}.Release|Any CPU.Build.0 = Release|Any CPU
{B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8094B2C-C9D5-4199-9F6B-EDF53B6E4EB1}.Release|Any CPU.Build.0 = Release|Any CPU
{0DBA7A53-6D52-4825-93CC-BBE785A02DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DBA7A53-6D52-4825-93CC-BBE785A02DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DBA7A53-6D52-4825-93CC-BBE785A02DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DBA7A53-6D52-4825-93CC-BBE785A02DBB}.Release|Any CPU.Build.0 = Release|Any CPU
{0A2AAF93-A749-4C04-BA0F-AA7F19E428C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A2AAF93-A749-4C04-BA0F-AA7F19E428C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A2AAF93-A749-4C04-BA0F-AA7F19E428C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A2AAF93-A749-4C04-BA0F-AA7F19E428C8}.Release|Any CPU.Build.0 = Release|Any CPU
{630219BA-72E1-41A9-8AA7-24D4E0DD7BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{630219BA-72E1-41A9-8AA7-24D4E0DD7BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{630219BA-72E1-41A9-8AA7-24D4E0DD7BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{630219BA-72E1-41A9-8AA7-24D4E0DD7BA1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit 9d322f9

Please sign in to comment.