private IStreamBufferConfigure GetConfigure()
        {
            int                hr;
            RegResult          dispo;
            IntPtr             hkey;
            StreamBufferConfig sbc = new StreamBufferConfig();

            IStreamBufferInitialize isbi = (IStreamBufferInitialize)sbc;

            // Default registry key is HKEY_CURRENT_USER\Software\Microsoft\DVR (which
            // is what we are using here)
            int i = RegCreateKeyEx(
                (IntPtr)HKEY.CurrentUser,
                @"Software\Microsoft",
                0,
                null,
                0,
                RegSAM.Read | RegSAM.Write,
                null,
                out hkey,
                out dispo
                );

            if (i != 0)
            {
                throw new Exception("Error reading registry");
            }

            hr = isbi.SetHKEY(hkey);
            DsError.ThrowExceptionForHR(hr);

            return((IStreamBufferConfigure)sbc);
        }
Ejemplo n.º 2
0
        public void DoTests()
        {
            m_isbi = (IStreamBufferInitialize) new StreamBufferConfig();

            try
            {
                TestSetHKEY();
                TestSetSIDs();
            }
            finally
            {
                Marshal.ReleaseComObject(m_isbi);
            }
        }
        private void AddStreamBufferSourceFilter()
        {
            this.streamBufferSource = (IBaseFilter) new StreamBufferSource();

            int hr = this.graphBuilder2.AddFilter(this.streamBufferSource, "Stream Buffer Source");

            DsError.ThrowExceptionForHR(hr);


            IStreamBufferInitialize streamBufferInitialize = this.streamBufferSource as IStreamBufferInitialize;

            hr = streamBufferInitialize.SetHKEY(streamBufferConfigHKey);


            ConnectStreamBufferSinkToSource();
        }
        private void AddStreamBufferSinkFilter()
        {
            try
            {
                this.streamBufferSink = (IBaseFilter) new SBE2Sink();
            }
            catch { }
            if (this.streamBufferSink == null)             // In case SBE2Sink is not supported, fallback to the former filter.
            {
                this.streamBufferSink = (IBaseFilter) new StreamBufferSink();
            }

            int hr = this.graphBuilder.AddFilter(this.streamBufferSink, "Stream Buffer Sink");

            DsError.ThrowExceptionForHR(hr);

            IStreamBufferInitialize streamBufferInitialize = this.streamBufferSink as IStreamBufferInitialize;

            hr = streamBufferInitialize.SetHKEY(streamBufferConfigHKey);
            DsError.ThrowExceptionForHR(hr);
        }
        /// <summary> create the used COM components and get the interfaces. </summary>
        protected override bool GetInterfaces(string filename)
        {
            Speed = 1;
            Log.Info("StreamBufferPlayer9: GetInterfaces()");

            //switch back to directx fullscreen mode

            //		Log.Info("StreamBufferPlayer9: switch to fullscreen mode");
            Log.Info("StreamBufferPlayer9: Enabling DX9 exclusive mode");
            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 1, 0, null);

            GUIWindowManager.SendMessage(msg);

            //Log.Info("StreamBufferPlayer9: build graph");

            try
            {
                _graphBuilder = (IGraphBuilder) new FilterGraph();
                //Log.Info("StreamBufferPlayer9: add _vmr9");

                _vmr9 = new VMR9Util();
                _vmr9.AddVMR9(_graphBuilder);
                _vmr9.Enable(false);


                int hr;
                m_StreamBufferConfig = new StreamBufferConfig();
                streamConfig2        = m_StreamBufferConfig as IStreamBufferConfigure2;
                if (streamConfig2 != null)
                {
                    // setting the StreamBufferEngine registry key
                    IntPtr HKEY = (IntPtr) unchecked ((int)0x80000002L);
                    IStreamBufferInitialize pTemp = (IStreamBufferInitialize)streamConfig2;
                    IntPtr subKey = IntPtr.Zero;

                    RegOpenKeyEx(HKEY, "SOFTWARE\\MediaPortal", 0, 0x3f, out subKey);
                    hr = pTemp.SetHKEY(subKey);
                    hr = streamConfig2.SetFFTransitionRates(8, 32);
                    //Log.Info("set FFTransitionRates:{0:X}",hr);

                    int max, maxnon;
                    hr = streamConfig2.GetFFTransitionRates(out max, out maxnon);

                    streamConfig2.GetBackingFileCount(out _minBackingFiles, out _maxBackingFiles);
                    streamConfig2.GetBackingFileDuration(out _backingFileDuration);
                }
                //Log.Info("StreamBufferPlayer9: add sbe");

                // create SBE source
                _bufferSource = (IStreamBufferSource) new StreamBufferSource();
                if (_bufferSource == null)
                {
                    Log.Error("StreamBufferPlayer9:Failed to create instance of SBE (do you have WinXp SP1?)");
                    return(false);
                }


                IBaseFilter filter = (IBaseFilter)_bufferSource;
                hr = _graphBuilder.AddFilter(filter, "SBE SOURCE");
                if (hr != 0)
                {
                    Log.Error("StreamBufferPlayer9:Failed to add SBE to graph");
                    return(false);
                }

                IFileSourceFilter fileSource = (IFileSourceFilter)_bufferSource;
                if (fileSource == null)
                {
                    Log.Error("StreamBufferPlayer9:Failed to get IFileSourceFilter");
                    return(false);
                }


                //Log.Info("StreamBufferPlayer9: open file:{0}",filename);
                hr = fileSource.Load(filename, null);
                if (hr != 0)
                {
                    Log.Error("StreamBufferPlayer9:Failed to open file:{0} :0x{1:x}", filename, hr);
                    return(false);
                }


                //Log.Info("StreamBufferPlayer9: add codecs");
                // add preferred video & audio codecs
                string strVideoCodec    = "";
                string strAudioCodec    = "";
                string strAudioRenderer = "";
                int    intFilters       = 0;  // FlipGer: count custom filters
                string strFilters       = ""; // FlipGer: collect custom filters
                using (Settings xmlreader = new MPSettings())
                {
                    // FlipGer: load infos for custom filters
                    int intCount = 0;
                    while (xmlreader.GetValueAsString("mytv", "filter" + intCount.ToString(), "undefined") != "undefined")
                    {
                        if (xmlreader.GetValueAsBool("mytv", "usefilter" + intCount.ToString(), false))
                        {
                            strFilters += xmlreader.GetValueAsString("mytv", "filter" + intCount.ToString(), "undefined") + ";";
                            intFilters++;
                        }
                        intCount++;
                    }
                    strVideoCodec    = xmlreader.GetValueAsString("mytv", "videocodec", "");
                    strAudioCodec    = xmlreader.GetValueAsString("mytv", "audiocodec", "");
                    strAudioRenderer = xmlreader.GetValueAsString("mytv", "audiorenderer", "Default DirectSound Device");
                    string strValue = xmlreader.GetValueAsString("mytv", "defaultar", "Normal");
                    GUIGraphicsContext.ARType = Util.Utils.GetAspectRatio(strValue);
                }
                if (strVideoCodec.Length > 0)
                {
                    _videoCodecFilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, strVideoCodec);
                }
                if (strAudioCodec.Length > 0)
                {
                    _audioCodecFilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, strAudioCodec);
                }
                if (strAudioRenderer.Length > 0)
                {
                    _audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(_graphBuilder, strAudioRenderer, true);
                }
                // FlipGer: add custom filters to graph
                customFilters = new IBaseFilter[intFilters];
                string[] arrFilters = strFilters.Split(';');
                for (int i = 0; i < intFilters; i++)
                {
                    customFilters[i] = DirectShowUtil.AddFilterToGraph(_graphBuilder, arrFilters[i]);
                }

                // render output pins of SBE
                DirectShowUtil.RenderOutputPins(_graphBuilder, (IBaseFilter)fileSource);

                _mediaCtrl     = (IMediaControl)_graphBuilder;
                _mediaEvt      = (IMediaEventEx)_graphBuilder;
                _mediaSeeking  = _bufferSource as IStreamBufferMediaSeeking;
                _mediaSeeking2 = _bufferSource as IStreamBufferMediaSeeking2;
                if (_mediaSeeking == null)
                {
                    Log.Error("Unable to get IMediaSeeking interface#1");
                }
                if (_mediaSeeking2 == null)
                {
                    Log.Error("Unable to get IMediaSeeking interface#2");
                }
                if (_audioRendererFilter != null)
                {
                    IMediaFilter    mp    = _graphBuilder as IMediaFilter;
                    IReferenceClock clock = _audioRendererFilter as IReferenceClock;
                    hr = mp.SetSyncSource(clock);
                }

                // Set the IBasicAudioInterface

                _basicAudio = (IBasicAudio)_graphBuilder;

                //        Log.Info("StreamBufferPlayer9:SetARMode");
                //        DirectShowUtil.SetARMode(_graphBuilder,AspectRatioMode.Stretched);

                //Log.Info("StreamBufferPlayer9: set Deinterlace");

                if (!_vmr9.IsVMR9Connected)
                {
                    //_vmr9 is not supported, switch to overlay
                    Log.Info("StreamBufferPlayer9: switch to overlay");
                    _mediaCtrl = null;
                    Cleanup();
                    return(base.GetInterfaces(filename));
                }
                _pinVmr9ConnectedTo = _vmr9.PinConnectedTo;
                _vmr9.SetDeinterlaceMode();
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("StreamBufferPlayer9:exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
                return(false);
            }
        }
        protected void ConfigureTimeShiftingRegistry()
        {
            //http://msdn.microsoft.com/en-us/library/windows/desktop/dd694948%28v=vs.85%29.aspx

            UIntPtr HKEY_CURRENT_USER = (UIntPtr)0x80000001;
            //unchecked
            //{
            //    HKEY_CURRENT_USER = (UIntPtr)0x80000001;
            //}

            // Create the StreamBufferConfig object.
            StreamBufferConfig     streamBufferConfig    = new StreamBufferConfig();
            IStreamBufferConfigure streamBufferConfigure = streamBufferConfig as IStreamBufferConfigure;

            // Create a new registry key to hold our settings.
            streamBufferConfigHKey = IntPtr.Zero;
            IntPtr p = Marshal.AllocCoTaskMem(4);

            Marshal.WriteIntPtr(p, IntPtr.Zero);
            try
            {
                int lRes = RegCreateKey(HKEY_CURRENT_USER, MainForm.RegistryBaseKey + "\\SBE", p);
                streamBufferConfigHKey = Marshal.ReadIntPtr(p);
            }
            finally
            {
                Marshal.FreeCoTaskMem(p);
            }

            // Set the registry key.
            IStreamBufferInitialize streamBufferInitialize = streamBufferConfigure as IStreamBufferInitialize;
            int hr = streamBufferInitialize.SetHKEY(streamBufferConfigHKey);

            DsError.ThrowExceptionForHR(hr);

            //http://msdn.microsoft.com/en-us/library/windows/desktop/dd694977%28v=vs.85%29.aspx
            //For Windows Vista or later the IStreamBufferSink::LockProfile method requires administrator privileges,
            // unless you first call IStreamBufferConfigure3::SetNamespace with the value NULL.
            IStreamBufferConfigure3 streamBufferConfigure3 = streamBufferConfig as IStreamBufferConfigure3;

            if (streamBufferConfigure3 != null)
            {
                hr = streamBufferConfigure3.SetNamespace(null);
                DsError.ThrowExceptionForHR(hr);
            }

            // Set the TimeShifting configuration
            //hr = streamBufferConfigure.SetDirectory("C:\\MyDirectory");
            string directory     = Settings.VideosFolder;
            string directoryPath = FileUtils.GetAbsolutePath(directory as string);

            hr = streamBufferConfigure.SetDirectory(directoryPath);
            DsError.ThrowExceptionForHR(hr);


            hr = streamBufferConfigure.SetBackingFileDuration(600);             // Min 15 seconds
            //TODO not working anymore!!
            hr = streamBufferConfigure.SetBackingFileCount(
                Math.Min(100, Math.Max(4, Settings.TimeShiftingBufferLengthMin / 10)),  // 4-100
                Math.Min(102, Math.Max(6, Settings.TimeShiftingBufferLengthMax / 10))); // 6-102
        }