Introduce CVideoStream for easier video handling (already includes a texture, important for common usage of streams)
This commit is contained in:
1 parent
89e528c2a6
commit
6a3bf7b2c0
15 files changed
+204
-168
No files matched your search
@@ -0,0 +1,45 @@
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
namespace VocaluxeLib
|
||||
{
|
||||
public class CVideoStream
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
public CTextureRef Texture;
|
||||
/// The actual position in s of the returned frame. Should be ~ time+VideoGap
|
||||
public float VideoTime;
|
||||
|
||||
public CVideoStream(int id)
|
||||
{
|
||||
ID = id;
|
||||
}
|
||||
|
||||
~CVideoStream()
|
||||
{
|
||||
if (ID >= 0)
|
||||
{
|
||||
CVideoStream tmp = this;
|
||||
CBase.Video.Close(ref tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should only be used by video decoders<br />
|
||||
/// Set's this stream to closed state and frees the texture
|
||||
/// </summary>
|
||||
public void SetClosed()
|
||||
{
|
||||
ID = -1;
|
||||
CBase.Drawing.RemoveTexture(ref Texture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the video stream is closed
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsClosed()
|
||||
{
|
||||
return ID < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace VocaluxeLib
|
||||
string GetThemeScreensPath(int partyModeID);
|
||||
int GetSkinIndex(int partyModeID);
|
||||
CTextureRef GetSkinTexture(string textureName, int partyModeID);
|
||||
int GetSkinVideo(string videoName, int partyModeID, bool loop);
|
||||
CVideoStream GetSkinVideo(string videoName, int partyModeID, bool loop);
|
||||
|
||||
bool GetColor(string colorName, int partyModeID, out SColorF color);
|
||||
SColorF GetPlayerColor(int playerNr);
|
||||
@@ -264,14 +264,14 @@ namespace VocaluxeLib
|
||||
|
||||
public interface IVideo
|
||||
{
|
||||
int Load(string videoFileName);
|
||||
bool Skip(int streamID, float startPosition, float videoGap);
|
||||
bool GetFrame(int streamID, ref CTextureRef videoTexture, float time, out float videoTime);
|
||||
bool IsFinished(int streamID);
|
||||
bool Close(int streamID);
|
||||
void SetLoop(int streamID, bool loop = true);
|
||||
void Resume(int streamID);
|
||||
void Pause(int streamID);
|
||||
CVideoStream Load(string videoFileName);
|
||||
bool Skip(CVideoStream stream, float startPosition, float videoGap);
|
||||
bool GetFrame(CVideoStream stream, float time);
|
||||
bool IsFinished(CVideoStream stream);
|
||||
void Close(ref CVideoStream stream);
|
||||
void SetLoop(CVideoStream stream, bool loop = true);
|
||||
void Resume(CVideoStream stream);
|
||||
void Pause(CVideoStream stream);
|
||||
}
|
||||
|
||||
public interface ISound
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
@@ -54,8 +53,7 @@ namespace VocaluxeLib.Menu
|
||||
private readonly Stopwatch _SlideShowTimer = new Stopwatch();
|
||||
private readonly List<CTextureRef> _SlideShowTextures = new List<CTextureRef>();
|
||||
|
||||
private int _VideoStream = -1;
|
||||
private CTextureRef _VidTex;
|
||||
private CVideoStream _VideoStream;
|
||||
|
||||
public SColorF Color;
|
||||
public bool ThemeLoaded
|
||||
@@ -136,13 +134,13 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
if (_VideoStream != -1)
|
||||
if (_VideoStream != null)
|
||||
CBase.Video.Resume(_VideoStream);
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (_VideoStream != -1)
|
||||
if (_VideoStream != null)
|
||||
CBase.Video.Pause(_VideoStream);
|
||||
}
|
||||
|
||||
@@ -176,9 +174,7 @@ namespace VocaluxeLib.Menu
|
||||
public void UnloadTextures()
|
||||
{
|
||||
_SlideShowTextures.Clear();
|
||||
CBase.Video.Close(_VideoStream);
|
||||
_VideoStream = -1;
|
||||
CBase.Drawing.RemoveTexture(ref _VidTex);
|
||||
CBase.Video.Close(ref _VideoStream);
|
||||
}
|
||||
|
||||
public void LoadTextures()
|
||||
@@ -299,11 +295,10 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
private bool _DrawVideo()
|
||||
{
|
||||
float time;
|
||||
CBase.Video.GetFrame(_VideoStream, ref _VidTex, 0, out time);
|
||||
if (_VidTex != null)
|
||||
CBase.Video.GetFrame(_VideoStream, _VideoStream.VideoTime);
|
||||
if (_VideoStream.Texture != null)
|
||||
{
|
||||
CBase.Drawing.DrawTexture(_VidTex, _GetDrawRect(), EAspect.Crop);
|
||||
CBase.Drawing.DrawTexture(_VideoStream.Texture, _GetDrawRect(), EAspect.Crop);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using VocaluxeLib.Draw;
|
||||
using VocaluxeLib.Songs;
|
||||
@@ -12,8 +9,7 @@ namespace VocaluxeLib.Utils.Player
|
||||
{
|
||||
private CSong _Song;
|
||||
private bool _VideoEnabled;
|
||||
private int _Video = -1;
|
||||
private CTextureRef _CurrentVideoTexture;
|
||||
private CVideoStream _Video;
|
||||
private CFading _VideoFading;
|
||||
|
||||
public bool VideoEnabled
|
||||
@@ -26,12 +22,8 @@ namespace VocaluxeLib.Utils.Player
|
||||
_VideoEnabled = value;
|
||||
if (_VideoEnabled)
|
||||
_LoadVideo();
|
||||
else if (_Video != -1)
|
||||
{
|
||||
CBase.Video.Close(_Video);
|
||||
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
|
||||
_Video = -1;
|
||||
}
|
||||
else if (_Video != null)
|
||||
CBase.Video.Close(ref _Video);
|
||||
}
|
||||
}
|
||||
public int SongID
|
||||
@@ -82,19 +74,18 @@ namespace VocaluxeLib.Utils.Player
|
||||
|
||||
public CTextureRef GetVideoTexture()
|
||||
{
|
||||
if (_Video == -1 || _Song == null)
|
||||
if (_Video == null || _Song == null)
|
||||
return null;
|
||||
float vtime;
|
||||
if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime))
|
||||
if (CBase.Video.GetFrame(_Video, CBase.Sound.GetPosition(_StreamID)))
|
||||
{
|
||||
if (_VideoFading != null)
|
||||
{
|
||||
bool finished;
|
||||
_CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished);
|
||||
_Video.Texture.Color.A = _VideoFading.GetValue(out finished);
|
||||
if (finished)
|
||||
_VideoFading = null;
|
||||
}
|
||||
return _CurrentVideoTexture;
|
||||
return _Video.Texture;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -108,7 +99,7 @@ namespace VocaluxeLib.Utils.Player
|
||||
|
||||
_Song = song;
|
||||
|
||||
base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false);
|
||||
Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay);
|
||||
_LoadVideo();
|
||||
|
||||
if (autoplay)
|
||||
@@ -122,7 +113,7 @@ namespace VocaluxeLib.Utils.Player
|
||||
|
||||
Stop();
|
||||
|
||||
base.Load(file, position, autoplay);
|
||||
Load(file, position, autoplay);
|
||||
}
|
||||
|
||||
public new void Play()
|
||||
@@ -138,22 +129,18 @@ namespace VocaluxeLib.Utils.Player
|
||||
|
||||
_Song = null;
|
||||
|
||||
if (_Video != -1)
|
||||
{
|
||||
CBase.Video.Close(_Video);
|
||||
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
|
||||
_Video = -1;
|
||||
}
|
||||
if (_Video != null)
|
||||
CBase.Video.Close(ref _Video);
|
||||
}
|
||||
|
||||
public new void TogglePause()
|
||||
{
|
||||
if (IsPlaying && _Video != -1)
|
||||
if (IsPlaying && _Video != null)
|
||||
{
|
||||
CBase.Video.Pause(_Video);
|
||||
CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap);
|
||||
}
|
||||
else if (_Video != -1)
|
||||
else if (_Video != null)
|
||||
CBase.Video.Resume(_Video);
|
||||
base.TogglePause();
|
||||
}
|
||||
@@ -164,7 +151,7 @@ namespace VocaluxeLib.Utils.Player
|
||||
return;
|
||||
|
||||
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
|
||||
if (_Video != -1 || String.IsNullOrEmpty(videoFilePath))
|
||||
if (_Video != null || String.IsNullOrEmpty(videoFilePath))
|
||||
return;
|
||||
_Video = CBase.Video.Load(videoFilePath);
|
||||
CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CEncoding.cs" />
|
||||
<Compile Include="CFading.cs" />
|
||||
<Compile Include="CVideoStream.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="IBasic.cs" />
|
||||
|
||||
Reference in new issue
Block a user