-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes and performance optimizations
-H264 parsing speed is increased (avoid constant memory copying when possible) -Small performance optimizations are made in general -Multi-threaded bugs are fixed -Fixed bug in RTSP over TCP when on some cameras were constant receive timeouts -RTCP reports minimum delay is increased up to 5 seconds to match RFC 3550 -New example project is added (JPEG snapshots maker)
- Loading branch information
Bogdanov Kirill
committed
Aug 12, 2018
1 parent
f80a36b
commit 78ad2c6
Showing
29 changed files
with
495 additions
and
235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
</configuration> |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{B8041875-F622-4B41-A727-CC4F2B227182}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>MjpegSnapshotsMaker</RootNamespace> | ||
<AssemblyName>MjpegSnapshotsMaker</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\CommandLineParser.2.2.1\lib\net45\CommandLine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.ComponentModel.Composition" /> | ||
<Reference Include="System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Console.4.0.0\lib\net46\System.Console.dll</HintPath> | ||
<Private>True</Private> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Reflection.TypeExtensions.4.1.0\lib\net46\System.Reflection.TypeExtensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\RtspClientSharp\RtspClientSharp.csproj"> | ||
<Project>{dc94331f-847e-4456-bd27-f147551750fb}</Project> | ||
<Name>RtspClientSharp</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using CommandLine; | ||
using RtspClientSharp; | ||
using RtspClientSharp.RawFrames.Video; | ||
|
||
namespace MjpegSnapshotsMaker | ||
{ | ||
class Program | ||
{ | ||
public class Options | ||
{ | ||
[Option('u', "uri", Required = true, HelpText = "RTSP URI")] | ||
public Uri Uri { get; set; } | ||
|
||
[Option('p', "path", Required = true, HelpText = "Path where snapshots should be saved")] | ||
public string Path { get; set; } | ||
|
||
[Option('i', "interval", Required = false, HelpText = "Snapshots saving interval in seconds")] | ||
public int Interval { get; set; } = 5; | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
Parser.Default.ParseArguments<Options>(args) | ||
.WithParsed(options => | ||
{ | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
|
||
Task makeSnapshotsTask = MakeSnapshotsAsync(options, cancellationTokenSource.Token); | ||
|
||
Console.ReadKey(); | ||
|
||
cancellationTokenSource.Cancel(); | ||
makeSnapshotsTask.Wait(); | ||
}) | ||
.WithNotParsed(options => | ||
{ | ||
Console.WriteLine("Usage example: MjpegSnapshotsMaker.exe " + | ||
"-u rtsp://admin:[email protected]:554/ucast/11 " + | ||
"-p S:\\Temp"); | ||
}); | ||
} | ||
|
||
private static async Task MakeSnapshotsAsync(Options options, CancellationToken token) | ||
{ | ||
try | ||
{ | ||
if (!Directory.Exists(options.Path)) | ||
Directory.CreateDirectory(options.Path); | ||
|
||
int intervalMs = options.Interval * 1000; | ||
int lastTimeSnapshotSaved = Environment.TickCount - intervalMs; | ||
|
||
var connectionParameters = new ConnectionParameters(options.Uri); | ||
using (var rtspClient = new RtspClient(connectionParameters)) | ||
{ | ||
rtspClient.FrameReceived += (sender, frame) => | ||
{ | ||
if (!(frame is RawJpegFrame)) | ||
return; | ||
|
||
int ticksNow = Environment.TickCount; | ||
|
||
if (Math.Abs(ticksNow - lastTimeSnapshotSaved) < intervalMs) | ||
return; | ||
|
||
lastTimeSnapshotSaved = ticksNow; | ||
|
||
string snapshotName = frame.Timestamp.ToString("O").Replace(":", "_") + ".jpg"; | ||
string path = Path.Combine(options.Path, snapshotName); | ||
|
||
ArraySegment<byte> frameSegment = frame.FrameSegment; | ||
|
||
using (var stream = File.OpenWrite(path)) | ||
stream.Write(frameSegment.Array, frameSegment.Offset, frameSegment.Count); | ||
|
||
Console.WriteLine($"[{DateTime.UtcNow}] Snapshot is saved to {snapshotName}"); | ||
}; | ||
|
||
Console.WriteLine("Connecting..."); | ||
await rtspClient.ConnectAsync(token); | ||
Console.WriteLine("Receiving..."); | ||
await rtspClient.ReceiveAsync(token); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e.ToString()); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("MjpegSnapshotsMaker")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("MjpegSnapshotsMaker")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("b8041875-f622-4b41-a727-cc4f2b227182")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<packages> | ||
<package id="CommandLineParser" version="2.2.1" targetFramework="net461" /> | ||
<package id="System.Collections" version="4.0.11" targetFramework="net461" /> | ||
<package id="System.Console" version="4.0.0" targetFramework="net461" /> | ||
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net461" /> | ||
<package id="System.Globalization" version="4.0.11" targetFramework="net461" /> | ||
<package id="System.IO" version="4.1.0" targetFramework="net461" /> | ||
<package id="System.Linq" version="4.1.0" targetFramework="net461" /> | ||
<package id="System.Linq.Expressions" version="4.1.0" targetFramework="net461" /> | ||
<package id="System.Reflection" version="4.1.0" targetFramework="net461" /> | ||
<package id="System.Reflection.Extensions" version="4.0.1" targetFramework="net461" /> | ||
<package id="System.Reflection.TypeExtensions" version="4.1.0" targetFramework="net461" /> | ||
<package id="System.Resources.ResourceManager" version="4.0.1" targetFramework="net461" /> | ||
<package id="System.Runtime" version="4.1.0" targetFramework="net461" /> | ||
<package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net461" /> | ||
</packages> |
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
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
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
Oops, something went wrong.