Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DirectOpenCommand"/> class.
 /// </summary>
 /// <param name="mediaCore">The manager.</param>
 /// <param name="inputStream">The custom implementation of an input stream.</param>
 public DirectOpenCommand(MediaEngine mediaCore, IMediaInputStream inputStream)
     : base(mediaCore)
 {
     InputStream = inputStream;
     Source      = inputStream.StreamUri;
     CommandType = CommandType.Open;
 }
Пример #2
0
        /// <summary>
        /// Opens the specified custom input stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>The awaitable task.</returns>
        public ConfiguredTaskAwaitable <bool> Open(IMediaInputStream stream) => Task.Run(async() =>
        {
            try { return(await MediaCore.Open(stream).ConfigureAwait(false)); }
            catch (Exception ex) { PostMediaFailedEvent(ex); }

            return(false);
        }).ConfigureAwait(true);
Пример #3
0
        /// <summary>
        /// Opens the media using a custom media input stream.
        /// </summary>
        /// <param name="stream">The URI.</param>
        /// <returns>The awaitable task</returns>
        /// <exception cref="InvalidOperationException">Source</exception>
        public async Task Open(IMediaInputStream stream)
        {
            if (BeginSynchronousCommand() == false)
            {
                return;
            }

            try
            {
                if (stream != null)
                {
                    await Commands.CloseAsync();

                    await Commands.OpenAsync(stream);
                }
                else
                {
                    await Commands.CloseAsync();
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                EndSynchronousCommand();
            }
        }
Пример #4
0
        /// <summary>
        /// Opens the media using a custom media input stream.
        /// </summary>
        /// <param name="stream">The URI.</param>
        /// <returns>The awaitable task</returns>
        /// <exception cref="InvalidOperationException">Source</exception>
        public async Task <bool> Open(IMediaInputStream stream)
        {
            if (stream != null)
            {
                await Commands.CloseMediaAsync();

                return(await Commands.OpenMediaAsync(stream));
            }
            else
            {
                return(await Commands.CloseMediaAsync());
            }
        }
Пример #5
0
        /// <summary>
        /// Opens the media using a custom media input stream.
        /// </summary>
        /// <param name="stream">The URI.</param>
        /// <returns>The awaitable task</returns>
        /// <exception cref="InvalidOperationException">Source</exception>
        public async Task Open(IMediaInputStream stream)
        {
            if (stream != null)
            {
                await Commands.CloseAsync();

                await Commands.OpenAsync(stream);
            }
            else
            {
                await Commands.CloseAsync();
            }
        }
 /// <summary>
 /// Opens the media using a custom media input stream.
 /// </summary>
 /// <param name="stream">The URI.</param>
 /// <returns>The awaitable task.</returns>
 /// <exception cref="InvalidOperationException">Source.</exception>
 public Task <bool> Open(IMediaInputStream stream)
 {
     if (stream != null)
     {
         return(Task.Run(async() =>
         {
             await Commands.CloseMediaAsync();
             return await Commands.OpenMediaAsync(stream);
         }));
     }
     else
     {
         return(Commands.CloseMediaAsync());
     }
 }
Пример #7
0
 /// <summary>
 /// Opens the media using a custom media input stream.
 /// </summary>
 /// <param name="stream">The URI.</param>
 /// <returns>The awaitable task</returns>
 /// <exception cref="InvalidOperationException">Source</exception>
 public Task <bool> Open(IMediaInputStream stream)
 {
     if (stream != null)
     {
         return(Task.Run(() =>
         {
             Commands.CloseMediaAsync().GetAwaiter().GetResult();
             return Commands.OpenMediaAsync(stream);
         }));
     }
     else
     {
         return(Commands.CloseMediaAsync());
     }
 }
Пример #8
0
        /// <summary>
        /// Opens the specified custom input stream.
        /// This command gets processed in a threadpool thread asynchronously.
        /// </summary>
        /// <param name="stream">The custom input stream.</param>
        /// <returns>
        /// The asynchronous task
        /// </returns>
        public async Task OpenAsync(IMediaInputStream stream)
        {
            // Check Uri Argument
            if (stream == null)
            {
                MediaCore?.Log(
                    MediaLogMessageType.Warning,
                    $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: '{nameof(stream)}' cannot be null");

                return;
            }

            if (CanExecuteCommands == false)
            {
                return;
            }
            else
            {
                IsOpening.Value = true;
            }

            var command = new OpenCommand(this, stream);

            ExecutingCommand = command;
            ClearCommandQueue();

            try
            {
                if (command.HasCompleted)
                {
                    return;
                }

                await command.StartAsync();
            }
            catch (Exception ex)
            {
                MediaCore?.Log(
                    MediaLogMessageType.Error,
                    $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: {ex.GetType()} - {ex.Message}");
            }
            finally
            {
                ExecutingCommand?.Complete();
                ExecutingCommand = null;
                IsOpening.Value  = false;
            }
        }
        public void Open(IMediaInputStream stream, Uri streamUri, HardwareDeviceInfo ha)
        {
            if (stream != null || streamUri != null)
            {
                Close();

                try
                {
                    // TODO: Sometimes when the stream can't be read, the sample player stays as if it were trying to open
                    // until the interrupt timeout occurs but and the Real-Time Clock continues. Strange behavior. Investigate more.

                    // Signal the initial state
                    var source = stream != null ? stream.StreamUri : streamUri;
                    State.ResetAll();
                    State.UpdateSource(source);

                    // Create a default stream container configuration object
                    var containerConfig = new ContainerConfiguration();


                    // Convert the URI object to something the Media Container understands (Uri to String)
                    var mediaSource = source.IsWellFormedOriginalString()
                        ? source.OriginalString
                        : Uri.EscapeUriString(source.OriginalString);

                    // When opening via URL (and not via custom input stream), fix up the protocols and stuff
                    if (stream == null)
                    {
                        try
                        {
                            // the async protocol prefix allows for increased performance for local files.
                            // or anything that is file-system related
                            if (source.IsFile || source.IsUnc)
                            {
                                // Set the default protocol Prefix
                                // The async protocol prefix by default does not ssem to provide
                                // any performance improvements. Just leaving it for future reference below.
                                // containerConfig.ProtocolPrefix = "async"
                                mediaSource = source.LocalPath;
                            }
                        }
                        catch { /* Ignore exception and continue */ }

                        // Support device URLs
                        // GDI GRAB: Example URI: device://gdigrab?desktop
                        if (string.IsNullOrWhiteSpace(source.Scheme) == false &&
                            (source.Scheme == "format" || source.Scheme == "device") &&
                            string.IsNullOrWhiteSpace(source.Host) == false &&
                            string.IsNullOrWhiteSpace(containerConfig.ForcedInputFormat) &&
                            string.IsNullOrWhiteSpace(source.Query) == false)
                        {
                            // Update the Input format and container input URL
                            // It is also possible to set some input options as follows:
                            // Example: streamOptions.PrivateOptions["framerate"] = "20"
                            containerConfig.ForcedInputFormat = source.Host;
                            mediaSource = Uri.UnescapeDataString(source.Query).TrimStart('?');
                            //this.LogInfo(Aspects.EngineCommand,
                            //    $"Media URI will be updated. Input Format: {source.Host}, Input Argument: {mediaSource}");
                        }
                    }

                    // Instantiate the public container using either a URL (default) or a custom input stream.
                    Container = stream == null ?
                                new MediaContainer(mediaSource, containerConfig, this) :
                                new MediaContainer(stream, containerConfig, this);

                    // Initialize the container
                    Container.Initialize();

                    Container.MediaOptions.VideoHardwareDevice = ha;

                    // Side-load subtitles if requested

                    // Get the main container open
                    Container.Open();

                    State.InitializeBufferingStatistics();

                    Workers = new MediaWorkerSet(this);
                    Workers.Start();
                }
                catch
                {
                    try { Workers?.Dispose(); } catch { /* Ignore any exceptions and continue */ }
                    try { Container?.Dispose(); } catch { /* Ignore any exceptions and continue */ }
                    Container = null;
                    throw;
                }
            }
            else
            {
                Close();
            }
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenCommand"/> class.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="inputStream">The custom implementation of an input stream.</param>
 public OpenCommand(MediaCommandManager manager, IMediaInputStream inputStream)
     : base(manager, MediaCommandType.Open)
 {
     InputStream = inputStream;
     Source      = inputStream.StreamUri;
 }