Esempio n. 1
0
        // Constructor
        public MetadataEditor(string filename)
        {
            IWMMetadataEditor metadataEditor = null;

              try
              {
            WindowsMediaWrapper.CreateEditor(out metadataEditor);
            metadataEditor.Open(filename);
            header = metadataEditor as IWMHeaderInfo3;

            if (header != null)
              header.GetAttributeCount(0xFFFF, out attrCount);
            else
              throw new ArgumentNullException("metadataEditor",
                   "Failed to cast as IWMHeaderInfo3");
              }
              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;
              }
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
0
        private void Config()
        {
            IWMMetadataEditor pEditor;

            WMUtils.WMCreateEditor(out pEditor);
            pEditor.Open(sFileName);
            m_head = (IWMHeaderInfo3)pEditor;
        }
Esempio n. 4
0
        //------------------------------------------------------------------------------
        // Name: CWMVCopy:CopyCodecInfo()
        // Desc: Copies codec information from the reader header to the writer header.
        //------------------------------------------------------------------------------
        protected void CopyCodecInfo()
        {
            int           cCodecInfo;
            StringBuilder pwszName        = null;
            StringBuilder pwszDescription = null;

            byte[]         pbCodecInfo        = null;
            IWMHeaderInfo3 pReaderHeaderInfo3 = null;
            IWMHeaderInfo3 pWriterHeaderInfo3 = null;

            pReaderHeaderInfo3 = m_pReaderHeaderInfo as IWMHeaderInfo3;

            pWriterHeaderInfo3 = m_pWriterHeaderInfo as IWMHeaderInfo3;

            pReaderHeaderInfo3.GetCodecInfoCount(out cCodecInfo);

            for (int i = 0; i < cCodecInfo; i++)
            {
                CodecInfoType enumCodecType;
                short         cchName        = 0;
                short         cchDescription = 0;
                short         cbCodecInfo    = 0;

                //
                // Get codec info from the source
                //
                pReaderHeaderInfo3.GetCodecInfo(i, ref cchName, null,
                                                ref cchDescription, null, out enumCodecType,
                                                ref cbCodecInfo, null);

                pwszName        = new StringBuilder(cchName);
                pwszDescription = new StringBuilder(cchDescription);
                pbCodecInfo     = new byte[cbCodecInfo];

                pReaderHeaderInfo3.GetCodecInfo(i, ref cchName, pwszName,
                                                ref cchDescription, pwszDescription, out enumCodecType,
                                                ref cbCodecInfo, pbCodecInfo);

                //
                // Add the codec info to the writer
                //
                pWriterHeaderInfo3.AddCodecInfo(pwszName.ToString(),
                                                pwszDescription.ToString(),
                                                enumCodecType,
                                                cbCodecInfo, pbCodecInfo);
            }
        }
        /// <summary>Initialize the editor.</summary>
        /// <param name="filepath">The path to the file whose metadata needs to be edited.</param>
        public AsfMetadataEditor(string filepath)
            : base()
        {
            if (filepath == null) throw new ArgumentNullException("filepath");
            _path = filepath;

            try
            {
                _editor = WMCreateEditor();
                _editor.Open(filepath);
                _headerInfo = (IWMHeaderInfo3)_editor;
            }
            catch
            {
                Dispose(true);
                throw;
            }
        }
        /// <summary>Initialize the editor.</summary>
        /// <param name="filepath">The path to the file whose metadata needs to be edited.</param>
        public AsfMetadataEditor(string filepath) : base()
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }
            _path = filepath;

            try
            {
                _editor = WMCreateEditor();
                _editor.Open(filepath);
                _headerInfo = (IWMHeaderInfo3)_editor;
            }
            catch
            {
                Dispose(true);
                throw;
            }
        }
        private static MetadataField GetAttributeByIndex(IWMHeaderInfo3 header, int index)
        {
            StringBuilder     attributeName       = null;
            ushort            attributeNameLength = 0;
            WMT_ATTR_DATATYPE attributeDataType;
            ushort            langIndex = 0;

            byte[] attributeValue       = null;
            uint   attributeValueLength = 0;

            header.GetAttributeByIndexEx(
                StreamNumber,
                (ushort)index,
                attributeName,
                ref attributeNameLength,
                out attributeDataType,
                out langIndex,
                attributeValue,
                ref attributeValueLength);

            attributeName  = new StringBuilder(attributeNameLength, attributeNameLength);
            attributeValue = new byte[attributeValueLength];

            header.GetAttributeByIndexEx(
                StreamNumber,
                (ushort)index,
                attributeName,
                ref attributeNameLength,
                out attributeDataType,
                out langIndex,
                attributeValue,
                ref attributeValueLength);

            object value = ParseAttributeValue(attributeValue, attributeDataType);

            MetadataField field = new MetadataField(attributeName.ToString(), value);

            return(field);
        }
 /// <summary>Releases all of the resources for the editor.</summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_editor != null)
         {
             try { _editor.Flush(); }
             catch (COMException) {}
             while (Marshal.ReleaseComObject(_editor) > 0)
             {
                 ;
             }
             _editor = null;
         }
         if (_headerInfo != null)
         {
             while (Marshal.ReleaseComObject(_headerInfo) > 0)
             {
                 ;
             }
             _headerInfo = null;
         }
     }
 }
