Results 1 to 6 of 6

Thread: Using QVideoProbe from QML

  1. #1
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Using QVideoProbe from QML

    I am trying to do the following: Using a camera (Well, a video for testing purposes, but will eventually be a QML Camera) decode a bar code. I have the barcode working for static images (VinScanner. C++, exposed to QML, works). Work want me to use the live camera feed so no capture is needed. It will just use the live feed. VideoProbe is my C++ class which wraps QVideoProbe. What I expect to see, at least, are several "frame" messages logged to the console. Nothing happens.

    Here is the QML:
    Qt Code:
    1. Video {
    2. id: video
    3. anchors.fill: parent
    4. autoLoad: true
    5. autoPlay: true
    6. source: "vin1.mp4"
    7. onPlaying: {
    8. probe.source = video
    9. console.log("source="+video.source)
    10. console.log("has video=" + video.hasVideo + " status="+video.status+ " playstate="+video.playbackState)
    11. console.log("videoCodec="+ video.metaData.videoCodec)
    12. }
    13. }
    14. VideoProbe {
    15. id: probe
    16. source: video
    17. onFrame: {
    18. console.log("frame\n")
    19. scanner.decode(videoFrame)
    20. }
    21. }
    22. VinScanner {
    23. id: scanner
    24. onDecoded: vinText.text = vin
    25. }
    To copy to clipboard, switch view to plain text mode 

    Now, what happens is a variety of things.
    First application output:
    VideoProbe::setSource() not a QMediaObject, got a: Video_QMLTYPE_0
    source=file:///home/xxx/Projects/build-vinscan-Desktop_Qt_5_2_1_GCC_64bit-Debug/qml/vinscan/vin1.mp4
    has video=false status=2 playstate=1
    videoCodec=undefined

    Now, what happens on the screen (QML window) is fine. I see the video I collected of me hovering over a bar code. However the hasVideo property is false.
    When I take this Video object and pass it to C++, I get a "Video_QMLTYPE_0" classname from obj->metaObject()->className() or, when it is a Camera, I get a QDeclarativeCamera (not part of QT API!) . Neither of which I expected to get. I expected to get a QObject* that I could promote to a QMediaObject*. But the qobject_cast<>() fails. Both the QCamera an QMediaPlayer inherit QMediaObject. I based my approach on that.

    I think the rest of what I have will work once I get the setSource(QObject*) function squared away.

    --VIDEOPROBE.H--
    Qt Code:
    1. class VideoProbe : public QVideoProbe
    2. {
    3. Q_OBJECT
    4.  
    5. QObject *m_source; Q_PROPERTY(QObject* source READ source WRITE setSource)
    6. //QObject *m_dest; Q_PROPERTY(QObject* dest READ dest WRITE setDest)
    7. bool m_active; Q_PROPERTY(bool active READ isActive WRITE setActive)
    8.  
    9. public:
    10. explicit VideoProbe(QObject *parent = 0);
    11. bool isActive(); void setActive(bool);
    12. QObject* source(); bool setSource(QObject *);
    13.  
    14. signals:
    15. void frame(QVideoFrame videoFrame);
    16.  
    17. public slots:
    18. void emitFrame(QVideoFrame videoFrame);
    19.  
    20. };
    To copy to clipboard, switch view to plain text mode 

    ----- SET SOURCE----
    Qt Code:
    1. bool VideoProbe::setSource(QObject* sourceObj)
    2. {
    3. m_source = sourceObj;
    4. bool ret =false;
    5. if (qobject_cast<QMediaObject*>(sourceObj))
    6. {
    7. ret = QVideoProbe::setSource((QMediaObject*)sourceObj);
    8. qDebug() << "VideoProbe::setSource()" << sourceObj << ret;
    9. } else {
    10. qDebug() << "VideoProbe::setSource() not a QMediaObject, got a:" << sourceObj->metaObject()->className();
    11. }
    12. return ret;
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 7th February 2014 at 08:11. Reason: added code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QVideoProbe from QML

    Quote Originally Posted by Scorp2us View Post
    But the qobject_cast<>() fails. Both the QCamera an QMediaPlayer inherit QMediaObject. I based my approach on that.
    But you have neither a QCamera nor a QMediaPlayer.

    The objects you have are subclasses of QDeclarativeItem which in turn is a QGraphicsObject which in turn derives from QObject.
    So you can qobject_cast to QGraphicsObject or QDeclarativeItem or to the objects' final classes. qobject_cast cannot transform an object into another, unrelated, class.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using QVideoProbe from QML

    Thanks, but why wouldn't these QML element classes be just subclasses of their Q* variants, along with being a subclass of QDeclartiveItem? Where does their magic happen? Are they proxies to a d pointer that does the magic?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QVideoProbe from QML

    A class can not be a subclass of to QObject derived classes.
    My guess is that those two are visual QtQuick components, i.e. they appear visually in the QML scene. In which case they need to derive from QDeclarativeItem.

    I don't know any details about their implementation but it is likely that they hold pointers to the non-UI classes, very likely indirectly through a d-pointer.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Scorp2us (7th February 2014)

  6. #5
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using QVideoProbe from QML

    I got it working like this
    Qt Code:
    1. bool VideoProbe::setSource(QObject* sourceObj)
    2. {
    3. m_source = sourceObj;
    4. bool ret =false;
    5. QMediaPlayer *player = qvariant_cast<QMediaPlayer*>(sourceObj->property("mediaObject"));
    6. qDebug() << "VideoProbe::setSource() player"<< player;
    7. ret = QVideoProbe::setSource((QMediaObject*)player);
    8. return ret;
    9. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to Scorp2us for this useful post:

    anda_skoa (7th February 2014)

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QVideoProbe from QML

    Ah, good to know!

    Btw, you don't have to do another cast in line 7, the variable player is already of type QMediaPlayer

    Cheers,
    _

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.