/// <summary> /// Wraps the WMCreateWriterNetworkSink function /// </summary> /// <returns>The network sink object</returns> public static IWMWriterNetworkSink CreateWriterNetworkSink() { IWMWriterNetworkSink res = null; Marshal.ThrowExceptionForHR(WMCreateWriterNetworkSink(out res)); return(res); }
private void Config() { IWMWriterNetworkSink pWMWriterNetworkSink = null; WMUtils.WMCreateWriterNetworkSink(out pWMWriterNetworkSink); m_pAddressAccess = (IWMAddressAccess2)pWMWriterNetworkSink; }
/// <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> /// Dispose of everything that may need disposing. /// </summary> public void Cleanup() { scriptBitrate = 0; writerAdvanced = null; writer = null; netSink = null; fileSink = null; audioProps = null; videoProps = null; audioInput = 0; videoInput = 0; scriptStreamNumber = 0; profileManager = null; }
public override void Dispose(bool disposing) { AppLogger.Message("ASFNetSink -- Dispose called"); if (_eventTimer != null) { _eventTimer.Enabled = false; } if (_netSink != null) { try { IWMRegisterCallback iCallback = (IWMRegisterCallback)_netSink; iCallback.Unadvise(this, IntPtr.Zero); _netSink.Close(); } catch (Exception ex) { AppLogger.Dump(ex); } finally { Marshal.ReleaseComObject(_netSink); _netSink = null; } } if (_writerAdvanced != null) { RemoveAllSinks(_writerAdvanced); Marshal.ReleaseComObject(_writerAdvanced); _writerAdvanced = null; } if (_writer != null) { Marshal.ReleaseComObject(_writer); _writer = null; } if (_asfFilter != null) { Marshal.ReleaseComObject(_asfFilter); _asfFilter = null; } base.Dispose(disposing); }
/// <summary> /// Adds a IWMWriterNetworkSink to the current AsfWriter output filter /// </summary> /// <param name="streamPort">The port out of which to stream the transcoded file</param> private void AddStreamSinkToCurrentOutputFilter(int streamPort) { int hr; DirectShowLib.IServiceProvider pServiceProvider; // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx WMAsfWriter asfwriter = (WMAsfWriter)currentOutputFilter; pServiceProvider = (DirectShowLib.IServiceProvider)asfwriter; // Get access to WMwriterAdvanced2 object using pServiceProvider (poss not futureproof) (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af ) DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2)); IWMWriterAdvanced2 WMWriterAdvanced2 = null; object o = null; hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o); // FAILS IN A STA THREAD DsError.ThrowExceptionForHR(hr); WMWriterAdvanced2 = (IWMWriterAdvanced2)o; IWMWriterNetworkSink nsink; WMUtils.WMCreateWriterNetworkSink(out nsink); NetworkSink = nsink; dc.Add(nsink); nsink.SetMaximumClients(1); nsink.SetNetworkProtocol(NetProtocol.HTTP); NetworkSink.Open(ref streamPort); // Will throw exception if port is in use int nSinks; WMWriterAdvanced2.GetSinkCount(out nSinks); if (nSinks > 0) { IWMWriterSink pSink = null; WMWriterAdvanced2.GetSink(0, out pSink); if (pSink != null) { WMWriterAdvanced2.RemoveSink(pSink); } Marshal.ReleaseComObject(pSink); pSink = null; } WMWriterAdvanced2.AddSink(NetworkSink); }
public WMWriter(MediaBuffer mb) { eventLog = new EventLog("WMG", ".", "WMGCore"); mb.OnSampleReady += new MediaBuffer.sampleReadyHandler(ReceiveSample); scriptBitrate = 0; writerAdvanced = null; writer = null; netSink = null; fileSink = null; audioProps = null; videoProps = null; audioInput = 0; videoInput = 0; scriptStreamNumber = 0; lastWriteTime = 0; profileManager = null; writeFailed = false; }
/// <summary> Shut down capture </summary> private void CloseInterfaces() { int hr; try { if (m_mediaCtrl != null) { // Stop the graph hr = m_mediaCtrl.Stop(); m_mediaCtrl = null; m_bRunning = false; } } catch (Exception ex) { Debug.WriteLine(ex); } if (m_pNetSink != null) { m_pNetSink.Close(); Marshal.ReleaseComObject(m_pNetSink); m_pNetSink = null; } #if DEBUG // Remove graph from the ROT if (m_rot != null) { m_rot.Dispose(); m_rot = null; } #endif if (m_graphBuilder != null) { Marshal.ReleaseComObject(m_graphBuilder); m_graphBuilder = null; } }
private static extern int WMCreateWriterNetworkSink([Out, MarshalAs(UnmanagedType.Interface)] out IWMWriterNetworkSink ppSink);
public static extern int WMCreateWriterNetworkSink( out IWMWriterNetworkSink ppSink );
/// <summary> /// Adds a IWMWriterNetworkSink to the current AsfWriter output filter /// </summary> /// <param name="streamPort">The port out of which to stream the transcoded file</param> private void AddStreamSinkToCurrentOutputFilter(int streamPort) { int hr; DirectShowLib.IServiceProvider pServiceProvider; // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx WMAsfWriter asfwriter = (WMAsfWriter)currentOutputFilter; pServiceProvider = (DirectShowLib.IServiceProvider)asfwriter; // Get access to WMwriterAdvanced2 object using pServiceProvider (poss not futureproof) (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af ) DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2)); IWMWriterAdvanced2 WMWriterAdvanced2 = null; object o = null; hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o); // FAILS IN A STA THREAD DsError.ThrowExceptionForHR(hr); WMWriterAdvanced2 = (IWMWriterAdvanced2)o; IWMWriterNetworkSink nsink; WMUtils.WMCreateWriterNetworkSink(out nsink); NetworkSink = nsink; dc.Add(nsink); nsink.SetMaximumClients(1); nsink.SetNetworkProtocol(NetProtocol.HTTP); NetworkSink.Open(ref streamPort); // Will throw exception if port is in use int nSinks; WMWriterAdvanced2.GetSinkCount(out nSinks); if (nSinks > 0) { IWMWriterSink pSink = null; WMWriterAdvanced2.GetSink(0, out pSink); if (pSink != null) WMWriterAdvanced2.RemoveSink(pSink); Marshal.ReleaseComObject(pSink); pSink = null; } WMWriterAdvanced2.AddSink(NetworkSink); }