public string this[string AttrName] { get { var head = new WMHeaderInfo(HeaderInfo); try { return(head[AttrName].Value.ToString()); } catch (COMException e) { if (e.ErrorCode == WM.ASF_E_NOTFOUND) { return(null); } throw; } } }
/// <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.wma.structs.WM_Attr"/> structures describing the metadata information that will be in the result stream</param> public WmaWriter(Stream output, WaveFormat format, IWMProfile profile, IEnumerable <WM_Attr> metadataAttributes) : base(output, format) { m_Writer = WM.CreateWriter(); var 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) { var 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"); } }
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); var streamNumbers = new ushort[outputCtns]; var 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 { props.GetMediaType(buffer, ref size); var 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; var 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; } } }