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:
Video {
id: video
anchors.fill: parent
autoLoad: true
autoPlay: true
source: "vin1.mp4"
onPlaying: {
probe.source = video
console.log("source="+video.source)
console.log("has video=" + video.hasVideo + " status="+video.status+ " playstate="+video.playbackState)
console.log("videoCodec="+ video.metaData.videoCodec)
}
}
VideoProbe {
id: probe
source: video
onFrame: {
console.log("frame\n")
scanner.decode(videoFrame)
}
}
VinScanner {
id: scanner
onDecoded: vinText.text = vin
}
Video {
id: video
anchors.fill: parent
autoLoad: true
autoPlay: true
source: "vin1.mp4"
onPlaying: {
probe.source = video
console.log("source="+video.source)
console.log("has video=" + video.hasVideo + " status="+video.status+ " playstate="+video.playbackState)
console.log("videoCodec="+ video.metaData.videoCodec)
}
}
VideoProbe {
id: probe
source: video
onFrame: {
console.log("frame\n")
scanner.decode(videoFrame)
}
}
VinScanner {
id: scanner
onDecoded: vinText.text = vin
}
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--
class VideoProbe : public QVideoProbe
{
Q_OBJECT
QObject *m_source;
Q_PROPERTY(QObject* source READ source WRITE setSource
) //QObject *m_dest; Q_PROPERTY(QObject* dest READ dest WRITE setDest)
bool m_active; Q_PROPERTY(bool active READ isActive WRITE setActive)
public:
explicit VideoProbe
(QObject *parent
= 0);
bool isActive(); void setActive(bool);
signals:
void frame(QVideoFrame videoFrame);
public slots:
void emitFrame(QVideoFrame videoFrame);
};
class VideoProbe : public QVideoProbe
{
Q_OBJECT
QObject *m_source; Q_PROPERTY(QObject* source READ source WRITE setSource)
//QObject *m_dest; Q_PROPERTY(QObject* dest READ dest WRITE setDest)
bool m_active; Q_PROPERTY(bool active READ isActive WRITE setActive)
public:
explicit VideoProbe(QObject *parent = 0);
bool isActive(); void setActive(bool);
QObject* source(); bool setSource(QObject *);
signals:
void frame(QVideoFrame videoFrame);
public slots:
void emitFrame(QVideoFrame videoFrame);
};
To copy to clipboard, switch view to plain text mode
----- SET SOURCE----
bool VideoProbe
::setSource(QObject* sourceObj
) {
m_source = sourceObj;
bool ret =false;
if (qobject_cast<QMediaObject*>(sourceObj))
{
ret = QVideoProbe::setSource((QMediaObject*)sourceObj);
qDebug() << "VideoProbe::setSource()" << sourceObj << ret;
} else {
qDebug() << "VideoProbe::setSource() not a QMediaObject, got a:" << sourceObj->metaObject()->className();
}
return ret;
}
bool VideoProbe::setSource(QObject* sourceObj)
{
m_source = sourceObj;
bool ret =false;
if (qobject_cast<QMediaObject*>(sourceObj))
{
ret = QVideoProbe::setSource((QMediaObject*)sourceObj);
qDebug() << "VideoProbe::setSource()" << sourceObj << ret;
} else {
qDebug() << "VideoProbe::setSource() not a QMediaObject, got a:" << sourceObj->metaObject()->className();
}
return ret;
}
To copy to clipboard, switch view to plain text mode
Bookmarks