Beispiel #1
0
        public void UpdateConfiguration(DirectShowPlayerConfiguration config)
        {
            var curConfig = GetConfiguration();

            _config.SaveConfiguration("directshowplayer", config);
            if (string.Compare(curConfig.FilterSet, config.FilterSet, true) != 0)
            {
                //update filters
                URCOMLoader.Instance.EnsureObjects(_appPaths.ProgramDataPath, _zipClient, false, true);
            }
        }
Beispiel #2
0
        public void Play(string path, long startPositionTicks, bool isVideo, MediaSourceInfo mediaSource, BaseItemDto item, bool isFullScreen, PlayerOptions options, IntPtr videoWindowHandle)
        {
            _isFadingOut = false;
            _isVideo     = isVideo;

            if (mediaSource.Protocol == MediaProtocol.File && mediaSource.VideoType.HasValue)
            {
                if (mediaSource.VideoType.Value == VideoType.VideoFile)
                {
                    if (File.Exists(mediaSource.Path) && !string.Equals(Path.GetExtension(mediaSource.Path), "dvr-ms", StringComparison.OrdinalIgnoreCase))
                    {
                        path = mediaSource.Path;
                    }
                }
                else if (mediaSource.VideoType.Value == VideoType.Iso)
                {
                    if (File.Exists(mediaSource.Path))
                    {
                        path = mediaSource.Path;
                    }
                }
                else
                {
                    if (Directory.Exists(mediaSource.Path))
                    {
                        path = GetFolderRipPath(mediaSource.VideoType.Value, mediaSource.Path);
                    }
                }
            }

            if (_player.PlayState != PlayState.Idle)
            {
                _player.Stop();
            }

            _logger.Info("Playing media source {0}", _json.SerializeToString(mediaSource));

            var config = new DirectShowPlayerConfiguration();

            config.VideoConfig.SetDefaults();
            config.AudioConfig.SetDefaults();
            config.SubtitleConfig.SetDefaults();

            config.AudioConfig.ShowTrayIcon = true;
            config.VideoConfig.ShowTrayIcon = true;

            SetPlayerOptions(options, config);

            _player.Play(path, startPositionTicks, isVideo, item, mediaSource, isFullScreen, videoWindowHandle, config);
        }
Beispiel #3
0
        private void SetPlayerOptions(PlayerOptions options, DirectShowPlayerConfiguration config)
        {
            if (string.Equals(options.videoOutputLevels, "full", StringComparison.OrdinalIgnoreCase))
            {
                config.VideoConfig.NominalRange = 1;
            }
            else if (string.Equals(options.videoOutputLevels, "limited", StringComparison.OrdinalIgnoreCase))
            {
                config.VideoConfig.NominalRange = 2;
            }

            config.VideoConfig.VideoRenderer = "madvr";

            //<option value="2">Intel Quick Sync</option>
            if (string.IsNullOrWhiteSpace(options.hwdec))
            {
                config.VideoConfig.HwaMode = 0;
            }
            else if (string.Equals(options.hwdec, "dxva2", StringComparison.OrdinalIgnoreCase))
            {
                config.VideoConfig.HwaMode = (int)LAVHWAccel.DXVA2Native;
            }
            else if (string.Equals(options.hwdec, "dxva2-copy", StringComparison.OrdinalIgnoreCase))
            {
                config.VideoConfig.HwaMode = (int)LAVHWAccel.DXVA2CopyBack;
            }

            config.VideoConfig.AutoChangeRefreshRate = false;

            if (string.Equals(options.deinterlace, "yes", StringComparison.OrdinalIgnoreCase))
            {
                config.VideoConfig.SW_DeintModes = (int)LAVSWDeintModes.YADIF;
            }

            switch (options.audioChannels ?? string.Empty)
            {
            case "7.1":
                config.AudioConfig.SpeakerLayout = "SevenDotOneSurround";
                break;

            case "5.1":
                config.AudioConfig.SpeakerLayout = "FiveDotOneSurround";
                break;

            case "stereo":
                config.AudioConfig.SpeakerLayout = "Stereo";
                break;
            }

            config.AudioConfig.ExpandMono = true;
            config.AudioConfig.Expand61   = false;

            config.AudioConfig.BitstreamCodecs = (options.audioSpdif ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();

            int drcLevel;

            if (int.TryParse(options.dynamicRangeCompression, NumberStyles.Integer, CultureInfo.InvariantCulture, out drcLevel))
            {
                config.AudioConfig.EnableDRC = true;
                config.AudioConfig.DRCLevel  = drcLevel;
            }
            else
            {
                config.AudioConfig.EnableDRC = false;
            }
        }
Beispiel #4
0
        public void Play(string path, long startPositionTicks, bool isVideo, BaseItemDto item, MediaSourceInfo mediaSource, bool enableFullScreen, IntPtr videoWindowHandle, DirectShowPlayerConfiguration config)
        {
            var playableItem = new PlayableItem
            {
                MediaSource  = mediaSource,
                PlayablePath = path,
                OriginalItem = item
            };

            try
            {
                InvokeOnPlayerThread(() =>
                {
                    //create a fresh DS Player everytime we want one
                    DisposePlayerInternal();

                    _mediaPlayer = new DirectShowPlayer(this, _logger, config, _httpClient, videoWindowHandle);
                    _mediaPlayer.Play(playableItem, enableFullScreen);

                    try
                    {
                        Standby.PreventSleepAndMonitorOff();
                    }
                    catch
                    {
                    }

                    try
                    {
                        if (startPositionTicks > 0)
                        {
                            _mediaPlayer.Seek(startPositionTicks);
                        }
                    }
                    catch
                    {
                    }

                    if (playableItem.IsVideo)
                    {
                        var audioIndex    = playableItem.MediaSource.DefaultAudioStreamIndex;
                        var subtitleIndex = playableItem.MediaSource.DefaultSubtitleStreamIndex;

                        if (audioIndex.HasValue && audioIndex.Value != -1)
                        {
                            try
                            {
                                SetAudioStreamIndexInternal(audioIndex.Value);
                            }
                            catch
                            {
                            }
                        }
                        try
                        {
                            SetSubtitleStreamIndexInternal(subtitleIndex ?? -1);
                        }
                        catch
                        {
                        }
                    }
                }, true);
            }
            catch (Exception ex)
            {
                OnPlaybackStopped(playableItem, null, TrackCompletionReason.Failure, null);

                throw;
            }
        }