Beispiel #1
0
        public bool Open(Uri.Locator name)
        {
            bool result = false;

            if (name.Scheme == "file" && this.SupportedExtensions.Contains(name.Path.Extension))
            {
                this.Buffer = Photo.Buffer.Abstract.Open(name);
                Kean.Math.Fraction rate = name.Query["rate"];
                if (rate.Nominator <= 0)
                {
                    rate = this.Rate;
                }
                this.Timer    = new System.Timers.Timer(1000 / (float)rate);
                this.Duration = new TimeSpan((long)(10000 * 1000 / (float)rate));

                this.Timer.Elapsed += (object sender, System.Timers.ElapsedEventArgs elapsedArguments) =>
                {
                    lock (this.signal)
                    {
                        System.Threading.Monitor.Pulse(this.signal);
                    }
                };
                result = true;
                this.Timer.Start();
            }
            return(result);
        }
Beispiel #2
0
 protected override DirectShow.Binding.IGraph Open(Uri.Locator name)
 {
     Graph.Live result = null;
     if (name.Scheme == "directshow+capture" && name.Authority.NotNull() && name.Query.NotNull() && name.Query["video"].NotNull())
     {
         string filename = name.Query["video"];
         result          = new Graph.Live();
         result.Recorder = new DirectShow.Binding.Graph();
         if (result.Recorder.Open(new DirectShow.Binding.Filters.Capture.All(name.Authority, new DirectShow.Binding.Filters.SampleGrabber.Yuyv(new Filters.Encoder.Mpeg2(new Filters.Multiplexer.Mpeg2(new DirectShow.Binding.Filters.File.Sink(filename)))))))
         {
             result.Recorder.Play();
             System.Threading.Thread.Sleep(2000);
             bool built = result.Open(new Filters.IO.Reader(filename, new Filters.Demultiplexer.Mpeg2(new Filters.Decoder.Mpeg2(new DirectShow.Binding.Filters.SampleGrabber.All())
             {
                 Output = -1
             })));
             if (built)
             {
                 System.Threading.Thread.Sleep(1000);
                 result.Play();
             }
             else
             {
                 result.Close();
                 result = null;
             }
         }
         else
         {
             result.Close();
             result = null;
         }
     }
     return(result as DirectShow.Binding.IGraph);
 }
 protected override DirectShow.Binding.IGraph Open(Uri.Locator name)
 {
     DirectShow.Binding.IGraph result = null;
     if (name.Scheme.Head == "elecard" && name.Scheme.Tail.NotNull() && name.Scheme.Tail.Head != "file" && name.Authority.NotNull() && name.Query["video"].IsNull())
     {
         name         = name.Copy();
         this.Timeout = name.Query.Get("timeout", this.Timeout);
         this.Latency = name.Query.Get("latency", this.Latency);
         name.Query.Remove("timeout", "latency");
         name.Scheme = name.Scheme.Tail;
         result      = new DirectShow.Binding.Graph(this.Application);
         if (this.Open(result, name))
         {
             result.Play();
             result.Stop();
             result.Play();
         }
         else
         {
             result.Close();
             result = null;
         }
     }
     return(result);
 }
Beispiel #4
0
 protected override int Prepare(Uri.Locator argument)
 {
     try
     {
         if (!argument.Query.Empty)
         {
             string value = argument.Query["resolution"];
             if (value.NotEmpty())
             {
                 this.resolution = (Geometry2D.Integer.Size)value;
             }
             value = argument.Query["format"];
             if (value.NotEmpty())
             {
                 base.Format = (Colorspace)Enum.Parse(typeof(Colorspace), value, true);
             }
             value = argument.Query["frames"];
             if (value.NotEmpty())
             {
                 this.frames = Kean.Math.Integer.Parse(value);
             }
         }
     }
     catch
     {
         this.Initialize();
     }
     return(this.frames);
 }
