Пример #1
0
        private IBaseFilter GetCapFilter(ref DsDevice dev)
        {
            string s;

            dev.Mon.GetDisplayName(null, null, out s);
            return((IBaseFilter)Marshal.BindToMoniker(s));
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                int current_session_id = Process.GetCurrentProcess().SessionId;
                int new_session_id     = 0;
                Console.WriteLine("Waiting For a Target Session");
                while (true)
                {
                    IEnumerable <int> sessions = GetSessionIds().Where(id => id != current_session_id);
                    if (sessions.Count() > 0)
                    {
                        new_session_id = sessions.First();
                        break;
                    }
                    Thread.Sleep(1000);
                }

                Console.WriteLine("Creating Process in Session {0} after 20secs", new_session_id);
                Thread.Sleep(20000);
                IHxHelpPaneServer server = (IHxHelpPaneServer)Marshal.BindToMoniker(String.Format("session:{0}!new:8cec58ae-07a1-11d9-b15e-000d56bfe6ee", new_session_id));
                Uri target = new Uri(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "notepad.exe"));
                server.Execute(target.AbsoluteUri);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Get all running openSTAAD instances
        /// </summary>
        /// <returns>A dictionary containing all running openSTAAD instances</returns>
        static Dictionary <string, OpenSTAAD> GetAllRunningOpenStaadInstances()
        {
            var runningObjectsTable           = GetRunningObjectTable();
            var runningObjectsTableEnumerator = runningObjectsTable.GetEnumerator();

            var staadInstances = new Dictionary <string, OpenSTAAD>();

            while (runningObjectsTableEnumerator.MoveNext())
            {
                // check if its a valid STAAD file
                string candidateName = runningObjectsTableEnumerator.Key.ToString();

                if (Path.GetExtension(candidateName).Equals(".std", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Check is the candidate is actually an OpenSTAAD instance
                    var openStaad = Marshal.BindToMoniker(candidateName) as OpenSTAAD;

                    if (openStaad != null)
                    {
                        staadInstances.Add(candidateName, openStaad);
                    }
                }
            }

            return(staadInstances);
        }
Пример #4
0
        /// <summary>
        /// Ported from Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
        /// By JetBrains dotPeek decompiler
        /// </summary>
        private object GetCOMObjectInternal(string pathName = null, string className = null)
        {
            if (String.IsNullOrEmpty(className))
            {
                return(Marshal.BindToMoniker(pathName));
            }
            else if (pathName == null)
            {
#if NETSTANDARD2_0
                throw new NotSupportedException("Getting object by classname not supported on netstandard2");
#else
                return(Marshal.GetActiveObject(className));
#endif
            }
            else if (pathName.Length == 0)
            {
                return(Activator.CreateInstance(System.Type.GetTypeFromProgID(className)));
            }
            else
            {
#if NETSTANDARD2_0
                throw new NotSupportedException("Getting object by classname not supported on netstandard2");
#else
                var persistFile = (IPersistFile)Marshal.GetActiveObject(className);
                persistFile.Load(pathName, 0);

                return((object)persistFile);
#endif
            }
        }
Пример #5
0
        // Create the queued component, call it, and release it
        private void SendMsg_Click(object sender, System.EventArgs e)
        {
            IQComponent iQC;

            this.Cursor = Cursors.WaitCursor;

            try
            {
                // invoke an instance of our queued component using a queue moniker
                // this provides a client reference that's called into as if it were an actual
                // instance of the server component
                iQC = (IQComponent)Marshal.BindToMoniker("queue:/new:Microsoft.Samples.Technologies.ComponentServices.QueuedComponents.QComponent");

                // Call into the queued component. if we're not connected to an activated
                // server object, this will place a packaged message in the QCDemoSvr queue.
                iQC.DisplayMessage(msgToSend.Text);

                // appropriate method for releasing our queued component
                Marshal.ReleaseComObject(iQC);
            }

            catch (Exception ex)
            {
                MessageBox.Show("An exception was caught : " + ex.Message + "\nMake sure you installed MSMQ and runned REGSVCS.EXE as explained in the README of this sample!", "Error");
            }

            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }
Пример #6
0
        private static IEnumMediaTypes GetEnumMediaTypes()
        {
            IBaseFilter filter;
            int         hr;
            IPin        pRet = null;

            DsDevice [] capDevices;

            // Get the collection of video devices
            capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            if (capDevices.Length == 0)
            {
                throw new Exception("No video capture devices found!");
            }

            DsDevice dev = capDevices[0];
            string   s;

            dev.Mon.GetDisplayName(null, null, out s);
            filter = Marshal.BindToMoniker(s) as IBaseFilter;

            pRet = DsFindPin.ByDirection(filter, PinDirection.Output, 0);

            IEnumMediaTypes enumMediaTypes;

            hr = pRet.EnumMediaTypes(out enumMediaTypes);
            DsError.ThrowExceptionForHR(hr);

            return(enumMediaTypes);
        }
        // Find an video compression filter
        IAMVfwCompressDialogs GetCompressionFilter()
        {
            DsDevice []           capDevices;
            IAMVfwCompressDialogs ifcd = null;
            int    x;
            string s = "";

            // Get the collection of video devices
            capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoCompressorCategory);
            if (capDevices.Length == 0)
            {
                throw new Exception("No video compressors found!");
            }

            for (x = 0; x < capDevices.Length; x++)
            {
                DsDevice dev = capDevices[x];

                dev.Mon.GetDisplayName(null, null, out s);

                if (dev.Name == "Intel Indeo® Video 4.5") //"Microsoft Video 1")
                {
                    break;
                }
            }

            if (x >= capDevices.Length)
            {
                throw new Exception("can't find the video 1 filter");
            }

            ifcd = Marshal.BindToMoniker(s) as IAMVfwCompressDialogs;

            return(ifcd);
        }
Пример #8
0
        private void Configure()
        {
            string s;

            DsDevice[] dd = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            dd[0].Mon.GetDisplayName(null, null, out s);

            m_ks = Marshal.BindToMoniker(s) as IKsTopologyInfo;
        }
