1 /* 2 * Copyright (C) 2012, Collabora Ltd. 3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation 8 * version 2.1 of the License. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 */ 20 21 #ifndef __GST_AMC_H__ 22 #define __GST_AMC_H__ 23 24 #include <gst/gst.h> 25 #include <gst/video/video.h> 26 #include <gst/audio/audio.h> 27 #include <jni.h> 28 29 #include "gstjniutils.h" 30 31 G_BEGIN_DECLS 32 33 typedef struct _GstAmcCodecInfo GstAmcCodecInfo; 34 typedef struct _GstAmcCodecType GstAmcCodecType; 35 typedef struct _GstAmcCodec GstAmcCodec; 36 typedef struct _GstAmcBufferInfo GstAmcBufferInfo; 37 typedef struct _GstAmcFormat GstAmcFormat; 38 typedef struct _GstAmcColorFormatInfo GstAmcColorFormatInfo; 39 40 struct _GstAmcCodecType { 41 gchar *mime; 42 43 gint *color_formats; 44 gint n_color_formats; 45 46 struct { 47 gint profile; 48 gint level; 49 } *profile_levels; 50 gint n_profile_levels; 51 }; 52 53 struct _GstAmcCodecInfo { 54 gchar *name; 55 gboolean is_encoder; 56 gboolean gl_output_only; 57 GstAmcCodecType *supported_types; 58 gint n_supported_types; 59 }; 60 61 struct _GstAmcFormat { 62 /* < private > */ 63 jobject object; /* global reference */ 64 }; 65 66 struct _GstAmcCodec { 67 /* < private > */ 68 jobject object; /* global reference */ 69 70 GstAmcBuffer *input_buffers, *output_buffers; 71 gsize n_input_buffers, n_output_buffers; 72 }; 73 74 struct _GstAmcBufferInfo { 75 gint flags; 76 gint offset; 77 gint64 presentation_time_us; 78 gint size; 79 }; 80 81 extern GQuark gst_amc_codec_info_quark; 82 83 GstAmcCodec * gst_amc_codec_new (const gchar *name, GError **err); 84 void gst_amc_codec_free (GstAmcCodec * codec); 85 86 gboolean gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format, jobject surface, gint flags, GError **err); 87 GstAmcFormat * gst_amc_codec_get_output_format (GstAmcCodec * codec, GError **err); 88 89 gboolean gst_amc_codec_start (GstAmcCodec * codec, GError **err); 90 gboolean gst_amc_codec_stop (GstAmcCodec * codec, GError **err); 91 gboolean gst_amc_codec_flush (GstAmcCodec * codec, GError **err); 92 gboolean gst_amc_codec_release (GstAmcCodec * codec, GError **err); 93 94 GstAmcBuffer * gst_amc_codec_get_output_buffer (GstAmcCodec * codec, gint index, GError **err); 95 GstAmcBuffer * gst_amc_codec_get_input_buffer (GstAmcCodec * codec, gint index, GError **err); 96 97 gint gst_amc_codec_dequeue_input_buffer (GstAmcCodec * codec, gint64 timeoutUs, GError **err); 98 gint gst_amc_codec_dequeue_output_buffer (GstAmcCodec * codec, GstAmcBufferInfo *info, gint64 timeoutUs, GError **err); 99 100 gboolean gst_amc_codec_queue_input_buffer (GstAmcCodec * codec, gint index, const GstAmcBufferInfo *info, GError **err); 101 gboolean gst_amc_codec_release_output_buffer (GstAmcCodec * codec, gint index, gboolean render, GError **err); 102 103 104 GstAmcFormat * gst_amc_format_new_audio (const gchar *mime, gint sample_rate, gint channels, GError **err); 105 GstAmcFormat * gst_amc_format_new_video (const gchar *mime, gint width, gint height, GError **err); 106 void gst_amc_format_free (GstAmcFormat * format); 107 108 gchar * gst_amc_format_to_string (GstAmcFormat * format, GError **err); 109 110 gboolean gst_amc_format_contains_key (GstAmcFormat *format, const gchar *key, GError **err); 111 112 gboolean gst_amc_format_get_float (GstAmcFormat *format, const gchar *key, gfloat *value, GError **err); 113 gboolean gst_amc_format_set_float (GstAmcFormat *format, const gchar *key, gfloat value, GError **err); 114 gboolean gst_amc_format_get_int (GstAmcFormat *format, const gchar *key, gint *value, GError **err); 115 gboolean gst_amc_format_set_int (GstAmcFormat *format, const gchar *key, gint value, GError **err); 116 gboolean gst_amc_format_get_string (GstAmcFormat *format, const gchar *key, gchar **value, GError **err); 117 gboolean gst_amc_format_set_string (GstAmcFormat *format, const gchar *key, const gchar *value, GError **err); 118 gboolean gst_amc_format_get_buffer (GstAmcFormat *format, const gchar *key, guint8 **data, gsize *size, GError **err); 119 gboolean gst_amc_format_set_buffer (GstAmcFormat *format, const gchar *key, guint8 *data, gsize size, GError **err); 120 121 GstVideoFormat gst_amc_color_format_to_video_format (const GstAmcCodecInfo * codec_info, const gchar * mime, gint color_format); 122 gint gst_amc_video_format_to_color_format (const GstAmcCodecInfo * codec_info, const gchar * mime, GstVideoFormat video_format); 123 124 struct _GstAmcColorFormatInfo { 125 gint color_format; 126 gint width, height, stride, slice_height; 127 gint crop_left, crop_right; 128 gint crop_top, crop_bottom; 129 gint frame_size; 130 }; 131 132 gboolean gst_amc_color_format_info_set (GstAmcColorFormatInfo * color_format_info, 133 const GstAmcCodecInfo * codec_info, const gchar * mime, 134 gint color_format, gint width, gint height, gint stride, gint slice_height, 135 gint crop_left, gint crop_right, gint crop_top, gint crop_bottom); 136 137 typedef enum 138 { 139 COLOR_FORMAT_COPY_OUT, 140 COLOR_FORMAT_COPY_IN 141 } GstAmcColorFormatCopyDirection; 142 143 gboolean gst_amc_color_format_copy ( 144 GstAmcColorFormatInfo * cinfo, GstAmcBuffer * cbuffer, const GstAmcBufferInfo * cbuffer_info, 145 GstVideoInfo * vinfo, GstBuffer * vbuffer, GstAmcColorFormatCopyDirection direction); 146 147 const gchar * gst_amc_avc_profile_to_string (gint profile, const gchar **alternative); 148 gint gst_amc_avc_profile_from_string (const gchar *profile); 149 const gchar * gst_amc_avc_level_to_string (gint level); 150 gint gst_amc_avc_level_from_string (const gchar *level); 151 const gchar * gst_amc_hevc_profile_to_string (gint profile); 152 gint gst_amc_hevc_profile_from_string (const gchar *profile); 153 const gchar * gst_amc_hevc_tier_level_to_string (gint tier_level, const gchar ** tier); 154 gint gst_amc_hevc_tier_level_from_string (const gchar * tier, const gchar *level); 155 gint gst_amc_h263_profile_to_gst_id (gint profile); 156 gint gst_amc_h263_profile_from_gst_id (gint profile); 157 gint gst_amc_h263_level_to_gst_id (gint level); 158 gint gst_amc_h263_level_from_gst_id (gint level); 159 const gchar * gst_amc_mpeg4_profile_to_string (gint profile); 160 gint gst_amc_mpeg4_profile_from_string (const gchar *profile); 161 const gchar * gst_amc_mpeg4_level_to_string (gint level); 162 gint gst_amc_mpeg4_level_from_string (const gchar *level); 163 const gchar * gst_amc_aac_profile_to_string (gint profile); 164 gint gst_amc_aac_profile_from_string (const gchar *profile); 165 166 gboolean gst_amc_audio_channel_mask_to_positions (guint32 channel_mask, gint channels, GstAudioChannelPosition *pos); 167 guint32 gst_amc_audio_channel_mask_from_positions (GstAudioChannelPosition *positions, gint channels); 168 void gst_amc_codec_info_to_caps (const GstAmcCodecInfo * codec_info, GstCaps **sink_caps, GstCaps **src_caps); 169 170 #define GST_ELEMENT_ERROR_FROM_ERROR(el, err) G_STMT_START { \ 171 gchar *__dbg; \ 172 g_assert (err != NULL); \ 173 __dbg = g_strdup (err->message); \ 174 GST_WARNING_OBJECT (el, "error: %s", __dbg); \ 175 gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_ERROR, \ 176 err->domain, err->code, \ 177 NULL, __dbg, __FILE__, GST_FUNCTION, __LINE__); \ 178 g_clear_error (&err); \ 179 } G_STMT_END 180 181 #define GST_ELEMENT_WARNING_FROM_ERROR(el, err) G_STMT_START { \ 182 gchar *__dbg; \ 183 g_assert (err != NULL); \ 184 __dbg = g_strdup (err->message); \ 185 GST_WARNING_OBJECT (el, "error: %s", __dbg); \ 186 gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_WARNING, \ 187 err->domain, err->code, \ 188 NULL, __dbg, __FILE__, GST_FUNCTION, __LINE__); \ 189 g_clear_error (&err); \ 190 } G_STMT_END 191 192 GST_DEBUG_CATEGORY_EXTERN (gst_amc_debug); 193 194 G_END_DECLS 195 196 #endif /* __GST_AMC_H__ */ 197