// When the users presses the different buttons on the playback control, this method
        // will follow those instructions
        private object PlaybackCommandHandler(Message message, FQID dest, FQID sender)
        {
            var commandData = message.Data as PlaybackCommandData;

            if (commandData != null)
            {
                switch (commandData.Command)
                {
                case PlaybackData.Begin:
                    _nextCommand = MyPlayCommand.Start;
                    break;

                case PlaybackData.End:
                    _nextCommand = MyPlayCommand.End;
                    break;

                case PlaybackData.Previous:
                    _nextCommand = MyPlayCommand.PrevFrame;
                    break;

                case PlaybackData.Next:
                    _nextCommand = MyPlayCommand.NextFrame;
                    break;

                case PlaybackData.PreviousSequence:
                    _nextCommand = MyPlayCommand.PrevSequence;
                    break;

                case PlaybackData.NextSequence:
                    _nextCommand = MyPlayCommand.NextSequence;
                    break;

                case PlaybackData.PlayForward:
                case PlaybackData.Play:
                    _mode = PlaybackPlayModeData.Forward;
                    break;

                case PlaybackData.PlayReverse:
                    _mode = PlaybackPlayModeData.Reverse;
                    break;

                case PlaybackData.PlayStop:
                    _mode = PlaybackPlayModeData.Stop;
                    break;
                }
            }
            return(null);
        }
示例#2
0
        private void JPEGFetchThread()
        {
            bool errorRecovery = false;

            while (!_stop)
            {
                if (_performCloseVideoSource)
                {
                    if (_jpegVideoSource != null)
                    {
                        _jpegVideoSource.Close();
                        _jpegVideoSource = null;
                    }
                    _performCloseVideoSource = false;
                }

                if (_newlySelectedItem != null)
                {
                    _selectedItem    = _newlySelectedItem;
                    _jpegVideoSource = new JPEGVideoSource(_selectedItem);
                    if (checkBoxAspect.Checked)
                    {
                        // Keeping aspect ratio can only work when the Media Toolkit knows the actual displayed area
                        _jpegVideoSource.Width  = pictureBox.Width;
                        _jpegVideoSource.Height = pictureBox.Height;
                        _jpegVideoSource.SetKeepAspectRatio(checkBoxAspect.Checked, checkBoxFill.Checked);                              // Must be done before Init
                    }
                    try
                    {
                        _jpegVideoSource.Init();
                        JPEGData jpegData = _currentShownTime == DateTime.MinValue ? _jpegVideoSource.GetBegin() : _jpegVideoSource.GetAtOrBefore(_currentShownTime) as JPEGData;
                        if (jpegData != null)
                        {
                            _requestInProgress = true;
                            ShowJPEG(jpegData);
                        }
                        else
                        {
                            ShowError("");      // Clear any error messages
                        }
                        _newlySelectedItem = null;
                        errorRecovery      = false;
                    }
                    catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to server ...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        _jpegVideoSource   = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                    }
                }

                if (errorRecovery)
                {
                    Thread.Sleep(3000);
                    continue;
                }

                if (_setNewResolution && _jpegVideoSource != null && _requestInProgress == false)
                {
                    try
                    {
                        _jpegVideoSource.Width  = _newWidth;
                        _jpegVideoSource.Height = _newHeight;
                        _jpegVideoSource.SetWidthHeight();
                        _setNewResolution = false;
                        JPEGData jpegData;
                        jpegData = _jpegVideoSource.GetAtOrBefore(_currentShownTime) as JPEGData;
                        if (jpegData != null)
                        {
                            _requestInProgress = true;
                            _currentShownTime  = DateTime.MinValue;
                            ShowJPEG(jpegData);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to recorder...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        _jpegVideoSource   = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                    }
                }

                if (_requestInProgress == false && _jpegVideoSource != null && _nextCommand != MyPlayCommand.None)
                {
                    JPEGData jpegData = null;
                    try
                    {
                        switch (_nextCommand)
                        {
                        case MyPlayCommand.Start:
                            jpegData = _jpegVideoSource.GetBegin();
                            break;

                        case MyPlayCommand.NextFrame:
                            jpegData = _jpegVideoSource.GetNext() as JPEGData;
                            break;

                        case MyPlayCommand.NextSequence:
                            jpegData = _jpegVideoSource.GetNextSequence();
                            break;

                        case MyPlayCommand.PrevFrame:
                            jpegData = _jpegVideoSource.GetPrevious();
                            break;

                        case MyPlayCommand.PrevSequence:
                            jpegData = _jpegVideoSource.GetPreviousSequence();
                            break;

                        case MyPlayCommand.End:
                            jpegData = _jpegVideoSource.GetEnd();
                            break;
                        }
                    } catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to recorder...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        _jpegVideoSource   = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                    }
                    if (jpegData != null)
                    {
                        _requestInProgress = true;
                        ShowJPEG(jpegData);
                    }

                    _nextCommand = MyPlayCommand.None;
                }

                if (_nextToFetchTime != DateTime.MinValue && _requestInProgress == false && _jpegVideoSource != null)
                {
                    bool willResultInSameFrame = false;
                    // Lets validate if we are just asking for the same frame
                    if (_currentTimeInformation != null)
                    {
                        if (_currentTimeInformation.PreviousTime < _nextToFetchTime &&
                            _currentTimeInformation.NextTime > _nextToFetchTime)
                        {
                            willResultInSameFrame = true;
                        }
                    }
                    if (willResultInSameFrame)
                    {
                        Debug.WriteLine("Now Fetch ignored: " + _nextToFetchTime.ToLongTimeString() + " - nextToFetch=" + _nextToFetchTime.ToLongTimeString());
                        // Same frame -> Ignore request
                        _requestInProgress = false;
                        _nextToFetchTime   = DateTime.MinValue;
                    }
                    else
                    {
                        Debug.WriteLine("Now Fetch: " + _nextToFetchTime.ToLongTimeString());
                        DateTime time = _nextToFetchTime;
                        _nextToFetchTime = DateTime.MinValue;

                        try
                        {
                            DateTime localTime = time.Kind == DateTimeKind.Local ? time : time.ToLocalTime();
                            DateTime utcTime   = time.Kind == DateTimeKind.Local ? time.ToUniversalTime() : time;

                            BeginInvoke(
                                new MethodInvoker(delegate() { textBoxAsked.Text = localTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); }));

                            JPEGData jpegData;
                            jpegData = _jpegVideoSource.GetAtOrBefore(utcTime) as JPEGData;
                            if (jpegData == null && _mode == PlaybackPlayModeData.Stop)
                            {
                                jpegData = _jpegVideoSource.GetNearest(utcTime) as JPEGData;
                            }

                            if (_mode == PlaybackPlayModeData.Reverse)
                            {
                                while (jpegData != null && jpegData.DateTime > utcTime)
                                {
                                    jpegData = _jpegVideoSource.GetPrevious();
                                }
                            }
                            else if (_mode == PlaybackPlayModeData.Forward)
                            {
                                if (jpegData != null && jpegData.DateTime < utcTime)
                                {
                                    jpegData = _jpegVideoSource.Get(utcTime) as JPEGData;
                                }
                            }
                            if (jpegData != null)
                            {
                                _requestInProgress = true;
                                ShowJPEG(jpegData);
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is CommunicationMIPException)
                            {
                                ShowError("Connection lost to server ...");
                            }
                            else
                            {
                                ShowError(ex.Message);
                            }
                            errorRecovery      = true;
                            _jpegVideoSource   = null;
                            _newlySelectedItem = _selectedItem;     // Redo the Initialization
                        }
                    }
                }
                Thread.Sleep(5);
            }
            _fetchThread = null;
        }
示例#3
0
 private void OnNextFrame(object sender, EventArgs e)
 {
     _nextCommand = MyPlayCommand.NextFrame;
 }
示例#4
0
 private void OnPreviousFrame(object sender, EventArgs e)
 {
     _nextCommand = MyPlayCommand.PrevFrame;
 }
示例#5
0
 private void OnNextSequence(object sender, EventArgs e)
 {
     _nextCommand = MyPlayCommand.NextSequence;
 }
示例#6
0
 private void buttonEnd_Click(object sender, EventArgs e)
 {
     _nextCommand = MyPlayCommand.End;
 }
