コード例 #1
0
ファイル: WmaStream.cs プロジェクト: Big3Software/hitbase
 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
ファイル: WmaStream.cs プロジェクト: Big3Software/hitbase
        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.nAvgBytesPerSec == OutputFormat.nAvgBytesPerSec) &&
                        (fmt.nBlockAlign == OutputFormat.nBlockAlign) &&
                        (fmt.nChannels == OutputFormat.nChannels) &&
                        (fmt.nSamplesPerSec == OutputFormat.nSamplesPerSec) &&
                        (fmt.wBitsPerSample == OutputFormat.wBitsPerSample))
                    {
                        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_OuputStream       = StreamNumbers[i];
                    m_Reader.SetReadStreamSamples(m_OuputStream, 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];
                m_Length   = SampleTime2BytePosition((ulong)head[WM.g_wszWMDuration]);
            }
            catch (COMException e)
            {
                if (e.ErrorCode != WM.ASF_E_NOTFOUND)
                {
                    throw (e);
                }
            }
        }
コード例 #3
0
        /// <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="format">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 format, IWMProfile profile, WM_Attr[] MetadataAttributes)
            : base(output, format)
        {
            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)m_InputDataFormat.nBlockAlign;
                    mt.formattype           = MediaTypes.WMFORMAT_WaveFormatEx;
                    mt.pUnk     = IntPtr.Zero;
                    mt.cbFormat = (uint)Marshal.SizeOf(m_InputDataFormat);

                    GCHandle h = GCHandle.Alloc(m_InputDataFormat, 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");
            }
        }