mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-01 21:18:52 +00:00
Use the buffer's free_func to map byteArray data without making a copy
This commit is contained in:
parent
af47c1ebdc
commit
4cbfe6fa13
1 changed files with 34 additions and 6 deletions
|
@ -385,11 +385,33 @@ gst_ahc_src_unlock_stop (GstBaseSrc * bsrc)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GstAHCSrc *self;
|
||||||
|
jbyteArray array;
|
||||||
|
jbyte *data;
|
||||||
|
} FreeFuncBuffer;
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_ahc_src_buffer_free_func (gpointer priv)
|
||||||
|
{
|
||||||
|
FreeFuncBuffer *data = (FreeFuncBuffer *) priv;
|
||||||
|
GstAHCSrc *self = data->self;
|
||||||
|
JNIEnv *env = gst_dvm_get_env ();
|
||||||
|
|
||||||
|
(*env)->ReleaseByteArrayElements(env, data->array, data->data, JNI_ABORT);
|
||||||
|
if (self->camera)
|
||||||
|
gst_ah_camera_add_callback_buffer (self->camera, data->array);
|
||||||
|
(*env)->DeleteGlobalRef (env, data->array);
|
||||||
|
|
||||||
|
g_slice_free (FreeFuncBuffer, data);
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_ahc_src_create (GstPushSrc * src, GstBuffer ** buffer)
|
gst_ahc_src_create (GstPushSrc * src, GstBuffer ** buffer)
|
||||||
{
|
{
|
||||||
GstAHCSrc *self = GST_AHC_SRC (src);
|
GstAHCSrc *self = GST_AHC_SRC (src);
|
||||||
JNIEnv *env = gst_dvm_get_env ();
|
JNIEnv *env = gst_dvm_get_env ();
|
||||||
|
FreeFuncBuffer *user_data;
|
||||||
jbyteArray data = NULL;
|
jbyteArray data = NULL;
|
||||||
|
|
||||||
while (data == NULL) {
|
while (data == NULL) {
|
||||||
|
@ -398,13 +420,19 @@ gst_ahc_src_create (GstPushSrc * src, GstBuffer ** buffer)
|
||||||
return GST_FLOW_WRONG_STATE;
|
return GST_FLOW_WRONG_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = gst_buffer_new_and_alloc (self->buffer_size);
|
//GST_WARNING_OBJECT (self, "Received data buffer %p", data);
|
||||||
(*env)->GetByteArrayRegion (env, data, 0, self->buffer_size,
|
|
||||||
(jbyte *) GST_BUFFER_DATA (*buffer));
|
|
||||||
gst_buffer_set_caps (*buffer, self->caps);
|
|
||||||
|
|
||||||
gst_ah_camera_add_callback_buffer (self->camera, data);
|
user_data = g_slice_new0 (FreeFuncBuffer);
|
||||||
(*env)->DeleteGlobalRef (env, data);
|
user_data->self = self;
|
||||||
|
user_data->array = data;
|
||||||
|
user_data->data = (*env)->GetByteArrayElements (env, data, NULL);
|
||||||
|
|
||||||
|
*buffer = gst_buffer_new ();
|
||||||
|
GST_BUFFER_DATA (*buffer) = (guint8 *) user_data->data;
|
||||||
|
GST_BUFFER_SIZE (*buffer) = self->buffer_size;
|
||||||
|
GST_BUFFER_MALLOCDATA (*buffer) = (gpointer) user_data;
|
||||||
|
GST_BUFFER_FREE_FUNC (*buffer) = gst_ahc_src_buffer_free_func;
|
||||||
|
gst_buffer_set_caps (*buffer, self->caps);
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue