Skip to content

Commit

Permalink
Added support for media clips
Browse files Browse the repository at this point in the history
  • Loading branch information
Leitet committed Oct 7, 2020
1 parent f3ac526 commit 2e27092
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 72 deletions.
25 changes: 13 additions & 12 deletions MediaPool/MediaPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,40 @@ private static void ListMediaPool(MediaPool.Format format, IList<string> args)

Switcher switcher = new Switcher(args[0]);
Log.Debug(String.Format("Switcher: {0}", switcher.GetProductName()));
IList<MediaStill> stills = switcher.GetStills();
IList<MediaSlot> mediaslots = switcher.getMediaSlots();

switch (format)
{
case MediaPool.Format.Text:
foreach (MediaStill still in stills)
foreach (MediaSlot slot in mediaslots)
{
Console.Out.WriteLine();
Console.Out.WriteLine(String.Format(" Name: {0}", still.Name));
Console.Out.WriteLine(String.Format(" Hash: {0}", still.Hash));
Console.Out.WriteLine(String.Format(" Slot: {0}", still.Slot.ToString()));
Console.Out.WriteLine(String.Format(" Media Player: {0}", still.MediaPlayer.ToString()));
Console.Out.WriteLine(String.Format(" Type: {0}", slot.Type));
Console.Out.WriteLine(String.Format(" Name: {0}", slot.Name));
Console.Out.WriteLine(String.Format(" Hash: {0}", slot.Hash));
Console.Out.WriteLine(String.Format(" Slot: {0}", slot.Slot.ToString()));
Console.Out.WriteLine(String.Format(" Media Player: {0}", slot.MediaPlayer.ToString()));
}
break;

case MediaPool.Format.JSON:
Console.Out.WriteLine(JsonConvert.SerializeObject(stills));
Console.Out.WriteLine(JsonConvert.SerializeObject(mediaslots));
break;

case MediaPool.Format.XML:
XmlSerializer xml = new XmlSerializer(stills.GetType());
xml.Serialize(Console.Out, stills);
XmlSerializer xml = new XmlSerializer(mediaslots.GetType());
xml.Serialize(Console.Out, mediaslots);
break;

case MediaPool.Format.CSV:
foreach (MediaStill still in stills)
foreach (MediaSlot slot in mediaslots)
{
Console.Out.WriteLine(still.ToCSV());
Console.Out.WriteLine(slot.ToCSV());
}
break;

default:
Console.Out.WriteLine(stills.ToString());
Console.Out.WriteLine(mediaslots.ToString());
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions MediaPool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jessica Smith")]
[assembly: AssemblyProduct("ATEM Switcher Library")]
[assembly: AssemblyCopyright("© Copyright Jessica Smith, 2014")]
[assembly: AssemblyCopyright("© Copyright Jessica Smith, 2014 & Chris Leitet, 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
6 changes: 3 additions & 3 deletions MediaUpload/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jessica Smith")]
[assembly: AssemblyProduct("ATEM Switcher Library")]
[assembly: AssemblyCopyright("© Copyright Jessica Smith, 2014")]
[assembly: AssemblyCopyright("© Copyright Jessica Smith, 2014 & Chris Leitet, 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
1 change: 1 addition & 0 deletions SwitcherLib/ConsoleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void Version()
AssemblyTitleAttribute title = (AssemblyTitleAttribute)Assembly.GetEntryAssembly().GetCustomAttribute(typeof(AssemblyTitleAttribute));
Console.Out.WriteLine(String.Format("{0} {1}.{2}.{3}", title.Title, version.Major.ToString(), version.Minor.ToString(), version.Revision.ToString()));
Console.Out.WriteLine("Jessica Smith <[email protected]>");
Console.Out.WriteLine("Chris Leitet https://github.com/cleitet");
Console.Out.WriteLine("This software is released under the MIT License");
}
}
Expand Down
80 changes: 45 additions & 35 deletions SwitcherLib/MediaStill.cs → SwitcherLib/MediaSlot.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
using BMDSwitcherAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SwitcherLib
{
public class MediaStill
{
public String Name;
public String Hash;
public int Slot;
public int MediaPlayer;

public MediaStill()
{
}

public MediaStill(IBMDSwitcherStills stills, uint index)
{
BMDSwitcherHash hash;
stills.GetHash(index, out hash);
this.Hash = String.Join("", BitConverter.ToString(hash.data).Split('-'));
stills.GetName(index, out this.Name);
this.Slot = (int)index + 1;
}

public String ToCSV()
{
return String.Join(",", this.Slot.ToString(), "\"" + this.Name + "\"", "\"" + this.Hash + "\"", this.MediaPlayer.ToString());
}
}
}
using BMDSwitcherAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SwitcherLib
{

public class MediaSlot
{
public String Type;
public String Name;
public String Hash;
public int Slot;
public int MediaPlayer;

public MediaSlot(IBMDSwitcherClip clip, uint index)
{
BMDSwitcherHash hash;
// Only getting the hash of the first frame
clip.GetFrameHash(0, out hash);
this.Hash = String.Join("", BitConverter.ToString(hash.data).Split('-'));
clip.GetName(out this.Name);
this.Slot = (int)index + 1;
this.Type = "Clip";
}

public MediaSlot(IBMDSwitcherStills stills, uint index)
{
BMDSwitcherHash hash;
stills.GetHash(index, out hash);
this.Hash = String.Join("", BitConverter.ToString(hash.data).Split('-'));
stills.GetName(index, out this.Name);
this.Slot = (int)index + 1;
this.Type = "Still";
}

public String ToCSV()
{
return String.Join(",", this.Slot.ToString(), "\"" + this.Type + "\"", "\"" + this.Name + "\"", "\"" + this.Hash + "\"", this.MediaPlayer.ToString());
}
}
}
64 changes: 46 additions & 18 deletions SwitcherLib/Switcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BMDSwitcherAPI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -123,49 +124,76 @@ public int GetVideoWidth()
}
}

public IList<MediaStill> GetStills()
public IList<MediaSlot> getMediaSlots()
{
IList<MediaStill> list = new List<MediaStill>();
IList<MediaSlot> list = new List<MediaSlot>();

IBMDSwitcherMediaPool switcherMediaPool = (IBMDSwitcherMediaPool)this.switcher;


// Handling the stills
IBMDSwitcherStills stills;
switcherMediaPool.GetStills(out stills);

uint count;
stills.GetCount(out count);
for (uint index = 0; index < count; index++)
uint stillsCount;
stills.GetCount(out stillsCount);
Log.Debug(string.Format("The unit has {0} stills slots", stillsCount));

for (uint index = 0; index < stillsCount; index++)
{
MediaStill mediaStill = new MediaStill(stills, index);
MediaSlot mediaStill = new MediaSlot(stills, index);
list.Add(mediaStill);
}

// Handling the clips
IBMDSwitcherClip clip;
uint clipCount;
switcherMediaPool.GetClipCount(out clipCount);
Log.Debug(String.Format("The unit has {0} clip slots", clipCount));

for (uint index = 0; index < clipCount; index++)
{
switcherMediaPool.GetClip(index, out clip);
MediaSlot mediaClip = new MediaSlot(clip, index);
list.Add(mediaClip);
}


IntPtr mediaPlayerIteratorPtr;
Guid mediaIteratorIID = typeof(IBMDSwitcherMediaPlayerIterator).GUID;
this.switcher.CreateIterator(ref mediaIteratorIID, out mediaPlayerIteratorPtr);
IBMDSwitcherMediaPlayerIterator mediaPlayerIterator = (IBMDSwitcherMediaPlayerIterator)Marshal.GetObjectForIUnknown(mediaPlayerIteratorPtr);

IBMDSwitcherMediaPlayer mediaPlayer;
mediaPlayerIterator.Next(out mediaPlayer);
int num1 = 1;
int currentMediaPlayerSlot = 1;
while (mediaPlayer != null)
{
_BMDSwitcherMediaPlayerSourceType type;
_BMDSwitcherMediaPlayerSourceType mediaPlayerSourceType;
string mediaPlayerSlotType = "";
uint index;
mediaPlayer.GetSource(out type, out index);
if (type == _BMDSwitcherMediaPlayerSourceType.bmdSwitcherMediaPlayerSourceTypeStill)
mediaPlayer.GetSource(out mediaPlayerSourceType, out index);

if (mediaPlayerSourceType == _BMDSwitcherMediaPlayerSourceType.bmdSwitcherMediaPlayerSourceTypeStill)
{
mediaPlayerSlotType = "Still";
}
else if (mediaPlayerSourceType == _BMDSwitcherMediaPlayerSourceType.bmdSwitcherMediaPlayerSourceTypeClip)
{
int num2 = (int)index + 1;
foreach (MediaStill mediaStill in list)
mediaPlayerSlotType = "Clip";
}

int mediaSlotUsedByMediaPlayer = (int)index + 1;
foreach (MediaSlot mediaSlot in list)
{
if (currentMediaPlayerSlot == mediaSlot.Slot && mediaPlayerSlotType == mediaSlot.Type )
{
if (mediaStill.Slot == num2)
{
mediaStill.MediaPlayer = num1;
break;
}
mediaSlot.MediaPlayer = currentMediaPlayerSlot;
break;
}
}
num1++;

currentMediaPlayerSlot++;
mediaPlayerIterator.Next(out mediaPlayer);
}
return list;
Expand Down
2 changes: 1 addition & 1 deletion SwitcherLib/SwitcherLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
<ItemGroup>
<Compile Include="Callbacks\Frame.cs" />
<Compile Include="Callbacks\UploadLock.cs" />
<Compile Include="MediaSlot.cs" />
<Compile Include="ConsoleUtils.cs" />
<Compile Include="Log.cs" />
<Compile Include="MediaStill.cs" />
<Compile Include="Switcher.cs" />
<Compile Include="Upload.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 2e27092

Please sign in to comment.