diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c deleted file mode 100644 index 1563219088..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codec-ml.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright (C) 2018 Collabora Ltd. - * Author: Xavier Claessens - * - * 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 "gstamc-internal-ml.h" -#include "gstamc-surfacetexture-ml.h" -#include "../gstamc-codec.h" -#include "../gstamc-constants.h" - -#include - -struct _GstAmcCodec -{ - MLHandle handle; - GstAmcSurfaceTexture *surface_texture; -}; - -static void -gst_amc_buffer_ml_free (GstAmcBuffer * buffer) -{ - g_free (buffer); -} - -static gboolean -gst_amc_buffer_ml_set_position_and_limit (GstAmcBuffer * buffer, GError ** err, - gint position, gint limit) -{ -/* FIXME: Do we need to do something? - buffer->data = buffer->data + position; - buffer->size = limit; -*/ - return TRUE; -} - -static GstAmcCodec * -gst_amc_codec_ml_new (const gchar * name, gboolean is_encoder, GError ** err) -{ - GstAmcCodec *codec = NULL; - MLResult result; - MLMediaCodecType type; - - g_return_val_if_fail (name != NULL, NULL); - - codec = g_slice_new0 (GstAmcCodec); - codec->handle = ML_INVALID_HANDLE; - type = is_encoder ? MLMediaCodecType_Encoder : MLMediaCodecType_Decoder; - result = - MLMediaCodecCreateCodec (MLMediaCodecCreation_ByName, type, name, - &codec->handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to create codec by name %s: %d", name, result); - gst_amc_codec_free (codec); - return NULL; - } - - return codec; -} - -static void -gst_amc_codec_ml_free (GstAmcCodec * codec) -{ - g_return_if_fail (codec != NULL); - - if (codec->handle != ML_INVALID_HANDLE) - MLMediaCodecDestroy (codec->handle); - g_clear_object (&codec->surface_texture); - g_slice_free (GstAmcCodec, codec); -} - -static gboolean -gst_amc_codec_ml_configure (GstAmcCodec * codec, GstAmcFormat * format, - GstAmcSurfaceTexture * surface_texture, GError ** err) -{ - MLResult result; - MLHandle surface_handle = ML_INVALID_HANDLE; - - g_return_val_if_fail (codec != NULL, FALSE); - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (surface_texture == NULL - || GST_IS_AMC_SURFACE_TEXTURE_ML (surface_texture), FALSE); - - g_set_object (&codec->surface_texture, surface_texture); - if (surface_texture != NULL) - surface_handle = - gst_amc_surface_texture_ml_get_handle ((GstAmcSurfaceTextureML *) - surface_texture); - - result = MLMediaCodecConfigureWithSurface (codec->handle, - gst_amc_format_ml_get_handle (format), surface_handle, 0); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to configure codec %d", result); - return FALSE; - } - - return TRUE; -} - -static GstAmcFormat * -gst_amc_codec_ml_get_output_format (GstAmcCodec * codec, GError ** err) -{ - MLHandle format_handle; - MLResult result; - - g_return_val_if_fail (codec != NULL, NULL); - - result = MLMediaCodecGetOutputFormat (codec->handle, &format_handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get output format %d", result); - return NULL; - } - - return gst_amc_format_ml_new_handle (format_handle); -} - -static gboolean -gst_amc_codec_ml_start (GstAmcCodec * codec, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (codec != NULL, FALSE); - - result = MLMediaCodecStart (codec->handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to start codec %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_codec_ml_stop (GstAmcCodec * codec, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (codec != NULL, FALSE); - - result = MLMediaCodecStop (codec->handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to stop codec %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_codec_ml_flush (GstAmcCodec * codec, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (codec != NULL, FALSE); - - result = MLMediaCodecFlush (codec->handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to flush codec %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_codec_ml_request_key_frame (GstAmcCodec * codec, GError ** err) -{ - /* If MagicLeap adds an API for requesting a keyframe, call it here */ - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Keyframe requests are not available on MagicLeap"); - return FALSE; -} - -static gboolean -gst_amc_codec_ml_set_dynamic_bitrate (GstAmcCodec * codec, GError ** err, - gint bitrate) -{ - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Dynamic bitrate control isn't available on MagicLeap"); - return FALSE; -} - -static gboolean -gst_amc_codec_ml_have_dynamic_bitrate () -{ - /* If MagicLeap ever provides an API for scaling bitrate, change this to TRUE */ - return FALSE; -} - -static gboolean -gst_amc_codec_ml_release (GstAmcCodec * codec, GError ** err) -{ - g_return_val_if_fail (codec != NULL, FALSE); - return TRUE; -} - -static GstAmcBuffer * -gst_amc_codec_ml_get_output_buffer (GstAmcCodec * codec, gint index, - GError ** err) -{ - MLResult result; - GstAmcBuffer *ret; - - g_return_val_if_fail (codec != NULL, NULL); - g_return_val_if_fail (index >= 0, NULL); - - ret = g_new0 (GstAmcBuffer, 1); - - /* When configured with a surface, getting the buffer pointer makes no sense, - * but on Android it's not an error, it just return NULL buffer. - * But MLMediaCodecGetInputBufferPointer() will return an error instead. */ - if (codec->surface_texture != NULL) { - return ret; - } - - result = - MLMediaCodecGetOutputBufferPointer (codec->handle, index, - (const uint8_t **) &ret->data, &ret->size); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get output buffer %d", result); - g_free (ret); - return NULL; - } - - return ret; -} - -static GstAmcBuffer * -gst_amc_codec_ml_get_input_buffer (GstAmcCodec * codec, gint index, - GError ** err) -{ - MLResult result; - GstAmcBuffer *ret; - - g_return_val_if_fail (codec != NULL, NULL); - g_return_val_if_fail (index >= 0, NULL); - - ret = g_new0 (GstAmcBuffer, 1); - - result = - MLMediaCodecGetInputBufferPointer (codec->handle, index, &ret->data, - &ret->size); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get input buffer %d", result); - g_free (ret); - return NULL; - } - - return ret; -} - -static gint -gst_amc_codec_ml_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs, - GError ** err) -{ - MLResult result; - int64_t index; - - g_return_val_if_fail (codec != NULL, G_MININT); - - result = MLMediaCodecDequeueInputBuffer (codec->handle, timeoutUs, &index); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to dequeue input buffer %d", result); - return G_MININT; - } - - if (index == MLMediaCodec_TryAgainLater) - return INFO_TRY_AGAIN_LATER; - - return index; -} - -static gint -gst_amc_codec_ml_dequeue_output_buffer (GstAmcCodec * codec, - GstAmcBufferInfo * info, gint64 timeoutUs, GError ** err) -{ - MLMediaCodecBufferInfo info_; - MLResult result; - int64_t index; - - g_return_val_if_fail (codec != NULL, G_MININT); - - result = - MLMediaCodecDequeueOutputBuffer (codec->handle, &info_, timeoutUs, - &index); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to dequeue output buffer %d", result); - return G_MININT; - } - - if (index == MLMediaCodec_OutputBuffersChanged) { - return gst_amc_codec_dequeue_output_buffer (codec, info, timeoutUs, err); - } else if (index == MLMediaCodec_FormatChanged) { - return INFO_OUTPUT_FORMAT_CHANGED; - } else if (index == MLMediaCodec_TryAgainLater) { - return INFO_TRY_AGAIN_LATER; - } - - info->flags = info_.flags; - - info->offset = info_.offset; - info->presentation_time_us = info_.presentation_time_us; - info->size = info_.size; - - return index; -} - -static gboolean -gst_amc_codec_ml_queue_input_buffer (GstAmcCodec * codec, gint index, - const GstAmcBufferInfo * info, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (codec != NULL, FALSE); - g_return_val_if_fail (info != NULL, FALSE); - - result = MLMediaCodecQueueInputBuffer (codec->handle, index, info->offset, - info->size, info->presentation_time_us, info->flags); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to queue input buffer %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_codec_ml_release_output_buffer (GstAmcCodec * codec, gint index, - gboolean render, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (codec != NULL, FALSE); - - result = MLMediaCodecReleaseOutputBuffer (codec->handle, index, render); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to release output buffer %d", result); - return FALSE; - } - - return TRUE; -} - -static GstAmcSurfaceTexture * -gst_amc_codec_ml_new_surface_texture (GError ** 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, -}; diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c deleted file mode 100644 index 003bdd9c81..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-codeclist-ml.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2018 Collabora Ltd. - * Author: Xavier Claessens - * - * 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 "../gstamc-codeclist.h" - -#include - -struct _GstAmcCodecInfoHandle -{ - uint64_t index; -}; - -struct _GstAmcCodecCapabilitiesHandle -{ - uint64_t index; - gchar *type; -}; - -gboolean -gst_amc_codeclist_get_count (gint * count, GError ** err) -{ - MLResult result; - uint64_t n; - - result = MLMediaCodecListCountCodecs (&n); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get codec list count: %d", result); - return FALSE; - } - - *count = n; - - return TRUE; -} - -GstAmcCodecInfoHandle * -gst_amc_codeclist_get_codec_info_at (gint index, GError ** err) -{ - GstAmcCodecInfoHandle *ret = g_new0 (GstAmcCodecInfoHandle, 1); - ret->index = index; - return ret; -} - -void -gst_amc_codec_info_handle_free (GstAmcCodecInfoHandle * handle) -{ - g_free (handle); -} - -gchar * -gst_amc_codec_info_handle_get_name (GstAmcCodecInfoHandle * handle, - GError ** err) -{ - MLResult result; - gchar *name; - - name = g_new0 (gchar, MAX_CODEC_NAME_LENGTH); - result = MLMediaCodecListGetCodecName (handle->index, name); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get codec name: %d", result); - g_free (name); - return NULL; - } - - return name; -} - -gboolean -gst_amc_codec_info_handle_is_encoder (GstAmcCodecInfoHandle * handle, - gboolean * is_encoder, GError ** err) -{ - MLResult result; - bool out; - - result = MLMediaCodecListIsEncoder (handle->index, &out); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to check if codec is an encoder: %d", result); - return FALSE; - } - - *is_encoder = out; - - return TRUE; -} - -gchar ** -gst_amc_codec_info_handle_get_supported_types (GstAmcCodecInfoHandle * handle, - gsize * length, GError ** err) -{ - MLMediaCodecListQueryResults types; - MLResult result; - gchar **ret; - gsize i; - - result = MLMediaCodecListGetSupportedMimes (handle->index, &types); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get codec supported types: %d", result); - return NULL; - } - - *length = types.count; - ret = g_new0 (gchar *, *length + 1); - for (i = 0; i < *length; i++) - ret[i] = g_strdup (types.data[i]); - - MLMediaCodecListQueryResultsRelease (&types); - - return ret; -} - -GstAmcCodecCapabilitiesHandle * -gst_amc_codec_info_handle_get_capabilities_for_type (GstAmcCodecInfoHandle * - handle, const gchar * type, GError ** err) -{ - GstAmcCodecCapabilitiesHandle *ret; - - ret = g_new0 (GstAmcCodecCapabilitiesHandle, 1); - ret->index = handle->index; - ret->type = g_strdup (type); - return ret; -} - -void -gst_amc_codec_capabilities_handle_free (GstAmcCodecCapabilitiesHandle * handle) -{ - g_free (handle->type); - g_free (handle); -} - -gint *gst_amc_codec_capabilities_handle_get_color_formats - (GstAmcCodecCapabilitiesHandle * handle, gsize * length, GError ** err) -{ - uint32_t *colorFormats; - MLResult result; - gint *ret; - gsize i; - - result = - MLMediaCodecListGetSupportedColorFormats (handle->index, handle->type, - &colorFormats, length); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get codec supported color formats: %d", result); - return NULL; - } - - ret = g_new0 (gint, *length); - for (i = 0; i < *length; i++) { - ret[i] = colorFormats[i]; - } - - MLMediaCodecListColorFormatsRelease (colorFormats); - - return ret; -} - -GstAmcCodecProfileLevel *gst_amc_codec_capabilities_handle_get_profile_levels - (GstAmcCodecCapabilitiesHandle * handle, gsize * length, GError ** err) -{ - MLMediaCodecListProfileLevel *profileLevels; - GstAmcCodecProfileLevel *ret; - MLResult result; - gsize i; - - result = - MLMediaCodecListGetSupportedProfileLevels (handle->index, handle->type, - &profileLevels, length); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get codec supported types: %d", result); - return NULL; - } - - ret = g_new0 (GstAmcCodecProfileLevel, *length); - for (i = 0; i < *length; i++) { - ret[i].profile = profileLevels[i].profile; - ret[i].level = profileLevels[i].level; - } - - MLMediaCodecListProfileLevelsRelease (profileLevels); - - return ret; -} diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c deleted file mode 100644 index 68d64b46dc..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-format-ml.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (C) 2018 Collabora Ltd. - * Author: Xavier Claessens - * - * 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 "gstamc-internal-ml.h" -#include "../gstamc-format.h" - -#include - -struct _GstAmcFormat -{ - MLHandle handle; -}; - -static GstAmcFormat * -gst_amc_format_ml_new_audio (const gchar * mime, gint sample_rate, - gint channels, GError ** err) -{ - GstAmcFormat *format = g_slice_new0 (GstAmcFormat); - MLResult result; - - result = - MLMediaFormatCreateAudio (mime, sample_rate, channels, &format->handle); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to create audio format"); - g_slice_free (GstAmcFormat, format); - return NULL; - } - - return format; -} - -static GstAmcFormat * -gst_amc_format_ml_new_video (const gchar * mime, gint width, gint height, - GError ** err) -{ - GstAmcFormat *format = g_slice_new0 (GstAmcFormat); - MLResult result; - - result = MLMediaFormatCreateVideo (mime, width, height, &format->handle); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to create video format"); - g_slice_free (GstAmcFormat, format); - return NULL; - } - - return format; -} - -GstAmcFormat * -gst_amc_format_ml_new_handle (MLHandle handle) -{ - GstAmcFormat *format = g_slice_new0 (GstAmcFormat); - format->handle = handle; - return format; -} - -MLHandle -gst_amc_format_ml_get_handle (GstAmcFormat * format) -{ - return format->handle; -} - -static void -gst_amc_format_ml_free (GstAmcFormat * format) -{ - g_return_if_fail (format != NULL); - g_slice_free (GstAmcFormat, format); -} - -static gchar * -gst_amc_format_ml_to_string (GstAmcFormat * format, GError ** err) -{ - MLResult result; - gchar *str; - - str = g_new0 (gchar, MAX_FORMAT_STRING_SIZE); - result = MLMediaFormatObjectToString (format->handle, str); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to convert format to string: %d", result); - g_free (str); - return NULL; - } - - return str; -} - -static gboolean -gst_amc_format_ml_get_float (GstAmcFormat * format, const gchar * key, - gfloat * value, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - result = MLMediaFormatGetKeyValueFloat (format->handle, key, value); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get float"); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_format_ml_set_float (GstAmcFormat * format, const gchar * key, - gfloat value, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - result = MLMediaFormatSetKeyFloat (format->handle, key, value); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to set float"); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_format_ml_get_int (GstAmcFormat * format, const gchar * key, - gint * value, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - result = MLMediaFormatGetKeyValueInt32 (format->handle, key, value); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get int"); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_format_ml_set_int (GstAmcFormat * format, const gchar * key, gint value, - GError ** err) -{ - MLResult result; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - result = MLMediaFormatSetKeyInt32 (format->handle, key, value); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to set int"); - return FALSE; - } - return TRUE; -} - -static gboolean -gst_amc_format_ml_get_string (GstAmcFormat * format, const gchar * key, - gchar ** value, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - *value = g_new0 (gchar, MAX_KEY_STRING_SIZE); - result = MLMediaFormatGetKeyString (format->handle, key, *value); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get string"); - g_clear_pointer (value, g_free); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_format_ml_set_string (GstAmcFormat * format, const gchar * key, - const gchar * value, GError ** err) -{ - MLResult result; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - result = MLMediaFormatSetKeyString (format->handle, key, value); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to set string"); - return FALSE; - } - return TRUE; -} - -static gboolean -gst_amc_format_ml_get_buffer (GstAmcFormat * format, const gchar * key, - guint8 ** data, gsize * size, GError ** err) -{ - MLResult result; - MLMediaFormatByteArray buffer; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (size != NULL, FALSE); - - result = MLMediaFormatGetKeyByteBuffer (format->handle, key, &buffer); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get buffer"); - return FALSE; - } - - *size = buffer.length; - *data = (guint8 *) g_memdup2 (buffer.ptr, buffer.length); - MLMediaFormatKeyByteBufferRelease (format->handle, &buffer); - - return TRUE; -} - -static gboolean -gst_amc_format_ml_set_buffer (GstAmcFormat * format, const gchar * key, - guint8 * data, gsize size, GError ** err) -{ - MLResult result; - MLMediaFormatByteArray buffer; - - g_return_val_if_fail (format != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); - - buffer.ptr = data; - buffer.length = size; - result = MLMediaFormatSetKeyByteBuffer (format->handle, key, &buffer); - if (result != MLResult_Ok) { - g_set_error_literal (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to set buffer"); - return FALSE; - } - 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, -}; diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-internal-ml.h b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-internal-ml.h deleted file mode 100644 index ad9ddf24f9..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-internal-ml.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2018 Collabora Ltd. - * Author: Xavier Claessens - * - * 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_AMC_INTERNAL_ML_H__ -#define __GST_AMC_INTERNAL_ML_H__ - -#include "../gstamc-codec.h" -#include "../gstamc-format.h" -#include - -G_BEGIN_DECLS - -extern GstAmcFormatVTable gst_amc_format_ml_vtable; -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 - -#endif /* __GST_AMC_INTERNAL_ML_H__ */ diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c deleted file mode 100644 index b47c134d4f..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-ml.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2023, Ratchanan Srirattanamet - * - * 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 - * - */ - -#include "../gstamc.h" -#include "gstamc-internal-ml.h" - -gboolean -gst_amc_static_init (void) -{ - /* - * MagicLeap doesn't require any static initialization. All required - * 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; -} diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c deleted file mode 100644 index f1bb3913b8..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2018 Collabora Ltd. - * Author: Xavier Claessens - * - * 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 "gstamc-surfacetexture-ml.h" - -#include -#include - -struct _GstAmcSurfaceTextureML -{ - GObject parent; - - MLHandle handle; - GstAmcSurfaceTextureOnFrameAvailableCallback callback; - gpointer user_data; -}; - -G_DEFINE_TYPE (GstAmcSurfaceTextureML, gst_amc_surface_texture_ml, - GST_TYPE_AMC_SURFACE_TEXTURE); - -static gboolean -gst_amc_surface_texture_ml_update_tex_image (GstAmcSurfaceTexture * base, - GError ** err) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (base); - MLResult result; - - result = MLMediaSurfaceTextureUpdateTexImage (self->handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to update tex image: %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_surface_texture_ml_detach_from_gl_context (GstAmcSurfaceTexture * base, - GError ** err) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (base); - MLResult result; - - result = MLMediaSurfaceTextureDetachFromGLContext (self->handle); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to detach from gl context: %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_surface_texture_ml_attach_to_gl_context (GstAmcSurfaceTexture * base, - gint texture_id, GError ** err) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (base); - MLResult result; - - result = MLMediaSurfaceTextureAttachToGLContext (self->handle, texture_id); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to attach to gl context: %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_surface_texture_ml_get_transform_matrix (GstAmcSurfaceTexture * base, - gfloat * matrix, GError ** err) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (base); - MLResult result; - - result = MLMediaSurfaceTextureGetTransformationMatrix (self->handle, matrix); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get transformation matrix: %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_surface_texture_ml_get_timestamp (GstAmcSurfaceTexture * base, - gint64 * timestamp, GError ** err) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (base); - MLResult result; - - result = MLMediaSurfaceTextureGetTimestamp (self->handle, timestamp); - if (result != MLResult_Ok) { - g_set_error (err, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, - "Failed to get timestamp: %d", result); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_amc_surface_texture_ml_release (GstAmcSurfaceTexture * base, GError ** err) -{ - /* Nothing to do here, resources will be released when this object gets - * destroyed. */ - return TRUE; -} - -static gboolean - gst_amc_surface_texture_ml_set_on_frame_available_callback - (GstAmcSurfaceTexture * base, - GstAmcSurfaceTextureOnFrameAvailableCallback callback, gpointer user_data, - GError ** err) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (base); - - self->callback = callback; - self->user_data = user_data; - return TRUE; -} - -static void -gst_amc_surface_texture_ml_dispose (GObject * object) -{ - GstAmcSurfaceTextureML *self = GST_AMC_SURFACE_TEXTURE_ML (object); - - MLMediaSurfaceTextureSetOnFrameAvailableCallback (self->handle, NULL, NULL); - MLMediaSurfaceTextureDestroy (&self->handle); - - G_OBJECT_CLASS (gst_amc_surface_texture_ml_parent_class)->dispose (object); -} - -static void -gst_amc_surface_texture_ml_class_init (GstAmcSurfaceTextureMLClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstAmcSurfaceTextureClass *surface_texture_class = - GST_AMC_SURFACE_TEXTURE_CLASS (klass); - - gobject_class->dispose = gst_amc_surface_texture_ml_dispose; - - surface_texture_class->update_tex_image = - gst_amc_surface_texture_ml_update_tex_image; - surface_texture_class->detach_from_gl_context = - gst_amc_surface_texture_ml_detach_from_gl_context; - surface_texture_class->attach_to_gl_context = - gst_amc_surface_texture_ml_attach_to_gl_context; - surface_texture_class->get_transform_matrix = - gst_amc_surface_texture_ml_get_transform_matrix; - surface_texture_class->get_timestamp = - gst_amc_surface_texture_ml_get_timestamp; - surface_texture_class->release = gst_amc_surface_texture_ml_release; - surface_texture_class->set_on_frame_available_callback = - gst_amc_surface_texture_ml_set_on_frame_available_callback; -} - -static void -on_frame_available_cb (MLHandle handle, gpointer user_data) -{ - GstAmcSurfaceTextureML *self = user_data; - - if (self->callback != NULL) - self->callback (GST_AMC_SURFACE_TEXTURE (self), self->user_data); -} - -static void -gst_amc_surface_texture_ml_init (GstAmcSurfaceTextureML * self) -{ - MLResult result; - - result = - MLMediaSurfaceTextureCreate (MLMediaSurfaceTextureBackend_OpenGL, - &self->handle); - if (result != MLResult_Ok) { - GST_ERROR ("MLMediaSurfaceTextureCreate returned error: %d", result); - return; - } - - result = - MLMediaSurfaceTextureSetOnFrameAvailableCallback (self->handle, - on_frame_available_cb, self); - if (result != MLResult_Ok) { - GST_ERROR - ("MLMediaSurfaceTextureSetOnFrameAvailableCallback returned error: %d", - result); - return; - } -} - -GstAmcSurfaceTextureML * -gst_amc_surface_texture_ml_new (GError ** err) -{ - return g_object_new (GST_TYPE_AMC_SURFACE_TEXTURE_ML, NULL); -} - -MLHandle -gst_amc_surface_texture_ml_get_handle (GstAmcSurfaceTextureML * self) -{ - return self->handle; -} diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.h b/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.h deleted file mode 100644 index c247c766b6..0000000000 --- a/subprojects/gst-plugins-bad/sys/androidmedia/magicleap/gstamc-surfacetexture-ml.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2018 Collabora Ltd. - * Author: Xavier Claessens - * - * 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_AMC_SURFACE_TEXTURE_ML_H__ -#define __GST_AMC_SURFACE_TEXTURE_ML_H__ - -#include "../gstamcsurfacetexture.h" -#include - -G_BEGIN_DECLS - -#define GST_TYPE_AMC_SURFACE_TEXTURE_ML gst_amc_surface_texture_ml_get_type () -G_DECLARE_FINAL_TYPE (GstAmcSurfaceTextureML, gst_amc_surface_texture_ml, GST, AMC_SURFACE_TEXTURE_ML, GstAmcSurfaceTexture) - -GstAmcSurfaceTextureML * gst_amc_surface_texture_ml_new (GError ** err); -MLHandle gst_amc_surface_texture_ml_get_handle (GstAmcSurfaceTextureML * self); - -G_END_DECLS - -#endif diff --git a/subprojects/gst-plugins-bad/sys/androidmedia/meson.build b/subprojects/gst-plugins-bad/sys/androidmedia/meson.build index bb0067a54f..703b50af08 100644 --- a/subprojects/gst-plugins-bad/sys/androidmedia/meson.build +++ b/subprojects/gst-plugins-bad/sys/androidmedia/meson.build @@ -6,6 +6,18 @@ androidmedia_sources = [ 'gstamcsurfacetexture.c', 'gstamcvideodec.c', 'gstamcvideoenc.c', + 'gstahcsrc.c', + 'gstahssrc.c', + 'gst-android-graphics-imageformat.c', + 'gst-android-hardware-camera.c', + 'gst-android-hardware-sensor.c', + 'gstjniutils.c', + 'jni/gstamc-jni.c', + 'jni/gstamc-codec-jni.c', + 'jni/gstamc-codeclist-jni.c', + 'jni/gstamc-format-jni.c', + 'jni/gstamcsurface.c', + 'jni/gstamcsurfacetexture-jni.c', ] androidmedia_java_sources = [ @@ -15,94 +27,49 @@ androidmedia_java_sources = [ ] amc_opt = get_option('androidmedia') -mgl_opt = get_option('magicleap') +amc_opt = amc_opt.require(gstgl_dep.found(), + error_message: 'androidmedia plugin requires GL support', +) +amc_opt = amc_opt.require(host_system == 'android', + error_message: 'androidmedia plugin requires android system', +) -if host_system != 'android' or (amc_opt.disabled() and mgl_opt.disabled()) +have_jni_h = cc.has_header('jni.h', required : amc_opt) + +if amc_opt.disabled() or not have_jni_h subdir_done() endif -if not gstgl_dep.found() - if amc_opt.enabled() or mgl_opt.enabled() - error('androidmedia plugin enabled but GL support was not detected') - endif - subdir_done() -endif - -# Check if we have MLSDK -ml_deps = [] -have_mlsdk = true -foreach lib : ['ml_mediacodec', 'ml_mediacodeclist', 'ml_mediaformat'] - dep = cc.find_library(lib, required : mgl_opt) - have_mlsdk = have_mlsdk and dep.found() - ml_deps += dep -endforeach - extra_deps = [] -extra_cargs = [] -if have_mlsdk - androidmedia_sources += [ - 'magicleap/gstamc-ml.c', - 'magicleap/gstamc-codec-ml.c', - 'magicleap/gstamc-codeclist-ml.c', - 'magicleap/gstamc-format-ml.c', - 'magicleap/gstamc-surfacetexture-ml.c', - ] - extra_deps = ml_deps - have_jni_h = false - extra_cargs += [ - '-DPLUGIN_NAME=mlmedia', - '-DPLUGIN_DESCRIPTION="Magic Leap Media plugin"' - ] - plugin_name = 'gstmlmedia' -else - have_jni_h = cc.has_header('jni.h', required : amc_opt) - extra_cargs += [ - '-DHAVE_JNI_H', - '-DPLUGIN_NAME=androidmedia', - '-DPLUGIN_DESCRIPTION="Android Media plugin"' - ] - androidmedia_sources += [ - 'gstahcsrc.c', - 'gstahssrc.c', - 'gst-android-graphics-imageformat.c', - 'gst-android-hardware-camera.c', - 'gst-android-hardware-sensor.c', - 'gstjniutils.c', - 'jni/gstamc-jni.c', - 'jni/gstamc-codec-jni.c', - 'jni/gstamc-codeclist-jni.c', - 'jni/gstamc-format-jni.c', - 'jni/gstamcsurface.c', - 'jni/gstamcsurfacetexture-jni.c', - ] +extra_cargs = [ + '-DHAVE_JNI_H', + '-DPLUGIN_NAME=androidmedia', + '-DPLUGIN_DESCRIPTION="Android Media plugin"' +] - # Build an Ndk support if its headers exists. We don't actually link into it - # but use only type definations (and then rely on dlopen and dlsym), so this - # doesn't affect compatibility with older Android versions. - if cc.check_header('media/NdkMediaCodec.h') - androidmedia_sources += [ - 'ndk/gstamc-codec-ndk.c', - 'ndk/gstamc-format-ndk.c', - ] - extra_cargs += [ '-DHAVE_NDKMEDIA' ] - extra_deps += [ cc.find_library('android', required : true) ] - endif - - plugin_name = 'gstandroidmedia' +# Build an Ndk support if its headers exists. We don't actually link into it +# but use only type definations (and then rely on dlopen and dlsym), so this +# doesn't affect compatibility with older Android versions. +if cc.check_header('media/NdkMediaCodec.h') + androidmedia_sources += [ + 'ndk/gstamc-codec-ndk.c', + 'ndk/gstamc-format-ndk.c', + ] + extra_cargs += [ '-DHAVE_NDKMEDIA' ] + extra_deps += [ cc.find_library('android', required : true) ] endif -if have_jni_h or have_mlsdk - gstandroidmedia = library(plugin_name, - androidmedia_sources, - c_args : [gst_plugins_bad_args, extra_cargs], - include_directories : [configinc], - dependencies : [gstgl_dep, gstpbutils_dep, gstaudio_dep, gstvideo_dep, - gstphotography_dep, gmodule_dep, orc_dep, extra_deps], - install : true, - install_dir : plugins_install_dir) - plugins += [gstandroidmedia] +gstandroidmedia = library('gstandroidmedia', + androidmedia_sources, + c_args : [gst_plugins_bad_args, extra_cargs], + include_directories : [configinc], + dependencies : [gstgl_dep, gstpbutils_dep, gstaudio_dep, gstvideo_dep, + gstphotography_dep, gmodule_dep, orc_dep, extra_deps], + install : true, + install_dir : plugins_install_dir) - install_data(androidmedia_java_sources, - install_dir : join_paths(get_option('datadir'), 'gst-android/ndk-build/androidmedia') - ) -endif +plugins += [gstandroidmedia] + +install_data(androidmedia_java_sources, + install_dir : join_paths(get_option('datadir'), 'gst-android/ndk-build/androidmedia') +)