简体   繁体   中英

USE ANativeWindow_lock return error -22 with android Gstreamer SDK

everyone,

now I am using Android Gstreamer SDK to implement streaming, by modifying http://docs.gstreamer.com/display/GstSDK/Android+tutorial+3%3A+Video this project, and I want to capture a image while streaming, so I add a JNI function to render a frame, Here is my function below:

void gst_native_render_image(JNIEnv *env, jobject thiz, jobject surface){  

CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
         if (!data) 
             return;

         GST_DEBUG ("Releasing Native Window %p", data->native_window);

         ANativeWindow_Buffer buffer;
         //ANativeWindow *window = ANativeWindow_fromSurface(env, surface);
         render_window = ANativeWindow_fromSurface(env, surface);
         ANativeWindow_acquire(render_window);
         //ANativeWindow *window = data->native_window;
         GST_DEBUG("Got window %p", render_window);

         if(render_window > 0){
                 int width = ANativeWindow_getWidth(render_window);
                 int height = ANativeWindow_getHeight(render_window);

                 GST_DEBUG("Got window %d %d", width,height);

                 ANativeWindow_setBuffersGeometry(render_window, width, height, WINDOW_FORMAT_RGBA_8888);

                 memset((void*)&buffer,0,sizeof(buffer));

                 int lockResult = 0;

                 lockResult = ANativeWindow_lock(render_window, &buffer, NULL);
                 if (lockResult == 0) {
                         GST_DEBUG("GStreamer: ANativeWindow_locked");
                         memcpy(buffer.bits, g_buffer,  640*320);
                         ANativeWindow_unlockAndPost(render_window);
                 }
                 else{
                         GST_DEBUG("GStreamer: ANativeWindow_lock failed error %d",lockResult);
                 }

                 GST_DEBUG("Releasing window");

                 ANativeWindow_release(render_window);
                 (*env)->CallVoidMethod(env, thiz, surface_pixel_render_id); // call JAVA method to save the pixel data....oranhuang
         }else {
                 GST_DEBUG("surface is null");
         }
}

but I always get return error -22 with ANativeWindow_lock() .

Is there anything else I need to do OR using ANativeWindow_lock() in the wrong way????

'cause there are just few discusses with ANativeWindow_lock() on the line , I don't know how to fix my error message..

I've encountered similar problem which also took me thousands of hours . However the solution turned out to be pretty straight forward, here is a quote from the comment of ANativeWindow_fromSurface :

/*... This acquires a reference on the ANativeWindow that is returned; be sure to use ANativeWindow_release() ...*/

So the window object would be lock upon ANativeWindow_fromSurface . Not just ANativeWindow_acquire ! Thus, the answer is: You have to call ANativeWindow_release to release it TWICE if you had already called ANativeWindow_acquire once before locking the window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM