Ejemplo n.º 1
0
        protected virtual void SaveSubtitlePreference()
        {
            BaseStreamInfoHandler subtitleStreams;

            lock (SyncObj)
                subtitleStreams = _streamInfoSubtitles;

            if (subtitleStreams == null)
            {
                return;
            }

            VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>() ?? new VideoSettings();

            settings.PreferredSubtitleStreamName = subtitleStreams.CurrentStreamName;
            // if the subtitle stream has proper LCID, remember it.
            int lcid = subtitleStreams.CurrentStream.IsAutoSubtitle ? 0 : subtitleStreams.CurrentStream.LCID;

            if (lcid != 0)
            {
                settings.PreferredSubtitleLanguage = lcid;
            }

            // if selected stream is "No subtitles" or "forced subtitle", we disable the setting
            settings.EnableMpcSubtitlesEngine = subtitleStreams.CurrentStreamName.ToLowerInvariant().Contains(GetNoSubsName().ToLowerInvariant()) == false &&
                                                subtitleStreams.CurrentStreamName.ToLowerInvariant().Contains(FORCED_SUBTITLES.ToLowerInvariant()) == false;
            ServiceRegistration.Get <ISettingsManager>().Save(settings);

            // Make sure MPC subs engine is enabled when valid subtitle got selected.
            MpcSubtitles.SetEnable(settings.EnableMpcSubtitlesEngine);
        }
Ejemplo n.º 2
0
        public void Render(Rectangle subsRect, Rectangle frameRect, int xOffsetInPixels)
        {
            Rectangle r    = posRelativeToFrame ? frameRect : subsRect;
            int       posY = adjustPosY * r.Height / GUIGraphicsContext.Height;

            MpcSubtitles.Render(r.X, r.Y + posY, r.Width, r.Height, xOffsetInPixels);
        }
Ejemplo n.º 3
0
        protected override void AddSubtitleFilter(bool isSourceFilterPresent)
        {
            VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>() ?? new VideoSettings();
            int           preferredSubtitleLcid      = settings.PreferredSubtitleLanguage;
            var           fileSystemResourceAccessor = _resourceAccessor as IFileSystemResourceAccessor;

            if (fileSystemResourceAccessor != null)
            {
                ServiceRegistration.Get <ILogger>().Debug("{0}: Adding MPC-HC subtitle engine", PlayerTitle);
                SubtitleStyle defStyle = new SubtitleStyle();
                defStyle.Load();
                MpcSubtitles.SetDefaultStyle(ref defStyle, false);

                IntPtr upDevice = SkinContext.Device.NativePointer;
                string filename = fileSystemResourceAccessor.ResourcePathName;

                MpcSubtitles.LoadSubtitles(upDevice, _displaySize, filename, _graphBuilder, @".\", preferredSubtitleLcid);
                if (settings.EnableSubtitles)
                {
                    MpcSubtitles.SetEnable(true);
                }
            }

            AddClosedCaptionsFilter();
        }
Ejemplo n.º 4
0
        public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
        {
            LoadSettings();
            MpcSubtitles.SetDefaultStyle(ref this.defStyle, this.overrideASSStyle);
            if (selectionOff)
            {
                MpcSubtitles.SetShowForcedOnly(false);
            }
            else
            {
                MpcSubtitles.SetShowForcedOnly(!this.autoShow);
            }
            //remove DirectVobSub
            DirectVobSubUtil.RemoveFromGraph(graphBuilder);
            {
                //remove InternalScriptRenderer as it takes subtitle pin
                IBaseFilter isr = null;
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
                if (isr != null)
                {
                    graphBuilder.RemoveFilter(isr);
                    DirectShowUtil.ReleaseComObject(isr);
                }
            }

            FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);

            Size size = new Size(GUIGraphicsContext.Width, GUIGraphicsContext.Height);

            return(MpcSubtitles.LoadSubtitles(
                       DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device),
                       size, filename, graphBuilder, subPaths));
        }
