Results 1 to 6 of 6

Thread: Using QVideoProbe from QML

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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.