components: Use GstPlay instead of GstPlayer for video player

This commit is contained in:
Kévin Commaille 2022-11-05 15:45:06 +01:00 committed by Kévin Commaille
parent 858cea35bf
commit bbe284554a
6 changed files with 49 additions and 31 deletions

12
Cargo.lock generated
View file

@ -1166,7 +1166,7 @@ dependencies = [
"gstreamer",
"gstreamer-base",
"gstreamer-pbutils",
"gstreamer-player",
"gstreamer-play",
"gstreamer-video",
"gtk-macros",
"gtk4",
@ -1880,25 +1880,25 @@ dependencies = [
]
[[package]]
name = "gstreamer-player"
name = "gstreamer-play"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "796e053b45803544c37a150ae6cbedc8019bc5f410dff78aa6041e7a1a969f2b"
checksum = "c10306f4665fab20777aa86ca77eb9bb4c3e9ae0e57b83ae829afede461dd4df"
dependencies = [
"bitflags",
"glib",
"gstreamer",
"gstreamer-player-sys",
"gstreamer-play-sys",
"gstreamer-video",
"libc",
"once_cell",
]
[[package]]
name = "gstreamer-player-sys"
name = "gstreamer-play-sys"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7930b84f995cf393906ee8499d7bf643aba1899ace61e20fee0ea416ad532f32"
checksum = "40438a38c5027da6f3e9d50d3862d11b877202fabd8e469f0d1888730167177a"
dependencies = [
"glib-sys",
"gobject-sys",

View file

@ -44,7 +44,7 @@ ashpd = { version = "0.4.0-alpha.1", features = [
gst = { version = "0.19.1", package = "gstreamer" }
gst_base = { version = "0.19.1", package = "gstreamer-base" }
gst_video = { version = "0.19.0", package = "gstreamer-video" }
gst_player = { version = "0.19.0", package = "gstreamer-player" }
gst_play = { version = "0.19.0", package = "gstreamer-play" }
gst_gtk = { version = "0.9.0", package = "gst-plugin-gtk4" }
gst_pbutils = { version = "0.19.0", package = "gstreamer-pbutils" }
image = "0.24"

View file

@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GstPlayer" id="player">
<object class="GstPlay" id="player">
<property name="video-renderer">
<object class="ComponentsVideoPlayerRenderer" id="video_renderer"/>
</property>
<property name="signal-dispatcher">
<object class="GstPlayerGMainContextSignalDispatcher"/>
</property>
<signal name="duration-changed" handler="duration_changed" swapped="true"/>
</object>
<template class="ComponentsVideoPlayer" parent="AdwBin">
<child>

View file

@ -22,10 +22,10 @@ dependency(
fallback: ['gtksourceview', 'gtksource_dep'],
default_options: ['gtk_doc=false', 'sysprof=false', 'gir=false', 'vapi=false', 'install_tests=false']
)
dependency('gstreamer-1.0', version: '>= 1.18')
dependency('gstreamer-base-1.0', version: '>= 1.18')
dependency('gstreamer-plugins-base-1.0', version: '>= 1.18')
dependency('gstreamer-video-1.0', version: '>= 1.18')
dependency('gstreamer-1.0', version: '>= 1.20')
dependency('gstreamer-base-1.0', version: '>= 1.20')
dependency('gstreamer-plugins-base-1.0', version: '>= 1.20')
dependency('gstreamer-video-1.0', version: '>= 1.20')
glib_compile_resources = find_program('glib-compile-resources', required: true)
glib_compile_schemas = find_program('glib-compile-schemas', required: true)

View file

@ -1,7 +1,8 @@
use adw::subclass::prelude::*;
use gst::ClockTime;
use gst_player::{Player, PlayerGMainContextSignalDispatcher};
use gtk::{gio, glib, prelude::*, CompositeTemplate};
use gst_play::{Play as GstPlay, PlayMessage};
use gtk::{gio, glib, glib::clone, prelude::*, CompositeTemplate};
use log::{error, warn};
use super::VideoPlayerRenderer;
@ -24,7 +25,7 @@ mod imp {
#[template_child]
pub timestamp: TemplateChild<gtk::Label>,
#[template_child]
pub player: TemplateChild<Player>,
pub player: TemplateChild<GstPlay>,
}
#[glib::object_subclass]
@ -35,9 +36,7 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
VideoPlayerRenderer::static_type();
PlayerGMainContextSignalDispatcher::static_type();
Self::bind_template(klass);
Self::Type::bind_template_callbacks(klass);
}
fn instance_init(obj: &InitializingObject<Self>) {
@ -52,7 +51,7 @@ mod imp {
glib::ParamSpecBoolean::builder("compact")
.explicit_notify()
.build(),
glib::ParamSpecObject::builder::<Player>("player")
glib::ParamSpecObject::builder::<GstPlay>("player")
.read_only()
.build(),
]
@ -77,6 +76,31 @@ mod imp {
_ => unimplemented!(),
}
}
fn constructed(&self) {
self.parent_constructed();
let obj = self.obj();
self.player
.message_bus()
.add_watch_local(
clone!(@weak obj => @default-return glib::Continue(false), move |_, message| {
match PlayMessage::parse(message) {
Ok(PlayMessage::DurationChanged { duration }) => obj.duration_changed(duration),
Ok(PlayMessage::Warning { error, .. }) => {
warn!("Warning playing video: {error}");
}
Ok(PlayMessage::Error { error, .. }) => {
error!("Error playing video: {error}");
}
_ => {}
}
glib::Continue(true)
}),
)
.unwrap();
}
}
impl WidgetImpl for VideoPlayer {}
@ -90,7 +114,6 @@ glib::wrapper! {
@extends gtk::Widget, adw::Bin, @implements gtk::Accessible;
}
#[gtk::template_callbacks]
impl VideoPlayer {
/// Create a new video player.
#[allow(clippy::new_without_default)]
@ -98,8 +121,8 @@ impl VideoPlayer {
glib::Object::new(&[])
}
/// The GStreamerPlayer for the video.
pub fn player(&self) -> &Player {
/// The `GstPlay` for the video.
pub fn player(&self) -> &GstPlay {
&self.imp().player
}
@ -127,7 +150,6 @@ impl VideoPlayer {
player.play();
}
#[template_callback]
fn duration_changed(&self, duration: Option<ClockTime>) {
let label = if let Some(duration) = duration {
let mut time = duration.seconds();

View file

@ -1,6 +1,6 @@
use adw::subclass::prelude::*;
use gst_gtk::PaintableSink;
use gst_player::{subclass::prelude::*, Player, PlayerVideoRenderer};
use gst_play::{subclass::prelude::*, Play, PlayVideoRenderer};
use gtk::{gdk, glib, prelude::*};
mod imp {
@ -18,7 +18,7 @@ mod imp {
impl ObjectSubclass for VideoPlayerRenderer {
const NAME: &'static str = "ComponentsVideoPlayerRenderer";
type Type = super::VideoPlayerRenderer;
type Interfaces = (PlayerVideoRenderer,);
type Interfaces = (PlayVideoRenderer,);
}
impl ObjectImpl for VideoPlayerRenderer {
@ -46,8 +46,8 @@ mod imp {
}
}
impl PlayerVideoRendererImpl for VideoPlayerRenderer {
fn create_video_sink(&self, _player: &Player) -> gst::Element {
impl PlayVideoRendererImpl for VideoPlayerRenderer {
fn create_video_sink(&self, _player: &Play) -> gst::Element {
self.sink.get().unwrap().to_owned().upcast()
}
}
@ -56,7 +56,7 @@ mod imp {
glib::wrapper! {
/// A widget displaying a video media file.
pub struct VideoPlayerRenderer(ObjectSubclass<imp::VideoPlayerRenderer>)
@implements PlayerVideoRenderer;
@implements PlayVideoRenderer;
}
impl VideoPlayerRenderer {