X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lib%2Fqtcamdevice.cpp;h=a8e180c1c4cc3353f845b9003cff1ab39d720537;hb=a7492b6f99baf0c2439dfefc34e453d1a1490230;hp=793eefa7e37a5165212c74f9f590ef792e8dae35;hpb=a13778c44e8589a1f16be56a6ce288e4da81928f;p=harmattan%2Fcameraplus diff --git a/lib/qtcamdevice.cpp b/lib/qtcamdevice.cpp index 793eefa..a8e180c 100644 --- a/lib/qtcamdevice.cpp +++ b/lib/qtcamdevice.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 @@ -29,13 +29,20 @@ #include "qtcamimagemode.h" #include "qtcamvideomode.h" #include "qtcamnotifications.h" - -// TODO: we want the ability to change the image and video gep from the app. +#include "gst/gstcopy.h" +#include "qtcampropertysetter.h" +#include "qtcamanalysisbin.h" QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name, const QVariant& id, QObject *parent) : QObject(parent), d_ptr(new QtCamDevicePrivate) { + static gboolean register_copy = TRUE; + if (register_copy) { + qt_cam_copy_register(); + register_copy = FALSE; + } + d_ptr->q_ptr = this; d_ptr->name = name; d_ptr->id = id; @@ -47,8 +54,18 @@ QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name, return; } + d_ptr->propertySetter = new QtCamPropertySetter(d_ptr); + d_ptr->createAndAddElement(d_ptr->conf->audioSource(), "audio-source", "QtCameraAudioSrc"); - d_ptr->createAndAddVideoSource(); + if (!d_ptr->conf->wrapperVideoSource().isEmpty() && + !d_ptr->conf->wrapperVideoSourceProperty().isEmpty()) { + d_ptr->createAndAddVideoSourceAndWrapper(); + } + else { + d_ptr->createAndAddVideoSource(); + } + + d_ptr->setDevicePoperty(); int flags = 0x00000001 /* no-audio-conversion - Do not use audio conversion elements */ @@ -60,11 +77,19 @@ QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name, d_ptr->setAudioCaptureCaps(); - // TODO: audio bitrate - // TODO: video bitrate - // TODO: filters - // TODO: capabilities - // TODO: custom properties for jifmux, mp4mux, audio encoder, video encoder, sink & video source + QStringList viewfinderFilters = d_ptr->conf->viewfinderFilters(); + if (!viewfinderFilters.isEmpty()) { + d_ptr->viewfinderFilters = + QtCamAnalysisBin::create(viewfinderFilters, "QtCamViewfinderFilters"); + + if (!d_ptr->viewfinderFilters) { + qWarning() << "Failed to create viewfinder filters"; + } + else { + g_object_set(d_ptr->cameraBin, "viewfinder-filter", d_ptr->viewfinderFilters->bin(), NULL); + } + } + d_ptr->listener = new QtCamGStreamerMessageListener(gst_element_get_bus(d_ptr->cameraBin), d_ptr, this); @@ -77,8 +102,14 @@ QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name, g_signal_connect(d_ptr->cameraBin, "notify::idle", G_CALLBACK(QtCamDevicePrivate::on_idle_changed), d_ptr); - g_signal_connect(d_ptr->wrapperVideoSource, "notify::ready-for-capture", - G_CALLBACK(QtCamDevicePrivate::on_ready_for_capture_changed), d_ptr); + if (d_ptr->wrapperVideoSource) { + g_signal_connect(d_ptr->wrapperVideoSource, "notify::ready-for-capture", + G_CALLBACK(QtCamDevicePrivate::on_ready_for_capture_changed), d_ptr); + } + else { + g_signal_connect(d_ptr->videoSource, "notify::ready-for-capture", + G_CALLBACK(QtCamDevicePrivate::on_ready_for_capture_changed), d_ptr); + } d_ptr->image = new QtCamImageMode(d_ptr, this); d_ptr->video = new QtCamVideoMode(d_ptr, this); @@ -87,7 +118,7 @@ QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name, } QtCamDevice::~QtCamDevice() { - stop(); + stop(true); d_ptr->image->deactivate(); d_ptr->video->deactivate(); @@ -95,6 +126,10 @@ QtCamDevice::~QtCamDevice() { delete d_ptr->image; d_ptr->image = 0; delete d_ptr->video; d_ptr->video = 0; + delete d_ptr->propertySetter; + + delete d_ptr->viewfinderFilters; + if (d_ptr->cameraBin) { gst_object_unref(d_ptr->cameraBin); } @@ -131,6 +166,10 @@ bool QtCamDevice::setViewfinder(QtCamViewfinder *viewfinder) { return true; } +QtCamViewfinder *QtCamDevice::viewfinder() const { + return d_ptr->viewfinder; +} + bool QtCamDevice::start() { if (d_ptr->error) { qWarning() << "Pipeline must be stopped first because of an error."; @@ -192,7 +231,7 @@ bool QtCamDevice::start() { return true; } -bool QtCamDevice::stop() { +bool QtCamDevice::stop(bool force) { if (!d_ptr->cameraBin) { return true; } @@ -200,6 +239,9 @@ bool QtCamDevice::stop() { if (d_ptr->error) { gst_element_set_state(d_ptr->cameraBin, GST_STATE_NULL); d_ptr->error = false; + + d_ptr->viewfinder->stop(); + return true; } @@ -212,11 +254,11 @@ bool QtCamDevice::stop() { } if (!isIdle()) { - return false; + if (!force) { + return false; + } } - d_ptr->viewfinder->stop(); - // First we go to ready: GstStateChangeReturn st = gst_element_set_state(d_ptr->cameraBin, GST_STATE_READY); if (st != GST_STATE_CHANGE_FAILURE) { @@ -227,6 +269,8 @@ bool QtCamDevice::stop() { // Now to NULL gst_element_set_state(d_ptr->cameraBin, GST_STATE_NULL); + d_ptr->viewfinder->stop(); + return true; }