コード例 #1
0
        /// <summary>
        /// Handles the MediaInitializing event of the Media control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MediaInitializingEventArgs"/> instance containing the event data.</param>
        private void OnMediaInitializing(object sender, MediaInitializingEventArgs e)
        {
            // An example of injecting input options for http/https streams
            if (e.Url.StartsWith("http://") || e.Url.StartsWith("https://"))
            {
                e.Configuration.PrivateOptions["user_agent"]          = $"{typeof(ContainerConfiguration).Namespace}/{typeof(ContainerConfiguration).Assembly.GetName().Version}";
                e.Configuration.PrivateOptions["headers"]             = "Referer:https://www.unosquare.com";
                e.Configuration.PrivateOptions["multiple_requests"]   = "1";
                e.Configuration.PrivateOptions["reconnect"]           = "1";
                e.Configuration.PrivateOptions["reconnect_streamed"]  = "1";
                e.Configuration.PrivateOptions["reconnect_delay_max"] = "10"; // in seconds

                // e.Configuration.PrivateOptions["reconnect_at_eof"] = "1"; // This prevents some HLS stream from opening properly
            }

            // Example of forcing tcp transport on rtsp feeds
            // RTSP is similar to HTTP but it only provides metadata about the underlying stream
            // Most RTSP compatible streams expose RTP data over both UDP and TCP.
            // TCP provides reliable communication while UDP does not
            if (e.Url.StartsWith("rtsp://"))
            {
                e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";
                e.Configuration.GlobalOptions.FlagNoBuffer       = true;
            }

            // A few WMV files I have tested don't have continuous enough audio packets to support
            // perfect synchronization between audio and video
            Media.RendererOptions.AudioDisableSync = e.Url.EndsWith(".wmv");

            // In realtime streams these settings can be used to reduce latency (see example from issue #152)
            // e.Options.GlobalOptions.FlagNoBuffer = true;
            // e.Options.GlobalOptions.ProbeSize = 8192;
            // e.Options.GlobalOptions.MaxAnalyzeDuration = System.TimeSpan.FromSeconds(1);
        }
