gstreamer-sharp: Query duration async
This commit is contained in:
1 parent
f4fca4d798
commit
5bac5e98bf
4 files changed
+89
-30
No files matched your search
@@ -198,7 +198,7 @@ namespace Vocaluxe.Base
|
|||||||
timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream);
|
timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream);
|
||||||
|
|
||||||
bool finished = CSound.IsFinished(_CurrentMusicStream);
|
bool finished = CSound.IsFinished(_CurrentMusicStream);
|
||||||
if (IsPlaying && (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished))
|
if (IsPlaying && ((timeToPlay <= CSettings.BackgroundMusicFadeTime && timeToPlay > 0) || finished))
|
||||||
{
|
{
|
||||||
if (_RepeatSong)
|
if (_RepeatSong)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
public bool IsPaused(int stream)
|
public bool IsPaused(int stream)
|
||||||
{
|
{
|
||||||
if (!Streams.ContainsKey(stream))
|
if (!Streams.ContainsKey(stream))
|
||||||
return true;
|
return false;
|
||||||
return Streams[stream].Paused;
|
return Streams[stream].Paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,8 +206,8 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
{
|
{
|
||||||
private Element _Element;
|
private Element _Element;
|
||||||
private bool _Loop;
|
private bool _Loop;
|
||||||
public bool _Closed;
|
public volatile bool _Closed;
|
||||||
public bool _Finished;
|
public volatile bool _Finished;
|
||||||
|
|
||||||
private bool _Fading;
|
private bool _Fading;
|
||||||
private bool _CloseStreamAfterFade;
|
private bool _CloseStreamAfterFade;
|
||||||
@@ -219,6 +219,10 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
private float _Volume = 100f;
|
private float _Volume = 100f;
|
||||||
|
|
||||||
public float _MaxVolume = 100f;
|
public float _MaxVolume = 100f;
|
||||||
|
|
||||||
|
private volatile float _Duration = -1f;
|
||||||
|
private volatile float _Position = 0f;
|
||||||
|
private volatile bool _QueryingDuration = false;
|
||||||
public CGstreamerSharpAudioStream(string media, bool prescan)
|
public CGstreamerSharpAudioStream(string media, bool prescan)
|
||||||
{
|
{
|
||||||
var convert = ElementFactory.Make("audioconvert", "convert");
|
var convert = ElementFactory.Make("audioconvert", "convert");
|
||||||
@@ -250,8 +254,14 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
_Element["uri"] = new Uri(media).AbsoluteUri;
|
_Element["uri"] = new Uri(media).AbsoluteUri;
|
||||||
_Element.SetState(State.Paused);
|
_Element.SetState(State.Paused);
|
||||||
|
|
||||||
if (prescan)
|
// Passing CLOCK_TIME_NONE here causes the pipeline to block for a long time so with
|
||||||
_Element.Bus.TimedPopFiltered(0xffffffffffffffff, MessageType.AsyncDone);
|
// prescan enabled the pipeline will wait 500ms for stream to initialize and then continue
|
||||||
|
/*if (prescan)
|
||||||
|
{
|
||||||
|
var msg = _Element.Bus.TimedPopFiltered(100L * Constants.MSECOND, MessageType.DurationChanged);
|
||||||
|
if(msg.Handle != IntPtr.Zero)
|
||||||
|
UpdateDuration();
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMessage(Message msg)
|
private void OnMessage(Message msg)
|
||||||
@@ -269,7 +279,10 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
string debug;
|
string debug;
|
||||||
msg.ParseError(out error, out debug);
|
msg.ParseError(out error, out debug);
|
||||||
CLog.LogError("Gstreamer error: message" + error.Message + ", code" + error.Code + " ,debug information" + debug);
|
CLog.LogError("Gstreamer error: message" + error.Message + ", code" + error.Code + " ,debug information" + debug);
|
||||||
break;
|
break;
|
||||||
|
case MessageType.DurationChanged:
|
||||||
|
UpdateDuration();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
msg.Unref();
|
msg.Unref();
|
||||||
}
|
}
|
||||||
@@ -277,12 +290,21 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
if (_Element != null)
|
if (!_Closed)
|
||||||
{
|
{
|
||||||
_Element.SetState(State.Null);
|
|
||||||
|
_Closed = true;
|
||||||
|
_Finished = true;
|
||||||
|
var t = new System.Threading.Thread(TerminateStream);
|
||||||
|
t.Start();
|
||||||
}
|
}
|
||||||
_Closed = true;
|
|
||||||
_Finished = true;
|
}
|
||||||
|
|
||||||
|
private void TerminateStream()
|
||||||
|
{
|
||||||
|
if (_Element != null)
|
||||||
|
; //_Element.SetState(State.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play(bool loop = false)
|
public void Play(bool loop = false)
|
||||||
@@ -356,11 +378,12 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
long duration = 0;
|
if (_Duration < 0 && !_QueryingDuration)
|
||||||
if (_Element != null)
|
{
|
||||||
if (!_Element.QueryDuration(Format.Time, out duration))
|
var t = new System.Threading.Thread(UpdateDuration);
|
||||||
CLog.LogError("Could not query duration");
|
t.Start();
|
||||||
return duration > 0 ? (duration / (long)Constants.SECOND) : 100;
|
}
|
||||||
|
return _Duration > 0 ? _Duration : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,10 +392,11 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
long position = 0;
|
long position = 0;
|
||||||
if (_Element != null)
|
if (!_Element.QueryPosition(Format.Time, out position))
|
||||||
if (!_Element.QueryPosition(Format.Time, out position))
|
CLog.LogError("Could not query position");
|
||||||
CLog.LogError("Could not query position");
|
else
|
||||||
return (float)(position / (double)Constants.SECOND);
|
_Position = (float)(position / (double)Constants.SECOND);
|
||||||
|
return _Position;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -385,7 +409,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _Element != null ? _Element.CurrentState == State.Paused : true;
|
return _Element != null ? _Element.TargetState == State.Paused : true;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -398,7 +422,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _Element != null ? _Element.CurrentState == State.Playing : false;
|
return _Element != null ? _Element.TargetState == State.Playing : false;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -436,6 +460,18 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateDuration()
|
||||||
|
{
|
||||||
|
_QueryingDuration = true;
|
||||||
|
long duration = -1;
|
||||||
|
while (duration < 0 && !_Closed && !_Finished && _Element != null)
|
||||||
|
{
|
||||||
|
if (_Element.QueryDuration(Format.Time, out duration))
|
||||||
|
_Duration = (float)(duration / (long)Constants.SECOND);
|
||||||
|
}
|
||||||
|
_QueryingDuration = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,6 +94,7 @@ namespace Vocaluxe.Screens
|
|||||||
|
|
||||||
private int _CurrentBeat;
|
private int _CurrentBeat;
|
||||||
private int _CurrentStream = -1;
|
private int _CurrentStream = -1;
|
||||||
|
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 int _CurrentVideo = -1;
|
||||||
@@ -417,6 +418,7 @@ namespace Vocaluxe.Screens
|
|||||||
_CurrentBeat = -100;
|
_CurrentBeat = -100;
|
||||||
_CurrentTime = 0f;
|
_CurrentTime = 0f;
|
||||||
_FinishTime = 0f;
|
_FinishTime = 0f;
|
||||||
|
_Length = -1f;
|
||||||
_TimeToFirstNote = 0f;
|
_TimeToFirstNote = 0f;
|
||||||
_TimeToFirstNoteDuet = 0f;
|
_TimeToFirstNoteDuet = 0f;
|
||||||
_Pause = false;
|
_Pause = false;
|
||||||
@@ -1302,6 +1304,9 @@ namespace Vocaluxe.Screens
|
|||||||
totalTime -= song.Start;
|
totalTime -= song.Start;
|
||||||
float currentTime = _CurrentTime - song.Start;
|
float currentTime = _CurrentTime - song.Start;
|
||||||
|
|
||||||
|
if (_Length < 0 && totalTime > 0)
|
||||||
|
_PrepareTimeLine();
|
||||||
|
|
||||||
if (totalTime <= 0f)
|
if (totalTime <= 0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1382,6 +1387,8 @@ namespace Vocaluxe.Screens
|
|||||||
if (totalTime <= 0f)
|
if (totalTime <= 0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_Length = totalTime;
|
||||||
|
|
||||||
foreach (CVoice voice in song.Notes.Voices)
|
foreach (CVoice voice in song.Notes.Voices)
|
||||||
{
|
{
|
||||||
foreach (CSongLine line in voice.Lines.Where(line => line.VisibleInTimeLine))
|
foreach (CSongLine line in voice.Lines.Where(line => line.VisibleInTimeLine))
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
|
|
||||||
private bool _SmallView;
|
private bool _SmallView;
|
||||||
|
|
||||||
|
private float _Length = -1f;
|
||||||
|
|
||||||
public CSongMenuTileBoard(int partyModeID)
|
public CSongMenuTileBoard(int partyModeID)
|
||||||
: base(partyModeID) {}
|
: base(partyModeID) {}
|
||||||
|
|
||||||
@@ -132,6 +134,9 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
for (int i = 0; i < _Tiles.Count; i++)
|
for (int i = 0; i < _Tiles.Count; i++)
|
||||||
_Tiles[i].Selected = _Locked == i + _Offset;
|
_Tiles[i].Selected = _Locked == i + _Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_Length < 0 && CBase.Sound.GetLength(_PreviewSongStream) > 0 && CBase.Songs.IsInCategory())
|
||||||
|
UpdateLength(CBase.Songs.GetVisibleSong(_PreviewId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _UpdatePreview()
|
private void _UpdatePreview()
|
||||||
@@ -145,6 +150,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
_VideoIcon.Visible = false;
|
_VideoIcon.Visible = false;
|
||||||
_MedleyCalcIcon.Visible = false;
|
_MedleyCalcIcon.Visible = false;
|
||||||
_MedleyTagIcon.Visible = false;
|
_MedleyTagIcon.Visible = false;
|
||||||
|
_Length = -1f;
|
||||||
|
|
||||||
//Check if nothing is selected (for preview)
|
//Check if nothing is selected (for preview)
|
||||||
if (_PreviewId < 0)
|
if (_PreviewId < 0)
|
||||||
@@ -173,14 +179,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
_MedleyCalcIcon.Visible = song.Medley.Source == EDataSource.Calculated;
|
_MedleyCalcIcon.Visible = song.Medley.Source == EDataSource.Calculated;
|
||||||
_MedleyTagIcon.Visible = song.Medley.Source == EDataSource.Tag;
|
_MedleyTagIcon.Visible = song.Medley.Source == EDataSource.Tag;
|
||||||
|
|
||||||
float time = CBase.Sound.GetLength(_PreviewSongStream);
|
UpdateLength(song);
|
||||||
if (Math.Abs(song.Finish) > 0.001)
|
|
||||||
time = song.Finish;
|
|
||||||
|
|
||||||
time -= song.Start;
|
|
||||||
var min = (int)Math.Floor(time / 60f);
|
|
||||||
var sec = (int)(time - min * 60f);
|
|
||||||
_SongLength.Text = min.ToString("00") + ":" + sec.ToString("00");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -197,6 +196,23 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateLength(CSong song)
|
||||||
|
{
|
||||||
|
float time = CBase.Sound.GetLength(_PreviewSongStream);
|
||||||
|
if (Math.Abs(song.Finish) > 0.001)
|
||||||
|
time = song.Finish;
|
||||||
|
|
||||||
|
// The audiobackend is not yet ready to return the length
|
||||||
|
if (time > 0)
|
||||||
|
{
|
||||||
|
time -= song.Start;
|
||||||
|
var min = (int)Math.Floor(time / 60f);
|
||||||
|
var sec = (int)(time - min * 60f);
|
||||||
|
_SongLength.Text = min.ToString("00") + ":" + sec.ToString("00");
|
||||||
|
_Length = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnShow()
|
public override void OnShow()
|
||||||
{
|
{
|
||||||
if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory())
|
if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory())
|
||||||
|
|||||||
Reference in new issue
Block a user