public StateChangeReturn SetState(State state)
        {
            int raw_ret           = gst_element_set_state(raw, (int)state);
            StateChangeReturn ret = (StateChangeReturn)raw_ret;

            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Initializes the Gstreamer pipeline and Glib loop.
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            GstUtilities.DetectGstPath();
            bool r = false;

            glibLoop   = new GLib.MainLoop();
            glibThread = new sysThread.Thread(glibLoop.Run)
            {
                IsBackground = true
            };

            if (pipeline == null)
            {
                pipelineCreated = this.SetupPipeline();
            }
            if (!pipelineCreated)
            {
                sysDbg.WriteLine("Error creating pipeline.");
            }
            StateChangeReturn ret = pipeline.SetState(State.Ready);

            r = pipelineCreated && (ret != StateChangeReturn.Failure);

            return(r);
        }
        public StateChangeReturn GetState()
        {
            //18446744073709551615 is infinite
            int raw_ret           = gst_element_get_state(raw, IntPtr.Zero, IntPtr.Zero, 100);
            StateChangeReturn ret = (StateChangeReturn)raw_ret;

            return(ret);
        }
예제 #4
0
        void ChangeStateWithDelay(State desiredState)
        {
            StateChangeReturn sret = pipeline.SetState(desiredState);

            if (sret == StateChangeReturn.Async)
            {
                State state, pending;
                sret = pipeline.GetState(out state, out pending, Constants.SECOND * 15L);
            }

            if (sret == StateChangeReturn.Success)
            {
                // TODO find another way to log succesful operations
                Console.WriteLine("State change successful");
            }
            else
            {
                // TODO is it the best way to notify about errors? Maybe bool instead?
                throw new Exception(String.Format("State change failed: {0} \n", sret));
            }
        }
예제 #5
0
        void OnOpenClick(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                _pipelineOK = false;
                if (_playbin != null)
                {
                    _playbin.SetState(State.Null);
                }
                else
                {
                    _playbin = ElementFactory.Make("playbin", "playbin");
                }
                if (_playbin == null)
                {
                    throw new Exception("Unable to create element playbin");
                }
                scale.Value = 0;

                _playbin.Bus.EnableSyncMessageEmission();
                _playbin.Bus.AddSignalWatch();
                _playbin.Bus.SyncMessage += OnBusSyncMessage;
                _playbin.Bus.Message     += OnBusMessage;

                var filePath = openFileDialog.FileName;
                var fileName = Path.GetFileNameWithoutExtension(filePath);
                this.Text = this.Name + " : " + fileName;

                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Unix:
                    _playbin["uri"] = "file://" + filePath;
                    break;

                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    _playbin["uri"] = "file:///" + filePath.Replace("\\", "/");
                    break;
                }

                StateChangeReturn sret = _playbin.SetState(Gst.State.Playing);

                if (sret == StateChangeReturn.Async)
                {
                    sret = _playbin.GetState(out var state, out var pending, Gst.Constants.SECOND * 5L);
                }
                if (sret == StateChangeReturn.Success)
                {
                    Console.WriteLine("State change successful");
                    _pipelineOK = true;
                }
                else
                {
                    Console.WriteLine($"State change failed for {filePath} ({sret})\n");
                }
            }
        }
