Skip to content

Commit

Permalink
RTP/RTCP over UDP transport is added
Browse files Browse the repository at this point in the history
Now it is possible to choose transport protocol for RTP/RTCP in connection parameters. See "RtpTransport" property in ConnectionParameters class.
Also several bug fixes and small improvements were made.
  • Loading branch information
Bogdanov Kirill committed Aug 11, 2018
1 parent ae139f9 commit 89ff04e
Show file tree
Hide file tree
Showing 47 changed files with 1,331 additions and 332 deletions.
10 changes: 9 additions & 1 deletion Examples/SimpleRtspClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void Main()

cancellationTokenSource.Cancel();

Console.WriteLine("Cancelling");
Console.WriteLine("Canceling");
connectTask.Wait(CancellationToken.None);
}

Expand All @@ -47,6 +47,10 @@ private static async Task ConnectAsync(ConnectionParameters connectionParameters
{
await rtspClient.ConnectAsync(token);
}
catch (OperationCanceledException)
{
return;
}
catch (RtspClientException e)
{
Console.WriteLine(e.ToString());
Expand All @@ -60,6 +64,10 @@ private static async Task ConnectAsync(ConnectionParameters connectionParameters
{
await rtspClient.ReceiveAsync(token);
}
catch (OperationCanceledException)
{
return;
}
catch (RtspClientException e)
{
Console.WriteLine(e.ToString());
Expand Down
2 changes: 1 addition & 1 deletion Examples/SimpleRtspPlayer/App.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Application x:Class="SimpleRtspPlayer.App"
<Application x:Class="SimpleRtspPlayer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:simpleRtspPlayer="clr-namespace:SimpleRtspPlayer"
Expand Down
35 changes: 0 additions & 35 deletions Examples/SimpleRtspPlayer/GUI/Commands/CommandHandler.cs

This file was deleted.

7 changes: 7 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/Models/MainWindowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class MainWindowModel : IMainWindowModel

public void Start(ConnectionParameters connectionParameters)
{
if (_rawFramesSource != null)
return;

_rawFramesSource = new RawFramesSource(connectionParameters);
_rawFramesSource.ConnectionStatusChanged += ConnectionStatusChanged;

Expand All @@ -25,8 +28,12 @@ public void Start(ConnectionParameters connectionParameters)

public void Stop()
{
if (_rawFramesSource == null)
return;

_rawFramesSource.Stop();
_realtimeVideoSource.SetRawFramesSource(null);
_rawFramesSource = null;
}

private void ConnectionStatusChanged(object sender, string s)
Expand Down
39 changes: 24 additions & 15 deletions Examples/SimpleRtspPlayer/GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
using System.Net;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using RtspClientSharp;
using SimpleRtspPlayer.GUI.Commands;
using SimpleRtspPlayer.GUI.Models;

namespace SimpleRtspPlayer.GUI.ViewModels
Expand All @@ -17,6 +16,8 @@ class MainWindowViewModel : INotifyPropertyChanged

private string _status = string.Empty;
private readonly IMainWindowModel _mainWindowModel;
private bool _startButtonEnabled = true;
private bool _stopButtonEnabled;

public string DeviceAddress { get; set; } = "rtsp://192.168.1.77:554/ucast/11";

Expand All @@ -25,11 +26,9 @@ class MainWindowViewModel : INotifyPropertyChanged

public IVideoSource VideoSource => _mainWindowModel.VideoSource;

private readonly CommandHandler _startClickCommand;
public ICommand StartClickCommand => _startClickCommand;

private readonly CommandHandler _stopClickCommand;
public ICommand StopClickCommand => _stopClickCommand;
public RelayCommand StartClickCommand { get; }
public RelayCommand StopClickCommand { get; }
public RelayCommand<CancelEventArgs> ClosingCommand { get; }

public string Status
{
Expand All @@ -46,9 +45,10 @@ public string Status
public MainWindowViewModel(IMainWindowModel mainWindowModel)
{
_mainWindowModel = mainWindowModel ?? throw new ArgumentNullException(nameof(mainWindowModel));

_startClickCommand = new CommandHandler(OnStartButtonClick, true);
_stopClickCommand = new CommandHandler(OnStopButtonClick, false);

StartClickCommand = new RelayCommand(OnStartButtonClick, () => _startButtonEnabled);
StopClickCommand = new RelayCommand(OnStopButtonClick, () => _stopButtonEnabled);
ClosingCommand = new RelayCommand<CancelEventArgs>(OnClosing);
}

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
Expand All @@ -71,27 +71,36 @@ private void OnStartButtonClick()

var credential = new NetworkCredential(Login, Password);
var connectionParameters = new ConnectionParameters(deviceUri, credential);

connectionParameters.RtpTransport = RtpTransportProtocol.UDP;
_mainWindowModel.Start(connectionParameters);
_mainWindowModel.StatusChanged += MainWindowModelOnStatusChanged;

_startClickCommand.SetCanExecute(false);
_stopClickCommand.SetCanExecute(true);
_startButtonEnabled = false;
StartClickCommand.RaiseCanExecuteChanged();
_stopButtonEnabled = true;
StopClickCommand.RaiseCanExecuteChanged();
}

private void OnStopButtonClick()
{
_mainWindowModel.Stop();
_mainWindowModel.StatusChanged -= MainWindowModelOnStatusChanged;

_stopClickCommand.SetCanExecute(false);
_startClickCommand.SetCanExecute(true);
_stopButtonEnabled = false;
StopClickCommand.RaiseCanExecuteChanged();
_startButtonEnabled = true;
StartClickCommand.RaiseCanExecuteChanged();
Status = string.Empty;
}

private void MainWindowModelOnStatusChanged(object sender, string s)
{
Application.Current.Dispatcher.Invoke(() => Status = s);
}

private void OnClosing(CancelEventArgs args)
{
_mainWindowModel.Stop();
}
}
}
7 changes: 7 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:gui="clr-namespace:SimpleRtspPlayer.GUI"
xmlns:views="clr-namespace:SimpleRtspPlayer.GUI.Views"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
mc:Ignorable="d"
Title="SimpleRtspPlayer" Width="1200" Height="675" MinWidth="16" MinHeight="16"
WindowStartupLocation="CenterScreen"
Expand All @@ -26,6 +28,11 @@
</Style.Triggers>
</Style>
</Window.Resources>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<command:EventToCommand Command="{Binding ClosingCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
Expand Down
6 changes: 5 additions & 1 deletion Examples/SimpleRtspPlayer/GUI/Views/VideoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class VideoView
private int _height;
private Int32Rect _dirtyRect;
private readonly Action<IDecodedVideoFrame> _invalidateAction;
private DispatcherOperation _invalidateOperation;

private Task _handleSizeChangedTask = Task.CompletedTask;
private CancellationTokenSource _resizeCancellationTokenSource = new CancellationTokenSource();
Expand Down Expand Up @@ -141,7 +142,10 @@ private static void OnVideoSourceChanged(DependencyObject d, DependencyPropertyC

private void OnFrameReceived(object sender, IDecodedVideoFrame decodedFrame)
{
Application.Current.Dispatcher.Invoke(_invalidateAction, DispatcherPriority.Send, decodedFrame);
if(_invalidateOperation != null && _invalidateOperation.Status != DispatcherOperationStatus.Completed)
return;

_invalidateOperation = Application.Current.Dispatcher.BeginInvoke(_invalidateAction, DispatcherPriority.Send, decodedFrame);
}

private void Invalidate(IDecodedVideoFrame decodedVideoFrame)
Expand Down
17 changes: 16 additions & 1 deletion Examples/SimpleRtspPlayer/SimpleRtspPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,24 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -58,7 +73,6 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="GUI\AddressValidationRule.cs" />
<Compile Include="GUI\Commands\CommandHandler.cs" />
<Compile Include="GUI\Models\IMainWindowModel.cs" />
<Compile Include="GUI\Models\MainWindowModel.cs" />
<Compile Include="RawFramesDecoding\DecodedFrames\DecodedVideoFrame.cs" />
Expand Down Expand Up @@ -118,6 +132,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
6 changes: 6 additions & 0 deletions Examples/SimpleRtspPlayer/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net461" />
<package id="MvvmLight" version="5.4.1" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.4.1" targetFramework="net461" />
</packages>
Loading

0 comments on commit 89ff04e

Please sign in to comment.