예제 #1
0
        // Constructor
        public MetadataEditor(string filename)
        {
            IWMMetadataEditor2 metadataEditor = null;

            try
            {
                WindowsMediaWrapper.CreateEditor(out metadataEditor);
                metadataEditor.Open(filename);

                header = (IWMHeaderInfo3)metadataEditor;
                header.GetAttributeCount(0xFFFF, out attrCount);
            }
            catch (COMException cex)
            {
                if ((ComError)cex.ErrorCode == ComError.NS_E_FILE_OPEN_FAILED)
                {
                    throw new FileNotFoundException
                              ("Failed to open the file into memory. The file may " +
                              " be missing or you may not have permission to open it.",
                              filename);
                }
                else
                {
                    throw cex;
                }
            }
        }
        private void Config()
        {
            IWMMetadataEditor edit;

            WMUtils.WMCreateEditor(out edit);

            m_edit = edit as IWMMetadataEditor2;
        }
		//------------------------------------------------------------------------------
		// Name: CDRMHeaderQuery(()
		// Desc: Constructor.
		//------------------------------------------------------------------------------
		public DRMHeaderQuery()
		{
			WMUtils.WMCreateEditor(out m_pEditor);

			m_pEditor2 = (IWMMetadataEditor2)m_pEditor;

			m_pDRMEditor = (IWMDRMEditor)m_pEditor;
		}
예제 #4
0
        //------------------------------------------------------------------------------
        // Name: CDRMHeaderQuery(()
        // Desc: Constructor.
        //------------------------------------------------------------------------------
        public CDrmHeaderQuery()
        {
            WMUtils.WMCreateEditor(out m_pEditor);

            m_pEditor2 = (IWMMetadataEditor2)m_pEditor;

            m_pDRMEditor = (IWMDRMEditor)m_pEditor;
        }
예제 #5
0
 public static extern uint WMCreateEditor(
     [Out, MarshalAs(UnmanagedType.Interface)] out IWMMetadataEditor2 ppMetadataEditor);
예제 #6
0
        public Metadata GetMetadata(object target)
        {
            if (target == null || !(target is string))
            {
                return(null);
            }

            string filename = target.ToString();

            IWMMetadataEditor2 metadataEditor = null;

            IWMSyncReader syncReader = null;

            WMMetadata metadata = new WMMetadata();

            try
            {
                WMFSDKFunctions.WMCreateEditor(out metadataEditor);
                metadataEditor.OpenEx(filename, FILE_ACCESS.GENERIC_READ, FILE_SHARE.FILE_SHARE_NONE);

                IWMHeaderInfo3 header = (IWMHeaderInfo3)metadataEditor;

                ushort attributeCount;
                header.GetAttributeCountEx(StreamNumber, out attributeCount);

                for (int i = 0; i < attributeCount; i++)
                {
                    MetadataField metadataField = GetAttributeByIndex(header, i);

                    metadata.AddMetadataField(metadataField);
                }
            }
            catch (COMException ex)
            {
                // TODO: Logging
            }
            finally
            {
                if (metadataEditor != null)
                {
                    metadataEditor.Close();
                    Marshal.FinalReleaseComObject(metadataEditor);
                    metadataEditor = null;
                }
            }

            try
            {
                WMFSDKFunctions.WMCreateSyncReader(IntPtr.Zero, WMT_RIGHTS.WMT_RIGHT_PLAYBACK, out syncReader);
                syncReader.Open(filename);

                int outputCount;
                syncReader.GetOutputCount(out outputCount);

                IWMOutputMediaProps outputMediaProps = null;

                for (uint i = 0; i < outputCount; i++)
                {
                    IWMOutputMediaProps innerOutputMediaProps;
                    syncReader.GetOutputProps(i, out innerOutputMediaProps);

                    Guid type;
                    innerOutputMediaProps.GetType(out type);

                    if (type == WMFSDKFunctions.WMMEDIATYPE_Video)
                    {
                        outputMediaProps = innerOutputMediaProps;
                        break;
                    }
                }

                if (outputMediaProps != null)
                {
                    int pcbType = 0;
                    outputMediaProps.GetMediaType(IntPtr.Zero, ref pcbType);

                    IntPtr mediaTypeBufferPtr = Marshal.AllocHGlobal(pcbType);

                    outputMediaProps.GetMediaType(mediaTypeBufferPtr, ref pcbType);

                    WM_MEDIA_TYPE     mediaType       = new WM_MEDIA_TYPE();
                    WMVIDEOINFOHEADER videoInfoHeader = new WMVIDEOINFOHEADER();
                    Marshal.PtrToStructure(mediaTypeBufferPtr, mediaType);

                    Marshal.FreeHGlobal(mediaTypeBufferPtr);
                    Marshal.PtrToStructure(mediaType.pbFormat, videoInfoHeader);

                    double frameRate = Math.Round((double)10000000 / videoInfoHeader.AvgTimePerFrame, 2);

                    metadata.AddMetadataField(new MetadataField("FrameRate", frameRate));
                }
            }
            catch (COMException ex)
            {
                // TODO: Logging
            }
            finally
            {
                if (syncReader != null)
                {
                    syncReader.Close();
                    Marshal.FinalReleaseComObject(syncReader);
                    syncReader = null;
                }
            }

            return(metadata);
        }