예제 #6
0
        void ButtonOpenClicked(object sender, EventArgs args)
        {
            FileChooserDialog dialog = new FileChooserDialog("Open", this, FileChooserAction.Open, new object[] { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept });

            dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal));

            if (dialog.Run() == (int)ResponseType.Accept)
            {
                _pipelineOK = false;

                if (_playbin != null)
                {
                    _playbin.SetState(Gst.State.Null);
                }
                else
                {
                    _playbin = ElementFactory.Make("playbin", "playbin");
                }

                _scale.Value = 0;

                if (_playbin == null)
                {
                    Console.WriteLine("Unable to create element 'playbin'");
                }

                _playbin.Bus.EnableSyncMessageEmission();
                _playbin.Bus.AddSignalWatch();

                _playbin.Bus.SyncMessage += delegate(object bus, SyncMessageArgs sargs) {
                    Gst.Message msg = sargs.Message;

                    if (!Gst.Video.GlobalVideo.IsVideoOverlayPrepareWindowHandleMessage(msg))
                    {
                        return;
                    }

                    Element src = msg.Src as Element;
                    if (src == null)
                    {
                        return;
                    }

                    try {
                        src["force-aspect-ratio"] = true;
                    }
                    catch (PropertyNotFoundException) {}
                    Element overlay = null;
                    if (src is Gst.Bin)
                    {
                        overlay = ((Gst.Bin)src).GetByInterface(VideoOverlayAdapter.GType);
                    }

                    VideoOverlayAdapter adapter = new VideoOverlayAdapter(overlay.Handle);
                    adapter.WindowHandle = _xWindowId;
                    adapter.HandleEvents(true);
                };

                _playbin.Bus.Message += delegate(object bus, MessageArgs margs) {
                    Message message = margs.Message;

                    switch (message.Type)
                    {
                    case Gst.MessageType.Error:
                        GLib.GException err;
                        string          msg;

                        message.ParseError(out err, out msg);
                        Console.WriteLine(String.Format("Error message: {0}", msg));
                        _pipelineOK = false;
                        break;

                    case Gst.MessageType.Eos:
                        Console.WriteLine("EOS");
                        break;
                    }
                };

                switch (System.Environment.OSVersion.Platform)
                {
                case PlatformID.Unix:
                    _playbin["uri"] = "file://" + dialog.Filename;
                    break;

                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    _playbin["uri"] = "file:///" + dialog.Filename.Replace("\\", "/");
                    break;
                }

                StateChangeReturn sret = _playbin.SetState(Gst.State.Playing);

                if (sret == StateChangeReturn.Async)
                {
                    State state, pending;
                    sret = _playbin.GetState(out state, out pending, Constants.SECOND * 5L);
                }

                if (sret == StateChangeReturn.Success)
                {
                    Console.WriteLine("State change successful");
                    _pipelineOK = true;
                }
                else
                {
                    Console.WriteLine("State change failed for {0} ({1})\n", dialog.Filename, sret);
                }
            }

            dialog.Destroy();
        }
        public void LoadVideo(string uri)
        {
            if (gstThread != null)
            {
                isrunning = false;
                gstThread.Join();
                gstThread = new Thread(new ThreadStart(KeepPolling));
            }

            if (playBin != null)
            {
                playerState = VideoPlayerState.STOPPED;
                Console.WriteLine("STOPPED");

                //Dispose playbin2 and appsink
                playBin.SetState(State.Null);
                playBin.Dispose();
                appSink.SetState(State.Null);
                appSink.Dispose();

                //Create playbin2 and appsink
                playBin = new PlayBin2();

                appSink      = ElementFactory.Make("appsink", "sink") as AppSink;
                appSink.Caps = new Caps("video/x-raw-yuv", new object[] {});
                //appSink.Caps = new Caps("video/x-raw-rgb", new object[] { "bpp", 24 });
                appSink.Drop       = true;
                appSink.MaxBuffers = 8;
                playBin.VideoSink  = appSink;
            }
            else
            {
                //Create playbin2 and appsink
                playBin      = new PlayBin2();
                appSink      = ElementFactory.Make("appsink", "sink") as AppSink;
                appSink.Caps = new Caps("video/x-raw-yuv", new object[] {});
                //appSink.Caps = new Caps("video/x-raw-rgb", new object[] { "bpp", 24 });
                appSink.Drop       = true;
                appSink.MaxBuffers = 8;
                playBin.VideoSink  = appSink;
            }

            //init variables
            texturesOK = false;
            width      = 0;
            height     = 0;

            //Set file uri
            string validUri = uri;

            if (!validUri.StartsWith("file://"))
            {
                validUri = "file://" + uri;
            }
            playBin.Uri = validUri;
            StateChangeReturn sr = playBin.SetState(State.Playing);

            Console.WriteLine(sr.ToString());
            playerState = VideoPlayerState.LOADING;
            Console.WriteLine("LOADING:" + validUri);

            if (gstThread == null)
            {
                gstThread = new Thread(new ThreadStart(KeepPolling));
            }

            isrunning = true;
            //Start polling thread...future thought, using async queue?
            gstThread.Start();

            return;
        }
예제 #8
0
    public static void Main(string [] args)
    {
        Application.Init();

        if (args.Length < 1)
        {
            Console.WriteLine("Please give filenames to read metadata from\n\n");
            return;
        }

        MakePipeline();

        int i = -1;

        while (++i < args.Length)
        {
            State   state, pending;
            TagList tags = null;

            string filename = args[i];

            if (!File.Exists(filename))
            {
                Console.WriteLine("File {0} does not exist", filename);
                continue;
            }

            source["location"] = filename;

            StateChangeReturn sret = pipeline.SetState(State.Paused);

            if (sret == StateChangeReturn.Async)
            {
                if (StateChangeReturn.Success != pipeline.GetState(out state, out pending, Clock.Second * 5))
                {
                    Console.WriteLine("State change failed for {0}. Aborting\n", filename);
                    break;
                }
            }
            else if (sret != StateChangeReturn.Success)
            {
                Console.WriteLine("{0} - Could not read file ({1})\n", filename, sret);
                continue;
            }

            if (!MessageLoop(pipeline, ref tags))
            {
                Console.Error.WriteLine("Failed in message reading for {0}", args[i]);
            }

            if (tags != null)
            {
                Console.WriteLine("Metadata for {0}:", filename);

                foreach (string tag in tags.Tags)
                {
                    PrintTag(tags, tag);
                }
                tags.Dispose();
                tags = null;
            }
            else
            {
                Console.WriteLine("No metadata found for {0}", args[0]);
            }

            sret = pipeline.SetState(State.Null);

            if (StateChangeReturn.Async == sret)
            {
                if (StateChangeReturn.Failure == pipeline.GetState(out state, out pending, Clock.TimeNone))
                {
                    Console.WriteLine("State change failed. Aborting");
                }
            }
        }

        if (pipeline != null)
        {
            pipeline.Dispose();
        }
    }
