Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Called when appsink receives a new sample */
- static GstFlowReturn new_sample_cb (GstElement *element, CustomData *data) {
- GstSample *sample;
- GstBuffer *buffer;
- GstVideoInfo info;
- GstCaps *caps;
- jint textureId;
- JNIEnv *env = get_jni_env ();
- GstVideoFrame *pframe;
- //GST_DEBUG("Got callback");
- pframe = &data->frame;
- // FIXME Assume that we already drew this one...
- if (data->frame_is_valid) {
- gst_video_frame_unmap(&data->frame);
- data->frame_is_valid = FALSE;
- }
- /* Get texture ID from buffer */
- sample = gst_app_sink_pull_sample( GST_APP_SINK( data->video_sink ) );
- //GST_DEBUG("Got sample");
- if (!sample) {
- GST_ERROR("Could not get sample");
- goto exit_none;
- }
- /* TODO can we cache this and the info? */
- caps = gst_sample_get_caps (sample);
- if (!caps) {
- GST_ERROR("Could not get caps");
- goto exit_sample;
- }
- if (!gst_video_info_from_caps( &info, caps)) {
- GST_ERROR("Could not get video info from caps");
- goto exit_caps;
- }
- buffer = gst_sample_get_buffer( sample );
- //GST_DEBUG("Got buffer");
- if ( !gst_video_frame_map( pframe, &info, buffer, GST_MAP_READ | GST_MAP_GL) )
- {
- GST_ERROR( "Failed to map video frame" );
- goto exit_caps;
- }
- data->frame_is_valid = TRUE;
- //GST_DEBUG("Map complete");
- textureId = (jint)(*(guint *) pframe->data[0]);
- GST_DEBUG("new_sample_cb(): texture id:%d, width: %d, height: %d format name: %s",
- textureId, pframe->info.width, pframe->info.height,
- pframe->info.finfo->name);
- /* Notify application */
- (*env)->CallVoidMethod (env, data->app, on_frame_available_method_id, textureId);
- if ((*env)->ExceptionCheck (env)) {
- GST_ERROR ("Failed to call Java method");
- (*env)->ExceptionClear (env);
- }
- exit_caps:
- gst_caps_unref(caps);
- exit_sample:
- /* Releases the buffer automatically */
- gst_sample_unref(sample);
- exit_none:
- return GST_FLOW_OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment