X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lib%2Fqtcamvideomode.cpp;h=762c108de0d6e125814b36d170d508fd0b7cc19c;hb=bbaadb8139399ca7d6088bf8ff69fa487eae57bd;hp=9573226f3f788ccbc9e31529a4cb1188e7514b8f;hpb=b5d64ba56b64a176af1c1d54c9a846c2d54358df;p=harmattan%2Fcameraplus diff --git a/lib/qtcamvideomode.cpp b/lib/qtcamvideomode.cpp index 9573226..762c108 100644 --- a/lib/qtcamvideomode.cpp +++ b/lib/qtcamvideomode.cpp @@ -1,7 +1,7 @@ /*! * This file is part of CameraPlus. * - * Copyright (C) 2012 Mohammed Sameer + * Copyright (C) 2012-2013 Mohammed Sameer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -25,6 +25,8 @@ #include "qtcamdevice.h" #include "qtcamvideosettings.h" #include "qtcamnotifications.h" +#include +#include class QtCamVideoModePrivate : public QtCamModePrivate { public: @@ -50,8 +52,53 @@ public: QtCamVideoResolution resolution; }; +class VideoDoneHandler : public DoneHandler { +public: + VideoDoneHandler(QtCamModePrivate *d, QObject *parent = 0) : + DoneHandler(d, "video-done", parent), m_done(false) {} + + virtual void handleMessage(GstMessage *message) { + DoneHandler::handleMessage(message); + wake(); + } + + void lock() { + m_mutex.lock(); + } + + void unlock() { + m_mutex.unlock(); + } + + void wait() { + m_cond.wait(&m_mutex); + } + + void reset() { + m_done = false; + } + + bool isDone() { + return m_done; + } + +private: + void wake() { + lock(); + m_done = true; + m_cond.wakeOne(); + unlock(); + } + + bool m_done; + QMutex m_mutex; + QWaitCondition m_cond; +}; + QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) : - QtCamMode(new QtCamVideoModePrivate(dev), "mode-video", "video-done", parent) { + QtCamMode(new QtCamVideoModePrivate(dev), "mode-video", parent) { + + d_ptr->init(new VideoDoneHandler(d_ptr, this)); d = (QtCamVideoModePrivate *)QtCamMode::d_ptr; @@ -93,12 +140,12 @@ void QtCamVideoMode::applySettings() { } void QtCamVideoMode::start() { - // Nothing + d_ptr->disableViewfinderFilters(); } void QtCamVideoMode::stop() { if (isRecording()) { - stopRecording(); + stopRecording(true); } } @@ -125,6 +172,9 @@ bool QtCamVideoMode::startRecording(const QString& fileName, const QString& tmpF g_object_set(d_ptr->dev->cameraBin, "location", file.toUtf8().data(), NULL); g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL); + VideoDoneHandler *handler = dynamic_cast(d_ptr->doneHandler); + handler->reset(); + emit recordingStateChanged(); emit canCaptureChanged(); @@ -132,9 +182,24 @@ bool QtCamVideoMode::startRecording(const QString& fileName, const QString& tmpF return true; } -void QtCamVideoMode::stopRecording() { +void QtCamVideoMode::stopRecording(bool sync) { if (isRecording()) { + VideoDoneHandler *handler = dynamic_cast(d_ptr->doneHandler); + if (sync) { + handler->lock(); + + if (handler->isDone()) { + handler->unlock(); + return; + } + } + g_signal_emit_by_name(d_ptr->dev->cameraBin, "stop-capture", NULL); + + if (sync) { + handler->wait(); + handler->unlock(); + } } } @@ -170,4 +235,8 @@ QtCamVideoSettings *QtCamVideoMode::settings() { return d->settings; } +QtCamVideoResolution QtCamVideoMode::currentResolution() { + return d->resolution; +} + #include "moc_qtcamvideomode.cpp"