Пример #1
0
        public void SetMediaItem(IResourceLocator locator, string mediaItemTitle)
        {
            // free previous opened resource
            FilterGraphTools.TryDispose(ref _resourceAccessor);
            FilterGraphTools.TryDispose(ref _rot);

            _state    = PlayerState.Active;
            _isPaused = true;
            try
            {
                _resourceLocator  = locator;
                _mediaItemTitle   = mediaItemTitle;
                _resourceAccessor = _resourceLocator.CreateAccessor();

                // Create a DirectShow FilterGraph
                CreateGraphBuilder();

                // Add it in ROT (Running Object Table) for debug purpose, it allows to view the Graph from outside (i.e. graphedit)
                _rot = new DsROTEntry(_graphBuilder);

                // Add a notification handler (see WndProc)
                _instancePtr = Marshal.AllocCoTaskMem(4);
                IMediaEventEx mee = _graphBuilder as IMediaEventEx;
                if (mee != null)
                {
                    mee.SetNotifyWindow(SkinContext.Form.Handle, WM_GRAPHNOTIFY, _instancePtr);
                }

                // Create the Allocator / Presenter object
                AddPresenter();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding audio renderer", PlayerTitle);
                AddAudioRenderer();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding preferred codecs", PlayerTitle);
                AddPreferredCodecs();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding source filter", PlayerTitle);
                AddSourceFilter();

                ServiceRegistration.Get <ILogger>().Debug("{0}: Run graph", PlayerTitle);

                //This needs to be done here before we check if the evr pins are connected
                //since this method gives players the chance to render the last bits of the graph
                OnBeforeGraphRunning();

                // Now run the graph, i.e. the DVD player needs a running graph before getting informations from dvd filter.
                IMediaControl mc = (IMediaControl)_graphBuilder;
                int           hr = mc.Run();
                new HRESULT(hr).Throw();

                _initialized = true;
                OnGraphRunning();
            }
            catch (Exception)
            {
                Shutdown();
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Update the subtitle texture from a Bitmap.
        /// </summary>
        public bool Allocate()
        {
            if (SubTexture != null)
            {
                return(true);
            }

            try
            {
                if (SubBitmap != null)
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        ImageInformation imageInformation;
                        SubBitmap.Save(stream, ImageFormat.Bmp);
                        stream.Position = 0;
                        SubTexture      = Texture.FromStream(_device, stream, (int)stream.Length, (int)Width,
                                                             (int)Height, 1,
                                                             Usage.Dynamic, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0,
                                                             out imageInformation);
                    }
                    // Free bitmap
                    FilterGraphTools.TryDispose(ref SubBitmap);
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("SubtitleRenderer: Failed to create subtitle texture!!!", e);
                return(false);
            }
            return(true);
        }
Пример #3
0
 public void Dispose()
 {
     lock (_subtitles)
         _subtitles.Clear();
     DisableSubtitleHandling();
     FilterGraphTools.TryDispose(ref _subTexture);
 }
Пример #4
0
 private void FreeResources()
 {
     // _combinedOsdSurface does not need an explicit Dispose, it's done on Texture dispose:
     // When SlimDx.Configuration.DetectDoubleDispose is set to true, an ObjectDisposedException will be thrown!
     _combinedOsdSurface = null;
     FilterGraphTools.TryDispose(ref _combinedOsdTexture);
     FilterGraphTools.TryDispose(ref _sprite);
 }
Пример #5
0
 private void FreeResources()
 {
     lock (_syncObj)
     {
         FilterGraphTools.TryDispose(ref _planes[0]);
         FilterGraphTools.TryDispose(ref _planes[1]);
         FilterGraphTools.TryDispose(ref _sprite);
     }
 }
Пример #6
0
        /// <summary>
        /// Frees the audio/video codecs.
        /// </summary>
        protected override void FreeCodecs()
        {
            // Free subtitle filter
            FilterGraphTools.TryDispose(ref _subtitleRenderer);
            FilterGraphTools.TryRelease(ref _subtitleFilter);

            // Free base class
            base.FreeCodecs();

            // Free file source
            FilterGraphTools.TryRelease(ref _fileSource);
        }
Пример #7
0
 /// <summary>
 /// Frees the audio/video codecs.
 /// </summary>
 protected virtual void FreeCodecs()
 {
     if (_streamFilter != null)
     {
         if (_graphBuilder != null)
         {
             _graphBuilder.RemoveFilter(_streamFilter);
         }
         FilterGraphTools.TryDispose(ref _streamFilter);
     }
     // If we opened an own Stream, dispose it here
     FilterGraphTools.TryDispose(ref _resourceStream);
 }
Пример #8
0
        protected override void FreeCodecs()
        {
            // Free all filters from graph
            if (_graphBuilder != null)
            {
                FilterGraphTools.RemoveAllFilters(_graphBuilder, true);
            }

            FilterGraphTools.TryDispose(ref _rot);
            FilterGraphTools.TryRelease(ref _graphBuilder);

            // Free file source
            FilterGraphTools.TryRelease(ref _fileSource);
        }
Пример #9
0
        /// <summary>
        /// Frees the audio/video codecs.
        /// </summary>
        protected override void FreeCodecs()
        {
            // Free subtitle filter
            FilterGraphTools.TryDispose(ref _subtitleRenderer);
            FilterGraphTools.TryRelease(ref _subtitleFilter);

            // Free locally mounted remote resources
            FilterGraphTools.TryDispose(ref _localFsRaHelper);

            // Free base class
            base.FreeCodecs();

            // Free file source
            FilterGraphTools.TryRelease(ref _sourceFilter);
        }
Пример #10
0
        /// <summary>
        /// Frees the audio/video codecs.
        /// </summary>
        protected override void FreeCodecs()
        {
            // Release stream selectors
            ReleaseStreamSelectors();

            // Free EVR
            SafeEvrDeinit();
            FreeEvrCallback();
            FilterGraphTools.TryRelease(ref _evr);
            base.FreeCodecs();

            FilterGraphTools.TryDispose(ref _mpcSubsRenderer);
            FilterGraphTools.TryDispose(ref _rot);
            FilterGraphTools.TryRelease(ref _graphBuilder, true);
        }
Пример #11
0
        protected void Shutdown(bool keepResourceAccessor = false)
        {
            StopSeeking();
            _initialized = false;
            ServiceRegistration.Get <ILogger>().Debug("{0}: Stop playing", PlayerTitle);

            try
            {
                if (_graphBuilder != null)
                {
                    FilterState   state;
                    IMediaEventEx me = (IMediaEventEx)_graphBuilder;
                    IMediaControl mc = (IMediaControl)_graphBuilder;

                    me.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);

                    mc.GetState(10, out state);
                    if (state != FilterState.Stopped)
                    {
                        mc.Stop();
                        mc.GetState(10, out state);
                        ServiceRegistration.Get <ILogger>().Debug("{0}: Graph state after stop command: {1}", PlayerTitle, state);
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("{0}: Exception when stopping graph: {1}", PlayerTitle, ex.ToString());
            }
            finally
            {
                if (_instancePtr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(_instancePtr);
                    _instancePtr = IntPtr.Zero;
                }

                FreeCodecs();
            }
            // Dispose resource locator and accessor
            if (!keepResourceAccessor)
            {
                FilterGraphTools.TryDispose(ref _resourceAccessor);
                FilterGraphTools.TryDispose(ref _resourceLocator);
            }
        }
Пример #12
0
        /// <summary>
        /// Frees the audio/video codecs.
        /// </summary>
        protected override void FreeCodecs()
        {
            // Release stream selectors
            ReleaseStreamSelectors();

            // Free all filters from graph
            if (_graphBuilder != null)
            {
                FilterGraphTools.RemoveAllFilters(_graphBuilder, true);
            }

            // Free EVR
            EvrDeinit(_presenterInstance);
            FreeEvrCallback();
            FilterGraphTools.TryRelease(ref _evr);

            FilterGraphTools.TryDispose(ref _rot);
            FilterGraphTools.TryRelease(ref _graphBuilder);
        }
Пример #13
0
        /// <summary>
        /// Update the subtitle texture from a Bitmap.
        /// </summary>
        /// <param name="subtitle"></param>
        private void SetSubtitle(Subtitle subtitle)
        {
            Texture texture = null;

            ServiceRegistration.Get <ILogger>().Debug("SubtitleRenderer: SetSubtitle : " + subtitle);
            if (subtitle != null)
            {
                try
                {
                    Bitmap bitmap = subtitle.SubBitmap;
                    if (bitmap != null)
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            ImageInformation imageInformation;
                            bitmap.Save(stream, ImageFormat.Bmp);
                            stream.Position = 0;
                            texture         = Texture.FromStream(_device, stream, (int)stream.Length, (int)subtitle.Width,
                                                                 (int)subtitle.Height, 1,
                                                                 Usage.Dynamic, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0,
                                                                 out imageInformation);
                        }
                        // Free bitmap
                        FilterGraphTools.TryDispose(ref subtitle.SubBitmap);
                    }
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Error("SubtitleRenderer: Failed to create subtitle texture!!!", e);
                    return;
                }
            }
            // Set new subtitle
            lock (_syncObj)
            {
                // Dispose of old subtitle
                FilterGraphTools.TryDispose(ref _subTexture);
                _subTexture      = texture;
                _currentSubtitle = subtitle;
            }
        }