コード例 #2
0
        /// <summary>
        /// Handles the MediaInitializing event of the Media control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MediaInitializingEventArgs"/> instance containing the event data.</param>
        private void OnMediaInitializing(object sender, MediaInitializingEventArgs e)
        {
            // An example of injecting input options for http/https streams
            if (e.MediaSource.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
                e.MediaSource.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
            {
                e.Configuration.PrivateOptions["user_agent"] = $"{typeof(ContainerConfiguration).Namespace}/{typeof(ContainerConfiguration).Assembly.GetName().Version}";
                e.Configuration.PrivateOptions["headers"]    = "Referer:https://www.unosquare.com";

                // Other configuration options
                // e.Configuration.PrivateOptions["multiple_requests"] = "1";
                // e.Configuration.PrivateOptions["reconnect"] = "1";
                // e.Configuration.PrivateOptions["reconnect_streamed"] = "1";
                // e.Configuration.PrivateOptions["reconnect_delay_max"] = "10"; // in seconds
                // e.Configuration.PrivateOptions["reconnect_at_eof"] = "1"; // This prevents some HLS stream from opening properly
            }

            // Example of forcing tcp transport on rtsp feeds
            // RTSP is similar to HTTP but it only provides metadata about the underlying stream
            // Most RTSP compatible streams expose RTP data over both UDP and TCP.
            // TCP provides reliable communication while UDP does not
            if (e.MediaSource.StartsWith("rtsp://", StringComparison.OrdinalIgnoreCase))
            {
                e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";
                e.Configuration.GlobalOptions.FlagNoBuffer       = true;

                // You can change the open/read timeout before the packet reading
                // operation fails.
                e.Configuration.ReadTimeout = TimeSpan.FromSeconds(10);
            }

            // Example of setting extra IPs for NDI (needs compatible build and Newtek binaries)
            if (e.Configuration.ForcedInputFormat == "libndi_newtek")
            {
                // Sample URL: device://libndi_newtek?COMPUTERNAME-HERE (Test Pattern)
                e.Configuration.PrivateOptions["extra_ips"] = "127.0.0.1";
            }

            // A decryption key can be set by specifying a hexadecimal string.
            if (e.MediaSource.EndsWith("03-encrypted.mp4", StringComparison.InvariantCultureIgnoreCase))
            {
                e.Configuration.PrivateOptions["decryption_key"] = "76a6c65c5ea762046bd749a2e632ccbb";
            }

            // In realtime streams these settings can be used to reduce latency (see example from issue #152)
            // e.Options.GlobalOptions.FlagNoBuffer = true;
            // e.Options.GlobalOptions.ProbeSize = 8192;
            // e.Options.GlobalOptions.MaxAnalyzeDuration = System.TimeSpan.FromSeconds(1);
        }
コード例 #3
0
        /// <summary>
        /// Handles the MediaInitializing event of the Media control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MediaInitializingEventArgs"/> instance containing the event data.</param>
        private void OnMediaInitializing(object sender, MediaInitializingEventArgs e)
        {
            ViewModel.NotificationMessage = "Media is opening . . .";

            // An example of injecting input options for http/https streams
            // A simple website to get live stream examples: https://pwn.sh/tools/getstream.html
            if (e.MediaSource.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
                e.MediaSource.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
            {
                // e.Configuration.PrivateOptions["user_agent"] = $"{typeof(ContainerConfiguration).Namespace}/{typeof(ContainerConfiguration).Assembly.GetName().Version}";
                e.Configuration.PrivateOptions["user_agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36";

                // e.Configuration.PrivateOptions["headers"] = "Referer:https://www.unosquare.com";
                e.Configuration.PrivateOptions["headers"] = "Referer: " + e.MediaSource;
            }

            // Example of forcing tcp transport on rtsp feeds
            // RTSP is similar to HTTP but it only provides metadata about the underlying stream
            // Most RTSP compatible streams expose RTP data over both UDP and TCP.
            // TCP provides reliable communication while UDP does not
            if (e.MediaSource.StartsWith("rtsp://", StringComparison.OrdinalIgnoreCase))
            {
                e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";
                e.Configuration.GlobalOptions.FlagNoBuffer       = true;

                // You can change the open/read timeout before the packet reading
                // operation fails.
                e.Configuration.ReadTimeout = TimeSpan.FromSeconds(10);
            }

            // Example of setting extra IPs for NDI (needs compatible build and Newtek binaries)
            if (e.Configuration.ForcedInputFormat == "libndi_newtek")
            {
                // Sample URL: device://libndi_newtek?COMPUTERNAME-HERE (Test Pattern)
                e.Configuration.PrivateOptions["extra_ips"] = "127.0.0.1";
            }

            // A decryption key can be set by specifying a hexadecimal string.
            if (e.MediaSource.EndsWith("03-encrypted.mp4", StringComparison.InvariantCultureIgnoreCase))
            {
                e.Configuration.PrivateOptions["decryption_key"] = "76a6c65c5ea762046bd749a2e632ccbb";
            }

            // In realtime streams these settings can be used to reduce latency (see example from issue #152)
            // e.Options.GlobalOptions.FlagNoBuffer = true;
            // e.Options.GlobalOptions.ProbeSize = 8192;
            // e.Options.GlobalOptions.MaxAnalyzeDuration = System.TimeSpan.FromSeconds(1);
        }
コード例 #4
0
        /// <summary>
        /// Handles the MediaInitializing event of the Media control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MediaInitializingEventArgs"/> instance containing the event data.</param>
        private void OnMediaInitializing(object sender, MediaInitializingEventArgs e)
        {
            // An example of injecting input options for http/https streams
            if (e.Url.StartsWith("http://") || e.Url.StartsWith("https://"))
            {
                e.Configuration.PrivateOptions["user_agent"]          = $"{typeof(ContainerConfiguration).Namespace}/{typeof(ContainerConfiguration).Assembly.GetName().Version}";
                e.Configuration.PrivateOptions["headers"]             = "Referer:https://www.unosquare.com";
                e.Configuration.PrivateOptions["multiple_requests"]   = "1";
                e.Configuration.PrivateOptions["reconnect"]           = "1";
                e.Configuration.PrivateOptions["reconnect_streamed"]  = "1";
                e.Configuration.PrivateOptions["reconnect_delay_max"] = "10"; // in seconds

                // e.Configuration.PrivateOptions["reconnect_at_eof"] = "1"; // This prevents some HLS stream from opening properly
            }

            // Example of forcing tcp transport on rtsp feeds
            // RTSP is similar to HTTP but it only provides metadata about the underlying stream
            // Most RTSP compatible streams expose RTP data over both UDP and TCP.
            // TCP provides reliable communication while UDP does not
            if (e.Url.StartsWith("rtsp://"))
            {
                e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";
                e.Configuration.GlobalOptions.FlagNoBuffer       = true;
            }

            // Example of setting extra IPs for NDI (needs compatible build and Newtek binaries)
            if (e.Configuration.ForcedInputFormat == "libndi_newtek")
            {
                // Sample URL: device://libndi_newtek?HOME-SLIMBIRD (Test Pattern)
                e.Configuration.PrivateOptions["extra_ips"] = "127.0.0.1";
            }

            // In realtime streams these settings can be used to reduce latency (see example from issue #152)
            // e.Options.GlobalOptions.FlagNoBuffer = true;
            // e.Options.GlobalOptions.ProbeSize = 8192;
            // e.Options.GlobalOptions.MaxAnalyzeDuration = System.TimeSpan.FromSeconds(1);
        }