Skip to content

Instantly share code, notes, and snippets.

@wmanley
Created October 24, 2014 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmanley/76974b124588c669c3b1 to your computer and use it in GitHub Desktop.
Save wmanley/76974b124588c669c3b1 to your computer and use it in GitHub Desktop.
PulseVideo from GStreamer Conference 2014 lightning talk [Zero copy video with file descriptor passing](http://gstconf.ubicast.tv/videos/zero-copy-video-with-file-descriptor-passing/)
[DBus (name = "com.example.VideoSource")]
interface VideoSource : GLib.Object {
public abstract string caps { owned get; }
public abstract GLib.UnixInputStream attach () throws Error;
}
void run() throws Error
{
VideoSource demo = Bus.get_proxy_sync (
BusType.SESSION, "com.example.VideoSource", "/com/example/videosource");
var caps = demo.caps;
var fd = demo.attach();
stdout.printf("CAPS: %s\n".printf(caps));
stdout.printf("FD: %i\n".printf(fd.fd));
var pipeline_desc =
"fdsrc fd=%i ! application/x-fd ! fddepay ! %s ! videoconvert ! filesink location=/dev/null".printf(fd.fd, caps);
/* var pipeline_desc =
"fdsrc fd=%i blocksize=%i ! %s ! videoconvert ! filesink location=/dev/null".printf(fd.fd, 1920*1080*3, caps);*/
stdout.printf("Pipeline: %s\n".printf(pipeline_desc));
var pipeline = (Gst.Pipeline) Gst.parse_launch(pipeline_desc);
pipeline.set_state (Gst.State.PLAYING);
// Creating and starting a GLib main loop
new MainLoop ().run ();
}
void main (string[] args) {
// Initializing GStreamer
Gst.init (ref args);
try {
run();
} catch (Error error) {
warning ("%s", error.message);
}
}
using GLib;
using Gst;
using Posix;
[DBus (name = "com.example.VideoSource")]
public class VideoSource : GLib.Object {
public string caps { get { return caps_; } }
private string caps_;
private Gst.Element multisocketsink;
public VideoSource (string caps, Gst.Element multisocketsink)
{
this.caps_ = caps;
this.multisocketsink = multisocketsink;
}
public GLib.UnixInputStream attach () throws Error
{
var fds = new int[2];
var success = Posix.socketpair (Posix.AF_UNIX, Posix.SOCK_STREAM, 0, fds);
var wtr = new GLib.Socket.from_fd(fds[0]);
GLib.Signal.emit_by_name(multisocketsink, "add", wtr, null);
return new GLib.UnixInputStream(fds[1], true);
}
}
void main (string[] args) {
// Initializing GStreamer
Gst.init (ref args);
// Creating pipeline and elements
var caps = "video/x-raw,format=RGB,width=1920,height=1080,framerate=30/1";
var pipeline = (Gst.Pipeline) Gst.parse_launch("videotestsrc is-live=true ! " + caps + " ! "
+ "fdpay ! multisocketsink name=sink");
var sink = pipeline.get_by_name("sink");
// Set pipeline state to PLAYING
pipeline.set_state (State.PLAYING);
var conn = GLib.Bus.get_sync (BusType.SESSION);
conn.register_object("/com/example/videosource", new VideoSource(caps, sink));
var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName",
new Variant ("(su)", "com.example.VideoSource", 0x4), null, 0, -1);
// Creating and starting a GLib main loop
new MainLoop ().run ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment