Skip to content

Commit

Permalink
Updating to v3.1 (pre-release)
Browse files Browse the repository at this point in the history
-= Re-coding MediaFramework =-

- Faster disposing and re-opening inputs
- Faster stream switch as it happens while demuxers/decoders are running
- Faster seeking as it happens while demuxers/decoders are running
- Faster cancelation implemenatation (removing aborts completely from MediaFramework)
- Better threading implementation
- Preparing MediaContext for other purposes (such as downloading / recording)

- Fixes compatibility issue with older Windows versions (not tested)
- Fixes #33
- Fixes #34

Public Properties changes (from v3.0)
- DecoderInput removed (just replace it with null)
- SubtitleStreams renamed to SubtitlesStreams


Former-commit-id: ba4cea7
  • Loading branch information
SuRGeoNix committed May 1, 2021
1 parent fceecc6 commit 16d19a4
Show file tree
Hide file tree
Showing 50 changed files with 2,750 additions and 2,621 deletions.
12 changes: 6 additions & 6 deletions FlyleafLib.Controls.WPF/Flyleaf.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@
<MenuItem Header="Down" CommandParameter=" -2" Command="{Binding SetSubsPositionY}"/>
</MenuItem>
<MenuItem Header="Streams">
<MenuItem Header="External" ItemsSource="{Binding Player.Plugins[DefaultExternal].SubtitleStreams}" AlternationCount="{Binding Player.Plugins[DefaultExternal].SubtitleStreams.Count}">
<MenuItem Header="External" ItemsSource="{Binding Player.Plugins[DefaultExternal].SubtitlesStreams}" AlternationCount="{Binding Player.Plugins[DefaultExternal].SubtitlesStreams.Count}">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Command" Value="{Binding DataContext.OpenStream, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}"/>
<Setter Property="CommandParameter" Value="{Binding DataContext, RelativeSource={RelativeSource Self}}"/>
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="IsChecked" Value="{Binding InUse, Mode=OneWay}"/>
<Setter Property="Header" Value="{Binding DecoderInput.Url}"/>
<Setter Property="Header" Value="{Binding Url}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<MenuItem Header="Embedded" ItemsSource="{Binding Player.Plugins[Default].SubtitleStreams}">
<MenuItem Header="Embedded" ItemsSource="{Binding Player.Plugins[Default].SubtitlesStreams}">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Command" Value="{Binding DataContext.OpenStream, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}"/>
Expand All @@ -171,20 +171,20 @@
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" [#{0}] {1}">
<Binding Path="DecoderInput.StreamIndex"/>
<Binding Path="StreamIndex"/>
<Binding Path="Language"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
<MenuItem Header="OpenSubtitles" ItemsSource="{Binding Player.Plugins[OpenSubtitles].SubtitleStreams}">
<MenuItem Header="OpenSubtitles" ItemsSource="{Binding Player.Plugins[OpenSubtitles].SubtitlesStreams}">
<MenuItem.Style>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Player.Plugins[OpenSubtitles].SubtitleStreams}" Value="{x:Null}">
<DataTrigger Binding="{Binding Player.Plugins[OpenSubtitles].SubtitlesStreams}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
Expand Down
10 changes: 4 additions & 6 deletions FlyleafLib.Controls.WPF/Flyleaf.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using MaterialDesignColors;

using FlyleafLib.MediaPlayer;
using FlyleafLib.Plugins.MediaStream;
using FlyleafLib.MediaStream;

namespace FlyleafLib.Controls.WPF
{
Expand Down Expand Up @@ -236,12 +236,11 @@ void RegisterCommands()
Zoom = new RelayCommand(ZoomAction);
}

int curZoom = 0;
public ICommand ZoomReset { get; set; }
public void ZoomResetAction(object obj = null) { curZoom = 0; Player.renderer.Zoom(curZoom); }
public void ZoomResetAction(object obj = null) { Player.renderer.Zoom = 0; }

public ICommand Zoom { get; set; }
public void ZoomAction(object offset) { curZoom += int.Parse(offset.ToString()); Player.renderer.Zoom(curZoom); }
public void ZoomAction(object offset) { Player.renderer.Zoom += int.Parse(offset.ToString()); }

public ICommand TakeSnapshot { get; set; }
public void TakeSnapshotAction(object obj = null) { Player.renderer.TakeSnapshot(System.IO.Path.Combine(Environment.CurrentDirectory,"FlyleafSnapshot.bmp")); }
Expand Down Expand Up @@ -594,8 +593,7 @@ private void Flyleaf_MouseWheel(int delta)
{
if (delta == 0) return;

curZoom += delta > 0 ? 50 : -50;
Player.renderer.Zoom(curZoom);
Player.renderer.Zoom += delta > 0 ? 50 : -50;
}
#endregion

Expand Down
14 changes: 7 additions & 7 deletions FlyleafLib.Controls.WPF/PopUpMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" #{0} ({1}) {2} @{3}Hz [CH: {4}] [Bits: {5}]">
<Binding Path="DecoderInput.StreamIndex"/>
<Binding Path="StreamIndex"/>
<Binding Path="Language"/>
<Binding Path="SampleFormat"/>
<Binding Path="SampleRate"/>
Expand Down Expand Up @@ -265,18 +265,18 @@
<MenuItem Header="Down" CommandParameter=" -2" Command="{Binding SetSubsPositionY}"/>
</MenuItem>
<MenuItem Header="Streams">
<MenuItem Header="External" ItemsSource="{Binding Player.Plugins[DefaultExternal].SubtitleStreams}" AlternationCount="{Binding Player.Plugins[DefaultExternal].SubtitleStreams.Count}">
<MenuItem Header="External" ItemsSource="{Binding Player.Plugins[DefaultExternal].SubtitlesStreams}" AlternationCount="{Binding Player.Plugins[DefaultExternal].SubtitlesStreams.Count}">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Command" Value="{Binding DataContext.OpenStream, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}"/>
<Setter Property="CommandParameter" Value="{Binding DataContext, RelativeSource={RelativeSource Self}}"/>
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="IsChecked" Value="{Binding InUse, Mode=OneWay}"/>
<Setter Property="Header" Value="{Binding DecoderInput.Url}"/>
<Setter Property="Header" Value="{Binding Url}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<MenuItem Header="Embedded" ItemsSource="{Binding Player.Plugins[Default].SubtitleStreams}">
<MenuItem Header="Embedded" ItemsSource="{Binding Player.Plugins[Default].SubtitlesStreams}">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Command" Value="{Binding DataContext.OpenStream, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}"/>
Expand All @@ -290,20 +290,20 @@
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" [#{0}] {1}">
<Binding Path="DecoderInput.StreamIndex"/>
<Binding Path="StreamIndex"/>
<Binding Path="Language"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
<MenuItem Header="OpenSubtitles" ItemsSource="{Binding Player.Plugins[OpenSubtitles].SubtitleStreams}">
<MenuItem Header="OpenSubtitles" ItemsSource="{Binding Player.Plugins[OpenSubtitles].SubtitlesStreams}">
<MenuItem.Style>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Player.Plugins[OpenSubtitles].SubtitleStreams}" Value="{x:Null}">
<DataTrigger Binding="{Binding Player.Plugins[OpenSubtitles].SubtitlesStreams}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
Expand Down
12 changes: 6 additions & 6 deletions FlyleafLib.Plugins.BitSwarm/BitSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;

using FlyleafLib.MediaPlayer;
using FlyleafLib.Plugins.MediaStream;
using FlyleafLib.MediaStream;
using SuRGeoNix.BitSwarmLib;
using SuRGeoNix.BitSwarmLib.BEP;

Expand Down Expand Up @@ -41,7 +41,7 @@ public class BitSwarm : PluginBase, IPluginVideo
public override void OnInitializing()
{
if (Player.curVideoPlugin == null || Player.curVideoPlugin.PluginName != PluginName) return;
if (Session.CurVideoStream != null && Session.CurVideoStream.DecoderInput.Stream is TorrentStream) ((TorrentStream)Session.CurVideoStream.DecoderInput.Stream).Cancel();
if (Session.CurVideoStream != null && Session.CurVideoStream.Stream is TorrentStream) ((TorrentStream)Session.CurVideoStream.Stream).Cancel();

try
{
Expand All @@ -62,7 +62,7 @@ public override void OnInitializing()
public override void OnInitializingSwitch()
{
if (Player.curVideoPlugin == null || Player.curVideoPlugin.PluginName != PluginName) return;
if (Session.CurVideoStream != null && Session.CurVideoStream.DecoderInput.Stream is TorrentStream) ((TorrentStream)Session.CurVideoStream.DecoderInput.Stream).Cancel();
if (Session.CurVideoStream != null && Session.CurVideoStream.Stream is TorrentStream) ((TorrentStream)Session.CurVideoStream.Stream).Cancel();
if (cfg != null) cfg.EnableBuffering = false;
}

Expand Down Expand Up @@ -145,14 +145,14 @@ public VideoStream GetVideoStream(VideoStream stream)

if (!Downloaded)
{
stream.DecoderInput.Stream = Torrent.GetTorrentStream(FileName);
stream.Stream = Torrent.GetTorrentStream(FileName);
bitSwarm.IncludeFiles(new List<string>() { FileName });
if (!bitSwarm.isRunning) { Log("Starting"); bitSwarm.Start(); }
}
else if (File.Exists(Path.Combine(FolderComplete, FileName)))
{
stream.DecoderInput.Stream = null;
stream.DecoderInput.Url = Path.Combine(FolderComplete, FileName);
stream.Stream = null;
stream.Url = Path.Combine(FolderComplete, FileName);

if (!DownloadNext()) { Log("Pausing"); bitSwarm.Pause(); }
}
Expand Down
24 changes: 12 additions & 12 deletions FlyleafLib.Plugins.OpenSubtitles/OpenSubtitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Newtonsoft.Json;

using FlyleafLib.MediaPlayer;
using FlyleafLib.Plugins.MediaStream;
using FlyleafLib.MediaStream;

namespace FlyleafLib.Plugins
{
Expand Down Expand Up @@ -228,7 +228,7 @@ orderby float.Parse(sub.SubRating) descending
}

foreach(var sub in subs)
SubtitleStreams.Add(new SubtitleStream()
SubtitlesStreams.Add(new SubtitlesStream()
{
UrlName = sub.SubFileName,
Rating = sub.SubRating,
Expand Down Expand Up @@ -257,45 +257,45 @@ public void Search(Language lang)

string hash = null;
if (Player.Session.Movie.FileSize != 0)
if (Session.CurVideoStream != null && Session.CurVideoStream.DecoderInput.Stream != null)
if (Session.CurVideoStream != null && Session.CurVideoStream.Stream != null)
{
var savePos = Session.CurVideoStream.DecoderInput.Stream.Position;
hash = Utils.ToHexadecimal(ComputeMovieHash(Session.CurVideoStream.DecoderInput.Stream, Player.Session.Movie.FileSize));
Session.CurVideoStream.DecoderInput.Stream.Position = savePos;
var savePos = Session.CurVideoStream.Stream.Position;
hash = Utils.ToHexadecimal(ComputeMovieHash(Session.CurVideoStream.Stream, Player.Session.Movie.FileSize));
Session.CurVideoStream.Stream.Position = savePos;
}
else
hash = Utils.ToHexadecimal(ComputeMovieHash(Player.Session.Movie.Url));

Search(Player.Session.Movie.Title, hash, Player.Session.Movie.FileSize, Player.Config.subs.Languages);
}

public bool Download(SubtitleStream stream)
public bool Download(SubtitlesStream stream)
{
if (stream.Tag == null || !(stream.Tag is OpenSubtitlesJson)) return false;

var sub = (OpenSubtitlesJson) stream.Tag;
if (sub.Download() != 0) return false;

stream.DecoderInput.Url = sub.AvailableAt;
stream.Url = sub.AvailableAt;

return true;
}

SubtitleStream IPluginSubtitles.OpenSubtitles(Language lang)
SubtitlesStream IPluginSubtitles.OpenSubtitles(Language lang)
{
foreach(var stream in SubtitleStreams)
foreach(var stream in SubtitlesStreams)
if (stream.Language == lang) return stream;

return null;
}

SubtitleStream IPluginSubtitles.OpenSubtitles(SubtitleStream stream)
SubtitlesStream IPluginSubtitles.OpenSubtitles(SubtitlesStream stream)
{
if (stream.Tag == null || !(stream.Tag is OpenSubtitlesJson)) return null;

return stream;
}

static void Log(string msg) { Console.WriteLine($"[{DateTime.Now.ToString("hh.mm.ss.fff")}] [OpenSubtitles] {msg}"); }
internal static void Log(string msg) { Console.WriteLine($"[{DateTime.Now.ToString("hh.mm.ss.fff")}] [OpenSubtitles] {msg}"); }
}
}
Loading

0 comments on commit 16d19a4

Please sign in to comment.