During the summer I gave a look to the Camera 2 API, and here are some complements to the information @vlagged provided.
The main purpose of the task is to replace the underlying implementation of droidmedia
with a Camera 2 API. But as a simpler target, I just tried to take a picture from Sailfish OS side, using a Camera 2 API function in droidmedia
.
The first step is to compile the Android side of droidmedia
. For this, I followed part of this tutorial: Sailfish X Xperia Android 10 Build and Flash | Sailfish OS Documentation namely
repo init -u https://github.com/mer-hybris/android.git -b $HAVERSION -m tagged-localbuild.xml
repo sync -jX --fetch-submodules
git clone --recurse-submodules https://github.com/mer-hybris/droid-src-sony droid-src -b "hybris-"$HAVERSION
ln -s droid-src/patches
droid-src/apply-patches.sh --mb
./setup-sources.sh --mb
source build/envsetup.sh
lunch aosp_$DEVICE-user
git clone https://github.com/sailfishos/droidmedia external/droidmedia
make libdroidmedia
This creates a library libdroidmedia.so
under out/target/product/$HABUILD_DEVICE/system/lib64/libdroidmedia.so
. I copy this library to a user directory on the phone (let’s call it devel
).
The second step is to compile the libhybris glue of droidmedia
for Sailfish OS side of things. I followed these steps in the SDK docker:
cd external/droimedia
mb2 -t SailfishOS-4.5-aarch64 -s rpm/droidmedia-devel.spec build
sb2 -t SailfishOS-4.5-aarch64.default -R rpm -U --force RPMS/droidmedia-devel-0.20170214.0-1.aarch64.rpm
This compile and install the libhybris glue in the SDK. I’ll use it later to compile a simple executable that is supposed to tkae a picture.
This small executable is made of the following main:
#include <QtQuick>
#include <QDebug>
#include <droidmediacamera2.h>
#include <sailfishapp.h>
void plop()
{
qDebug() << droid_media_camera2_get_number_of_cameras();
}
int main(int argc, char *argv[])
{
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
app->setOrganizationName("Demo");
app->setApplicationName("Sextant");
plop();
DroidMediaCamera2 *camera = droid_media_camera2_connect(1);
if (camera) {
qDebug() << droid_media_camera2_take_picture(camera);
//droid_media_camera2_disconnect(camera);
}
QScopedPointer<QQuickView> view(SailfishApp::createView());
view->setSource(SailfishApp::pathToMainQml());
view->show();
return app->exec();
}
As you see, it is calling a new droidmedia function droid_media_camera2_get_number_of_cameras()
testing the listing of cameras and then calling droid_media_camera2_connect(1)
to connect to the second listed camera and finally call droid_media_camera2_take_picture(camera)
to shot a picture. These functions are basically the same than the currently existing ones, except that they are supposed to use a Camera 2 API.
I implemented these functions in droidmedia
, see my branch GitHub - dcaliste/droidmedia at camera2, following various sources like android.hardware.camera2 | Android Developers or https://github.com/justinjoy/native-camera2/blob/master/app/src/main/jni/native-camera2-jni.cpp
To run the executable (called sextant
here), I compile it within the SDK, using my new libhybris glue from my droidmedia
branch and send it to the phone under the same devel
directory. To run it, one needs to export the devel
directory as a source for hybris libraries:
cd devel
HYBRIS_LD_LIBRARY_PATH=$PWD:/usr/libexec/droid-hybris/system/lib64 ./sextant
What is working: the listing of cameras and their characteristics. What is not working: shooting a picture :(( The Camera2 functions are not reporting any error as far as I know. It is reporting that the session is ready. But nothing happens.
So I’m stuck there. Since the Camera 2 implementation is open source in Android, I added some debug messages here and there, but was not able to understand what was wrong.