mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
ahcsrc: porting from 0.10 to 1.0
This commit is contained in:
parent
becaf2852d
commit
f1809c4d93
19 changed files with 1490 additions and 2722 deletions
|
@ -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
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* 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
|
||||
|
@ -23,7 +26,7 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/dvm/gstdvm.h>
|
||||
#include "gstjniutils.h"
|
||||
|
||||
#include "gst-android-graphics-imageformat.h"
|
||||
|
||||
|
@ -31,7 +34,7 @@
|
|||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jmethodID getBitsPerPixel;
|
||||
jmethodID get_bits_per_pixel;
|
||||
jint JPEG;
|
||||
jint NV16;
|
||||
jint NV21;
|
||||
|
@ -53,30 +56,95 @@ gint ImageFormat_YV12;
|
|||
static gboolean
|
||||
_init_classes (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env;
|
||||
|
||||
jfieldID fieldID;
|
||||
jclass klass;
|
||||
|
||||
GError *err = NULL;
|
||||
|
||||
env = gst_amc_jni_get_env ();
|
||||
|
||||
/* android.graphics.ImageFormat */
|
||||
GST_DVM_GET_CLASS (android_graphics_imageformat,
|
||||
"android/graphics/ImageFormat");
|
||||
GST_DVM_GET_STATIC_METHOD (android_graphics_imageformat, getBitsPerPixel,
|
||||
"(I)I");
|
||||
klass = android_graphics_imageformat.klass =
|
||||
gst_amc_jni_get_class (env, &err, "android/graphics/ImageFormat");
|
||||
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, JPEG, Int, "I");
|
||||
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;
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, NV16, Int, "I");
|
||||
|
||||
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;
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, NV21, Int, "I");
|
||||
|
||||
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;
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, RGB_565, Int, "I");
|
||||
|
||||
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;
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, UNKNOWN, Int, "I");
|
||||
|
||||
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;
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, YUY2, Int, "I");
|
||||
|
||||
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;
|
||||
GST_DVM_GET_CONSTANT (android_graphics_imageformat, YV12, Int, "I");
|
||||
|
||||
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
|
||||
|
@ -93,7 +161,7 @@ gst_android_graphics_imageformat_init (void)
|
|||
void
|
||||
gst_android_graphics_imageformat_deinit (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env = gst_amc_jni_get_env ();
|
||||
|
||||
if (android_graphics_imageformat.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_graphics_imageformat.klass);
|
||||
|
@ -104,11 +172,21 @@ gst_android_graphics_imageformat_deinit (void)
|
|||
gint
|
||||
gst_ag_imageformat_get_bits_per_pixel (gint format)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env;
|
||||
GError *err = NULL;
|
||||
|
||||
jclass klass = android_graphics_imageformat.klass;
|
||||
|
||||
jint bpp = 0;
|
||||
|
||||
bpp = GST_DVM_STATIC_CALL (return -1, Int,
|
||||
android_graphics_imageformat, getBitsPerPixel, format);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* 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
|
||||
|
@ -23,8 +26,6 @@
|
|||
#define __GST_ANDROID_GRAPHICS_IMAGEFORMAT_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* 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
|
||||
|
@ -23,11 +26,10 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/dvm/gstdvm.h>
|
||||
#include "gstjniutils.h"
|
||||
|
||||
#include "gst-android-graphics-surfacetexture.h"
|
||||
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
|
@ -39,14 +41,28 @@ static struct
|
|||
static gboolean
|
||||
_init_classes (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env;
|
||||
GError *err = NULL;
|
||||
|
||||
env = gst_amc_jni_get_env ();
|
||||
|
||||
/* android.graphics.SurfaceTexture */
|
||||
GST_DVM_GET_CLASS (android_graphics_surfacetexture,
|
||||
"android/graphics/SurfaceTexture");
|
||||
GST_DVM_GET_CONSTRUCTOR (android_graphics_surfacetexture, constructor,
|
||||
"(I)V");
|
||||
GST_DVM_GET_METHOD (android_graphics_surfacetexture, release, "()V");
|
||||
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;
|
||||
}
|
||||
|
@ -65,7 +81,7 @@ gst_android_graphics_surfacetexture_init (void)
|
|||
void
|
||||
gst_android_graphics_surfacetexture_deinit (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env = gst_amc_jni_get_env ();
|
||||
|
||||
if (android_graphics_surfacetexture.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_graphics_surfacetexture.klass);
|
||||
|
@ -76,7 +92,7 @@ gst_android_graphics_surfacetexture_deinit (void)
|
|||
GstAGSurfaceTexture *
|
||||
gst_ag_surfacetexture_new (gint texture_id)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env = gst_amc_jni_get_env ();
|
||||
jobject object = NULL;
|
||||
GstAGSurfaceTexture *tex = NULL;
|
||||
|
||||
|
@ -105,15 +121,23 @@ gst_ag_surfacetexture_new (gint texture_id)
|
|||
void
|
||||
gst_ag_surfacetexture_release (GstAGSurfaceTexture * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
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);
|
||||
}
|
||||
|
||||
GST_DVM_CALL (, self->object, Void, android_graphics_surfacetexture, release);
|
||||
}
|
||||
|
||||
void
|
||||
gst_ag_surfacetexture_free (GstAGSurfaceTexture * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
JNIEnv *env = gst_amc_jni_get_env ();
|
||||
|
||||
(*env)->DeleteGlobalRef (env, self->object);
|
||||
g_slice_free (GstAGSurfaceTexture, self);
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* 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
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,9 @@
|
|||
* 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
|
||||
|
|
|
@ -1,531 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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/dvm/gstdvm.h>
|
||||
|
||||
#include "gst-android-media-mediacodec.h"
|
||||
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jmethodID constructor;
|
||||
jfieldID flags;
|
||||
jfieldID offset;
|
||||
jfieldID presentationTimeUs;
|
||||
jfieldID size;
|
||||
} android_media_mediacodec_bufferinfo;
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jmethodID configure;
|
||||
jmethodID createByCodecName;
|
||||
jmethodID createDecoderByType;
|
||||
jmethodID createEncoderByType;
|
||||
jmethodID dequeueInputBuffer;
|
||||
jmethodID dequeueOutputBuffer;
|
||||
jmethodID flush;
|
||||
jmethodID getInputBuffers;
|
||||
jmethodID getOutputBuffers;
|
||||
jmethodID getOutputFormat;
|
||||
jmethodID queueInputBuffer;
|
||||
jmethodID release;
|
||||
jmethodID releaseOutputBuffer;
|
||||
jmethodID start;
|
||||
jmethodID stop;
|
||||
jint BUFFER_FLAG_SYNC_FRAME;
|
||||
jint BUFFER_FLAG_CODEC_CONFIG;
|
||||
jint BUFFER_FLAG_END_OF_STREAM;
|
||||
jint CONFIGURE_FLAG_ENCODE;
|
||||
jint INFO_TRY_AGAIN_LATER;
|
||||
jint INFO_OUTPUT_FORMAT_CHANGED;
|
||||
jint INFO_OUTPUT_BUFFERS_CHANGED;
|
||||
} android_media_mediacodec;
|
||||
|
||||
gint MediaCodec_BUFFER_FLAG_SYNC_FRAME;
|
||||
gint MediaCodec_BUFFER_FLAG_CODEC_CONFIG;
|
||||
gint MediaCodec_BUFFER_FLAG_END_OF_STREAM;
|
||||
|
||||
gint MediaCodec_CONFIGURE_FLAG_ENCODE;
|
||||
|
||||
gint MediaCodec_INFO_TRY_AGAIN_LATER;
|
||||
gint MediaCodec_INFO_OUTPUT_FORMAT_CHANGED;
|
||||
gint MediaCodec_INFO_OUTPUT_BUFFERS_CHANGED;
|
||||
|
||||
static gboolean
|
||||
_init_classes (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
/* android.media.MediaCodec */
|
||||
GST_DVM_GET_CLASS (android_media_mediacodec, "android/media/MediaCodec");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediacodec, createByCodecName,
|
||||
"(Ljava/lang/String;)Landroid/media/MediaCodec;");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediacodec, createDecoderByType,
|
||||
"(Ljava/lang/String;)Landroid/media/MediaCodec;");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediacodec, createEncoderByType,
|
||||
"(Ljava/lang/String;)Landroid/media/MediaCodec;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, configure,
|
||||
"(Landroid/media/MediaFormat;Landroid/view/Surface;"
|
||||
"Landroid/media/MediaCrypto;I)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, dequeueInputBuffer, "(J)I");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, dequeueOutputBuffer,
|
||||
"(Landroid/media/MediaCodec$BufferInfo;J)I");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, flush, "()V");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, getInputBuffers,
|
||||
"()[Ljava/nio/ByteBuffer;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, getOutputBuffers,
|
||||
"()[Ljava/nio/ByteBuffer;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, getOutputFormat,
|
||||
"()Landroid/media/MediaFormat;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, queueInputBuffer, "(IIIJI)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, release, "()V");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, releaseOutputBuffer, "(IZ)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, start, "()V");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodec, stop, "()V");
|
||||
|
||||
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, BUFFER_FLAG_SYNC_FRAME, Int,
|
||||
"I");
|
||||
MediaCodec_BUFFER_FLAG_SYNC_FRAME =
|
||||
android_media_mediacodec.BUFFER_FLAG_SYNC_FRAME;
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, BUFFER_FLAG_CODEC_CONFIG, Int,
|
||||
"I");
|
||||
MediaCodec_BUFFER_FLAG_CODEC_CONFIG =
|
||||
android_media_mediacodec.BUFFER_FLAG_CODEC_CONFIG;
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, BUFFER_FLAG_END_OF_STREAM,
|
||||
Int, "I");
|
||||
MediaCodec_BUFFER_FLAG_END_OF_STREAM =
|
||||
android_media_mediacodec.BUFFER_FLAG_END_OF_STREAM;
|
||||
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, CONFIGURE_FLAG_ENCODE, Int,
|
||||
"I");
|
||||
MediaCodec_CONFIGURE_FLAG_ENCODE =
|
||||
android_media_mediacodec.CONFIGURE_FLAG_ENCODE;
|
||||
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, INFO_TRY_AGAIN_LATER, Int,
|
||||
"I");
|
||||
MediaCodec_INFO_TRY_AGAIN_LATER =
|
||||
android_media_mediacodec.INFO_TRY_AGAIN_LATER;
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, INFO_OUTPUT_FORMAT_CHANGED,
|
||||
Int, "I");
|
||||
MediaCodec_INFO_OUTPUT_FORMAT_CHANGED =
|
||||
android_media_mediacodec.INFO_OUTPUT_FORMAT_CHANGED;
|
||||
GST_DVM_GET_CONSTANT (android_media_mediacodec, INFO_OUTPUT_BUFFERS_CHANGED,
|
||||
Int, "I");
|
||||
MediaCodec_INFO_OUTPUT_BUFFERS_CHANGED =
|
||||
android_media_mediacodec.INFO_OUTPUT_BUFFERS_CHANGED;
|
||||
|
||||
/* android.media.MediaCodec.BufferInfo */
|
||||
GST_DVM_GET_CLASS (android_media_mediacodec_bufferinfo,
|
||||
"android/media/MediaCodec$BufferInfo");
|
||||
GST_DVM_GET_CONSTRUCTOR (android_media_mediacodec_bufferinfo, constructor,
|
||||
"()V");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodec_bufferinfo, flags, "I");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodec_bufferinfo, offset, "I");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodec_bufferinfo, presentationTimeUs,
|
||||
"J");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodec_bufferinfo, size, "I");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_android_media_mediacodec_init (void)
|
||||
{
|
||||
if (!_init_classes ()) {
|
||||
gst_android_media_mediacodec_deinit ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gst_android_media_mediacodec_deinit (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
if (android_media_mediacodec.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediacodec.klass);
|
||||
android_media_mediacodec.klass = NULL;
|
||||
|
||||
if (android_media_mediacodec_bufferinfo.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediacodec_bufferinfo.klass);
|
||||
android_media_mediacodec_bufferinfo.klass = NULL;
|
||||
}
|
||||
|
||||
/* android.media.MediaCodec */
|
||||
|
||||
#define AMMC_CALL(error_statement, type, method, ...) \
|
||||
GST_DVM_CALL (error_statement, self->object, type, \
|
||||
android_media_mediacodec, method, ## __VA_ARGS__);
|
||||
#define AMMC_STATIC_CALL(error_statement, type, method, ...) \
|
||||
GST_DVM_STATIC_CALL (error_statement, type, \
|
||||
android_media_mediacodec, method, ## __VA_ARGS__);
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodec_configure (GstAmMediaCodec * self, GstAmMediaFormat * format,
|
||||
gint flags)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (return FALSE, Void, configure, format->object, NULL, NULL, flags);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GstAmMediaCodec *
|
||||
gst_am_mediacodec_create_by_codec_name (const gchar * name)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GstAmMediaCodec *codec = NULL;
|
||||
jobject object = NULL;
|
||||
jstring name_str;
|
||||
|
||||
name_str = (*env)->NewStringUTF (env, name);
|
||||
if (name_str == NULL)
|
||||
goto done;
|
||||
|
||||
object = AMMC_STATIC_CALL (goto done, Object, createByCodecName, name_str);
|
||||
if (object) {
|
||||
codec = g_slice_new0 (GstAmMediaCodec);
|
||||
codec->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!codec->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaCodec, codec);
|
||||
codec = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (name_str)
|
||||
(*env)->DeleteLocalRef (env, name_str);
|
||||
|
||||
return codec;
|
||||
}
|
||||
|
||||
|
||||
GstAmMediaFormat *
|
||||
gst_am_mediacodec_get_output_format (GstAmMediaCodec * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GstAmMediaFormat *format = NULL;
|
||||
jobject object = NULL;
|
||||
|
||||
object = AMMC_CALL (return NULL, Object, getOutputFormat);
|
||||
if (object) {
|
||||
format = g_slice_new0 (GstAmMediaFormat);
|
||||
format->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!format->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaFormat, format);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodec_start (GstAmMediaCodec * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (return FALSE, Void, start);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodec_stop (GstAmMediaCodec * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (return FALSE, Void, stop);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodec_flush (GstAmMediaCodec * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (return FALSE, Void, flush);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gst_am_mediacodec_free (GstAmMediaCodec * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
(*env)->DeleteGlobalRef (env, self->object);
|
||||
g_slice_free (GstAmMediaCodec, self);
|
||||
}
|
||||
|
||||
void
|
||||
gst_am_mediacodec_release (GstAmMediaCodec * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (, Void, release);
|
||||
}
|
||||
|
||||
void
|
||||
gst_am_mediacodec_free_buffers (GstAmMediaCodecBuffer * buffers,
|
||||
gsize n_buffers)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jsize i;
|
||||
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
if (buffers[i].object)
|
||||
(*env)->DeleteGlobalRef (env, buffers[i].object);
|
||||
}
|
||||
g_free (buffers);
|
||||
}
|
||||
|
||||
GstAmMediaCodecBuffer *
|
||||
gst_am_mediacodec_get_output_buffers (GstAmMediaCodec * self, gsize * n_buffers)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jobject output_buffers = NULL;
|
||||
jsize n_output_buffers;
|
||||
GstAmMediaCodecBuffer *ret = NULL;
|
||||
jsize i;
|
||||
|
||||
*n_buffers = 0;
|
||||
output_buffers = AMMC_CALL (goto done, Object, getOutputBuffers);
|
||||
if (!output_buffers)
|
||||
goto done;
|
||||
|
||||
n_output_buffers = (*env)->GetArrayLength (env, output_buffers);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get output buffers array length");
|
||||
goto done;
|
||||
}
|
||||
|
||||
*n_buffers = n_output_buffers;
|
||||
ret = g_new0 (GstAmMediaCodecBuffer, n_output_buffers);
|
||||
|
||||
for (i = 0; i < n_output_buffers; i++) {
|
||||
jobject buffer = NULL;
|
||||
|
||||
buffer = (*env)->GetObjectArrayElement (env, output_buffers, i);
|
||||
if ((*env)->ExceptionCheck (env) || !buffer) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get output buffer %d", i);
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret[i].object = (*env)->NewGlobalRef (env, buffer);
|
||||
(*env)->DeleteLocalRef (env, buffer);
|
||||
if (!ret[i].object) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to create global reference %d", i);
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret[i].data = (*env)->GetDirectBufferAddress (env, ret[i].object);
|
||||
if (!ret[i].data) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get buffer address %d", i);
|
||||
goto error;
|
||||
}
|
||||
ret[i].size = (*env)->GetDirectBufferCapacity (env, ret[i].object);
|
||||
}
|
||||
|
||||
done:
|
||||
if (output_buffers)
|
||||
(*env)->DeleteLocalRef (env, output_buffers);
|
||||
output_buffers = NULL;
|
||||
|
||||
return ret;
|
||||
error:
|
||||
if (ret)
|
||||
gst_am_mediacodec_free_buffers (ret, n_output_buffers);
|
||||
ret = NULL;
|
||||
*n_buffers = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
GstAmMediaCodecBuffer *
|
||||
gst_am_mediacodec_get_input_buffers (GstAmMediaCodec * self, gsize * n_buffers)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jobject input_buffers = NULL;
|
||||
jsize n_input_buffers;
|
||||
GstAmMediaCodecBuffer *ret = NULL;
|
||||
jsize i;
|
||||
|
||||
*n_buffers = 0;
|
||||
|
||||
input_buffers = AMMC_CALL (goto done, Object, getOutputBuffers);
|
||||
if (!input_buffers)
|
||||
goto done;
|
||||
|
||||
n_input_buffers = (*env)->GetArrayLength (env, input_buffers);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get input buffers array length");
|
||||
goto done;
|
||||
}
|
||||
|
||||
*n_buffers = n_input_buffers;
|
||||
ret = g_new0 (GstAmMediaCodecBuffer, n_input_buffers);
|
||||
|
||||
for (i = 0; i < n_input_buffers; i++) {
|
||||
jobject buffer = NULL;
|
||||
|
||||
buffer = (*env)->GetObjectArrayElement (env, input_buffers, i);
|
||||
if ((*env)->ExceptionCheck (env) || !buffer) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get input buffer %d", i);
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret[i].object = (*env)->NewGlobalRef (env, buffer);
|
||||
(*env)->DeleteLocalRef (env, buffer);
|
||||
if (!ret[i].object) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to create global reference %d", i);
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret[i].data = (*env)->GetDirectBufferAddress (env, ret[i].object);
|
||||
if (!ret[i].data) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get buffer address %d", i);
|
||||
goto error;
|
||||
}
|
||||
ret[i].size = (*env)->GetDirectBufferCapacity (env, ret[i].object);
|
||||
}
|
||||
|
||||
done:
|
||||
if (input_buffers)
|
||||
(*env)->DeleteLocalRef (env, input_buffers);
|
||||
input_buffers = NULL;
|
||||
|
||||
return ret;
|
||||
error:
|
||||
if (ret)
|
||||
gst_am_mediacodec_free_buffers (ret, n_input_buffers);
|
||||
ret = NULL;
|
||||
*n_buffers = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_am_mediacodec_dequeue_input_buffer (GstAmMediaCodec * self,
|
||||
gint64 timeoutUs)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gint ret = G_MININT;
|
||||
|
||||
ret = AMMC_CALL (return G_MININT, Int, dequeueInputBuffer, timeoutUs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define AMMCBI_FIELD(error_statement, type, field) \
|
||||
GST_DVM_FIELD (error_statement, buffer_info, type, \
|
||||
android_media_mediacodec_bufferinfo, field);
|
||||
|
||||
static gboolean
|
||||
_fill_buffer_info (JNIEnv * env, jobject buffer_info,
|
||||
GstAmMediaCodecBufferInfo * info)
|
||||
{
|
||||
info->flags = AMMCBI_FIELD (return FALSE, Int, flags);
|
||||
info->offset = AMMCBI_FIELD (return FALSE, Int, offset);
|
||||
info->presentation_time_us =
|
||||
AMMCBI_FIELD (return FALSE, Long, presentationTimeUs);
|
||||
info->size = AMMCBI_FIELD (return FALSE, Int, size);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_am_mediacodec_dequeue_output_buffer (GstAmMediaCodec * self,
|
||||
GstAmMediaCodecBufferInfo * info, gint64 timeoutUs)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gint ret = G_MININT;
|
||||
jobject info_o = NULL;
|
||||
|
||||
info_o = (*env)->NewObject (env, android_media_mediacodec_bufferinfo.klass,
|
||||
android_media_mediacodec_bufferinfo.constructor);
|
||||
if (!info_o) {
|
||||
GST_ERROR ("Failed to call Java method");
|
||||
(*env)->ExceptionClear (env);
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = AMMC_CALL (goto error, Int, dequeueOutputBuffer, info_o, timeoutUs);
|
||||
|
||||
if (!_fill_buffer_info (env, info_o, info))
|
||||
goto error;
|
||||
|
||||
done:
|
||||
if (info_o)
|
||||
(*env)->DeleteLocalRef (env, info_o);
|
||||
info_o = NULL;
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
ret = G_MININT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodec_queue_input_buffer (GstAmMediaCodec * self, gint index,
|
||||
const GstAmMediaCodecBufferInfo * info)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (return FALSE, Void, queueInputBuffer, index, info->offset,
|
||||
info->size, info->presentation_time_us, info->flags);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodec_release_output_buffer (GstAmMediaCodec * self, gint index)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
AMMC_CALL (return FALSE, Void, releaseOutputBuffer, index, JNI_FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GST_ANDROID_MEDIA_MEDIACODEC_H__
|
||||
#define __GST_ANDROID_MEDIA_MEDIACODEC_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "gst-android-media-mediaformat.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstAmMediaCodecBuffer GstAmMediaCodecBuffer;
|
||||
typedef struct _GstAmMediaCodecBufferInfo GstAmMediaCodecBufferInfo;
|
||||
typedef struct _GstAmMediaCodec GstAmMediaCodec;
|
||||
|
||||
struct _GstAmMediaCodecBuffer {
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
/*< private >*/
|
||||
jobject object; /* global reference */
|
||||
};
|
||||
|
||||
struct _GstAmMediaCodecBufferInfo {
|
||||
gint flags;
|
||||
gint offset;
|
||||
gint64 presentation_time_us;
|
||||
gint size;
|
||||
};
|
||||
|
||||
struct _GstAmMediaCodec {
|
||||
/*< private >*/
|
||||
jobject object; /* global reference */
|
||||
};
|
||||
|
||||
extern gint MediaCodec_BUFFER_FLAG_SYNC_FRAME;
|
||||
extern gint MediaCodec_BUFFER_FLAG_CODEC_CONFIG;
|
||||
extern gint MediaCodec_BUFFER_FLAG_END_OF_STREAM;
|
||||
|
||||
extern gint MediaCodec_CONFIGURE_FLAG_ENCODE;
|
||||
|
||||
extern gint MediaCodec_INFO_TRY_AGAIN_LATER;
|
||||
extern gint MediaCodec_INFO_OUTPUT_FORMAT_CHANGED;
|
||||
extern gint MediaCodec_INFO_OUTPUT_BUFFERS_CHANGED;
|
||||
|
||||
gboolean gst_android_media_mediacodec_init (void);
|
||||
void gst_android_media_mediacodec_deinit (void);
|
||||
|
||||
gboolean gst_am_mediacodec_configure (GstAmMediaCodec * self,
|
||||
GstAmMediaFormat * format, gint flags);
|
||||
|
||||
GstAmMediaCodec * gst_am_mediacodec_create_by_codec_name (const gchar *name);
|
||||
GstAmMediaCodec * gst_am_mediacodec_create_decoder_by_type (const gchar *type);
|
||||
GstAmMediaCodec * gst_am_mediacodec_create_encoder_by_type (const gchar *type);
|
||||
|
||||
void gst_am_mediacodec_free (GstAmMediaCodec * self);
|
||||
|
||||
gint gst_am_mediacodec_dequeue_input_buffer (GstAmMediaCodec * self,
|
||||
gint64 timeoutUs);
|
||||
gint gst_am_mediacodec_dequeue_output_buffer (GstAmMediaCodec * self,
|
||||
GstAmMediaCodecBufferInfo *info, gint64 timeoutUs);
|
||||
gboolean gst_am_mediacodec_flush (GstAmMediaCodec * self);
|
||||
|
||||
GstAmMediaCodecBuffer * gst_am_mediacodec_get_input_buffers (GstAmMediaCodec * self,
|
||||
gsize * n_buffers);
|
||||
GstAmMediaCodecBuffer * gst_am_mediacodec_get_output_buffers (GstAmMediaCodec * self,
|
||||
gsize * n_buffers);
|
||||
void gst_am_mediacodec_free_buffers (GstAmMediaCodecBuffer * buffers, gsize n_buffers);
|
||||
GstAmMediaFormat * gst_am_mediacodec_get_output_format (GstAmMediaCodec * self);
|
||||
|
||||
gboolean gst_am_mediacodec_queue_input_buffer (GstAmMediaCodec * self,
|
||||
gint index, const GstAmMediaCodecBufferInfo *info);
|
||||
void gst_am_mediacodec_release (GstAmMediaCodec * self);
|
||||
gboolean gst_am_mediacodec_release_output_buffer (GstAmMediaCodec * self,
|
||||
gint index);
|
||||
|
||||
gboolean gst_am_mediacodec_start (GstAmMediaCodec * self);
|
||||
gboolean gst_am_mediacodec_stop (GstAmMediaCodec * self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_ANDROID_MEDIA_MEDIACODEC_H__ */
|
|
@ -1,517 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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/dvm/gstdvm.h>
|
||||
|
||||
#include "gst-android-media-mediacodecinfo.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jmethodID getCapabilitiesForType;
|
||||
jmethodID getName;
|
||||
jmethodID getSupportedTypes;
|
||||
jmethodID isEncoder;
|
||||
} android_media_mediacodecinfo;
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jfieldID colorFormats;
|
||||
jfieldID profileLevels;
|
||||
} android_media_mediacodeccapabilities;
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jfieldID level;
|
||||
jfieldID profile;
|
||||
} android_media_mediacodecprofilelevel;
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
|
||||
jint CHANNEL_OUT_FRONT_LEFT;
|
||||
jint CHANNEL_OUT_FRONT_RIGHT;
|
||||
jint CHANNEL_OUT_FRONT_CENTER;
|
||||
jint CHANNEL_OUT_LOW_FREQUENCY;
|
||||
jint CHANNEL_OUT_BACK_LEFT;
|
||||
jint CHANNEL_OUT_BACK_RIGHT;
|
||||
jint CHANNEL_OUT_FRONT_LEFT_OF_CENTER;
|
||||
jint CHANNEL_OUT_FRONT_RIGHT_OF_CENTER;
|
||||
jint CHANNEL_OUT_BACK_CENTER;
|
||||
jint CHANNEL_OUT_SIDE_LEFT;
|
||||
jint CHANNEL_OUT_SIDE_RIGHT;
|
||||
jint CHANNEL_OUT_TOP_CENTER;
|
||||
jint CHANNEL_OUT_TOP_FRONT_LEFT;
|
||||
jint CHANNEL_OUT_TOP_FRONT_CENTER;
|
||||
jint CHANNEL_OUT_TOP_FRONT_RIGHT;
|
||||
jint CHANNEL_OUT_TOP_BACK_LEFT;
|
||||
jint CHANNEL_OUT_TOP_BACK_CENTER;
|
||||
jint CHANNEL_OUT_TOP_BACK_RIGHT;
|
||||
} android_media_audioformat;
|
||||
|
||||
gint AudioFormat_CHANNEL_OUT_FRONT_LEFT;
|
||||
gint AudioFormat_CHANNEL_OUT_FRONT_RIGHT;
|
||||
gint AudioFormat_CHANNEL_OUT_FRONT_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_LOW_FREQUENCY;
|
||||
gint AudioFormat_CHANNEL_OUT_BACK_LEFT;
|
||||
gint AudioFormat_CHANNEL_OUT_BACK_RIGHT;
|
||||
gint AudioFormat_CHANNEL_OUT_FRONT_LEFT_OF_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_BACK_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_SIDE_LEFT;
|
||||
gint AudioFormat_CHANNEL_OUT_SIDE_RIGHT;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_FRONT_LEFT;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_FRONT_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_FRONT_RIGHT;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_BACK_LEFT;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_BACK_CENTER;
|
||||
gint AudioFormat_CHANNEL_OUT_TOP_BACK_RIGHT;
|
||||
|
||||
|
||||
static gboolean
|
||||
_init_classes (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
/* android.media.MediaCodecInfo */
|
||||
GST_DVM_GET_CLASS (android_media_mediacodecinfo,
|
||||
"android/media/MediaCodecInfo");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodecinfo, getCapabilitiesForType,
|
||||
"(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodecinfo, getName,
|
||||
"()Ljava/lang/String;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodecinfo, getSupportedTypes,
|
||||
"()[java/lang/String;");
|
||||
GST_DVM_GET_METHOD (android_media_mediacodecinfo, isEncoder, "()Z");
|
||||
|
||||
GST_DVM_GET_CLASS (android_media_mediacodeccapabilities,
|
||||
"android/media/MediaCodecInfo$CodecCapabilities");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodeccapabilities, colorFormats, "[I");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodeccapabilities, profileLevels,
|
||||
"[Landroid/media/MediaCodecInfo$CodecProfileLevel;");
|
||||
|
||||
GST_DVM_GET_CLASS (android_media_mediacodecprofilelevel,
|
||||
"android/media/MediaCodecInfo$ProfileLevel");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodecprofilelevel, level, "I");
|
||||
GST_DVM_GET_FIELD (android_media_mediacodecprofilelevel, profile, "I");
|
||||
|
||||
GST_DVM_GET_CLASS (android_media_audioformat, "android/media/AudioFormat");
|
||||
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_FRONT_LEFT, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_FRONT_LEFT =
|
||||
android_media_audioformat.CHANNEL_OUT_FRONT_LEFT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_FRONT_RIGHT, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_FRONT_RIGHT =
|
||||
android_media_audioformat.CHANNEL_OUT_FRONT_RIGHT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_FRONT_CENTER,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_FRONT_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_FRONT_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_LOW_FREQUENCY,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_LOW_FREQUENCY =
|
||||
android_media_audioformat.CHANNEL_OUT_LOW_FREQUENCY;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_BACK_LEFT, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_BACK_LEFT =
|
||||
android_media_audioformat.CHANNEL_OUT_BACK_LEFT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_BACK_RIGHT, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_BACK_RIGHT =
|
||||
android_media_audioformat.CHANNEL_OUT_BACK_RIGHT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat,
|
||||
CHANNEL_OUT_FRONT_LEFT_OF_CENTER, Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_FRONT_LEFT_OF_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_FRONT_LEFT_OF_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat,
|
||||
CHANNEL_OUT_FRONT_RIGHT_OF_CENTER, Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_FRONT_RIGHT_OF_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_BACK_CENTER, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_BACK_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_BACK_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_SIDE_LEFT, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_SIDE_LEFT =
|
||||
android_media_audioformat.CHANNEL_OUT_SIDE_LEFT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_SIDE_RIGHT, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_SIDE_RIGHT =
|
||||
android_media_audioformat.CHANNEL_OUT_SIDE_RIGHT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_CENTER, Int,
|
||||
"I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_FRONT_LEFT,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_FRONT_LEFT =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_FRONT_LEFT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_FRONT_CENTER,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_FRONT_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_FRONT_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_FRONT_RIGHT,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_FRONT_RIGHT =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_FRONT_RIGHT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_BACK_LEFT,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_BACK_LEFT =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_BACK_LEFT;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_BACK_CENTER,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_BACK_CENTER =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_BACK_CENTER;
|
||||
GST_DVM_GET_CONSTANT (android_media_audioformat, CHANNEL_OUT_TOP_BACK_RIGHT,
|
||||
Int, "I");
|
||||
AudioFormat_CHANNEL_OUT_TOP_BACK_RIGHT =
|
||||
android_media_audioformat.CHANNEL_OUT_TOP_BACK_RIGHT;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_android_media_mediacodecinfo_init (void)
|
||||
{
|
||||
if (!_init_classes ()) {
|
||||
gst_android_media_mediacodecinfo_deinit ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gst_android_media_mediacodecinfo_deinit (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
if (android_media_mediacodecinfo.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediacodecinfo.klass);
|
||||
android_media_mediacodecinfo.klass = NULL;
|
||||
|
||||
if (android_media_mediacodeccapabilities.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediacodeccapabilities.klass);
|
||||
android_media_mediacodeccapabilities.klass = NULL;
|
||||
|
||||
if (android_media_mediacodecprofilelevel.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediacodecprofilelevel.klass);
|
||||
android_media_mediacodecprofilelevel.klass = NULL;
|
||||
|
||||
if (android_media_audioformat.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_audioformat.klass);
|
||||
android_media_audioformat.klass = NULL;
|
||||
}
|
||||
|
||||
/* android.media.MediaCodecInfo */
|
||||
#define AMMCI_CALL(error_statement, type, method, ...) \
|
||||
GST_DVM_CALL (error_statement, self->object, type, \
|
||||
android_media_mediacodecinfo, method, ## __VA_ARGS__);
|
||||
|
||||
void
|
||||
gst_am_mediacodecinfo_free (GstAmMediaCodecInfo * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
(*env)->DeleteGlobalRef (env, self->object);
|
||||
g_slice_free (GstAmMediaCodecInfo, self);
|
||||
}
|
||||
|
||||
void
|
||||
gst_am_mediacodeccapabilities_free (GstAmMediaCodecCapabilities * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
(*env)->DeleteGlobalRef (env, self->object);
|
||||
g_slice_free (GstAmMediaCodecCapabilities, self);
|
||||
}
|
||||
|
||||
void
|
||||
gst_am_mediacodecprofilelevel_free (GstAmMediaCodecProfileLevel * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
(*env)->DeleteGlobalRef (env, self->object);
|
||||
g_slice_free (GstAmMediaCodecProfileLevel, self);
|
||||
}
|
||||
|
||||
|
||||
GstAmMediaCodecCapabilities *
|
||||
gst_am_mediacodecinfo_get_capabilities_for_type (GstAmMediaCodecInfo * self,
|
||||
const gchar * type)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jobject object = NULL;
|
||||
jstring type_str = NULL;
|
||||
GstAmMediaCodecCapabilities *caps = NULL;
|
||||
|
||||
type_str = (*env)->NewStringUTF (env, type);
|
||||
if (!type_str)
|
||||
goto done;
|
||||
|
||||
object = AMMCI_CALL (goto done, Object, getCapabilitiesForType, type_str);
|
||||
|
||||
if (object) {
|
||||
caps = g_slice_new0 (GstAmMediaCodecCapabilities);
|
||||
caps->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!caps->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaCodecCapabilities, caps);
|
||||
caps = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (type_str)
|
||||
(*env)->DeleteLocalRef (env, type_str);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
gchar *
|
||||
gst_am_mediacodecinfo_get_name (GstAmMediaCodecInfo * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring v_str = NULL;
|
||||
const gchar *v = NULL;
|
||||
gchar *ret = NULL;
|
||||
|
||||
v_str = AMMCI_CALL (return NULL, Object, getName);
|
||||
if (v_str) {
|
||||
v = (*env)->GetStringUTFChars (env, v_str, NULL);
|
||||
if (!v) {
|
||||
GST_ERROR ("Failed to convert string to UTF8");
|
||||
(*env)->ExceptionClear (env);
|
||||
goto done;
|
||||
}
|
||||
ret = g_strdup (v);
|
||||
}
|
||||
|
||||
done:
|
||||
if (v)
|
||||
(*env)->ReleaseStringUTFChars (env, v_str, v);
|
||||
if (v_str)
|
||||
(*env)->DeleteLocalRef (env, v_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GList *
|
||||
gst_am_mediacodecinfo_get_supported_types (GstAmMediaCodecInfo * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jarray arr = NULL;
|
||||
jint arr_len = 0;
|
||||
GList *ret = NULL;
|
||||
gint i;
|
||||
|
||||
arr = AMMCI_CALL (goto done, Object, getSupportedTypes);
|
||||
if (!arr)
|
||||
goto done;
|
||||
arr_len = (*env)->GetArrayLength (env, arr);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get array length");
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < arr_len; i++) {
|
||||
jstring str = NULL;
|
||||
const gchar *str_v = NULL;
|
||||
|
||||
str = (*env)->GetObjectArrayElement (env, arr, i);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get array element %d", i);
|
||||
continue;
|
||||
}
|
||||
if (!str)
|
||||
continue;
|
||||
|
||||
str_v = (*env)->GetStringUTFChars (env, str, NULL);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get string characters");
|
||||
(*env)->DeleteLocalRef (env, str);
|
||||
str = NULL;
|
||||
continue;
|
||||
}
|
||||
ret = g_list_append (ret, g_strdup (str_v));
|
||||
(*env)->ReleaseStringUTFChars (env, str, str_v);
|
||||
str_v = NULL;
|
||||
(*env)->DeleteLocalRef (env, str);
|
||||
str = NULL;
|
||||
}
|
||||
|
||||
done:
|
||||
if (arr)
|
||||
(*env)->DeleteLocalRef (env, arr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediacodecinfo_is_encoder (GstAmMediaCodecInfo * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gboolean ret = FALSE;
|
||||
|
||||
ret = AMMCI_CALL (return FALSE, Boolean, isEncoder);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define AMMCC_FIELD(error_statement, type, field) \
|
||||
GST_DVM_FIELD (error_statement, self->object, type, \
|
||||
android_media_mediacodeccapabilities, field);
|
||||
|
||||
GList *
|
||||
gst_am_mediacodeccapabilities_get_color_formats (GstAmMediaCodecCapabilities *
|
||||
self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GList *ret = NULL;
|
||||
jarray arr = NULL;
|
||||
jint arr_len = 0;
|
||||
jint *arr_n = NULL;
|
||||
gint i;
|
||||
|
||||
arr = AMMCC_FIELD (goto done, Object, colorFormats);
|
||||
arr_len = (*env)->GetArrayLength (env, arr);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get array length");
|
||||
goto done;
|
||||
}
|
||||
|
||||
arr_n = (*env)->GetIntArrayElements (env, arr, NULL);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get array elements");
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < arr_len; i++)
|
||||
ret = g_list_append (ret, GINT_TO_POINTER (arr_n[i]));
|
||||
|
||||
done:
|
||||
if (arr_n)
|
||||
(*env)->ReleaseIntArrayElements (env, arr, arr_n, JNI_ABORT);
|
||||
if (arr)
|
||||
(*env)->DeleteLocalRef (env, arr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GList *
|
||||
gst_am_mediacodeccapabilities_get_profile_levels (GstAmMediaCodecCapabilities *
|
||||
self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jarray arr = NULL;
|
||||
jint arr_len = 0;
|
||||
GList *ret = NULL;
|
||||
gint i;
|
||||
|
||||
arr = AMMCC_FIELD (goto done, Object, profileLevels);
|
||||
if (!arr)
|
||||
goto done;
|
||||
arr_len = (*env)->GetArrayLength (env, arr);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get array length");
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < arr_len; i++) {
|
||||
jobject object = NULL;
|
||||
|
||||
object = (*env)->GetObjectArrayElement (env, arr, i);
|
||||
if ((*env)->ExceptionCheck (env)) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get array element %d", i);
|
||||
continue;
|
||||
}
|
||||
if (!object)
|
||||
continue;
|
||||
|
||||
if (object) {
|
||||
GstAmMediaCodecProfileLevel *profile_level =
|
||||
g_slice_new0 (GstAmMediaCodecProfileLevel);
|
||||
|
||||
profile_level->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
object = NULL;
|
||||
if (!profile_level->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaCodecProfileLevel, profile_level);
|
||||
} else {
|
||||
ret = g_list_append (ret, profile_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (arr)
|
||||
(*env)->DeleteLocalRef (env, arr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define AMMCPL_FIELD(error_statement, type, field) \
|
||||
GST_DVM_FIELD (error_statement, self->object, type, \
|
||||
android_media_mediacodecprofilelevel, field);
|
||||
|
||||
gint
|
||||
gst_am_mediacodecprofilelevel_get_level (GstAmMediaCodecProfileLevel * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gint ret;
|
||||
|
||||
ret = AMMCPL_FIELD (return -1, Int, level);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_am_mediacodecprofilelevel_get_profile (GstAmMediaCodecProfileLevel * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gint ret;
|
||||
|
||||
ret = AMMCPL_FIELD (return -1, Int, profile);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GST_ANDROID_MEDIA_MEDIACODECINFO_H__
|
||||
#define __GST_ANDROID_MEDIA_MEDIACODECINFO_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <jni.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstAmMediaCodecInfo GstAmMediaCodecInfo;
|
||||
typedef struct _GstAmMediaCodecCapabilities GstAmMediaCodecCapabilities;
|
||||
typedef struct _GstAmMediaCodecProfileLevel GstAmMediaCodecProfileLevel;
|
||||
|
||||
struct _GstAmMediaCodecInfo {
|
||||
/*< private >*/
|
||||
jobject object; /* global reference */
|
||||
};
|
||||
|
||||
struct _GstAmMediaCodecCapabilities {
|
||||
/*< private >*/
|
||||
jobject object; /* global reference */
|
||||
};
|
||||
|
||||
struct _GstAmMediaCodecProfileLevel {
|
||||
/*< private >*/
|
||||
jobject object; /* global reference */
|
||||
};
|
||||
|
||||
gboolean gst_android_media_mediacodecinfo_init (void);
|
||||
void gst_android_media_mediacodecinfo_deinit (void);
|
||||
|
||||
void gst_am_mediacodecinfo_free (GstAmMediaCodecInfo * self);
|
||||
void gst_am_mediacodeccapabilities_free (GstAmMediaCodecCapabilities * self);
|
||||
void gst_am_mediacodecprofilelevel_free (GstAmMediaCodecProfileLevel * self);
|
||||
|
||||
GstAmMediaCodecCapabilities * gst_am_mediacodecinfo_get_capabilities_for_type (GstAmMediaCodecInfo * self, const gchar *type);
|
||||
gchar * gst_am_mediacodecinfo_get_name (GstAmMediaCodecInfo * self);
|
||||
/* GList <gchar *> */
|
||||
GList * gst_am_mediacodecinfo_get_supported_types (GstAmMediaCodecInfo * self);
|
||||
gboolean gst_am_mediacodecinfo_is_encoder (GstAmMediaCodecInfo * self);
|
||||
|
||||
/* GList <int> */
|
||||
GList * gst_am_mediacodeccapabilities_get_color_formats (GstAmMediaCodecCapabilities *self);
|
||||
/* GList <GstAmMediaCodecProfileLevel *> */
|
||||
GList * gst_am_mediacodeccapabilities_get_profile_levels (GstAmMediaCodecCapabilities *self);
|
||||
|
||||
gint gst_am_mediacodecprofilelevel_get_level (GstAmMediaCodecProfileLevel *self);
|
||||
gint gst_am_mediacodecprofilelevel_get_profile (GstAmMediaCodecProfileLevel *self);
|
||||
|
||||
extern gint AudioFormat_CHANNEL_OUT_FRONT_LEFT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_FRONT_RIGHT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_FRONT_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_LOW_FREQUENCY;
|
||||
extern gint AudioFormat_CHANNEL_OUT_BACK_LEFT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_BACK_RIGHT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_FRONT_LEFT_OF_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_BACK_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_SIDE_LEFT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_SIDE_RIGHT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_FRONT_LEFT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_FRONT_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_FRONT_RIGHT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_BACK_LEFT;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_BACK_CENTER;
|
||||
extern gint AudioFormat_CHANNEL_OUT_TOP_BACK_RIGHT;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_ANDROID_MEDIA_MEDIACODECINFO_H__ */
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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/dvm/gstdvm.h>
|
||||
|
||||
#include "gst-android-media-mediacodeclist.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jmethodID getCodecCount;
|
||||
jmethodID getCodecInfoAt;
|
||||
} android_media_mediacodeclist;
|
||||
|
||||
|
||||
static gboolean
|
||||
_init_classes (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
/* android.media.MediaCodecList */
|
||||
GST_DVM_GET_CLASS (android_media_mediacodeclist,
|
||||
"android/media/MediaCodecList");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediacodeclist, getCodecCount,
|
||||
"()I;");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediacodeclist, getCodecInfoAt,
|
||||
"(I)Landroid/media/MediaCodecInfo;");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_android_media_mediacodeclist_init (void)
|
||||
{
|
||||
if (!_init_classes ()) {
|
||||
gst_android_media_mediacodeclist_deinit ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gst_android_media_mediacodeclist_deinit (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
if (android_media_mediacodeclist.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediacodeclist.klass);
|
||||
android_media_mediacodeclist.klass = NULL;
|
||||
}
|
||||
|
||||
/* android.media.MediaFormat */
|
||||
#define AMMCL_STATIC_CALL(error_statement, type, method, ...) \
|
||||
GST_DVM_STATIC_CALL (error_statement, type, \
|
||||
android_media_mediacodeclist, method, ## __VA_ARGS__);
|
||||
|
||||
gint
|
||||
gst_am_mediacodeclist_get_codec_count (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gint count = 0;
|
||||
|
||||
count = AMMCL_STATIC_CALL (goto done, Int, getCodecCount);
|
||||
|
||||
done:
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
GstAmMediaCodecInfo *
|
||||
gst_am_mediacodeclist_get_codec_info_at (gint index)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GstAmMediaCodecInfo *info = NULL;
|
||||
jobject object = NULL;
|
||||
|
||||
object = AMMCL_STATIC_CALL (goto done, Object, getCodecInfoAt, index);
|
||||
if (object) {
|
||||
info = g_slice_new0 (GstAmMediaCodecInfo);
|
||||
info->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!info->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaCodecInfo, info);
|
||||
info = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return info;
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GST_ANDROID_MEDIA_MEDIACODECLIST_H__
|
||||
#define __GST_ANDROID_MEDIA_MEDIACODECLIST_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "gst-android-media-mediacodecinfo.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gboolean gst_android_media_mediacodeclist_init (void);
|
||||
void gst_android_media_mediacodeclist_deinit (void);
|
||||
|
||||
gint gst_am_mediacodeclist_get_codec_count (void);
|
||||
GstAmMediaCodecInfo * gst_am_mediacodeclist_get_codec_info_at (int index);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_ANDROID_MEDIA_MEDIACODECLIST_H__ */
|
|
@ -1,554 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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/dvm/gstdvm.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gst-android-media-mediaformat.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
jclass klass;
|
||||
jmethodID constructor;
|
||||
jmethodID containsKey;
|
||||
jmethodID createAudioFormat;
|
||||
jmethodID createVideoFormat;
|
||||
jmethodID getByteBuffer;
|
||||
jmethodID getFloat;
|
||||
jmethodID getInteger;
|
||||
jmethodID getLong;
|
||||
jmethodID getString;
|
||||
jmethodID setByteBuffer;
|
||||
jmethodID setFloat;
|
||||
jmethodID setInteger;
|
||||
jmethodID setLong;
|
||||
jmethodID setString;
|
||||
jmethodID toString;
|
||||
} android_media_mediaformat;
|
||||
|
||||
|
||||
static gboolean
|
||||
_init_classes (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
/* android.media.MediaFormat */
|
||||
GST_DVM_GET_CLASS (android_media_mediaformat, "android/media/MediaFormat");
|
||||
GST_DVM_GET_CONSTRUCTOR (android_media_mediaformat, constructor, "()V");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediaformat, createAudioFormat,
|
||||
"(Ljava/lang/String;II)Landroid/media/MediaFormat;");
|
||||
GST_DVM_GET_STATIC_METHOD (android_media_mediaformat, createVideoFormat,
|
||||
"(Ljava/lang/String;II)Landroid/media/MediaFormat;");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, toString,
|
||||
"()Ljava/lang/String;");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, containsKey,
|
||||
"(Ljava/lang/String;)Z");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, getFloat,
|
||||
"(Ljava/lang/String;)F");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, setFloat,
|
||||
"(Ljava/lang/String;F)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, getInteger,
|
||||
"(Ljava/lang/String;)I");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, setInteger,
|
||||
"(Ljava/lang/String;I)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, getLong,
|
||||
"(Ljava/lang/String;)J");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, setLong,
|
||||
"(Ljava/lang/String;J)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, getString,
|
||||
"(Ljava/lang/String;)Ljava/lang/String;");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, setString,
|
||||
"(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, getByteBuffer,
|
||||
"(Ljava/lang/String;)Ljava/nio/ByteBuffer;");
|
||||
GST_DVM_GET_METHOD (android_media_mediaformat, setByteBuffer,
|
||||
"(Ljava/lang/String;Ljava/nio/ByteBuffer;)V");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_android_media_mediaformat_init (void)
|
||||
{
|
||||
if (!_init_classes ()) {
|
||||
gst_android_media_mediaformat_deinit ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gst_android_media_mediaformat_deinit (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
if (android_media_mediaformat.klass)
|
||||
(*env)->DeleteGlobalRef (env, android_media_mediaformat.klass);
|
||||
android_media_mediaformat.klass = NULL;
|
||||
}
|
||||
|
||||
/* android.media.MediaFormat */
|
||||
#define AMMF_CALL(error_statement, type, method, ...) \
|
||||
GST_DVM_CALL (error_statement, self->object, type, \
|
||||
android_media_mediaformat, method, ## __VA_ARGS__);
|
||||
#define AMMF_STATIC_CALL(error_statement, type, method, ...) \
|
||||
GST_DVM_STATIC_CALL (error_statement, type, \
|
||||
android_media_mediaformat, method, ## __VA_ARGS__);
|
||||
|
||||
GstAmMediaFormat *
|
||||
gst_am_mediaformat_new (void)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GstAmMediaFormat *format = NULL;
|
||||
jobject object = NULL;
|
||||
|
||||
object = (*env)->NewObject (env, android_media_mediaformat.klass,
|
||||
android_media_mediaformat.constructor);
|
||||
if ((*env)->ExceptionCheck (env) || !object) {
|
||||
GST_ERROR ("Failed to create callback object");
|
||||
(*env)->ExceptionClear (env);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
format = g_slice_new0 (GstAmMediaFormat);
|
||||
format->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!format->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaFormat, format);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
GstAmMediaFormat *
|
||||
gst_am_mediaformat_create_audio_format (const gchar * mime,
|
||||
gint sample_rate, gint channels)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GstAmMediaFormat *format = NULL;
|
||||
jstring mime_str;
|
||||
jobject object = NULL;
|
||||
|
||||
mime_str = (*env)->NewStringUTF (env, mime);
|
||||
if (mime_str == NULL)
|
||||
goto done;
|
||||
|
||||
object = AMMF_STATIC_CALL (goto done, Object, createAudioFormat, mime_str,
|
||||
sample_rate, channels);
|
||||
if (object) {
|
||||
format = g_slice_new0 (GstAmMediaFormat);
|
||||
format->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!format->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaFormat, format);
|
||||
format = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (mime_str)
|
||||
(*env)->DeleteLocalRef (env, mime_str);
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
GstAmMediaFormat *
|
||||
gst_am_mediaformat_create_video_format (const gchar * mime,
|
||||
gint width, gint height)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
GstAmMediaFormat *format = NULL;
|
||||
jstring mime_str;
|
||||
jobject object = NULL;
|
||||
|
||||
mime_str = (*env)->NewStringUTF (env, mime);
|
||||
if (mime_str == NULL)
|
||||
goto done;
|
||||
|
||||
object = AMMF_STATIC_CALL (goto done, Object, createVideoFormat, mime_str,
|
||||
width, height);
|
||||
if (object) {
|
||||
format = g_slice_new0 (GstAmMediaFormat);
|
||||
format->object = (*env)->NewGlobalRef (env, object);
|
||||
(*env)->DeleteLocalRef (env, object);
|
||||
if (!format->object) {
|
||||
GST_ERROR ("Failed to create global reference");
|
||||
(*env)->ExceptionClear (env);
|
||||
g_slice_free (GstAmMediaFormat, format);
|
||||
format = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (mime_str)
|
||||
(*env)->DeleteLocalRef (env, mime_str);
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
void
|
||||
gst_am_mediaformat_free (GstAmMediaFormat * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
|
||||
(*env)->DeleteGlobalRef (env, self->object);
|
||||
g_slice_free (GstAmMediaFormat, self);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gst_am_mediaformat_to_string (GstAmMediaFormat * self)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring v_str = NULL;
|
||||
const gchar *v = NULL;
|
||||
gchar *ret = NULL;
|
||||
|
||||
v_str = AMMF_CALL (return NULL, Object, toString);
|
||||
if (v_str) {
|
||||
v = (*env)->GetStringUTFChars (env, v_str, NULL);
|
||||
if (!v) {
|
||||
GST_ERROR ("Failed to convert string to UTF8");
|
||||
(*env)->ExceptionClear (env);
|
||||
goto done;
|
||||
}
|
||||
ret = g_strdup (v);
|
||||
}
|
||||
|
||||
done:
|
||||
if (v)
|
||||
(*env)->ReleaseStringUTFChars (env, v_str, v);
|
||||
if (v_str)
|
||||
(*env)->DeleteLocalRef (env, v_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_contains_key (GstAmMediaFormat * self, const gchar * key)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gboolean ret = FALSE;
|
||||
jstring key_str = NULL;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
ret = AMMF_CALL (ret = FALSE; goto done, Boolean, containsKey, key_str);
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_get_float (GstAmMediaFormat * self, const gchar * key,
|
||||
gfloat * value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
*value = 0;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
*value = AMMF_CALL (goto done, Float, getFloat, key_str);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_set_float (GstAmMediaFormat * self, const gchar * key,
|
||||
gfloat value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
AMMF_CALL (goto done, Void, setFloat, key_str, value);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_get_int (GstAmMediaFormat * self, const gchar * key,
|
||||
gint * value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
*value = 0;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
*value = AMMF_CALL (goto done, Int, getInteger, key_str);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_set_int (GstAmMediaFormat * self, const gchar * key,
|
||||
gint value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
AMMF_CALL (goto done, Void, setInteger, key_str, value);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_get_long (GstAmMediaFormat * self, const gchar * key,
|
||||
glong * value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
jlong long_value;
|
||||
|
||||
*value = 0;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
long_value = AMMF_CALL (goto done, Long, getLong, key_str);
|
||||
*value = long_value;
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_set_long (GstAmMediaFormat * self, const gchar * key,
|
||||
glong value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
jlong long_value = value;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
AMMF_CALL (goto done, Void, setLong, key_str, long_value);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_get_string (GstAmMediaFormat * self, const gchar * key,
|
||||
gchar ** value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gboolean ret = FALSE;
|
||||
jstring key_str = NULL;
|
||||
jstring v_str = NULL;
|
||||
const gchar *v = NULL;
|
||||
|
||||
*value = 0;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
v_str = AMMF_CALL (goto done, Object, getString, key_str);
|
||||
|
||||
v = (*env)->GetStringUTFChars (env, v_str, NULL);
|
||||
if (!v) {
|
||||
GST_ERROR ("Failed to convert string to UTF8");
|
||||
(*env)->ExceptionClear (env);
|
||||
goto done;
|
||||
}
|
||||
|
||||
*value = g_strdup (v);
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
if (v)
|
||||
(*env)->ReleaseStringUTFChars (env, v_str, v);
|
||||
if (v_str)
|
||||
(*env)->DeleteLocalRef (env, v_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_set_string (GstAmMediaFormat * self, const gchar * key,
|
||||
const gchar * value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
jstring v_str = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
v_str = (*env)->NewStringUTF (env, value);
|
||||
if (!v_str)
|
||||
goto done;
|
||||
|
||||
AMMF_CALL (goto done, Void, setString, key_str, v_str);
|
||||
ret = TRUE;
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
if (v_str)
|
||||
(*env)->DeleteLocalRef (env, v_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_get_buffer (GstAmMediaFormat * self, const gchar * key,
|
||||
GstBuffer ** value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
gboolean ret = FALSE;
|
||||
jstring key_str = NULL;
|
||||
jobject v = NULL;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
|
||||
*value = 0;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
v = AMMF_CALL (goto done, Object, getByteBuffer, key_str);
|
||||
|
||||
data = (*env)->GetDirectBufferAddress (env, v);
|
||||
if (!data) {
|
||||
(*env)->ExceptionClear (env);
|
||||
GST_ERROR ("Failed to get buffer address");
|
||||
goto done;
|
||||
}
|
||||
size = (*env)->GetDirectBufferCapacity (env, v);
|
||||
*value = gst_buffer_new_and_alloc (size);
|
||||
memcpy (GST_BUFFER_DATA (*value), data, size);
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
if (v)
|
||||
(*env)->DeleteLocalRef (env, v);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_am_mediaformat_set_buffer (GstAmMediaFormat * self, const gchar * key,
|
||||
GstBuffer * value)
|
||||
{
|
||||
JNIEnv *env = gst_dvm_get_env ();
|
||||
jstring key_str = NULL;
|
||||
jobject v = NULL;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
key_str = (*env)->NewStringUTF (env, key);
|
||||
if (!key_str)
|
||||
goto done;
|
||||
|
||||
/* FIXME: The buffer must remain valid until the codec is stopped */
|
||||
v = (*env)->NewDirectByteBuffer (env, GST_BUFFER_DATA (value),
|
||||
GST_BUFFER_SIZE (value));
|
||||
if (!v)
|
||||
goto done;
|
||||
|
||||
AMMF_CALL (goto done, Void, setByteBuffer, key_str, v);
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
if (key_str)
|
||||
(*env)->DeleteLocalRef (env, key_str);
|
||||
if (v)
|
||||
(*env)->DeleteLocalRef (env, v);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012, Collabora Ltd.
|
||||
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GST_ANDROID_MEDIA_MEDIAFORMAT_H__
|
||||
#define __GST_ANDROID_MEDIA_MEDIAFORMAT_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <jni.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstAmMediaFormat GstAmMediaFormat;
|
||||
|
||||
struct _GstAmMediaFormat {
|
||||
/*< private >*/
|
||||
jobject object; /* global reference */
|
||||
};
|
||||
|
||||
gboolean gst_android_media_mediaformat_init (void);
|
||||
void gst_android_media_mediaformat_deinit (void);
|
||||
|
||||
GstAmMediaFormat * gst_am_mediaformat_new (void);
|
||||
GstAmMediaFormat * gst_am_mediaformat_create_audio_format (const gchar *mime,
|
||||
gint sample_rate, gint channels);
|
||||
GstAmMediaFormat * gst_am_mediaformat_create_video_format (const gchar *mime,
|
||||
gint width, gint height);
|
||||
void gst_am_mediaformat_free (GstAmMediaFormat * self);
|
||||
|
||||
gboolean gst_am_mediaformat_get_float (GstAmMediaFormat * self,
|
||||
const gchar *key, gfloat *value);
|
||||
gboolean gst_am_mediaformat_set_float (GstAmMediaFormat * self,
|
||||
const gchar *key, gfloat value);
|
||||
gboolean gst_am_mediaformat_get_int (GstAmMediaFormat * self,
|
||||
const gchar *key, gint *value);
|
||||
gboolean gst_am_mediaformat_set_int (GstAmMediaFormat * self,
|
||||
const gchar *key, gint value);
|
||||
gboolean gst_am_mediaformat_get_long (GstAmMediaFormat * self,
|
||||
const gchar *key, glong *value);
|
||||
gboolean gst_am_mediaformat_set_long (GstAmMediaFormat * self,
|
||||
const gchar *key, glong value);
|
||||
gboolean gst_am_mediaformat_get_string (GstAmMediaFormat * self,
|
||||
const gchar *key, gchar **value);
|
||||
gboolean gst_am_mediaformat_set_string (GstAmMediaFormat * self,
|
||||
const gchar *key, const gchar *value);
|
||||
gboolean gst_am_mediaformat_get_buffer (GstAmMediaFormat * self,
|
||||
const gchar *key, GstBuffer **value);
|
||||
gboolean gst_am_mediaformat_set_buffer (GstAmMediaFormat * self,
|
||||
const gchar *key, GstBuffer *value);
|
||||
|
||||
|
||||
gboolean gst_am_mediaformat_contains_key (GstAmMediaFormat * self,
|
||||
const gchar *key);
|
||||
gchar * gst_am_mediaformat_to_string (GstAmMediaFormat * self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_ANDROID_MEDIA_MEDIAFORMAT_H__ */
|
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,9 @@
|
|||
* 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
|
||||
|
@ -68,6 +71,7 @@ struct _GstAHCSrc
|
|||
gint fps_max;
|
||||
gboolean start;
|
||||
gboolean smooth_zoom;
|
||||
GMutex mutex;
|
||||
|
||||
/* Properties */
|
||||
gint device;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue