From bee188937625c0ea72b5bb236f79f94d1dd5f25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 27 Jan 2021 22:07:17 +0100 Subject: [PATCH] Port app to the new GstClapper API --- src/main.js | 4 ++-- src/misc.js | 4 ++-- src/player.js | 18 +++++++++--------- src/playerBase.js | 26 +++++++++++++------------- src/widget.js | 20 ++++++++++---------- src/widgetRemote.js | 8 ++++---- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main.js b/src/main.js index 15bec1ab..76d169c4 100644 --- a/src/main.js +++ b/src/main.js @@ -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); diff --git a/src/misc.js b/src/misc.js index 79ad654a..f8d5458f 100644 --- a/src/misc.js +++ b/src/misc.js @@ -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; diff --git a/src/player.js b/src/player.js index bad6f1fd..21f31bd0 100644 --- a/src/player.js +++ b/src/player.js @@ -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; @@ -188,7 +188,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 +213,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 +275,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 +387,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 +402,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 +726,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; diff --git a/src/playerBase.js b/src/playerBase.js index a2287e46..048fac3b 100644 --- a/src/playerBase.js +++ b/src/playerBase.js @@ -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,7 +10,7 @@ const { settings } = Misc; let WebServer; var PlayerBase = GObject.registerClass( -class ClapperPlayerBase extends GstPlayer.Player +class ClapperPlayerBase extends GstClapper.Clapper { _init() { @@ -34,10 +34,10 @@ class ClapperPlayerBase extends GstPlayer.Player const acquired = context.acquire(); debug(`default context acquired: ${acquired}`); - const dispatcher = new GstPlayer.PlayerGMainContextSignalDispatcher({ + const dispatcher = new GstClapper.ClapperGMainContextSignalDispatcher({ application_context: context, }); - const renderer = new GstPlayer.PlayerVideoOverlayVideoRenderer({ + const renderer = new GstClapper.ClapperVideoOverlayVideoRenderer({ video_sink: glsinkbin }); @@ -50,7 +50,7 @@ class ClapperPlayerBase extends GstPlayer.Player 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; @@ -87,13 +87,13 @@ class ClapperPlayerBase extends GstPlayer.Player set_initial_config() { - const gstPlayerConfig = { + const gstClapperConfig = { position_update_interval: 1000, user_agent: 'clapper', }; - for(let option of Object.keys(gstPlayerConfig)) - this.set_config_option(option, gstPlayerConfig[option]); + for(let option of Object.keys(gstClapperConfig)) + this.set_config_option(option, gstClapperConfig[option]); this.set_mute(false); @@ -104,7 +104,7 @@ class ClapperPlayerBase extends GstPlayer.Player set_config_option(option, value) { - const setOption = GstPlayer.Player[`config_set_${option}`]; + const setOption = GstClapper.Clapper[`config_set_${option}`]; if(!setOption) return debug(`unsupported option: ${option}`, 'LEVEL_WARNING'); @@ -158,7 +158,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(); } @@ -186,13 +186,13 @@ class ClapperPlayerBase extends GstPlayer.Player switch(this.seekingMode) { case 'fast': if(isSeekMode) - this.set_seek_mode(GstPlayer.PlayerSeekMode.FAST); + this.set_seek_mode(GstClapper.ClapperSeekMode.FAST); else this.set_config_option('seek_fast', true); break; case 'accurate': if(isSeekMode) - this.set_seek_mode(GstPlayer.PlayerSeekMode.ACCURATE); + this.set_seek_mode(GstClapper.ClapperSeekMode.ACCURATE); else { this.set_config_option('seek_fast', false); this.set_config_option('seek_accurate', true); @@ -200,7 +200,7 @@ class ClapperPlayerBase extends GstPlayer.Player break; default: if(isSeekMode) - this.set_seek_mode(GstPlayer.PlayerSeekMode.DEFAULT); + this.set_seek_mode(GstClapper.ClapperSeekMode.DEFAULT); else { this.set_config_option('seek_fast', false); this.set_config_option('seek_accurate', false); diff --git a/src/widget.js b/src/widget.js index 970910e4..48fab83c 100644 --- a/src/widget.js +++ b/src/widget.js @@ -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); } diff --git a/src/widgetRemote.js b/src/widgetRemote.js index a79ad4a7..8bf3288f 100644 --- a/src/widgetRemote.js +++ b/src/widgetRemote.js @@ -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: