#include "qtcamvideomode.h"
#include "qtcamnotifications.h"
-// TODO: we want the ability to change the image and video gep from the app.
-
QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name,
const QVariant& id, QObject *parent) :
QObject(parent), d_ptr(new QtCamDevicePrivate) {
// TODO: audio bitrate
// TODO: video bitrate
// TODO: filters
- // TODO: capabilities
// TODO: custom properties for jifmux, mp4mux, audio encoder, video encoder, sink & video source
d_ptr->listener = new QtCamGStreamerMessageListener(gst_element_get_bus(d_ptr->cameraBin),
d_ptr, this);
break;
default:
- // TODO: other types
break;
}
}
// we use. For now we will not set any FPS.
d_ptr->setCaps("image-capture-caps", d->resolution.captureResolution(), -1);
- setPreviewSize(d->resolution.previewResolution());
+ d_ptr->setPreviewSize(d->resolution.previewResolution());
// If we don't reset the caps then: if we switch from video to image then we fail
// the next time we restart the pipeline.
return false;
}
- setFileName(fileName);
+ d_ptr->setFileName(fileName);
g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
#include <gst/video/video.h>
#include <QImage>
-#define PREVIEW_CAPS "video/x-raw-rgb, width = (int) %1, height = (int) %2, bpp = (int) 32, depth = (int) 24, red_mask = (int) 65280, green_mask = (int) 16711680, blue_mask = (int) -16777216"
-
class PreviewImageHandler : public QtCamGStreamerMessageHandler {
public:
PreviewImageHandler(QtCamMode *m, QObject *parent = 0) :
// We need to copy because GStreamer will free the buffer after we return
// and since QImage doesn't copythe data by default we will end up with garbage.
- // TODO: consider a QImage subclass that takes a GstBuffer reference
+ // There is no way to subclass QImage to prevent copying :|
QImage cp = image.copy();
QString fileName = QString::fromUtf8(file);
class DoneHandler : public QtCamGStreamerMessageHandler {
public:
- DoneHandler(QtCamMode *m, const char *done, QObject *parent = 0) :
+ DoneHandler(QtCamModePrivate *m, const char *done, QObject *parent = 0) :
QtCamGStreamerMessageHandler(done, parent) {
mode = m;
}
if (gst_structure_has_field(s, "filename")) {
const char *str = gst_structure_get_string(s, "filename");
if (str) {
- fileName = QString::fromUtf8(str);
+ mode->fileName = QString::fromUtf8(str);
}
}
- QMetaObject::invokeMethod(mode, "saved", Q_ARG(QString, fileName));
+ QMetaObject::invokeMethod(mode->q_ptr, "saved", Q_ARG(QString, mode->fileName));
}
- QString fileName;
- QtCamMode *mode;
+ QtCamModePrivate *mode;
};
QtCamMode::QtCamMode(QtCamModePrivate *d, const char *mode, const char *done, QObject *parent) :
QObject(parent), d_ptr(d) {
+ d_ptr->q_ptr = this;
d_ptr->id = d_ptr->modeId(mode);
d_ptr->previewImageHandler = new PreviewImageHandler(this, this);
- d_ptr->doneHandler = new DoneHandler(this, done, this);
+ d_ptr->doneHandler = new DoneHandler(d_ptr, done, this);
}
QtCamMode::~QtCamMode() {
// TODO: check that we can actually do it. Perhaps the pipeline is busy.
g_object_set(d_ptr->dev->cameraBin, "mode", d_ptr->id, NULL);
- // TODO: is that needed ?
- // d_ptr->dev->resetCapabilities();
-
d_ptr->dev->listener->addHandler(d_ptr->previewImageHandler);
d_ptr->dev->listener->addHandler(d_ptr->doneHandler);
return d_ptr->dev->active == this;
}
-void QtCamMode::setPreviewSize(const QSize& size) {
- if (!d_ptr->dev->cameraBin) {
- return;
- }
-
- if (size.width() <= 0 && size.height() <= 0) {
- g_object_set(d_ptr->dev->cameraBin, "preview-caps", NULL, "post-previews", FALSE, NULL);
- }
- else {
- QString preview = QString(PREVIEW_CAPS).arg(size.width()).arg(size.height());
-
- GstCaps *caps = gst_caps_from_string(preview.toAscii());
-
- g_object_set(d_ptr->dev->cameraBin, "preview-caps", caps, "post-previews", TRUE, NULL);
-
- gst_caps_unref(caps);
- }
-}
-
-void QtCamMode::setFileName(const QString& fileName) {
- d_ptr->doneHandler->fileName = fileName;
-}
-
QtCamDevice *QtCamMode::device() const {
return d_ptr->dev->q_ptr;
}
virtual void start() = 0;
virtual void stop() = 0;
- // TODO: move this from here
- void setPreviewSize(const QSize& size);
-
- // TODO: move this from here
- void setFileName(const QString& fileName);
-
QtCamModePrivate *d_ptr;
};
#endif /* GST_USE_UNSTABLE_API */
#include <gst/interfaces/photography.h>
+#define PREVIEW_CAPS "video/x-raw-rgb, width = (int) %1, height = (int) %2, bpp = (int) 32, depth = (int) 24, red_mask = (int) 65280, green_mask = (int) 16711680, blue_mask = (int) -16777216"
+
class QtCamDevicePrivate;
class PreviewImageHandler;
class DoneHandler;
return -1;
}
- GParamSpecEnum *e = (GParamSpecEnum *)pspec;
+ GParamSpecEnum *e = G_PARAM_SPEC_ENUM(pspec);
GEnumClass *klass = e->enum_class;
for (unsigned x = 0; x < klass->n_values; x++) {
}
}
+ void setPreviewSize(const QSize& size) {
+ if (!dev->cameraBin) {
+ return;
+ }
+
+ if (size.width() <= 0 && size.height() <= 0) {
+ g_object_set(dev->cameraBin, "preview-caps", NULL, "post-previews", FALSE, NULL);
+ }
+ else {
+ QString preview = QString(PREVIEW_CAPS).arg(size.width()).arg(size.height());
+
+ GstCaps *caps = gst_caps_from_string(preview.toAscii());
+
+ g_object_set(dev->cameraBin, "preview-caps", caps, "post-previews", TRUE, NULL);
+
+ gst_caps_unref(caps);
+ }
+ }
+
+ void setFileName(const QString& file) {
+ fileName = file;
+ }
+
int id;
+ QtCamMode *q_ptr;
QtCamDevicePrivate *dev;
PreviewImageHandler *previewImageHandler;
DoneHandler *doneHandler;
+ QString fileName;
};
#endif /* QT_CAM_MODE_P_H */
}
}
- // TODO: Use signals from QtCamNotifications instead ?
QObject::connect(d_ptr->dev->q_ptr, SIGNAL(idleStateChanged(bool)),
this, SLOT(_d_idleStateChanged(bool)));
}
d_ptr->setCaps("video-capture-caps", d->resolution.captureResolution(), fps);
- setPreviewSize(d->resolution.previewResolution());
+ d_ptr->setPreviewSize(d->resolution.previewResolution());
// Not sure this is needed but just in case.
d_ptr->resetCaps("image-capture-caps");
return false;
}
- setFileName(fileName);
+ d_ptr->setFileName(fileName);
QMetaObject::invokeMethod(d_ptr->dev->notifications, "videoRecordingStarted");
QtCamZoom::QtCamZoom(QtCamDevice *dev, QObject *parent) :
QtCamCapability(new QtCamZoomPrivate(dev, this), parent) {
- ((QtCamZoomPrivate *) d_ptr)->init();
+ dynamic_cast<QtCamZoomPrivate *>(d_ptr)->init();
}
QtCamZoom::~QtCamZoom() {
}
qreal QtCamZoom::value() {
- return ((QtCamZoomPrivate *) d_ptr)->zoom();
+ return dynamic_cast<QtCamZoomPrivate *>(d_ptr)->zoom();
}
bool QtCamZoom::setValue(qreal zoom) {
- if (((QtCamZoomPrivate *) d_ptr)->setZoom(zoom)) {
+ if (dynamic_cast<QtCamZoomPrivate *>(d_ptr)->setZoom(zoom)) {
emit valueChanged();
return true;
}
}
qreal QtCamZoom::minimumValue() {
+ // TODO: hardcoded
return 1.0;
}
qreal QtCamZoom::maximumValue() {
- return ((QtCamZoomPrivate *) d_ptr)->maxZoom();
+ return dynamic_cast<QtCamZoomPrivate *>(d_ptr)->maxZoom();
}
}
Rectangle {
- // TODO: color
// TODO: fade out transition
- // TODO: there is a toolbar visible on the first startup
id: standby
color: "black"
anchors.fill: parent