コード例 #1
0
ファイル: CAudioPlay.cs プロジェクト: gchudov/WindowsMediaLib
        /// <summary>
        /// Open the file that contains the audio
        /// </summary>
        /// <param name="pwszUrl"></param>
        public void Open(string pwszUrl)
        {
            // Check that the parameter is not NULL and that the reader is initialized.
            if (null == pwszUrl)
            {
                throw new COMException("null url", E_InvalidArgument);
            }

            if (IsDisposed())
            {
                throw new COMException("Instance has been Disposed", E_Unexpected);
            }

            try
            {
                // Close previously opened file, if any.
                Close();
            }
            catch { }

            m_hAsyncEvent.Reset();

            // Open the file with the reader object. This method call also sets
            //  the status callback that the reader will use.
            m_pReader.Open(pwszUrl, this, IntPtr.Zero);

            // Wait for the Open call to complete. The event is set in the OnStatus
            //  callback when the reader reports completion.
            m_hAsyncEvent.WaitOne();

            // Check the HRESULT reported by the reader object to the OnStatus
            //  callback. Most errors in opening files will be reported this way.
            if (Failed(m_hrAsync))
            {
                throw new COMException("Could not open the specified file", m_hrAsync);
            }

            try
            {
                m_pHeaderInfo = (IWMHeaderInfo)m_pReader;

                // Get Seekable, Broadcast & Duration
                RetrieveAttributes();

                // Set the audio ouput number for the current file.
                // Only the first audio output is retrieved, regardless of the
                //  number of audio outputs in the file.
                GetAudioOutput();
            }
            catch
            {
                try
                {
                    Close();
                }
                catch { }
                throw;
            }
        }
コード例 #2
0
        private void Config()
        {
            IWMMetadataEditor pEditor;

            WMUtils.WMCreateEditor(out pEditor);
            pEditor.Open(sFileName);
            m_head = (IWMHeaderInfo)pEditor;
        }
コード例 #3
0
ファイル: WMProp.cs プロジェクト: gchudov/WindowsMediaLib
        // Use IWMMetadataEditor interface to access
        // StreamNumber attribute
        ///////////////////////////////////////////////////////////////////////////////
        void GetBoolAttribsFromEditor(IWMHeaderInfo pHeaderInfo, string pwszName, out bool pResult)
        {
            AttrDataType wmType;
            short        wStreamNum = 0;
            short        cbLen      = 0;

            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, null, ref cbLen);

            byte[] pData = new byte[cbLen];
            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, pData, ref cbLen);

            pResult = BitConverter.ToBoolean(pData, 0);
        }
コード例 #4
0
ファイル: WMVCopy.cs プロジェクト: gchudov/WindowsMediaLib
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::CopyScriptInList()
        // Desc: Copies scripts in m_ScriptList to the header of the writer.
        //------------------------------------------------------------------------------
        protected void CopyScriptInList(string pwszOutputFile)
        {
            IWMMetadataEditor pEditor           = null;
            IWMHeaderInfo     pWriterHeaderInfo = null;

            //
            // Scripts can be added by the metadata editor.
            // Create an editor
            //
            WMUtils.WMCreateEditor(out pEditor);

            try
            {
                //
                // Open the output using the editor
                //
                pEditor.Open(pwszOutputFile);

                pWriterHeaderInfo = pEditor as IWMHeaderInfo;

                foreach (CScript pScript in m_ScriptList)
                {
                    //
                    // Add the script to the writer
                    //
                    pWriterHeaderInfo.AddScript(pScript.m_pwszType,
                                                pScript.m_pwszParameter,
                                                pScript.m_cnsTime);
                }

                //
                // Close and release the editor
                //
                pEditor.Flush();

                pEditor.Close();
            }
            finally
            {
                Marshal.ReleaseComObject(pEditor);
            }
        }
