Beispiel #1
0
        static Codecs()
        {
            RawColor = new RawCodec();
            JpegColor = new JpegCodec();

            RawDepth = new RawCodec();
            JpegDepth = new JpegCodec();
            PngDepth = new PngCodec();

            RawInfrared = new RawCodec();
            JpegInfrared = new JpegCodec();
            PngInfrared = new PngCodec();
        }
Beispiel #2
0
        public KinectPlay(string colorLocation, string depthLocation, string infraredLocation, FileMetadata metadata)
        {
            
            _timer.Tick += _timer_Tick;

            this._colorStream = File.Open(colorLocation, FileMode.Open, FileAccess.Read);
            this._depthStream = File.Open(depthLocation, FileMode.Open, FileAccess.Read);
            this._infraredStream = File.Open(infraredLocation, FileMode.Open, FileAccess.Read);

            _colorReader = new BinaryReader(_colorStream);
            _depthReader = new BinaryReader(_depthStream);
            _infraredReader = new BinaryReader(_infraredStream);

            while (_colorReader.BaseStream.Position != _colorReader.BaseStream.Length)
            {

                FrameTypes type = (FrameTypes)_colorReader.ReadInt32();
                if (_colorPlay == null)
                {
                    ICodec codec = new RawCodec();
                    if (metadata.ColorCodecId == Codecs.JpegColor.ColorCodecId)
                        codec = new JpegCodec();

                    _colorPlay = new PlayColorSystem(codec);
                    _activePlaySystems.Add(_colorPlay);
                    _colorPlay.PropertyChanged += play_PropertyChanged;
                    _colorPlay.FrameArrived += colorPlay_FrameArrived;
                }
                _colorPlay.AddFrame(_colorReader);
            }
            while (_depthReader.BaseStream.Position != _depthReader.BaseStream.Length)
            {
                FrameTypes type = (FrameTypes)_depthReader.ReadInt32();
                if (_depthPlay == null)
                {
                    ICodec codec = new RawCodec();
                    if (metadata.DepthCodecId == Codecs.JpegDepth.DepthCodecId)
                        codec = new JpegCodec();
                    else if (metadata.DepthCodecId == Codecs.PngDepth.DepthCodecId)
                        codec = new PngCodec();

                    _depthPlay = new PlayDepthSystem(codec);
                    _activePlaySystems.Add(_depthPlay);
                    _depthPlay.PropertyChanged += play_PropertyChanged;
                    _depthPlay.FrameArrived += depthPlay_FrameArrived;
                }
                _depthPlay.AddFrame(_depthReader);
            }
            while (_infraredReader.BaseStream.Position != _infraredReader.BaseStream.Length)
            {
                FrameTypes type = (FrameTypes)_infraredReader.ReadInt32();
                if (_infraredPlay == null)
                {
                    ICodec codec = new RawCodec();
                    if (metadata.InfraredCodecId == Codecs.JpegInfrared.InfraredCodecId)
                        codec = new JpegCodec();
                    else if (metadata.InfraredCodecId == Codecs.PngInfrared.InfraredCodecId)
                        codec = new PngCodec();

                    _infraredPlay = new PlayInfraredSystem(codec);
                    _activePlaySystems.Add(_infraredPlay);
                    _infraredPlay.PropertyChanged += play_PropertyChanged;
                    _infraredPlay.FrameArrived += infraredPlay_FrameArrived;
                }
                _infraredPlay.AddFrame(_infraredReader);
            }
                  
                

            foreach (var playSystem in _activePlaySystems)
            {
                if (playSystem.Frames.Count > 0)
                {
                    playSystem.Frames.Sort();

                    for (var i = 0; i < playSystem.Frames.Count; i++)
                    {
                        playSystem.FrameTimeToIndex[playSystem.Frames[i].RelativeTime] = i;
                    }

                    var first = playSystem.Frames.First().RelativeTime;
                    var last = playSystem.Frames.Last().RelativeTime;
                    if (first < _minTimespan)
                        _minTimespan = first;
                    if (last > _maxTimespan)
                        _maxTimespan = last;
                }
            }

            bool hasFrames = false;

            foreach (var playSystem in _activePlaySystems)
            {
                if (playSystem.Frames.Count > 0)
                {
                    playSystem.StartingOffset = _minTimespan;
                    hasFrames = true;
                }
            }

            if (hasFrames)
            {
                this.Duration = _maxTimespan - _minTimespan;
            }
            else
            {
                this.Duration = TimeSpan.Zero;
            }
        }