Unable to retrieve the video-sink

Abu Abdullah falcon.sheep at gmail.com
Sun Feb 25 03:45:27 UTC 2018


Hi,

I'm modifying tutorial-3 to get snapshot (bitmap) while the streaming
is on. the problem is with getting the video_sink, it always gives me
null. the same thing for pipeline. any hints is appreciated.

the code is the following:
**************************
static jobject gst_native_snapshot (JNIEnv* env, jobject thiz) {
    CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
    if (!data) return NULL;

    GST_DEBUG ("gst_native_snapshot 2");

    //gst_element_set_state (data->pipeline, GST_STATE_READY);

    //if (!data->pipeline) return NULL;

    GST_DEBUG ("gst_native_snapshot 3");

    //data->video_sink =
gst_bin_get_by_interface(GST_BIN(data->pipeline),
GST_TYPE_VIDEO_OVERLAY);
    //data->video_sink = gst_bin_get_by_name(GST_BIN(data->pipeline), "mysink");

    GST_DEBUG ("gst_native_snapshot 4");

    if (data->video_sink)
    {
        GstSample *sample =
gst_base_sink_get_last_sample(GST_BASE_SINK(GST_VIDEO_OVERLAY(data->video_sink
)));
        GstBuffer *buffer = gst_sample_get_buffer(sample);
        GST_DEBUG("gst_native_snapshot 6");
        GstCaps *caps = gst_sample_get_caps(sample);
        GST_DEBUG ("snapshot caps %" GST_PTR_FORMAT, caps);
        GstMapInfo map;
        gst_buffer_map(buffer, &map, GST_MAP_READ);
        GstVideoInfo info;
        gst_video_info_from_caps(&info, caps);
        GST_DEBUG("format name is %s", GST_VIDEO_INFO_NAME(&info));

        // get static method id of createBitmap(int width, int height,
Bitmap.Config config)
        jclass java_bitmap_class = (*env)->FindClass(env,
"android/graphics/Bitmap");
        jmethodID mid = (*env)->GetStaticMethodID(env,
java_bitmap_class, "createBitmap",
"(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");

        // enum for Bitmap.Config
        jclass bcfg_class = (*env)->FindClass(env,
"android/graphics/Bitmap$Config");
        jobject java_bitmap_config =
(*env)->CallStaticObjectMethod(env, bcfg_class,
(*env)->GetStaticMethodID(env,bcfg_clas, "valueOf",
"(Ljava/lang/String;)Landroid/graphics/Bitmap$Config;"),(*env)->NewStringUTF(env,"RGB_565"));

        jobject objectbitmap = (*env)->CallStaticObjectMethod(env,
java_bitmap_class, mid, GST_VIDEO_INFO_WIDTH(&info),
GST_VIDEO_INFO_HEIGHT(&info), java_bitmap_config);

        void *pixels = NULL;
        int ret = AndroidBitmap_lockPixels(env, objectbitmap, &pixels);
        memcpy(pixels, map.data, map.size);
        AndroidBitmap_unlockPixels(env, objectbitmap);

        return objectbitmap;
    }
    else
    {
        GST_DEBUG("Could not retrieve video sink");
        return NULL;
    }
}


More information about the gstreamer-android mailing list