/// <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> /// Retrieve the url that should be connected to from media player. From withing /// media player user File/Open URL and entry the string returned from this function. /// </summary> /// <returns></returns> public string GetURL() { int iSize = 0; // Call the function once to get the size m_pNetSink.GetHostURL(null, ref iSize); StringBuilder sRet = new StringBuilder(iSize, iSize); m_pNetSink.GetHostURL(sRet, ref iSize); // Trim off the trailing null return(sRet.ToString().Substring(0, iSize - 1)); }
/// <summary> /// Retreives the Sink URL, as reported by the given network writer sink /// </summary> /// <param name="networkSink">sink to analyze</param> /// <returns>a string of the URL.</returns> private string GetURL(IWMWriterNetworkSink networkSink) { int iSize = 0; // Call the function once to get the size networkSink.GetHostURL(null, ref iSize); StringBuilder sRet = new StringBuilder(iSize, iSize); networkSink.GetHostURL(sRet, ref iSize); // Trim off the trailing null return(sRet.ToString().Substring(0, iSize - 1)); }
/// <summary> /// Retrieve the url that should be connected to from media player. From withing /// media player user File/Open URL and entry the string returned from this function. /// </summary> /// <returns></returns> public string GetURL() { int hr; int iSize = 0; // Call the function once to get the size hr = m_pNetSink.GetHostURL(null, ref iSize); WMError.ThrowExceptionForHR(hr); StringBuilder sRet = new StringBuilder(iSize, iSize); hr = m_pNetSink.GetHostURL(sRet, ref iSize); WMError.ThrowExceptionForHR(hr); // Trim off the trailing null return(sRet.ToString().Substring(0, iSize - 1)); }
private void TestMisc() { StringBuilder sb = null; int iLen = 0; int iPort = 1011; m_pSink.Open(ref iPort); m_pSink.GetHostURL(sb, ref iLen); sb = new StringBuilder(iLen); m_pSink.GetHostURL(sb, ref iLen); Debug.Assert(sb.ToString().Contains(iPort.ToString())); m_pSink.Disconnect(); m_pSink.Close(); }
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); } }