コード例 #5
0
ファイル: WMVCopy.cs プロジェクト: gchudov/WindowsMediaLib
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::CreateWriter()
        // Desc: Creates a writer and sets the profile and output of this writer.
        //------------------------------------------------------------------------------
        protected void CreateWriter(string pwszOutputFile)
        {
            int dwInputCount = 0;

            Console.WriteLine("Creating the Writer...");

            //
            // Create a writer
            //
            WMUtils.WMCreateWriter(IntPtr.Zero, out m_pWriter);

            //
            // Get the IWMWriterAdvanced interface of the writer
            //
            m_pWriterAdvanced = m_pWriter as IWMWriterAdvanced;

            //
            // Get the IWMHeaderInfo interface of the writer
            //
            m_pWriterHeaderInfo = m_pWriter as IWMHeaderInfo;

            //
            // Set the profile of the writer to the reader's profile
            //
            m_pWriter.SetProfile(m_pReaderProfile);

            m_pWriter.GetInputCount(out dwInputCount);

            //
            // Set the input property to null so the SDK knows we're going to
            // send compressed samples to the inputs of the writer.
            //
            for (int i = 0; i < dwInputCount; i++)
            {
                m_pWriter.SetInputProps(i, null);
            }

            //
            // Set the output file of the writer
            //
            m_pWriter.SetOutputFilename(pwszOutputFile);
        }
コード例 #6
0
ファイル: CAudioPlay.cs プロジェクト: gchudov/WindowsMediaLib
        public void Dispose()
        {
            try
            {
                Close();
            }
            catch { }
            if (!IsDisposed())
            {
                Marshal.ReleaseComObject(m_pReader);
                m_pReader     = null;
                m_pHeaderInfo = null;
            }

            if (IntPtr.Zero != m_hWaveOut)
            {
                waveOut.Close(m_hWaveOut); // Ignore return
                m_hWaveOut = IntPtr.Zero;
            }

            if (IntPtr.Zero != m_hMixer)
            {
                Mixer.Close(m_hMixer);
                m_hMixer = IntPtr.Zero;
            }

            if (null != m_hAsyncEvent)
            {
                m_hAsyncEvent.Close();
                m_hAsyncEvent = null;
            }

            m_pWfx = null;
#if SUPPORT_DRM
            objDRM.Dispose();
            m_pwszURL = null;
#endif
        }
コード例 #7
0
ファイル: CAudioPlay.cs プロジェクト: gchudov/WindowsMediaLib
        /// <summary>
        /// Create the player
        /// </summary>
        /// <param name="iDevice">Zero based index of the playback device.  See GetDevs for a list of devices.</param>
        public CAudioPlay(int iDevice, Form fForm)
        {
            m_DeviceIndex = iDevice;
            m_fForm       = fForm;

            WaveOutCaps woc = new WaveOutCaps();
            int         mmr = waveOut.GetDevCaps(iDevice, woc, Marshal.SizeOf(woc));

            waveOut.ThrowExceptionForError(mmr);

            m_WaveCaps = woc.dwSupport;

            m_bIsSeekable      = false;
            m_bIsBroadcast     = false;
            m_dwAudioOutputNum = -1;
            m_hrAsync          = 0;
            m_hWaveOut         = IntPtr.Zero;
            m_hMixer           = IntPtr.Zero;
            m_pReader          = null;
            m_pHeaderInfo      = null;
            m_cnsFileDuration  = 0;
            m_pWfx             = null;
            m_MaxSampleSize    = -1;
            m_OldTime          = -1;
            m_UseNext          = 0;
            m_InsBuf           = new INSBuf[MAXBUFFERS];

            // Create an event for asynchronous calls.
            // When code in this class makes a call to an asynchronous
            //  method, it will wait for the event to be set to resume
            //  processing.
            m_hAsyncEvent = new AutoResetEvent(false);

            // Create a reader object, requesting only playback rights.
            WMUtils.WMCreateReader(IntPtr.Zero, Rights.Playback, out m_pReader);
        }
コード例 #8
0
 /// <summary>
 /// WMHeaderInfo constructor
 /// </summary>
 /// <param name="headinfo">IWMHeaderInfo to wrap</param>
 public WMHeaderInfo(IWMHeaderInfo headinfo)
 {
     m_HeaderInfo = headinfo;
 }
コード例 #9
0
ファイル: WMHeaderInfo.cs プロジェクト: 4dvn/yeti
 /// <summary>
 /// WMHeaderInfo constructor
 /// </summary>
 /// <param name="headinfo">IWMHeaderInfo to wrap</param>
 public WMHeaderInfo(IWMHeaderInfo headinfo)
 {
     m_HeaderInfo = headinfo;
 }
