Esempio n. 1
0
        /// <summary>
        /// Configs the asf.
        /// </summary>
        /// <param name="capGraph">The cap graph.</param>
        /// <param name="szOutputFileName">Name of the sz output file.</param>
        /// <returns></returns>
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szOutputFileName)
        {
            IBaseFilter       asfWriter        = null;
            IFileSinkFilter   pTmpSink         = null;
            IWMProfileManager ppProfileManager = null;
            IWMProfile        ppProfile        = null;

            try
            {
                WindowsMediaLib.WMUtils.WMCreateProfileManager(out ppProfileManager);
                string prx = File.ReadAllText(Path.Combine(Path.GetDirectoryName(
                                                               Assembly.GetEntryAssembly().Location), "profile.prx"));
                ppProfileManager.LoadProfileByData(prx, out ppProfile);

                int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);
                Marshal.ThrowExceptionForHR(hr);

                WindowsMediaLib.IConfigAsfWriter lConfig = asfWriter as WindowsMediaLib.IConfigAsfWriter;
                lConfig.ConfigureFilterUsingProfile(ppProfile);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
                Marshal.ReleaseComObject(ppProfile);
                Marshal.ReleaseComObject(ppProfileManager);
            }

            return(asfWriter);
        }
Esempio n. 2
0
        IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szFileName)
        {
            int hr;

            IBaseFilter     asfWriter = null;
            IFileSinkFilter pTmpSink  = null;

            // You *must* set an output file name.  Even though it never gets used
            hr = capGraph.SetOutputFileName(MediaSubType.Asf, szFileName, out asfWriter, out pTmpSink);
            DsError.ThrowExceptionForHR(hr);

            try
            {
                WindowsMediaLib.IConfigAsfWriter lConfig = asfWriter as WindowsMediaLib.IConfigAsfWriter;

                // Use one of the pre-defined system profiles.  I picked one with mucho
                // compression and no audio streams

                // Windows Media Video 8 for Dial-up Modem (No audio, 56 Kbps)
                Guid cat = new Guid(0x6E2A6955, 0x81DF, 0x4943, 0xBA, 0x50, 0x68, 0xA9, 0x86, 0xA7, 0x08, 0xF6);

                lConfig.ConfigureFilterUsingProfileGuid(cat);
            }
            finally
            {
                if (pTmpSink != null)
                {
                    Marshal.ReleaseComObject(pTmpSink);
                    pTmpSink = null;
                }
            }

            return(asfWriter);
        }
Esempio n. 3
0
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph,
                                      string szOutputFileName,
                                      CaptureOptions.VideoCompression quality)
        {
            IFileSinkFilter pTmpSink  = null;
            IBaseFilter     asfWriter = null;

            int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);

            Marshal.ThrowExceptionForHR(hr);

            try
            {
                IConfigAsfWriter lConfig = (IConfigAsfWriter)asfWriter;

                string profileData;
                int    bitRate;
                switch (quality)
                {
                case CaptureOptions.VideoCompression.MinimalSize:
                    bitRate = (int)(1000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                case CaptureOptions.VideoCompression.Optimal:
                    bitRate = (int)(2000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                case CaptureOptions.VideoCompression.BestQuality:
                    bitRate = (int)(4000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                default:
                    throw new ApplicationException("Internal error: unknown type of the required video codec");
                }

                //Getting XML with profile.
                using (var reader = new StreamReader(Path.Combine(Directories.GetConfigDirectory(), "Encoder.prx")))
                {
                    profileData = reader.ReadToEnd();
                }
                profileData = profileData.Replace("__FRAME_WIDTH__", _inFrameWidth.ToString());
                profileData = profileData.Replace("__FRAME_HEIGHT__", _inFrameHeight.ToString());
                profileData = profileData.Replace("__BIT_RATE__", bitRate.ToString());

                // Get manager
                IWMProfileManager profileManager;
                WMUtils.WMCreateProfileManager(out profileManager);

                // Create profile
                IWMProfile profile;
                profileManager.LoadProfileByData(profileData, out profile);
                lConfig.ConfigureFilterUsingProfile(profile);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
            }

            return(asfWriter);
        }
Esempio n. 4
0
        /// <summary>
        /// Configures the WM ASF Writer filter. (populates member variables as well)
        /// </summary>
        protected void ConfigureWriterFilter()
        {
            IWMProfile profile = GetWMProfile(CurrentProfile);

            WindowsMediaLib.IConfigAsfWriter configAsf = (WindowsMediaLib.IConfigAsfWriter)_asfFilter;
            configAsf.ConfigureFilterUsingProfile(profile);

            //Retreive the IWMWriter* objects from the WM ASF Writer filter.
            _writerAdvanced = GetWriterAdvanced();
            _writer         = (IWMWriter)_writerAdvanced;

            //The WM ASF Writer comes with a File-Writer-Sink, which we need to remove.
            RemoveAllSinks(_writerAdvanced);

            //set SourceConfig settings
            _writerAdvanced.SetSyncTolerance(SourceConfig.SyncToleranceMilliseconds);

            _writerAdvanced.SetLiveSource(SourceConfig.LiveSource);
        }
Esempio n. 5
0
        void ConfigureASFWriter(WMAsfWriter asf_filter, WTVStreamingVideoRequest strq, FrameSize SourceFrameSize)
        {
            int hr;

            // Now it's added to the graph, configure it with the selected WM Profile
            SendDebugMessage("Getting WM profile with quality of " + strq.Quality.ToString(), 0);
            WindowsMediaLib.IWMProfileManager profileManager;
            WMUtils.WMCreateProfileManager(out profileManager);
            IWMProfile wmProfile;
            string     txtPrxProfile = getPRXProfileForQuality(strq.Quality);

            if (!(string.IsNullOrEmpty(txtPrxProfile)))
            {
                SendDebugMessage("Adjusting WM profile to fit video within designated frame size", 0);
                // SET VIDEO SIZE TO FIT WITHIN THE RIGHT FRAME
                SendDebugMessage("Source video size is " + SourceFrameSize.ToString(), 0);
                FrameSize containerSize = frameSizeForStreamRequest(strq);
                SendDebugMessage("Container size is " + containerSize.ToString(), 0);
                FrameSize newVideoSize = new FrameSize(SourceFrameSize, containerSize);
                SendDebugMessage("Output size is " + newVideoSize.ToString(), 0);
                SetProfileFrameSize(ref txtPrxProfile, newVideoSize);
                SetProfileCustomSettings(ref txtPrxProfile, ref strq); // returns immediately if not custom quality
                SendDebugMessage("Configuring ASF Writer with profile", 0);
                profileManager.LoadProfileByData(txtPrxProfile, out wmProfile);
                WindowsMediaLib.IConfigAsfWriter configWriter = (WindowsMediaLib.IConfigAsfWriter)asf_filter;
                configWriter.ConfigureFilterUsingProfile(wmProfile);
                configWriter.SetIndexMode(true);  // yes index - DEFAULT

                /* Additional config  - TEST
                 * //DirectShowLib.IConfigAsfWriter2 configAsfWriter2 = (DirectShowLib.IConfigAsfWriter2)asf_filter;
                 * //configAsfWriter2.SetParam(ASFWriterConfig.AutoIndex, 0, 0);  // IT IS DEFAULT */



                // (NOT WORKING)
                // SET ANAMORPHIC VIDEO MARKERS WITHIN STREAM (ASPECT RATIO) *******************************
                UInt32 uiAspectX = (UInt32)SourceFrameSize.Width;
                byte[] bAspectX  = BitConverter.GetBytes(uiAspectX);
                UInt32 uiAspectY = (UInt32)SourceFrameSize.Height;
                byte[] bAspectY  = BitConverter.GetBytes(uiAspectY);

                DirectShowLib.IServiceProvider pServiceProvider;  // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx
                pServiceProvider = (DirectShowLib.IServiceProvider)asf_filter;
                DsGuid dsgIWMHeaderinfo = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o3 = null;
                hr = pServiceProvider.QueryService(dsgIWMHeaderinfo, dsgIWMHeaderinfo, out o3);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo headerinfo = (IWMHeaderInfo)o3;

                // Get access to WMwriterAdvanced2 object using pServiceProvider  (poss not futureproof)  (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af )
                DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o = null;
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMWriterAdvanced2 WMWriterAdvanced2 = null;
                WMWriterAdvanced2 = (IWMWriterAdvanced2)o;

                // Get Access to IWMHeaderInfo3 through WMWriterAdvanced2
                object o2 = null;
                //pServiceProvider = (DirectShowLib.IServiceProvider)WMWriterAdvanced2;
                DsGuid dsgIWMHeaderInfo3 = DsGuid.FromGuid(new Guid(GUIDs.IWMHeaderInfo3));
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgIWMHeaderInfo3, out o2); // LET'S SEE
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo3 WMHeaderInfo3 = null;
                WMHeaderInfo3 = (IWMHeaderInfo3)o2;
                short pwIndex;

                // Add Aspect Ratio information
                WMHeaderInfo3.AddAttribute(2, "AspectRatioX", out pwIndex, AttrDataType.DWORD, 0, bAspectX, bAspectX.Length);
                WMHeaderInfo3.AddAttribute(2, "AspectRatioY", out pwIndex, AttrDataType.DWORD, 0, bAspectY, bAspectY.Length);

                // Try with other interface too
                headerinfo.SetAttribute(2, "AspectRatioX", AttrDataType.DWORD, bAspectX, Convert.ToInt16(bAspectX.Length));
                headerinfo.SetAttribute(2, "AspectRatioY", AttrDataType.DWORD, bAspectY, Convert.ToInt16(bAspectY.Length));



                // ************ DEINTERLACE (experimental)
                if (strq.DeInterlaceMode > 0)
                {
                    DeInterlaceModes dimode = DeInterlaceModes.WM_DM_NOTINTERLACED;
                    // Deinterlace Mode
                    if (strq.DeInterlaceMode == 1)
                    {
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_NORMAL;
                    }
                    else if (strq.DeInterlaceMode == 2)
                    {
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_HALFSIZE;
                    }

                    // Index of video pin
                    int pinIndex = FilterGraphTools.FindPinIndexByMediaType(currentOutputFilter, PinDirection.Input, MediaType.Video, MediaSubType.Null);



                    byte[] bDiMode = BitConverter.GetBytes((int)dimode);
                    short  szOf    = (short)bDiMode.Length;

                    // Set to use deinterlace mode
                    try
                    {
                        WMWriterAdvanced2.SetInputSetting(pinIndex, g_wszDeinterlaceMode, AttrDataType.DWORD, bDiMode, szOf);
                    }
                    catch (Exception ex)
                    {
                        SendDebugMessageWithException("Could not set interlace mode:", ex);
                    }
                }
            }
            else
            {
                SendDebugMessage("Warning - PRX Profile string was empty; using default WM config.");
            }
        }