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>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>DMX2</RootNamespace>
|
<RootNamespace>DMX2</RootNamespace>
|
||||||
<AssemblyName>DMX-2.0</AssemblyName>
|
<AssemblyName>DMX-2.0</AssemblyName>
|
||||||
<ReleaseVersion>2.0</ReleaseVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|
@ -50,10 +49,6 @@
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
<Package>gtk-sharp-2.0</Package>
|
<Package>gtk-sharp-2.0</Package>
|
||||||
</Reference>
|
</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" />
|
<Reference Include="System.Web" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace DMX2
|
namespace DMX2
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +33,7 @@ namespace DMX2
|
||||||
|
|
||||||
SeqSonUI ui=null;
|
SeqSonUI ui=null;
|
||||||
|
|
||||||
static bool gsinit=false;
|
Process mplayerProcess = null;
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
List<string> files = new List<string>();
|
||||||
|
|
||||||
|
|
@ -39,10 +41,7 @@ namespace DMX2
|
||||||
|
|
||||||
uint volume=100;
|
uint volume=100;
|
||||||
|
|
||||||
delegate void Task ();
|
|
||||||
|
|
||||||
System.Collections.Concurrent.ConcurrentQueue<Task> taskQueue =
|
|
||||||
new System.Collections.Concurrent.ConcurrentQueue<Task>();
|
|
||||||
|
|
||||||
TimeSpan fading=TimeSpan.Zero;
|
TimeSpan fading=TimeSpan.Zero;
|
||||||
TimeSpan fadeLen;
|
TimeSpan fadeLen;
|
||||||
|
|
@ -50,10 +49,7 @@ namespace DMX2
|
||||||
int fadeVEnd;
|
int fadeVEnd;
|
||||||
|
|
||||||
TimeSpan duration = TimeSpan.Zero;
|
TimeSpan duration = TimeSpan.Zero;
|
||||||
|
TimeSpan position = TimeSpan.Zero;
|
||||||
Gst.Element element = null;
|
|
||||||
Gst.State state,pending;
|
|
||||||
Gst.StateChangeReturn scret;
|
|
||||||
|
|
||||||
bool repeat = false;
|
bool repeat = false;
|
||||||
|
|
||||||
|
|
@ -71,6 +67,7 @@ namespace DMX2
|
||||||
|
|
||||||
public int Index {
|
public int Index {
|
||||||
get {
|
get {
|
||||||
|
|
||||||
return files.IndexOf (curfile);
|
return files.IndexOf (curfile);
|
||||||
}
|
}
|
||||||
set {
|
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)
|
public int AddFile (int pos, string file)
|
||||||
{
|
{
|
||||||
lock (this) {
|
lock (this) {
|
||||||
|
|
@ -95,38 +131,26 @@ namespace DMX2
|
||||||
get{ return volume;}
|
get{ return volume;}
|
||||||
set {
|
set {
|
||||||
volume=value;
|
volume=value;
|
||||||
if(element!=null)
|
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
|
||||||
element["volume"] = (double)volume / 100.0d ;
|
|
||||||
volumeEventTarget.FeedBack ();
|
volumeEventTarget.FeedBack ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSpan PlayTime {
|
public TimeSpan PlayTime {
|
||||||
get{
|
get{
|
||||||
if(element==null) return TimeSpan.Zero;
|
if(mplayerProcess!=null && !mplayerProcess.HasExited)
|
||||||
Gst.Format format = Gst.Format.Time ; long cur;
|
mplayerProcess.StandardInput.WriteLine ("get_time_pos");
|
||||||
element.QueryPosition(ref format, out cur);
|
return position;
|
||||||
return TimeSpan.FromMilliseconds(cur/1000000);
|
|
||||||
}
|
}
|
||||||
set{
|
set{
|
||||||
if(element==null) return;
|
if (CheckMplayer ()) {
|
||||||
QueueTask(delegate(){
|
mplayerProcess.StandardInput.WriteLine ("seek {0} 2", value.TotalMilliseconds / 1000);
|
||||||
//Console.WriteLine("Seek");
|
}
|
||||||
long pos = (long)(value.TotalMilliseconds) * 1000000;
|
|
||||||
element.Seek (Gst.Format.Time,Gst.SeekFlags.Flush|Gst.SeekFlags.Accurate,pos);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSpan Duration {
|
public TimeSpan Duration {
|
||||||
get {
|
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;
|
return duration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,55 +169,42 @@ namespace DMX2
|
||||||
|
|
||||||
curfile = files[pos];
|
curfile = files[pos];
|
||||||
Stop();
|
Stop();
|
||||||
|
mplayerProcess.StandardInput.WriteLine ("volume 0 1");
|
||||||
duration = TimeSpan.Zero;
|
mplayerProcess.StandardInput.WriteLine ("loadfile \"{0}\" 0", curfile);
|
||||||
|
mplayerProcess.StandardInput.WriteLine ("get_time_length");
|
||||||
Uri uri = new Uri(curfile);
|
mplayerProcess.StandardInput.WriteLine ("pausing seek 0 2");
|
||||||
|
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
|
||||||
element = Gst.ElementFactory.Make("playbin");
|
Paused = true;
|
||||||
element["uri"] = uri.AbsoluteUri;
|
|
||||||
element.SetState(Gst.State.Paused);
|
|
||||||
element["volume"] = (double)volume / 100.0d ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play ()
|
public void Play ()
|
||||||
{
|
{
|
||||||
if(element == null)return;
|
if (curfile==null || !Paused)
|
||||||
QueueTask(delegate(){
|
return;
|
||||||
//Console.WriteLine("Play");
|
if (!CheckMplayer ())
|
||||||
element.SetState(Gst.State.Playing);
|
return;
|
||||||
});
|
mplayerProcess.StandardInput.WriteLine ("pause");
|
||||||
|
Paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Pause ()
|
public void Pause ()
|
||||||
{
|
{
|
||||||
if(element == null)return;
|
if (curfile==null || Paused)
|
||||||
QueueTask(delegate(){
|
return;
|
||||||
element.SetState(Gst.State.Paused);
|
if (!CheckMplayer ())
|
||||||
});
|
return;
|
||||||
|
mplayerProcess.StandardInput.WriteLine ("pause");
|
||||||
|
Paused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop ()
|
public void Stop ()
|
||||||
{
|
{
|
||||||
if(element == null)return;
|
CheckMplayer ();
|
||||||
element.SetState(Gst.State.Null);
|
mplayerProcess.StandardInput.WriteLine ("stop");
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SequenceurSon ()
|
public SequenceurSon ()
|
||||||
{
|
{
|
||||||
GstInit();
|
|
||||||
volumeEventTarget = new actionEventTargetEx (
|
volumeEventTarget = new actionEventTargetEx (
|
||||||
delegate(EventData data) {
|
delegate(EventData data) {
|
||||||
Volume = (uint)(100 * data.value / 255);
|
Volume = (uint)(100 * data.value / 255);
|
||||||
|
|
@ -230,52 +241,16 @@ namespace DMX2
|
||||||
|
|
||||||
public string State {
|
public string State {
|
||||||
get {
|
get {
|
||||||
if(element == null) return "Stopped";
|
return string.Empty;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateState ()
|
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)
|
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) {
|
if (fading != TimeSpan.Zero) {
|
||||||
fading-=time;
|
fading-=time;
|
||||||
|
|
@ -291,11 +266,6 @@ namespace DMX2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (repeat) {
|
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
|
#region IDisposable implementation
|
||||||
void IDisposable.Dispose ()
|
void IDisposable.Dispose ()
|
||||||
{
|
{
|
||||||
if(element==null)return;
|
if (mplayerProcess != null && !mplayerProcess.HasExited) {
|
||||||
element.SetState(Gst.State.Null);
|
mplayerProcess.StandardInput.WriteLine ("quit");
|
||||||
element.Dispose();
|
if (!mplayerProcess.WaitForExit (1000))
|
||||||
element=null;
|
mplayerProcess.Kill ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
0
configure
vendored
Executable file → Normal file
0
configure
vendored
Executable file → Normal file
Loading…
Reference in a new issue