예제 #9
0
    void ButtonOpenClicked(object sender, EventArgs args)
    {
        FileChooserDialog dialog = new FileChooserDialog("Open", this, FileChooserAction.Open, new object[] { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept });

        dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal));

        if (dialog.Run() == (int)ResponseType.Accept)
        {
            _pipelineOK = false;

            if (_pipeline != null)
            {
                _pipeline.SetState(Gst.State.Null);
                _pipeline.Dispose();
            }

            _scale.Value = 0;

            _pipeline = new Pipeline(string.Empty);

            Element     playbin = ElementFactory.Make("playbin", "playbin");
            XvImageSink sink    = XvImageSink.Make("sink");

            if (_pipeline == null)
            {
                Console.WriteLine("Unable to create pipeline");
            }
            if (playbin == null)
            {
                Console.WriteLine("Unable to create element 'playbin'");
            }
            if (sink == null)
            {
                Console.WriteLine("Unable to create element 'sink'");
            }

            _pipeline.Add(playbin);

            XOverlayAdapter sinkadapter = new XOverlayAdapter(sink);
            sinkadapter.XwindowId = gdk_x11_drawable_get_xid(_da.GdkWindow.Handle);

            playbin.SetProperty("video-sink", sink);
            playbin.SetProperty("uri", "file://" + dialog.Filename);

            StateChangeReturn sret = _pipeline.SetState(Gst.State.Playing);

            if (sret == StateChangeReturn.Async)
            {
                State state, pending;
                sret = _pipeline.GetState(out state, out pending, Clock.Second * 5);
            }

            if (sret == StateChangeReturn.Success)
            {
                _pipelineOK = true;
            }
            else
            {
                Console.WriteLine("State change failed for {0} ({1})\n", dialog.Filename, sret);
            }
        }

        dialog.Destroy();
    }
예제 #10
0
 /// <summary>
 /// Window (this) must be visible before this method is called.
 /// </summary>
 public void StartStream()
 {
     StateChangeReturn s = Pipeline.SetState(State.Playing);
 }
예제 #11
0
  void ButtonOpenClicked (object sender, EventArgs args) {
    FileChooserDialog dialog = new FileChooserDialog ("Open", this, FileChooserAction.Open, new object[] { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept });
    dialog.SetCurrentFolder (Environment.GetFolderPath (Environment.SpecialFolder.Personal));

    if (dialog.Run () == (int) ResponseType.Accept) {
      _pipelineOK = false;

      if (_playbin != null) {
        _playbin.SetState (Gst.State.Null);
      } else {
        _playbin = new PlayBin2 ();
      }

      _scale.Value = 0;

      if (_playbin == null)
        Console.WriteLine ("Unable to create element 'playbin'");

      _playbin.Bus.EnableSyncMessageEmission ();
      _playbin.Bus.AddSignalWatch ();

      _playbin.Bus.SyncMessage += delegate (object bus, SyncMessageArgs sargs) {
        Gst.Message msg = sargs.Message;
        if (msg == null || msg.Type != Gst.MessageType.Element ||
            msg.Structure == null || msg.Structure.Name == null ||
            !msg.Structure.Name.Equals ("prepare-xwindow-id"))
          return;

        Element src = msg.Src as Element;
        if (src == null)
          return;

        if (src.HasProperty ("force-aspect-ratio"))
          src["force-aspect-ratio"] = true;

        (src as XOverlay).XwindowId = _xWindowId;
        (src as XOverlay).HandleEvents (true);
      };

      _playbin.Bus.Message += delegate (object bus, MessageArgs margs) {
        Message message = margs.Message;

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

            message.ParseError (out err, out msg);
            Console.WriteLine (String.Format ("Error message: {0}", msg));
            _pipelineOK = false;
            break;
          case Gst.MessageType.Eos:
            Console.WriteLine ("EOS");
            break;
        }
      };

      switch (System.Environment.OSVersion.Platform) {
        case PlatformID.Unix:
          _playbin["uri"] = "file://" + dialog.Filename;
          break;
        case PlatformID.Win32NT:
        case PlatformID.Win32S:
        case PlatformID.Win32Windows:
        case PlatformID.WinCE:
          _playbin["uri"] = "file:///" + dialog.Filename.Replace("\\","/");
          break;
      }

      StateChangeReturn sret = _playbin.SetState (Gst.State.Playing);

      if (sret == StateChangeReturn.Async) {
        State state, pending;
        sret = _playbin.GetState (out state, out pending, Clock.Second * 5);
      }

      if (sret == StateChangeReturn.Success) {
        Console.WriteLine ("State change successful");
        _pipelineOK = true;
      } else {
        Console.WriteLine ("State change failed for {0} ({1})\n", dialog.Filename, sret);
      }
    }

    dialog.Destroy ();
  }
예제 #12
0
 public YascStreamingException(StateChangeReturn state) : base(string.Format("State change error: {0} ", state.ToString()))
 {
 }