使用 ANativeWindow_lock 返回错误 -22 与 android Gstreamer SDK

Posted

技术标签:

【中文标题】使用 ANativeWindow_lock 返回错误 -22 与 android Gstreamer SDK【英文标题】:USE ANativeWindow_lock return error -22 with android Gstreamer SDK 【发布时间】:2014-12-01 09:39:52 【问题描述】:

大家,

现在我正在使用android Gstreamer SDK来实现流,通过修改http://docs.gstreamer.com/display/GstSDK/Android+tutorial+3%3A+Video这个项目, 我想在流式传输时捕获图像,所以我添加了一个 JNI 函数来渲染帧, 下面是我的功能:

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");
         

但我总是收到返回错误 -22 和 ANativeWindow_lock()

还有什么我需要做的或者以错误的方式使用ANativeWindow_lock()????

因为在线上与ANativeWindow_lock()的讨论很少, 我不知道如何修复我的错误消息..

【问题讨论】:

【参考方案1】:

我也遇到过类似的问题,这也花了我数千小时。然而,结果证明解决方案非常简单,这里引用 ANativeWindow_fromSurface 的评论:

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

所以窗口对象将在ANativeWindow_fromSurface 上被锁定。不仅仅是ANativeWindow_acquire!因此,答案是:如果您在锁定窗口之前已经调用过一次ANativeWindow_acquire,则必须调用ANativeWindow_release 来释放它TWICE

【讨论】:

以上是关于使用 ANativeWindow_lock 返回错误 -22 与 android Gstreamer SDK的主要内容,如果未能解决你的问题,请参考以下文章

EditContext OnFieldChanged 报错返回类型

React 请求设置了 responseType: 'blob',返回了JSON格式错误信息处理

根据报错信息返回判断系统容器系统

python异常报错详解

JNI NewStringUTF报错解决方案

MFC中的SQL查询语句返回空就报错怎么办?