Merge branch 'android-hardware-camera'

This branch adds support for Android Hardware Camera API through a new
element called ahcsrc. This is the "old" Android Camera API, then only
API available on Android 4.X.

https://bugzilla.gnome.org/show_buf.cgi?id=737786
This commit is contained in:
Nicolas Dufresne 2016-01-21 13:50:44 -05:00
commit 2193fa8ffe
13 changed files with 7370 additions and 9 deletions

View file

@ -0,0 +1,28 @@
<plugin>
<name>androidcamera</name>
<description>Capture from Android cameras</description>
<filename>../../sys/androidcamera/.libs/libgstandroidcamera.so</filename>
<basename>libgstandroidcamera.so</basename>
<version>0.10.22.1</version>
<license>LGPL</license>
<source>gst-plugins-bad</source>
<package>GStreamer Bad Plug-ins git</package>
<origin>Unknown package origin</origin>
<elements>
<element>
<name>ahcsrc</name>
<longname>Android Camera Source</longname>
<class>Source/Video</class>
<description>Reads frames from android.hardware.Camera class into buffers</description>
<author>Youness Alaoui &lt;youness.alaoui@collabora.co.uk&gt;</author>
<pads>
<caps>
<name>src</name>
<direction>source</direction>
<presence>always</presence>
<details>video/x-raw-yuv, format=(fourcc) { YV12 , YUY2 , NV21 , NV16 }, width=(int) [ 1, 2147483647 ], height=(int) [ 1, 2147483647 ], framerate=(fraction) [ 0/1, 2147483647/1 ]; video/x-raw-rgb, bpp=(int)16, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, width=(int) [ 1, 2147483647 ], height=(int) [ 1, 2147483647 ], framerate=(fraction) [ 0/1, 2147483647/1 ] </details>
</caps>
</pads>
</element>
</elements>
</plugin>

View file

@ -1,22 +1,30 @@
plugin_LTLIBRARIES = libgstandroidmedia.la
libgstandroidmedia_la_SOURCES = \
gstamc.c \
gstahcsrc.c \
gstamcaudiodec.c \
gstamcvideodec.c \
gstamcvideoenc.c \
gstamc.c \
gstamcsurface.c \
gstamcsurfacetexture.c \
gstamcvideodec.c \
gstamcvideoenc.c \
gst-android-graphics-imageformat.c \
gst-android-graphics-surfacetexture.c \
gst-android-hardware-camera.c \
gstjniutils.c
noinst_HEADERS = \
gstamc.h \
gstamc-constants.h \
gstahcsrc.h \
gstamcaudiodec.h \
gstamcvideodec.h \
gstamcvideoenc.h \
gstamc-constants.h \
gstamc.h \
gstamcsurface.h \
gstamcsurfacetexture.h \
gstamcvideodec.h \
gstamcvideoenc.h \
gst-android-graphics-imageformat.h \
gst-android-graphics-surfacetexture.h \
gst-android-hardware-camera.h \
gstjniutils.h
libgstandroidmedia_la_CFLAGS = \
@ -25,8 +33,11 @@ libgstandroidmedia_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(GST_CFLAGS) \
$(ORC_CFLAGS)
$(ORC_CFLAGS) \
-DGST_USE_UNSTABLE_API
libgstandroidmedia_la_LIBADD = \
$(top_builddir)/gst-libs/gst/interfaces/libgstphotography-$(GST_API_VERSION).la \
$(top_builddir)/gst-libs/gst/gl/libgstgl-$(GST_API_VERSION).la \
$(GST_PLUGINS_BASE_LIBS) \
-lgstaudio-@GST_API_VERSION@ \
@ -39,4 +50,6 @@ libgstandroidmedia_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstandroidmedia_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
androidmedia_java_classesdir = $(datadir)/gst-android/ndk-build/androidmedia/
androidmedia_java_classes_DATA = org/freedesktop/gstreamer/androidmedia/GstAmcOnFrameAvailableListener.java
androidmedia_java_classes_DATA = \
org/freedesktop/gstreamer/androidmedia/GstAhcCallback.java \
org/freedesktop/gstreamer/androidmedia/GstAmcOnFrameAvailableListener.java

View file

@ -0,0 +1,192 @@
/*
* Copyright (C) 2012, Collabora Ltd.
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstjniutils.h"
#include "gst-android-graphics-imageformat.h"
static struct
{
jclass klass;
jmethodID get_bits_per_pixel;
jint JPEG;
jint NV16;
jint NV21;
jint RGB_565;
jint UNKNOWN;
jint YUY2;
jint YV12;
} android_graphics_imageformat = {
0};
gint ImageFormat_JPEG;
gint ImageFormat_NV16;
gint ImageFormat_NV21;
gint ImageFormat_RGB_565;
gint ImageFormat_UNKNOWN;
gint ImageFormat_YUY2;
gint ImageFormat_YV12;
static gboolean
_init_classes (void)
{
JNIEnv *env;
jfieldID fieldID;
jclass klass;
GError *err = NULL;
env = gst_amc_jni_get_env ();
/* android.graphics.ImageFormat */
klass = android_graphics_imageformat.klass =
gst_amc_jni_get_class (env, &err, "android/graphics/ImageFormat");
if (err)
goto failed;
android_graphics_imageformat.get_bits_per_pixel =
gst_amc_jni_get_static_method_id (env, &err, klass,
"getBitsPerPixel", "(I)I");
if (err)
goto failed;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "JPEG", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.JPEG))
goto failed;
ImageFormat_JPEG = android_graphics_imageformat.JPEG;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "NV16", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.NV16))
goto failed;
ImageFormat_NV16 = android_graphics_imageformat.NV16;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "NV21", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.NV21))
goto failed;
ImageFormat_NV21 = android_graphics_imageformat.NV21;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "RGB_565", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.RGB_565))
goto failed;
ImageFormat_RGB_565 = android_graphics_imageformat.RGB_565;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "UNKNOWN", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.UNKNOWN))
goto failed;
ImageFormat_UNKNOWN = android_graphics_imageformat.UNKNOWN;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "YUY2", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.YUY2))
goto failed;
ImageFormat_YUY2 = android_graphics_imageformat.YUY2;
fieldID = gst_amc_jni_get_static_field_id (env, &err, klass, "YV12", "I");
if (err)
goto failed;
if (!gst_amc_jni_get_static_int_field (env, &err, klass, fieldID,
&android_graphics_imageformat.YV12))
goto failed;
ImageFormat_YV12 = android_graphics_imageformat.YV12;
return TRUE;
failed:
if (err) {
GST_ERROR ("Failed to get android.graphics.ImageFormat class: %s",
err->message);
g_clear_error (&err);
}
return FALSE;
}
gboolean
gst_android_graphics_imageformat_init (void)
{
if (!_init_classes ()) {
gst_android_graphics_imageformat_deinit ();
return FALSE;
}
return TRUE;
}
void
gst_android_graphics_imageformat_deinit (void)
{
JNIEnv *env = gst_amc_jni_get_env ();
if (android_graphics_imageformat.klass)
(*env)->DeleteGlobalRef (env, android_graphics_imageformat.klass);
android_graphics_imageformat.klass = NULL;
}
/* android.graphics.ImageFormat */
gint
gst_ag_imageformat_get_bits_per_pixel (gint format)
{
JNIEnv *env;
GError *err = NULL;
jclass klass = android_graphics_imageformat.klass;
jint bpp = 0;
env = gst_amc_jni_get_env ();
if (!gst_amc_jni_call_static_int_method (env, &err,
klass, android_graphics_imageformat.get_bits_per_pixel, &bpp, format)) {
GST_ERROR ("Failed to get android.graphics.ImageFormat class: %s",
err->message);
g_clear_error (&err);
}
return bpp;
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (C) 2012, Collabora Ltd.
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __GST_ANDROID_GRAPHICS_IMAGEFORMAT_H__
#define __GST_ANDROID_GRAPHICS_IMAGEFORMAT_H__
#include <gst/gst.h>
G_BEGIN_DECLS
/* android.graphics.ImageFormat */
extern gint ImageFormat_JPEG;
extern gint ImageFormat_NV16;
extern gint ImageFormat_NV21;
extern gint ImageFormat_RGB_565;
extern gint ImageFormat_UNKNOWN;
extern gint ImageFormat_YUY2;
extern gint ImageFormat_YV12;
gboolean gst_android_graphics_imageformat_init (void);
void gst_android_graphics_imageformat_deinit (void);
gint gst_ag_imageformat_get_bits_per_pixel (gint format);
G_END_DECLS
#endif /* __GST_ANDROID_GRAPHICS_IMAGEFORMAT_H__ */

View file

@ -0,0 +1,144 @@
/*
* Copyright (C) 2012, Collabora Ltd.
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstjniutils.h"
#include "gst-android-graphics-surfacetexture.h"
static struct
{
jclass klass;
jmethodID constructor;
jmethodID release;
} android_graphics_surfacetexture = {
0};
static gboolean
_init_classes (void)
{
JNIEnv *env;
GError *err = NULL;
env = gst_amc_jni_get_env ();
/* android.graphics.SurfaceTexture */
android_graphics_surfacetexture.klass =
gst_amc_jni_get_class (env, &err, "android/graphics/SurfaceTexture");
if (!android_graphics_surfacetexture.klass) {
GST_ERROR ("Failed to get android.graphics.SurfaceTexture class: %s",
err->message);
g_clear_error (&err);
return FALSE;
}
android_graphics_surfacetexture.constructor =
gst_amc_jni_get_method_id (env, &err,
android_graphics_surfacetexture.klass, "<init>", "(I)V");
android_graphics_surfacetexture.release =
gst_amc_jni_get_method_id (env, &err,
android_graphics_surfacetexture.klass, "release", "()V");
return TRUE;
}
gboolean
gst_android_graphics_surfacetexture_init (void)
{
if (!_init_classes ()) {
gst_android_graphics_surfacetexture_deinit ();
return FALSE;
}
return TRUE;
}
void
gst_android_graphics_surfacetexture_deinit (void)
{
JNIEnv *env = gst_amc_jni_get_env ();
if (android_graphics_surfacetexture.klass)
(*env)->DeleteGlobalRef (env, android_graphics_surfacetexture.klass);
android_graphics_surfacetexture.klass = NULL;
}
/* android.graphics.SurfaceTexture */
GstAGSurfaceTexture *
gst_ag_surfacetexture_new (gint texture_id)
{
JNIEnv *env = gst_amc_jni_get_env ();
jobject object = NULL;
GstAGSurfaceTexture *tex = NULL;
object = (*env)->NewObject (env,
android_graphics_surfacetexture.klass,
android_graphics_surfacetexture.constructor, texture_id);
if ((*env)->ExceptionCheck (env) || !object) {
GST_ERROR ("Failed to call Java method");
(*env)->ExceptionClear (env);
return NULL;
}
tex = g_slice_new0 (GstAGSurfaceTexture);
tex->object = (*env)->NewGlobalRef (env, object);
if (!tex->object) {
GST_ERROR ("Failed to create global reference");
(*env)->ExceptionClear (env);
g_slice_free (GstAGSurfaceTexture, tex);
tex = NULL;
}
(*env)->DeleteLocalRef (env, object);
return tex;
}
void
gst_ag_surfacetexture_release (GstAGSurfaceTexture * self)
{
JNIEnv *env;
GError *err = NULL;
env = gst_amc_jni_get_env ();
if (!gst_amc_jni_call_void_method (env, &err, self->object,
android_graphics_surfacetexture.release)) {
GST_ERROR ("Failed to call release: %s", err->message);
g_clear_error (&err);
}
}
void
gst_ag_surfacetexture_free (GstAGSurfaceTexture * self)
{
JNIEnv *env = gst_amc_jni_get_env ();
(*env)->DeleteGlobalRef (env, self->object);
g_slice_free (GstAGSurfaceTexture, self);
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2012, Collabora Ltd.
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __GST_ANDROID_GRAPHICS_SURFACETEXTURE_H__
#define __GST_ANDROID_GRAPHICS_SURFACETEXTURE_H__
#include <gst/gst.h>
#include <jni.h>
G_BEGIN_DECLS
typedef struct _GstAGSurfaceTexture GstAGSurfaceTexture;
/* android.graphics.SurfaceTexture */
struct _GstAGSurfaceTexture {
/* < private > */
jobject object; /* global reference */
};
gboolean gst_android_graphics_surfacetexture_init (void);
void gst_android_graphics_surfacetexture_deinit (void);
/* android.graphics.SurfaceTexture */
GstAGSurfaceTexture *gst_ag_surfacetexture_new (gint texture_id);
void gst_ag_surfacetexture_release (GstAGSurfaceTexture *self);
void gst_ag_surfacetexture_free (GstAGSurfaceTexture *self);
G_END_DECLS
#endif /* __GST_ANDROID_GRAPHICS_SURFACETEXTURE_H__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,252 @@
/*
* Copyright (C) 2012, Collabora Ltd.
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __GST_ANDROID_HARDWARE_CAMERA_H__
#define __GST_ANDROID_HARDWARE_CAMERA_H__
#include <gst/gst.h>
#include <jni.h>
#include "gst-android-graphics-surfacetexture.h"
#include "gst-android-graphics-imageformat.h"
G_BEGIN_DECLS
typedef struct _GstAHCamera GstAHCamera;
typedef struct _GstAHCCameraInfo GstAHCCameraInfo;
typedef struct _GstAHCSize GstAHCSize;
typedef struct _GstAHCParameters GstAHCParameters;
/* android.hardware.Camera */
struct _GstAHCamera
{
/* < private > */
jobject object; /* global reference */
};
/* android.hardware.Camera.CameraInfo */
struct _GstAHCCameraInfo
{
gint facing;
gint orientation;
};
extern gint CameraInfo_CAMERA_FACING_BACK;
extern gint CameraInfo_CAMERA_FACING_FRONT;
/* android.hardware.Camera.Size */
struct _GstAHCSize
{
gint width;
gint height;
};
/* android.hardware.Camera.Parameters */
struct _GstAHCParameters
{
/* < private > */
jobject object; /* global reference */
};
extern const gchar *Parameters_WHITE_BALANCE_AUTO;
extern const gchar *Parameters_WHITE_BALANCE_INCANDESCENT;
extern const gchar *Parameters_WHITE_BALANCE_FLUORESCENT;
extern const gchar *Parameters_WHITE_BALANCE_WARM_FLUORESCENT;
extern const gchar *Parameters_WHITE_BALANCE_DAYLIGHT;
extern const gchar *Parameters_WHITE_BALANCE_CLOUDY_DAYLIGHT;
extern const gchar *Parameters_WHITE_BALANCE_TWILIGHT;
extern const gchar *Parameters_WHITE_BALANCE_SHADE;
extern const gchar *Parameters_EFFECT_NONE;
extern const gchar *Parameters_EFFECT_MONO;
extern const gchar *Parameters_EFFECT_NEGATIVE;
extern const gchar *Parameters_EFFECT_SOLARIZE;
extern const gchar *Parameters_EFFECT_SEPIA;
extern const gchar *Parameters_EFFECT_POSTERIZE;
extern const gchar *Parameters_EFFECT_WHITEBOARD;
extern const gchar *Parameters_EFFECT_BLACKBOARD;
extern const gchar *Parameters_EFFECT_AQUA;
extern const gchar *Parameters_ANTIBANDING_AUTO;
extern const gchar *Parameters_ANTIBANDING_50HZ;
extern const gchar *Parameters_ANTIBANDING_60HZ;
extern const gchar *Parameters_ANTIBANDING_OFF;
extern const gchar *Parameters_FLASH_MODE_OFF;
extern const gchar *Parameters_FLASH_MODE_AUTO;
extern const gchar *Parameters_FLASH_MODE_ON;
extern const gchar *Parameters_FLASH_MODE_RED_EYE;
extern const gchar *Parameters_FLASH_MODE_TORCH;
extern const gchar *Parameters_SCENE_MODE_AUTO;
extern const gchar *Parameters_SCENE_MODE_ACTION;
extern const gchar *Parameters_SCENE_MODE_PORTRAIT;
extern const gchar *Parameters_SCENE_MODE_LANDSCAPE;
extern const gchar *Parameters_SCENE_MODE_NIGHT;
extern const gchar *Parameters_SCENE_MODE_NIGHT_PORTRAIT;
extern const gchar *Parameters_SCENE_MODE_THEATRE;
extern const gchar *Parameters_SCENE_MODE_BEACH;
extern const gchar *Parameters_SCENE_MODE_SNOW;
extern const gchar *Parameters_SCENE_MODE_SUNSET;
extern const gchar *Parameters_SCENE_MODE_STEADYPHOTO;
extern const gchar *Parameters_SCENE_MODE_FIREWORKS;
extern const gchar *Parameters_SCENE_MODE_SPORTS;
extern const gchar *Parameters_SCENE_MODE_PARTY;
extern const gchar *Parameters_SCENE_MODE_CANDLELIGHT;
extern const gchar *Parameters_SCENE_MODE_BARCODE;
extern const gchar *Parameters_FOCUS_MODE_AUTO;
extern const gchar *Parameters_FOCUS_MODE_INFINITY;
extern const gchar *Parameters_FOCUS_MODE_MACRO;
extern const gchar *Parameters_FOCUS_MODE_FIXED;
extern const gchar *Parameters_FOCUS_MODE_EDOF;
extern const gchar *Parameters_FOCUS_MODE_CONTINUOUS_VIDEO;
extern const gchar *Parameters_FOCUS_MODE_CONTINUOUS_PICTURE;
/* android.hardware.Camera.ErrorCallback */
typedef void (*GstAHCErrorCallback) (gint error, gpointer user_data);
/* android.hardware.Camera.PreviewCallback */
typedef void (*GstAHCPreviewCallback) (jbyteArray data, gpointer user_data);
/* android.hardware.Camera.AutoFocusCallback */
typedef void (*GstAHCAutoFocusCallback) (gboolean success, gpointer user_data);
gboolean gst_android_hardware_camera_init (void);
void gst_android_hardware_camera_deinit (void);
/* android.hardware.Camera */
void gst_ah_camera_add_callback_buffer (GstAHCamera * self, jbyteArray buffer);
gboolean gst_ah_camera_auto_focus (GstAHCamera * self,
GstAHCAutoFocusCallback cb, gpointer user_data);
gboolean gst_ah_camera_cancel_auto_focus (GstAHCamera * self);
gboolean gst_ah_camera_get_camera_info (gint camera_id,
GstAHCCameraInfo * camera_info);
gint gst_ah_camera_get_number_of_cameras (void);
GstAHCParameters *gst_ah_camera_get_parameters (GstAHCamera * self);
gboolean gst_ah_camera_lock (GstAHCamera * self);
GstAHCamera *gst_ah_camera_open (gint camera_id);
gboolean gst_ah_camera_reconnect (GstAHCamera * self);
void gst_ah_camera_release (GstAHCamera * self);
void gst_ah_camera_free (GstAHCamera * self);
gboolean gst_ah_camera_set_parameters (GstAHCamera * self,
GstAHCParameters * params);
gboolean gst_ah_camera_set_error_callback (GstAHCamera * self,
GstAHCErrorCallback cb, gpointer user_data);
gboolean gst_ah_camera_set_preview_callback_with_buffer (GstAHCamera * self,
GstAHCPreviewCallback cb, gpointer user_data);
void gst_ah_camera_set_preview_texture (GstAHCamera * self,
GstAGSurfaceTexture * surfaceTexture);
gboolean gst_ah_camera_start_preview (GstAHCamera * self);
gboolean gst_ah_camera_start_smooth_zoom (GstAHCamera * self, gint value);
gboolean gst_ah_camera_stop_preview (GstAHCamera * self);
gboolean gst_ah_camera_stop_smooth_zoom (GstAHCamera * self);
gboolean gst_ah_camera_unlock (GstAHCamera * self);
/* android.hardware.Camera.Size */
GstAHCSize *gst_ahc_size_new (gint width, gint height);
void gst_ahc_size_free (GstAHCSize * self);
/* android.hardware.Camera.Parameters */
gchar *gst_ahc_parameters_flatten (GstAHCParameters * self);
const gchar *gst_ahc_parameters_get_antibanding (GstAHCParameters * self);
const gchar *gst_ahc_parameters_get_color_effect (GstAHCParameters * self);
gint gst_ahc_parameters_get_exposure_compensation (GstAHCParameters * self);
gfloat gst_ahc_parameters_get_exposure_compensation_step (GstAHCParameters
* self);
const gchar *gst_ahc_parameters_get_flash_mode (GstAHCParameters * self);
gfloat gst_ahc_parameters_get_focal_length (GstAHCParameters * self);
const gchar *gst_ahc_parameters_get_focus_mode (GstAHCParameters * self);
gfloat gst_ahc_parameters_get_horizontal_view_angle (GstAHCParameters * self);
gint gst_ahc_parameters_get_max_exposure_compensation (GstAHCParameters * self);
gint gst_ahc_parameters_get_max_zoom (GstAHCParameters * self);
gint gst_ahc_parameters_get_min_exposure_compensation (GstAHCParameters * self);
gint gst_ahc_parameters_get_preview_format (GstAHCParameters * self);
gboolean gst_ahc_parameters_get_preview_fps_range (GstAHCParameters * self,
gint * min, gint * max);
GstAHCSize *gst_ahc_parameters_get_preview_size (GstAHCParameters * self);
const gchar *gst_ahc_parameters_get_scene_mode (GstAHCParameters * self);
/* GList <const gchar *> */
GList *gst_ahc_parameters_get_supported_antibanding (GstAHCParameters * self);
void gst_ahc_parameters_supported_antibanding_free (GList * list);
/* GList <const gchar *> */
GList *gst_ahc_parameters_get_supported_color_effects (GstAHCParameters * self);
void gst_ahc_parameters_supported_color_effects_free (GList * list);
/* GList <const gchar *> */
GList *gst_ahc_parameters_get_supported_flash_modes (GstAHCParameters * self);
void gst_ahc_parameters_supported_flash_modes_free (GList * list);
/* GList <const gchar *> */
GList *gst_ahc_parameters_get_supported_focus_modes (GstAHCParameters * self);
void gst_ahc_parameters_supported_focus_modes_free (GList * list);
/* GList <int> */
GList *gst_ahc_parameters_get_supported_preview_formats (GstAHCParameters
* self);
void gst_ahc_parameters_supported_preview_formats_free (GList * list);
/* GList <int [2]> */
GList *gst_ahc_parameters_get_supported_preview_fps_range (GstAHCParameters
* self);
void gst_ahc_parameters_supported_preview_fps_range_free (GList * list);
/* GList <GstAHCSize *> */
GList *gst_ahc_parameters_get_supported_preview_sizes (GstAHCParameters * self);
void gst_ahc_parameters_supported_preview_sizes_free (GList * list);
/* GList <const gchar *> */
GList *gst_ahc_parameters_get_supported_scene_modes (GstAHCParameters * self);
void gst_ahc_parameters_supported_scene_modes_free (GList * list);
/* GList <const gchar *> */
GList *gst_ahc_parameters_get_supported_white_balance (GstAHCParameters * self);
void gst_ahc_parameters_supported_white_balance_free (GList * list);
gfloat gst_ahc_parameters_get_vertical_view_angle (GstAHCParameters * self);
gboolean gst_ahc_parameters_get_video_stabilization (GstAHCParameters * self);
const gchar *gst_ahc_parameters_get_white_balance (GstAHCParameters * self);
gint gst_ahc_parameters_get_zoom (GstAHCParameters * self);
/* GList <int> */
GList *gst_ahc_parameters_get_zoom_ratios (GstAHCParameters * self);
void gst_ahc_parameters_zoom_ratios_free (GList * list);
gboolean gst_ahc_parameters_is_smooth_zoom_supported (GstAHCParameters * self);
gboolean gst_ahc_parameters_is_video_stabilization_supported (
GstAHCParameters * self);
gboolean gst_ahc_parameters_is_zoom_supported (GstAHCParameters * self);
gboolean gst_ahc_parameters_set_antibanding (GstAHCParameters * self,
const gchar * antibanding);
gboolean gst_ahc_parameters_set_color_effect (GstAHCParameters * self,
const gchar * value);
gboolean gst_ahc_parameters_set_exposure_compensation (GstAHCParameters * self,
gint value);
gboolean gst_ahc_parameters_set_flash_mode (GstAHCParameters * self,
const gchar * value);
gboolean gst_ahc_parameters_set_focus_mode (GstAHCParameters * self,
const gchar * value);
gboolean gst_ahc_parameters_set_preview_format (GstAHCParameters * self,
gint format);
gboolean gst_ahc_parameters_set_preview_fps_range (GstAHCParameters * self,
gint min, gint max);
gboolean gst_ahc_parameters_set_preview_size (GstAHCParameters * self,
gint width, gint height);
gboolean gst_ahc_parameters_set_scene_mode (GstAHCParameters * self,
const gchar * value);
gboolean gst_ahc_parameters_set_white_balance (GstAHCParameters * self,
const gchar * value);
gboolean gst_ahc_parameters_set_video_stabilization (GstAHCParameters * self,
gboolean toggle);
gboolean gst_ahc_parameters_set_zoom (GstAHCParameters * self, gint value);
gboolean gst_ahc_parameters_unflatten (GstAHCParameters * self,
const gchar * flattened);
void gst_ahc_parameters_free (GstAHCParameters * self);
G_END_DECLS
#endif /* __GST_ANDROID_HARDWARE_CAMERA_H__ */

View file

@ -0,0 +1,68 @@
/*
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/dvm/gstdvm.h>
#include "gst-android-hardware-camera.h"
#include "gstahcsrc.h"
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_dvm_init ())
return FALSE;
if (!gst_android_graphics_surfacetexture_init ())
return FALSE;
if (!gst_android_graphics_imageformat_init ()) {
gst_android_graphics_surfacetexture_deinit ();
return FALSE;
}
if (!gst_android_hardware_camera_init ()) {
gst_android_graphics_surfacetexture_deinit ();
gst_android_graphics_imageformat_deinit ();
return FALSE;
}
return gst_element_register (plugin, "ahcsrc", GST_RANK_NONE,
GST_TYPE_AHC_SRC);
}
#ifdef GST_PLUGIN_DEFINE2
GST_PLUGIN_DEFINE2 (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
androidcamera,
"Android Camera plugin",
plugin_init,
PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
#else
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"androidcamera",
"Android Camera plugin",
plugin_init,
PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
#endif

2513
sys/androidmedia/gstahcsrc.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,89 @@
/* GStreamer android.hardware.Camera Source
*
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_AHC_SRC_H__
#define __GST_AHC_SRC_H__
#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>
#include <gst/base/gstdataqueue.h>
#include "gst-android-hardware-camera.h"
G_BEGIN_DECLS
#define GST_TYPE_AHC_SRC \
(gst_ahc_src_get_type())
#define GST_AHC_SRC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AHC_SRC, GstAHCSrc))
#define GST_AHC_SRC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AHC_SRC, GstAHCSrcClass))
#define GST_IS_AHC_SRC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AHC_SRC))
#define GST_IS_AHC_SRC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AHC_SRC))
typedef struct _GstAHCSrc GstAHCSrc;
typedef struct _GstAHCSrcClass GstAHCSrcClass;
/**
* GstAHCSrc:
*
* Opaque data structure.
*/
struct _GstAHCSrc
{
/*< private >*/
GstPushSrc parent;
GstAHCamera *camera;
GstAGSurfaceTexture *texture;
GList *data;
GstDataQueue *queue;
gint buffer_size;
GstClockTime previous_ts;
gint format;
gint width;
gint height;
gint fps_min;
gint fps_max;
gboolean start;
gboolean smooth_zoom;
GMutex mutex;
/* Properties */
gint device;
};
struct _GstAHCSrcClass
{
GstPushSrcClass parent_class;
GList *probe_properties;
};
GType gst_ahc_src_get_type (void);
G_END_DECLS
#endif /* __GST_AHC_SRC_H__ */

View file

@ -29,6 +29,8 @@
#define orc_memcpy memcpy
#endif
#include "gstahcsrc.h"
#include "gstamc.h"
#include "gstamc-constants.h"
@ -3316,6 +3318,28 @@ plugin_init (GstPlugin * plugin)
if (!register_codecs (plugin))
return FALSE;
if (!gst_android_graphics_surfacetexture_init ()) {
GST_ERROR ("Failed to init android surface texture");
return FALSE;
}
if (!gst_android_graphics_imageformat_init ()) {
GST_ERROR ("Failed to init android image format");
gst_android_graphics_surfacetexture_deinit ();
return FALSE;
}
if (!gst_android_hardware_camera_init ()) {
gst_android_graphics_surfacetexture_deinit ();
gst_android_graphics_imageformat_deinit ();
return FALSE;
}
if (!gst_element_register (plugin, "ahcsrc", GST_RANK_NONE, GST_TYPE_AHC_SRC)) {
GST_ERROR ("Failed to register android camera source");
return FALSE;
}
return TRUE;
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2012, Collabora Ltd.
* Author: Youness Alaoui
*
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
package org.freedesktop.gstreamer.androidmedia;
import android.hardware.Camera;
public class GstAhcCallback implements Camera.PreviewCallback,
Camera.ErrorCallback,
Camera.AutoFocusCallback {
public long mUserData;
public long mCallback;
public static native void gst_ah_camera_on_preview_frame(byte[] data, Camera camera,
long callback, long user_data);
public static native void gst_ah_camera_on_error(int error, Camera camera,
long callback, long user_data);
public static native void gst_ah_camera_on_auto_focus(boolean success, Camera camera,
long callback, long user_data);
public GstAhcCallback(long callback, long user_data) {
mCallback = callback;
mUserData = user_data;
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
gst_ah_camera_on_preview_frame(data, camera, mCallback, mUserData);
}
@Override
public void onError(int error, Camera camera) {
gst_ah_camera_on_error(error, camera, mCallback, mUserData);
}
@Override
public void onAutoFocus(boolean success, Camera camera) {
gst_ah_camera_on_auto_focus(success, camera, mCallback, mUserData);
}
}