Пример #1
0
        private void ShowMetadata(MetadataPlaybackData metadata)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new ShowMetadataDelegate(ShowMetadata), metadata);
            }
            else
            {
                Debug.WriteLine("ShowMetadata imagetime:" + metadata.DateTime.ToLocalTime());
                if (metadata.DateTime != _currentShownTime && _selectedItem != null)
                {
                    textOutput.Text  = metadata.Content.GetMetadataString();
                    textBoxTime.Text = metadata.DateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss.fff");

                    // Inform the PlybackController of the time information - so skipping can be done correctly
                    _currentTimeInformation = new PlaybackTimeInformationData
                    {
                        Item         = _selectedItem.FQID,
                        CurrentTime  = metadata.DateTime,
                        NextTime     = metadata.NextDateTime ?? metadata.DateTime.AddMilliseconds(1),
                        PreviousTime = metadata.PreviousDateTime ?? metadata.DateTime.AddMilliseconds(-1)
                    };
                    EnvironmentManager.Instance.SendMessage(
                        new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.PlaybackTimeInformation, _currentTimeInformation), _playbackFQID);

                    _currentShownTime = metadata.DateTime;
                    if (_mode == PlaybackPlayModeData.Stop)
                    {
                        // When playback is stopped, we move the time to where the user have scrolled, or if the user pressed
                        // one of the navigation buttons (Next..., Prev...)
                        EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.PlaybackCommand,
                                                                                                       new PlaybackCommandData
                        {
                            Command  = PlaybackData.Goto,
                            DateTime = metadata.DateTime
                        }),
                                                                _playbackFQID);
                    }
                    Debug.WriteLine("Image time: " + metadata.DateTime.ToLocalTime().ToString("HH.mm.ss.fff") + ", Mode=" + _mode);
                }
                _requestInProgress = false;
            }
        }
Пример #2
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;
        }