예제 #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);
        }
예제 #2
0
        protected void OpenSink()
        {
            AppLogger.Message("ASFNetSink -- OpenSink");
            //extract the port number from the SinkURL
            Uri uri     = new Uri(this.ClientURL);
            int portNum = uri.Port;

            // Done configuring the network sink, open it
            _netSink.Open(ref portNum);
        }
예제 #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;
                }
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
        /// <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);
        }
        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);
            }
        }
예제 #7
0
        /// <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);
        }