This is to avoid tracker indexing the video being recorded and waste CPU time.
The problem with tracker is it keeps getting update events because the file is
being written to. Tracker will ignore them but that still wastes CPU.
}
-bool VideoMode::startRecording(const QString& fileName) {
- return m_video ? m_video->startRecording(fileName) : false;
+bool VideoMode::startRecording(const QString& fileName, const QString& tmpFileName) {
+ return m_video ? m_video->startRecording(fileName, tmpFileName) : false;
}
void VideoMode::stopRecording() {
VideoMode(QObject *parent = 0);
~VideoMode();
- Q_INVOKABLE bool startRecording(const QString& fileName);
+ Q_INVOKABLE bool startRecording(const QString& fileName, const QString& tmpFileName);
bool isRecording();
#include "qtcamgstreamermessagelistener.h"
#include <gst/video/video.h>
#include <QImage>
+#include <QFile>
class PreviewImageHandler : public QtCamGStreamerMessageHandler {
public:
if (gst_structure_has_field(s, "filename")) {
const char *str = gst_structure_get_string(s, "filename");
if (str) {
- mode->fileName = QString::fromUtf8(str);
+ mode->tempFileName = QString::fromUtf8(str);
+ }
+ }
+
+ if (mode->fileName.isEmpty()) {
+ mode->fileName = mode->tempFileName;
+ }
+
+ if (!mode->tempFileName.isEmpty() && !mode->fileName.isEmpty() &&
+ mode->tempFileName != mode->fileName) {
+ if (!QFile::rename(mode->tempFileName, mode->fileName)) {
+ qCritical() << "Failed to rename" << mode->tempFileName << "to" << mode->fileName;
}
}
void setFileName(const QString& file) {
fileName = file;
}
+ void setTempFileName(const QString& file) {
+ tempFileName = file;
+ }
int id;
QtCamMode *q_ptr;
PreviewImageHandler *previewImageHandler;
DoneHandler *doneHandler;
QString fileName;
+ QString tempFileName;
};
#endif /* QT_CAM_MODE_P_H */
return !d_ptr->dev->q_ptr->isIdle();
}
-bool QtCamVideoMode::startRecording(const QString& fileName) {
+bool QtCamVideoMode::startRecording(const QString& fileName, const QString& tmpFileName) {
if (!canCapture() || isRecording()) {
return false;
}
}
d_ptr->setFileName(fileName);
+ d_ptr->setTempFileName(tmpFileName);
+
+ QString file = tmpFileName.isEmpty() ? fileName : tmpFileName;
QMetaObject::invokeMethod(d_ptr->dev->notifications, "videoRecordingStarted");
- g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
+ g_object_set(d_ptr->dev->cameraBin, "location", file.toUtf8().data(), NULL);
g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
emit recordingStateChanged();
virtual void applySettings();
bool isRecording();
- Q_INVOKABLE bool startRecording(const QString& fileName);
+
+ bool startRecording(const QString& fileName, const QString& tmpFileName = QString());
bool setResolution(const QtCamVideoResolution& resolution);
}
- if (!videoMode.startRecording(fileNaming.videoFileName())) {
+ if (!videoMode.startRecording(fileNaming.videoFileName(),
+ fileNaming.temporaryVideoFileName())) {
showError(qsTr("Failed to record video. Please restart the camera."));
policyMode = CameraResources.Video
}
// TODO: flash not ready
// TODO: focus, caf, ...
// TODO: portrait/landscape
-// TODO: record video in a hidden directory and then copy the video to avoid tracker indexing it.
// TODO: stop viewfinder in settings pages ?
// TODO: grid lines, face tracking, ambr
// TODO: complete settings pages
#include <QFile>
#define PATH QString("%1%2MyDocs%2cameraplus%2").arg(QDir::homePath()).arg(QDir::separator())
+#define TEMP_PATH QString("%1%2MyDocs%2.cameraplus%2").arg(QDir::homePath()).arg(QDir::separator())
FileNaming::FileNaming(QObject *parent) :
QObject(parent) {
QString FileNaming::path() const {
return PATH;
}
+
+QString FileNaming::temporaryVideoFileName() {
+ if (!QDir::root().mkpath(TEMP_PATH)) {
+ qWarning() << "Failed to create temporary path" << TEMP_PATH;
+ return QString();
+ }
+
+ return QString("%1.cameraplus_video.tmp").arg(TEMP_PATH);
+}
Q_INVOKABLE QString imageFileName();
Q_INVOKABLE QString videoFileName();
+ Q_INVOKABLE QString temporaryVideoFileName();
QString path() const;