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
@@ -364,13 +364,13 @@ namespace Vocaluxe.Base
|
||||
_LastEvalBeat = RecordedBeat;
|
||||
}
|
||||
|
||||
public static void ResetToLastLine(int soundStream, int vidStream)
|
||||
public static void ResetToLastLine(int soundStream, CVideoStream vidStream)
|
||||
{
|
||||
float[] time = _GetLastSungLineStart();
|
||||
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)
|
||||
time = 0;
|
||||
|
||||
+16
-16
@@ -282,7 +282,7 @@ namespace Vocaluxe.Base
|
||||
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);
|
||||
}
|
||||
@@ -810,44 +810,44 @@ namespace Vocaluxe.Base
|
||||
|
||||
class CBvideo : IVideo
|
||||
{
|
||||
public int Load(string videoFileName)
|
||||
public CVideoStream Load(string 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Vocaluxe.Lib.Video;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
@@ -14,9 +15,10 @@ namespace Vocaluxe.Base
|
||||
public CTextureRef Texture;
|
||||
}
|
||||
|
||||
class CVideoSkinElement : CSkinElement
|
||||
class CVideoSkinElement
|
||||
{
|
||||
public int VideoStream = -1;
|
||||
public string Value;
|
||||
public CVideoStream VideoStream;
|
||||
}
|
||||
|
||||
class CSkin
|
||||
@@ -123,8 +125,7 @@ namespace Vocaluxe.Base
|
||||
|
||||
foreach (CVideoSkinElement vsk in VideoList.Values)
|
||||
{
|
||||
CVideo.Close(vsk.VideoStream);
|
||||
CDraw.RemoveTexture(ref vsk.Texture);
|
||||
CVideo.Close(ref vsk.VideoStream);
|
||||
}
|
||||
SkinList.Clear();
|
||||
VideoList.Clear();
|
||||
@@ -272,19 +273,19 @@ namespace Vocaluxe.Base
|
||||
return false;
|
||||
}
|
||||
|
||||
public int GetVideo(string videoName, bool loop = true)
|
||||
public CVideoStream GetVideo(string videoName, bool loop = true)
|
||||
{
|
||||
CVideoSkinElement 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));
|
||||
CVideo.SetLoop(sk.VideoStream, loop);
|
||||
}
|
||||
return sk.VideoStream;
|
||||
}
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Vocaluxe.Base.Fonts;
|
||||
using Vocaluxe.Lib.Video;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
@@ -82,6 +83,11 @@ namespace Vocaluxe.Base
|
||||
return LoadSkins() && LoadTheme();
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
UnloadSkins();
|
||||
}
|
||||
|
||||
public static bool LoadSkins()
|
||||
{
|
||||
//Fail if loading of any skin failed or no skin was loaded
|
||||
@@ -380,10 +386,10 @@ namespace Vocaluxe.Base
|
||||
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);
|
||||
return skin == null ? -1 : skin.GetVideo(videoName, loop);
|
||||
return skin == null ? null : skin.GetVideo(videoName, loop);
|
||||
}
|
||||
#endregion Theme and Skin index handling
|
||||
|
||||
|
||||
+19
-18
@@ -17,7 +17,6 @@
|
||||
|
||||
using Vocaluxe.Lib.Video;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
namespace Vocaluxe.Base
|
||||
{
|
||||
@@ -60,49 +59,51 @@ namespace Vocaluxe.Base
|
||||
return _VideoDecoder.GetNumStreams();
|
||||
}
|
||||
|
||||
public static int Load(string videoFileName)
|
||||
public static CVideoStream Load(string 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()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using Vocaluxe.Lib.Video;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
@@ -6,8 +7,7 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
class CVideoPlayer
|
||||
{
|
||||
private CTextureRef _VideoTexture;
|
||||
private int _VideoStream;
|
||||
private CVideoStream _VideoStream;
|
||||
private readonly Stopwatch _VideoTimer = new Stopwatch();
|
||||
private bool _Finished;
|
||||
private bool _Loaded;
|
||||
@@ -57,12 +57,12 @@ namespace Vocaluxe.Base
|
||||
float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f;
|
||||
_Finished = CVideo.Finished(_VideoStream);
|
||||
|
||||
CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime);
|
||||
CVideo.GetFrame(_VideoStream, videoTime);
|
||||
}
|
||||
if (_VideoTexture == null)
|
||||
if (_VideoStream.Texture == null)
|
||||
return;
|
||||
|
||||
CDraw.DrawTexture(_VideoTexture, CSettings.RenderRect, EAspect.Crop);
|
||||
CDraw.DrawTexture(_VideoStream.Texture, CSettings.RenderRect, EAspect.Crop);
|
||||
}
|
||||
|
||||
public void PreLoad()
|
||||
@@ -71,10 +71,9 @@ namespace Vocaluxe.Base
|
||||
if (paused)
|
||||
CVideo.Resume(_VideoStream);
|
||||
float videoTime = 0f;
|
||||
while (_VideoTexture == null && videoTime < 1f)
|
||||
while (_VideoStream.Texture == null && videoTime < 1f)
|
||||
{
|
||||
float dummy;
|
||||
CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy);
|
||||
CVideo.GetFrame(_VideoStream, 0);
|
||||
videoTime += 0.05f;
|
||||
}
|
||||
if (paused)
|
||||
@@ -83,8 +82,7 @@ namespace Vocaluxe.Base
|
||||
|
||||
public void Close()
|
||||
{
|
||||
CVideo.Close(_VideoStream);
|
||||
CDraw.RemoveTexture(ref _VideoTexture);
|
||||
CVideo.Close(ref _VideoStream);
|
||||
_Loaded = false;
|
||||
_Finished = false;
|
||||
_VideoTimer.Reset();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Vocaluxe.Lib.Video.Acinerella;
|
||||
using VocaluxeLib.Draw;
|
||||
using VocaluxeLib;
|
||||
|
||||
namespace Vocaluxe.Lib.Video
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Vocaluxe.Lib.Video
|
||||
_Decoder.Clear();
|
||||
}
|
||||
|
||||
public int Load(string videoFileName)
|
||||
public CVideoStream Load(string videoFileName)
|
||||
{
|
||||
var decoder = new CDecoder();
|
||||
|
||||
@@ -47,21 +47,23 @@ namespace Vocaluxe.Lib.Video
|
||||
{
|
||||
int id = _LastID++;
|
||||
_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;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
{
|
||||
decoder.Close();
|
||||
_Decoder.Remove(streamID);
|
||||
return true;
|
||||
_Decoder.Remove(stream.ID);
|
||||
}
|
||||
return false;
|
||||
stream.SetClosed();
|
||||
stream = null;
|
||||
}
|
||||
|
||||
public int GetNumStreams()
|
||||
@@ -69,60 +71,70 @@ namespace Vocaluxe.Lib.Video
|
||||
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;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
return decoder.GetFrame(ref frame, time, out videoTime);
|
||||
videoTime = 0;
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
return decoder.GetFrame(ref stream.Texture, time, out stream.VideoTime);
|
||||
stream.VideoTime = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public float GetLength(int streamID)
|
||||
public float GetLength(CVideoStream stream)
|
||||
{
|
||||
CDecoder decoder;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
return decoder.Length;
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public bool Skip(int streamID, float start, float gap)
|
||||
public bool Skip(CVideoStream stream, float start, float gap)
|
||||
{
|
||||
CDecoder decoder;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
return decoder.Skip(start, gap);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetLoop(int streamID, bool loop)
|
||||
public void SetLoop(CVideoStream stream, bool loop)
|
||||
{
|
||||
CDecoder decoder;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
decoder.Loop = loop;
|
||||
}
|
||||
|
||||
public void Pause(int streamID)
|
||||
public void Pause(CVideoStream stream)
|
||||
{
|
||||
CDecoder decoder;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
decoder.Paused = true;
|
||||
}
|
||||
|
||||
public void Resume(int streamID)
|
||||
public void Resume(CVideoStream stream)
|
||||
{
|
||||
CDecoder decoder;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
decoder.Paused = false;
|
||||
}
|
||||
|
||||
public bool Finished(int streamID)
|
||||
public bool Finished(CVideoStream stream)
|
||||
{
|
||||
CDecoder decoder;
|
||||
if (_Decoder.TryGetValue(streamID, out decoder))
|
||||
if (_TryGetDecoder(stream, out decoder))
|
||||
return decoder.Finished;
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using VocaluxeLib.Draw;
|
||||
using VocaluxeLib;
|
||||
|
||||
namespace Vocaluxe.Lib.Video
|
||||
{
|
||||
@@ -36,15 +36,14 @@ namespace Vocaluxe.Lib.Video
|
||||
/// Loads the file with the given file path.
|
||||
/// </summary>
|
||||
/// <param name="videoFileName">Absolute file path of the video file</param>
|
||||
/// <returns>StreamID >=0 on success or -1 on failure</returns>
|
||||
int Load(string videoFileName);
|
||||
/// <returns>stream >=0 on success or -1 on failure</returns>
|
||||
CVideoStream Load(string videoFileName);
|
||||
|
||||
/// <summary>
|
||||
/// Closes the stream with the given ID
|
||||
/// </summary>
|
||||
/// <param name="streamID">ID of the stream</param>
|
||||
/// <returns>true if stream was closed, false if stream doesn't exist or already closed</returns>
|
||||
bool Close(int streamID);
|
||||
/// <param name="stream">ID of the stream</param>
|
||||
void Close(ref CVideoStream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of streams currently active
|
||||
@@ -55,60 +54,56 @@ namespace Vocaluxe.Lib.Video
|
||||
/// <summary>
|
||||
/// Gets the length of the video in s
|
||||
/// </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>
|
||||
float GetLength(int streamID);
|
||||
float GetLength(CVideoStream stream);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </param>
|
||||
/// </summary>
|
||||
/// <param name="stream">Id of the stream</param>
|
||||
/// <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 />
|
||||
/// <b>Note:</b>Will be ignored for looped playback!
|
||||
/// </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>
|
||||
bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime);
|
||||
bool GetFrame(CVideoStream stream, float time);
|
||||
|
||||
/// <summary>
|
||||
/// Seeks to given position
|
||||
/// </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="gap">New video gap -> Actual position will be start+gap</param>
|
||||
/// <returns>True on success</returns>
|
||||
bool Skip(int streamID, float start, float gap);
|
||||
bool Skip(CVideoStream stream, float start, float gap);
|
||||
|
||||
/// <summary>
|
||||
/// Set if the video should be looped
|
||||
/// </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>
|
||||
void SetLoop(int streamID, bool loop);
|
||||
void SetLoop(CVideoStream stream, bool loop);
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the video (no new frames will be decoded)
|
||||
/// </summary>
|
||||
/// <param name="streamID">Id of the stream</param>
|
||||
void Pause(int streamID);
|
||||
/// <param name="stream">Id of the stream</param>
|
||||
void Pause(CVideoStream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Resumes a paused video
|
||||
/// </summary>
|
||||
/// <param name="streamID">Id of the stream</param>
|
||||
void Resume(int streamID);
|
||||
/// <param name="stream">Id of the stream</param>
|
||||
void Resume(CVideoStream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the given video is finished
|
||||
/// </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>
|
||||
bool Finished(int streamID);
|
||||
bool Finished(CVideoStream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Do a step of the decoder in unthreaded decoders. Should be called once every frame.
|
||||
|
||||
@@ -263,6 +263,7 @@ namespace Vocaluxe
|
||||
CController.Close();
|
||||
CVocaluxeServer.Close();
|
||||
CGraphics.Close();
|
||||
CTheme.Close();
|
||||
CCover.Close();
|
||||
CBackgroundMusic.Close();
|
||||
CWebcam.Close();
|
||||
|
||||
@@ -23,6 +23,7 @@ using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Vocaluxe.Base;
|
||||
using Vocaluxe.Base.Fonts;
|
||||
using Vocaluxe.Lib.Video;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
using VocaluxeLib.Menu;
|
||||
@@ -96,9 +97,8 @@ namespace Vocaluxe.Screens
|
||||
private float _Length = -1f;
|
||||
//private int _NextStream = -1;
|
||||
private const float _Volume = 100f;
|
||||
private int _CurrentVideo = -1;
|
||||
private CVideoStream _CurrentVideo;
|
||||
private EAspect _VideoAspect = EAspect.Crop;
|
||||
private CTextureRef _CurrentVideoTexture;
|
||||
private CTextureRef _CurrentWebcamFrameTexture;
|
||||
private CTextureRef _Background;
|
||||
|
||||
@@ -400,10 +400,9 @@ namespace Vocaluxe.Screens
|
||||
_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, ref _CurrentVideoTexture, _CurrentTime, out vtime);
|
||||
CVideo.GetFrame(_CurrentVideo, _CurrentTime);
|
||||
}
|
||||
|
||||
if (_Webcam)
|
||||
@@ -418,8 +417,7 @@ namespace Vocaluxe.Screens
|
||||
|
||||
_FadeOut = false;
|
||||
|
||||
_CurrentVideo = -1;
|
||||
_CurrentVideoTexture = null;
|
||||
_CurrentVideo = null;
|
||||
_CurrentWebcamFrameTexture = null;
|
||||
_CurrentBeat = -100;
|
||||
_CurrentTime = 0f;
|
||||
@@ -464,9 +462,9 @@ namespace Vocaluxe.Screens
|
||||
{
|
||||
CTextureRef background;
|
||||
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;
|
||||
}
|
||||
else if (_Webcam)
|
||||
@@ -557,11 +555,9 @@ namespace Vocaluxe.Screens
|
||||
_CurrentStream = -1;
|
||||
}
|
||||
CRecord.Stop();
|
||||
if (_CurrentVideo != -1)
|
||||
if (_CurrentVideo != null)
|
||||
{
|
||||
CVideo.Close(_CurrentVideo);
|
||||
_CurrentVideo = -1;
|
||||
CDraw.RemoveTexture(ref _CurrentVideoTexture);
|
||||
CVideo.Close(ref _CurrentVideo);
|
||||
}
|
||||
CDraw.RemoveTexture(ref _Background);
|
||||
|
||||
@@ -624,8 +620,6 @@ namespace Vocaluxe.Screens
|
||||
}
|
||||
CGame.ResetPlayer();
|
||||
|
||||
CDraw.RemoveTexture(ref _CurrentVideoTexture);
|
||||
|
||||
if (!String.IsNullOrEmpty(song.VideoFileName))
|
||||
{
|
||||
_CurrentVideo = CVideo.Load(Path.Combine(song.Folder, song.VideoFileName));
|
||||
|
||||
@@ -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