/// <summary> /// Prepare the network writer. /// </summary> /// <param name="port"></param> /// <param name="maxClients"></param> /// <returns></returns> public bool ConfigNet(uint port, uint maxClients) { if ((writerAdvanced == null) || (netSink == null)) { Debug.WriteLine("WriterAdvanced and NetSink must exist before calling ConfigNet"); return(false); } try { netSink.SetNetworkProtocol(WMT_NET_PROTOCOL.WMT_PROTOCOL_HTTP); netSink.Open(ref port); uint size = 0; netSink.GetHostURL(IntPtr.Zero, ref size); IntPtr buf = Marshal.AllocCoTaskMem((int)(2 * (size + 1))); netSink.GetHostURL(buf, ref size); String url = Marshal.PtrToStringAuto(buf); Marshal.FreeCoTaskMem(buf); Debug.WriteLine("Connect to:" + url); netSink.SetMaximumClients(maxClients); writerAdvanced.AddSink(netSink); } catch (Exception e) { eventLog.WriteEntry("Failed to configure network: " + e.ToString(), EventLogEntryType.Error, 1000); Debug.WriteLine("Failed to configure network: " + e.ToString()); return(false); } return(true); }
/// <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"); } }
/// <summary> /// Get and configure the IWMWriterAdvanced /// </summary> /// <param name="asfWriter">IBaseFilter from which to get the IWMWriterAdvanced</param> void DoAnet(IBaseFilter asfWriter) { int hr; int dwPortNum = PortNum; // Get the IWMWriterAdvanced IWMWriterAdvanced pWriterAdvanced = GetWriterAdvanced(asfWriter); try { // Remove all the sinks from the writer RemoveAllSinks(pWriterAdvanced); // Say we are using live data hr = pWriterAdvanced.SetLiveSource(true); WMError.ThrowExceptionForHR(hr); // Create a network sink hr = WMUtils.WMCreateWriterNetworkSink(out m_pNetSink); WMError.ThrowExceptionForHR(hr); // Configure the network sink hr = m_pNetSink.SetNetworkProtocol(NetProtocol.HTTP); WMError.ThrowExceptionForHR(hr); // Configure the network sink hr = m_pNetSink.SetMaximumClients(MaxClients); WMError.ThrowExceptionForHR(hr); // Done configuring the network sink, open it hr = m_pNetSink.Open(ref dwPortNum); WMError.ThrowExceptionForHR(hr); // Add the network sink to the IWMWriterAdvanced hr = pWriterAdvanced.AddSink(m_pNetSink as IWMWriterSink); WMError.ThrowExceptionForHR(hr); } finally { if (pWriterAdvanced != null) { Marshal.ReleaseComObject(pWriterAdvanced); pWriterAdvanced = null; } } }
private void TestSink() { int i; IWMWriterFileSink pSink; IWMWriterSink pSink2; WMUtils.WMCreateWriterFileSink(out pSink); m_Writer.AddSink(pSink); m_Writer.GetSinkCount(out i); Debug.Assert(i == 1); m_Writer.GetSink(0, out pSink2); Debug.Assert(pSink2 != null); m_Writer.RemoveSink(pSink2); m_Writer.GetSinkCount(out i); Debug.Assert(i == 0); }
private void Config() { WMUtils.WMCreateWriter(IntPtr.Zero, out writer); writer.SetProfileByID(g); WMUtils.WMCreateWriterNetworkSink(out sink); m_clientConns = (IWMClientConnections)sink; IWMWriterAdvanced advWriter = (IWMWriterAdvanced)writer; advWriter.AddSink(sink); sink.Open(ref port); int urlLen = 0; sink.GetHostURL(null, ref urlLen); sbUrl = new StringBuilder(urlLen); sink.GetHostURL(sbUrl, ref urlLen); writer.BeginWriting(); WMUtils.WMCreateReader(IntPtr.Zero, Rights.Playback, out reader); reader.Open(sbUrl.ToString(), this, new IntPtr(123)); lock (m_openLock) { Monitor.Wait(m_openLock); } reader.Start(0, 0, 1.0f, new IntPtr(321)); lock (m_openLock) { Monitor.Wait(m_openLock); } }
/// <summary> /// Adds the network sink to the ASF Writer filter. /// </summary> protected void AddSinkToWriter() { // Add the network sink _writerAdvanced.AddSink(_netSink as IWMWriterSink); }