Skip to content

Commit 89ff04e

Browse files
author
Bogdanov Kirill
committed
RTP/RTCP over UDP transport is added
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.
1 parent ae139f9 commit 89ff04e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1331
-332
lines changed

Examples/SimpleRtspClient/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void Main()
2424

2525
cancellationTokenSource.Cancel();
2626

27-
Console.WriteLine("Cancelling");
27+
Console.WriteLine("Canceling");
2828
connectTask.Wait(CancellationToken.None);
2929
}
3030

@@ -47,6 +47,10 @@ private static async Task ConnectAsync(ConnectionParameters connectionParameters
4747
{
4848
await rtspClient.ConnectAsync(token);
4949
}
50+
catch (OperationCanceledException)
51+
{
52+
return;
53+
}
5054
catch (RtspClientException e)
5155
{
5256
Console.WriteLine(e.ToString());
@@ -60,6 +64,10 @@ private static async Task ConnectAsync(ConnectionParameters connectionParameters
6064
{
6165
await rtspClient.ReceiveAsync(token);
6266
}
67+
catch (OperationCanceledException)
68+
{
69+
return;
70+
}
6371
catch (RtspClientException e)
6472
{
6573
Console.WriteLine(e.ToString());

Examples/SimpleRtspPlayer/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Application x:Class="SimpleRtspPlayer.App"
1+
<Application x:Class="SimpleRtspPlayer.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:simpleRtspPlayer="clr-namespace:SimpleRtspPlayer"

Examples/SimpleRtspPlayer/GUI/Commands/CommandHandler.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

Examples/SimpleRtspPlayer/GUI/Models/MainWindowModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class MainWindowModel : IMainWindowModel
1515

1616
public void Start(ConnectionParameters connectionParameters)
1717
{
18+
if (_rawFramesSource != null)
19+
return;
20+
1821
_rawFramesSource = new RawFramesSource(connectionParameters);
1922
_rawFramesSource.ConnectionStatusChanged += ConnectionStatusChanged;
2023

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

2629
public void Stop()
2730
{
31+
if (_rawFramesSource == null)
32+
return;
33+
2834
_rawFramesSource.Stop();
2935
_realtimeVideoSource.SetRawFramesSource(null);
36+
_rawFramesSource = null;
3037
}
3138

3239
private void ConnectionStatusChanged(object sender, string s)

Examples/SimpleRtspPlayer/GUI/ViewModels/MainWindowViewModel.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
using System.Net;
44
using System.Runtime.CompilerServices;
55
using System.Windows;
6-
using System.Windows.Input;
6+
using GalaSoft.MvvmLight.Command;
77
using RtspClientSharp;
8-
using SimpleRtspPlayer.GUI.Commands;
98
using SimpleRtspPlayer.GUI.Models;
109

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

1817
private string _status = string.Empty;
1918
private readonly IMainWindowModel _mainWindowModel;
19+
private bool _startButtonEnabled = true;
20+
private bool _stopButtonEnabled;
2021

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

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

2627
public IVideoSource VideoSource => _mainWindowModel.VideoSource;
2728

28-
private readonly CommandHandler _startClickCommand;
29-
public ICommand StartClickCommand => _startClickCommand;
30-
31-
private readonly CommandHandler _stopClickCommand;
32-
public ICommand StopClickCommand => _stopClickCommand;
29+
public RelayCommand StartClickCommand { get; }
30+
public RelayCommand StopClickCommand { get; }
31+
public RelayCommand<CancelEventArgs> ClosingCommand { get; }
3332

3433
public string Status
3534
{
@@ -46,9 +45,10 @@ public string Status
4645
public MainWindowViewModel(IMainWindowModel mainWindowModel)
4746
{
4847
_mainWindowModel = mainWindowModel ?? throw new ArgumentNullException(nameof(mainWindowModel));
49-
50-
_startClickCommand = new CommandHandler(OnStartButtonClick, true);
51-
_stopClickCommand = new CommandHandler(OnStopButtonClick, false);
48+
49+
StartClickCommand = new RelayCommand(OnStartButtonClick, () => _startButtonEnabled);
50+
StopClickCommand = new RelayCommand(OnStopButtonClick, () => _stopButtonEnabled);
51+
ClosingCommand = new RelayCommand<CancelEventArgs>(OnClosing);
5252
}
5353

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

7272
var credential = new NetworkCredential(Login, Password);
7373
var connectionParameters = new ConnectionParameters(deviceUri, credential);
74-
74+
connectionParameters.RtpTransport = RtpTransportProtocol.UDP;
7575
_mainWindowModel.Start(connectionParameters);
7676
_mainWindowModel.StatusChanged += MainWindowModelOnStatusChanged;
7777

78-
_startClickCommand.SetCanExecute(false);
79-
_stopClickCommand.SetCanExecute(true);
78+
_startButtonEnabled = false;
79+
StartClickCommand.RaiseCanExecuteChanged();
80+
_stopButtonEnabled = true;
81+
StopClickCommand.RaiseCanExecuteChanged();
8082
}
8183

8284
private void OnStopButtonClick()
8385
{
8486
_mainWindowModel.Stop();
8587
_mainWindowModel.StatusChanged -= MainWindowModelOnStatusChanged;
8688

87-
_stopClickCommand.SetCanExecute(false);
88-
_startClickCommand.SetCanExecute(true);
89+
_stopButtonEnabled = false;
90+
StopClickCommand.RaiseCanExecuteChanged();
91+
_startButtonEnabled = true;
92+
StartClickCommand.RaiseCanExecuteChanged();
8993
Status = string.Empty;
9094
}
9195

9296
private void MainWindowModelOnStatusChanged(object sender, string s)
9397
{
9498
Application.Current.Dispatcher.Invoke(() => Status = s);
9599
}
100+
101+
private void OnClosing(CancelEventArgs args)
102+
{
103+
_mainWindowModel.Stop();
104+
}
96105
}
97106
}

Examples/SimpleRtspPlayer/GUI/Views/MainWindow.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:gui="clr-namespace:SimpleRtspPlayer.GUI"
77
xmlns:views="clr-namespace:SimpleRtspPlayer.GUI.Views"
8+
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
9+
xmlns:command="http://www.galasoft.ch/mvvmlight"
810
mc:Ignorable="d"
911
Title="SimpleRtspPlayer" Width="1200" Height="675" MinWidth="16" MinHeight="16"
1012
WindowStartupLocation="CenterScreen"
@@ -26,6 +28,11 @@
2628
</Style.Triggers>
2729
</Style>
2830
</Window.Resources>
31+
<i:Interaction.Triggers>
32+
<i:EventTrigger EventName="Closing">
33+
<command:EventToCommand Command="{Binding ClosingCommand}" PassEventArgsToCommand="True" />
34+
</i:EventTrigger>
35+
</i:Interaction.Triggers>
2936
<Grid>
3037
<Grid.RowDefinitions>
3138
<RowDefinition Height="*" />

Examples/SimpleRtspPlayer/GUI/Views/VideoView.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public partial class VideoView
2626
private int _height;
2727
private Int32Rect _dirtyRect;
2828
private readonly Action<IDecodedVideoFrame> _invalidateAction;
29+
private DispatcherOperation _invalidateOperation;
2930

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

142143
private void OnFrameReceived(object sender, IDecodedVideoFrame decodedFrame)
143144
{
144-
Application.Current.Dispatcher.Invoke(_invalidateAction, DispatcherPriority.Send, decodedFrame);
145+
if(_invalidateOperation != null && _invalidateOperation.Status != DispatcherOperationStatus.Completed)
146+
return;
147+
148+
_invalidateOperation = Application.Current.Dispatcher.BeginInvoke(_invalidateAction, DispatcherPriority.Send, decodedFrame);
145149
}
146150

147151
private void Invalidate(IDecodedVideoFrame decodedVideoFrame)

Examples/SimpleRtspPlayer/SimpleRtspPlayer.csproj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,24 @@
3636
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3737
</PropertyGroup>
3838
<ItemGroup>
39+
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
40+
<HintPath>..\..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
41+
</Reference>
42+
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
43+
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
44+
</Reference>
45+
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
46+
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
47+
</Reference>
48+
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
49+
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
50+
</Reference>
3951
<Reference Include="System" />
4052
<Reference Include="System.Data" />
4153
<Reference Include="System.Drawing" />
54+
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
55+
<HintPath>..\..\packages\MvvmLightLibs.5.4.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
56+
</Reference>
4257
<Reference Include="System.Xml" />
4358
<Reference Include="Microsoft.CSharp" />
4459
<Reference Include="System.Core" />
@@ -58,7 +73,6 @@
5873
<SubType>Designer</SubType>
5974
</ApplicationDefinition>
6075
<Compile Include="GUI\AddressValidationRule.cs" />
61-
<Compile Include="GUI\Commands\CommandHandler.cs" />
6276
<Compile Include="GUI\Models\IMainWindowModel.cs" />
6377
<Compile Include="GUI\Models\MainWindowModel.cs" />
6478
<Compile Include="RawFramesDecoding\DecodedFrames\DecodedVideoFrame.cs" />
@@ -118,6 +132,7 @@
118132
<Generator>ResXFileCodeGenerator</Generator>
119133
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
120134
</EmbeddedResource>
135+
<None Include="packages.config" />
121136
<None Include="Properties\Settings.settings">
122137
<Generator>SettingsSingleFileGenerator</Generator>
123138
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net461" />
4+
<package id="MvvmLight" version="5.4.1" targetFramework="net461" />
5+
<package id="MvvmLightLibs" version="5.4.1" targetFramework="net461" />
6+
</packages>

0 commit comments

Comments
 (0)