androidmedia: allow multiple implementations of codec and format

When implementing NDK media support, it would be useful to also have JNI
implementation in the same binary as NDK media compatibility is lower.
As such, implement a rudimentary vtable system for gstamc-codec and
gstamc-format, and allow choosing the implementation at static_init()
time.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4115>
This commit is contained in:
Ratchanan Srirattanamet 2023-11-12 02:32:21 +07:00 committed by GStreamer Marge Bot
parent d0ffcb46df
commit a50ce9c6b0
13 changed files with 716 additions and 153 deletions

View file

@ -0,0 +1,179 @@
/*
* Copyright (C) 2012,2018 Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) 2022 Ratchanan Srirattanamet <peathot@hotmail.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 <gst/gst.h>
#include "gstamc-codec.h"
GstAmcCodecVTable *gst_amc_codec_vtable = NULL;
void
gst_amc_buffer_free (GstAmcBuffer * buffer)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->buffer_free (buffer);
}
gboolean
gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err,
gint position, gint limit)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->buffer_set_position_and_limit (buffer, err,
position, limit);
}
GstAmcCodec *
gst_amc_codec_new (const gchar * name, gboolean is_encoder, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->create (name, is_encoder, err);
}
void
gst_amc_codec_free (GstAmcCodec * codec)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->free (codec);
}
gboolean
gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format,
GstAmcSurfaceTexture * surface_texture, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->configure (codec, format, surface_texture, err);
}
GstAmcFormat *
gst_amc_codec_get_output_format (GstAmcCodec * codec, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->get_output_format (codec, err);
}
gboolean
gst_amc_codec_start (GstAmcCodec * codec, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->start (codec, err);
}
gboolean
gst_amc_codec_stop (GstAmcCodec * codec, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->stop (codec, err);
}
gboolean
gst_amc_codec_flush (GstAmcCodec * codec, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->flush (codec, err);
}
gboolean
gst_amc_codec_release (GstAmcCodec * codec, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->release (codec, err);
}
gboolean
gst_amc_codec_request_key_frame (GstAmcCodec * codec, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->request_key_frame (codec, err);
}
gboolean
gst_amc_codec_have_dynamic_bitrate (void)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->have_dynamic_bitrate ();
}
gboolean
gst_amc_codec_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err,
gint bitrate)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->set_dynamic_bitrate (codec, err, bitrate);
}
GstAmcBuffer *
gst_amc_codec_get_output_buffer (GstAmcCodec * codec, gint index, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->get_output_buffer (codec, index, err);
}
GstAmcBuffer *
gst_amc_codec_get_input_buffer (GstAmcCodec * codec, gint index, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->get_input_buffer (codec, index, err);
}
gint
gst_amc_codec_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs,
GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->dequeue_input_buffer (codec, timeoutUs, err);
}
gint
gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec,
GstAmcBufferInfo * info, gint64 timeoutUs, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->dequeue_output_buffer (codec, info, timeoutUs,
err);
}
gboolean
gst_amc_codec_queue_input_buffer (GstAmcCodec * codec, gint index,
const GstAmcBufferInfo * info, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->queue_input_buffer (codec, index, info, err);
}
gboolean
gst_amc_codec_release_output_buffer (GstAmcCodec * codec, gint index,
gboolean render, GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->release_output_buffer (codec, index, render,
err);
}
GstAmcSurfaceTexture *
gst_amc_codec_new_surface_texture (GError ** err)
{
g_assert (gst_amc_codec_vtable != NULL);
return gst_amc_codec_vtable->new_surface_texture (err);
}

View file

@ -30,6 +30,7 @@ G_BEGIN_DECLS
typedef struct _GstAmcBuffer GstAmcBuffer; typedef struct _GstAmcBuffer GstAmcBuffer;
typedef struct _GstAmcBufferInfo GstAmcBufferInfo; typedef struct _GstAmcBufferInfo GstAmcBufferInfo;
typedef struct _GstAmcCodecVTable GstAmcCodecVTable;
typedef struct _GstAmcCodec GstAmcCodec; typedef struct _GstAmcCodec GstAmcCodec;
struct _GstAmcBuffer { struct _GstAmcBuffer {
@ -44,6 +45,82 @@ struct _GstAmcBufferInfo {
gint size; gint size;
}; };
struct _GstAmcCodecVTable
{
void (* buffer_free) (GstAmcBuffer * buffer);
gboolean (* buffer_set_position_and_limit) (GstAmcBuffer * buffer,
GError ** err,
gint position,
gint limit);
GstAmcCodec * (* create) (const gchar * name,
gboolean is_encoder,
GError ** err);
void (* free) (GstAmcCodec * codec);
gboolean (* configure) (GstAmcCodec * codec,
GstAmcFormat * format,
GstAmcSurfaceTexture * surface_texture,
GError **err);
GstAmcFormat * (* get_output_format) (GstAmcCodec * codec,
GError **err);
gboolean (* start) (GstAmcCodec * codec,
GError **err);
gboolean (* stop) (GstAmcCodec * codec,
GError **err);
gboolean (* flush) (GstAmcCodec * codec,
GError **err);
gboolean (* release) (GstAmcCodec * codec,
GError **err);
gboolean (* request_key_frame) (GstAmcCodec * codec,
GError **err);
gboolean (* have_dynamic_bitrate) (void);
gboolean (* set_dynamic_bitrate) (GstAmcCodec * codec,
GError **err,
gint bitrate);
GstAmcBuffer * (* get_output_buffer) (GstAmcCodec * codec,
gint index,
GError **err);
GstAmcBuffer * (* get_input_buffer) (GstAmcCodec * codec,
gint index,
GError **err);
gint (* dequeue_input_buffer) (GstAmcCodec * codec,
gint64 timeoutUs,
GError **err);
gint (* dequeue_output_buffer) (GstAmcCodec * codec,
GstAmcBufferInfo *info,
gint64 timeoutUs,
GError **err);
gboolean (* queue_input_buffer) (GstAmcCodec * codec,
gint index,
const GstAmcBufferInfo *info,
GError **err);
gboolean (* release_output_buffer) (GstAmcCodec * codec,
gint index,
gboolean render,
GError **err);
GstAmcSurfaceTexture * (* new_surface_texture) (GError ** err);
};
extern GstAmcCodecVTable *gst_amc_codec_vtable;
void gst_amc_buffer_free (GstAmcBuffer * buffer); void gst_amc_buffer_free (GstAmcBuffer * buffer);
gboolean gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err, gboolean gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err,
gint position, gint limit); gint position, gint limit);

View file

@ -0,0 +1,122 @@
/*
* Copyright (C) 2012,2018 Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) 2023 Ratchanan Srirattanamet <peathot@hotmail.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 <gst/gst.h>
#include "gstamc-format.h"
GstAmcFormatVTable *gst_amc_format_vtable = NULL;
GstAmcFormat *
gst_amc_format_new_audio (const gchar * mime, gint sample_rate, gint channels,
GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->new_audio (mime, sample_rate, channels, err);
}
GstAmcFormat *
gst_amc_format_new_video (const gchar * mime, gint width, gint height,
GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->new_video (mime, width, height, err);
}
void
gst_amc_format_free (GstAmcFormat * format)
{
g_assert (gst_amc_format_vtable != NULL);
gst_amc_format_vtable->free (format);
}
gchar *
gst_amc_format_to_string (GstAmcFormat * format, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->to_string (format, err);
}
gboolean
gst_amc_format_get_float (GstAmcFormat * format, const gchar * key,
gfloat * value, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->get_float (format, key, value, err);
}
gboolean
gst_amc_format_set_float (GstAmcFormat * format, const gchar * key,
gfloat value, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->set_float (format, key, value, err);
}
gboolean
gst_amc_format_get_int (GstAmcFormat * format, const gchar * key, gint * value,
GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->get_int (format, key, value, err);
}
gboolean
gst_amc_format_set_int (GstAmcFormat * format, const gchar * key, gint value,
GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->set_int (format, key, value, err);
}
gboolean
gst_amc_format_get_string (GstAmcFormat * format, const gchar * key,
gchar ** value, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->get_string (format, key, value, err);
}
gboolean
gst_amc_format_set_string (GstAmcFormat * format, const gchar * key,
const gchar * value, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->set_string (format, key, value, err);
}
gboolean
gst_amc_format_get_buffer (GstAmcFormat * format, const gchar * key,
guint8 ** data, gsize * size, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->get_buffer (format, key, data, size, err);
}
gboolean
gst_amc_format_set_buffer (GstAmcFormat * format, const gchar * key,
guint8 * data, gsize size, GError ** err)
{
g_assert (gst_amc_format_vtable != NULL);
return gst_amc_format_vtable->set_buffer (format, key, data, size, err);
}

View file

@ -25,9 +25,71 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GstAmcFormatVTable GstAmcFormatVTable;
typedef struct _GstAmcFormat GstAmcFormat; typedef struct _GstAmcFormat GstAmcFormat;
typedef struct _GstAmcColorFormatInfo GstAmcColorFormatInfo; typedef struct _GstAmcColorFormatInfo GstAmcColorFormatInfo;
struct _GstAmcFormatVTable {
GstAmcFormat * (* new_audio) (const gchar *mime,
gint sample_rate,
gint channels,
GError **err);
GstAmcFormat * (* new_video) (const gchar *mime,
gint width,
gint height,
GError **err);
void (* free) (GstAmcFormat * format);
gchar * (* to_string) (GstAmcFormat * format,
GError **err);
gboolean (* get_float) (GstAmcFormat *format,
const gchar *key,
gfloat *value,
GError **err);
gboolean (* set_float) (GstAmcFormat *format,
const gchar *key,
gfloat value,
GError **err);
gboolean (* get_int) (GstAmcFormat *format,
const gchar *key,
gint *value,
GError **err);
gboolean (* set_int) (GstAmcFormat *format,
const gchar *key,
gint value,
GError **err);
gboolean (* get_string) (GstAmcFormat *format,
const gchar *key,
gchar **value,
GError **err);
gboolean (* set_string) (GstAmcFormat *format,
const gchar *key,
const gchar *value,
GError **err);
gboolean (* get_buffer) (GstAmcFormat *format,
const gchar *key,
guint8 **data,
gsize *size,
GError **err);
gboolean (* set_buffer) (GstAmcFormat *format,
const gchar *key,
guint8 *data,
gsize size,
GError **err);
};
extern GstAmcFormatVTable *gst_amc_format_vtable;
GstAmcFormat * gst_amc_format_new_audio (const gchar *mime, gint sample_rate, gint channels, GError **err); GstAmcFormat * gst_amc_format_new_audio (const gchar *mime, gint sample_rate, gint channels, GError **err);
GstAmcFormat * gst_amc_format_new_video (const gchar *mime, gint width, gint height, GError **err); GstAmcFormat * gst_amc_format_new_video (const gchar *mime, gint width, gint height, GError **err);
void gst_amc_format_free (GstAmcFormat * format); void gst_amc_format_free (GstAmcFormat * format);

View file

@ -413,8 +413,8 @@ error:
return FALSE; return FALSE;
} }
void static void
gst_amc_buffer_free (GstAmcBuffer * buffer_) gst_amc_buffer_jni_free (GstAmcBuffer * buffer_)
{ {
RealBuffer *buffer = (RealBuffer *) buffer_; RealBuffer *buffer = (RealBuffer *) buffer_;
JNIEnv *env; JNIEnv *env;
@ -470,9 +470,9 @@ gst_amc_buffer_get_position_and_limit (RealBuffer * buffer_, GError ** err,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer_, GError ** err, gst_amc_buffer_jni_set_position_and_limit (GstAmcBuffer * buffer_,
gint position, gint limit) GError ** err, gint position, gint limit)
{ {
RealBuffer *buffer = (RealBuffer *) buffer_; RealBuffer *buffer = (RealBuffer *) buffer_;
JNIEnv *env; JNIEnv *env;
@ -498,8 +498,8 @@ gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer_, GError ** err,
return TRUE; return TRUE;
} }
GstAmcCodec * static GstAmcCodec *
gst_amc_codec_new (const gchar * name, gboolean is_encoder, GError ** err) gst_amc_codec_jni_new (const gchar * name, gboolean is_encoder, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
GstAmcCodec *codec = NULL; GstAmcCodec *codec = NULL;
@ -545,8 +545,8 @@ error:
goto done; goto done;
} }
void static void
gst_amc_codec_free (GstAmcCodec * codec) gst_amc_codec_jni_free (GstAmcCodec * codec)
{ {
JNIEnv *env; JNIEnv *env;
@ -572,8 +572,8 @@ gst_amc_codec_free (GstAmcCodec * codec)
g_slice_free (GstAmcCodec, codec); g_slice_free (GstAmcCodec, codec);
} }
gboolean static gboolean
gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format, gst_amc_codec_jni_configure (GstAmcCodec * codec, GstAmcFormat * format,
GstAmcSurfaceTexture * surface, GError ** err) GstAmcSurfaceTexture * surface, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -602,8 +602,8 @@ gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format,
codec->surface ? codec->surface->jobject : NULL, NULL, flags); codec->surface ? codec->surface->jobject : NULL, NULL, flags);
} }
GstAmcFormat * static GstAmcFormat *
gst_amc_codec_get_output_format (GstAmcCodec * codec, GError ** err) gst_amc_codec_jni_get_output_format (GstAmcCodec * codec, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
GstAmcFormat *ret = NULL; GstAmcFormat *ret = NULL;
@ -633,8 +633,8 @@ done:
} }
static RealBuffer * static RealBuffer *
gst_amc_codec_get_input_buffers (GstAmcCodec * codec, gsize * n_buffers, gst_amc_codec_jni_get_input_buffers (GstAmcCodec * codec,
GError ** err) gsize * n_buffers, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
jobject input_buffers = NULL; jobject input_buffers = NULL;
@ -660,8 +660,8 @@ done:
} }
static RealBuffer * static RealBuffer *
gst_amc_codec_get_output_buffers (GstAmcCodec * codec, gsize * n_buffers, gst_amc_codec_jni_get_output_buffers (GstAmcCodec * codec,
GError ** err) gsize * n_buffers, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
jobject output_buffers = NULL; jobject output_buffers = NULL;
@ -686,8 +686,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_codec_start (GstAmcCodec * codec, GError ** err) gst_amc_codec_jni_start (GstAmcCodec * codec, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
gboolean ret; gboolean ret;
@ -705,7 +705,8 @@ gst_amc_codec_start (GstAmcCodec * codec, GError ** err)
gst_amc_jni_free_buffer_array (env, codec->input_buffers, gst_amc_jni_free_buffer_array (env, codec->input_buffers,
codec->n_input_buffers); codec->n_input_buffers);
codec->input_buffers = codec->input_buffers =
gst_amc_codec_get_input_buffers (codec, &codec->n_input_buffers, err); gst_amc_codec_jni_get_input_buffers (codec, &codec->n_input_buffers,
err);
if (!codec->input_buffers) { if (!codec->input_buffers) {
gst_amc_codec_stop (codec, NULL); gst_amc_codec_stop (codec, NULL);
return FALSE; return FALSE;
@ -715,8 +716,8 @@ gst_amc_codec_start (GstAmcCodec * codec, GError ** err)
return ret; return ret;
} }
gboolean static gboolean
gst_amc_codec_stop (GstAmcCodec * codec, GError ** err) gst_amc_codec_jni_stop (GstAmcCodec * codec, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -740,8 +741,8 @@ gst_amc_codec_stop (GstAmcCodec * codec, GError ** err)
media_codec.stop); media_codec.stop);
} }
gboolean static gboolean
gst_amc_codec_flush (GstAmcCodec * codec, GError ** err) gst_amc_codec_jni_flush (GstAmcCodec * codec, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -753,7 +754,7 @@ gst_amc_codec_flush (GstAmcCodec * codec, GError ** err)
} }
static gboolean static gboolean
gst_amc_codec_set_parameter (GstAmcCodec * codec, JNIEnv * env, gst_amc_codec_jni_set_parameter (GstAmcCodec * codec, JNIEnv * env,
GError ** err, const gchar * key, int value) GError ** err, const gchar * key, int value)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
@ -786,28 +787,28 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_codec_request_key_frame (GstAmcCodec * codec, GError ** err) gst_amc_codec_jni_request_key_frame (GstAmcCodec * codec, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
g_return_val_if_fail (codec != NULL, FALSE); g_return_val_if_fail (codec != NULL, FALSE);
env = gst_amc_jni_get_env (); env = gst_amc_jni_get_env ();
return gst_amc_codec_set_parameter (codec, env, err, return gst_amc_codec_jni_set_parameter (codec, env, err,
PARAMETER_KEY_REQUEST_SYNC_FRAME, 0); PARAMETER_KEY_REQUEST_SYNC_FRAME, 0);
} }
gboolean static gboolean
gst_amc_codec_have_dynamic_bitrate () gst_amc_codec_jni_have_dynamic_bitrate ()
{ {
/* Dynamic bitrate scaling is supported on Android >= 19, /* Dynamic bitrate scaling is supported on Android >= 19,
* where the setParameters() call is available */ * where the setParameters() call is available */
return (media_codec.setParameters != NULL); return (media_codec.setParameters != NULL);
} }
gboolean static gboolean
gst_amc_codec_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err, gst_amc_codec_jni_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err,
gint bitrate) gint bitrate)
{ {
JNIEnv *env; JNIEnv *env;
@ -815,12 +816,12 @@ gst_amc_codec_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err,
g_return_val_if_fail (codec != NULL, FALSE); g_return_val_if_fail (codec != NULL, FALSE);
env = gst_amc_jni_get_env (); env = gst_amc_jni_get_env ();
return gst_amc_codec_set_parameter (codec, env, err, return gst_amc_codec_jni_set_parameter (codec, env, err,
PARAMETER_KEY_VIDEO_BITRATE, bitrate); PARAMETER_KEY_VIDEO_BITRATE, bitrate);
} }
gboolean static gboolean
gst_amc_codec_release (GstAmcCodec * codec, GError ** err) gst_amc_codec_jni_release (GstAmcCodec * codec, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -844,8 +845,9 @@ gst_amc_codec_release (GstAmcCodec * codec, GError ** err)
media_codec.release); media_codec.release);
} }
GstAmcBuffer * static GstAmcBuffer *
gst_amc_codec_get_output_buffer (GstAmcCodec * codec, gint index, GError ** err) gst_amc_codec_jni_get_output_buffer (GstAmcCodec * codec, gint index,
GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
jobject buffer = NULL; jobject buffer = NULL;
@ -898,8 +900,9 @@ error:
return NULL; return NULL;
} }
GstAmcBuffer * static GstAmcBuffer *
gst_amc_codec_get_input_buffer (GstAmcCodec * codec, gint index, GError ** err) gst_amc_codec_jni_get_input_buffer (GstAmcCodec * codec, gint index,
GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
jobject buffer = NULL; jobject buffer = NULL;
@ -952,8 +955,8 @@ error:
return NULL; return NULL;
} }
gint static gint
gst_amc_codec_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs, gst_amc_codec_jni_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs,
GError ** err) GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -970,8 +973,8 @@ gst_amc_codec_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs,
} }
static gboolean static gboolean
gst_amc_codec_fill_buffer_info (JNIEnv * env, jobject buffer_info, gst_amc_codec_jni_fill_buffer_info (JNIEnv * env,
GstAmcBufferInfo * info, GError ** err) jobject buffer_info, GstAmcBufferInfo * info, GError ** err)
{ {
g_return_val_if_fail (buffer_info != NULL, FALSE); g_return_val_if_fail (buffer_info != NULL, FALSE);
@ -995,8 +998,8 @@ gst_amc_codec_fill_buffer_info (JNIEnv * env, jobject buffer_info,
return TRUE; return TRUE;
} }
gint static gint
gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec, gst_amc_codec_jni_dequeue_output_buffer (GstAmcCodec * codec,
GstAmcBufferInfo * info, gint64 timeoutUs, GError ** err) GstAmcBufferInfo * info, gint64 timeoutUs, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -1027,8 +1030,8 @@ gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec,
gst_amc_jni_free_buffer_array (env, codec->output_buffers, gst_amc_jni_free_buffer_array (env, codec->output_buffers,
codec->n_output_buffers); codec->n_output_buffers);
codec->output_buffers = codec->output_buffers =
gst_amc_codec_get_output_buffers (codec, gst_amc_codec_jni_get_output_buffers (codec, &codec->n_output_buffers,
&codec->n_output_buffers, err); err);
if (!codec->output_buffers) { if (!codec->output_buffers) {
ret = G_MININT; ret = G_MININT;
goto done; goto done;
@ -1042,7 +1045,7 @@ gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec,
goto done; goto done;
} }
if (ret >= 0 && !gst_amc_codec_fill_buffer_info (env, info_o, info, err)) { if (ret >= 0 && !gst_amc_codec_jni_fill_buffer_info (env, info_o, info, err)) {
ret = G_MININT; ret = G_MININT;
goto done; goto done;
} }
@ -1055,8 +1058,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_codec_queue_input_buffer (GstAmcCodec * codec, gint index, gst_amc_codec_jni_queue_input_buffer (GstAmcCodec * codec, gint index,
const GstAmcBufferInfo * info, GError ** err) const GstAmcBufferInfo * info, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -1070,8 +1073,8 @@ gst_amc_codec_queue_input_buffer (GstAmcCodec * codec, gint index,
info->presentation_time_us, info->flags); info->presentation_time_us, info->flags);
} }
gboolean static gboolean
gst_amc_codec_release_output_buffer (GstAmcCodec * codec, gint index, gst_amc_codec_jni_release_output_buffer (GstAmcCodec * codec, gint index,
gboolean render, GError ** err) gboolean render, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -1083,8 +1086,40 @@ gst_amc_codec_release_output_buffer (GstAmcCodec * codec, gint index,
media_codec.release_output_buffer, index, render); media_codec.release_output_buffer, index, render);
} }
GstAmcSurfaceTexture * static GstAmcSurfaceTexture *
gst_amc_codec_new_surface_texture (GError ** err) gst_amc_codec_jni_new_surface_texture (GError ** err)
{ {
return (GstAmcSurfaceTexture *) gst_amc_surface_texture_jni_new (err); return (GstAmcSurfaceTexture *) gst_amc_surface_texture_jni_new (err);
} }
GstAmcCodecVTable gst_amc_codec_jni_vtable = {
.buffer_free = gst_amc_buffer_jni_free,
.buffer_set_position_and_limit = gst_amc_buffer_jni_set_position_and_limit,
.create = gst_amc_codec_jni_new,
.free = gst_amc_codec_jni_free,
.configure = gst_amc_codec_jni_configure,
.get_output_format = gst_amc_codec_jni_get_output_format,
.start = gst_amc_codec_jni_start,
.stop = gst_amc_codec_jni_stop,
.flush = gst_amc_codec_jni_flush,
.request_key_frame = gst_amc_codec_jni_request_key_frame,
.have_dynamic_bitrate = gst_amc_codec_jni_have_dynamic_bitrate,
.set_dynamic_bitrate = gst_amc_codec_jni_set_dynamic_bitrate,
.release = gst_amc_codec_jni_release,
.get_output_buffer = gst_amc_codec_jni_get_output_buffer,
.get_input_buffer = gst_amc_codec_jni_get_input_buffer,
.dequeue_input_buffer = gst_amc_codec_jni_dequeue_input_buffer,
.dequeue_output_buffer = gst_amc_codec_jni_dequeue_output_buffer,
.queue_input_buffer = gst_amc_codec_jni_queue_input_buffer,
.release_output_buffer = gst_amc_codec_jni_release_output_buffer,
.new_surface_texture = gst_amc_codec_jni_new_surface_texture,
};

