Skip to content

Commit

Permalink
Direct3D 11 Video Decoding Support (NV12)
Browse files Browse the repository at this point in the history
Used the already included by Monogame, SharpDX Libraries


Former-commit-id: fce268c
  • Loading branch information
SuRGeoNix committed Jun 3, 2020
1 parent ea53f93 commit c98316d
Show file tree
Hide file tree
Showing 9 changed files with 664 additions and 423 deletions.
272 changes: 138 additions & 134 deletions MediaRouter/Codecs/FFmpeg.cs

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions MediaRouter/MediaRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MediaRouter
ConcurrentQueue<MediaFrame> sFrames;

int AUDIO_MIX_QUEUE_SIZE = 50; int AUDIO_MAX_QUEUE_SIZE = 60;
int VIDEO_MIX_QUEUE_SIZE = 2; int VIDEO_MAX_QUEUE_SIZE = 3;
int VIDEO_MIX_QUEUE_SIZE = 1; int VIDEO_MAX_QUEUE_SIZE = 2;
int SUBS_MIN_QUEUE_SIZE = 5; int SUBS_MAX_QUEUE_SIZE = 10;

// Status
Expand All @@ -54,7 +54,7 @@ enum Status
// Callbacks
public Action AudioResetClbk;
public Action<byte[], int, int> AudioFrameClbk;
public Action<byte[], long, long> VideoFrameClbk;
public Action<byte[], long, IntPtr> VideoFrameClbk;
public Action<string, int> SubFrameClbk;

public Action<bool> OpenTorrentSuccessClbk;
Expand All @@ -81,8 +81,9 @@ enum Status
public long Duration { get; private set; }
public long CurTime { get; private set; }
public int verbosity { get; set; }
public bool HighQuality { get { return decoder.HighQuality; } set { decoder.HighQuality = value; } }
public bool HWAcceleration { get; set; }
public bool HighQuality { get { return decoder.HighQuality; } set { decoder.HighQuality = value; } }
public bool HWAccel { get { return decoder.HWAccel; } set { decoder.HWAccel = value; } }
public bool iSHWAccelSuccess{ get { return decoder.hwAccelSuccess; } }
public long AudioExternalDelay
{
get { return audioExternalDelay; }
Expand Down Expand Up @@ -134,10 +135,10 @@ private void Initialize()
if (vScreamer != null) vScreamer.Abort();
if (sScreamer != null) sScreamer.Abort();

isReady = false;
status = Status.STOPPED;
beforeSeeking = Status.STOPPED;
decoder.HWAcceleration = HWAcceleration;
isReady = false;
status = Status.STOPPED;
beforeSeeking = Status.STOPPED;
decoder.HWAccel = HWAccel;

lock (aFrames) aFrames = new ConcurrentQueue<MediaFrame>();
lock (vFrames) vFrames = new ConcurrentQueue<MediaFrame>();
Expand Down Expand Up @@ -306,7 +307,7 @@ private void VideoScreamer()
// Video Frames [Callback]
CurTime = vFrame.timestamp;
//Log($"[VIDEO SCREAMER] Frame Scream [CurTS: {vFrame.timestamp/10000}] [Clock: {(videoStartTicks + videoClock.ElapsedTicks)/10000} | {CurTime/10000}] [Distance: {(vFrame.timestamp - (videoStartTicks + videoClock.ElapsedTicks))/10000}] [DiffTicks: {vFrame.timestamp - (videoStartTicks + videoClock.ElapsedTicks)}]");
VideoFrameClbk.BeginInvoke(vFrame.data, vFrame.timestamp, distanceTicks, null, null);
VideoFrameClbk.BeginInvoke(vFrame.data, vFrame.timestamp, vFrame.texture, null, null);
}

Log($"[VIDEO SCREAMER] Finished -> {videoStartTicks/10000}");
Expand Down Expand Up @@ -784,7 +785,7 @@ public void Seek(int ms, bool curPos = false)
lock (vFrames) vFrames.TryPeek(out vFrame);
CurTime = vFrame.timestamp;
videoStartTicks = vFrame.timestamp;
VideoFrameClbk.BeginInvoke(vFrame.data, vFrame.timestamp, 0, null, null);
VideoFrameClbk.BeginInvoke(vFrame.data, vFrame.timestamp, vFrame.texture, null, null);
}
if (beforeSeeking == Status.PLAYING)
Expand Down
15 changes: 15 additions & 0 deletions MediaRouter/MediaRouter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
<HintPath>Libraries\Codecs\FFmpeg\FFmpeg.AutoGen.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SharpDX, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\UI Example\Libraries\Monogame\SharpDX.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SharpDX.Direct3D11, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\UI Example\Libraries\Monogame\SharpDX.Direct3D11.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SharpDX.DXGI, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\UI Example\Libraries\Monogame\SharpDX.DXGI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
2 changes: 1 addition & 1 deletion MediaRouter/MediaStreamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public MediaStreamer(int verbosity = 0)
this.verbosity = verbosity;

decoder = new Codecs.FFmpeg(null, verbosity);
decoder.HWAcceleration = false;
decoder.HWAccel = false;
decoder.BufferingDone = BufferingDone;
}
private void Initialize()
Expand Down
5 changes: 4 additions & 1 deletion UI Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Windows.Forms;

namespace PartyTime.UI_Example
{
Expand All @@ -8,9 +9,11 @@ public static class Program
[STAThread]
static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
using (var game = new frmDisplay())
game.Run();
}
}
#endif
}
}
15 changes: 15 additions & 0 deletions UI Example/UI Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@
<HintPath>..\packages\NAudio.1.10.0\lib\net35\NAudio.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SharpDX, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\PartyTime\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SharpDX.Direct3D11, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\PartyTime\packages\SharpDX.Direct3D11.4.2.0\lib\net45\SharpDX.Direct3D11.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SharpDX.DXGI, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\PartyTime\packages\SharpDX.DXGI.4.2.0\lib\net45\SharpDX.DXGI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
Expand Down
Loading

0 comments on commit c98316d

Please sign in to comment.