Beispiel #5
0
        static string[] GetImageSeries(Uri.Locator name)
        {
            string[]        result;
            MatchCollection matches = Regex.Matches(name.Path.Stem, @"(.*\D+)(\d*)(\d{2})$");

            // If the file has a name ending in 2 or more digits,
            // assume series and get a sorted list of the files in it.
            // NOTE: This will include any files with an identical name before the digits,
            // including files without digits in the filename, i.e. opening a file named "image012.png"
            // will open a series including files such as "image.png" and "imagery.png" if they exist.
            if (matches.Count == 1)
            {
                string match     = matches[0].Groups[1].Value;
                string directory = System.IO.Path.GetDirectoryName(name.PlatformPath);
                result = System.IO.Directory.GetFiles(directory, match + "*." + name.Path.Extension, System.IO.SearchOption.TopDirectoryOnly).Sort();
            }
            else if (matches.Count > 1)             // This shouldn't happen, but if it does,
            // panic so we can identify why it happened
            {
                result = null;
                //TODO: throw some exception
            }
            else             // The filename didn't end in 2 or more digits, so just take the one file.
            {
                result = new string[] { name.PlatformPath }
            };
            return(result);
        }
    }
Beispiel #6
0
 protected override DirectShow.Binding.IGraph Open(Uri.Locator name)
 {
     DirectShow.Binding.IGraph result = null;
     if (name.Scheme == "directshow+capture" && name.Scheme.Tail.NotNull() && name.Authority.NotNull() && name.Query["video"].NotEmpty())
     {
         name        = name.Copy();
         name.Scheme = name.Scheme.Tail;
         DirectShow.Binding.Graph temporary = new DirectShow.Binding.Graph();
         bool built = temporary.Open(new DirectShow.Binding.Filters.Capture.All(name.Authority, new DirectShow.Binding.Filters.SampleGrabber.Yuyv(new DirectShow.Binding.Filters.NullRenderer())
         {
             FuzzyMatch = this.Fuzzy
         }));
         if (built)
         {
             temporary.Play();
             System.Threading.Thread.Sleep(500);
         }
         temporary.Close();
         temporary = null;
         result    = new DirectShow.Binding.Graph(this.Application);
         if (this.Open(result, name))
         {
             result.Play();
         }
         else
         {
             result.Close();
             result = null;
         }
     }
     return(result);
 }
Beispiel #7
0
        public bool Open(Uri.Locator name)
        {
            bool result = false;

            if (name.Scheme == "sensoray")
            {
                int device = 0;
                int stream = 0;
                if (name.Authority.NotNull() && name.Authority.Endpoint.Host.NotNull() && name.Authority.Endpoint.Host.Head.NotEmpty())
                {
                    if (name.Authority.Endpoint.Host.Tail.NotNull() && name.Authority.Endpoint.Host.Tail.Head.NotEmpty())
                    {
                        if (!(int.TryParse(name.Authority.Endpoint.Host.Head, out device)))
                        {
                            device = 0;
                        }
                        if (!(int.TryParse(name.Authority.Endpoint.Host.Tail.Head, out stream)))
                        {
                            stream = 0;
                        }
                    }
                    else if (!(int.TryParse(name.Authority.Endpoint.Host.Head, out stream)))
                    {
                        stream = 0;
                    }
                }
                string system = name.Query["system"];
                this.videoSystem        = name.Query.GetEnumeration <VideoSystem>("system", VideoSystem.Pal);
                this.device             = Device.Open(device, this.videoSystem);
                this.device.Deinterlace = name.Query.NotFalse("deinterlace");

                this.size = (Geometry2D.Integer.Size)name.Query["size"];
                if (this.size.IsNull() || this.size.Area <= 0)
                {
                    this.size = this.device.NativeSize;
                }

                this.stream = this.device[stream];

                string record = null;
                if ((record = name.Query["record"]).NotEmpty())
                {
                    result = this.stream.Start(this.size, name.Query.GetEnumeration <Encoding>("encoding", Encoding.H264), name.Query.Get("bitrate", 2500), record);
                }
                else
                {
                    result = this.stream.Start(this.size, image => this.Send(0, DateTime.Now, TimeSpan.FromSeconds(this.videoSystem == VideoSystem.Ntsc ? 1 / 30.0f : 1 / 25.0f), image.Convert <Raster.Yuv422>(), null));
                    string video = null;
                    if (result && (video = name.Query["video"]).NotEmpty())
                    {
                        this.recordStream = this.device[(stream + 1) % 2];
                        this.recordStream.Start(this.size, name.Query.GetEnumeration <Encoding>("encoding", Encoding.H264), name.Query.Get("bitrate", 2500), new Uri.Locator("file", video));
                    }
                }
                this.Status = result ? Status.Playing : Status.Closed;
            }
            return(result);
        }
Beispiel #8
0
 public virtual bool Open(Uri.Locator resource)
 {
     this.Resource = resource;
     if (this.OpenFilter.NotNull())
     {
         resource = this.OpenFilter(resource);
     }
     lock (this.Lock)
         return(this.Players.Open(resource));
 }
Beispiel #9
0
        bool Open(DirectShow.Binding.IGraph graph, Uri.Locator name)
        {
            bool   result   = false;
            string filename = name.Query["video"];

            name.Query.Remove("video");
            if (result = filename.NotEmpty())
            {
                result = graph.Open(new DirectShow.Binding.Filters.Capture.All(name.Authority, new DirectShow.Binding.Filters.SampleGrabber.Yuyv(new Filters.Encoder.Mpeg(new Filters.Multiplexer.Mpeg(new Filters.IO.Dump(filename))))));
            }
            return(result);
        }
Beispiel #10
0
 public override bool Open(Uri.Locator resource)
 {
     lock (this.@lock)
     {
         bool result = base.Open(resource);
         if (result)
         {
             base.Play();
         }
         return(result);
     }
 }
        bool Open(DirectShow.Binding.IGraph graph, Uri.Locator name)
        {
            bool result = graph.Open(new Filters.Net.RTPSource(name, new DirectShow.Binding.Filters.Decoder.Mpeg2(new DirectShow.Binding.Filters.Dmo.ColorConverter(new DirectShow.Binding.Filters.SampleGrabber.All()
            {
                FuzzyMatch = true
            })))
            {
                Output = 0
            });

            graph.Save("file:///./test.grf");
            return(result);
        }
 bool Open(DirectShow.Binding.IGraph graph, Uri.Locator name)
 {
     return(graph.Open(new Filters.Net.SourcePlus(name, new Filters.Demultiplexer.MpegPush(new Filters.Decoder.All(new DirectShow.Binding.Filters.SampleGrabber.All())
     {
         Output = -1
     })
     {
         WaitForOutput = new TimeSpan(0, 0, 0, 1), Latency = this.Latency
     })
     {
         Timeout = this.Timeout
     }) ||
            graph.Open(new Filters.Net.RtspSource(name, new Filters.Decoder.SD.Avc(new DirectShow.Binding.Filters.SampleGrabber.All()))));
 }
Beispiel #13
0
 public static Buffer.Abstract Open(Uri.Locator name)
 {
     Buffer.Abstract result;
     string[]        photoPaths = GetImageSeries(name);
     // If the series contains more than roughly 40 images, we can't store them all in memory.
     if (photoPaths.Length > 40)
     {
         result = new Buffer.Long(photoPaths);
     }
     else
     {
         result = new Buffer.Short(photoPaths);
     }
     return(result);
 }
 protected override DirectShow.Binding.IGraph Open(Uri.Locator locator)
 {
     Timeshift.Graph.NonLive result = null;
     if (locator.Scheme == "elecard+udp" && locator.Query["video"].NotNull())
     {
         string filename = locator.Query["video"];
         locator        = locator.Copy();
         locator.Scheme = "udp";
         locator.Query.Remove("video");
         result          = new Graph.NonLive();
         result.Recorder = new DirectShow.Binding.Graph();
         if (result.Recorder.Open(new Filters.Net.SourcePlus(locator, new Filters.File.Sink(filename))))
         {
             result.Recorder.Play();
             System.Threading.Thread.Sleep(1000);
             DirectShow.Binding.Filters.SampleGrabber.All samplegrabber = new DirectShow.Binding.Filters.SampleGrabber.All()
             {
                 FuzzyMatch = this.Fuzzy
             };
             bool built = result.Open(new Filters.File.Source(filename, new Filters.Demultiplexer.Mpeg(new Filters.Decoder.All(samplegrabber))
             {
                 Output = 0
             })) ||
                          result.Open(new Filters.File.Source(filename, new Filters.Demultiplexer.Mpeg(new Filters.Decoder.All(samplegrabber))
             {
                 Output = 1
             }));
             if (built)
             {
                 System.Threading.Thread.Sleep(1000);
                 result.Play();
             }
             else
             {
                 result.Close();
                 result = null;
             }
         }
         else
         {
             result.Close();
             result = null;
         }
     }
     return(result as DirectShow.Binding.IGraph);
 }
Beispiel #15
0
 protected override DirectShow.Binding.IGraph Open(Uri.Locator name)
 {
     DirectShow.Binding.IGraph result = null;
     if (name.Path.NotNull())
     {
         string file      = name.PlatformPath;
         string extension = System.IO.Path.GetExtension(file).ToLower().TrimStart('.');
         if (name.Scheme == "file" && file.NotEmpty() && this.SupportedExtensions.Exists(v => v == extension) && System.IO.File.Exists(file))
         {
             result = new Binding.Graph();
             if (!this.Open(result, file))
             {
                 result.Close();
                 result = null;
             }
         }
     }
     return(result);
 }
 protected override DirectShow.Binding.IGraph Open(Uri.Locator name)
 {
     DirectShow.Binding.IGraph result = null;
     if (name.Scheme.Head == "axrtsphttp" && name.Authority.NotNull() && name.Query["video"].IsNull())
     {
         name   = name.Copy();
         result = new DirectShow.Binding.Graph(this.Application);
         if (this.Open(result, name))
         {
             result.Play();
             //result.Stop();
             //result.Play();
         }
         else
         {
             result.Close();
             result = null;
         }
     }
     return(result);
 }
Beispiel #17
0
        public sealed override void Open(Uri.Locator argument)
        {
            this.cache = new Collection.Vector <Tuple <Raster.Image, Tuple <string, object>[]> >(this.Prepare(argument));
            new Action <int>(frame =>
            {
                Tuple <Raster.Image, Tuple <string, object>[]> result = this.Generate(frame);
                Raster.Image generated = result.Item1;
                {
                    switch (this.Format)
                    {
                    default:
                    case Colorspace.Bgra:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Bgra>(), result.Item2);
                        break;

                    case Colorspace.Bgr:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Bgr>(), result.Item2);
                        break;

                    case Colorspace.Yuv420:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Yuv420>(), result.Item2);
                        break;

                    case Colorspace.Yvu420:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Yvu420>(), result.Item2);
                        break;

                    case Colorspace.Yuyv:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Yuyv>(), result.Item2);
                        break;

                    case Colorspace.Monochrome:
                        result = Tuple.Create <Raster.Image, Tuple <string, object>[]>(generated.Convert <Raster.Monochrome>(), result.Item2);
                        break;
                    }
                }
                lock (this.cache)
                    this.cache[frame] = result;
            }).For(this.Count);
        }
Beispiel #18
0
        bool Media.Player.IStream.Open(Uri.Locator name)
        {
            this.ParseArguments(name);
            bool result = (this.Graph = this.Open(name)).NotNull();

            if (result)
            {
                if (this.Debug)
                {
                    this.Graph.Save(Uri.Locator.FromPlatformPath(System.Environment.SpecialFolder.MyDocuments, "graph.grf"));
                }
                this.Graph.Send = (DateTime position, TimeSpan lifeTime, Bitmap.Image frame) =>
                {
                    if (this.Graph.NotNull())
                    {
                        this.LastPosition = position;
                        this.sendFrame(0, position, lifeTime, frame, null);
                    }
                };
            }
            return(result);
        }
Beispiel #19
0
 protected override DirectShow.Binding.IGraph Open(Uri.Locator locator)
 {
     DirectShow.Binding.IGraph result = null;
     if (locator.Scheme == "directshow+capture" && locator.Authority.NotNull())
     {
         result = new DirectShow.Binding.Graph();
         bool built = result.Open(new DirectShow.Binding.Filters.Capture.All(locator.Authority, new DirectShow.Binding.Filters.SampleGrabber.Yuyv(new DirectShow.Binding.Filters.NullRenderer())
         {
             FuzzyMatch = this.Fuzzy
         }));
         if (built)
         {
             result.Play();
         }
         else
         {
             result.Close();
             result = null;
         }
     }
     return(result);
 }
Beispiel #20
0
        public bool Open([Settings.Parameter("locator", "Locator of file, capture device or video stream.")] Uri.Locator resource)
        {
            bool result = false;

            if (resource.NotNull())
            {
                string crop = resource.Query["crop"];
                if (crop.NotEmpty())
                {
                    this.Crop = (Geometry2D.Integer.Shell)crop;
                }
                string scan = resource.Query["scan"];
                if (scan.NotEmpty())
                {
                    this.Scan = (Media.Scan)Enum.Parse(typeof(Media.Scan), scan, true);
                }
                this.Ratio = resource.Query["ratio"];
                resource.Query.Remove("crop", "ratio", "scan");
                result = this.backend.Open(resource);
            }
            return(result);
        }
Beispiel #21
0
        public bool Open(Uri.Locator name)
        {
            bool result = false;

            if (name.Scheme == "test" && this.generator.IsNull() && name.Authority.NotNull())
            {
                this.generator = this.Generators.Find(generator => generator.Name == name.Authority.Endpoint.Host);
                if (this.generator.NotNull())
                {
                    this.generator.Open(name);
                    Kean.Math.Fraction rate = name.Query["rate"];
                    if (rate.Nominator > 0)
                    {
                        this.Timer = new System.Timers.Timer(1000 / (float)rate);
                    }
                    else
                    {
                        this.Timer = new System.Timers.Timer(1000 / this.FramesPerSeconds);
                    }
                    this.Timer.Elapsed += (object sender, System.Timers.ElapsedEventArgs elapsedArguments) =>
                    {
                        lock (this.signal)
                        {
                            if (this.generator.NotNull())
                            {
                                this.Index = (this.Index + 1) % this.Count;
                            }
                            System.Threading.Monitor.Pulse(this.signal);
                        }
                    };
                    result = true;
                    if (this is Stream && !(this is Linear))
                    {
                        this.Timer.Start();
                    }
                }
            }
            return(result);
        }
Beispiel #22
0
        bool Open(DirectShow.Binding.IGraph graph, Uri.Locator name)
        {
            bool   result   = false;
            string filename = name.Query["video"];

            name.Query.Remove("video");
            if (result = filename.NotEmpty())
            {
                result = graph.Open(
                    new Filters.Net.SourcePlus(name, new DirectShow.Binding.Filters.Utils.InfinitePinTee(
                                                   new DirectShow.Binding.Filters.Abstract[] { new Filters.Demultiplexer.MpegPush(new Filters.Decoder.SD.All(new DirectShow.Binding.Filters.SampleGrabber.All())
                    {
                        Output = -1
                    })
                                                                                               {
                                                                                                   WaitForOutput = new TimeSpan(0, 0, 0, 1)
                                                                                               } },
                                                   new DirectShow.Binding.Filters.Abstract[] { new Filters.File.Sink(filename) }
                                                   )));
            }
            return(result);
        }
 public bool Save(Uri.Locator resource)
 {
     return(new Xml.Dom.Document(this.root).Save(resource) && this.ResetPage());
 }
