【问题标题】:How do I properly subclass with glib using Rust?如何使用 Rust 正确地使用 glib 进行子类化?
【发布时间】:2021-04-14 21:02:21
【问题描述】:

我正在关注this 教程,因为我想创建一个 gstreamer 插件。我认为我的教程有点过时了,但是 Cargo.toml 文件没有指定它们用于教程的版本。我在 glib 方面遇到了一些问题,我希望有更多 glib 经验的人可以帮助我。

本教程提示我编写以下几行。 我添加了我遇到的错误,以及我已经在 cmets 中尝试过的东西:

mod rgb2gray/imp

#[derive(Default)]
pub struct Rgb2Gray {}

impl Rgb2Gray {}

// This macro doesn't seem to exist 
// I tried putting "glib::glib_object_subclass!();" inside the struct (???)
// after that I get: "the trait `glib::subclass::object::ObjectImpl` is not implemented for `rgb2gray::imp::Rgb2Gray`"
#[glib::object_subclass] 
impl ObjectSubclass for Rgb2Gray {
    const NAME: &'static str = "RsRgb2Gray";
    type Type = super::Rgb2Gray; // TYPE is not a variable in ObjectSubclass
    type ParentType = gst_base::BaseTransform;
}

mod rgb2gray

mod imp;

// Again, this macro doesn't seem to exist
// I tried glib::glib_wrapper
glib::wrapper! {
    // The following line doesn't accept ObjectSubclass, it does accept Boxed, or Object, or Shared.
    //  I tried Object, but then it wants more information in the angle brackets... And I'm not sure what kind of information.
    pub struct Rgb2Gray(ObjectSubclass<imp::Rgb2Gray>) @extends gst_base::BaseTransform, gst::Element, gst::Object;
}

// more code...

【问题讨论】:

  • 你的Cargo.toml的内容是什么,你从编译器得到什么错误信息?

标签: rust gstreamer glib gstreamer-1.0


【解决方案1】:

您是否将其与https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/tree/master/tutorial 的代码进行了比较?那个构建得很好,所以我假设代码和降价不同步的地方。

从你上面写的错误来看,你使用的是最新版本的 glib 而不是 git 版本。如何选择 git 版本,请参阅其中的Cargo.toml

如果您使用的是最新版本,则需要 0.6 分支的代码/降价代码:https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/tree/0.6/tutorial

【讨论】:

  • 天哪,你完全正确!我应该知道的,但我没想过要检查。非常感谢!
猜你喜欢
  • 2021-10-23
  • 1970-01-01
  • 1970-01-01
  • 2020-10-03
  • 1970-01-01
  • 2012-11-11
  • 2020-09-22
  • 2016-02-20
  • 1970-01-01
相关资源
最近更新 更多