Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        private void TestProt()
        {
            NetProtocol pP;

            m_pSink.SetNetworkProtocol(NetProtocol.HTTP);
            m_pSink.GetNetworkProtocol(out pP);

            Debug.Assert(pP == NetProtocol.HTTP);
        }
Ejemplo n.º 3
0
        /// <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;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the Network Writer Sink (populates member variable)
        /// </summary>
        private void CreateNetworkWriterSink()
        {
            //Create Network Sink
            WMUtils.WMCreateWriterNetworkSink(out _netSink);

            // Configure the network sink

            //register to receive callbacks from the Network Sink
            IWMRegisterCallback iCallback = (IWMRegisterCallback)_netSink;

            iCallback.Advise(this, IntPtr.Zero);

            _netSink.SetNetworkProtocol(NetProtocol.HTTP);

            if ((SourceConfig.MaxClients < 0) || (SourceConfig.MaxClients > 50))
            {
                throw new SourceConfigException("MaxClients must be 0-50 for ASFNetSink!");
            }
            _netSink.SetMaximumClients(SourceConfig.MaxClients);
        }