Skip to content

Instantly share code, notes, and snippets.

@mohan43u
Last active August 29, 2015 14:09
Show Gist options
  • Save mohan43u/ed944832080c0d85b786 to your computer and use it in GitHub Desktop.
Save mohan43u/ed944832080c0d85b786 to your computer and use it in GitHub Desktop.
#!/usr/bin/env gjs
const Lang = imports.lang;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gst = imports.gi.Gst;
const Mainloop = imports.mainloop;
let TestAV = new Lang.Class({
Name: "Helloworld",
Extends: GObject.Object,
Signals: {
'eos': {}
},
_init: function(params) {
this.parent(params);
Gst.init_check(null);
this.__elements_init();
},
__elements_init: function() {
this.pipeline = new Gst.Pipeline();
this.video = {src: Gst.ElementFactory.make('autovideosrc', null),
sink: Gst.ElementFactory.make('autovideosink', null)};
this.audio = {src: Gst.ElementFactory.make('autoaudiosrc', null),
sink: Gst.ElementFactory.make('autoaudiosink', null)};
this.pipeline.add(this.video.src);
this.pipeline.add(this.video.sink);
this.pipeline.add(this.audio.src);
this.pipeline.add(this.audio.sink);
this.video.src.link(this.video.sink);
this.audio.src.link(this.audio.sink);
this.msgbus = this.pipeline.get_bus();
this.msgbus.add_watch(GLib.PRIORITY_DEFAULT, Lang.bind(this, this.__msgbus_cb));
},
__msgbus_cb: function(bus, message) {
switch(message.type) {
case(Gst.MessageType.ERROR):
case(Gst.MessageType.EOS): {
this.pipeline.set_state(Gst.State.NULL);
this.emit('eos');
} break;
case(Gst.MessageType.STATE_CHANGED): {
let states = message.parse_state_changed();
print(message.seqnum
+ ': state changed from '
+ Gst.Element.state_get_name(states[0])
+ ' to '
+ Gst.Element.state_get_name(states[1])
+ ' on '
+ message.src.name
+ ' ...');
} break;
default: {
print(message.seqnum
+ ': received '
+ Gst.MessageType.get_name(message.type)
+ ' from '
+ message.src.name + ' ...');
}
}
return true;
},
play: function() {
this.pipeline.set_state(Gst.State.PLAYING);
}
});
let testav = new TestAV();
testav.connect('eos', function(){Mainloop.quit()});
testav.play();
Mainloop.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment