コード例 #1
0
 public string this[string AttrName]
 {
     get
     {
         WMHeaderInfo head = new WMHeaderInfo(HeaderInfo);
         try
         {
             return(head[AttrName].Value.ToString());
         }
         catch (COMException e)
         {
             if (e.ErrorCode == WM.ASF_E_NOTFOUND)
             {
                 return(null);
             }
             else
             {
                 throw (e);
             }
         }
     }
 }
コード例 #2
0
ファイル: WmaWriter.cs プロジェクト: gauravkar/NAudio
        /// <summary>
        /// Create the writer indicating Metadata information
        /// </summary>
        /// <param name="output"><see cref="System.IO.Stream"/> Where resulting WMA string will be written</param>
        /// <param name="inputFormat">PCM format of input data received in <see cref="WmaWriter.Write"/> method</param>
        /// <param name="profile">IWMProfile that describe the resulting compressed stream</param>
        /// <param name="MetadataAttributes">Array of <see cref="Yeti.WMFSdk.WM_Attr"/> structures describing the metadata information that will be in the result stream</param>
        public WmaWriter(Stream output, WaveFormat inputFormat, IWMProfile profile, WM_Attr[] MetadataAttributes)
        {
            this.m_outputStream = output;
            this.m_inputFormat = inputFormat;
            m_Writer = WM.CreateWriter();
            IWMWriterAdvanced wa = (IWMWriterAdvanced)m_Writer;
            wa.AddSink((IWMWriterSink)this);
            m_Writer.SetProfile(profile);
            uint inputs;
            m_Writer.GetInputCount(out inputs);
            if (inputs == 1)
            {
                IWMInputMediaProps InpProps;
                Guid type;
                m_Writer.GetInputProps(0, out InpProps);
                InpProps.GetType(out type);
                if (type == MediaTypes.WMMEDIATYPE_Audio)
                {
                    WM_MEDIA_TYPE mt;
                    mt.majortype = MediaTypes.WMMEDIATYPE_Audio;
                    mt.subtype = MediaTypes.WMMEDIASUBTYPE_PCM;
                    mt.bFixedSizeSamples = true;
                    mt.bTemporalCompression = false;
                    mt.lSampleSize = (uint)inputFormat.BlockAlign;
                    mt.formattype = MediaTypes.WMFORMAT_WaveFormatEx;
                    mt.pUnk = IntPtr.Zero;
                    mt.cbFormat = (uint)Marshal.SizeOf(inputFormat);

                    GCHandle h = GCHandle.Alloc(inputFormat, GCHandleType.Pinned);
                    try
                    {
                        mt.pbFormat = h.AddrOfPinnedObject();
                        InpProps.SetMediaType(ref mt);
                    }
                    finally
                    {
                        h.Free();
                    }
                    m_Writer.SetInputProps(0, InpProps);
                    if (MetadataAttributes != null)
                    {
                        WMHeaderInfo info = new WMHeaderInfo((IWMHeaderInfo)m_Writer);
                        foreach (WM_Attr attr in MetadataAttributes)
                        {
                            info.SetAttribute(attr);
                        }
                        info = null;
                    }
                    m_Writer.BeginWriting();
                    m_Profile = profile;
                }
                else
                {
                    throw new ArgumentException("Invalid profile", "profile");
                }
            }
            else
            {
                throw new ArgumentException("Invalid profile", "profile");
            }
        }
