Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image capture added #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
* Xabier Rodriguez Calvar <[email protected]>
* Víctor Jáquez <[email protected]>
* Based on the original idea of Jens Wilke <[email protected]>

* Michele Tameni <[email protected]>
50 changes: 34 additions & 16 deletions src/aura.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Contact: Miguel Gómez <[email protected]>
* Xabier Rodriguez Calvar <[email protected]>
* Víctor Jáquez <[email protected]>
* Michele Tameni <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -224,12 +225,42 @@ PageStackWindow {
}
}

Button {
id: cameraShutter
platformStyle: ButtonStyle {
background: "qrc:/resources/shutter-bg.png"
disabledBackground: "qrc:/resources/shutter-bg.png"
pressedBackground: "qrc:/resources/shutter-bg-pressed.png"
textColor: "white"
fontPixelSize: UIConstants.FONT_DEFAULT
fontFamily: UIConstants.FONT_FAMILY
}
anchors {
top: postCapture.bottom
topMargin: 5
right: shutter.left
rightMargin: 10
}
height: 90
width: 100
iconSource: "qrc:/resources/camera-icon.png"
visible: controller.recording ? false: !page.__dialogsVisible
enabled: controller.pipelineReady
opacity: enabled ? 1 : page.__dimmedOpacity
Behavior on opacity { NumberAnimation { duration: page.__animationDuration } }

onClicked: {
controller.cameraShutterClicked()
}
}

Image {
id: timer
anchors {
top: postCapture.bottom
top: shutter.bottom
topMargin: 5
left: postCapture.left
left: shutter.left
leftMargin: 10
}
source: "qrc:/resources/timer-bg.png"
Text {
Expand All @@ -243,20 +274,7 @@ PageStackWindow {
color: "white"
text: controller.recordedTime
}
visible: !page.__dialogsVisible
}

Text {
id: deviceText
anchors {
left: deviceConf.left
bottom: deviceConf.top
}
visible: !controller.recording && !page.__dialogsVisible
font.pixelSize: UIConstants.FONT_DEFAULT
font.family: UIConstants.FONT_FAMILY
color: "white"
text: "Camera"
visible: controller.recording ? !page.__dialogsVisible : false
}

Rectangle {
Expand Down
16 changes: 16 additions & 0 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Contact: Miguel Gómez <[email protected]>
* Xabier Rodriguez Calvar <[email protected]>
* Víctor Jáquez <[email protected]>
* Michele Tameni <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -141,6 +142,16 @@ void Controller::stopRecording()
}
}

void Controller::captureImage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't really need to acquire the recording resources in order to get a pic. That's only needed for video because you need to get the audio recording resources. For pics, you already have the camera and the viewfinder since the app gets launched, so you don't need anything else.

{
if (ResourceManager::instance()->acquireRecordingResources()) {
m_pipeline->captureImage();
} else {
qCritical() << "Recording resources denied";
resourcesLost();
}
}

void Controller::shutterClicked()
{
if (!m_recording) {
Expand All @@ -150,6 +161,11 @@ void Controller::shutterClicked()
}
}

void Controller::cameraShutterClicked()
{
captureImage();
}

