Introduce CVideoStream for easier video handling (already includes a texture, important for common usage of streams)

This commit is contained in:
Flamefire committed 2014-10-05 14:20:57 +02:00
1 parent 89e528c2a6
commit 6a3bf7b2c0
15 files changed
+204 -168

No files matched your search

+2 -2
View File
@@ -364,13 +364,13 @@ namespace Vocaluxe.Base
_LastEvalBeat = RecordedBeat; _LastEvalBeat = RecordedBeat;
} }
public static void ResetToLastLine(int soundStream, int vidStream) public static void ResetToLastLine(int soundStream, CVideoStream vidStream)
{ {
float[] time = _GetLastSungLineStart(); float[] time = _GetLastSungLineStart();
ResetToTime(time[0], time[1], soundStream, vidStream); ResetToTime(time[0], time[1], soundStream, vidStream);
} }
public static void ResetToTime(float time, float nextStart, int soundStream, int vidStream) public static void ResetToTime(float time, float nextStart, int soundStream, CVideoStream vidStream)
{ {
if (time < 0) if (time < 0)
time = 0; time = 0;
+16 -16
View File
@@ -282,7 +282,7 @@ namespace Vocaluxe.Base
return CTheme.GetSkinTexture(textureName, partyModeID); return CTheme.GetSkinTexture(textureName, partyModeID);
} }
public int GetSkinVideo(string videoName, int partyModeID, bool loop) public CVideoStream GetSkinVideo(string videoName, int partyModeID, bool loop)
{ {
return CTheme.GetSkinVideo(videoName, partyModeID, loop); return CTheme.GetSkinVideo(videoName, partyModeID, loop);
} }
@@ -810,44 +810,44 @@ namespace Vocaluxe.Base
class CBvideo : IVideo class CBvideo : IVideo
{ {
public int Load(string videoFileName) public CVideoStream Load(string videoFileName)
{ {
return CVideo.Load(videoFileName); return CVideo.Load(videoFileName);
} }
public bool Skip(int videoStream, float startPosition, float videoGap) public bool Skip(CVideoStream stream, float startPosition, float videoGap)
{ {
return CVideo.Skip(videoStream, startPosition, videoGap); return CVideo.Skip(stream, startPosition, videoGap);
} }
public bool GetFrame(int videoStream, ref CTextureRef videoTexture, float time, out float videoTime) public bool GetFrame(CVideoStream stream, float time)
{ {
return CVideo.GetFrame(videoStream, ref videoTexture, time, out videoTime); return CVideo.GetFrame(stream, time);
} }
public bool IsFinished(int videoStream) public bool IsFinished(CVideoStream stream)
{ {
return CVideo.Finished(videoStream); return CVideo.Finished(stream);
} }
public bool Close(int videoStream) public void Close(ref CVideoStream stream)
{ {
return CVideo.Close(videoStream); CVideo.Close(ref stream);
} }
public void SetLoop(int streamID, bool loop = true) public void SetLoop(CVideoStream stream, bool loop = true)
{ {
CVideo.SetLoop(streamID, loop); CVideo.SetLoop(stream, loop);
} }
public void Pause(int streamID) public void Pause(CVideoStream stream)
{ {
CVideo.Pause(streamID); CVideo.Pause(stream);
} }
public void Resume(int streamID) public void Resume(CVideoStream stream)
{ {
CVideo.Resume(streamID); CVideo.Resume(stream);
} }
} }
+8 -7
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using Vocaluxe.Lib.Video;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -14,9 +15,10 @@ namespace Vocaluxe.Base
public CTextureRef Texture; public CTextureRef Texture;
} }
class CVideoSkinElement : CSkinElement class CVideoSkinElement
{ {
public int VideoStream = -1; public string Value;
public CVideoStream VideoStream;
} }
class CSkin class CSkin
@@ -123,8 +125,7 @@ namespace Vocaluxe.Base
foreach (CVideoSkinElement vsk in VideoList.Values) foreach (CVideoSkinElement vsk in VideoList.Values)
{ {
CVideo.Close(vsk.VideoStream); CVideo.Close(ref vsk.VideoStream);
CDraw.RemoveTexture(ref vsk.Texture);
} }
SkinList.Clear(); SkinList.Clear();
VideoList.Clear(); VideoList.Clear();
@@ -272,19 +273,19 @@ namespace Vocaluxe.Base
return false; return false;
} }
public int GetVideo(string videoName, bool loop = true) public CVideoStream GetVideo(string videoName, bool loop = true)
{ {
CVideoSkinElement sk; CVideoSkinElement sk;
if (VideoList.TryGetValue(videoName, out sk)) if (VideoList.TryGetValue(videoName, out sk))
{ {
if (sk.VideoStream == -1) if (sk.VideoStream == null || sk.VideoStream.IsClosed())
{ {
sk.VideoStream = CVideo.Load(Path.Combine(_Folder, sk.Value)); sk.VideoStream = CVideo.Load(Path.Combine(_Folder, sk.Value));
CVideo.SetLoop(sk.VideoStream, loop); CVideo.SetLoop(sk.VideoStream, loop);
} }
return sk.VideoStream; return sk.VideoStream;
} }
return -1; return null;
} }
} }
} }
+8 -2
View File
@@ -21,6 +21,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using Vocaluxe.Base.Fonts; using Vocaluxe.Base.Fonts;
using Vocaluxe.Lib.Video;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -82,6 +83,11 @@ namespace Vocaluxe.Base
return LoadSkins() && LoadTheme(); return LoadSkins() && LoadTheme();
} }
public static void Close()
{
UnloadSkins();
}
public static bool LoadSkins() public static bool LoadSkins()
{ {
//Fail if loading of any skin failed or no skin was loaded //Fail if loading of any skin failed or no skin was loaded
@@ -380,10 +386,10 @@ namespace Vocaluxe.Base
return null; return null;
} }
public static int GetSkinVideo(string videoName, int partyModeID, bool loop = true) public static CVideoStream GetSkinVideo(string videoName, int partyModeID, bool loop = true)
{ {
CSkin skin = _GetSkin(partyModeID); CSkin skin = _GetSkin(partyModeID);
return skin == null ? -1 : skin.GetVideo(videoName, loop); return skin == null ? null : skin.GetVideo(videoName, loop);
} }
#endregion Theme and Skin index handling #endregion Theme and Skin index handling
+19 -18
View File
@@ -17,7 +17,6 @@
using Vocaluxe.Lib.Video; using Vocaluxe.Lib.Video;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw;
namespace Vocaluxe.Base namespace Vocaluxe.Base
{ {
@@ -60,49 +59,51 @@ namespace Vocaluxe.Base
return _VideoDecoder.GetNumStreams(); return _VideoDecoder.GetNumStreams();
} }
public static int Load(string videoFileName) public static CVideoStream Load(string videoFileName)
{ {
return _VideoDecoder.Load(videoFileName); return _VideoDecoder.Load(videoFileName);
} }
public static bool Close(int streamID) public static void Close(ref CVideoStream stream)
{ {
return _VideoDecoder.Close(streamID); //Check for null because the videostreams may close themselves on destroy (GC)
if (_VideoDecoder != null)
_VideoDecoder.Close(ref stream);
} }
public static float GetLength(int streamID) public static float GetLength(CVideoStream stream)
{ {
return _VideoDecoder.GetLength(streamID); return _VideoDecoder.GetLength(stream);
} }
public static bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime) public static bool GetFrame(CVideoStream stream, float time)
{ {
return _VideoDecoder.GetFrame(streamID, ref frame, time, out videoTime); return _VideoDecoder.GetFrame(stream, time);
} }
public static bool Skip(int streamID, float start, float gap) public static bool Skip(CVideoStream stream, float start, float gap)
{ {
return _VideoDecoder.Skip(streamID, start, gap); return _VideoDecoder.Skip(stream, start, gap);
} }
public static void SetLoop(int streamID, bool loop) public static void SetLoop(CVideoStream stream, bool loop)
{ {
_VideoDecoder.SetLoop(streamID, loop); _VideoDecoder.SetLoop(stream, loop);
} }
public static void Pause(int streamID) public static void Pause(CVideoStream stream)
{ {
_VideoDecoder.Pause(streamID); _VideoDecoder.Pause(stream);
} }
public static void Resume(int streamID) public static void Resume(CVideoStream stream)
{ {
_VideoDecoder.Resume(streamID); _VideoDecoder.Resume(stream);
} }
public static bool Finished(int streamID) public static bool Finished(CVideoStream stream)
{ {
return _VideoDecoder.Finished(streamID); return _VideoDecoder.Finished(stream);
} }
public static void Update() public static void Update()
+8 -10
View File
@@ -1,4 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using Vocaluxe.Lib.Video;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -6,8 +7,7 @@ namespace Vocaluxe.Base
{ {
class CVideoPlayer class CVideoPlayer
{ {
private CTextureRef _VideoTexture; private CVideoStream _VideoStream;
private int _VideoStream;
private readonly Stopwatch _VideoTimer = new Stopwatch(); private readonly Stopwatch _VideoTimer = new Stopwatch();
private bool _Finished; private bool _Finished;
private bool _Loaded; private bool _Loaded;
@@ -57,12 +57,12 @@ namespace Vocaluxe.Base
float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f;
_Finished = CVideo.Finished(_VideoStream); _Finished = CVideo.Finished(_VideoStream);
CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); CVideo.GetFrame(_VideoStream, videoTime);
} }
if (_VideoTexture == null) if (_VideoStream.Texture == null)
return; return;
CDraw.DrawTexture(_VideoTexture, CSettings.RenderRect, EAspect.Crop); CDraw.DrawTexture(_VideoStream.Texture, CSettings.RenderRect, EAspect.Crop);
} }
public void PreLoad() public void PreLoad()
@@ -71,10 +71,9 @@ namespace Vocaluxe.Base
if (paused) if (paused)
CVideo.Resume(_VideoStream); CVideo.Resume(_VideoStream);
float videoTime = 0f; float videoTime = 0f;
while (_VideoTexture == null && videoTime < 1f) while (_VideoStream.Texture == null && videoTime < 1f)
{ {
float dummy; CVideo.GetFrame(_VideoStream, 0);
CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy);
videoTime += 0.05f; videoTime += 0.05f;
} }
if (paused) if (paused)
@@ -83,8 +82,7 @@ namespace Vocaluxe.Base
public void Close() public void Close()
{ {
CVideo.Close(_VideoStream); CVideo.Close(ref _VideoStream);
CDraw.RemoveTexture(ref _VideoTexture);
_Loaded = false; _Loaded = false;
_Finished = false; _Finished = false;
_VideoTimer.Reset(); _VideoTimer.Reset();
+37 -25
View File
@@ -17,7 +17,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Vocaluxe.Lib.Video.Acinerella; using Vocaluxe.Lib.Video.Acinerella;
using VocaluxeLib.Draw; using VocaluxeLib;
namespace Vocaluxe.Lib.Video namespace Vocaluxe.Lib.Video
{ {
@@ -39,7 +39,7 @@ namespace Vocaluxe.Lib.Video
_Decoder.Clear(); _Decoder.Clear();
} }
public int Load(string videoFileName) public CVideoStream Load(string videoFileName)
{ {
var decoder = new CDecoder(); var decoder = new CDecoder();
@@ -47,21 +47,23 @@ namespace Vocaluxe.Lib.Video
{ {
int id = _LastID++; int id = _LastID++;
_Decoder.Add(id, decoder); _Decoder.Add(id, decoder);
return id; return new CVideoStream(id);
} }
return -1; return null;
} }
public bool Close(int streamID) public void Close(ref CVideoStream stream)
{ {
if (stream == null)
return;
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
{ {
decoder.Close(); decoder.Close();
_Decoder.Remove(streamID); _Decoder.Remove(stream.ID);
return true;
} }
return false; stream.SetClosed();
stream = null;
} }
public int GetNumStreams() public int GetNumStreams()
@@ -69,60 +71,70 @@ namespace Vocaluxe.Lib.Video
return _Decoder.Count; return _Decoder.Count;
} }
public bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime) public bool GetFrame(CVideoStream stream, float time)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
return decoder.GetFrame(ref frame, time, out videoTime); return decoder.GetFrame(ref stream.Texture, time, out stream.VideoTime);
videoTime = 0; stream.VideoTime = 0;
return false; return false;
} }
public float GetLength(int streamID) public float GetLength(CVideoStream stream)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
return decoder.Length; return decoder.Length;
return 0f; return 0f;
} }
public bool Skip(int streamID, float start, float gap) public bool Skip(CVideoStream stream, float start, float gap)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
return decoder.Skip(start, gap); return decoder.Skip(start, gap);
return false; return false;
} }
public void SetLoop(int streamID, bool loop) public void SetLoop(CVideoStream stream, bool loop)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
decoder.Loop = loop; decoder.Loop = loop;
} }
public void Pause(int streamID) public void Pause(CVideoStream stream)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
decoder.Paused = true; decoder.Paused = true;
} }
public void Resume(int streamID) public void Resume(CVideoStream stream)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
decoder.Paused = false; decoder.Paused = false;
} }
public bool Finished(int streamID) public bool Finished(CVideoStream stream)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_TryGetDecoder(stream, out decoder))
return decoder.Finished; return decoder.Finished;
return true; return true;
} }
public void Update() {} public void Update() {}
private bool _TryGetDecoder(CVideoStream stream, out CDecoder decoder)
{
if (stream == null)
{
decoder = null;
return false;
}
return _Decoder.TryGetValue(stream.ID, out decoder);
}
} }
} }
+20 -25
View File
@@ -15,7 +15,7 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using VocaluxeLib.Draw; using VocaluxeLib;
namespace Vocaluxe.Lib.Video namespace Vocaluxe.Lib.Video
{ {
@@ -36,15 +36,14 @@ namespace Vocaluxe.Lib.Video
/// Loads the file with the given file path. /// Loads the file with the given file path.
/// </summary> /// </summary>
/// <param name="videoFileName">Absolute file path of the video file</param> /// <param name="videoFileName">Absolute file path of the video file</param>
/// <returns>StreamID &gt;=0 on success or -1 on failure</returns> /// <returns>stream &gt;=0 on success or -1 on failure</returns>
int Load(string videoFileName); CVideoStream Load(string videoFileName);
/// <summary> /// <summary>
/// Closes the stream with the given ID /// Closes the stream with the given ID
/// </summary> /// </summary>
/// <param name="streamID">ID of the stream</param> /// <param name="stream">ID of the stream</param>
/// <returns>true if stream was closed, false if stream doesn't exist or already closed</returns> void Close(ref CVideoStream stream);
bool Close(int streamID);
/// <summary> /// <summary>
/// Gets the number of streams currently active /// Gets the number of streams currently active
@@ -55,60 +54,56 @@ namespace Vocaluxe.Lib.Video
/// <summary> /// <summary>
/// Gets the length of the video in s /// Gets the length of the video in s
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream</param> /// <param name="stream">Id of the stream</param>
/// <returns>Length of the video in s</returns> /// <returns>Length of the video in s</returns>
float GetLength(int streamID); float GetLength(CVideoStream stream);
/// <summary> /// <summary>
/// Gets a frame of the video and sets the current video time /// Gets a frame of the video and sets the current video time
/// </summary>
/// <param name="streamID">Id of the stream</param>
/// <param name="frame">
/// Reference to already initialized video texture (from previous calls). If null, one will be created.<br />
/// Returns the current video frame which might be outdated if time != current (internal) video position or unchanged (even null) if none is available. /// Returns the current video frame which might be outdated if time != current (internal) video position or unchanged (even null) if none is available.
/// </param> /// </summary>
/// <param name="stream">Id of the stream</param>
/// <param name="time"> /// <param name="time">
/// The position in s of the video you want to get a frame of. If != current (internal) video position, it will seek to get to right position.<br /> /// The position in s of the video you want to get a frame of. If != current (internal) video position, it will seek to get to right position.<br />
/// <b>Note:</b>Will be ignored for looped playback! /// <b>Note:</b>Will be ignored for looped playback!
/// </param> /// </param>
/// <param name="videoTime">The actual position in s of the returned frame. Should be ~ time+VideoGap</param>
/// <returns>True if frame is valid, false: frame and videoTime might be unchanged or invalid</returns> /// <returns>True if frame is valid, false: frame and videoTime might be unchanged or invalid</returns>
bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime); bool GetFrame(CVideoStream stream, float time);
/// <summary> /// <summary>
/// Seeks to given position /// Seeks to given position
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream</param> /// <param name="stream">Id of the stream</param>
/// <param name="start">Position to seek to</param> /// <param name="start">Position to seek to</param>
/// <param name="gap">New video gap -> Actual position will be start+gap</param> /// <param name="gap">New video gap -> Actual position will be start+gap</param>
/// <returns>True on success</returns> /// <returns>True on success</returns>
bool Skip(int streamID, float start, float gap); bool Skip(CVideoStream stream, float start, float gap);
/// <summary> /// <summary>
/// Set if the video should be looped /// Set if the video should be looped
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream</param> /// <param name="stream">Id of the stream</param>
/// <param name="loop">True if it should be looped</param> /// <param name="loop">True if it should be looped</param>
void SetLoop(int streamID, bool loop); void SetLoop(CVideoStream stream, bool loop);
/// <summary> /// <summary>
/// Pauses the video (no new frames will be decoded) /// Pauses the video (no new frames will be decoded)
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream</param> /// <param name="stream">Id of the stream</param>
void Pause(int streamID); void Pause(CVideoStream stream);
/// <summary> /// <summary>
/// Resumes a paused video /// Resumes a paused video
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream</param> /// <param name="stream">Id of the stream</param>
void Resume(int streamID); void Resume(CVideoStream stream);
/// <summary> /// <summary>
/// Check if the given video is finished /// Check if the given video is finished
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream</param> /// <param name="stream">Id of the stream</param>
/// <returns>True if all frames are shown</returns> /// <returns>True if all frames are shown</returns>
bool Finished(int streamID); bool Finished(CVideoStream stream);
/// <summary> /// <summary>
/// Do a step of the decoder in unthreaded decoders. Should be called once every frame. /// Do a step of the decoder in unthreaded decoders. Should be called once every frame.
+1
View File
@@ -263,6 +263,7 @@ namespace Vocaluxe
CController.Close(); CController.Close();
CVocaluxeServer.Close(); CVocaluxeServer.Close();
CGraphics.Close(); CGraphics.Close();
CTheme.Close();
CCover.Close(); CCover.Close();
CBackgroundMusic.Close(); CBackgroundMusic.Close();
CWebcam.Close(); CWebcam.Close();
+9 -15
View File
@@ -23,6 +23,7 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Vocaluxe.Base; using Vocaluxe.Base;
using Vocaluxe.Base.Fonts; using Vocaluxe.Base.Fonts;
using Vocaluxe.Lib.Video;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
using VocaluxeLib.Menu; using VocaluxeLib.Menu;
@@ -96,9 +97,8 @@ namespace Vocaluxe.Screens
private float _Length = -1f; private float _Length = -1f;
//private int _NextStream = -1; //private int _NextStream = -1;
private const float _Volume = 100f; private const float _Volume = 100f;
private int _CurrentVideo = -1; private CVideoStream _CurrentVideo;
private EAspect _VideoAspect = EAspect.Crop; private EAspect _VideoAspect = EAspect.Crop;
private CTextureRef _CurrentVideoTexture;
private CTextureRef _CurrentWebcamFrameTexture; private CTextureRef _CurrentWebcamFrameTexture;
private CTextureRef _Background; private CTextureRef _Background;
@@ -400,10 +400,9 @@ namespace Vocaluxe.Screens
_Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString(fmtString); _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString(fmtString);
} }
if (_CurrentVideo != -1 && !_FadeOut && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON) if (_CurrentVideo != null && !_FadeOut && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON)
{ {
float vtime; CVideo.GetFrame(_CurrentVideo, _CurrentTime);
CVideo.GetFrame(_CurrentVideo, ref _CurrentVideoTexture, _CurrentTime, out vtime);
} }
if (_Webcam) if (_Webcam)
@@ -418,8 +417,7 @@ namespace Vocaluxe.Screens
_FadeOut = false; _FadeOut = false;
_CurrentVideo = -1; _CurrentVideo = null;
_CurrentVideoTexture = null;
_CurrentWebcamFrameTexture = null; _CurrentWebcamFrameTexture = null;
_CurrentBeat = -100; _CurrentBeat = -100;
_CurrentTime = 0f; _CurrentTime = 0f;
@@ -464,9 +462,9 @@ namespace Vocaluxe.Screens
{ {
CTextureRef background; CTextureRef background;
var aspect = EAspect.Crop; var aspect = EAspect.Crop;
if (_CurrentVideo != -1 && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam) if (_CurrentVideo != null && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam)
{ {
background = _CurrentVideoTexture; background = _CurrentVideo.Texture;
aspect = _VideoAspect; aspect = _VideoAspect;
} }
else if (_Webcam) else if (_Webcam)
@@ -557,11 +555,9 @@ namespace Vocaluxe.Screens
_CurrentStream = -1; _CurrentStream = -1;
} }
CRecord.Stop(); CRecord.Stop();
if (_CurrentVideo != -1) if (_CurrentVideo != null)
{ {
CVideo.Close(_CurrentVideo); CVideo.Close(ref _CurrentVideo);
_CurrentVideo = -1;
CDraw.RemoveTexture(ref _CurrentVideoTexture);
} }
CDraw.RemoveTexture(ref _Background); CDraw.RemoveTexture(ref _Background);
@@ -624,8 +620,6 @@ namespace Vocaluxe.Screens
} }
CGame.ResetPlayer(); CGame.ResetPlayer();
CDraw.RemoveTexture(ref _CurrentVideoTexture);
if (!String.IsNullOrEmpty(song.VideoFileName)) if (!String.IsNullOrEmpty(song.VideoFileName))
{ {
_CurrentVideo = CVideo.Load(Path.Combine(song.Folder, song.VideoFileName)); _CurrentVideo = CVideo.Load(Path.Combine(song.Folder, song.VideoFileName));
+45
View File
@@ -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;
}
}
}
+9 -9
View File
@@ -103,7 +103,7 @@ namespace VocaluxeLib
string GetThemeScreensPath(int partyModeID); string GetThemeScreensPath(int partyModeID);
int GetSkinIndex(int partyModeID); int GetSkinIndex(int partyModeID);
CTextureRef GetSkinTexture(string textureName, 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); bool GetColor(string colorName, int partyModeID, out SColorF color);
SColorF GetPlayerColor(int playerNr); SColorF GetPlayerColor(int playerNr);
@@ -264,14 +264,14 @@ namespace VocaluxeLib
public interface IVideo public interface IVideo
{ {
int Load(string videoFileName); CVideoStream Load(string videoFileName);
bool Skip(int streamID, float startPosition, float videoGap); bool Skip(CVideoStream stream, float startPosition, float videoGap);
bool GetFrame(int streamID, ref CTextureRef videoTexture, float time, out float videoTime); bool GetFrame(CVideoStream stream, float time);
bool IsFinished(int streamID); bool IsFinished(CVideoStream stream);
bool Close(int streamID); void Close(ref CVideoStream stream);
void SetLoop(int streamID, bool loop = true); void SetLoop(CVideoStream stream, bool loop = true);
void Resume(int streamID); void Resume(CVideoStream stream);
void Pause(int streamID); void Pause(CVideoStream stream);
} }
public interface ISound public interface ISound
+7 -12
View File
@@ -16,7 +16,6 @@
#endregion #endregion
using System; using System;
using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.Generic; using System.Collections.Generic;
@@ -54,8 +53,7 @@ namespace VocaluxeLib.Menu
private readonly Stopwatch _SlideShowTimer = new Stopwatch(); private readonly Stopwatch _SlideShowTimer = new Stopwatch();
private readonly List<CTextureRef> _SlideShowTextures = new List<CTextureRef>(); private readonly List<CTextureRef> _SlideShowTextures = new List<CTextureRef>();
private int _VideoStream = -1; private CVideoStream _VideoStream;
private CTextureRef _VidTex;
public SColorF Color; public SColorF Color;
public bool ThemeLoaded public bool ThemeLoaded
@@ -136,13 +134,13 @@ namespace VocaluxeLib.Menu
public void Resume() public void Resume()
{ {
if (_VideoStream != -1) if (_VideoStream != null)
CBase.Video.Resume(_VideoStream); CBase.Video.Resume(_VideoStream);
} }
public void Pause() public void Pause()
{ {
if (_VideoStream != -1) if (_VideoStream != null)
CBase.Video.Pause(_VideoStream); CBase.Video.Pause(_VideoStream);
} }
@@ -176,9 +174,7 @@ namespace VocaluxeLib.Menu
public void UnloadTextures() public void UnloadTextures()
{ {
_SlideShowTextures.Clear(); _SlideShowTextures.Clear();
CBase.Video.Close(_VideoStream); CBase.Video.Close(ref _VideoStream);
_VideoStream = -1;
CBase.Drawing.RemoveTexture(ref _VidTex);
} }
public void LoadTextures() public void LoadTextures()
@@ -299,11 +295,10 @@ namespace VocaluxeLib.Menu
private bool _DrawVideo() private bool _DrawVideo()
{ {
float time; CBase.Video.GetFrame(_VideoStream, _VideoStream.VideoTime);
CBase.Video.GetFrame(_VideoStream, ref _VidTex, 0, out time); if (_VideoStream.Texture != null)
if (_VidTex != null)
{ {
CBase.Drawing.DrawTexture(_VidTex, _GetDrawRect(), EAspect.Crop); CBase.Drawing.DrawTexture(_VideoStream.Texture, _GetDrawRect(), EAspect.Crop);
return true; return true;
} }
return false; return false;
+14 -27
View File
@@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using System.IO;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
using VocaluxeLib.Songs; using VocaluxeLib.Songs;
@@ -12,8 +9,7 @@ namespace VocaluxeLib.Utils.Player
{ {
private CSong _Song; private CSong _Song;
private bool _VideoEnabled; private bool _VideoEnabled;
private int _Video = -1; private CVideoStream _Video;
private CTextureRef _CurrentVideoTexture;
private CFading _VideoFading; private CFading _VideoFading;
public bool VideoEnabled public bool VideoEnabled
@@ -26,12 +22,8 @@ namespace VocaluxeLib.Utils.Player
_VideoEnabled = value; _VideoEnabled = value;
if (_VideoEnabled) if (_VideoEnabled)
_LoadVideo(); _LoadVideo();
else if (_Video != -1) else if (_Video != null)
{ CBase.Video.Close(ref _Video);
CBase.Video.Close(_Video);
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
} }
} }
public int SongID public int SongID
@@ -82,19 +74,18 @@ namespace VocaluxeLib.Utils.Player
public CTextureRef GetVideoTexture() public CTextureRef GetVideoTexture()
{ {
if (_Video == -1 || _Song == null) if (_Video == null || _Song == null)
return null; return null;
float vtime; if (CBase.Video.GetFrame(_Video, CBase.Sound.GetPosition(_StreamID)))
if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime))
{ {
if (_VideoFading != null) if (_VideoFading != null)
{ {
bool finished; bool finished;
_CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished); _Video.Texture.Color.A = _VideoFading.GetValue(out finished);
if (finished) if (finished)
_VideoFading = null; _VideoFading = null;
} }
return _CurrentVideoTexture; return _Video.Texture;
} }
return null; return null;
} }
@@ -108,7 +99,7 @@ namespace VocaluxeLib.Utils.Player
_Song = song; _Song = song;
base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false); Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay);
_LoadVideo(); _LoadVideo();
if (autoplay) if (autoplay)
@@ -122,7 +113,7 @@ namespace VocaluxeLib.Utils.Player
Stop(); Stop();
base.Load(file, position, autoplay); Load(file, position, autoplay);
} }
public new void Play() public new void Play()
@@ -138,22 +129,18 @@ namespace VocaluxeLib.Utils.Player
_Song = null; _Song = null;
if (_Video != -1) if (_Video != null)
{ CBase.Video.Close(ref _Video);
CBase.Video.Close(_Video);
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
} }
public new void TogglePause() public new void TogglePause()
{ {
if (IsPlaying && _Video != -1) if (IsPlaying && _Video != null)
{ {
CBase.Video.Pause(_Video); CBase.Video.Pause(_Video);
CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap);
} }
else if (_Video != -1) else if (_Video != null)
CBase.Video.Resume(_Video); CBase.Video.Resume(_Video);
base.TogglePause(); base.TogglePause();
} }
@@ -164,7 +151,7 @@ namespace VocaluxeLib.Utils.Player
return; return;
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName); string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
if (_Video != -1 || String.IsNullOrEmpty(videoFilePath)) if (_Video != null || String.IsNullOrEmpty(videoFilePath))
return; return;
_Video = CBase.Video.Load(videoFilePath); _Video = CBase.Video.Load(videoFilePath);
CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture
+1
View File
@@ -78,6 +78,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="CEncoding.cs" /> <Compile Include="CEncoding.cs" />
<Compile Include="CFading.cs" /> <Compile Include="CFading.cs" />
<Compile Include="CVideoStream.cs" />
<Compile Include="Extensions.cs" /> <Compile Include="Extensions.cs" />
<Compile Include="GlobalSuppressions.cs" /> <Compile Include="GlobalSuppressions.cs" />
<Compile Include="IBasic.cs" /> <Compile Include="IBasic.cs" />