Merge pull request #37 from Rafostar/gstplayer

Add custom gstreamer libs as part of the app
This commit is contained in:
Rafał Dzięgiel
2021-02-04 16:09:10 +01:00
committed by GitHub
47 changed files with 11223 additions and 146 deletions

View File

@@ -2,10 +2,10 @@ imports.gi.versions.Gdk = '4.0';
imports.gi.versions.Gtk = '4.0';
const { Gst } = imports.gi;
const { App } = imports.src.app;
Gst.init(null);
const { App } = imports.src.app;
function main(argv)
{
new App().run(argv);

View File

@@ -1,4 +1,4 @@
const { Gio, GstAudio, GstPlayer, Gdk, Gtk } = imports.gi;
const { Gio, GstAudio, GstClapper, Gdk, Gtk } = imports.gi;
const Debug = imports.src.debug;
const { debug } = Debug;
@@ -52,7 +52,7 @@ function inhibitForState(state, window)
{
let isInhibited = false;
if(state === GstPlayer.PlayerState.PLAYING) {
if(state === GstClapper.ClapperState.PLAYING) {
if(inhibitCookie)
return;

View File

@@ -1,4 +1,4 @@
const { Gdk, Gio, GLib, GObject, Gst, GstPlayer, Gtk } = imports.gi;
const { Gdk, Gio, GLib, GObject, Gst, GstClapper, Gtk } = imports.gi;
const ByteArray = imports.byteArray;
const Debug = imports.src.debug;
const Misc = imports.src.misc;
@@ -78,11 +78,6 @@ class ClapperPlayer extends PlayerBase
set_uri(uri)
{
/* FIXME: Player does not notify about
* rate change after file load */
if(this.rate !== 1)
this.set_rate(1);
if(Gst.Uri.get_protocol(uri) !== 'file')
return super.set_uri(uri);
@@ -188,7 +183,7 @@ class ClapperPlayer extends PlayerBase
this.seek_done = false;
if(this.state === GstPlayer.PlayerState.STOPPED)
if(this.state === GstClapper.ClapperState.STOPPED)
this.pause();
if(position < 0)
@@ -213,7 +208,7 @@ class ClapperPlayer extends PlayerBase
/* FIXME: Remove this check when GstPlay(er) have set_seek_mode function */
if(this.set_seek_mode) {
this.set_seek_mode(GstPlayer.PlayerSeekMode.DEFAULT);
this.set_seek_mode(GstClapper.ClapperSeekMode.DEFAULT);
this.seekingMode = 'normal';
this.needsFastSeekRestore = true;
}
@@ -275,7 +270,7 @@ class ClapperPlayer extends PlayerBase
toggle_play()
{
const action = (this.state === GstPlayer.PlayerState.PLAYING)
const action = (this.state === GstClapper.ClapperState.PLAYING)
? 'pause'
: 'play';
@@ -387,11 +382,11 @@ class ClapperPlayer extends PlayerBase
this.state = state;
this.emitWs('state_changed', state);
if(state !== GstPlayer.PlayerState.BUFFERING) {
if(state !== GstClapper.ClapperState.BUFFERING) {
const root = player.widget.get_root();
if(this.quitOnStop) {
if(root && state === GstPlayer.PlayerState.STOPPED)
if(root && state === GstClapper.ClapperState.STOPPED)
root.run_dispose();
return;
@@ -402,11 +397,11 @@ class ClapperPlayer extends PlayerBase
const clapperWidget = player.widget.get_ancestor(Gtk.Grid);
if(!clapperWidget) return;
if(!this.seek_done && state !== GstPlayer.PlayerState.BUFFERING) {
if(!this.seek_done && state !== GstClapper.ClapperState.BUFFERING) {
clapperWidget.updateTime();
if(this.needsFastSeekRestore) {
this.set_seek_mode(GstPlayer.PlayerSeekMode.FAST);
this.set_seek_mode(GstClapper.ClapperSeekMode.FAST);
this.seekingMode = 'fast';
this.needsFastSeekRestore = false;
}
@@ -726,7 +721,7 @@ class ClapperPlayer extends PlayerBase
{
this._performCloseCleanup(window);
if(this.state === GstPlayer.PlayerState.STOPPED)
if(this.state === GstClapper.ClapperState.STOPPED)
return window.run_dispose();
this.quitOnStop = true;

View File

@@ -1,4 +1,4 @@
const { Gio, GLib, GObject, Gst, GstPlayer, Gtk } = imports.gi;
const { Gio, GLib, GObject, Gst, GstClapper, Gtk } = imports.gi;
const Debug = imports.src.debug;
const Misc = imports.src.misc;
const { PlaylistWidget } = imports.src.playlist;
@@ -10,34 +10,16 @@ const { settings } = Misc;
let WebServer;
var PlayerBase = GObject.registerClass(
class ClapperPlayerBase extends GstPlayer.Player
class ClapperPlayerBase extends GstClapper.Clapper
{
_init()
{
if(!Gst.is_initialized())
Gst.init(null);
const plugin = 'gtk4glsink';
const gtk4glsink = Gst.ElementFactory.make(plugin, null);
if(!gtk4glsink) {
debug(new Error(
`Could not load "${plugin}".`
+ ' Do you have gstreamer-plugins-good-gtk4 installed?'
));
}
const gtk4plugin = new GstClapper.ClapperGtk4Plugin();
const glsinkbin = Gst.ElementFactory.make('glsinkbin', null);
glsinkbin.sink = gtk4glsink;
glsinkbin.sink = gtk4plugin.video_sink;
const context = GLib.MainContext.ref_thread_default();
const acquired = context.acquire();
debug(`default context acquired: ${acquired}`);
const dispatcher = new GstPlayer.PlayerGMainContextSignalDispatcher({
application_context: context,
});
const renderer = new GstPlayer.PlayerVideoOverlayVideoRenderer({
const dispatcher = new GstClapper.ClapperGMainContextSignalDispatcher();
const renderer = new GstClapper.ClapperVideoOverlayVideoRenderer({
video_sink: glsinkbin
});
@@ -46,11 +28,11 @@ class ClapperPlayerBase extends GstPlayer.Player
video_renderer: renderer
});
this.widget = gtk4glsink.widget;
this.widget = gtk4plugin.video_sink.widget;
this.widget.vexpand = true;
this.widget.hexpand = true;
this.state = GstPlayer.PlayerState.STOPPED;
this.state = GstClapper.ClapperState.STOPPED;
this.visualization_enabled = false;
this.webserver = null;
@@ -62,10 +44,6 @@ class ClapperPlayerBase extends GstPlayer.Player
this.set_and_bind_settings();
settings.connect('changed', this._onSettingsKeyChanged.bind(this));
/* FIXME: additional reference for working around GstPlayer
* buggy signal dispatcher on self. Remove when ported to BUS API */
this.ref();
}
set_and_bind_settings()
@@ -87,14 +65,6 @@ class ClapperPlayerBase extends GstPlayer.Player
set_initial_config()
{
const gstPlayerConfig = {
position_update_interval: 1000,
user_agent: 'clapper',
};
for(let option of Object.keys(gstPlayerConfig))
this.set_config_option(option, gstPlayerConfig[option]);
this.set_mute(false);
/* FIXME: change into option in preferences */
@@ -102,20 +72,6 @@ class ClapperPlayerBase extends GstPlayer.Player
pipeline.ring_buffer_max_size = 8 * 1024 * 1024;
}
set_config_option(option, value)
{
const setOption = GstPlayer.Player[`config_set_${option}`];
if(!setOption)
return debug(`unsupported option: ${option}`, 'LEVEL_WARNING');
const config = this.get_config();
setOption(config, value);
const success = this.set_config(config);
if(!success)
debug(`could not change option: ${option}`);
}
set_all_plugins_ranks()
{
let data = [];
@@ -158,7 +114,7 @@ class ClapperPlayerBase extends GstPlayer.Player
{
this.widget.ignore_textures = isEnabled;
if(this.state !== GstPlayer.PlayerState.PLAYING)
if(this.state !== GstClapper.ClapperState.PLAYING)
this.widget.queue_render();
}
@@ -181,30 +137,16 @@ class ClapperPlayerBase extends GstPlayer.Player
switch(key) {
case 'seeking-mode':
const isSeekMode = (typeof this.set_seek_mode !== 'undefined');
this.seekingMode = settings.get_string('seeking-mode');
switch(this.seekingMode) {
case 'fast':
if(isSeekMode)
this.set_seek_mode(GstPlayer.PlayerSeekMode.FAST);
else
this.set_config_option('seek_fast', true);
this.set_seek_mode(GstClapper.ClapperSeekMode.FAST);
break;
case 'accurate':
if(isSeekMode)
this.set_seek_mode(GstPlayer.PlayerSeekMode.ACCURATE);
else {
this.set_config_option('seek_fast', false);
this.set_config_option('seek_accurate', true);
}
this.set_seek_mode(GstClapper.ClapperSeekMode.ACCURATE);
break;
default:
if(isSeekMode)
this.set_seek_mode(GstPlayer.PlayerSeekMode.DEFAULT);
else {
this.set_config_option('seek_fast', false);
this.set_config_option('seek_accurate', false);
}
this.set_seek_mode(GstClapper.ClapperSeekMode.DEFAULT);
break;
}
break;

View File

@@ -1,4 +1,4 @@
const { Gdk, GLib, GObject, GstPlayer, Gtk } = imports.gi;
const { Gdk, GLib, GObject, GstClapper, Gtk } = imports.gi;
const { Controls } = imports.src.controls;
const Debug = imports.src.debug;
const Misc = imports.src.misc;
@@ -237,7 +237,7 @@ class ClapperWidget extends Gtk.Grid
let type, text, codec;
switch(info.constructor) {
case GstPlayer.PlayerVideoInfo:
case GstClapper.ClapperVideoInfo:
type = 'video';
codec = info.get_codec() || 'Undetermined';
text = codec + ', ' +
@@ -248,7 +248,7 @@ class ClapperWidget extends Gtk.Grid
if(fps)
text += `@${fps}`;
break;
case GstPlayer.PlayerAudioInfo:
case GstClapper.ClapperAudioInfo:
type = 'audio';
codec = info.get_codec() || 'Undetermined';
if(codec.includes('(')) {
@@ -261,7 +261,7 @@ class ClapperWidget extends Gtk.Grid
text += ', ' + codec + ', '
+ info.get_channels() + ' Channels';
break;
case GstPlayer.PlayerSubtitleInfo:
case GstClapper.ClapperSubtitleInfo:
type = 'subtitle';
text = info.get_language() || 'Undetermined';
break;
@@ -408,7 +408,7 @@ class ClapperWidget extends Gtk.Grid
{
if(isShow && !this.controls.visualizationsButton.isVisList) {
debug('creating visualizations list');
const visArr = GstPlayer.Player.visualizations_get();
const visArr = GstClapper.Clapper.visualizations_get();
if(!visArr.length)
return;
@@ -446,7 +446,7 @@ class ClapperWidget extends Gtk.Grid
_onPlayerStateChanged(player, state)
{
switch(state) {
case GstPlayer.PlayerState.BUFFERING:
case GstClapper.ClapperState.BUFFERING:
debug('player state changed to: BUFFERING');
if(player.needsTocUpdate) {
this.controls._setChapterVisible(false);
@@ -457,18 +457,18 @@ class ClapperWidget extends Gtk.Grid
this.needsTracksUpdate = true;
}
break;
case GstPlayer.PlayerState.STOPPED:
case GstClapper.ClapperState.STOPPED:
debug('player state changed to: STOPPED');
this.controls.currentPosition = 0;
this.controls.positionScale.set_value(0);
this.controls.togglePlayButton.setPrimaryIcon();
this.needsTracksUpdate = true;
break;
case GstPlayer.PlayerState.PAUSED:
case GstClapper.ClapperState.PAUSED:
debug('player state changed to: PAUSED');
this.controls.togglePlayButton.setPrimaryIcon();
break;
case GstPlayer.PlayerState.PLAYING:
case GstClapper.ClapperState.PLAYING:
debug('player state changed to: PLAYING');
this.controls.togglePlayButton.setSecondaryIcon();
if(this.needsTracksUpdate) {
@@ -483,7 +483,7 @@ class ClapperWidget extends Gtk.Grid
break;
}
const isNotStopped = (state !== GstPlayer.PlayerState.STOPPED);
const isNotStopped = (state !== GstClapper.ClapperState.STOPPED);
this.revealerTop.endTime.set_visible(isNotStopped);
}

View File

@@ -1,4 +1,4 @@
const { GObject, Gtk, GstPlayer } = imports.gi;
const { GObject, Gtk, GstClapper } = imports.gi;
const Buttons = imports.src.buttons;
const Misc = imports.src.misc;
const { PlayerRemote } = imports.src.playerRemote;
@@ -50,11 +50,11 @@ class ClapperWidgetRemote extends Gtk.Grid
switch(action) {
case 'state_changed':
switch(value) {
case GstPlayer.PlayerState.STOPPED:
case GstPlayer.PlayerState.PAUSED:
case GstClapper.ClapperState.STOPPED:
case GstClapper.ClapperState.PAUSED:
this.togglePlayButton.setPrimaryIcon();
break;
case GstPlayer.PlayerState.PLAYING:
case GstClapper.ClapperState.PLAYING:
this.togglePlayButton.setSecondaryIcon();
break;
default: