Ejemplo n.º 1
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);
 }
        public override bool Build(DirectShowLib.IPin source, IBuild build)
        {
            this.build          = build;
            this.build.OnClose += this.Dispose;
            bool result;

            if (result = base.Build(source, build))
            {
                DirectShowLib.AMMediaType media = new DirectShowLib.AMMediaType();
                Exception.GraphError.Check((this.grabber as  DirectShowLib.ISampleGrabber).GetConnectedMediaType(media));
                DirectShowLib.VideoInfoHeader header = (DirectShowLib.VideoInfoHeader)System.Runtime.InteropServices.Marshal.PtrToStructure(media.formatPtr, typeof(DirectShowLib.VideoInfoHeader));
                this.size     = new Geometry2D.Integer.Size(header.BmiHeader.Width, header.BmiHeader.Height);
                this.lifetime = header.AvgTimePerFrame;
                // NOTE!!!! Here we set a default frame rate if the video does not have such information available.
                if (this.lifetime < 1000 || this.lifetime > 10000000)
                {
                    this.lifetime = 400000;
                }
                if (this.Rate.NotNull())
                {
                    double factor = (double)this.Rate / (1000 / new TimeSpan(this.lifetime).TotalMilliseconds);
                    int    code   = (this.build.Graph as DirectShowLib.IMediaSeeking).SetRate(factor);
                }
            }
            return(result);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
0
 public bool Start(Geometry2D.Integer.Size size, Action <Raster.Image> callback)
 {
     this.backend.Type = Encoding.Uyvy;
     this.backend.Size = size;
     this.backend.LowLatencyPreview = size == this.device.NativeSize;
     this.callback            = buffer => callback.Call(new Raster.Uyvy(buffer, size));
     this.backend.OnCallback += this.callback;
     return(this.backend.StartCallback());
 }
Ejemplo n.º 6
0
 private void Initialize()
 {
     this.metaData      = false;
     this.frames        = 25 * 2;
     this.resolution    = new Geometry2D.Integer.Size(640, 480);
     this.photo         = Bitmap.Image.OpenResource("Generator/strip.png");
     this.Format        = Colorspace.Yuv420;
     this.motionType    = MotionType.Mirror;
     this.controlPoints = new Collection.List <ControlPoint>();
     this.controlPoints.Add(new ControlPoint(0, 1, 0, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, 40, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, 0, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, -40, 0));
     this.controlPoints.Add(new ControlPoint(0, 1, 0, 0));
 }
Ejemplo n.º 7
0
		public override bool Build(DirectShowLib.IPin source, IBuild build)
		{
			this.build = build;
			this.build.OnClose += this.Dispose;
			bool result;
			if (result = base.Build(source, build))
			{
				DirectShowLib.AMMediaType media = new DirectShowLib.AMMediaType();
				Exception.GraphError.Check((this.grabber as  DirectShowLib.ISampleGrabber).GetConnectedMediaType(media));
				DirectShowLib.VideoInfoHeader header = (DirectShowLib.VideoInfoHeader)System.Runtime.InteropServices.Marshal.PtrToStructure(media.formatPtr, typeof(DirectShowLib.VideoInfoHeader));
				this.size = new Geometry2D.Integer.Size(header.BmiHeader.Width, header.BmiHeader.Height);
				this.lifetime = header.AvgTimePerFrame;
				// NOTE!!!! Here we set a default frame rate if the video does not have such information available.
				if (this.lifetime < 1000 || this.lifetime > 10000000)
					this.lifetime = 400000;
				if (this.Rate.NotNull())
				{
					double factor = (double)this.Rate / (1000 / new TimeSpan(this.lifetime).TotalMilliseconds) ;
					int code = (this.build.Graph as DirectShowLib.IMediaSeeking).SetRate(factor);
				}
			}
			return result;
		}
Ejemplo n.º 8
0
 protected override Raster.Image CreateBitmap(Buffer.Sized data, Geometry2D.Integer.Size resolution)
 {
     return(new Raster.Yuyv(data, resolution, this.CoordinateSystem));
 }
Ejemplo n.º 9
0
		protected internal override Geometry2D.Integer.Size ClampTextureSize(Geometry2D.Integer.Size size)
		{
			if (size.Width > this.MaximumTextureSize)
			{
				Error.Log.Append(Error.Level.Warning, "Texture Width Exceeds Limit", string.Format("The requested texture size \"{0}\" is bigger than the maximum texture size \"{1}, {1}\". The textures width will be clamped.", size, this.MaximumTextureSize));
				size = new Geometry2D.Integer.Size(this.MaximumTextureSize, size.Height);
			}
			if (size.Height > this.MaximumTextureSize)
			{
				Error.Log.Append(Error.Level.Warning, "Texture Height Exceeds Limit", string.Format("The requested texture size \"{0}\" is bigger than the maximum texture size \"{1}, {1}\". The textures height will be clamped.", size, this.MaximumTextureSize));
				size = new Geometry2D.Integer.Size(size.Width, this.MaximumTextureSize);
			}
			return size;
		}
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
		public void Create(Geometry2D.Integer.Size size)
		{
			this.Size = size;
			this.Create();
		}
Ejemplo n.º 12
0
 private void Initialize()
 {
     this.frames     = 10;
     this.resolution = new Geometry2D.Integer.Size(640, 480);
     base.Format     = Colorspace.Bgra;
 }
Ejemplo n.º 13
0
 protected abstract Bitmap.Image CreateBitmap(Buffer.Sized data, Geometry2D.Integer.Size resolution);