コード例 #10
0
ファイル: WMHeaderInfo.cs プロジェクト: tdhieu/openvss
		public WMHeaderInfo(IWMHeaderInfo headerInfo)
		{
			_headerInfo = headerInfo;
		}
コード例 #11
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.");
            }
        }
コード例 #12
0
ファイル: WMVCopy.cs プロジェクト: gchudov/WindowsMediaLib
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::Copy()
        // Desc: Copies the input file to the output file. The script stream is moved
        //       to the header if fMoveScriptStream is true.
        //------------------------------------------------------------------------------
        public void Copy(
            string pwszInputFile,
            string pwszOutputFile,
            long qwMaxDuration,
            bool fMoveScriptStream)
        {
            //
            // Initialize the pointers
            //
            m_hEvent            = null;
            m_pReader           = null;
            m_pReaderAdvanced   = null;
            m_pReaderHeaderInfo = null;
            m_pReaderProfile    = null;
            m_pWriter           = null;
            m_pWriterAdvanced   = null;
            m_pWriterHeaderInfo = null;

            m_dwStreamCount   = 0;
            m_pguidStreamType = null;
            m_pwStreamNumber  = null;

            if (null == pwszInputFile || null == pwszOutputFile)
            {
                throw new COMException("Missing input or output file", E_InvalidArgument);
            }

            m_fMoveScriptStream = fMoveScriptStream;
            m_qwMaxDuration     = qwMaxDuration;

            //
            // Event for the asynchronous calls
            //
            m_hEvent = new AutoResetEvent(false);

            //
            // Create the Reader
            //
            CreateReader(pwszInputFile);

            //
            // Get profile information
            //
            GetProfileInfo();

            //
            // Create the Writer
            //
            CreateWriter(pwszOutputFile);

            //
            // Copy all attributes
            //
            CopyAttribute();

            //
            // Copy codec info
            //
            CopyCodecInfo();

            //
            // Copy all scripts in the header
            //
            CopyScriptInHeader();

            //
            // Process samples: read from the reader, and write to the writer
            //

            try
            {
                Process();
            }
            catch (Exception e)
            {
                int hr = Marshal.GetHRForException(e);
                //
                // Output some common error messages.
                //
                if (NSResults.E_VIDEO_CODEC_NOT_INSTALLED == hr)
                {
                    Console.WriteLine("Processing samples failed: Video codec not installed");
                }
                if (NSResults.E_AUDIO_CODEC_NOT_INSTALLED == hr)
                {
                    Console.WriteLine("Processing samples failed: Audio codec not installed");
                }
                else if (NSResults.E_INVALID_OUTPUT_FORMAT == hr)
                {
                    Console.WriteLine("Processing samples failed: Invalid output format ");
                }
                else if (NSResults.E_VIDEO_CODEC_ERROR == hr)
                {
                    Console.WriteLine("Processing samples failed: An unexpected error occurred with the video codec ");
                }
                else if (NSResults.E_AUDIO_CODEC_ERROR == hr)
                {
                    Console.WriteLine("Processing samples failed: An unexpected error occurred with the audio codec ");
                }
                else
                {
                    Console.WriteLine(string.Format("Processing samples failed: Error (hr=0x{0:x})", hr));
                }
                throw;
            }

            //
            // Copy all scripts in m_ScriptList
            //
            CopyScriptInList(pwszOutputFile);

            //
            // Copy marker information
            //
            CopyMarker(pwszOutputFile);

            Console.WriteLine("Copy finished.");

            //
            // Note: The output file is indexed automatically.
            // You can use IWMWriterFileSink3::SetAutoIndexing(false) to disable
            // auto indexing.
            //

            Dispose();
        }
コード例 #13
0
ファイル: WMVCopy.cs プロジェクト: gchudov/WindowsMediaLib
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::CopyMarker()
        // Desc: Copies the markers from the source file to the destination file.
        //------------------------------------------------------------------------------
        protected void CopyMarker(string pwszOutputFile)
        {
            short             cMarker           = 0;
            IWMMetadataEditor pEditor           = null;
            IWMHeaderInfo     pWriterHeaderInfo = null;
            StringBuilder     pwszMarkerName    = null;

            m_pReaderHeaderInfo.GetMarkerCount(out cMarker);

            //
            // Markers can be copied only by the metadata editor.
            // Create an editor
            //
            WMUtils.WMCreateEditor(out pEditor);

            try
            {
                //
                // Open the output using the editor
                //
                pEditor.Open(pwszOutputFile);

                pWriterHeaderInfo = pEditor as IWMHeaderInfo;

                for (short i = 0; i < cMarker; i++)
                {
                    short cchMarkerNameLen = 0;
                    long  cnsMarkerTime    = 0;

                    //
                    // Get the memory size for this marker
                    //
                    m_pReaderHeaderInfo.GetMarker(i,
                                                  null,
                                                  ref cchMarkerNameLen,
                                                  out cnsMarkerTime);

                    pwszMarkerName = new StringBuilder(cchMarkerNameLen);

                    m_pReaderHeaderInfo.GetMarker(i,
                                                  pwszMarkerName,
                                                  ref cchMarkerNameLen,
                                                  out cnsMarkerTime);
                    //
                    // Add marker to the writer
                    //
                    pWriterHeaderInfo.AddMarker(pwszMarkerName.ToString(),
                                                cnsMarkerTime);
                }

                //
                // Close and release the editor
                //
                pEditor.Flush();

                pEditor.Close();
            }
            finally
            {
                Marshal.ReleaseComObject(pEditor);
            }
        }
コード例 #14
0
ファイル: WMVCopy.cs プロジェクト: gchudov/WindowsMediaLib
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::CreateReader()
        // Desc: Creates a reader and opens the source file using this reader.
        //------------------------------------------------------------------------------
        protected void CreateReader(string pwszInputFile)
        {
            Console.WriteLine("Creating the Reader...");

            //
            // Create a reader
            //
            WMUtils.WMCreateReader(IntPtr.Zero, 0, out m_pReader);

            //
            // Get the IWMReaderAdvanced interface
            //
            m_pReaderAdvanced = m_pReader as IWMReaderAdvanced;

            //
            // Get the IWMHeaderInfo interface of the reader
            //
            m_pReaderHeaderInfo = m_pReader as IWMHeaderInfo;

            //
            // Open the reader; use "this" as the callback interface.
            //
            m_pReader.Open(pwszInputFile, this, IntPtr.Zero);

            //
            // Wait until WMT_OPENED status message is received in OnStatus()
            //
            WaitForCompletion();

            //
            // Get the duration of the source file
            //
            short        wStreamNumber = 0;
            AttrDataType enumType;
            short        cbLength = 8; // sizeof(m_qwDuration);

            byte[] b = new byte[cbLength];

            m_pReaderHeaderInfo.GetAttributeByName(ref wStreamNumber,
                                                   Constants.g_wszWMDuration,
                                                   out enumType,
                                                   b,
                                                   ref cbLength);

            m_qwDuration = BitConverter.ToInt64(b, 0);

            if (m_qwDuration == 0)
            {
                throw new COMException("Duration is zero", E_InvalidArgument);
            }

            //
            // Turn on the user clock
            //
            m_pReaderAdvanced.SetUserProvidedClock(true);

            //
            // Turn on manual stream selection, so we get all streams.
            //
            m_pReaderAdvanced.SetManualStreamSelection(true);
        }
コード例 #15
0
ファイル: WMHeaderInfo.cs プロジェクト: tmpkus/openvss
 public WMHeaderInfo(IWMHeaderInfo headerInfo)
 {
     _headerInfo = headerInfo;
 }
コード例 #16
0
        // Use IWMMetadataEditor interface to access
        // StreamNumber attribute
        ///////////////////////////////////////////////////////////////////////////////
        void GetBoolAttribsFromEditor(IWMHeaderInfo pHeaderInfo, string pwszName, out bool pResult)
        {
            AttrDataType wmType;
            short wStreamNum = 0;
            short cbLen = 0;

            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, null, ref cbLen);

            byte[] pData = new byte[cbLen];
            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, pData, ref cbLen);

            pResult = BitConverter.ToBoolean(pData, 0);
        }