Пример #14
0
        public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwTexture)
        {
            lock (_lock)
                if (dwTexture != IntPtr.Zero && cx != 0 && cy != 0)
                {
                    if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
                    {
                        _originalVideoSize = new Size(cx, cy);
                    }

                    _aspectRatio.Width  = arx;
                    _aspectRatio.Height = ary;

                    FilterGraphTools.TryDispose(ref _texture);
                    _texture = new Texture(dwTexture);
                }

            VideoSizePresentDlgt vsp = VideoSizePresent;

            if (vsp != null)
            {
                vsp(this);
                VideoSizePresent = null;
            }

            // Inform caller that we have changed the texture
            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }

            if (_renderDlgt != null)
            {
                _renderDlgt();
            }

            return(0);
        }
Пример #15
0
        public void DrawItem(BluRayAPI.OSDTexture item)
        {
            try
            {
                lock (_syncObj)
                {
                    var index = (int)item.Plane;

                    // Dispose old texture only if new texture for plane is different
                    if (_planes[index] != null)
                    {
                        var isNewTexture = _planes[index].NativePointer != item.Texture;
                        if (isNewTexture)
                        {
                            FilterGraphTools.TryDispose(ref _planes[index]);
                        }
                    }

                    if (item.Width == 0 || item.Height == 0 || item.Texture == IntPtr.Zero)
                    {
                        return;
                    }

                    var texture = new Texture(item.Texture);
                    //SaveTexture(texture, index);
                    _planes[index] = texture;
                }
            }
            catch (Exception ex)
            {
                BluRayPlayerBuilder.LogError(ex.ToString());
            }

            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }
        }
Пример #16
0
        protected override void FreeCodecs()
        {
            // Signal shutdown
            _shutdownEvent.Set();
            if (!_eventThread.Join(100))
            {
                _eventThread.Abort();
            }

            // Free subtitle filter
            FilterGraphTools.TryDispose(ref _subtitleRenderer);
            FilterGraphTools.TryRelease(ref _subtitleFilter);

            // Free OSD renderer
            FilterGraphTools.TryDispose(ref _osdRenderer);

            // Free file source
            FilterGraphTools.TryRelease(ref _bdReader);
            FilterGraphTools.TryDispose(ref _fileSource);

            // Free base class
            base.FreeCodecs();
        }
Пример #17
0
 /// <summary>
 /// Frees the audio/video codecs.
 /// </summary>
 protected virtual void FreeCodecs()
 {
     // If we opened an own Stream, dispose it here
     FilterGraphTools.TryDispose(ref _resourceStream);
 }
Пример #18
0
 public virtual void Dispose()
 {
     FilterGraphTools.TryDispose(ref _resourceAccessor);
     FilterGraphTools.TryDispose(ref _resourceLocator);
     UnsubscribeFromMessages();
 }
Пример #19
0
 public override void Dispose()
 {
     FilterGraphTools.TryDispose(ref _filterWrapper);
     base.Dispose();
 }
Пример #20
0
        private void SetMatchingSubTitle()
        {
            lock (_syncObj)
            {
                if (_player == null)
                {
                    return;
                }

                if (_clearOnNextRender)
                {
                    _clearOnNextRender = false;
                    _currentSubtitle   = null;
                    FilterGraphTools.TryDispose(ref _subTexture);
                }

                if (_renderSubtitles == false)
                {
                    return;
                }
            }

            double   currentTime = _player.CurrentTime.TotalSeconds;
            Subtitle currentSubtitle;

            lock (_syncObj)
            {
                _currentTime    = currentTime;
                currentSubtitle = _currentSubtitle;
            }

            // If we currently have a subtitle an it is in current time, no need to look for another one yet
            if (currentSubtitle != null && currentSubtitle.PresentTime <= currentTime && currentTime <= currentSubtitle.PresentTime + currentSubtitle.TimeOut)
            {
                currentSubtitle.ShouldDraw = true;
                return;
            }

            // If we have already a sub in queue, wait until it's time to show
            if (currentSubtitle != null && currentSubtitle.PresentTime > currentTime)
            {
                currentSubtitle.ShouldDraw = false;
                return;
            }

            // Check for waiting subs
            lock (_syncObj)
            {
                while (_subtitles.Count > 0)
                {
                    Subtitle next = _subtitles.First.Value;
                    // if the next should be displayed now or previously
                    if (next.PresentTime <= currentTime)
                    {
                        // remove from queue
                        _subtitles.RemoveFirst();

                        // if it is not too late for this sub to be displayed, break
                        if (next.PresentTime + next.TimeOut >= currentTime)
                        {
                            next.ShouldDraw = true;
                            SetSubtitle(next);
                            return;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (currentSubtitle != null)
            {
                SetSubtitle(null);
            }
        }
Пример #21
0
 private void FreeSurface()
 {
     lock (_lock)
         FilterGraphTools.TryDispose(ref _surface);
 }
 protected override void FreeCodecs()
 {
     base.FreeCodecs();
     FilterGraphTools.TryDispose(ref _filterWrapper);
 }