View file

@ -131,9 +131,9 @@ done:
return ret; return ret;
} }
GstAmcFormat * static GstAmcFormat *
gst_amc_format_new_audio (const gchar * mime, gint sample_rate, gint channels, gst_amc_format_jni_new_audio (const gchar * mime, gint sample_rate,
GError ** err) gint channels, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
GstAmcFormat *format = NULL; GstAmcFormat *format = NULL;
@ -168,8 +168,8 @@ error:
goto done; goto done;
} }
GstAmcFormat * static GstAmcFormat *
gst_amc_format_new_video (const gchar * mime, gint width, gint height, gst_amc_format_jni_new_video (const gchar * mime, gint width, gint height,
GError ** err) GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -205,8 +205,8 @@ error:
goto done; goto done;
} }
void static void
gst_amc_format_free (GstAmcFormat * format) gst_amc_format_jni_free (GstAmcFormat * format)
{ {
JNIEnv *env; JNIEnv *env;
@ -217,8 +217,8 @@ gst_amc_format_free (GstAmcFormat * format)
g_slice_free (GstAmcFormat, format); g_slice_free (GstAmcFormat, format);
} }
gchar * static gchar *
gst_amc_format_to_string (GstAmcFormat * format, GError ** err) gst_amc_format_jni_to_string (GstAmcFormat * format, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
jstring v_str = NULL; jstring v_str = NULL;
@ -238,8 +238,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_get_float (GstAmcFormat * format, const gchar * key, gst_amc_format_jni_get_float (GstAmcFormat * format, const gchar * key,
gfloat * value, GError ** err) gfloat * value, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -269,8 +269,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_set_float (GstAmcFormat * format, const gchar * key, gst_amc_format_jni_set_float (GstAmcFormat * format, const gchar * key,
gfloat value, GError ** err) gfloat value, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -299,9 +299,9 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_get_int (GstAmcFormat * format, const gchar * key, gint * value, gst_amc_format_jni_get_int (GstAmcFormat * format, const gchar * key,
GError ** err) gint * value, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
gboolean ret = FALSE; gboolean ret = FALSE;
@ -331,9 +331,9 @@ done:
} }
gboolean static gboolean
gst_amc_format_set_int (GstAmcFormat * format, const gchar * key, gint value, gst_amc_format_jni_set_int (GstAmcFormat * format, const gchar * key,
GError ** err) gint value, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
jstring key_str = NULL; jstring key_str = NULL;
@ -361,8 +361,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_get_string (GstAmcFormat * format, const gchar * key, gst_amc_format_jni_get_string (GstAmcFormat * format, const gchar * key,
gchar ** value, GError ** err) gchar ** value, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -396,8 +396,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_set_string (GstAmcFormat * format, const gchar * key, gst_amc_format_jni_set_string (GstAmcFormat * format, const gchar * key,
const gchar * value, GError ** err) const gchar * value, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -434,8 +434,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_get_buffer (GstAmcFormat * format, const gchar * key, gst_amc_format_jni_get_buffer (GstAmcFormat * format, const gchar * key,
guint8 ** data, gsize * size, GError ** err) guint8 ** data, gsize * size, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -489,8 +489,8 @@ done:
return ret; return ret;
} }
gboolean static gboolean
gst_amc_format_set_buffer (GstAmcFormat * format, const gchar * key, gst_amc_format_jni_set_buffer (GstAmcFormat * format, const gchar * key,
guint8 * data, gsize size, GError ** err) guint8 * data, gsize size, GError ** err)
{ {
JNIEnv *env; JNIEnv *env;
@ -537,3 +537,20 @@ done:
return ret; return ret;
} }
GstAmcFormatVTable gst_amc_format_jni_vtable = {
.new_audio = gst_amc_format_jni_new_audio,
.new_video = gst_amc_format_jni_new_video,
.free = gst_amc_format_jni_free,
.to_string = gst_amc_format_jni_to_string,
.get_float = gst_amc_format_jni_get_float,
.set_float = gst_amc_format_jni_set_float,
.get_int = gst_amc_format_jni_get_int,
.set_int = gst_amc_format_jni_set_int,
.get_string = gst_amc_format_jni_get_string,
.set_string = gst_amc_format_jni_set_string,
.get_buffer = gst_amc_format_jni_get_buffer,
.set_buffer = gst_amc_format_jni_set_buffer,
};

View file

@ -35,5 +35,8 @@ gst_amc_static_init (void)
if (!gst_amc_surface_texture_jni_static_init ()) if (!gst_amc_surface_texture_jni_static_init ())
return FALSE; return FALSE;
gst_amc_format_vtable = &gst_amc_format_jni_vtable;
gst_amc_codec_vtable = &gst_amc_codec_jni_vtable;
return TRUE; return TRUE;
} }

View file

@ -19,6 +19,12 @@
#include <glib.h> #include <glib.h>
#include "../gstamc-format.h"
#include "../gstamc-codec.h"
extern GstAmcFormatVTable gst_amc_format_jni_vtable;
extern GstAmcCodecVTable gst_amc_codec_jni_vtable;
gboolean gst_amc_codeclist_jni_static_init (void); gboolean gst_amc_codeclist_jni_static_init (void);
gboolean gst_amc_format_jni_static_init (void); gboolean gst_amc_format_jni_static_init (void);
gboolean gst_amc_codec_jni_static_init (void); gboolean gst_amc_codec_jni_static_init (void);

View file

@ -35,14 +35,14 @@ struct _GstAmcCodec
GstAmcSurfaceTexture *surface_texture; GstAmcSurfaceTexture *surface_texture;
}; };
void static void
gst_amc_buffer_free (GstAmcBuffer * buffer) gst_amc_buffer_ml_free (GstAmcBuffer * buffer)
{ {
g_free (buffer); g_free (buffer);
} }
gboolean static gboolean
gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err, gst_amc_buffer_ml_set_position_and_limit (GstAmcBuffer * buffer, GError ** err,
gint position, gint limit) gint position, gint limit)
{ {
/* FIXME: Do we need to do something? /* FIXME: Do we need to do something?
@ -52,8 +52,8 @@ gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err,
return TRUE; return TRUE;
} }
GstAmcCodec * static GstAmcCodec *
gst_amc_codec_new (const gchar * name, gboolean is_encoder, GError ** err) gst_amc_codec_ml_new (const gchar * name, gboolean is_encoder, GError ** err)
{ {
GstAmcCodec *codec = NULL; GstAmcCodec *codec = NULL;
MLResult result; MLResult result;
@ -77,8 +77,8 @@ gst_amc_codec_new (const gchar * name, gboolean is_encoder, GError ** err)
return codec; return codec;
} }
void static void
gst_amc_codec_free (GstAmcCodec * codec) gst_amc_codec_ml_free (GstAmcCodec * codec)
{ {
g_return_if_fail (codec != NULL); g_return_if_fail (codec != NULL);
@ -88,8 +88,8 @@ gst_amc_codec_free (GstAmcCodec * codec)
g_slice_free (GstAmcCodec, codec); g_slice_free (GstAmcCodec, codec);
} }
gboolean static gboolean
gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format, gst_amc_codec_ml_configure (GstAmcCodec * codec, GstAmcFormat * format,
GstAmcSurfaceTexture * surface_texture, GError ** err) GstAmcSurfaceTexture * surface_texture, GError ** err)
{ {
MLResult result; MLResult result;
@ -107,7 +107,7 @@ gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format,
surface_texture); surface_texture);
result = MLMediaCodecConfigureWithSurface (codec->handle, result = MLMediaCodecConfigureWithSurface (codec->handle,
gst_amc_format_get_handle (format), surface_handle, 0); gst_amc_format_ml_get_handle (format), surface_handle, 0);
if (result != MLResult_Ok) { if (result != MLResult_Ok) {
g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED,
"Failed to configure codec %d", result); "Failed to configure codec %d", result);
@ -117,8 +117,8 @@ gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format,
return TRUE; return TRUE;
} }
GstAmcFormat * static GstAmcFormat *
gst_amc_codec_get_output_format (GstAmcCodec * codec, GError ** err) gst_amc_codec_ml_get_output_format (GstAmcCodec * codec, GError ** err)
{ {
MLHandle format_handle; MLHandle format_handle;
MLResult result; MLResult result;
@ -132,11 +132,11 @@ gst_amc_codec_get_output_format (GstAmcCodec * codec, GError ** err)
return NULL; return NULL;
} }
return gst_amc_format_new_handle (format_handle); return gst_amc_format_ml_new_handle (format_handle);
} }
gboolean static gboolean
gst_amc_codec_start (GstAmcCodec * codec, GError ** err) gst_amc_codec_ml_start (GstAmcCodec * codec, GError ** err)
{ {
MLResult result; MLResult result;
@ -152,8 +152,8 @@ gst_amc_codec_start (GstAmcCodec * codec, GError ** err)
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_codec_stop (GstAmcCodec * codec, GError ** err) gst_amc_codec_ml_stop (GstAmcCodec * codec, GError ** err)
{ {
MLResult result; MLResult result;
@ -169,8 +169,8 @@ gst_amc_codec_stop (GstAmcCodec * codec, GError ** err)
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_codec_flush (GstAmcCodec * codec, GError ** err) gst_amc_codec_ml_flush (GstAmcCodec * codec, GError ** err)
{ {
MLResult result; MLResult result;
@ -186,8 +186,8 @@ gst_amc_codec_flush (GstAmcCodec * codec, GError ** err)
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_codec_request_key_frame (GstAmcCodec * codec, GError ** err) gst_amc_codec_ml_request_key_frame (GstAmcCodec * codec, GError ** err)
{ {
/* If MagicLeap adds an API for requesting a keyframe, call it here */ /* If MagicLeap adds an API for requesting a keyframe, call it here */
g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED,
@ -195,8 +195,8 @@ gst_amc_codec_request_key_frame (GstAmcCodec * codec, GError ** err)
return FALSE; return FALSE;
} }
gboolean static gboolean
gst_amc_codec_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err, gst_amc_codec_ml_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err,
gint bitrate) gint bitrate)
{ {
g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED,
@ -204,22 +204,23 @@ gst_amc_codec_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err,
return FALSE; return FALSE;
} }
gboolean static gboolean
gst_amc_codec_have_dynamic_bitrate () gst_amc_codec_ml_have_dynamic_bitrate ()
{ {
/* If MagicLeap ever provides an API for scaling bitrate, change this to TRUE */ /* If MagicLeap ever provides an API for scaling bitrate, change this to TRUE */
return FALSE; return FALSE;
} }
gboolean static gboolean
gst_amc_codec_release (GstAmcCodec * codec, GError ** err) gst_amc_codec_ml_release (GstAmcCodec * codec, GError ** err)
{ {
g_return_val_if_fail (codec != NULL, FALSE); g_return_val_if_fail (codec != NULL, FALSE);
return TRUE; return TRUE;
} }
GstAmcBuffer * static GstAmcBuffer *
gst_amc_codec_get_output_buffer (GstAmcCodec * codec, gint index, GError ** err) gst_amc_codec_ml_get_output_buffer (GstAmcCodec * codec, gint index,
GError ** err)
{ {
MLResult result; MLResult result;
GstAmcBuffer *ret; GstAmcBuffer *ret;
@ -249,8 +250,9 @@ gst_amc_codec_get_output_buffer (GstAmcCodec * codec, gint index, GError ** err)
return ret; return ret;
} }
GstAmcBuffer * static GstAmcBuffer *
gst_amc_codec_get_input_buffer (GstAmcCodec * codec, gint index, GError ** err) gst_amc_codec_ml_get_input_buffer (GstAmcCodec * codec, gint index,
GError ** err)
{ {
MLResult result; MLResult result;
GstAmcBuffer *ret; GstAmcBuffer *ret;
@ -273,8 +275,8 @@ gst_amc_codec_get_input_buffer (GstAmcCodec * codec, gint index, GError ** err)
return ret; return ret;
} }
gint static gint
gst_amc_codec_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs, gst_amc_codec_ml_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs,
GError ** err) GError ** err)
{ {
MLResult result; MLResult result;
@ -295,8 +297,8 @@ gst_amc_codec_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs,
return index; return index;
} }
gint static gint
gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec, gst_amc_codec_ml_dequeue_output_buffer (GstAmcCodec * codec,
GstAmcBufferInfo * info, gint64 timeoutUs, GError ** err) GstAmcBufferInfo * info, gint64 timeoutUs, GError ** err)
{ {
MLMediaCodecBufferInfo info_; MLMediaCodecBufferInfo info_;
@ -331,8 +333,8 @@ gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec,
return index; return index;
} }
gboolean static gboolean
gst_amc_codec_queue_input_buffer (GstAmcCodec * codec, gint index, gst_amc_codec_ml_queue_input_buffer (GstAmcCodec * codec, gint index,
const GstAmcBufferInfo * info, GError ** err) const GstAmcBufferInfo * info, GError ** err)
{ {
MLResult result; MLResult result;
@ -351,8 +353,8 @@ gst_amc_codec_queue_input_buffer (GstAmcCodec * codec, gint index,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_codec_release_output_buffer (GstAmcCodec * codec, gint index, gst_amc_codec_ml_release_output_buffer (GstAmcCodec * codec, gint index,
gboolean render, GError ** err) gboolean render, GError ** err)
{ {
MLResult result; MLResult result;
@ -369,8 +371,40 @@ gst_amc_codec_release_output_buffer (GstAmcCodec * codec, gint index,
return TRUE; return TRUE;
} }
GstAmcSurfaceTexture * static GstAmcSurfaceTexture *
gst_amc_codec_new_surface_texture (GError ** err) gst_amc_codec_ml_new_surface_texture (GError ** err)
{ {
return (GstAmcSurfaceTexture *) gst_amc_surface_texture_ml_new (err); return (GstAmcSurfaceTexture *) gst_amc_surface_texture_ml_new (err);
} }
GstAmcCodecVTable gst_amc_codec_ml_vtable = {
.buffer_free = gst_amc_buffer_ml_free,
.buffer_set_position_and_limit = gst_amc_buffer_ml_set_position_and_limit,
.create = gst_amc_codec_ml_new,
.free = gst_amc_codec_ml_free,
.configure = gst_amc_codec_ml_configure,
.get_output_format = gst_amc_codec_ml_get_output_format,
.start = gst_amc_codec_ml_start,
.stop = gst_amc_codec_ml_stop,
.flush = gst_amc_codec_ml_flush,
.request_key_frame = gst_amc_codec_ml_request_key_frame,
.have_dynamic_bitrate = gst_amc_codec_ml_have_dynamic_bitrate,
.set_dynamic_bitrate = gst_amc_codec_ml_set_dynamic_bitrate,
.release = gst_amc_codec_ml_release,
.get_output_buffer = gst_amc_codec_ml_get_output_buffer,
.get_input_buffer = gst_amc_codec_ml_get_input_buffer,
.dequeue_input_buffer = gst_amc_codec_ml_dequeue_input_buffer,
.dequeue_output_buffer = gst_amc_codec_ml_dequeue_output_buffer,
.queue_input_buffer = gst_amc_codec_ml_queue_input_buffer,
.release_output_buffer = gst_amc_codec_ml_release_output_buffer,
.new_surface_texture = gst_amc_codec_ml_new_surface_texture,
};

View file

@ -32,9 +32,9 @@ struct _GstAmcFormat
MLHandle handle; MLHandle handle;
}; };
GstAmcFormat * static GstAmcFormat *
gst_amc_format_new_audio (const gchar * mime, gint sample_rate, gint channels, gst_amc_format_ml_new_audio (const gchar * mime, gint sample_rate,
GError ** err) gint channels, GError ** err)
{ {
GstAmcFormat *format = g_slice_new0 (GstAmcFormat); GstAmcFormat *format = g_slice_new0 (GstAmcFormat);
MLResult result; MLResult result;
@ -51,8 +51,8 @@ gst_amc_format_new_audio (const gchar * mime, gint sample_rate, gint channels,
return format; return format;
} }
GstAmcFormat * static GstAmcFormat *
gst_amc_format_new_video (const gchar * mime, gint width, gint height, gst_amc_format_ml_new_video (const gchar * mime, gint width, gint height,
GError ** err) GError ** err)
{ {
GstAmcFormat *format = g_slice_new0 (GstAmcFormat); GstAmcFormat *format = g_slice_new0 (GstAmcFormat);
@ -70,7 +70,7 @@ gst_amc_format_new_video (const gchar * mime, gint width, gint height,
} }
GstAmcFormat * GstAmcFormat *
gst_amc_format_new_handle (MLHandle handle) gst_amc_format_ml_new_handle (MLHandle handle)
{ {
GstAmcFormat *format = g_slice_new0 (GstAmcFormat); GstAmcFormat *format = g_slice_new0 (GstAmcFormat);
format->handle = handle; format->handle = handle;
@ -78,20 +78,20 @@ gst_amc_format_new_handle (MLHandle handle)
} }
MLHandle MLHandle
gst_amc_format_get_handle (GstAmcFormat * format) gst_amc_format_ml_get_handle (GstAmcFormat * format)
{ {
return format->handle; return format->handle;
} }
void static void
gst_amc_format_free (GstAmcFormat * format) gst_amc_format_ml_free (GstAmcFormat * format)
{ {
g_return_if_fail (format != NULL); g_return_if_fail (format != NULL);
g_slice_free (GstAmcFormat, format); g_slice_free (GstAmcFormat, format);
} }
gchar * static gchar *
gst_amc_format_to_string (GstAmcFormat * format, GError ** err) gst_amc_format_ml_to_string (GstAmcFormat * format, GError ** err)
{ {
MLResult result; MLResult result;
gchar *str; gchar *str;
@ -108,8 +108,8 @@ gst_amc_format_to_string (GstAmcFormat * format, GError ** err)
return str; return str;
} }
gboolean static gboolean
gst_amc_format_get_float (GstAmcFormat * format, const gchar * key, gst_amc_format_ml_get_float (GstAmcFormat * format, const gchar * key,
gfloat * value, GError ** err) gfloat * value, GError ** err)
{ {
MLResult result; MLResult result;
@ -128,8 +128,8 @@ gst_amc_format_get_float (GstAmcFormat * format, const gchar * key,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_set_float (GstAmcFormat * format, const gchar * key, gst_amc_format_ml_set_float (GstAmcFormat * format, const gchar * key,
gfloat value, GError ** err) gfloat value, GError ** err)
{ {
MLResult result; MLResult result;
@ -147,9 +147,9 @@ gst_amc_format_set_float (GstAmcFormat * format, const gchar * key,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_get_int (GstAmcFormat * format, const gchar * key, gint * value, gst_amc_format_ml_get_int (GstAmcFormat * format, const gchar * key,
GError ** err) gint * value, GError ** err)
{ {
MLResult result; MLResult result;
@ -167,8 +167,8 @@ gst_amc_format_get_int (GstAmcFormat * format, const gchar * key, gint * value,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_set_int (GstAmcFormat * format, const gchar * key, gint value, gst_amc_format_ml_set_int (GstAmcFormat * format, const gchar * key, gint value,
GError ** err) GError ** err)
{ {
MLResult result; MLResult result;
@ -185,8 +185,8 @@ gst_amc_format_set_int (GstAmcFormat * format, const gchar * key, gint value,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_get_string (GstAmcFormat * format, const gchar * key, gst_amc_format_ml_get_string (GstAmcFormat * format, const gchar * key,
gchar ** value, GError ** err) gchar ** value, GError ** err)
{ {
MLResult result; MLResult result;
@ -207,8 +207,8 @@ gst_amc_format_get_string (GstAmcFormat * format, const gchar * key,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_set_string (GstAmcFormat * format, const gchar * key, gst_amc_format_ml_set_string (GstAmcFormat * format, const gchar * key,
const gchar * value, GError ** err) const gchar * value, GError ** err)
{ {
MLResult result; MLResult result;
@ -225,8 +225,8 @@ gst_amc_format_set_string (GstAmcFormat * format, const gchar * key,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_get_buffer (GstAmcFormat * format, const gchar * key, gst_amc_format_ml_get_buffer (GstAmcFormat * format, const gchar * key,
guint8 ** data, gsize * size, GError ** err) guint8 ** data, gsize * size, GError ** err)
{ {
MLResult result; MLResult result;
@ -251,8 +251,8 @@ gst_amc_format_get_buffer (GstAmcFormat * format, const gchar * key,
return TRUE; return TRUE;
} }
gboolean static gboolean
gst_amc_format_set_buffer (GstAmcFormat * format, const gchar * key, gst_amc_format_ml_set_buffer (GstAmcFormat * format, const gchar * key,
guint8 * data, gsize size, GError ** err) guint8 * data, gsize size, GError ** err)
{ {
MLResult result; MLResult result;
@ -272,3 +272,20 @@ gst_amc_format_set_buffer (GstAmcFormat * format, const gchar * key,
} }
return TRUE; return TRUE;
} }
GstAmcFormatVTable gst_amc_format_ml_vtable = {
.new_audio = gst_amc_format_ml_new_audio,
.new_video = gst_amc_format_ml_new_video,
.free = gst_amc_format_ml_free,
.to_string = gst_amc_format_ml_to_string,
.get_float = gst_amc_format_ml_get_float,
.set_float = gst_amc_format_ml_set_float,
.get_int = gst_amc_format_ml_get_int,
.set_int = gst_amc_format_ml_set_int,
.get_string = gst_amc_format_ml_get_string,
.set_string = gst_amc_format_ml_set_string,
.get_buffer = gst_amc_format_ml_get_buffer,
.set_buffer = gst_amc_format_ml_set_buffer,
};

View file

@ -21,13 +21,17 @@
#ifndef __GST_AMC_INTERNAL_ML_H__ #ifndef __GST_AMC_INTERNAL_ML_H__
#define __GST_AMC_INTERNAL_ML_H__ #define __GST_AMC_INTERNAL_ML_H__
#include "../gstamc-codec.h"
#include "../gstamc-format.h" #include "../gstamc-format.h"
#include <ml_api.h> #include <ml_api.h>
G_BEGIN_DECLS G_BEGIN_DECLS
GstAmcFormat *gst_amc_format_new_handle (MLHandle handle); extern GstAmcFormatVTable gst_amc_format_ml_vtable;
MLHandle gst_amc_format_get_handle (GstAmcFormat * format); extern GstAmcCodecVTable gst_amc_codec_ml_vtable;
GstAmcFormat *gst_amc_format_ml_new_handle (MLHandle handle);
MLHandle gst_amc_format_ml_get_handle (GstAmcFormat * format);
G_END_DECLS G_END_DECLS

View file

@ -18,6 +18,7 @@
*/ */
#include "../gstamc.h" #include "../gstamc.h"
#include "gstamc-internal-ml.h"
gboolean gboolean
gst_amc_static_init (void) gst_amc_static_init (void)
@ -26,5 +27,9 @@ gst_amc_static_init (void)
* MagicLeap doesn't require any static initialization. All required * MagicLeap doesn't require any static initialization. All required
* functions are in C and are linked into the plugin directly. * functions are in C and are linked into the plugin directly.
*/ */
gst_amc_codec_vtable = &gst_amc_codec_ml_vtable;
gst_amc_format_vtable = &gst_amc_format_ml_vtable;
return TRUE; return TRUE;
} }

View file

@ -1,6 +1,8 @@
androidmedia_sources = [ androidmedia_sources = [
'gstamcaudiodec.c', 'gstamcaudiodec.c',
'gstamc.c', 'gstamc.c',
'gstamc-codec.c',
'gstamc-format.c',
'gstamcsurfacetexture.c', 'gstamcsurfacetexture.c',
'gstamcvideodec.c', 'gstamcvideodec.c',
'gstamcvideoenc.c', 'gstamcvideoenc.c',