Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
75ef2dc
Added support to play with initial timestamp.
john-jaraceski-seventh Oct 30, 2020
d5e88a7
Added nuspec file.
john-jaraceski-seventh Oct 30, 2020
41aca42
Merge pull request #1 from seventhltda/release/1.4
john-jaraceski-seventh Oct 30, 2020
c776e70
Initialized parser base date/time with default value.
john-jaraceski-seventh Nov 27, 2020
f2e3293
Merge pull request #2 from seventhltda/release/1.4.1
john-jaraceski-seventh Nov 27, 2020
f1223d3
Corrected base date/time initialization.
john-jaraceski-seventh Dec 13, 2020
d7ee66d
Merge pull request #3 from seventhltda/release/1.4.2
john-jaraceski-seventh Dec 13, 2020
2c9f3df
Implement Header of SDP parser to H265/HEVC codec.
Mar 30, 2021
5031b14
[DGB-6] Correção feita no H264Parser para exibir os PFrames que antes…
Aug 12, 2021
698ac91
[DGB-6] Correct H264Parser to show PFrames that was ignored
Aug 12, 2021
197ef5a
Merge branch 'release/1.4.3' of https://github.com/seventhltda/RtspCl…
Aug 13, 2021
c9bd82a
[DG1395] - Parser and Slicer implementation (few methods yet) / Analy…
Aug 19, 2021
e91d0e3
[DG-1395] Implementation of the VPS, SPS and PPS Parser
Aug 20, 2021
70a49d5
[DG-1395] Fragmentation Unit Decoding implemented / Pack Mode Type ch…
Aug 23, 2021
d7fbb10
[DG-1395] Vps, Sps and Pps parsers implementation
Aug 25, 2021
3dc8c7e
[DG-1395] Trying to decode de FU / Started to create a log textbox to…
Sep 15, 2021
2f2f7a3
Log component created to help in the HEVC's debug process
Sep 17, 2021
3a8188d
Fragmentation Unit successfully reconstructed
Sep 17, 2021
b9cc360
Starting the decode procces / Unit Tests implemented for H265Slicer
Oct 6, 2021
1323bad
Corrected wrong offset increment at ParseFP (H265VideoPayloadParser)
Oct 8, 2021
0c15e87
H265 Working
Oct 15, 2021
f9cc5a8
[DG-1395] H265 Support added
Oct 21, 2021
b047ae8
[DG-1395] - Corrected file conflit and nuget version
Oct 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Examples/SimpleRtspPlayer/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
namespace SimpleRtspPlayer
using SimpleRtspPlayer.GUI.Views;
using System;
using System.Windows;

namespace SimpleRtspPlayer
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
public partial class App : Application
{
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);

//LoggerWindow.Instance.Show();
}
}
}
2 changes: 2 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/RealtimeVideoSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private FFmpegVideoCodecId DetectCodecId(RawVideoFrame videoFrame)
return FFmpegVideoCodecId.MJPEG;
if (videoFrame is RawH264Frame)
return FFmpegVideoCodecId.H264;
if (videoFrame is RawH265Frame)
return FFmpegVideoCodecId.HEVC;

throw new ArgumentOutOfRangeException(nameof(videoFrame));
}
Expand Down
63 changes: 63 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/ViewModels/LoggerWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Logger;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using LoggerWindow = SimpleRtspPlayer.GUI.Views.LoggerWindow;

namespace SimpleRtspPlayer.GUI.ViewModels
{
public unsafe class LoggerWindowViewModel : ViewModelBase
{
private bool _canExecute = true;

public RelayCommand SaveLogToFileCommand { get; }
public RelayCommand ClearLogCommand { get; }

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LogDelegate(byte* data);

public static LogDelegate logDelegate;

public LoggerWindowViewModel()
{
PlayerLogger.fLogMethod = (s) => OnLogUpdated(s);
logDelegate = new LogDelegate(PlayerLogger.LogDllOutput);

SaveLogToFileCommand = new RelayCommand(OnSaveLogToFile, () => _canExecute);
ClearLogCommand = new RelayCommand(OnClearLog, () => _canExecute);
}

private void OnSaveLogToFile()
{
var path = $@"";
var logToSave = SimpleRtspPlayer.GUI.Views.LoggerWindow.Instance.logTextBox.Text;
var appendTextId = $"--------------- LogDate { DateTime.Now.Day }_{ DateTime.Now.Hour}_{ DateTime.Now.Minute}_{ DateTime.Now.Second} ---------------";

StringBuilder sb = new StringBuilder($"{ appendTextId }\n{ logToSave }");

if (!File.Exists(path))
{
File.WriteAllText(path, sb.ToString());
}

File.AppendAllText(path, sb.ToString());
}

private void OnClearLog()
=> LoggerWindow.Instance.logTextBox.Clear();

private void OnLogUpdated(string info)
{
Application.Current.Dispatcher.Invoke(() =>
{
LoggerWindow.Instance.logTextBox.AppendText($"{ info }\n");
LoggerWindow.Instance.logTextBox.CaretIndex = LoggerWindow.Instance.logTextBox.Text.Length;
LoggerWindow.Instance.logTextBox.ScrollToEnd();
});
}
}
}
17 changes: 9 additions & 8 deletions Examples/SimpleRtspPlayer/GUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using GalaSoft.MvvmLight.Command;
using RtspClientSharp;
using SimpleRtspPlayer.GUI.Models;
using System;
using System.ComponentModel;
using System.Net;
using System.Runtime.CompilerServices;
using System.Windows;
using GalaSoft.MvvmLight.Command;
using RtspClientSharp;
using SimpleRtspPlayer.GUI.Models;

namespace SimpleRtspPlayer.GUI.ViewModels
{
Expand All @@ -19,8 +19,9 @@ class MainWindowViewModel : INotifyPropertyChanged
private bool _startButtonEnabled = true;
private bool _stopButtonEnabled;

public string DeviceAddress { get; set; } = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
public LoggerWindowViewModel loggerViewModel;

public string DeviceAddress { get; set; } = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"; //Remove this comment before commit to the remote branch
public string Login { get; set; } = "admin";
public string Password { get; set; } = "123456";

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

StartClickCommand = new RelayCommand(OnStartButtonClick, () => _startButtonEnabled);
StopClickCommand = new RelayCommand(OnStopButtonClick, () => _stopButtonEnabled);
ClosingCommand = new RelayCommand<CancelEventArgs>(OnClosing);
Expand All @@ -71,10 +72,10 @@ private void OnStartButtonClick()

var credential = new NetworkCredential(Login, Password);

var connectionParameters = !string.IsNullOrEmpty(deviceUri.UserInfo) ? new ConnectionParameters(deviceUri) :
var connectionParameters = !string.IsNullOrEmpty(deviceUri.UserInfo) ? new ConnectionParameters(deviceUri) :
new ConnectionParameters(deviceUri, credential);

connectionParameters.RtpTransport = RtpTransportProtocol.UDP;
connectionParameters.RtpTransport = RtpTransportProtocol.TCP;
connectionParameters.CancelTimeout = TimeSpan.FromSeconds(1);

_mainWindowModel.Start(connectionParameters);
Expand Down
25 changes: 25 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/Views/LoggerView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Window x:Class="SimpleRtspPlayer.GUI.Views.LoggerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SimpleRtspPlayer.GUI.Views"
mc:Ignorable="d"
Title="Logger" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>

<TextBox x:Name="logTextBox" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" IsReadOnly="True"/>

</Grid>
</Window>
17 changes: 17 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/Views/LoggerView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Logger;
using System.Windows;

namespace SimpleRtspPlayer.GUI.Views
{
/// <summary>
/// Interaction logic for Logger.xaml
/// </summary>
public partial class LoggerView : Window
{
public LoggerView()
{
InitializeComponent();
PlayerLogger.fLogMethod = (s) => logTextBox.AppendText(s);
}
}
}
30 changes: 30 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/Views/LoggerWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Window x:Class="SimpleRtspPlayer.GUI.Views.LoggerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodels="clr-namespace:SimpleRtspPlayer.GUI.ViewModels"
DataContext="{Binding LoggerWindowViewModel, Source={StaticResource ViewModelLocator}}"
mc:Ignorable="d"
Title="LoggerWindow" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="*" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>

<TextBox x:Name="logTextBox" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" IsReadOnly="True"
HorizontalAlignment="Left" VerticalAlignment="Top" VerticalScrollBarVisibility="Auto" Width="760" Height="350"/>

<StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Save to File" Width="200" Margin="4" Command="{Binding SaveLogToFileCommand}" />
<Button Content="Clear Log" Width="200" Margin="4" Command="{Binding ClearLogCommand}" />
</StackPanel>
</Grid>
</Window>
23 changes: 23 additions & 0 deletions Examples/SimpleRtspPlayer/GUI/Views/LoggerWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Windows;

namespace SimpleRtspPlayer.GUI.Views
{
/// <summary>
/// Interaction logic for LoggerWindow.xaml
/// </summary>
public partial class LoggerWindow
{
public static LoggerWindow Instance { get; private set; }

static LoggerWindow()
{
Instance = new LoggerWindow();
}

private LoggerWindow()
{
InitializeComponent();
}

}
}
8 changes: 6 additions & 2 deletions Examples/SimpleRtspPlayer/GUI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<views:VideoView Grid.Row="0" VideoSource="{Binding VideoSource}" />
<views:VideoView Grid.Column="0" Grid.Row="0" VideoSource="{Binding VideoSource}" />
<Grid Grid.Row="1" Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
Expand Down Expand Up @@ -74,7 +78,7 @@
<Button Content="Start" Width="200" Margin="4" Command="{Binding StartClickCommand}" />
<Button Content="Stop" Width="200" Margin="4" Command="{Binding StopClickCommand}" />
</StackPanel>
<TextBlock Margin="2" Grid.Row="3" Text="Supported codecs: H264/MJPEG; Use &quot;http:&#47;&#47;&quot; prefix in address to connect through HTTP tunnel" />
<TextBlock Margin="2" Grid.Row="3" Text="Supported codecs: H264/H265/MJPEG; Use &quot;http:&#47;&#47;&quot; prefix in address to connect through HTTP tunnel" />
<TextBlock Margin="2" Grid.Row="4" Height="20" Background="LightGray" Text="{Binding Status}" />
</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static FFmpegDecodedVideoScaler Create(DecodedVideoFrameParameters decode
scaledWidth, scaledHeight, scaledFFmpegPixelFormat, scaleQuality, out var handle);

if (resultCode != 0)
throw new DecoderException(@"An error occurred while creating scaler, code: {resultCode}");
throw new DecoderException($"An error occurred while creating scaler, code: {resultCode}");

return new FFmpegDecodedVideoScaler(handle, scaledWidth, scaledHeight, scaledPixelFormat);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ private static FFmpegPixelFormat GetFFmpegPixelFormat(PixelFormat pixelFormat)
return FFmpegPixelFormat.BGRA;
if (pixelFormat == PixelFormat.Grayscale)
return FFmpegPixelFormat.GRAY8;
if (pixelFormat == PixelFormat.Bgr24)
if (pixelFormat == PixelFormat.Bgr24)
return FFmpegPixelFormat.BGR24;

throw new ArgumentOutOfRangeException(nameof(pixelFormat));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using RtspClientSharp.RawFrames.Video;
using SimpleRtspPlayer.RawFramesDecoding.DecodedFrames;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using RtspClientSharp.RawFrames.Video;
using SimpleRtspPlayer.RawFramesDecoding.DecodedFrames;

namespace SimpleRtspPlayer.RawFramesDecoding.FFmpeg
{
Expand Down Expand Up @@ -71,13 +70,39 @@ public unsafe IDecodedVideoFrame TryDecode(RawVideoFrame rawVideoFrame)
}
}
}
else if (rawVideoFrame is RawH265IFrame rawH265IFrame)
{
if (rawH265IFrame.ParametersBytesSegment.Array != null &&
!_extraData.SequenceEqual(rawH265IFrame.ParametersBytesSegment))
{
if (_extraData.Length != rawH265IFrame.ParametersBytesSegment.Count)
_extraData = new byte[rawH265IFrame.ParametersBytesSegment.Count];

Buffer.BlockCopy(rawH265IFrame.ParametersBytesSegment.Array, rawH265IFrame.ParametersBytesSegment.Offset,
_extraData, 0, rawH265IFrame.ParametersBytesSegment.Count);

fixed (byte* initDataPtr = &_extraData[0])
{
resultCode = FFmpegVideoPInvoke.SetVideoDecoderExtraData(_decoderHandle,
(IntPtr)initDataPtr, _extraData.Length);

if (resultCode != 0)
throw new DecoderException(
$"An error occurred while setting video extra data, {_videoCodecId} codec, code: {resultCode}");
}
}
}

char* resultString = null;

resultCode = FFmpegVideoPInvoke.DecodeFrame(_decoderHandle, (IntPtr)rawBufferPtr,
rawVideoFrame.FrameSegment.Count,
out int width, out int height, out FFmpegPixelFormat pixelFormat);

if (resultCode != 0)
return null;
throw new DecoderException(
$"An error occurred while trying to decode the frames, { _videoCodecId } codec, code: { resultCode }");


if (_currentFrameParameters.Width != width || _currentFrameParameters.Height != height ||
_currentFrameParameters.PixelFormat != pixelFormat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

namespace SimpleRtspPlayer.RawFramesDecoding.FFmpeg
{
// enum AVCodecID at https://ffmpeg.org/doxygen/3.2/group__lavc__core.html#gaadca229ad2c20e060a14fec08a5cc7ce
enum FFmpegVideoCodecId
{
MJPEG = 7,
H264 = 27
H264 = 27,
HEVC = 173
}

[Flags]
Expand All @@ -24,6 +26,7 @@ enum FFmpegPixelFormat
None = -1,
BGR24 = 3,
GRAY8 = 8,
YUVJ420P = 12,
BGRA = 28
}

Expand All @@ -45,6 +48,15 @@ static class FFmpegVideoPInvoke
public static extern int DecodeFrame(IntPtr handle, IntPtr rawBuffer, int rawBufferLength, out int frameWidth,
out int frameHeight, out FFmpegPixelFormat framePixelFormat);

[DllImport(LibraryName, EntryPoint = "custom_alloc", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void* Malloc(int buffer_size);

[DllImport(LibraryName, EntryPoint = "free_buff", CallingConvention = CallingConvention.Cdecl)]
public static extern void Free(IntPtr buffer);

[DllImport(LibraryName, EntryPoint = "custom_free", CallingConvention = CallingConvention.Cdecl)]
public static extern void CustomFree(IntPtr buff);

[DllImport(LibraryName, EntryPoint = "scale_decoded_video_frame", CallingConvention = CallingConvention.Cdecl)]
public static extern int ScaleDecodedVideoFrame(IntPtr handle, IntPtr scalerHandle, IntPtr scaledBuffer,
int scaledBufferStride);
Expand Down
Loading