示例#7
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     _nextCommand = MyPlayCommand.Start;
 }
        private void BitmapFetchThread()
        {
            bool errorRecovery = false;

            try
            {
                while (!_stop)
                {
                    try
                    {
                        if (_stopPlayback)
                        {
                            if (_bitmapVideoSource != null)
                            {
                                _bitmapVideoSource.Close();
                            }
                            _bitmapVideoSource = null;
                            _nextCommand       = MyPlayCommand.None;
                            _nextToFetchTime   = DateTime.MinValue;
                        }

                        if (_bitmapVideoSourceNext != null)
                        {
                            lock (_bitmapVideoSourceNextLock)
                            {
                                if (_bitmapVideoSource != null)
                                {
                                    _bitmapVideoSource.Close();
                                }
                                _bitmapVideoSource     = _bitmapVideoSourceNext;
                                _bitmapVideoSourceNext = null;
                            }
                            _bitmapVideoSource.Init();
                            ShowError("");      // Clear messages
                            errorRecovery = false;
                        }

                        if (_bitmapVideoSource != null && _setResolution)
                        {
                            _bitmapVideoSource.Width  = _newWidth;
                            _bitmapVideoSource.Height = _newHeight;
                            _bitmapVideoSource.SetWidthHeight();
                            _setResolution = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to server ...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery          = true;
                        _bitmapVideoSourceNext = _bitmapVideoSource;
                        _bitmapVideoSource     = null;
                        _nextCommand           = MyPlayCommand.None;
                        _nextToFetchTime       = DateTime.MinValue;
                    }

                    if (errorRecovery)
                    {
                        Thread.Sleep(3000);
                        continue;
                    }

                    if (Selected && _nextCommand != MyPlayCommand.None && _bitmapVideoSource != null && !_requestInProgress)
                    {
                        try
                        {
                            BitmapData bitmapData = null;
                            switch (_nextCommand)
                            {
                            case MyPlayCommand.Start:
                                bitmapData = _bitmapVideoSource.GetBegin();
                                break;

                            case MyPlayCommand.End:
                                bitmapData = _bitmapVideoSource.GetEnd();
                                break;

                            case MyPlayCommand.PrevSequence:
                                bitmapData = _bitmapVideoSource.GetPreviousSequence();
                                break;

                            case MyPlayCommand.NextSequence:
                                bitmapData = _bitmapVideoSource.GetNextSequence();
                                break;

                            case MyPlayCommand.PrevFrame:
                                bitmapData = _bitmapVideoSource.GetPrevious();
                                break;

                            case MyPlayCommand.NextFrame:
                                bitmapData = _bitmapVideoSource.GetNext() as BitmapData;
                                break;
                            }
                            if (bitmapData != null)
                            {
                                ShowBitmap(bitmapData);
                                // Lets get the Smart Client to show this time, (This will issue a new set time command, but is same again (that we ignore))
                                EnvironmentManager.Instance.PostMessage(
                                    new Message(MessageId.SmartClient.PlaybackCommand,
                                                new PlaybackCommandData
                                {
                                    Command  = PlaybackData.Goto,
                                    DateTime = bitmapData.DateTime
                                }));
                                bitmapData.Dispose();
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is CommunicationMIPException)
                            {
                                ShowError("Connection lost to server ...");
                            }
                            else
                            {
                                ShowError(ex.Message);
                            }
                            errorRecovery          = true;
                            _bitmapVideoSourceNext = _bitmapVideoSource;
                            _bitmapVideoSource     = null;
                            continue;
                        }

                        _nextCommand = MyPlayCommand.None;
                    }

                    if (_nextToFetchTime != DateTime.MinValue &&
                        (_nextToFetchTime != _currentShownTime || _redisplay) &&
                        _bitmapVideoSource != null &&
                        !_requestInProgress)
                    {
                        DateTime time    = _nextToFetchTime;
                        DateTime utcTime = time.Kind == DateTimeKind.Local ? time.ToUniversalTime() : time;

                        // Next 4 lines new for MIPSDK 2014
                        bool willResultInSameFrame = _currentTimeInformation != null &&
                                                     _currentTimeInformation.NextTime > utcTime &&
                                                     _currentTimeInformation.PreviousTime < utcTime;

                        // Lets validate if we are just asking for the same frame
                        _nextToFetchTime = DateTime.MinValue;

                        if (!willResultInSameFrame)
                        {
                            try
                            {
                                if (_mode == PlaybackPlayModeData.Stop)
                                {
                                    _bitmapVideoSource.GoTo(utcTime, PlaybackPlayModeData.Reverse);
                                }

                                var bitmapData = _bitmapVideoSource.GetAtOrBefore(utcTime) as BitmapData;

                                // For MIPSDK 2014
                                if (bitmapData != null && bitmapData.IsPreviousAvailable == false)
                                {
                                    if (utcTime - TimeSpan.FromMilliseconds(10) < bitmapData.DateTime)
                                    {
                                        bitmapData.PreviousDateTime = utcTime - TimeSpan.FromMilliseconds(10);
                                    }
                                    else
                                    {
                                        bitmapData.PreviousDateTime = bitmapData.DateTime;
                                    }
                                }

                                if (bitmapData != null)
                                {
                                    ShowBitmap(bitmapData);
                                    bitmapData.Dispose();
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex is CommunicationMIPException)
                                {
                                    ShowError("Connection lost to server ...");
                                }
                                else
                                {
                                    ShowError(ex.Message);
                                }
                                errorRecovery          = true;
                                _bitmapVideoSourceNext = _bitmapVideoSource;
                                _bitmapVideoSource     = null;
                            }
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (Exception ex)
            {
                EnvironmentManager.Instance.ExceptionHandler("RGBVideoEnhancement.PlaybackThread", ex);
            }

            if (_bitmapVideoSource != null)
            {
                _bitmapVideoSource.Close();
                _bitmapVideoSource = null;
            }
            _fetchThread = null;
        }
示例#9
0
        private void MetadataFetchThread()
        {
            MetadataPlaybackSource metadataSource = null;
            bool errorRecovery = false;

            while (!_stop)
            {
                if (_performCloseMetadataSource)
                {
                    if (metadataSource != null)
                    {
                        metadataSource.Close();
                        metadataSource = null;
                    }
                    _performCloseMetadataSource = false;
                }

                if (_newlySelectedItem != null)
                {
                    _selectedItem  = _newlySelectedItem;
                    metadataSource = new MetadataPlaybackSource(_selectedItem);
                    try
                    {
                        metadataSource.Init();
                        var metadata = _currentShownTime == DateTime.MinValue ? metadataSource.GetBegin() : metadataSource.GetAtOrBefore(_currentShownTime);
                        if (metadata != null)
                        {
                            _requestInProgress = true;
                            ShowMetadata(metadata);
                        }
                        else
                        {
                            ShowError("");      // Clear any error messages
                        }
                        _newlySelectedItem = null;
                        errorRecovery      = false;
                    }
                    catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to server ...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        metadataSource     = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                    }
                }

                if (errorRecovery)
                {
                    Thread.Sleep(3000);
                    continue;
                }

                if (_requestInProgress == false && metadataSource != null && _nextCommand != MyPlayCommand.None)
                {
                    MetadataPlaybackData metadataPlaybackData = null;
                    try
                    {
                        switch (_nextCommand)
                        {
                        case MyPlayCommand.Start:
                            metadataPlaybackData = metadataSource.GetBegin();
                            break;

                        case MyPlayCommand.NextFrame:
                            metadataPlaybackData = metadataSource.GetNext();
                            break;

                        case MyPlayCommand.NextSequence:
                            metadataPlaybackData = metadataSource.GetNextSequence();
                            break;

                        case MyPlayCommand.PrevFrame:
                            metadataPlaybackData = metadataSource.GetPrevious();
                            break;

                        case MyPlayCommand.PrevSequence:
                            metadataPlaybackData = metadataSource.GetPreviousSequence();
                            break;

                        case MyPlayCommand.End:
                            metadataPlaybackData = metadataSource.GetEnd();
                            break;
                        }
                    } catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to recorder...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        metadataSource     = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                    }
                    if (metadataPlaybackData != null)
                    {
                        _requestInProgress = true;
                        ShowMetadata(metadataPlaybackData);
                    }

                    _nextCommand = MyPlayCommand.None;
                }

                if (_nextToFetchTime != DateTime.MinValue && _requestInProgress == false && metadataSource != null)
                {
                    bool willResultInSameFrame = false;
                    // Lets validate if we are just asking for the same frame
                    if (_currentTimeInformation != null)
                    {
                        if (_currentTimeInformation.PreviousTime < _nextToFetchTime &&
                            _currentTimeInformation.NextTime > _nextToFetchTime)
                        {
                            willResultInSameFrame = true;
                        }
                    }
                    if (willResultInSameFrame)
                    {
                        // Same frame -> Ignore request
                        _requestInProgress = false;
                        _nextToFetchTime   = DateTime.MinValue;
                    }
                    else
                    {
                        Debug.WriteLine("Now Fetch: " + _nextToFetchTime.ToLongTimeString());
                        DateTime time = _nextToFetchTime;
                        _nextToFetchTime = DateTime.MinValue;

                        try
                        {
                            DateTime localTime = time.Kind == DateTimeKind.Local ? time : time.ToLocalTime();
                            DateTime utcTime   = time.Kind == DateTimeKind.Local ? time.ToUniversalTime() : time;

                            BeginInvoke(
                                new MethodInvoker(delegate { textBoxAsked.Text = localTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); }));

                            var metadata = metadataSource.GetAtOrBefore(utcTime);
                            if (_mode == PlaybackPlayModeData.Reverse)
                            {
                                while (metadata != null && metadata.DateTime > utcTime)
                                {
                                    metadata = metadataSource.GetPrevious();
                                }
                            }
                            else if (_mode == PlaybackPlayModeData.Forward)
                            {
                                if (metadata != null && metadata.DateTime < utcTime)
                                {
                                    metadata = metadataSource.Get(utcTime);
                                }
                            }
                            if (metadata != null)
                            {
                                _requestInProgress = true;
                                ShowMetadata(metadata);
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is CommunicationMIPException)
                            {
                                ShowError("Connection lost to server ...");
                            }
                            else
                            {
                                ShowError(ex.Message);
                            }
                            errorRecovery      = true;
                            metadataSource     = null;
                            _newlySelectedItem = _selectedItem;     // Redo the Initialization
                        }
                    }
                }
                Thread.Sleep(5);
            }
            _fetchThread = null;
        }
示例#10
0
        private void BitmapFetchThread()
        {
            bool errorRecovery = false;
            BitmapVideoSource _bitmapVideoSource = null;

            while (!_stop)
            {
                if (_performCloseVideoSource)
                {
                    if (_bitmapVideoSource != null)
                    {
                        _bitmapVideoSource.Close();
                        _bitmapVideoSource = null;
                    }
                    _performCloseVideoSource = false;
                }

                if (_newlySelectedItem != null)
                {
                    _selectedItem             = _newlySelectedItem;
                    _bitmapVideoSource        = new BitmapVideoSource(_selectedItem);
                    _bitmapVideoSource.Width  = pictureBox.Width;
                    _bitmapVideoSource.Height = pictureBox.Height;
                    _bitmapVideoSource.SetKeepAspectRatio(true, true);

                    try
                    {
                        _bitmapVideoSource.Init();

                        BitmapData bitmapData = _bitmapVideoSource.GetAtOrBefore(DateTime.Now) as BitmapData;
                        if (bitmapData != null)
                        {
                            ShowBitmap(bitmapData);
                        }
                        else
                        {
                            ShowError("");      // Clear any error messages
                        }
                        _newlySelectedItem = null;
                        errorRecovery      = false;

                        BeginInvoke(new MethodInvoker(delegate() { groupBoxPlayback.Enabled = true; }));
                    } catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to server ...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        _bitmapVideoSource = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                    }
                }

                if (errorRecovery || _bitmapVideoSource == null)
                {
                    if (this.IsHandleCreated)
                    {
                        BeginInvoke(new MethodInvoker(delegate() { groupBoxPlayback.Enabled = false; }));
                    }
                    if (_mode != PlaybackData.PlayStop)
                    {
                        buttonStop_Click(null, null);
                    }
                    Thread.Sleep(3000);
                    continue;
                }

                if (_performReSize)
                {
                    _bitmapVideoSource.Width  = _reSizeWidth;
                    _bitmapVideoSource.Height = _reSizeHeight;
                    _bitmapVideoSource.SetWidthHeight();
                    if (_mode == PlaybackPlayModeData.Stop)
                    {
                        _nextToFetchTime = _currentShownTime;
                        _redisplay       = true;
                    }
                }

                if (_nextCommand != MyPlayCommand.None && _requestInProgress == false)
                {
                    try
                    {
                        BitmapData bitmapData = null;
                        switch (_nextCommand)
                        {
                        case MyPlayCommand.Start:
                            bitmapData = _bitmapVideoSource.GetBegin();
                            break;

                        case MyPlayCommand.End:
                            bitmapData = _bitmapVideoSource.GetEnd();
                            break;

                        case MyPlayCommand.PrevSequence:
                            bitmapData = _bitmapVideoSource.GetPreviousSequence();
                            break;

                        case MyPlayCommand.NextSequence:
                            bitmapData = _bitmapVideoSource.GetNextSequence();
                            break;

                        case MyPlayCommand.PrevFrame:
                            bitmapData = _bitmapVideoSource.GetPrevious();
                            break;

                        case MyPlayCommand.NextFrame:
                            bitmapData = _bitmapVideoSource.GetNext() as BitmapData;
                            break;
                        }
                        if (bitmapData != null)
                        {
                            ShowBitmap(bitmapData);
                            bitmapData.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is CommunicationMIPException)
                        {
                            ShowError("Connection lost to server ...");
                        }
                        else
                        {
                            ShowError(ex.Message);
                        }
                        errorRecovery      = true;
                        _bitmapVideoSource = null;
                        _newlySelectedItem = _selectedItem;     // Redo the Initialization
                        _nextCommand       = MyPlayCommand.None;
                        Thread.Sleep(3000);
                        continue;
                    }
                    _nextCommand = MyPlayCommand.None;
                }

                if (_nextToFetchTime != DateTime.MinValue && _requestInProgress == false)
                {
                    Debug.WriteLine("NextToFetch = " + _nextToFetchTime.ToString());

                    DateTime time      = _nextToFetchTime;
                    DateTime localTime = time.Kind == DateTimeKind.Local ? time : time.ToLocalTime();
                    DateTime utcTime   = time.Kind == DateTimeKind.Local ? time.ToUniversalTime() : time;

                    // Next 10 lines new for MIPSDK 2014
                    bool willResultInSameFrame = false;
                    // Lets validate if we are just asking for the same frame
                    if (_currentTimeInformation != null)
                    {
                        if (_mode == PlaybackPlayModeData.Forward &&
                            _currentTimeInformation.NextTime > utcTime)
                        {
                            willResultInSameFrame = true;
                        }
                        if (_mode == PlaybackPlayModeData.Reverse &&
                            _currentTimeInformation.PreviousTime < utcTime)
                        {
                            willResultInSameFrame = true;
                        }
                    }
                    _nextToFetchTime = DateTime.MinValue;

                    if (willResultInSameFrame)
                    {
                        // Same frame -> Ignore request
                    }
                    else
                    {
                        try
                        {
                            BeginInvoke(
                                new MethodInvoker(delegate() { textBoxAsked.Text = localTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); }));

                            BitmapData bitmapData = null;
                            switch (_mode)
                            {
                            case PlaybackPlayModeData.Stop:
                                bitmapData = _bitmapVideoSource.GetAtOrBefore(utcTime) as BitmapData;

                                // Next 2 lines new for MIPSDK 2014
                                if (bitmapData != null && bitmapData.IsPreviousAvailable == false)
                                {
                                    bitmapData.PreviousDateTime = bitmapData.DateTime - TimeSpan.FromMilliseconds(10);
                                }
                                break;

                            case PlaybackPlayModeData.Forward:
                                _bitmapVideoSource.GoTo(utcTime, _mode);
                                bitmapData = _bitmapVideoSource.GetNext() as BitmapData;

                                // Next 2 lines new for MIPSDK 2014
                                if (bitmapData != null && bitmapData.IsPreviousAvailable == false)
                                {
                                    if (utcTime - TimeSpan.FromMilliseconds(10) < bitmapData.DateTime)
                                    {
                                        bitmapData.PreviousDateTime = utcTime - TimeSpan.FromMilliseconds(10);
                                    }
                                    else
                                    {
                                        bitmapData.PreviousDateTime = bitmapData.DateTime;
                                    }
                                }
                                break;

                            case PlaybackPlayModeData.Reverse:
                                _bitmapVideoSource.GoTo(utcTime, _mode);
                                bitmapData = _bitmapVideoSource.GetPrevious();
                                // Next 2 lines new for MIPSDK 2014
                                if (bitmapData != null && bitmapData.IsPreviousAvailable == false)
                                {
                                    bitmapData.PreviousDateTime = bitmapData.DateTime - TimeSpan.FromMilliseconds(10);
                                }
                                break;
                            }

                            if (bitmapData != null)
                            {
                                ShowBitmap(bitmapData);
                                bitmapData.Dispose();
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is CommunicationMIPException)
                            {
                                ShowError("Connection lost to server ...");
                            }
                            else
                            {
                                ShowError(ex.Message);
                            }
                            errorRecovery      = true;
                            _bitmapVideoSource = null;
                            _nextCommand       = MyPlayCommand.None;
                            _newlySelectedItem = _selectedItem;                             // Redo the Initialization
                        }
                    }
                }
            }
            _fetchThread = null;
        }