void Controller::setResolution(Pipeline::Resolution value)
{
if (m_currentResolution != value) {
Expand Down
3 changes: 3 additions & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Contact: Miguel Gómez <[email protected]>
* Xabier Rodriguez Calvar <[email protected]>
* Víctor Jáquez <[email protected]>
* Michele Tameni <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -94,7 +95,9 @@ public slots:
void pausePipeline();
void startRecording();
void stopRecording();
void captureImage();
void shutterClicked();
void cameraShutterClicked();
void setRecording(bool recording);
void setVideoEffect(const QString &value);
void setColorFilter(const ControllerSettings::ColorFilter value);
Expand Down
45 changes: 43 additions & 2 deletions src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Contact: Miguel Gómez <[email protected]>
* Xabier Rodriguez Calvar <[email protected]>
* Víctor Jáquez <[email protected]>
* Michele Tameni <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -166,9 +167,25 @@ Pipeline::~Pipeline()
gst_object_unref(GST_OBJECT(camerabin));
}

void Pipeline::setCameraMode()
{
currentMode = MODE_IMAGE;
g_object_set(camerabin, "mode", 0, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you use MODE_IMAGE here instead of 0?


// set auto scene mode
gst_photography_set_scene_mode(GST_PHOTOGRAPHY(videoSrc),
GST_PHOTOGRAPHY_SCENE_MODE_AUTO);
// disable autofocus
gst_photography_set_autofocus (GST_PHOTOGRAPHY(videoSrc), FALSE);
// disable flash
g_object_set(videoSrc, "video-torch", FALSE, NULL);

}

void Pipeline::setVideoMode()
{
g_object_set(camerabin, "mode", 1, NULL);
currentMode = MODE_VIDEO;
g_object_set(camerabin, "mode", MODE_VIDEO, NULL);

// set auto scene mode
gst_photography_set_scene_mode(GST_PHOTOGRAPHY(videoSrc),
Expand Down Expand Up @@ -209,6 +226,9 @@ void Pipeline::prepare()

void Pipeline::startRecording()
{
if(currentMode == MODE_IMAGE)
setVideoMode();

currentFile = nextFileName();
emit savedFileNameChanged(currentFile);

Expand All @@ -229,6 +249,27 @@ void Pipeline::stopRecording()
g_signal_emit_by_name(camerabin, "capture-stop", 0);
}

void Pipeline::captureImage()
{
if(currentMode == MODE_VIDEO)
setCameraMode();

currentFile = nextFileName();
emit savedFileNameChanged(currentFile);

// set next file name
g_object_set(camerabin,
"filename",
currentFile.toUtf8().constData(),
NULL);

// write image metadata
writeMetadata();

g_signal_emit_by_name(camerabin, "capture-start", 0);
}


void Pipeline::setResolution(Resolution value)
{
int width, height;
Expand Down Expand Up @@ -436,7 +477,7 @@ QString Pipeline::nextFileName()
int index = dir.count() + 1;

QString filename(APP_FOLDER);
filename += QDir::separator() + QString("%1_%2.%3").arg(date).arg(index).arg(FILE_SUFFIX);
filename += QDir::separator() + QString("%1_%2.%3").arg(date).arg(index).arg((currentMode==MODE_VIDEO) ? VIDEO_FILE_SUFFIX : IMAGE_FILE_SUFFIX);
return filename;
}

Expand Down
11 changes: 10 additions & 1 deletion src/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Contact: Miguel Gómez <[email protected]>
* Xabier Rodriguez Calvar <[email protected]>
* Víctor Jáquez <[email protected]>
* Michele Tameni <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -58,6 +59,7 @@ class Pipeline : public QObject
Pipeline(QObject *parent = 0);
~Pipeline();
void setupFileStorage();
void setCameraMode();
void setVideoMode();
void setResolution(const Resolution value);
void setZoom(const double value);
Expand All @@ -70,6 +72,7 @@ class Pipeline : public QObject
void prepare();
void startRecording();
void stopRecording();
void captureImage();
void setWindowId(int winId);
void handleBusMessage(GstMessage *message);
bool isIdle();
Expand All @@ -84,7 +87,6 @@ class Pipeline : public QObject
QString nextFileName();
void setupEffectBins();
void writeMetadata();

GstElement *camerabin;
GstElement *videoSrc;
GstElement *viewfinder;
Expand All @@ -100,5 +102,12 @@ class Pipeline : public QObject
int windowId;
QSystemDeviceInfo systemInfo;
QString currentFile;

typedef enum {
MODE_IMAGE,
MODE_VIDEO
} videoMode;
int currentMode;

};
#endif
1 change: 1 addition & 0 deletions src/res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<file>resources/switch-bg.png</file>
<file>resources/switch-handle.png</file>
<file>resources/switch-handle-pressed.png</file>
<file>resources/camera-icon.png</file>
</qresource>
</RCC>
Binary file added src/resources/camera-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

#define INTERNAL_EMMC_PATH "/home/user/MyDocs"
#define APP_FOLDER INTERNAL_EMMC_PATH"/aura"
#define FILE_SUFFIX "mp4"
#define VIDEO_FILE_SUFFIX "mp4"
#define IMAGE_FILE_SUFFIX "jpg"

// zoom
#define ZOOM_MIN 1.0
Expand Down