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
+34 -69
+34 -69
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();
@@ -39,41 +36,32 @@ namespace Vocaluxe.Lib.Video
public void CloseAll() public void CloseAll()
{ {
lock (_MutexDecoder) foreach (var decoder in _Decoder.Values)
{ decoder.Close();
foreach (var decoder in _Decoder.Values) _Decoder.Clear();
decoder.Close();
_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++;
{ _Decoder.Add(id, decoder);
int id = _LastID++; return id;
_Decoder.Add(id, decoder);
return id;
}
} }
return -1; return -1;
} }
public bool Close(int streamID) public bool Close(int streamID)
{ {
lock (_MutexDecoder) CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder))
{ {
CDecoder decoder; decoder.Close();
if (_Decoder.TryGetValue(streamID, out decoder)) _Decoder.Remove(streamID);
{ return true;
decoder.Close();
_Decoder.Remove(streamID);
return true;
}
} }
return false; return false;
} }
@@ -85,81 +73,58 @@ 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)
{ {
CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder))
return decoder.GetFrame(ref frame, time, out videoTime);
videoTime = 0; videoTime = 0;
lock (_MutexDecoder)
{
CDecoder decoder;
if (_Decoder.TryGetValue(streamID, out decoder))
return decoder.GetFrame(ref frame, time, out videoTime);
}
return false; return false;
} }
public float GetLength(int streamID) public float GetLength(int streamID)
{ {
lock (_MutexDecoder) CDecoder decoder;
{ if (_Decoder.TryGetValue(streamID, out decoder))
CDecoder decoder; return decoder.Length;
if (_Decoder.TryGetValue(streamID, out decoder))
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;
{ if (_Decoder.TryGetValue(streamID, out decoder))
CDecoder decoder; return decoder.Skip(start, gap);
if (_Decoder.TryGetValue(streamID, out decoder))
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;
{ if (_Decoder.TryGetValue(streamID, out decoder))
CDecoder decoder; decoder.Loop = loop;
if (_Decoder.TryGetValue(streamID, out decoder))
decoder.Loop = loop;
}
} }
public void Pause(int streamID) public void Pause(int streamID)
{ {
lock (_MutexDecoder) CDecoder decoder;
{ if (_Decoder.TryGetValue(streamID, out decoder))
CDecoder decoder; decoder.Paused = true;
if (_Decoder.TryGetValue(streamID, out decoder))
decoder.Paused = true;
}
} }
public void Resume(int streamID) public void Resume(int streamID)
{ {
lock (_MutexDecoder) CDecoder decoder;
{ if (_Decoder.TryGetValue(streamID, out decoder))
CDecoder decoder; decoder.Paused = false;
if (_Decoder.TryGetValue(streamID, out decoder))
decoder.Paused = false;
}
} }
public bool Finished(int streamID) public bool Finished(int streamID)
{ {
lock (_MutexDecoder) CDecoder decoder;
{ if (_Decoder.TryGetValue(streamID, out decoder))
CDecoder decoder; return decoder.Finished;
if (_Decoder.TryGetValue(streamID, out decoder))
return decoder.Finished;
}
return true; return true;
} }
public void Update(){} public void Update() {}
} }
} }