Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
SUPER HACK! completly recreate camera hal to restart preview (hammerh…
Browse files Browse the repository at this point in the history
…ead)

This is a masive SUPER HACK! it completly destroy and recreate camera
hal to restart preview. ¯\_(ツ)_/¯

Kinda fixes: ubports/ubuntu-touch#611
  • Loading branch information
mariogrip committed Dec 21, 2019
1 parent 9014b4e commit b9204c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/aalimagecapturecontrol.cpp
Expand Up @@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "aalcameracontrol.h"
#include "aalcameraservice.h"
#include "aalimagecapturecontrol.h"
#include "aalimageencodercontrol.h"
Expand All @@ -26,6 +27,8 @@
#include <hybris/camera/camera_compatibility_layer.h>
#include <hybris/camera/camera_compatibility_layer_capabilities.h>

#include <hybris/properties/properties.h>

#include <QDir>
#include <QObject>
#include <QFile>
Expand Down Expand Up @@ -54,6 +57,10 @@ AalImageCaptureControl::AalImageCaptureControl(AalCameraService *service, QObjec
m_audioPlayer->setMedia(QUrl::fromLocalFile("/system/media/audio/ui/camera_click.ogg"));
m_audioPlayer->setAudioRole(QAudio::NotificationRole);

char name[PROP_VALUE_MAX] = "";
property_get("ro.product.device", name, "");
m_deviceName = name;

QObject::connect(&m_storageManager, &StorageManager::previewReady,
this, &AalImageCaptureControl::imageCaptured);
}
Expand Down Expand Up @@ -172,7 +179,13 @@ void AalImageCaptureControl::saveJpeg(const QByteArray& data)

// Restart the viewfinder and notify that the camera is ready to capture again
if (m_service->androidControl()) {
android_camera_start_preview(m_service->androidControl());
// SUPER HACK! completly destroy and recreate camera hal to restart preview
if (m_deviceName == "hammerhead") {
emit m_service->cameraControl()->setState(QCamera::UnloadedState);
emit m_service->cameraControl()->setState(QCamera::ActiveState);
} else {
android_camera_start_preview(m_service->androidControl());
}
}
m_service->updateCaptureReady();

Expand Down
1 change: 1 addition & 0 deletions src/aalimagecapturecontrol.h
Expand Up @@ -80,6 +80,7 @@ private Q_SLOTS:
QString m_galleryPath;
QMediaPlayer *m_audioPlayer;
QSettings m_settings;
std::string m_deviceName;

QMap<DiskWriteWatcher*, int> m_pendingSaveOperations;
};
Expand Down

0 comments on commit b9204c3

Please sign in to comment.