amc: Select between encoder/decoder at GstAmcCodec construct time

Magical 0/1 values where passed to gst_amc_codec_configure() flags
argument. It's more natural to have a boolean is gst_amc_codec_new().
This commit is contained in:
Xavier Claessens 2019-03-26 11:24:58 -04:00
parent 0fe0270244
commit ad7c4f5f27
5 changed files with 16 additions and 10 deletions

View file

@ -50,10 +50,10 @@ void gst_amc_buffer_free (GstAmcBuffer * buffer);
gboolean gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer, GError ** err,
gint position, gint limit);
GstAmcCodec * gst_amc_codec_new (const gchar *name, GError **err);
GstAmcCodec * gst_amc_codec_new (const gchar *name, gboolean is_encoder, GError **err);
void gst_amc_codec_free (GstAmcCodec * codec);
gboolean gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format, GstAmcSurfaceTexture * surface_texture, gint flags, GError **err);
gboolean gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format, GstAmcSurfaceTexture * surface_texture, GError **err);
GstAmcFormat * gst_amc_codec_get_output_format (GstAmcCodec * codec, GError **err);
gboolean gst_amc_codec_start (GstAmcCodec * codec, GError **err);

View file

@ -244,7 +244,7 @@ gst_amc_audio_dec_open (GstAudioDecoder * decoder)
GST_DEBUG_OBJECT (self, "Opening decoder");
self->codec = gst_amc_codec_new (klass->codec_info->name, &err);
self->codec = gst_amc_codec_new (klass->codec_info->name, FALSE, &err);
if (!self->codec) {
GST_ELEMENT_ERROR_FROM_ERROR (self, err);
return FALSE;
@ -964,7 +964,7 @@ gst_amc_audio_dec_set_format (GstAudioDecoder * decoder, GstCaps * caps)
GST_STR_NULL (format_string));
g_free (format_string);
if (!gst_amc_codec_configure (self->codec, format, NULL, 0, &err)) {
if (!gst_amc_codec_configure (self->codec, format, NULL, &err)) {
GST_ERROR_OBJECT (self, "Failed to configure codec");
GST_ELEMENT_ERROR_FROM_ERROR (self, err);
return FALSE;

View file

@ -433,7 +433,7 @@ gst_amc_video_dec_open (GstVideoDecoder * decoder)
GST_DEBUG_OBJECT (self, "Opening decoder");
self->codec = gst_amc_codec_new (klass->codec_info->name, &err);
self->codec = gst_amc_codec_new (klass->codec_info->name, FALSE, &err);
if (!self->codec) {
GST_ELEMENT_ERROR_FROM_ERROR (self, err);
return FALSE;
@ -2030,7 +2030,7 @@ gst_amc_video_dec_set_format (GstVideoDecoder * decoder,
GST_STR_NULL (format_string));
g_free (format_string);
if (!gst_amc_codec_configure (self->codec, format, self->surface, 0, &err)) {
if (!gst_amc_codec_configure (self->codec, format, self->surface, &err)) {
GST_ERROR_OBJECT (self, "Failed to configure codec");
GST_ELEMENT_ERROR_FROM_ERROR (self, err);
return FALSE;

View file

@ -578,7 +578,7 @@ gst_amc_video_enc_open (GstVideoEncoder * encoder)
GST_DEBUG_OBJECT (self, "Opening encoder");
self->codec = gst_amc_codec_new (klass->codec_info->name, &err);
self->codec = gst_amc_codec_new (klass->codec_info->name, TRUE, &err);
if (!self->codec) {
GST_ELEMENT_ERROR_FROM_ERROR (self, err);
return FALSE;
@ -1317,7 +1317,7 @@ gst_amc_video_enc_set_format (GstVideoEncoder * encoder,
GST_STR_NULL (format_string));
g_free (format_string);
if (!gst_amc_codec_configure (self->codec, format, NULL, 1, &err)) {
if (!gst_amc_codec_configure (self->codec, format, NULL, &err)) {
GST_ERROR_OBJECT (self, "Failed to configure codec");
GST_ELEMENT_ERROR_FROM_ERROR (self, err);
goto quit;

View file

@ -37,6 +37,7 @@ struct _GstAmcCodec
RealBuffer *input_buffers, *output_buffers;
gsize n_input_buffers, n_output_buffers;
GstAmcSurface *surface;
gboolean is_encoder;
};
static struct
@ -440,7 +441,7 @@ gst_amc_buffer_set_position_and_limit (GstAmcBuffer * buffer_, GError ** err,
}
GstAmcCodec *
gst_amc_codec_new (const gchar * name, GError ** err)
gst_amc_codec_new (const gchar * name, gboolean is_encoder, GError ** err)
{
JNIEnv *env;
GstAmcCodec *codec = NULL;
@ -457,6 +458,7 @@ gst_amc_codec_new (const gchar * name, GError ** err)
}
codec = g_slice_new0 (GstAmcCodec);
codec->is_encoder = is_encoder;
if (!gst_amc_jni_call_static_object_method (env, err, media_codec.klass,
media_codec.create_by_codec_name, &object, name_str))
@ -514,9 +516,10 @@ gst_amc_codec_free (GstAmcCodec * codec)
gboolean
gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format,
GstAmcSurfaceTexture * surface, gint flags, GError ** err)
GstAmcSurfaceTexture * surface, GError ** err)
{
JNIEnv *env;
gint flags = 0;
g_return_val_if_fail (codec != NULL, FALSE);
g_return_val_if_fail (format != NULL, FALSE);
@ -532,6 +535,9 @@ gst_amc_codec_configure (GstAmcCodec * codec, GstAmcFormat * format,
return FALSE;
}
if (codec->is_encoder)
flags = 1;
return gst_amc_jni_call_void_method (env, err, codec->object,
media_codec.configure, format->object, codec->surface, NULL, flags);
}