1

我正在用 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。

4

1 回答 1

1

您的变量pipe可能超出范围。尝试使用object.signal.connect(...)而不是GLib.Signal.connect,根据:https ://wiki.gnome.org/Vala/SignalsAndCallbacks

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

于 2013-09-08T11:54:04.283 回答