Пример #9
0
        public static IBaseFilter AddFilterToGraph(IGraphBuilder graphBuilder, FilterName filterName, string baseDir, Guid clsid)
        {
            if (String.IsNullOrEmpty(filterName.Name))
            {
                return(null);
            }

            try
            {
                IBaseFilter NewFilter = null;

                // use local lib
                if (!String.IsNullOrEmpty(filterName.Filename) && filterName.CLSID != Guid.Empty)
                {
                    string dllPath = Path.Combine(baseDir, filterName.Filename);
                    NewFilter = FilterFromFile.LoadFilterFromDll(dllPath, filterName.CLSID,
                                                                 !Path.IsPathRooted(dllPath));
                }

                // or try load from system
                if (NewFilter == null)
                {
                    foreach (Filter filter in Filters.LegacyFilters)
                    {
                        if (String.Compare(filter.Name, filterName.Name, true) == 0 &&
                            (clsid == Guid.Empty || filter.CLSID == clsid))
                        {
                            NewFilter = (IBaseFilter)Marshal.BindToMoniker(filter.MonikerString);
                        }
                    }
                }

                int hr = graphBuilder.AddFilter(NewFilter, filterName.Name);
                if (hr < 0)
                {
                    log.Error("Unable to add filter: {0} to graph", filterName);
                    NewFilter = null;
                }
                else
                {
                    log.Debug("Added filter: {0} to graph", filterName);
                }

                if (NewFilter == null)
                {
                    log.Error("Failed filter: {0} not found", filterName);
                }

                return(NewFilter);
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error adding filter: {0} to graph", filterName);
                return(null);
            }
        }
        static void Main(string[] args)
        {
            Excel.Workbook  MyWorkBook;
            Excel.Worksheet MyWorkSheet;
            string          FileName = @"C:\Cases\Test\bin\Debug\Mybook.xls";

            MyWorkBook  = (Excel.Workbook)Marshal.BindToMoniker(FileName);
            MyWorkSheet = (Excel.Worksheet)MyWorkBook.ActiveSheet;
            System.Windows.Forms.Application.Run();
        }
Пример #11
0
        void BuildGraph()
        {
            DsDevice [] devs;
            string      s;

            devs = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVAudio);
            DsDevice dev = devs[0];

            dev.Mon.GetDisplayName(null, null, out s);
            m_itva = Marshal.BindToMoniker(s) as IAMTVAudio;
        }
Пример #12
0
        void BuildGraph()
        {
            DsDevice [] devs;
            string      s;

            devs = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar);
            DsDevice dev = devs[0];

            dev.Mon.GetDisplayName(null, null, out s);
            m_ixbar = Marshal.BindToMoniker(s) as IAMCrossbar;
        }
Пример #13
0
        /// <summary>
        /// Erzeugt einen neuen Filter.
        /// </summary>
        /// <returns>Der gewünschte Filter.</returns>
        public static VMR Create()
        {
            // Create
            var instance = Marshal.BindToMoniker(VMRMoniker);

            try
            {
                // Report
                return(new VMR(instance));
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref instance);
            }
        }
Пример #14
0
        /// <summary>
        /// Erzeugt eine neue Referenz unter Angabe eines eindeutigen Namens.
        /// </summary>
        /// <typeparam name="T">Die Art des verwalteten Objektes.</typeparam>
        /// <param name="moniker">Der eindeutige Namen zum Objekt.</param>
        /// <returns>Die gewünschte Referenz.</returns>
        public static TypedComIdentity <T> Create <T>(string moniker) where T : class
        {
            // Create
            var instance = Marshal.BindToMoniker(moniker);

            try
            {
                // Report
                return(Create((T)instance));
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref instance);
            }
        }
Пример #15
0
        /*Connecting to Active Directory, searching for the current object's computerName property, determining if the AD computer object
         * has Bitlocker data associated with it, if Bitlocker data is present, the Bitlocker Recovery Key, Recovery Guid and Date are assigned to properties
         * of a BitlockerData object, that object is then returned to the calling function*/
        public BitlockerData getBitlockerInfo(ComputerInfo c)
        {
            BitlockerData bitlockerInfoObject = new BitlockerData();

            using (DirectoryEntry parent = new DirectoryEntry("LDAP://wcc.local:636"))
            {
                using (DirectorySearcher LdapSearcher = new DirectorySearcher(parent))
                {
                    LdapSearcher.Filter = string.Concat("(&(objectClass=computer)(name=", c.computerName, "))");
                    SearchResult srcComp = LdapSearcher.FindOne();
                    if (srcComp != null)
                    {
                        using (DirectoryEntry compEntry = srcComp.GetDirectoryEntry())
                        {
                            try
                            {
                                Object objValue = Marshal.BindToMoniker(srcComp.GetDirectoryEntry().Path.Replace("GC://", "LDAP://"));
                                Type   tType    = objValue.GetType();
                                tType.InvokeMember("Filter",
                                                   System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.Public, null,
                                                   objValue, new Object[] { "msFVE-RecoveryInformation" });
                                foreach (Object obj in (IEnumerable)objValue)
                                {
                                    Guid     gRecoveryGUID = new Guid((Byte[])obj.GetType().InvokeMember("msFVE-RecoveryGuid", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null));
                                    string   name          = obj.GetType().InvokeMember("name", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null).ToString();
                                    string   dateString    = name.Substring(3, name.IndexOf("T", System.StringComparison.Ordinal) - 3);
                                    DateTime date          = Convert.ToDateTime(dateString);
                                    string   dateOnly      = date.ToString().Substring(0, date.ToString().IndexOf(" "));
                                    string   time          = name.Substring(name.IndexOf("T", System.StringComparison.Ordinal) + 1, name.IndexOf("{", System.StringComparison.Ordinal) - 20);
                                    string   objTime       = DateTime.Parse(time).ToString("h:mm:ss tt");
                                    time = objTime;
                                    DateTime dateTime = Convert.ToDateTime(dateOnly + " " + time);
                                    if (gRecoveryGUID != null)
                                    {
                                        bitlockerInfoObject.recoveryGuid     = gRecoveryGUID.ToString().ToUpper();
                                        bitlockerInfoObject.recoveryPassword = obj.GetType().InvokeMember("msFVE-RecoveryPassword", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null).ToString();
                                        bitlockerInfoObject.date             = dateTime;
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
            return(bitlockerInfoObject);
        }
Пример #16
0
        // Find an audio filter
        IBaseFilter GetAudioFilter()
        {
            DsDevice [] capDevices;

            // Get the collection of video devices
            capDevices = DsDevice.GetDevicesOfCat(FilterCategory.AudioInputDevice);
            if (capDevices.Length == 0)
            {
                throw new Exception("No audio capture devices found!");
            }

            DsDevice dev = capDevices[0];
            string   s;

            dev.Mon.GetDisplayName(null, null, out s);
            return(Marshal.BindToMoniker(s) as IBaseFilter);
        }
Пример #17
0
        public static IBaseFilter AddFilterToGraph(IGraphBuilder graphBuilder, string strFilterName, Guid clsid)
        {
            if (string.IsNullOrEmpty(strFilterName))
            {
                return(null);
            }

            try
            {
                IBaseFilter NewFilter = null;
                foreach (Filter filter in Filters.LegacyFilters)
                {
                    if (String.Compare(filter.Name, strFilterName, true) == 0 && (clsid == Guid.Empty || filter.CLSID == clsid))
                    {
                        NewFilter = (IBaseFilter)Marshal.BindToMoniker(filter.MonikerString);

                        int hr = graphBuilder.AddFilter(NewFilter, strFilterName);
                        if (hr < 0)
                        {
                            log.Error("Unable to add filter: {0} to graph", strFilterName);
                            NewFilter = null;
                        }
                        else
                        {
                            log.Debug("Added filter: {0} to graph", strFilterName);
                        }
                        break;
                    }
                }
                if (NewFilter == null)
                {
                    log.Error("Failed filter: {0} not found", strFilterName);
                }
                return(NewFilter);
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error adding filter: {0} to graph", strFilterName);
                return(null);
            }
        }
Пример #18
0
        private void DoSetup()
        {
            DsDevice [] capDevices = DsDevice.GetDevicesOfCat(FilterCategory.LegacyAmFilterCategory);

            foreach (DsDevice dev in capDevices)
            {
                string s;

                dev.Mon.GetDisplayName(null, null, out s);

                try
                {
                    m_ica = Marshal.BindToMoniker(s) as ICodecAPI;
                    if (dev.Name == "Microsoft MPEG-1/DD Audio Decoder")
                    {
                        break;
                    }
                }
                catch { }
            }
        }
Пример #19
0
        /// <summary>
        /// Ported from Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
        /// By JetBrains dotPeek decompiler
        /// </summary>
        private object GetCOMObjectInternal(string pathName = null, string className = null)
        {
            if (String.IsNullOrEmpty(className))
            {
                return(Marshal.BindToMoniker(pathName));
            }
            else if (pathName == null)
            {
                return(Marshal.GetActiveObject(className));
            }
            else if (pathName.Length == 0)
            {
                return(Activator.CreateInstance(System.Type.GetTypeFromProgID(className)));
            }
            else
            {
                var persistFile = (IPersistFile)Marshal.GetActiveObject(className);
                persistFile.Load(pathName, 0);

                return((object)persistFile);
            }
        }
        public static object GetObject(object moniker, object progId)
        {
            moniker = Microsoft.JScript.Convert.ToPrimitive(moniker, PreferredType.Either);
            if (!(progId is Missing))
            {
                progId = Microsoft.JScript.Convert.ToPrimitive(progId, PreferredType.Either);
            }
            string monikerName = (Microsoft.JScript.Convert.GetTypeCode(moniker) == TypeCode.String) ? moniker.ToString() : null;
            string progID      = (Microsoft.JScript.Convert.GetTypeCode(progId) == TypeCode.String) ? progId.ToString() : null;

            if ((monikerName == null) || ((monikerName.Length == 0) && (progID == null)))
            {
                throw new JScriptException(JSError.TypeMismatch);
            }
            if ((progID == null) && !(progId is Missing))
            {
                throw new JScriptException(JSError.TypeMismatch);
            }
            if ((progID != null) && (progID.Length == 0))
            {
                throw new JScriptException(JSError.InvalidCall);
            }
            if ((progID == null) || (progID.Length == 0))
            {
                return(Marshal.BindToMoniker(monikerName));
            }
            if ((monikerName == null) || (monikerName.Length == 0))
            {
                return(Marshal.GetActiveObject(progID));
            }
            object obj2 = Activator.CreateInstance(Type.GetTypeFromProgID(progID));

            if (!(obj2 is UCOMIPersistFile))
            {
                throw new JScriptException(JSError.FileNotFound);
            }
            ((UCOMIPersistFile)obj2).Load(monikerName, 0);
            return(obj2);
        }
Пример #21
0
        public void Execute(string fullpath)
        {
            bool ContaainChinese = false;

            for (int i = 0; i < fullpath.Length; i++)
            {
                if (Regex.IsMatch(fullpath[i].ToString(), @"[\u4e00-\u9fbb]"))
                {
                    ContaainChinese = true;
                    break;
                }
            }
            if (Regex.IsMatch(fullpath, @"(.*)(\.exe)$") && ContaainChinese == false)
            {
                IHxHelpPaneServer server = (IHxHelpPaneServer)Marshal.BindToMoniker(String.Format("new:8cec58ae-07a1-11d9-b15e-000d56bfe6ee"));
                Uri target = new Uri(fullpath);
                server.Execute(target.AbsoluteUri);
            }
            else
            {
                Process.Start(fullpath);
            }
        }
Пример #22
0
        private void menuObjectBindMoniker_Click(object sender, EventArgs e)
        {
            using (GetTextForm frm = new GetTextForm(_last_moniker))
            {
                frm.Text = "Specify Moniker";
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        _last_moniker = frm.Data;
                        object comObj = Marshal.BindToMoniker(_last_moniker);

                        if (comObj != null)
                        {
                            OpenObjectInformation(comObj, _last_moniker);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Пример #23
0
        private bool AddWmAsfWriter(string fileName, Quality quality, Standard standard)
        {
            //add asf file writer
            IPin pinOut0, pinOut1;
            IPin pinIn0, pinIn1;

            Log.Info("DVRMS2WMV: add WM ASF Writer to graph");
            string monikerAsfWriter =
                @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{7C23220E-55BB-11D3-8B16-00C04FB6BD3D}";

            fileWriterbase = Marshal.BindToMoniker(monikerAsfWriter) as IBaseFilter;
            if (fileWriterbase == null)
            {
                Log.Error("DVRMS2WMV:FAILED:Unable to create ASF WM Writer");
                Cleanup();
                return(false);
            }

            int hr = graphBuilder.AddFilter(fileWriterbase, "WM ASF Writer");

            if (hr != 0)
            {
                Log.Error("DVRMS2WMV:FAILED:Add ASF WM Writer to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            IFileSinkFilter2 fileWriterFilter = fileWriterbase as IFileSinkFilter2;

            if (fileWriterFilter == null)
            {
                Log.Error("DVR2XVID:FAILED:Add unable to get IFileSinkFilter for filewriter");
                Cleanup();
                return(false);
            }
            hr = fileWriterFilter.SetFileName(fileName, null);
            hr = fileWriterFilter.SetMode(AMFileSinkFlags.OverWrite);
            Log.Info("DVRMS2WMV: connect audio/video codecs outputs -> ASF WM Writer");
            //connect output #0 of videocodec->asf writer pin 1
            //connect output #0 of audiocodec->asf writer pin 0
            pinOut0 = DsFindPin.ByDirection((IBaseFilter)Mpeg2AudioCodec, PinDirection.Output, 0);
            pinOut1 = DsFindPin.ByDirection((IBaseFilter)Mpeg2VideoCodec, PinDirection.Output, 0);
            if (pinOut0 == null || pinOut1 == null)
            {
                Log.Error("DVRMS2WMV:FAILED:unable to get outpins of video codec");
                Cleanup();
                return(false);
            }
            pinIn0 = DsFindPin.ByDirection(fileWriterbase, PinDirection.Input, 0);
            if (pinIn0 == null)
            {
                Log.Error("DVRMS2WMV:FAILED:unable to get pins of asf wm writer");
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut0, pinIn0);
            if (hr != 0)
            {
                Log.Error("DVRMS2WMV:FAILED:unable to connect audio pins :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinIn1 = DsFindPin.ByDirection(fileWriterbase, PinDirection.Input, 1);
            if (pinIn1 == null)
            {
                Log.Error("DVRMS2WMV:FAILED:unable to get pins of asf wm writer");
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut1, pinIn1);
            if (hr != 0)
            {
                Log.Error("DVRMS2WMV:FAILED:unable to connect video pins :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            IConfigAsfWriter   config          = fileWriterbase as IConfigAsfWriter;
            IWMProfileManager  profileManager  = null;
            IWMProfileManager2 profileManager2 = null;
            IWMProfile         profile         = null;

            hr = WMLib.WMCreateProfileManager(out profileManager);
            string strprofileType = "";

            switch (quality)
            {
            case Quality.HiDef:
                //hr = WMLib.WMCreateProfileManager(out profileManager);
                if (standard == Standard.Film)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPHiDef-FILM.prx");
                }
                if (standard == Standard.NTSC)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPHiDef-NTSC.prx");
                }
                if (standard == Standard.PAL)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPHiDef-PAL.prx");
                }
                Log.Info("DVRMS2WMV: set WMV HiDef quality profile {0}", strprofileType);
                break;

            case Quality.VeryHigh:
                if (standard == Standard.Film)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPVeryHigh-FILM.prx");
                }
                if (standard == Standard.NTSC)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPVeryHigh-NTSC.prx");
                }
                if (standard == Standard.PAL)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPVeryHigh-PAL.prx");
                }
                Log.Info("DVRMS2WMV: set WMV Very High quality profile {0}", strprofileType);
                break;

            case Quality.High:
                if (standard == Standard.Film)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPHigh-FILM.prx");
                }
                if (standard == Standard.NTSC)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPHigh-NTSC.prx");
                }
                if (standard == Standard.PAL)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPHigh-PAL.prx");
                }
                Log.Info("DVRMS2WMV: set WMV High quality profile {0}", strprofileType);
                break;

            case Quality.Medium:
                if (standard == Standard.Film)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPMedium-FILM.prx");
                }
                if (standard == Standard.NTSC)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPMedium-NTSC.prx");
                }
                if (standard == Standard.PAL)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPMedium-PAL.prx");
                }
                Log.Info("DVRMS2WMV: set WMV Medium quality profile {0}", strprofileType);
                break;

            case Quality.Low:
                if (standard == Standard.Film)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPLow-FILM.prx");
                }
                if (standard == Standard.NTSC)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPLow-NTSC.prx");
                }
                if (standard == Standard.PAL)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPLow-PAL.prx");
                }
                Log.Info("DVRMS2WMV: set WMV Low quality profile {0}", strprofileType);
                break;

            case Quality.Portable:
                if (standard == Standard.Film)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPPortable-FILM.prx");
                }
                if (standard == Standard.NTSC)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPPortable-NTSC.prx");
                }
                if (standard == Standard.PAL)
                {
                    strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPPortable-PAL.prx");
                }
                Log.Info("DVRMS2WMV: set WMV Portable quality profile {0}", strprofileType);
                break;

            case Quality.Custom:
                //load custom profile
                string customBitrate = "";
                //Adjust the parameters to suit the custom settings the user has selected.
                switch (bitrate)
                {
                case 0:
                    customBitrate = "100Kbs";
                    break;

                case 1:
                    customBitrate = "256Kbs";
                    break;

                case 2:
                    customBitrate = "384Kbs";
                    break;

                case 3:
                    customBitrate = "768Kbs";
                    break;

                case 4:
                    customBitrate = "1536Kbs";
                    break;

                case 5:
                    customBitrate = "3072Kbs";
                    break;

                case 6:
                    customBitrate = "5376Kbs";
                    break;
                }
                Log.Info("DVRMS2WMV: custom bitrate = {0}", customBitrate);
                //TODO: get fps values & frame size
                //TODO: adjust settings required
                //Call the SetCutomPorfile method to load the custom profile, adjust it's params from user settings & then save it.
                //SetCutomProfile(videoBitrate, audioBitrate, videoHeight, videoWidth, videoFps); //based on user inputs
                //We then reload it after as per other quality settings / profiles.
                strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPCustom.prx");
                Log.Info("DVRMS2WMV: set WMV Custom quality profile {0}", strprofileType);
                break;
            }
            //Loads profile from the above quality selection.
            using (StreamReader prx = new StreamReader(strprofileType))
            {
                String profileContents = prx.ReadToEnd();
                profileManager2 = profileManager as IWMProfileManager2;

                hr = profileManager2.LoadProfileByData(profileContents, out profile);
                if (hr != 0)
                {
                    Log.Info("DVRMS2WMV: get WMV profile - FAILED! {0}", hr);
                    Cleanup();
                    return(false);
                }
            }


            Log.Info("DVRMS2WMV: load profile - SUCCESS!");
            //configures the WM ASF Writer to the chosen profile
            hr = config.ConfigureFilterUsingProfile(profile);
            if (hr != 0)
            {
                Log.Info("DVRMS2WMV: configure profile - FAILED! {0}", hr);
                Cleanup();
                return(false);
            }
            Log.Info("DVRMS2WMV: configure profile - SUCCESS!");
            //TODO: Add DB recording information into WMV.

            //Release resorces
            if (profile != null)
            {
                Marshal.ReleaseComObject(profile);
                profile = null;
            }
            if (profileManager != null)
            {
                Marshal.ReleaseComObject(profileManager);
                profileManager = null;
            }
            return(true);
        }
Пример #24
0
        private bool AddCodecs(IGraphBuilder graphBuilder, TranscodeInfo info)
        {
            //TODO: Add de-interlacing probably by filter
            int hr;

            Log.Info("TSReader2MP4: add h264 video encoder to graph");
            //Lead H264 Encoder (4.0)
            string monikerH264 = @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{E2B7DF52-38C5-11D5-91F6-00104BDB8FF9}";

            h264Encoder = Marshal.BindToMoniker(monikerH264) as IBaseFilter;
            if (h264Encoder == null)
            {
                Log.Error("TSReader2MP4: FAILED: Unable to create h264 video encoder");
                Cleanup();
                return(false);
            }
            hr = graphBuilder.AddFilter(h264Encoder, "h264 video encoder");
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: h264 video encoder to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            Log.Info("TSReader2MP4: add aac audio encoder to graph");
            //Monograph AAC Encoder
            //string monikerAAC = @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{88F36DB6-D898-40B5-B409-466A0EECC26A}";
            //Lead AAC Encoder
            string monikerAAC = @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{E2B7DD70-38C5-11D5-91F6-00104BDB8FF9}";

            aacEncoder = Marshal.BindToMoniker(monikerAAC) as IBaseFilter;
            if (aacEncoder == null)
            {
                Log.Error("TSReader2MP4: FAILED: Unable to create aac audio encoder");
                Cleanup();
                return(false);
            }
            hr = graphBuilder.AddFilter(aacEncoder, "aac audio encoder");
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: Add aac audio encoder to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            // dump filter ????
            //add filewriter
            Log.Info("TSReader2MP4: add FileWriter to graph");
            string monikerFileWrite =
                @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{8596E5F0-0DA5-11D0-BD21-00A0C911CE86}";
            IBaseFilter fileWriterbase = Marshal.BindToMoniker(monikerFileWrite) as IBaseFilter;

            if (fileWriterbase == null)
            {
                Log.Error("TSReader2MP4: FAILED: Unable to create FileWriter");
                Cleanup();
                return(false);
            }
            fileWriterFilter = fileWriterbase as IFileSinkFilter2;
            if (fileWriterFilter == null)
            {
                Log.Error("TSReader2MP4: FAILED: Add unable to get IFileSinkFilter for filewriter");
                Cleanup();
                return(false);
            }

            hr = graphBuilder.AddFilter(fileWriterbase, "FileWriter");
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: Add FileWriter to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            //set output filename
            string outputFileName = System.IO.Path.ChangeExtension(info.file, ".mp4");

            Log.Info("TSReader2MP4: set output file to :{0}", outputFileName);
            hr = fileWriterFilter.SetFileName(outputFileName, null);
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: unable to set filename for filewriter :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            // add mp4 muxer
            Log.Info("TSReader2MP4: add MP4 Muxer to graph");
            //Lead ISO Multiplexer
            string monikermp4Muxer =
                @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{990D1978-E48D-43AF-B12D-24A7456EC89F}";

            mp4Muxer = Marshal.BindToMoniker(monikermp4Muxer) as IBaseFilter;
            if (mp4Muxer == null)
            {
                Log.Error("TSReader2MP4: FAILED: Unable to create MP4Mux");
                Cleanup();
                return(false);
            }
            hr = graphBuilder.AddFilter(mp4Muxer, "MP4Mux");
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: Add MP4Mux to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            //connect output of audio codec to aac encoder
            IPin pinOut, pinIn;

            Log.Info("TSReader2MP4: connect audio codec->aac encoder");
            pinIn = DsFindPin.ByDirection(aacEncoder, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input pin of aac encoder:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinOut = DsFindPin.ByDirection(AudioCodec, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get output pin of audio codec :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: unable to connect audio codec->aac encoder: 0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            //connect output of video codec to h264 encoder
            Log.Info("TSReader2MP4: connect video codec->h264 encoder");
            pinIn = DsFindPin.ByDirection(h264Encoder, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input pin of h264 encoder:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinOut = DsFindPin.ByDirection(VideoCodec, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get output pin of video codec :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: unable to connect video codec->h264 encoder :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            //connect output of aac encoder to pin#0 of mp4mux
            Log.Info("TSReader2MP4: connect aac encoder->mp4mux");
            pinOut = DsFindPin.ByDirection(aacEncoder, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input pin of aac encoder:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinIn = DsFindPin.ByDirection(mp4Muxer, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input pin#1 of mp4 muxer :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: unable to connect aac encoder->mp4mux: 0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            //connect output of h264 encoder to pin#1 of mp4mux
            Log.Info("TSReader2MP4: connect h264 encoder->mp4mux");
            pinOut = DsFindPin.ByDirection(h264Encoder, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input pin of h264 encoder :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinIn = DsFindPin.ByDirection(mp4Muxer, PinDirection.Input, 1);
            if (pinIn == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input#0 pin of mp4mux :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: unable to connect h264 encoder->mp4mux :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            // dump filter??
            //connect mp4 muxer out->filewriter
            Log.Info("TSReader2MP4: connect mp4mux->filewriter");
            pinOut = DsFindPin.ByDirection(mp4Muxer, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get output pin of avimux:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinIn = DsFindPin.ByDirection(fileWriterbase, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("TSReader2MP4: FAILED: cannot get input pin of filewriter :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("TSReader2MP4: FAILED: connect mp4 muxer->filewriter :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            return(true);
        }
Пример #25
0
        /// <summary>
        ///  Create a new filter graph and add filters (devices, compressors, misc),
        ///  but leave the filters unconnected. Call RenderGraph()
        ///  to connect the filters.
        /// </summary>
        protected void CreateGraph()
        {
            //Skip if already created
            if ((int)ActualGraphState < (int)GraphState.Created)
            {
                // Make a new filter graph
                GraphBuilder = (ExtendStreaming.IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(Uuid.Clsid.FilterGraph, true));

                // Get the Capture Graph Builder
                var clsid = Uuid.Clsid.CaptureGraphBuilder2;
                var riid  = typeof(ExtendStreaming.ICaptureGraphBuilder2).GUID;
                CaptureGraphBuilder = (ExtendStreaming.ICaptureGraphBuilder2)Workaround.CreateDsInstance(ref clsid, ref riid);

                // Link the CaptureGraphBuilder to the filter graph
                var hr = CaptureGraphBuilder.SetFiltergraph(GraphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                var comType = Type.GetTypeFromCLSID(Uuid.Clsid.SampleGrabber);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow SampleGrabber not installed/registered!");
                }
                var comObj = Activator.CreateInstance(comType);
                SampGrabber = (EditStreaming.ISampleGrabber)comObj; comObj = null;

                _baseGrabFlt = (CoreStreaming.IBaseFilter)SampGrabber;

                var media = new CoreStreaming.AMMediaType();
                // Get the video device and add it to the filter graph
                if (VideoDevice != null)
                {
                    VideoDeviceFilter = (CoreStreaming.IBaseFilter)Marshal.BindToMoniker(VideoDevice.MonikerString);

                    hr = GraphBuilder.AddFilter(VideoDeviceFilter, "Video Capture Device");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    media.majorType           = Uuid.MediaType.Video;
                    media.subType             = Uuid.MediaSubType.RGB32; //RGB24;
                    media.formatType          = Uuid.FormatType.VideoInfo;
                    media.temporalCompression = true;                    //New

                    hr = SampGrabber.SetMediaType(media);

                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    hr = GraphBuilder.AddFilter(_baseGrabFlt, "Grabber");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                // Retrieve the stream control interface for the video device
                // FindInterface will also add any required filters
                // (WDM devices in particular may need additional
                // upstream filters to function).

                // Try looking for an interleaved media type
                object o;
                var    cat = Uuid.PinCategory.Capture;
                var    med = Uuid.MediaType.Interleaved;
                var    iid = typeof(ExtendStreaming.IAMStreamConfig).GUID;
                hr = CaptureGraphBuilder.FindInterface(ref cat, ref med, VideoDeviceFilter, ref iid, out o);

                if (hr != 0)
                {
                    // If not found, try looking for a video media type
                    med = Uuid.MediaType.Video;
                    hr  = CaptureGraphBuilder.FindInterface(ref cat, ref med, VideoDeviceFilter, ref iid, out o);

                    if (hr != 0)
                    {
                        o = null;
                    }
                }

                VideoStreamConfig = o as ExtendStreaming.IAMStreamConfig;

                // Retreive the media control interface (for starting/stopping graph)
                MediaControl = (ControlStreaming.IMediaControl)GraphBuilder;

                // Reload any video crossbars
                //if (videoSources != null) videoSources.Dispose(); videoSources = null;

                _videoInfoHeader = (EditStreaming.VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(EditStreaming.VideoInfoHeader));
                Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;

                hr = SampGrabber.SetBufferSamples(false);
                if (hr == 0)
                {
                    hr = SampGrabber.SetOneShot(false);
                }
                if (hr == 0)
                {
                    hr = SampGrabber.SetCallback(null, 0);
                }
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // Update the state now that we are done
            ActualGraphState = GraphState.Created;
        }
Пример #26
0
 public void BindToMoniker_ThrowsNotSupportedException()
 {
     Assert.Throws <NotSupportedException>(() => Marshal.BindToMoniker("test"));
 }
Пример #27
0
        /// <summary>
        ///  Create a new filter graph and add filters (devices, compressors, misc),
        ///  but leave the filters unconnected. Call RenderGraph()
        ///  to connect the filters.
        /// </summary>
        void CreateGraph()
        {
            //Skip if already created
            if ((int)_actualGraphState < (int)GraphState.Created)
            {
                // Make a new filter graph
                _graphBuilder = (IGraphBuilder) new FilterGraph();

                // Get the Capture Graph Builder
                _captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                // Link the CaptureGraphBuilder to the filter graph
                var hr = _captureGraphBuilder.SetFiltergraph(_graphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                var comObj = new SampleGrabber();
                _sampGrabber = (ISampleGrabber)comObj;

                _baseGrabFlt = (IBaseFilter)_sampGrabber;

                var media = new AMMediaType();
                // Get the video device and add it to the filter graph
                if (VideoDevice != null)
                {
                    _videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(VideoDevice.MonikerString);

                    hr = _graphBuilder.AddFilter(_videoDeviceFilter, "Video Capture Device");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    media.majorType           = MediaType.Video;
                    media.subType             = MediaSubType.RGB32; //RGB24;
                    media.formatType          = FormatType.VideoInfo;
                    media.temporalCompression = true;               //New

                    hr = _sampGrabber.SetMediaType(media);

                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    hr = _graphBuilder.AddFilter(_baseGrabFlt, "Grabber");
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                // Retrieve the stream control interface for the video device
                // FindInterface will also add any required filters
                // (WDM devices in particular may need additional
                // upstream filters to function).

                // Try looking for an interleaved media type
                var cat = PinCategory.Capture;
                var med = MediaType.Interleaved;
                var iid = typeof(IAMStreamConfig).GUID;
                hr = _captureGraphBuilder.FindInterface(cat, med, _videoDeviceFilter, iid, out var o);

                if (hr != 0)
                {
                    // If not found, try looking for a video media type
                    med = MediaType.Video;
                    hr  = _captureGraphBuilder.FindInterface(cat, med, _videoDeviceFilter, iid, out o);

                    if (hr != 0)
                    {
                        // ReSharper disable once RedundantAssignment
                        o = null;
                    }
                }

                //VideoStreamConfig = o as IAMStreamConfig;

                // Retreive the media control interface (for starting/stopping graph)
                _mediaControl = (IMediaControl)_graphBuilder;

                // Reload any video crossbars
                //if (videoSources != null) videoSources.Dispose(); videoSources = null;

                _videoInfoHeader = Marshal.PtrToStructure <VideoInfoHeader>(media.formatPtr);
                Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;

                hr = _sampGrabber.SetBufferSamples(true);

                if (hr == 0)
                {
                    hr = _sampGrabber.SetOneShot(false);
                }

                if (hr == 0)
                {
                    hr = _sampGrabber.SetCallback(null, 0);
                }

                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // Update the state now that we are done
            _actualGraphState = GraphState.Created;
        }
Пример #28
0
        public bool Transcode(TranscodeInfo info, MediaPortal.Core.Transcoding.VideoFormat format,
                              MediaPortal.Core.Transcoding.Quality quality, Standard standard)
        {
            if (!Supports(format))
            {
                return(false);
            }
            string ext = System.IO.Path.GetExtension(info.file);

            if (ext.ToLower() != ".dvr-ms" && ext.ToLower() != ".sbe")
            {
                Log.Info("DVRMS2DIVX: wrong file format");
                return(false);
            }

            //disable xvid status window while encoding

            /*  try
             *                        {
             *                                using (RegistryKey subkey = Registry.CurrentUser.OpenSubKey(@"Software\GNU\XviD", true))
             *                                {
             *                                        if (subkey != null)
             *                                        {
             *                                                Int32 uivalue = 0;
             *                                                subkey.SetValue("display_status", (Int32)uivalue);
             *                                                subkey.SetValue("debug", (Int32)uivalue);
             *                                                subkey.SetValue("bitrate", (Int32)bitrate);
             *
             *                                                uivalue = 1;
             *                                                subkey.SetValue("interlacing", (Int32)uivalue);
             *                                        }
             *                                }
             *                        }
             *                        catch (Exception)
             *                        {
             *                        }*/
            //Type comtype = null;
            //object comobj = null;
            try
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();

                _rotEntry = new DsROTEntry((IFilterGraph)graphBuilder);

                Log.Info("DVRMS2DIVX: add filesource");
                bufferSource = (IStreamBufferSource) new StreamBufferSource();

                IBaseFilter filter = (IBaseFilter)bufferSource;
                graphBuilder.AddFilter(filter, "SBE SOURCE");
                IFileSourceFilter fileSource = (IFileSourceFilter)bufferSource;
                Log.Info("DVRMS2DIVX: load file:{0}", info.file);
                int hr = fileSource.Load(info.file, null);


                /*string strDemuxerMoniker = @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{AFB6C280-2C41-11D3-8A60-0000F81E0E4A}";
                 *
                 *                      mpegDemuxer = Marshal.BindToMoniker(strDemuxerMoniker) as IBaseFilter;
                 *                      if (mpegDemuxer == null)
                 *                      {
                 *                                      Log.Error("DVRMS2DIVX:FAILED:unable to add mpeg2 demuxer");
                 *                                      Cleanup();
                 *                                      return false;
                 *                      }
                 *                      hr = graphBuilder.AddFilter(mpegDemuxer, "MPEG-2 Demultiplexer");
                 *                      if (hr != 0)
                 *                      {
                 *                                      Log.Error("DVRMS2DIVX:FAILED:Add mpeg2 demuxer to filtergraph :0x{0:X}", hr);
                 *                                      Cleanup();
                 *                                      return false;
                 *                      }*/

                //add mpeg2 audio/video codecs
                string strVideoCodecMoniker =
                    @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{39F498AF-1A09-4275-B193-673B0BA3D478}";
                string strAudioCodec = "MPC - MPA Decoder Filter";
                Log.Info("DVRMS2DIVX: add MPV mpeg2 video decoder");
                Mpeg2VideoCodec = Marshal.BindToMoniker(strVideoCodecMoniker) as IBaseFilter;
                if (Mpeg2VideoCodec == null)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to add MPV mpeg2 video decoder");
                    Cleanup();
                    return(false);
                }
                hr = graphBuilder.AddFilter(Mpeg2VideoCodec, "MPC - MPEG-2 Video Decoder (Gabest)");
                if (hr != 0)
                {
                    Log.Error("DVRMS2DIVX:FAILED:Add MPV mpeg2 video  to filtergraph :0x{0:X}", hr);
                    Cleanup();
                    return(false);
                }

                Log.Info("DVRMS2DIVX: add MPA mpeg2 audio codec:{0}", strAudioCodec);
                Mpeg2AudioCodec = DirectShowUtil.AddFilterToGraph(graphBuilder, strAudioCodec);
                if (Mpeg2AudioCodec == null)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to add MPV mpeg2 audio codec");
                    Cleanup();
                    return(false);
                }

                //connect output #0 of streambuffer source->mpeg2 audio codec pin 1
                //connect output #1 of streambuffer source->mpeg2 video codec pin 1
                Log.Info("DVRMS2DIVX: connect streambufer source->mpeg audio/video decoders");
                IPin pinOut0, pinOut1;
                IPin pinIn0, pinIn1;
                pinOut0 = DsFindPin.ByDirection((IBaseFilter)bufferSource, PinDirection.Output, 0); //audio
                pinOut1 = DsFindPin.ByDirection((IBaseFilter)bufferSource, PinDirection.Output, 1); //video
                if (pinOut0 == null || pinOut1 == null)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to get pins of source");
                    Cleanup();
                    return(false);
                }

                pinIn0 = DsFindPin.ByDirection(Mpeg2VideoCodec, PinDirection.Input, 0); //video
                pinIn1 = DsFindPin.ByDirection(Mpeg2AudioCodec, PinDirection.Input, 0); //audio
                if (pinIn0 == null || pinIn1 == null)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to get pins of mpeg2 video/audio codec");
                    Cleanup();
                    return(false);
                }

                hr = graphBuilder.Connect(pinOut0, pinIn1);
                if (hr != 0)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to connect audio pins :0x{0:X}", hr);
                    Cleanup();
                    return(false);
                }


                hr = graphBuilder.Connect(pinOut1, pinIn0);
                if (hr != 0)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to connect video pins :0x{0:X}", hr);
                    Cleanup();
                    return(false);
                }
                if (!AddCodecs(graphBuilder, info))
                {
                    return(false);
                }

                //				hr=(graphBuilder as IMediaFilter).SetSyncSource(null);
                //				if (hr!=0)
                //					Log.Error("DVRMS2DIVX:FAILED:to SetSyncSource :0x{0:X}",hr);
                mediaControl = graphBuilder as IMediaControl;
                mediaSeeking = bufferSource as IStreamBufferMediaSeeking;
                mediaEvt     = graphBuilder as IMediaEventEx;
                mediaPos     = graphBuilder as IMediaPosition;

                //get file duration
                Log.Info("DVRMS2DIVX: Get duration of movie");
                long lTime = 5 * 60 * 60;
                lTime *= 10000000;
                long pStop = 0;
                hr = mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
                                               AMSeekingSeekingFlags.NoPositioning);
                if (hr == 0)
                {
                    long lStreamPos;
                    mediaSeeking.GetCurrentPosition(out lStreamPos); // stream position
                    m_dDuration = lStreamPos;
                    lTime       = 0;
                    mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
                                              AMSeekingSeekingFlags.NoPositioning);
                }
                double duration = m_dDuration / 10000000d;
                Log.Info("DVRMS2DIVX: movie duration:{0}", MediaPortal.Util.Utils.SecondsToHMSString((int)duration));

                //				hr=(graphBuilder as IMediaFilter).SetSyncSource(null);
                //				if (hr!=0)
                //					Log.Error("DVRMS2DIVX:FAILED:to SetSyncSource :0x{0:X}",hr);
                hr = mediaControl.Run();
                if (hr != 0)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to start graph :0x{0:X}", hr);
                    Cleanup();
                    return(false);
                }
                int maxCount = 20;
                while (true)
                {
                    long lCurrent;
                    mediaSeeking.GetCurrentPosition(out lCurrent);
                    double dpos = (double)lCurrent;
                    dpos /= 10000000d;
                    System.Threading.Thread.Sleep(100);
                    if (dpos >= 2.0d)
                    {
                        break;
                    }
                    maxCount--;
                    if (maxCount <= 0)
                    {
                        break;
                    }
                }

                mediaControl.Stop();
                FilterState state;
                mediaControl.GetState(500, out state);
                GC.Collect();
                GC.Collect();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                graphBuilder.RemoveFilter(aviMuxer);
                graphBuilder.RemoveFilter(divxCodec);
                graphBuilder.RemoveFilter(mp3Codec);
                graphBuilder.RemoveFilter((IBaseFilter)fileWriterFilter);
                if (!AddCodecs(graphBuilder, info))
                {
                    return(false);
                }

                //				hr=(graphBuilder as IMediaFilter).SetSyncSource(null);
                //			if (hr!=0)
                //					Log.Error("DVRMS2DIVX:FAILED:to SetSyncSource :0x{0:X}",hr);

                Log.Info("DVRMS2DIVX: start transcoding");
                hr = mediaControl.Run();
                if (hr != 0)
                {
                    Log.Error("DVRMS2DIVX:FAILED:unable to start graph :0x{0:X}", hr);
                    Cleanup();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log.Error("DVRMS2DIVX:Unable create graph: {0}", ex.Message);
                Cleanup();
                return(false);
            }
            return(true);
        }
Пример #29
0
        private bool AddCodecs(IGraphBuilder graphBuilder, TranscodeInfo info)
        {
            int hr;

            Log.Info("DVRMS2DIVX: add ffdshow (Divx) codec to graph");
            string monikerXVID = @"@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\ffdshow video encoder";

            divxCodec = Marshal.BindToMoniker(monikerXVID) as IBaseFilter;
            if (divxCodec == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:Unable to create Divx MPEG-4 Codec");
                Cleanup();
                return(false);
            }

            hr = graphBuilder.AddFilter(divxCodec, "ffdshow video encoder");
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:Add DivX MPEG-4 Codec to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }


            Log.Info("DVRMS2DIVX: add MPEG3 codec to graph");
            string monikerMPEG3 = @"@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\85MPEG Layer-3";

            mp3Codec = Marshal.BindToMoniker(monikerMPEG3) as IBaseFilter;
            if (mp3Codec == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:Unable to create MPEG Layer-3 Codec");
                Cleanup();
                return(false);
            }

            hr = graphBuilder.AddFilter(mp3Codec, "MPEG Layer-3");
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:Add MPEG Layer-3 to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            //add filewriter
            Log.Info("DVRMS2DIVX: add FileWriter to graph");
            string monikerFileWrite =
                @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{8596E5F0-0DA5-11D0-BD21-00A0C911CE86}";
            IBaseFilter fileWriterbase = Marshal.BindToMoniker(monikerFileWrite) as IBaseFilter;

            if (fileWriterbase == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:Unable to create FileWriter");
                Cleanup();
                return(false);
            }


            fileWriterFilter = fileWriterbase as IFileSinkFilter2;
            if (fileWriterFilter == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:Add unable to get IFileSinkFilter for filewriter");
                Cleanup();
                return(false);
            }

            hr = graphBuilder.AddFilter(fileWriterbase, "FileWriter");
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:Add FileWriter to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }


            //set output filename
            //AMMediaType mt = new AMMediaType();
            string outputFileName = System.IO.Path.ChangeExtension(info.file, ".avi");

            Log.Info("DVRMS2DIVX: set output file to :{0}", outputFileName);
            hr = fileWriterFilter.SetFileName(outputFileName, null);
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:unable to set filename for filewriter :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            // add avi muxer
            Log.Info("DVRMS2DIVX: add AVI Muxer to graph");
            string monikerAviMuxer =
                @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{E2510970-F137-11CE-8B67-00AA00A3F1A6}";

            aviMuxer = Marshal.BindToMoniker(monikerAviMuxer) as IBaseFilter;
            if (aviMuxer == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:Unable to create AviMux");
                Cleanup();
                return(false);
            }


            hr = graphBuilder.AddFilter(aviMuxer, "AviMux");
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:Add AviMux to filtergraph :0x{0:X}", hr);
                Cleanup();
                return(false);
            }


            //connect output of mpeg2 codec to xvid codec
            Log.Info("DVRMS2DIVX: connect mpeg2 video codec->divx codec");
            IPin pinOut, pinIn;

            pinIn = DsFindPin.ByDirection(divxCodec, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get input pin of divx codec:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinOut = DsFindPin.ByDirection(Mpeg2VideoCodec, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get output pin of mpeg2 video codec :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:unable to connect mpeg2 video codec->divx:0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            //connect output of mpeg2 audio codec to mpeg3 codec
            Log.Info("DVRMS2DIVX: connect mpeg2 audio codec->mp3 codec");
            pinIn = DsFindPin.ByDirection(mp3Codec, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get input pin of mp3 codec:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinOut = DsFindPin.ByDirection(Mpeg2AudioCodec, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get output pin of mpeg2 audio codec :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:unable to connect mpeg2 audio codec->mpeg3:0x{0:X}", hr);
                Cleanup();
                return(false);
            }


            //connect output of mpeg3 codec to pin#0 of avimux
            Log.Info("DVRMS2DIVX: connect mp3 codec->avimux");
            pinOut = DsFindPin.ByDirection(mp3Codec, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get input pin of mp3 codec:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinIn = DsFindPin.ByDirection(aviMuxer, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get output pin of mpeg2 audio codec :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:unable to connect mpeg3 codec->avimux:0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            //connect output of xvid codec to pin#1 of avimux
            Log.Info("DVRMS2DIVX: connect divx codec->avimux");
            pinOut = DsFindPin.ByDirection(divxCodec, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get input pin of mp3 codec:0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            pinIn = DsFindPin.ByDirection(aviMuxer, PinDirection.Input, 1);
            if (pinIn == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get output#1 pin of avimux :0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:unable to connect divx codec->avimux:0x{0:X}", hr);
                Cleanup();
                return(false);
            }


            //connect avi mux out->filewriter in
            Log.Info("DVRMS2DIVX: connect avimux->filewriter");
            pinOut = DsFindPin.ByDirection(aviMuxer, PinDirection.Output, 0);
            if (pinOut == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get output pin of avimux:0x{0:X}", hr);
                Cleanup();
                return(false);
            }

            pinIn = DsFindPin.ByDirection(fileWriterbase, PinDirection.Input, 0);
            if (pinIn == null)
            {
                Log.Error("DVRMS2DIVX:FAILED:cannot get input pin of Filewriter :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            hr = graphBuilder.Connect(pinOut, pinIn);
            if (hr != 0)
            {
                Log.Error("DVRMS2DIVX:FAILED:connect muxer->filewriter :0x{0:X}", hr);
                Cleanup();
                return(false);
            }
            return(true);
        }
Пример #30
0
        // ----------------------------------------------------------------------------------------------------
        // Post-Processing Operations
        // ----------------------------------------------------------------------------------------------------
        // protected override void EndProcessing() { }


        // ----------------------------------------------------------------------------------------------------
        // Static Method(s)
        // ----------------------------------------------------------------------------------------------------

        // Active Configuration Name
        protected static string GetDTEActiveConfigurationNameBySolutionFile(string path) => ((dynamic)Marshal.BindToMoniker(path)).SolutionBuild.ActiveConfiguration.Name;