Beispiel #24
0
        protected override int Prepare(Uri.Locator argument)
        {
            try
            {
                Uri.Path path = argument.PlatformPath;
                if (path.NotNull())
                {
                    Bitmap.Image image = Bitmap.Image.Open(path);
                    this.photo = image;
                }
                if (!argument.Query.Empty)
                {
                    string value = argument.Query["resolution"];
                    if (value.NotEmpty())
                    {
                        this.resolution = (Geometry2D.Integer.Size)value;
                    }
                    value = argument.Query["format"];
                    if (value.NotEmpty())
                    {
                        base.Format = (Colorspace)Enum.Parse(typeof(Colorspace), value, true);
                    }
                    value = argument.Query["frames"];
                    if (value.NotEmpty())
                    {
                        this.frames = Kean.Math.Integer.Parse(value);
                    }
                    value = argument.Query["meta"];
                    if (value.NotEmpty())
                    {
                        this.metaData = bool.Parse(value);
                    }
                    value = argument.Query["motiontype"];
                    if (value.NotEmpty())
                    {
                        this.motionType = (MotionType)Enum.Parse(typeof(MotionType), value, true);
                    }
                    value = argument.Query["motion"];
                    if (value.NotEmpty())
                    {
                        string[] motion = value.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                        this.controlPoints.Clear();
                        switch (this.motionType)
                        {
                        default:
                        case MotionType.Repeat:
                        case MotionType.Periodic:
                            for (int i = 0; i < motion.Length - 3; i += 4)
                            {
                                this.controlPoints.Add(new ControlPoint(Kean.Math.Single.Parse(motion[i]), Kean.Math.Single.Parse(motion[i + 1]), Kean.Math.Single.Parse(motion[i + 2]), Kean.Math.Single.Parse(motion[i + 3])));
                            }
                            break;

                        case MotionType.Mirror:
                            for (int i = 0; i < motion.Length - 3; i += 4)
                            {
                                this.controlPoints.Add(new ControlPoint(Kean.Math.Single.Parse(motion[i]), Kean.Math.Single.Parse(motion[i + 1]), Kean.Math.Single.Parse(motion[i + 2]), Kean.Math.Single.Parse(motion[i + 3])));
                            }
                            for (int i = motion.Length - 5; i >= 3; i -= 4)
                            {
                                this.controlPoints.Add(new ControlPoint(Kean.Math.Single.Parse(motion[i - 3]), Kean.Math.Single.Parse(motion[i - 2]), Kean.Math.Single.Parse(motion[i - 1]), Kean.Math.Single.Parse(motion[i])));
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                this.Initialize();
            }
            this.motion = new Geometry2D.Single.Transform[this.frames];
            float step = this.frames / (float)(this.controlPoints.Count - 1);

            Tuple <float, Geometry2D.Single.Transform>[] measures = new Tuple <float, Geometry2D.Single.Transform> [this.controlPoints.Count];
            for (int i = 0; i < this.controlPoints.Count; i++)
            {
                measures[i] = Tuple.Create <float, Geometry2D.Single.Transform>(i * step, (Geometry2D.Single.Transform)(Geometry2D.Single.Transform.CreateTranslation(this.controlPoints[i].X, this.controlPoints[i].Y) * Geometry2D.Single.Transform.CreateRotation(Kean.Math.Single.ToRadians(this.controlPoints[i].Angle)) * Geometry2D.Single.Transform.CreateScaling(this.controlPoints[i].Scale)));
            }
            Interpolation.Splines.Method method;
            switch (this.motionType)
            {
            default:
            case MotionType.Repeat:
                method = Interpolation.Splines.Method.Natural;
                break;

            case MotionType.Periodic:
                method = Interpolation.Splines.Method.Periodic;
                break;

            case MotionType.Mirror:
                method = Interpolation.Splines.Method.Natural;
                break;
            }
            this.interpolate = new Kean.Math.Regression.Interpolation.Splines.Geometry2D.Single.Transform(method, measures);
            return(this.frames);
        }
Beispiel #25
0
 protected virtual void ParseArguments(Uri.Locator name)
 {
     this.Rate = name.Query["rate"];
 }
Beispiel #26
0
 public bool Start(Geometry2D.Integer.Size size, Encoding encoding, int bitrate, Uri.Locator resource)
 {
     this.backend.Size       = size;
     this.backend.Type       = encoding;
     this.backend.Mp4Mode    = Binding.Mp4Mode.Standard;
     this.backend.RecordMode = Binding.RecordMode.Video;
     this.backend.Bitrate    = bitrate;
     return(this.backend.StartRecord(resource.PlatformPath));
 }
Beispiel #27
0
 public Resource(ResourceType type, string label, Uri.Locator locator)
 {
     this.Type    = type;
     this.label   = label;
     this.Locator = locator;
 }
Beispiel #28
0
        public bool Open(Uri.Locator resource)
        {
            bool result = false;

            if (this.status == Status.Closed)
            {
                System.Threading.AutoResetEvent wait = new System.Threading.AutoResetEvent(false);
                Action <Uri.Locator>            run  = argument =>
                {
                    Player.IStream player = null;
                    Uri.Locator    path   = argument as Uri.Locator;
                    foreach (Player.IStream p in this)
                    {
                        if (p.NotNull() && p.Open(path))
                        {
                            Error.Log.Append(Error.Level.Message, "Open Succeeded", "Successfully opened \"" + path + "\" with player \"" + p.Type());
                            lock (this.@lock)
                            {
                                player       = p;
                                this.player  = player;
                                this.status  = this.player.Status;
                                this.hasNext = path.Query["video"].NotEmpty() && p is Player.INonLinear;
                                result       = true;
                            }
                            break;
                        }
                    }
                    wait.Set();
                    if (player.NotNull())
                    {
                        try
                        {
                            lock (this.incomingLock)
                            {                             // throw away all old incoming commands
                                this.incomingPlaying = null;
                                this.incomingSeek    = null;
                            }
                            while (player.Status != Status.Closed)
                            {
                                player.Poll();
                                bool isLinear    = false;
                                bool isNonLinear = false;
                                if (player is Player.ILinear && (player as Player.ILinear).IsLinear)
                                {
                                    {
                                        bool?    playing;
                                        DateTime?seek;
                                        lock (this.incomingLock)
                                        {
                                            playing = this.incomingPlaying;
                                            seek    = this.incomingSeek;
                                            this.incomingPlaying = null;
                                            this.incomingSeek    = null;
                                        }
                                        if (playing.HasValue)
                                        {
                                            if (playing.Value)
                                            {
                                                (player as Player.ILinear).Play();
                                            }
                                            else
                                            {
                                                (player as Player.ILinear).Pause();
                                            }
                                        }
                                        if (player is Player.INonLinear && (player as Player.INonLinear).IsNonLinear && seek.HasValue)
                                        {
                                            (player as Player.INonLinear).Seek(seek.Value);
                                        }
                                    }
                                    isLinear    = player is Player.ILinear && (player as Player.ILinear).IsLinear;
                                    isNonLinear = player is Player.INonLinear && (player as Player.INonLinear).IsNonLinear;
                                    DateTime position = (player as Player.ILinear).Position;
                                    DateTime start    = isNonLinear ? (player as Player.INonLinear).Start : new DateTime();
                                    DateTime end      = isNonLinear ? (player as Player.INonLinear).End : position;

                                    lock (this.@lock)
                                    {
                                        this.start       = start;
                                        this.end         = end;
                                        this.position    = position;
                                        this.isLinear    = isLinear;
                                        this.isNonLinear = isNonLinear;
                                    }
                                }
                                else
                                {
                                    bool freezed;
                                    lock (this.incomingLock)
                                        freezed = this.incomingPlaying.HasValue && !this.incomingPlaying.Value;
                                    lock (this.@lock)
                                        this.status = freezed ? Status.Paused : Status.Playing;
                                }
                                lock (this.@lock)
                                {
                                    if (player is Player.ILinear && (player as Player.ILinear).IsLinear)
                                    {
                                        this.status = player.Status;
                                    }
                                    this.UpdateState(this.status == Status.Closed, this.status == Status.Playing, this.start ?? new DateTime(), this.end, this.position, isLinear, isNonLinear, this.hasNext);
                                }
                            }
                        }
                        finally
                        {
                            player.Close();
                        }
                    }
                };
                Action <Uri.Locator> wrappedRun = Error.Log.CatchErrors ?
                                                  argument =>
                {
                    try
                    {
                        run(argument);
                    }
                    catch (System.Exception e)
                    {
                        Error.Log.Append(Error.Level.Recoverable, result ? "Failed During Playback of Media \"" + argument + "\"" : "Failed to Open Media \"" + argument + "\"", e);
                        result = false;
                        wait.Set();
                    }
                } :
                run;
                this.sender = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(a => wrappedRun(a as Uri.Locator)))
                {
                    Name = "Input Thread"
                };
                this.sender.Start(resource);
                wait.WaitOne();
            }
            return(result);
        }
Beispiel #29
0
 public abstract void Open(Uri.Locator argument);
Beispiel #30
0
 protected virtual int Prepare(Uri.Locator argument)
 {
     return(0);
 }