Fix Duration Update
This commit is contained in:
1 parent
dd6503c911
commit
235ce266e5
1 file changed
+11
-32
@@ -30,10 +30,7 @@ namespace Vocaluxe.Lib.Sound.Playback.GstreamerSharp
|
|||||||
private volatile bool _IsFinished;
|
private volatile bool _IsFinished;
|
||||||
|
|
||||||
private volatile float _Position;
|
private volatile float _Position;
|
||||||
private volatile bool _QueryingDuration;
|
|
||||||
private System.Threading.Thread _QueryDurationThread;
|
|
||||||
|
|
||||||
private readonly object _DurationLock = new object(); //For atomic check-and-update of _QueryingDuration
|
|
||||||
private readonly object _ElementLock = new object(); //Hold this if you set _Element=null or when accessing _Element from outside the main thread
|
private readonly object _ElementLock = new object(); //Hold this if you set _Element=null or when accessing _Element from outside the main thread
|
||||||
|
|
||||||
public override float Volume
|
public override float Volume
|
||||||
@@ -60,12 +57,9 @@ namespace Vocaluxe.Lib.Sound.Playback.GstreamerSharp
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (base.Length < 0 && _QueryDurationThread == null && _Element != null)
|
//TODO: Is it ok, to remove this? Gst should post a message if duration was changed so this should not be required
|
||||||
{
|
//if (base.Length < 0 && _Element != null)
|
||||||
// _QueryDurationThread does not get reset so it is created only once!
|
// _UpdateDuration();
|
||||||
_QueryDurationThread = new System.Threading.Thread(_UpdateDuration) {Name = "GSt Update Duration"};
|
|
||||||
_QueryDurationThread.Start();
|
|
||||||
}
|
|
||||||
return base.Length >= 0f ? base.Length : 0f;
|
return base.Length >= 0f ? base.Length : 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,12 +174,9 @@ namespace Vocaluxe.Lib.Sound.Playback.GstreamerSharp
|
|||||||
// Passing CLOCK_TIME_NONE here causes the pipeline to block for a long time so with
|
// Passing CLOCK_TIME_NONE here causes the pipeline to block for a long time so with
|
||||||
// prescan enabled the pipeline will wait 500ms for stream to initialize and then continue
|
// prescan enabled the pipeline will wait 500ms for stream to initialize and then continue
|
||||||
// if it takes more than 500ms, duration queries will be performed asynchronously
|
// if it takes more than 500ms, duration queries will be performed asynchronously
|
||||||
if (prescan)
|
Message msg = _Element.Bus.TimedPopFiltered(prescan ? ulong.MaxValue : 0L, MessageType.AsyncDone);
|
||||||
{
|
if (msg.Handle != IntPtr.Zero)
|
||||||
Message msg = _Element.Bus.TimedPopFiltered(0xffffffffffffffff, MessageType.AsyncDone);
|
_UpdateDuration();
|
||||||
if (msg.Handle != IntPtr.Zero)
|
|
||||||
_UpdateDuration();
|
|
||||||
}
|
|
||||||
_FileOpened = true;
|
_FileOpened = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -274,26 +265,14 @@ namespace Vocaluxe.Lib.Sound.Playback.GstreamerSharp
|
|||||||
|
|
||||||
private void _UpdateDuration()
|
private void _UpdateDuration()
|
||||||
{
|
{
|
||||||
if (_QueryingDuration)
|
lock (_ElementLock)
|
||||||
return;
|
|
||||||
lock (_DurationLock)
|
|
||||||
{
|
{
|
||||||
if (_QueryingDuration)
|
if (_Element == null)
|
||||||
return;
|
return;
|
||||||
_QueryingDuration = true;
|
long duration;
|
||||||
|
if (_Element.QueryDuration(Format.Time, out duration))
|
||||||
|
Length = duration / (float)Constants.SECOND;
|
||||||
}
|
}
|
||||||
long duration = -1;
|
|
||||||
while (duration < 0 && !IsFinished)
|
|
||||||
{
|
|
||||||
lock (_ElementLock)
|
|
||||||
{
|
|
||||||
if (_Element == null)
|
|
||||||
break;
|
|
||||||
if (_Element.QueryDuration(Format.Time, out duration))
|
|
||||||
Length = duration / (float)Constants.SECOND;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_QueryingDuration = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user