Removed video lock (decoder list is used just from main thread)

This commit is contained in:
Flamefire committed 2013-05-26 01:23:49 +02:00
1 parent b493a1f3d7
commit 382429ab5e
1 file changed
+2 -37
+2 -37
View File
@@ -17,7 +17,6 @@
// */ // */
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Vocaluxe.Lib.Video.Acinerella; using Vocaluxe.Lib.Video.Acinerella;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -29,8 +28,6 @@ namespace Vocaluxe.Lib.Video
private readonly Dictionary<int, CDecoder> _Decoder = new Dictionary<int, CDecoder>(); private readonly Dictionary<int, CDecoder> _Decoder = new Dictionary<int, CDecoder>();
private int _LastID; private int _LastID;
private readonly Object _MutexDecoder = new Object();
public bool Init() public bool Init()
{ {
CloseAll(); CloseAll();
@@ -38,34 +35,26 @@ namespace Vocaluxe.Lib.Video
} }
public void CloseAll() public void CloseAll()
{
lock (_MutexDecoder)
{ {
foreach (var decoder in _Decoder.Values) foreach (var decoder in _Decoder.Values)
decoder.Close(); decoder.Close();
_Decoder.Clear(); _Decoder.Clear();
} }
}
public int Load(string videoFileName) public int Load(string videoFileName)
{ {
CDecoder decoder = new CDecoder(); var decoder = new CDecoder();
if (decoder.Open(videoFileName)) if (decoder.Open(videoFileName))
{
lock (_MutexDecoder)
{ {
int id = _LastID++; int id = _LastID++;
_Decoder.Add(id, decoder); _Decoder.Add(id, decoder);
return id; return id;
} }
}
return -1; return -1;
} }
public bool Close(int streamID) public bool Close(int streamID)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
@@ -74,7 +63,6 @@ namespace Vocaluxe.Lib.Video
_Decoder.Remove(streamID); _Decoder.Remove(streamID);
return true; return true;
} }
}
return false; return false;
} }
@@ -84,82 +72,59 @@ namespace Vocaluxe.Lib.Video
} }
public bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime) public bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime)
{
videoTime = 0;
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
return decoder.GetFrame(ref frame, time, out videoTime); return decoder.GetFrame(ref frame, time, out videoTime);
} videoTime = 0;
return false; return false;
} }
public float GetLength(int streamID) public float GetLength(int streamID)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
return decoder.Length; return decoder.Length;
}
return 0f; return 0f;
} }
public bool Skip(int streamID, float start, float gap) public bool Skip(int streamID, float start, float gap)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, 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(int streamID, bool loop)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
decoder.Loop = loop; decoder.Loop = loop;
} }
}
public void Pause(int streamID) public void Pause(int streamID)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
decoder.Paused = true; decoder.Paused = true;
} }
}
public void Resume(int streamID) public void Resume(int streamID)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
decoder.Paused = false; decoder.Paused = false;
} }
}
public bool Finished(int streamID) public bool Finished(int streamID)
{
lock (_MutexDecoder)
{ {
CDecoder decoder; CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder)) if (_Decoder.TryGetValue(streamID, out decoder))
return decoder.Finished; return decoder.Finished;
}
return true; return true;
} }
public void Update() {} public void Update() {}
} }
} }