コード例 #3
0
        private void Init(WaveFormat OutputFormat)
        {
            m_outputNumber = GetAudioOutputNumber(m_reader);
            if (m_outputNumber == InvalidOuput)
            {
                throw new ArgumentException("An audio stream was not found");
            }
            int[] FormatIndexes = GetPCMOutputNumbers(m_reader, (uint)m_outputNumber);
            if (FormatIndexes.Length == 0)
            {
                throw new ArgumentException("An audio stream was not found");
            }
            if (OutputFormat != null)
            {
                m_outputFormatNumber = -1;
                for (int i = 0; i < FormatIndexes.Length; i++)
                {
                    WaveFormat fmt = GetOutputFormat(m_reader, (uint)m_outputNumber, (uint)FormatIndexes[i]);
                    if (// (fmt.wFormatTag == OutputFormat.wFormatTag) &&
                      (fmt.AverageBytesPerSecond == OutputFormat.AverageBytesPerSecond) &&
                      (fmt.BlockAlign == OutputFormat.BlockAlign) &&
                      (fmt.Channels == OutputFormat.Channels) &&
                      (fmt.SampleRate == OutputFormat.SampleRate) &&
                      (fmt.BitsPerSample == OutputFormat.BitsPerSample))
                    {
                        m_outputFormatNumber = FormatIndexes[i];
                        m_outputFormat = fmt;
                        break;
                    }
                }
                if (m_outputFormatNumber < 0)
                {
                    throw new ArgumentException("No PCM output found");
                }
            }
            else
            {
                m_outputFormatNumber = FormatIndexes[0];
                m_outputFormat = GetOutputFormat(m_reader, (uint)m_outputNumber, (uint)FormatIndexes[0]);
            }
            uint OutputCtns = 0;
            m_reader.GetOutputCount(out OutputCtns);
            ushort[] StreamNumbers = new ushort[OutputCtns];
            WMT_STREAM_SELECTION[] StreamSelections = new WMT_STREAM_SELECTION[OutputCtns];
            for (uint i = 0; i < OutputCtns; i++)
            {
                m_reader.GetStreamNumberForOutput(i, out StreamNumbers[i]);
                if (i == m_outputNumber)
                {
                    StreamSelections[i] = WMT_STREAM_SELECTION.WMT_ON;
                    m_outputStream = StreamNumbers[i];
                    m_reader.SetReadStreamSamples(m_outputStream, false);
                }
                else
                {
                    StreamSelections[i] = WMT_STREAM_SELECTION.WMT_OFF;
                }
            }
            m_reader.SetStreamsSelected((ushort)OutputCtns, StreamNumbers, StreamSelections);
            IWMOutputMediaProps Props = null;
            m_reader.GetOutputFormat((uint)m_outputNumber, (uint)m_outputFormatNumber, out Props);
            m_reader.SetOutputProps((uint)m_outputNumber, Props);

            uint Size = 0;
            Props.GetMediaType(IntPtr.Zero, ref Size);
            IntPtr buffer = Marshal.AllocCoTaskMem((int)Size);
            try
            {
                WM_MEDIA_TYPE mt;
                Props.GetMediaType(buffer, ref Size);
                mt = (WM_MEDIA_TYPE)Marshal.PtrToStructure(buffer, typeof(WM_MEDIA_TYPE));
                m_sampleSize = mt.lSampleSize;
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
                Props = null;
            }

            m_seekable = false;
            m_length = -1;
            WMHeaderInfo head = new WMHeaderInfo(HeaderInfo);
            try
            {
                m_seekable = (bool)head[WM.g_wszWMSeekable];
                // Yuval Naveh
                ulong nanoDuration = (ulong)head[WM.g_wszWMDuration];
                m_duration = new TimeSpan((long)nanoDuration);
                m_length = SampleTime2BytePosition(nanoDuration);
            }
            catch (COMException e)
            {
                if (e.ErrorCode != WM.ASF_E_NOTFOUND)
                {
                    throw (e);
                }
            }

        }
コード例 #4
0
 public string this[string AttrName]
 {
     get
     {
         WMHeaderInfo head = new WMHeaderInfo(HeaderInfo);
         try
         {
             return head[AttrName].Value.ToString();
         }
         catch (COMException e)
         {
             if (e.ErrorCode == WM.ASF_E_NOTFOUND)
             {
                 return null;
             }
             else
             {
                 throw (e);
             }
         }
     }
 }
コード例 #5
0
        private void Init(WaveFormat OutputFormat)
        {
            m_outputNumber = GetAudioOutputNumber(m_reader);
            if (m_outputNumber == InvalidOuput)
            {
                throw new ArgumentException("An audio stream was not found");
            }
            int[] FormatIndexes = GetPCMOutputNumbers(m_reader, (uint)m_outputNumber);
            if (FormatIndexes.Length == 0)
            {
                throw new ArgumentException("An audio stream was not found");
            }
            if (OutputFormat != null)
            {
                m_outputFormatNumber = -1;
                for (int i = 0; i < FormatIndexes.Length; i++)
                {
                    WaveFormat fmt = GetOutputFormat(m_reader, (uint)m_outputNumber, (uint)FormatIndexes[i]);
                    if (// (fmt.wFormatTag == OutputFormat.wFormatTag) &&
                        (fmt.AverageBytesPerSecond == OutputFormat.AverageBytesPerSecond) &&
                        (fmt.BlockAlign == OutputFormat.BlockAlign) &&
                        (fmt.Channels == OutputFormat.Channels) &&
                        (fmt.SampleRate == OutputFormat.SampleRate) &&
                        (fmt.BitsPerSample == OutputFormat.BitsPerSample))
                    {
                        m_outputFormatNumber = FormatIndexes[i];
                        m_outputFormat       = fmt;
                        break;
                    }
                }
                if (m_outputFormatNumber < 0)
                {
                    throw new ArgumentException("No PCM output found");
                }
            }
            else
            {
                m_outputFormatNumber = FormatIndexes[0];
                m_outputFormat       = GetOutputFormat(m_reader, (uint)m_outputNumber, (uint)FormatIndexes[0]);
            }
            uint OutputCtns = 0;

            m_reader.GetOutputCount(out OutputCtns);
            ushort[] StreamNumbers = new ushort[OutputCtns];
            WMT_STREAM_SELECTION[] StreamSelections = new WMT_STREAM_SELECTION[OutputCtns];
            for (uint i = 0; i < OutputCtns; i++)
            {
                m_reader.GetStreamNumberForOutput(i, out StreamNumbers[i]);
                if (i == m_outputNumber)
                {
                    StreamSelections[i] = WMT_STREAM_SELECTION.WMT_ON;
                    m_outputStream      = StreamNumbers[i];
                    m_reader.SetReadStreamSamples(m_outputStream, false);
                }
                else
                {
                    StreamSelections[i] = WMT_STREAM_SELECTION.WMT_OFF;
                }
            }
            m_reader.SetStreamsSelected((ushort)OutputCtns, StreamNumbers, StreamSelections);
            IWMOutputMediaProps Props = null;

            m_reader.GetOutputFormat((uint)m_outputNumber, (uint)m_outputFormatNumber, out Props);
            m_reader.SetOutputProps((uint)m_outputNumber, Props);

            int size = 0;

            Props.GetMediaType(IntPtr.Zero, ref size);
            IntPtr buffer = Marshal.AllocCoTaskMem(size);

            try
            {
                WM_MEDIA_TYPE mt;
                Props.GetMediaType(buffer, ref size);
                mt           = (WM_MEDIA_TYPE)Marshal.PtrToStructure(buffer, typeof(WM_MEDIA_TYPE));
                m_sampleSize = mt.lSampleSize;
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
                Props = null;
            }

            m_seekable = false;
            m_length   = -1;
            WMHeaderInfo head = new WMHeaderInfo(HeaderInfo);

            try
            {
                m_seekable = (bool)head[WM.g_wszWMSeekable];
                // Yuval Naveh
                ulong nanoDuration = (ulong)head[WM.g_wszWMDuration];
                m_duration = new TimeSpan((long)nanoDuration);
                m_length   = SampleTime2BytePosition(nanoDuration);
            }
            catch (COMException e)
            {
                if (e.ErrorCode != WM.ASF_E_NOTFOUND)
                {
                    throw (e);
                }
            }
        }
コード例 #6
0
ファイル: WmaWriter.cs プロジェクト: weimingtom/OtterUI
        /// <summary>
        /// Create the writer indicating Metadata information
        /// </summary>
        /// <param name="output"><see cref="System.IO.Stream"/> Where resulting WMA string will be written</param>
        /// <param name="inputFormat">PCM format of input data received in <see cref="WmaWriter.Write"/> method</param>
        /// <param name="profile">IWMProfile that describe the resulting compressed stream</param>
        /// <param name="MetadataAttributes">Array of <see cref="Yeti.WMFSdk.WM_Attr"/> structures describing the metadata information that will be in the result stream</param>
        public WmaWriter(Stream output, WaveFormat inputFormat, IWMProfile profile, WM_Attr[] MetadataAttributes)
        {
            this.m_outputStream = output;
            this.m_inputFormat  = inputFormat;
            m_Writer            = WM.CreateWriter();
            IWMWriterAdvanced wa = (IWMWriterAdvanced)m_Writer;

            wa.AddSink((IWMWriterSink)this);
            m_Writer.SetProfile(profile);
            uint inputs;

            m_Writer.GetInputCount(out inputs);
            if (inputs == 1)
            {
                IWMInputMediaProps InpProps;
                Guid type;
                m_Writer.GetInputProps(0, out InpProps);
                InpProps.GetType(out type);
                if (type == MediaTypes.WMMEDIATYPE_Audio)
                {
                    WM_MEDIA_TYPE mt;
                    mt.majortype            = MediaTypes.WMMEDIATYPE_Audio;
                    mt.subtype              = MediaTypes.WMMEDIASUBTYPE_PCM;
                    mt.bFixedSizeSamples    = true;
                    mt.bTemporalCompression = false;
                    mt.lSampleSize          = (uint)inputFormat.BlockAlign;
                    mt.formattype           = MediaTypes.WMFORMAT_WaveFormatEx;
                    mt.pUnk     = IntPtr.Zero;
                    mt.cbFormat = (uint)Marshal.SizeOf(inputFormat);

                    GCHandle h = GCHandle.Alloc(inputFormat, GCHandleType.Pinned);
                    try
                    {
                        mt.pbFormat = h.AddrOfPinnedObject();
                        InpProps.SetMediaType(ref mt);
                    }
                    finally
                    {
                        h.Free();
                    }
                    m_Writer.SetInputProps(0, InpProps);
                    if (MetadataAttributes != null)
                    {
                        WMHeaderInfo info = new WMHeaderInfo((IWMHeaderInfo)m_Writer);
                        foreach (WM_Attr attr in MetadataAttributes)
                        {
                            info.SetAttribute(attr);
                        }
                        info = null;
                    }
                    m_Writer.BeginWriting();
                    m_Profile = profile;
                }
                else
                {
                    throw new ArgumentException("Invalid profile", "profile");
                }
            }
            else
            {
                throw new ArgumentException("Invalid profile", "profile");
            }
        }