async void CleanupAsync()
        {
            Debug.WriteLine("StreamingMediaPlugin.CleanupAsync()");

            try
            {
                var playbackSession = _playbackSession;

                if (null != playbackSession)
                {
                    await playbackSession.StopAsync(CancellationToken.None);

                    await playbackSession.CloseAsync();
                }

                using (await _asyncLock.LockAsync(CancellationToken.None))
                {
                    if (_mediaStreamFacade == null)
                    {
                        return;
                    }

                    if (_mediaStreamFacade.IsDisposed)
                    {
                        _mediaStreamFacade = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("StreamingMediaPlugin.CleanupAsync() failed: " + ex.Message);
            }
        }
Пример #2
0
        public void OnUnload()
        {
            Stop();
            var mediaStreamFasacde = mediaStreamFascade;

            this.mediaStreamFascade = null;
            mediaStreamFascade.DisposeBackground("MainPage unload");
        }
Пример #3
0
        void InitializeMediaStream()
        {
            if (mediaStreamFascade != null)
            {
                return;
            }

            mediaStreamFascade              = MediaStreamFacadeSettings.Parameters.Create();
            mediaStreamFascade.StateChange += TsMediaManagerOnStateChange;
        }
Пример #4
0
        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
            {
                return;
            }

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
        }
Пример #5
0
        void OnUnload()
        {
            Debug.WriteLine("MainPage unload");

            StopMedia();

            var mediaStreamFacade = _mediaStreamFacade;

            _mediaStreamFacade = null;

            mediaStreamFacade.DisposeBackground("MainPage unload");
        }
Пример #6
0
        // IDK if this is broken or not. However it should only be called by the MediaFailed method.
        public void CleanupMediaStream()
        {
            mediaElement.Source = null;

            if (mediaStreamFascade == null)
            {
                return;
            }

            mediaStreamFascade.StateChange -= TsMediaManagerOnStateChange;
            mediaStreamFascade.DisposeSafe();
            mediaStreamFascade = null;
        }
        IMediaStreamFacade InitializeMediaStream()
        {
            if (null != _mediaStreamFacade && _mediaStreamFacade.IsDisposed)
            {
                _mediaStreamFacade = null;
            }

            if (null == _mediaStreamFacade)
            {
                _mediaStreamFacade = CreateMediaStreamFacade();
            }

            return(_mediaStreamFacade);
        }
Пример #8
0
        public async Task StartAsync()
        {
            var mediaElementManager = new SimulatedMediaElementManager();

            _mediaStreamFacade = new MediaStreamFacade();

            _mediaStreamFacade.SetParameter(_httpClientFactoryParameters);

            _mediaStreamFacade.SetParameter(new SimulatedMediaStreamConfigurator(mediaElementManager));

            var source = new Uri(Sources[0]);

            var mss = await _mediaStreamFacade.CreateMediaStreamSourceAsync(source, CancellationToken.None).ConfigureAwait(false);

            if (null == mss)
            {
                Debug.WriteLine("Unable to create media stream source");
                return;
            }

            mediaElementManager.SetSource(mss);

            Thread.Sleep(750);

            mediaElementManager.Play();

            return;
#pragma warning disable 162
            var timer = new Timer(_ =>
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();

                var gcMemory = GC.GetTotalMemory(true).BytesToMiB();

                var source2 = Sources[_count];

                Debug.WriteLine("Switching to {0} (GC {1:F3} MiB)", source, gcMemory);

                var url = null == source ? null : new Uri(source2);

                if (++_count >= Sources.Length)
                    _count = 0;
            });

            timer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
#pragma warning restore 162
        }
Пример #9
0
        void CleanupMediaStream()
        {
            mediaElement1.Source = null;

            if (null == _mediaStreamFacade)
            {
                return;
            }

            _mediaStreamFacade.StateChange -= TsMediaManagerOnStateChange;

            _mediaStreamFacade.DisposeSafe();

            _mediaStreamFacade = null;
        }
Пример #10
0
        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
            {
                return;
            }

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.SetParameter(_httpClientFactory);

            _mediaStreamFacade.SetParameter(new ApplicationInformation("HlsView", "1.0.0.0"));

            _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
        }
        async Task InitializeMediaStreamAsync()
        {
            Debug.WriteLine("MediaPlayerManager.InitializeMediaStreamAsync()");

            if (null != _mediaStreamFacade)
            {
                await CloseMediaSourceAsync().WithCancellation(_cancellationToken).ConfigureAwait(false);

                try
                {
                    await _mediaStreamFacade.StopAsync(_cancellationToken).ConfigureAwait(false);

                    ForceGc();

                    return;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("MediaPlayerManager.InitializeMediaStreamAsync() stop failed: " + ex.ExtendedMessage());
                }

                try
                {
                    await CleanupMediaStreamFacadeAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("MediaPlayerManager.InitializeMediaStreamAsync() cleanup failed: " + ex.ExtendedMessage());
                }
            }

            ForceGc();

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.SetParameter(_bufferingPolicy);

            _mediaStreamFacade.SetParameter(_mediaManagerParameters);

            _mediaStreamFacade.SetParameter(WebReaderManagerParameters);

            _mediaStreamFacade.SetParameter(_metadataHandler.MetadataSink);

            _mediaStreamFacade.StateChange += MediaStreamFacadeOnStateChange;
        }
        async Task CleanupMediaStreamFacadeAsync()
        {
            Debug.WriteLine("MediaPlayerManager.CleanupMediaStreamFacadeAsync()");

            var msf = _mediaStreamFacade;

            if (null == msf)
            {
                return;
            }

            _mediaStreamFacade = null;

            msf.StateChange -= MediaStreamFacadeOnStateChange;

            await msf.CloseAsync().ConfigureAwait(false);

            msf.DisposeBackground("MediaPlayerManager CleanupMediaStreamFacadeAsync");
        }
        public void Dispose()
        {
            Debug.WriteLine("MediaPlayerManager.Dispose()");

            _mediaPlayer.MediaOpened         -= MediaPlayerOnMediaOpened;
            _mediaPlayer.MediaEnded          -= MediaPlayerOnMediaEnded;
            _mediaPlayer.CurrentStateChanged -= MediaPlayerOnCurrentStateChanged;
            _mediaPlayer.MediaFailed         -= MediaPlayerOnMediaFailed;

            if (null != _mediaStreamFacade)
            {
                _mediaStreamFacade.StateChange -= MediaStreamFacadeOnStateChange;

                _mediaStreamFacade.Dispose();
                _mediaStreamFacade = null;
            }

            _asyncLock.Dispose();
        }
Пример #14
0
        /// <summary>
        ///     Creates a new instance of the MediaElementWrapper class.
        /// </summary>
        /// <param name="mediaStreamFacade"></param>
        public MediaElementWrapper(IMediaStreamFacade mediaStreamFacade)
        {
            if (mediaStreamFacade == null)
                throw new ArgumentNullException("mediaStreamFacade");

            Debug.WriteLine("MediaElementWrapper.ctor()");

            HorizontalContentAlignment = HorizontalAlignment.Stretch;
            VerticalContentAlignment = VerticalAlignment.Stretch;

            _mediaStreamFacade = mediaStreamFacade;

            MediaElement = new MediaElement();
            MediaElement.MediaEnded += MediaElement_MediaEnded;
            MediaElement.MediaFailed += MediaElement_MediaFailed;
#if WINDOWS_PHONE
            MediaElement.MarkerReached += MediaElement_MarkerReached;
#endif
            Content = MediaElement;
            _templateAppliedTaskSource = new TaskCompletionSource<object>();
        }
Пример #15
0
        /// <summary>
        ///     Creates a new instance of the MediaElementWrapper class.
        /// </summary>
        /// <param name="mediaStreamFacade"></param>
        public MediaElementWrapper(IMediaStreamFacade mediaStreamFacade)
        {
            if (mediaStreamFacade == null)
            {
                throw new ArgumentNullException("mediaStreamFacade");
            }

            Debug.WriteLine("MediaElementWrapper.ctor()");

            HorizontalContentAlignment = HorizontalAlignment.Stretch;
            VerticalContentAlignment   = VerticalAlignment.Stretch;

            _mediaStreamFacade = mediaStreamFacade;

            MediaElement              = new MediaElement();
            MediaElement.MediaEnded  += MediaElement_MediaEnded;
            MediaElement.MediaFailed += MediaElement_MediaFailed;
#if WINDOWS_PHONE
            MediaElement.MarkerReached += MediaElement_MarkerReached;
#endif
            Content = MediaElement;
            _templateAppliedTaskSource = new TaskCompletionSource <object>();
        }
Пример #16
0
        void CloseMedia()
        {
            StopMedia();

            if (null != mediaElement1)
            {
                mediaElement1.Source = null;
            }

            if (null == _mediaStreamFacade)
            {
                return;
            }

            var mediaStreamFacade = _mediaStreamFacade;

            _mediaStreamFacade = null;

            mediaStreamFacade.StateChange -= TsMediaManagerOnStateChange;

            // Don't block the cleanup in case someone is mashing the play button.
            // It could deadlock.
            mediaStreamFacade.DisposeBackground("MainPage CloseMedia");
        }
Пример #17
0
        void CleanupMediaStreamFacade()
        {
            if (null == _mediaStreamFacade)
                return;

            var mediaStreamFacade = _mediaStreamFacade;

            _mediaStreamFacade = null;

            mediaStreamFacade.StateChange -= TsMediaManagerOnStateChange;

            // Don't block the cleanup in case someone is mashing buttons.
            // It could deadlock.
            mediaStreamFacade.DisposeBackground("MainPage CleanupMediaStreamFacade");
        }
Пример #18
0
        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
                return;

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
        }
Пример #19
0
        void CleanupMediaStream()
        {
            mediaElement1.Source = null;

            if (null == _mediaStreamFacade)
                return;

            _mediaStreamFacade.StateChange -= TsMediaManagerOnStateChange;

            _mediaStreamFacade.DisposeSafe();

            _mediaStreamFacade = null;
        }
 private static void InitialiseMediaStream()
 {
     _logger.Info("Creating stream facade");
     _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();
 }
Пример #21
0
        async Task CleanupMediaStreamFacadeAsync()
        {
            Debug.WriteLine("MediaPlayerManager.CleanupMediaStreamFacadeAsync()");

            var msf = _mediaStreamFacade;

            if (null == msf)
                return;

            _mediaStreamFacade = null;

            msf.StateChange -= MediaStreamFacadeOnStateChange;

            await msf.CloseAsync().ConfigureAwait(false);

            msf.DisposeBackground("MediaPlayerManager CleanupMediaStreamFacadeAsync");
        }
Пример #22
0
        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
                return;

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();
        }
Пример #23
0
        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
                return;

            // Enable UseHttpConnection to use sockets directly instead of going through
            // the system's default HTTP client.  HttpConnection is not as picky about
            // headers and it will not pollute the system's HTTP cache, but it will always
            // open a new connection for each request.
            //MediaStreamFacadeSettings.Parameters.UseHttpConnection = true;

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
        }
