没有来自GstBus的“消息”信号

时间:2013-09-08 02:58:32

标签: gtk gstreamer vala

我正在用Gstreamer-1.0和vala-0.20以及Gtk + -3.0写一些转换器

我注意到我的管道总线上没有任何“消息”, 因为我的信号处理程序从未被调用过:

 public void job_add_on_click(GLib.Object but, void *data)
 {
    Gtk.Window win = ((but as Widget).get_toplevel()) as Gtk.Window;          
    TreeView tree = (data as TreeView);
    TreeModel model = tree.model;
    stdout.printf ("trctrc\n");
    ListStore store = (model as ListStore);
    FileChooserDialog dialog = new FileChooserDialog("Selectionner un fichier",
                                                     win, Gtk.FileChooserAction.OPEN,
                                                     Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
                                                     Gtk.Stock.OPEN, Gtk.ResponseType.ACCEPT, null);
    dialog.select_multiple = true;
    Dialog dial = dialog as Dialog;
    if(dial.run() != Gtk.ResponseType.ACCEPT)return;
        SList<File> lis = dialog.get_files();
        dialog.close ();
        Element decode = ElementFactory.make("decodebin","decode");
        Element src = ElementFactory.make("filesrc","src");
        Pipeline pipe = new Pipeline("pipe");
        Element pix = ElementFactory.make("autovideosink","pix");//gdkpixbufsink
        pipe.add_many(src, decode, pix);
        ForBus fb = new ForBus( store, tree, win, pipe);
        Gst.Bus b = pipe.get_bus();
        b.add_signal_watch();
        b.message.connect(fb.pix_watch_on_bus);
        src.link_pads("src", decode, "sink");
        GLib.Signal.connect(decode , "pad-added", (GLib.Callback)pad_add, (void *)pipe);
        uint len = lis.length();
        stdout.printf ("chacla\n");
        uint i = 0;
        int rm = 0;
        File file;
        string title, path;
        for(i=0; i<len; i++)
        {
            file = lis.nth_data(i);
            title = file.get_basename();
            path = file.get_path();
            fb.path = path;
            fb.title = title;
            string loc;
            src.set("location", path);
            src.get("location", out loc );
            stdout.printf ("location: %s\n", loc);
            stdout.printf ("path file: %s  title: %s\n", fb.path, fb.title);
                      stdout.printf ("state of pipe14 %s\n", pipe.current_state.to_string ());
            pipe.set_state(Gst.State.PLAYING);
              pipe.get_state (null, null, Gst.CLOCK_TIME_NONE);
            stdout.printf ("change meme non\n");
            while(pipe.current_state != Gst.State.PAUSED)
            {
                Thread.usleep (2000000);
                stdout.printf ("state of pipe11 %s\n", pipe.current_state.to_string ());
            }
            stdout.printf ("%d fois\n", (int)i);
            pipe.set_state(Gst.State.NULL);
            fb.end_int = pipe.numchildren;
            for(rm = fb.start_int; rm < fb.end_int; rm++)
            {
                pipe.remove(pipe.get_by_name("sink".concat((rm).to_string())));
            }
        }
        b.remove_signal_watch();

    }

    public class ForBus: GLib.Object
    {
          public TreeIter iter;
          public ListStore store;
          public TreeView tree;
          public Gtk.Window win;
          public string path;
          public string title;
          public Pipeline pipe;
          public int start_int;
          public int end_int;
          public ForBus( ListStore store, TreeView tree, Gtk.Window win, Pipeline pip)
          {
              this.store = store;
              this.tree  = tree;
              this.win = win;
              this.pipe = pip;
              this.start_int = pipe.numchildren;
              stdout.printf ("creation pipe childreen %d", this.start_int);
          }
          public void pix_watch_on_bus(Gst.Bus bus, Gst.Message msg)
          {
             stdout.printf ("name message originator\n");
          }
    }

  public void pad_add(Element decode1, Pad new_pad, void* data)
    {
        stdout.printf ("not good I suppose hein\n");
        Gst.Pipeline pipe = data as Gst.Pipeline;
        stdout.printf ("it is good here\n");
        Caps actual_caps = new_pad.query_caps (null);
        if(actual_caps == null)stdout.printf ("this caaps is null\n");
        unowned Structure stru = actual_caps.get_structure(0);
                stdout.printf ("tictidddddddvvvvvc\n");
        stdout.printf ("name of pad %s\n", stru.get_name ());
        if(stru.get_name().has_prefix ("video/x-raw"))
        {
            stdout.printf ("video\n");
            Element pix = pipe.get_by_name("pix");
            if(pix == null)stdout.printf ("pix is null\n");
            Pad pad = pix.get_static_pad("sink");
            stdout.printf ("danger\n");
            if(pad.is_linked() == true)
            {
                stdout.printf ("audio\n");
                Element tmp = ElementFactory.make("alsa","sink".concat((pipe.numchildren).to_string()));
                Pad p = tmp.get_static_pad("sink");
                stdout.printf ("%d\n", pipe.numchildren);
                pipe.add(tmp);
                new_pad.link(p);
                tmp.sync_state_with_parent();
                return;
            }
            stdout.printf ("calcuta\n");
            new_pad.link(pad);
            stdout.printf ("do it ffff\n");
        stdout.printf ("state of pipe %s\n", pipe.current_state.to_string ());
            return;
        }
        Element tmp1 = ElementFactory.make("autoaudiosink","sink".concat((pipe.numchildren).to_string()));
        pipe.add(tmp1);
        stdout.printf ("%d\n", pipe.numchildren);
        Pad p1 = tmp1.get_static_pad("sink");
        new_pad.link(p1);
        stdout.printf ("sa data rek\n");
        stdout.printf ("end of\n");
        tmp1.sync_state_with_parent();
        stdout.printf ("with its parent\n");
        if(pipe.current_state==Gst.State.PLAYING)stdout.printf ("pipe is playing\n");
    }

所有stdout.printf都是出于调试目的。

我使用Gtk,因此这段代码背后有mainloop。

1 个答案:

答案 0 :(得分:1)

您的变量pipe可能超出范围。请按照https://wiki.gnome.org/Vala/SignalsAndCallbacks

使用object.signal.connect(...)代替GLib.Signal.connect

如果你必须在Vala中使用void*,你可能会做比你应该做的更多的工作,因为Vala应该用更安全的东西来抽象它。