Modif SeqSON -> abandon gstreamer pour mplayer
This commit is contained in:
parent
6393439f31
commit
6dc84ae469
3 changed files with 78 additions and 112 deletions
|
|
@ -9,7 +9,6 @@
|
|||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>DMX2</RootNamespace>
|
||||
<AssemblyName>DMX-2.0</AssemblyName>
|
||||
<ReleaseVersion>2.0</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
|
@ -50,10 +49,6 @@
|
|||
<Private>False</Private>
|
||||
<Package>gtk-sharp-2.0</Package>
|
||||
</Reference>
|
||||
<Reference Include="gstreamer-sharp, Version=0.9.2.0, Culture=neutral, PublicKeyToken=4956b48baf980190">
|
||||
<Private>False</Private>
|
||||
<Package>gstreamer-sharp-0.10</Package>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ using System.Collections.Generic;
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.Xml;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DMX2
|
||||
{
|
||||
|
|
@ -31,18 +33,15 @@ namespace DMX2
|
|||
|
||||
SeqSonUI ui=null;
|
||||
|
||||
static bool gsinit=false;
|
||||
Process mplayerProcess = null;
|
||||
|
||||
List<string> files = new List<string>();
|
||||
|
||||
string curfile = string.Empty;
|
||||
|
||||
uint volume=100;
|
||||
|
||||
|
||||
delegate void Task ();
|
||||
|
||||
System.Collections.Concurrent.ConcurrentQueue<Task> taskQueue =
|
||||
new System.Collections.Concurrent.ConcurrentQueue<Task>();
|
||||
|
||||
TimeSpan fading=TimeSpan.Zero;
|
||||
TimeSpan fadeLen;
|
||||
|
|
@ -50,10 +49,7 @@ namespace DMX2
|
|||
int fadeVEnd;
|
||||
|
||||
TimeSpan duration = TimeSpan.Zero;
|
||||
|
||||
Gst.Element element = null;
|
||||
Gst.State state,pending;
|
||||
Gst.StateChangeReturn scret;
|
||||
TimeSpan position = TimeSpan.Zero;
|
||||
|
||||
bool repeat = false;
|
||||
|
||||
|
|
@ -71,6 +67,7 @@ namespace DMX2
|
|||
|
||||
public int Index {
|
||||
get {
|
||||
|
||||
return files.IndexOf (curfile);
|
||||
}
|
||||
set {
|
||||
|
|
@ -81,6 +78,45 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
|
||||
bool Paused{ get; set;}
|
||||
|
||||
bool CheckMplayer(){
|
||||
if (mplayerProcess == null || mplayerProcess.HasExited) {
|
||||
if (mplayerProcess != null)
|
||||
mplayerProcess.Dispose ();
|
||||
ProcessStartInfo startinfo = new ProcessStartInfo ();
|
||||
startinfo.FileName = "mplayer";
|
||||
startinfo.Arguments = "--quiet --idle --slave";
|
||||
startinfo.RedirectStandardInput = true;
|
||||
startinfo.RedirectStandardOutput = true;
|
||||
startinfo.UseShellExecute = false;
|
||||
|
||||
mplayerProcess = Process.Start (startinfo);
|
||||
mplayerProcess.OutputDataReceived += ProcessMplayerOut;
|
||||
mplayerProcess.BeginOutputReadLine ();
|
||||
return !mplayerProcess.HasExited;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessMplayerOut (object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
string data = e.Data;
|
||||
if (data.StartsWith ("ANS_LENGTH")) {
|
||||
string d = data.Substring (11);
|
||||
double dData;
|
||||
if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData))
|
||||
duration = TimeSpan.FromSeconds( dData );
|
||||
}
|
||||
if (data.StartsWith ("ANS_TIME_POSITION")) {
|
||||
string d = data.Substring (18);
|
||||
double dData;
|
||||
if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData))
|
||||
position = TimeSpan.FromSeconds( dData );
|
||||
}
|
||||
Console.WriteLine ("data => {0}", data);
|
||||
}
|
||||
|
||||
public int AddFile (int pos, string file)
|
||||
{
|
||||
lock (this) {
|
||||
|
|
@ -95,38 +131,26 @@ namespace DMX2
|
|||
get{ return volume;}
|
||||
set {
|
||||
volume=value;
|
||||
if(element!=null)
|
||||
element["volume"] = (double)volume / 100.0d ;
|
||||
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
|
||||
volumeEventTarget.FeedBack ();
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan PlayTime {
|
||||
get{
|
||||
if(element==null) return TimeSpan.Zero;
|
||||
Gst.Format format = Gst.Format.Time ; long cur;
|
||||
element.QueryPosition(ref format, out cur);
|
||||
return TimeSpan.FromMilliseconds(cur/1000000);
|
||||
if(mplayerProcess!=null && !mplayerProcess.HasExited)
|
||||
mplayerProcess.StandardInput.WriteLine ("get_time_pos");
|
||||
return position;
|
||||
}
|
||||
set{
|
||||
if(element==null) return;
|
||||
QueueTask(delegate(){
|
||||
//Console.WriteLine("Seek");
|
||||
long pos = (long)(value.TotalMilliseconds) * 1000000;
|
||||
element.Seek (Gst.Format.Time,Gst.SeekFlags.Flush|Gst.SeekFlags.Accurate,pos);
|
||||
});
|
||||
if (CheckMplayer ()) {
|
||||
mplayerProcess.StandardInput.WriteLine ("seek {0} 2", value.TotalMilliseconds / 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan Duration {
|
||||
get {
|
||||
if(element==null) return TimeSpan.Zero;
|
||||
if(duration == TimeSpan.Zero)
|
||||
{
|
||||
Gst.Format fmt = Gst.Format.Time; long dur;
|
||||
element.QueryDuration(ref fmt,out dur);
|
||||
return TimeSpan.FromMilliseconds(dur/1000000);
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
|
|
@ -145,55 +169,42 @@ namespace DMX2
|
|||
|
||||
curfile = files[pos];
|
||||
Stop();
|
||||
|
||||
duration = TimeSpan.Zero;
|
||||
|
||||
Uri uri = new Uri(curfile);
|
||||
|
||||
element = Gst.ElementFactory.Make("playbin");
|
||||
element["uri"] = uri.AbsoluteUri;
|
||||
element.SetState(Gst.State.Paused);
|
||||
element["volume"] = (double)volume / 100.0d ;
|
||||
mplayerProcess.StandardInput.WriteLine ("volume 0 1");
|
||||
mplayerProcess.StandardInput.WriteLine ("loadfile \"{0}\" 0", curfile);
|
||||
mplayerProcess.StandardInput.WriteLine ("get_time_length");
|
||||
mplayerProcess.StandardInput.WriteLine ("pausing seek 0 2");
|
||||
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
|
||||
Paused = true;
|
||||
}
|
||||
|
||||
public void Play ()
|
||||
{
|
||||
if(element == null)return;
|
||||
QueueTask(delegate(){
|
||||
//Console.WriteLine("Play");
|
||||
element.SetState(Gst.State.Playing);
|
||||
});
|
||||
if (curfile==null || !Paused)
|
||||
return;
|
||||
if (!CheckMplayer ())
|
||||
return;
|
||||
mplayerProcess.StandardInput.WriteLine ("pause");
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
public void Pause ()
|
||||
{
|
||||
if(element == null)return;
|
||||
QueueTask(delegate(){
|
||||
element.SetState(Gst.State.Paused);
|
||||
});
|
||||
if (curfile==null || Paused)
|
||||
return;
|
||||
if (!CheckMplayer ())
|
||||
return;
|
||||
mplayerProcess.StandardInput.WriteLine ("pause");
|
||||
Paused = true;
|
||||
}
|
||||
|
||||
public void Stop ()
|
||||
{
|
||||
if(element == null)return;
|
||||
element.SetState(Gst.State.Null);
|
||||
element.Dispose();
|
||||
element=null;
|
||||
Task t;
|
||||
while(taskQueue.TryDequeue (out t));
|
||||
}
|
||||
|
||||
static void GstInit ()
|
||||
{
|
||||
if(gsinit) return;
|
||||
gsinit=true;
|
||||
string[] args = new string[] {"--gst-disable-segtrap"};
|
||||
Gst.Application.Init("dmx2", ref args );
|
||||
CheckMplayer ();
|
||||
mplayerProcess.StandardInput.WriteLine ("stop");
|
||||
}
|
||||
|
||||
public SequenceurSon ()
|
||||
{
|
||||
GstInit();
|
||||
volumeEventTarget = new actionEventTargetEx (
|
||||
delegate(EventData data) {
|
||||
Volume = (uint)(100 * data.value / 255);
|
||||
|
|
@ -230,52 +241,16 @@ namespace DMX2
|
|||
|
||||
public string State {
|
||||
get {
|
||||
if(element == null) return "Stopped";
|
||||
UpdateState();
|
||||
string rpStr = repeat ? " (r)" : string.Empty;
|
||||
if(pending == Gst.State.VoidPending){
|
||||
return string.Format("{0}{1}", state.ToString(),rpStr);
|
||||
}
|
||||
if(scret == Gst.StateChangeReturn.Async)
|
||||
return string.Format("{0}=>{1}{2}", state,pending,rpStr);
|
||||
return string.Format("{0}=>{1} : {2} {3}",state,pending,scret,rpStr);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateState ()
|
||||
{
|
||||
scret = element.GetState (out state, out pending, 0UL);
|
||||
}
|
||||
|
||||
bool CheckAsync ()
|
||||
{
|
||||
if (element == null) return false;
|
||||
UpdateState ();
|
||||
return (scret != Gst.StateChangeReturn.Async);
|
||||
}
|
||||
|
||||
void QueueTask (Task t)
|
||||
{
|
||||
if (CheckAsync ()) {
|
||||
//Console.WriteLine("Sync");
|
||||
t();
|
||||
return;
|
||||
}
|
||||
//Console.WriteLine("Queue");
|
||||
taskQueue.Enqueue(t);
|
||||
}
|
||||
|
||||
public override void Tick (TimeSpan time)
|
||||
{
|
||||
if (taskQueue.Count>0 && CheckAsync()){
|
||||
//Console.WriteLine(State);
|
||||
Task task;
|
||||
if(taskQueue.TryDequeue(out task))
|
||||
{
|
||||
//Console.WriteLine("ASync");
|
||||
task();
|
||||
}
|
||||
}
|
||||
|
||||
if (fading != TimeSpan.Zero) {
|
||||
fading-=time;
|
||||
|
|
@ -291,11 +266,6 @@ namespace DMX2
|
|||
}
|
||||
}
|
||||
if (repeat) {
|
||||
if (state == Gst.State.Playing) {
|
||||
if ((Duration - PlayTime).TotalSeconds < 0.001) {
|
||||
PlayTime = TimeSpan.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -478,10 +448,11 @@ namespace DMX2
|
|||
#region IDisposable implementation
|
||||
void IDisposable.Dispose ()
|
||||
{
|
||||
if(element==null)return;
|
||||
element.SetState(Gst.State.Null);
|
||||
element.Dispose();
|
||||
element=null;
|
||||
if (mplayerProcess != null && !mplayerProcess.HasExited) {
|
||||
mplayerProcess.StandardInput.WriteLine ("quit");
|
||||
if (!mplayerProcess.WaitForExit (1000))
|
||||
mplayerProcess.Kill ();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
0
configure
vendored
Executable file → Normal file
0
configure
vendored
Executable file → Normal file
Loading…
Reference in a new issue