Reputation: 4917
I'm trying to display a received data from an UDP Socket (which already token by a Callback from the of AppSink)
Here is my code which is supposed to display the received data :
static void gst_native_receive_video_data(JNIEnv *env, jobject thiz, jbyteArray array) {
jbyte *data = (*env)->GetByteArrayElements(env, array, NULL);
jsize size = (*env)->GetArrayLength(env, array);
GstBuffer *buffer = gst_buffer_new_allocate(NULL, size, NULL);
gst_buffer_fill(buffer, 0, data, size);
gchar *videoConsumerString = g_strdup_printf(
"appsrc name=source is-live=true do-timestamp=true min-latency=0 max-latency=100000000 ! video/x-raw,format=RGB,width=320,height=240,framerate=30/1 ! videoconvert ! autovideosink");
GstElement *consumer = gst_parse_launch(videoConsumerString, NULL);
g_free(videoConsumerString);
GstElement *source = gst_bin_get_by_name(GST_BIN(consumer), "source");
gst_app_src_push_buffer(GST_APP_SRC(source), buffer);
gst_element_set_state(consumer, GST_STATE_PLAYING);
gst_object_unref(source);
gst_object_unref(consumer);
(*env)->ReleaseByteArrayElements(env, array, data, JNI_ABORT);
}
Please give me the correct way to display the received data.
Thank you in advance for your help.
P.S: I'm newbie on Gstreamer Community
Upvotes: 1
Views: 895
Reputation: 4917
I fixed the issue , as the pipeline must be on another thread so i put it on another thread. Here is the pipeline which used the read the buffer data :
pCustomData->pipeline = gst_parse_launch ("appsrc name=source ! application/x-rtp, encoding-name=H264 ! rtpjitterbuffer drop-on-latency=false latency=10 ! rtph264depay ! h264parse ! queue ! avdec_h264 ! queue ! videoconvert ! videoflip method=counterclockwise ! autovideosink",&error);
and the method to read the received external data :
static void gst_native_receive_video_data(JNIEnv *env, jobject thiz, jbyteArray array) {
jbyte *temp = (*env)->GetByteArrayElements(env, array, NULL);
jsize size = (*env)->GetArrayLength(env, array);
GstBuffer *buffer = gst_buffer_new_allocate(NULL, size, NULL);
gst_buffer_fill(buffer, 0, temp, size);
GstElement *source = gst_bin_get_by_name(GST_BIN(pCustomData->pipeline), "source");
gst_app_src_push_buffer(GST_APP_SRC(source), buffer);
gst_object_unref(source);
(*env)->ReleaseByteArrayElements(env, array, temp, JNI_ABORT);
}
Upvotes: 2