Esempio n. 9
0
 public WMFMetadataEditor(IWMHeaderInfo3 headerInfo3)
 {
     this.HeaderInfo3 = headerInfo3;
 }
Esempio n. 10
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.");
            }
        }
Esempio n. 11
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);
        }
 /// <summary>Releases all of the resources for the editor.</summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_editor != null)
         {
             try { _editor.Flush(); }
             catch(COMException){}
             while(Marshal.ReleaseComObject(_editor) > 0);
             _editor = null;
         }
         if (_headerInfo != null)
         {
             while(Marshal.ReleaseComObject(_headerInfo) > 0);
             _headerInfo = null;
         }
     }
 }
Esempio n. 13
0
        public static bool BASS_TAG_GetFromFile(int stream, TAG_INFO tags)
        {
            if ((stream == 0) || (tags == null))
            {
                return(false);
            }
            bool flag = false;

            tags.channelInfo = new BASS_CHANNELINFO();
            if (BASS_ChannelGetInfo(stream, tags.channelInfo))
            {
                BASSTag tagType = BASSTag.BASS_TAG_UNKNOWN;
                IntPtr  p       = BASS_TAG_GetIntPtr(stream, tags.channelInfo, out tagType);
                if (p != IntPtr.Zero)
                {
                    switch (tagType)
                    {
                    case BASSTag.BASS_TAG_ID3:
                        return(ReadID3v1(p, tags));

                    case BASSTag.BASS_TAG_ID3V2:
                        return(ReadID3v2(p, tags));

                    case BASSTag.BASS_TAG_OGG:
                        return(tags.UpdateFromMETA(p.ToInt32(), true));

                    case BASSTag.BASS_TAG_HTTP:
                    case BASSTag.BASS_TAG_ICY:
                    case BASSTag.BASS_TAG_META:
                        return(flag);

                    case BASSTag.BASS_TAG_APE:
                        return(tags.UpdateFromMETA(p.ToInt32(), false));

                    case BASSTag.BASS_TAG_MP4:
                        return(tags.UpdateFromMETA(p.ToInt32(), false));

                    case BASSTag.BASS_TAG_WMA:
                        flag = tags.UpdateFromMETA(p.ToInt32(), true);
                        try
                        {
                            IntPtr pUnk = BASS_WMA_GetWMObject(stream);
                            if (!(pUnk != IntPtr.Zero))
                            {
                                return(flag);
                            }
                            IWMHeaderInfo3 objectForIUnknown = (IWMHeaderInfo3)Marshal.GetObjectForIUnknown(pUnk);
                            ArrayList      allPictures       = new WMFMetadataEditor(objectForIUnknown).GetAllPictures();
                            if (allPictures != null)
                            {
                                foreach (TagPicture picture in allPictures)
                                {
                                    tags.AddPicture(picture);
                                }
                            }
                            objectForIUnknown = null;
                            GC.Collect();
                        }
                        catch
                        {
                        }
                        return(flag);

                    case BASSTag.BASS_TAG_RIFF_INFO:
                        return(tags.UpdateFromMETA(p.ToInt32(), false));

                    case BASSTag.BASS_TAG_MUSIC_NAME:
                        tags.title  = BASS_ChannelGetMusicName(stream);
                        tags.artist = BASS_ChannelGetMusicMessage(stream);
                        return(true);
                    }
                }
            }
            return(flag);
        }
Esempio n. 14
0
 /// <summary>
 /// Open an editor on the given file.
 /// </summary>
 /// <param name="fileName">The path to the file to open</param>
 /// <remarks>This will throw an exception if the format of the file is unknown.</remarks>
 public MetaDataEditor(string fileName)
 {
     WMFSDKFunctions.WMCreateEditor(out this.editor);
     this.headerInfo = (IWMHeaderInfo3)this.editor;
     this.editor.Open(fileName);
 }