Skip to content

Commit

Permalink
Restored Android JNI and NDK camera plugins, ow working fine.
Browse files Browse the repository at this point in the history
  • Loading branch information
hipersayanX committed Sep 2, 2023
1 parent bbd4096 commit 0ef4a4b
Show file tree
Hide file tree
Showing 18 changed files with 4,712 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libAvKys/Plugins/MultiSrc/src/ndkmedia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ else ()
add_library(MultiSrc_ndkmedia EXCLUDE_FROM_ALL ${SOURCES})
endif ()

set_target_properties(MultiSink_ndkmedia PROPERTIES
set_target_properties(MultiSrc_ndkmedia PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR}/${AKPLUGINSDIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR}/${AKPLUGINSDIR})
add_dependencies(MultiSrc_ndkmedia avkys)
Expand Down
2 changes: 2 additions & 0 deletions libAvKys/Plugins/VideoCapture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ cmake_minimum_required(VERSION 3.16)
project(VideoCapture)

add_subdirectory(src)
add_subdirectory(src/capture/androidcamera)
add_subdirectory(src/capture/dshow)
add_subdirectory(src/capture/libuvc)
add_subdirectory(src/capture/mediafoundation)
add_subdirectory(src/capture/ndkcamera)
add_subdirectory(src/capture/pipewire)
add_subdirectory(src/capture/qtcamera)
add_subdirectory(src/capture/v4l2sys)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Webcamoid, webcam capture application.
# Copyright (C) 2021 Gonzalo Exequiel Pedone
#
# Webcamoid is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Webcamoid is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Webcamoid. If not, see <https://www.gnu.org/licenses/>.
#
# Web-Site: https://webcamoid.github.io/

cmake_minimum_required(VERSION 3.16)

project(VideoCapture_androidcamera)

add_subdirectory(jar)
add_subdirectory(src)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Webcamoid, webcam capture application.
# Copyright (C) 2021 Gonzalo Exequiel Pedone
#
# Webcamoid is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Webcamoid is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Webcamoid. If not, see <https://www.gnu.org/licenses/>.
#
# Web-Site: https://webcamoid.github.io/

cmake_minimum_required(VERSION 3.16)

project(VideoCapture_androidcamerajar)

include(../../../../../../cmake/ProjectCommons.cmake)

set(SOURCES_PREFIX src/org/webcamoid/plugins/VideoCapture/submodules/androidcamera)
set(SOURCES ${SOURCES_PREFIX}/AkAndroidCameraCallbacks.java)

if (ANDROID)
include(UseJava)
find_package(Java ${ANDROID_JAVA_VERSION})

if (Java_FOUND)
set(CMAKE_JAVA_COMPILE_FLAGS "-source" "${ANDROID_JAVA_VERSION}" "-target" "${ANDROID_JAVA_VERSION}")
add_jar(VideoCapture_androidcamerajar
SOURCES ${SOURCES}
INCLUDE_JARS
${ANDROID_JAR_DIRECTORY}/android.jar
OUTPUT_NAME AkVideoCapture_androidcamera
OUTPUT_DIR ${CMAKE_BINARY_DIR}/${BUILDDIR}/${JARDIR})
install_jar(VideoCapture_androidcamerajar DESTINATION ${JARDIR})
endif ()
endif ()

add_custom_target(VideoCapture_androidcamerajar_sources SOURCES ${SOURCES})
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* Webcamoid, webcam capture application.
* Copyright (C) 2019 Gonzalo Exequiel Pedone
*
* Webcamoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Webcamoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Webcamoid. If not, see <https://www.gnu.org/licenses/>.
*
* Web-Site: https://webcamoid.github.io/
*/

package org.webcamoid.plugins.VideoCapture.submodules.androidcamera;

import android.hardware.Camera;
import android.view.SurfaceHolder;

public class AkAndroidCameraCallbacks implements Camera.PreviewCallback,
Camera.ShutterCallback,
Camera.PictureCallback,
SurfaceHolder.Callback
{
private long m_userPtr = 0;
private byte[] m_lastPreviewBuffer = null;
private int m_index = 0;

private AkAndroidCameraCallbacks(long userPtr)
{
m_userPtr = userPtr;
}

public void resetPictureIndex()
{
m_index = 0;
}

// Camera.PreviewCallback

@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
// Re-enqueue the last buffer
if (m_lastPreviewBuffer != null)
camera.addCallbackBuffer(m_lastPreviewBuffer);

m_lastPreviewBuffer = data;

if (data != null)
previewFrameReady(m_userPtr, data);
}

// Camera.ShutterCallback

@Override
public void onShutter()
{
shutterActivated(m_userPtr);
}

// Camera.PictureCallback

@Override
public void onPictureTaken(byte[] data, Camera camera)
{
if (data != null)
pictureTaken(m_userPtr, m_index, data);

m_index++;
}

// SurfaceHolder.Callback

@Override
public void surfaceChanged(SurfaceHolder holder,
int format,
int width,
int height)
{
}

@Override
public void surfaceCreated(SurfaceHolder holder)
{
notifySurfaceCreated(m_userPtr);
}

@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
notifySurfaceDestroyed(m_userPtr);
}

private static native void previewFrameReady(long userPtr, byte[] data);
private static native void notifySurfaceCreated(long userPtr);
private static native void notifySurfaceDestroyed(long userPtr);
private static native void shutterActivated(long userPtr);
private static native void pictureTaken(long userPtr,
int index,
byte[] data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Webcamoid, webcam capture application.
# Copyright (C) 2021 Gonzalo Exequiel Pedone
#
# Webcamoid is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Webcamoid is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Webcamoid. If not, see <https://www.gnu.org/licenses/>.
#
# Web-Site: https://webcamoid.github.io/

cmake_minimum_required(VERSION 3.16)

project(VideoCapture_androidcamerasrc LANGUAGES CXX)

include(../../../../../../cmake/ProjectCommons.cmake)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(QT_COMPONENTS
Concurrent
Widgets)

if (ANDROID)
include(UseJava)
find_package(Java ${ANDROID_JAVA_VERSION})
endif ()

find_package(QT NAMES Qt${QT_VERSION_MAJOR} COMPONENTS
${QT_COMPONENTS}
REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} ${QT_MINIMUM_VERSION} COMPONENTS
${QT_COMPONENTS}
REQUIRED)

set(SOURCES
../../../capture.cpp
../../../capture.h
captureandroidcamera.cpp
captureandroidcamera.h
plugin.cpp
plugin.h
pspec.json)

if (ANDROID AND Java_FOUND)
qt_add_plugin(VideoCapture_androidcamerasrc ${SOURCES})
else ()
add_library(VideoCapture_androidcamerasrc SHARED EXCLUDE_FROM_ALL ${SOURCES})
endif ()

set_target_properties(VideoCapture_androidcamerasrc PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR}/${AKPLUGINSDIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BUILDDIR}/${AKPLUGINSDIR})
set_target_properties(VideoCapture_androidcamerasrc PROPERTIES
OUTPUT_NAME VideoCapture_androidcamera)
add_dependencies(VideoCapture_androidcamerasrc avkys)
target_include_directories(VideoCapture_androidcamerasrc
PRIVATE
../../..
../../../../../../Lib/src)
target_compile_definitions(VideoCapture_androidcamerasrc PRIVATE AVKYS_PLUGIN_VIDEOCAPTURE_ANDROIDCAMERA)
list(TRANSFORM QT_COMPONENTS PREPEND Qt${QT_VERSION_MAJOR}:: OUTPUT_VARIABLE QT_LIBS)
target_link_libraries(VideoCapture_androidcamerasrc
PUBLIC
${QT_LIBS}
avkys)

if (ANDROID)
target_link_libraries(VideoCapture_androidcamerasrc
PRIVATE
Qt${QT_VERSION_MAJOR}::CorePrivate)
endif ()

install(TARGETS VideoCapture_androidcamerasrc
LIBRARY DESTINATION ${AKPLUGINSDIR}
RUNTIME DESTINATION ${AKPLUGINSDIR})
Loading

0 comments on commit 0ef4a4b

Please sign in to comment.