Ejemplo n.º 5
0
        protected override void LoadAdvancedSettings(Settings xmlreader)
        {
            int    subPicsBufferAhead = xmlreader.GetValueAsInt("subtitles", "subPicsBufferAhead", 3);
            bool   pow2textures       = xmlreader.GetValueAsBool("subtitles", "pow2tex", false);
            string textureSize        = xmlreader.GetValueAsString("subtitles", "textureSize", "Medium");
            bool   disableAnimation   = xmlreader.GetValueAsBool("subtitles", "disableAnimation", true);

            int  w, h;
            int  screenW = GUIGraphicsContext.Width;
            int  screenH = GUIGraphicsContext.Height;
            bool res1080 = (screenW == 1920 && screenH == 1080);
            bool res720  = (screenW >= 1280 && screenW <= 1368 && screenH >= 720 && screenH <= 768);

            if (textureSize.Equals("Desktop"))
            {
                w = screenW;
                h = screenH;
            }
            else if (textureSize.Equals("Low"))
            {
                if (res1080)
                {
                    w = 854;
                    h = 480;
                }
                else if (res720)
                {
                    w = 512;
                    h = 288;
                }
                else
                {
                    w = (int)(Math.Round(screenW / 3.0));
                    h = (int)(Math.Round(screenH / 3.0));
                }
            }
            else //if (textureSize.Equals("Medium"))
            {
                if (res1080)
                {
                    w = 1280;
                    h = 720;
                }
                else if (res720)
                {
                    w = 854;
                    h = 480;
                }
                else
                {
                    w = (int)(Math.Round(screenW * 2.0 / 3));
                    h = (int)(Math.Round(screenH * 2.0 / 3));
                }
            }
            Log.Debug("MpcEngine: using texture size of {0}x{1}", w, h);
            Size size = new Size(w, h);

            MpcSubtitles.SetAdvancedOptions(subPicsBufferAhead, size, pow2textures, disableAnimation);
        }
        public MpcStreamInfoHandler()
        {
            var subtitleCount = MpcSubtitles.GetCount();

            for (int i = 0; i < subtitleCount; ++i)
            {
                string     subtitleTrackName = MpcSubtitles.GetTrackName(i);
                int        lcid      = BaseDXPlayer.LookupLcidFromName(subtitleTrackName);
                StreamInfo subStream = new StreamInfo(null, i, subtitleTrackName, lcid);
                AddUnique(subStream);
            }
            AddUnique(new StreamInfo(null, subtitleCount + 1, VideoPlayer.NO_SUBTITLES, 0));
        }
 public override bool EnableStream(string selectedStream)
 {
     // Do not enumerate raw stream names again, as they were made unique (adding counters)
     for (int i = 0; i < Count; ++i)
     {
         string subtitleTrackName = this[i].Name;
         if (subtitleTrackName.Equals(selectedStream))
         {
             ServiceRegistration.Get <ILogger>().Debug("MpcStreamInfoHandler: Enable stream '{0}'", selectedStream);
             MpcSubtitles.SetCurrent(i);
             lock (_syncObj)
                 _currentStream = this[i];
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
 public void SetDevice(IntPtr device)
 {
     if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR)
     {
         // Need to init there to have the setting for madVR.
         LoadSettings();
         MpcSubtitles.SetDefaultStyle(ref this.defStyle, this.overrideASSStyle);
         if (selectionOff)
         {
             MpcSubtitles.SetShowForcedOnly(false);
         }
         else
         {
             MpcSubtitles.SetShowForcedOnly(!this.autoShow);
         }
     }
     MpcSubtitles.SetDevice(device);
 }
Ejemplo n.º 9
0
        protected override void AddSubtitleFilter(bool isSourceFilterPresent)
        {
            VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>() ?? new VideoSettings();
            int           preferredSubtitleLcid = settings.PreferredSubtitleLanguage;

            ServiceRegistration.Get <ILogger>().Debug("{0}: Adding MPC-HC subtitle engine", PlayerTitle);
            SubtitleStyle defStyle = new SubtitleStyle();

            defStyle.Load();
            MpcSubtitles.SetDefaultStyle(ref defStyle, false);

            IntPtr upDevice = SkinContext.Device.NativePointer;
            string filename = string.Empty;

            string paths;

            if (GetSubtitlePath(out paths, out filename))
            {
                MpcSubtitles.LoadSubtitles(upDevice, _displaySize, filename, _graphBuilder, paths, preferredSubtitleLcid);
                MpcSubtitles.SetEnable(settings.EnableMpcSubtitlesEngine);
            }
        }
Ejemplo n.º 10
0
 public void SaveToDisk()
 {
     MpcSubtitles.SaveToDisk();
 }
Ejemplo n.º 11
0
 public void SetDevice(IntPtr device)
 {
     MpcSubtitles.SetDevice(device);
 }
Ejemplo n.º 12
0
 public void SetTime(long nsSampleTime)
 {
     MpcSubtitles.SetTime(nsSampleTime);
 }
Ejemplo n.º 13
0
 public string GetSubtitleName(int i)
 {
     return(MpcSubtitles.GetTrackName(i));
 }
Ejemplo n.º 14
0
 public string GetLanguage(int i)
 {
     return(MpcSubtitles.GetLanguage(i));
 }
Ejemplo n.º 15
0
 public int GetCount()
 {
     return(MpcSubtitles.GetCount());
 }
Ejemplo n.º 16
0
 public void RenderEx(Rectangle subsRect, Rectangle frameRect, int xOffsetInPixels)
 {
     MpcSubtitles.RenderEx(subsRect, frameRect, xOffsetInPixels, posRelativeToFrame);
 }
Ejemplo n.º 17
0
 public bool IsModified()
 {
     return(MpcSubtitles.IsModified());
 }
Ejemplo n.º 18
0
        public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
        {
            LoadSettings();
            MpcSubtitles.SetDefaultStyle(ref this.defStyle, this.overrideASSStyle);
            if (selectionOff)
            {
                MpcSubtitles.SetShowForcedOnly(false);
            }
            else
            {
                MpcSubtitles.SetShowForcedOnly(!this.autoShow);
            }
            //remove DirectVobSub
            DirectVobSubUtil.RemoveFromGraph(graphBuilder);
            {
                //remove InternalScriptRenderer as it takes subtitle pin
                IBaseFilter isr = null;
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
                if (isr != null)
                {
                    graphBuilder.RemoveFilter(isr);
                    DirectShowUtil.ReleaseComObject(isr);
                }
            }

            FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);

            Size size = new Size(GUIGraphicsContext.Width, GUIGraphicsContext.Height);

            // Get Default Language from MP Setting and parse it to MPC-HC Engine (needed for forced track)
            string defaultLanguageCulture = "EN";
            string localizedCINameSub     = "EN";
            int    lcidCI = 0;

            using (Settings xmlreader = new MPSettings())
            {
                try
                {
                    if (g_Player.IsVideo && (g_Player.CurrentFile.ToUpperInvariant().Contains(@"\BDMV\INDEX.BDMV")))
                    {
                        localizedCINameSub = (xmlreader.GetValueAsString("bdplayer", "subtitlelanguage", "English"));
                        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
                        {
                            if (ci.EnglishName == localizedCINameSub)
                            {
                                lcidCI = ci.TextInfo.LCID;;
                            }
                        }
                        Log.Info("MpcEngine: Subtitle Blu-ray Player CultureInfo {0}", localizedCINameSub);
                    }
                    else
                    {
                        CultureInfo ci = new CultureInfo(xmlreader.GetValueAsString("subtitles", "language", defaultLanguageCulture));
                        lcidCI = ci.TextInfo.LCID;
                        Log.Info("MpcEngine: Subtitle VideoPlayer CultureInfo {0}", ci);
                    }
                }
                catch (Exception ex)
                {
                    CultureInfo ci = new CultureInfo(defaultLanguageCulture);
                    lcidCI = ci.TextInfo.LCID;
                    Log.Error(
                        "MpcEngine: SelectSubtitleLanguage - unable to build CultureInfo, make sure MediaPortal.xml is not corrupted! - {0}",
                        ex);
                }
            }

            return(MpcSubtitles.LoadSubtitles(
                       DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device),
                       size, filename, graphBuilder, subPaths, lcidCI));
        }
Ejemplo n.º 19
0
 public void FreeSubtitles()
 {
     MpcSubtitles.FreeSubtitles();
 }