Пример #24
0
        async Task UnsafeCleanupMediaStreamFacadeAsync(IMediaStreamFacade mediaStreamFacade)
        {
            mediaStreamFacade.StateChange -= TsMediaManagerOnStateChange;

            try
            {
                var localMediaStreamFacade = mediaStreamFacade;

                var closeTask = Task.Run(() => localMediaStreamFacade.CloseAsync());

                var timeoutTask = Task.Delay(6000);

                await Task.WhenAny(closeTask, timeoutTask).ConfigureAwait(false);

                if (closeTask.IsCompleted)
                    closeTask.Wait();
                else
                {
                    Debug.WriteLine("AudioTrackStreamer.UnsafeCleanupMediaStreamFacadeAsync() CloseAsync timeout");

                    var cleanupTask = closeTask.ContinueWith(t =>
                    {
                        var ex = t.Exception;
                        if (null != ex)
                            Debug.WriteLine("AudioTrackStreamer.UnsafeCleanupMediaStreamFacadeAsync() CloseAsync() failed: " + ex.Message);

                        localMediaStreamFacade.DisposeSafe();
                    });

                    TaskCollector.Default.Add(cleanupTask, "AudioTrackStreamer facade cleanup");

                    Abort();

                    return;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AudioTrackStreamer.UnsafeCleanupMediaStreamFacadeAsync() close async failed: " + ex.ExtendedMessage());

                Abort();
            }

            // Should this Collect be inside the #if DEBUG?
            // The available memory is usually only on the
            // order of a couple of megabytes on a 512MB device.
            // We are at a point where we can afford to stall
            // for a while and we have just released a large
            // number of objects.
            GC.Collect();
#if DEBUG
            GC.WaitForPendingFinalizers();
            GC.Collect();

            DumpMemory();
#endif
        }
Пример #25
0
        IMediaStreamFacade InitializeMediaStream()
        {
            if (null != _mediaStreamFacade && _mediaStreamFacade.IsDisposed)
                _mediaStreamFacade = null;

            if (null == _mediaStreamFacade)
                _mediaStreamFacade = CreateMediaStreamFacade();

            return _mediaStreamFacade;
        }
Пример #26
0
        async Task CleanupMediaStreamFacadeAsync(IMediaStreamFacade mediaStreamFacade)
        {
            Debug.WriteLine("AudioTrackStreamer.CleanupMediaStreamFacade(msf)");

            try
            {
                var wasOk = mediaStreamFacade == Interlocked.CompareExchange(ref _mediaStreamFacade, null, mediaStreamFacade);

                if (wasOk)
                    await UnsafeCleanupMediaStreamFacadeAsync(mediaStreamFacade).ConfigureAwait(false);
                else
                    Debug.WriteLine("AudioTrackStreamer.CleanupMediaStreamFacade(msf) cleanup lost race with something");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AudioTrackStreamer.CleanupMediaStreamFacade(msf) cleanup failed: " + ex.ExtendedMessage());
            }
        }
Пример #27
0
        async Task CleanupAsync()
        {
            Debug.WriteLine("StreamingMediaPlugin.CleanupAsync()");

            try
            {
                var playbackSession = _playbackSession;

                if (null != playbackSession)
                    await playbackSession.CloseAsync().ConfigureAwait(false);

                using (await _asyncLock.LockAsync(CancellationToken.None).ConfigureAwait(false))
                {
                    if (_mediaStreamFacade.IsDisposed)
                        _mediaStreamFacade = null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("StreamingMediaPlugin.CleanupAsync() failed: " + ex.Message);
            }
        }
Пример #28
0
        public void Dispose()
        {
            Debug.WriteLine("MediaPlayerManager.Dispose()");

            _mediaPlayer.MediaOpened -= MediaPlayerOnMediaOpened;
            _mediaPlayer.MediaEnded -= MediaPlayerOnMediaEnded;
            _mediaPlayer.CurrentStateChanged -= MediaPlayerOnCurrentStateChanged;
            _mediaPlayer.MediaFailed -= MediaPlayerOnMediaFailed;

            if (null != _mediaStreamFacade)
            {
                _mediaStreamFacade.StateChange -= MediaStreamFacadeOnStateChange;

                _mediaStreamFacade.Dispose();
                _mediaStreamFacade = null;
            }

            _asyncLock.Dispose();
        }
Пример #29
0
        void OnUnload()
        {
            Debug.WriteLine("MainPage unload");

            StopMedia();

            var mediaStreamFacade = _mediaStreamFacade;
            _mediaStreamFacade = null;

            mediaStreamFacade.DisposeBackground("MainPage unload");
        }
Пример #30
0
        void CleanupMedia()
        {
            StopMedia();

            if (null == _mediaStreamFacade)
                return;

            var mediaStreamFacade = _mediaStreamFacade;

            _mediaStreamFacade = null;

            //Don't block the dispose
            mediaStreamFacade.DisposeBackground("PlayerPage CleanupMedia");
        }
Пример #31
0
        async Task InitializeMediaStreamAsync()
        {
            Debug.WriteLine("MediaPlayerManager.InitializeMediaStreamAsync()");

            if (null != _mediaStreamFacade)
            {
                await CloseMediaSourceAsync().WithCancellation(_cancellationToken).ConfigureAwait(false);

                try
                {
                    await _mediaStreamFacade.StopAsync(_cancellationToken).ConfigureAwait(false);

                    ForceGc();

                    return;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("MediaPlayerManager.InitializeMediaStreamAsync() stop failed: " + ex.ExtendedMessage());
                }

                try
                {
                    await CleanupMediaStreamFacadeAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("MediaPlayerManager.InitializeMediaStreamAsync() cleanup failed: " + ex.ExtendedMessage());
                }
            }

            ForceGc();

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.SetParameter(_bufferingPolicy);

            _mediaStreamFacade.SetParameter(_mediaManagerParameters);

            _mediaStreamFacade.SetParameter(WebReaderManagerParameters);

            _mediaStreamFacade.SetParameter(_metadataHandler.MetadataSink);

            _mediaStreamFacade.StateChange += MediaStreamFacadeOnStateChange;
        }