Exemplo n.º 1
0
        //udpsrc port=9000  buffer-size=60000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! queue ! avdec_h264

        public MainForm()
        {
            // These environment variables are necessary to locate GStreamer libraries, and to stop it from loading

            // wrong libraries installed elsewhere on the system.

            string apppath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            System.Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", "");

            System.Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH", apppath + @"\gstreamer\bin\plugins");

            System.Environment.SetEnvironmentVariable("PATH", @"C:\Windows;"

                                                      + apppath + @"\gstreamer\lib;"

                                                      + apppath + @"\gstreamer\bin");

            System.Environment.SetEnvironmentVariable("GST_REGISTRY", apppath + @"\gstreamer\bin\registry.bin");



            // These are for saving debug information.

            System.Environment.SetEnvironmentVariable("GST_DEBUG", "*:3");

            System.Environment.SetEnvironmentVariable("GST_DEBUG_FILE", "GstreamerLog.txt");

            System.Environment.SetEnvironmentVariable("GST_DEBUG_DUMP_DOT_DIR", apppath);



            // Initialize Gstreamer
            Gst.Application.Init();

            // Build the pipeline
            var source = ElementFactory.Make("videotestsrc", "source");
            var sink   = ElementFactory.Make("autovideosink", "sink");

            // Create the empty pipeline
            var pipeline = new Pipeline("test-pipeline");

            if (pipeline == null || source == null || sink == null)
            {
                Console.WriteLine("Not all elements could be created");
                return;
            }

            // Build the pipeline
            pipeline.Add(source, sink);
            if (!source.Link(sink))
            {
                Console.WriteLine("Elements could not be linked");
                return;
            }

            // Modify the source's properties
            source["pattern"] = 0;

            // Start playing
            var ret = pipeline.SetState(State.Playing);

            if (ret == StateChangeReturn.Failure)
            {
                Console.WriteLine("Unable to set the pipeline to the playing state");
                return;
            }

            // Wait until error or EOS
            var bus = pipeline.Bus;

            //var msg = bus.TimedPopFiltered(Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error);

            // Free resources

            /*  if (msg != null)
             * {
             *    switch (msg.Type)
             *    {
             *        case MessageType.Error:
             *            GLib.GException exc;
             *            string debug;
             *            msg.ParseError(out exc, out debug);
             *            Console.WriteLine(String.Format("Error received from element {0}: {1}", msg.Src.Name, exc.Message));
             *            Console.WriteLine(String.Format("Debugging information {0}", debug));
             *            break;
             *        case MessageType.Eos:
             *            Console.WriteLine("End-Of-Stream reached");
             *            break;
             *        default:
             *            // We should not reach here because we only asked for ERRORs and EOS
             *            Console.WriteLine("Unexpected messag received");
             *            break;
             *    }
             * }*/

            pipeline.SetState(State.Null);

            //  return;



            Gst.Application.Init();



            InitializeComponent();



            // Create a main loop for GLib, run it in a separate thread

            m_GLibMainLoop = new Gst.GLib.MainLoop();

            m_GLibThread = new System.Threading.Thread(m_GLibMainLoop.Run);

            m_GLibThread.IsBackground = true;

            m_GLibThread.Name = "GLibMainLoop";

            m_GLibThread.Start();



            // System.Threading.Thread.CurrentThread.Name = "WinForms";



            CreatePipeline();
        }
Exemplo n.º 2
0
        //udpsrc port=9000  buffer-size=60000 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! queue ! avdec_h264

        public MainForm()
        {
            // These environment variables are necessary to locate GStreamer libraries, and to stop it from loading

            // wrong libraries installed elsewhere on the system.

            string apppath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            System.Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", "");

            System.Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH", apppath + @"\gstreamer\bin\plugins");

            System.Environment.SetEnvironmentVariable("PATH", @"C:\Windows;"

                                                        + apppath + @"\gstreamer\lib;"

                                                        + apppath + @"\gstreamer\bin");

            System.Environment.SetEnvironmentVariable("GST_REGISTRY", apppath + @"\gstreamer\bin\registry.bin");



            // These are for saving debug information.

            System.Environment.SetEnvironmentVariable("GST_DEBUG", "*:3");

            System.Environment.SetEnvironmentVariable("GST_DEBUG_FILE", "GstreamerLog.txt");

            System.Environment.SetEnvironmentVariable("GST_DEBUG_DUMP_DOT_DIR", apppath);











            // Initialize Gstreamer
            Gst.Application.Init();

            // Build the pipeline
            var source = ElementFactory.Make("videotestsrc", "source");
            var sink = ElementFactory.Make("autovideosink", "sink");

            // Create the empty pipeline
            var pipeline = new Pipeline("test-pipeline");

            if (pipeline == null || source == null || sink == null)
            {
                Console.WriteLine("Not all elements could be created");
                return;
            }

            // Build the pipeline
            pipeline.Add(source, sink);
            if (!source.Link(sink))
            {
                Console.WriteLine("Elements could not be linked");
                return;
            }

            // Modify the source's properties
            source["pattern"] = 0;

            // Start playing
            var ret = pipeline.SetState(State.Playing);
            if (ret == StateChangeReturn.Failure)
            {
                Console.WriteLine("Unable to set the pipeline to the playing state");
                return;
            }

            // Wait until error or EOS
            var bus = pipeline.Bus;
            //var msg = bus.TimedPopFiltered(Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error);

            // Free resources
          /*  if (msg != null)
            {
                switch (msg.Type)
                {
                    case MessageType.Error:
                        GLib.GException exc;
                        string debug;
                        msg.ParseError(out exc, out debug);
                        Console.WriteLine(String.Format("Error received from element {0}: {1}", msg.Src.Name, exc.Message));
                        Console.WriteLine(String.Format("Debugging information {0}", debug));
                        break;
                    case MessageType.Eos:
                        Console.WriteLine("End-Of-Stream reached");
                        break;
                    default:
                        // We should not reach here because we only asked for ERRORs and EOS
                        Console.WriteLine("Unexpected messag received");
                        break;
                }
            }*/

            pipeline.SetState(State.Null);

          //  return;


          

            Gst.Application.Init(); 



            InitializeComponent();



            // Create a main loop for GLib, run it in a separate thread

            m_GLibMainLoop = new Gst.GLib.MainLoop();

            m_GLibThread = new System.Threading.Thread(m_GLibMainLoop.Run);

            m_GLibThread.IsBackground = true;

            m_GLibThread.Name = "GLibMainLoop";

            m_GLibThread.Start();



           // System.Threading.Thread.CurrentThread.Name = "WinForms";



            CreatePipeline();

        }