简体   繁体   English

插件中的QML和QtGStreamer

[英]QML and QtGStreamer within plugin

I'm trying to prepare QML plugin to play video on embedded device in a way that other developers can use it without much hassle. 我正在尝试准备QML插件,以使其在其他设备上可以轻松使用的方式在嵌入式设备上播放视频。 However the way it is currently proposed requires almost always writing some C++ wrapper around your QML application. 但是,当前提出的方法几乎总是需要围绕QML应用程序编写一些C ++包装器。 I'm refering to this example: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/qt-gstreamer/html/examples_2qmlplayer_2main_8cpp-example.html 我指的是以下示例: http : //gstreamer.freedesktop.org/data/doc/gstreamer/head/qt-gstreamer/html/examples_2qmlplayer_2main_8cpp-example.html

I would like to be able to have plugin and simply write: 我希望能够有插件并简单地编写:

import AwesomeVideoPlugin 1.0

Rect
{
    AwesomeVideo
    {
        width: 320 
        height: 240
        url: "./myvideo.avi" 
        // ... some minor stuff like mouse click handling, controls, etc.
    }
}

Currently QtGStreamer requires to provide videoSurface property to VideoItem. 当前,QtGStreamer需要向VideoItem提供videoSurface属性。 The only way to do this is to create and set context for additional property in rootContext(). 唯一的方法是为rootContext()中的其他属性创建和设置上下文。 And to create GraphicsVideoSurface I need QGraphicsView (QDeclarativeView fills this role). 要创建GraphicsVideoSurface,我需要QGraphicsView(QDeclarativeView担任此角色)。

Is it possible to: 是否有可能:

  1. Get QDeclarativeView from within QDeclarativeItem (to which I have only access from QML plugin) in a way that it can be later used to feed GraphicsVideoSurface? 从QDeclarativeItem(我只能从QML插件访问)中获取QDeclarativeView,以便以后可以使用它来提供GraphicsVideoSurface? My guess is no - however I've found path QFraphicsItem::scene() ==> QGraphScene ==> QGraphScene::views() ==> QList of QGraphicsView - it looks like VERY bad programming but maybe somebody got it to work (I'm getting segfault) 我的猜测不是-但是我找到了路径QFraphicsItem :: scene()==> QGraphScene ==> QGraphScene :: views()==> QGraphicsView的QList-看起来编程很糟糕,但也许有人可以使用它(我遇到段错误)

  2. Is there other way to provide video sink for QtGStreamer from within QDeclarativeItem ? 还有其他方法可以从QDeclarativeItem内部为QtGStreamer提供视频接收器吗?

Greetz 格蕾兹

Yatsa 弥撒

I had the same question, but haven't come up with an elegant solution. 我有同样的问题,但还没有提出一个优雅的解决方案。

However, one thought would be to make the videosurface available via an accessor function from a sub-classed QApplication object. 但是,一种想法是通过访问器功能从子类QApplication对象中使视频表面可用。

This would, of course, mean that your plug-in depends on the application subclass having a getVideoSurface method, but it does remove the ugliness from the QML code. 当然,这意味着您的插件依赖于具有getVideoSurface方法的应用程序子类,但是它确实消除了QML代码中的丑陋之处。

class MyApp : public QApplication
{
    ....
     QGst::Ui::GraphicsVideoSurface *getVideoSurface() { return m_videosurface; }
}

 ...
int MyApp::init()
{
     m_viewer = new QDeclarativeView(); 
     m_viewer->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
     m_videosurface = new QGst::Ui::GraphicsVideoSurface(m_viewer);
}

MyVideoPlugin::MyVideoPlugin(QDeclarativeItem *parent) : QDeclarativeItem(parent)
{
    QGst::Ui::GraphicsVideoSurface *surface = ((MyApp*)qApp)->getVideoSurface();
}
...

Now the MyVideoPlugin element may be used without referencing an exported videosurface context item. 现在,可以使用MyVideoPlugin元素,而无需引用导出的videosurface上下文项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM