static void CbMessage(object o, MessageArgs args)
        {
            var bus = o as Bus;
            var msg = args.Message;

            switch (args.Message.Type)
            {
            case MessageType.Error:
                msg.ParseError(out GLib.GException err, out string debug);
                Console.WriteLine($"Error: {err.Message}");
                _pipeline.SetState(State.Ready);
                _loop.Quit();
                break;

            case MessageType.Eos:
                // end-of-stream
                _pipeline.SetState(State.Ready);
                _loop.Quit();
                break;

            case MessageType.Buffering:
                // If the stream is live, we do not care about buffering.
                if (_isLive)
                {
                    break;
                }
                _bufferingLevel = msg.ParseBuffering();
                if (_bufferingLevel < 100)
                {
                    _pipeline.SetState(State.Paused);
                }
                else
                {
                    _pipeline.SetState(State.Playing);
                }
                break;

            case MessageType.ClockLost:
                // Get a new clock
                _pipeline.SetState(State.Paused);
                _pipeline.SetState(State.Playing);
                break;

            default:
                // Unhandled message
                break;
            }
        }
    public void TestBufferOwnershipNIp()
    {
        MyTransformNIp.Register();

        Pipeline pipeline = new Pipeline();
        Element  src      = ElementFactory.Make("fakesrc");

        src["sizetype"] = 2;
        Element capsfilter = ElementFactory.Make("capsfilter");

        capsfilter["caps"] = Caps.FromString("foo/bar");
        src["num-buffers"] = 10;
        MyTransformNIp transform = new MyTransformNIp();
        Element        sink      = ElementFactory.Make("fakesink");

        pipeline.Add(src, capsfilter, transform, sink);
        Element.Link(src, capsfilter, transform, sink);

        GLib.MainLoop loop = new GLib.MainLoop();

        pipeline.Bus.AddWatch(delegate(Bus bus, Message message) {
            switch (message.Type)
            {
            case MessageType.Error:
                Enum err;
                string msg;

                message.ParseError(out err, out msg);
                Assert.Fail(String.Format("Error message: {0}", msg));
                loop.Quit();
                break;

            case MessageType.Eos:
                loop.Quit();
                break;
            }
            return(true);
        });

        pipeline.SetState(State.Playing);
        loop.Run();
        Assert.IsTrue(transform.transformed);
        pipeline.SetState(State.Null);
    }
Ejemplo n.º 3
0
    static void Main(string[] args)
    {
        Gst.Application.Init();
        TransformSample.Register();

        Pipeline pipeline         = new Pipeline();
        Element  videotestsrc     = ElementFactory.Make("videotestsrc");
        Element  transform        = new TransformSample();
        Element  ffmpegcolorspace = ElementFactory.Make("ffmpegcolorspace");
        Element  videosink        = ElementFactory.Make("autovideosink");

        pipeline.Add(videotestsrc, transform, ffmpegcolorspace, videosink);
        Element.Link(videotestsrc, transform, ffmpegcolorspace, videosink);

        GLib.MainLoop loop = new GLib.MainLoop();

        pipeline.Bus.AddSignalWatch();
        pipeline.Bus.Message += delegate(object sender, MessageArgs margs) {
            Message message = margs.Message;

            switch (message.Type)
            {
            case MessageType.Error:
                Enum   err;
                string msg;

                message.ParseError(out err, out msg);
                System.Console.WriteLine(String.Format("Error message: {0}", msg));
                loop.Quit();
                break;

            case MessageType.Eos:
                loop.Quit();
                break;
            }
        };

        pipeline.SetState(State.Playing);
        loop.Run();
        pipeline.SetState(State.Null);
    }
    public static void Main(string [] args)
    {
        if (args.Length < 2)
        {
            Console.WriteLine("Usage: mono decodebin-transcoder.exe <input-file> <output-file>");
            return;
        }

        Gst.Application.Init();
        loop = new GLib.MainLoop();

        DecodeBinTranscoder transcoder = new DecodeBinTranscoder();

        transcoder.Error += delegate(object o, ErrorArgs eargs) {
            Console.WriteLine("Error: {0}", eargs.Error);
            transcoder.Dispose();
            loop.Quit();
        };

        transcoder.Finished += delegate {
            Console.WriteLine("\nFinished");
            transcoder.Dispose();
            loop.Quit();
        };

        transcoder.Progress += delegate(object o, ProgressArgs pargs) {
            Console.Write("\rEncoding: {0} / {1} ({2:00.00}%) ",
                          new TimeSpan((pargs.Position / (long)Clock.Second) * TimeSpan.TicksPerSecond),
                          new TimeSpan((pargs.Duration / (long)Clock.Second) * TimeSpan.TicksPerSecond),
                          ((double)pargs.Position / (double)pargs.Duration) * 100.0);
        };

        transcoder.Transcode(args[0], args[1]);

        loop.Run();
    }
Ejemplo n.º 5
0
    bool MessageReceived(Bus bus, Message message)
    {
        MessageType type = message.Type;

        switch (type)
        {
        case MessageType.StateChanged: {
            State old, newState, pending;
            message.ParseStateChanged(out old, out newState, out pending);
            if (message.Src == (Gst.Object)pipeline && newState == State.Playing)
            {
                loop.Quit();
            }
            break;
        }

        case MessageType.Error:
            break;

        default:
            break;
        }
        return(true);
    }