// Sets new native window for creating EGLSurface. void gl_ThreadSetWindow(ANativeWindow* window) { // We accept new window only when rendering // thread is active. Otherwise we can't promise // it gets released as expected. if (!gl_ThreadRunning()) { ANativeWindow_release(window); return; } // Acquire thread lock. gl_ThreadLock(); // If we have new nativeWin. if (GLOBALS.window != window) { // If there is old one, release it first. if (GLOBALS.window) { ANativeWindow_release(GLOBALS.window); } // Store new nativeWin and mark it changed. GLOBALS.window = window; GLOBALS.windowChanged = GL_THREAD_TRUE; // Set window size to zero and mark it changed. GLOBALS.windowWidth = GLOBALS.windowHeight = 0; GLOBALS.windowSizeChanged = GL_THREAD_TRUE; } // Else if window != NULL. else if (window) { // Release window instantly. ANativeWindow_release(window); } // Release thread lock. gl_ThreadUnlock(); }
int UVCPreview::stopPreview() { ENTER(); bool b = isRunning(); if (LIKELY(b)) { mIsRunning = false; pthread_cond_signal(&preview_sync); pthread_cond_signal(&capture_sync); if (pthread_join(capture_thread, NULL) != EXIT_SUCCESS) { LOGW("UVCPreview::terminate capture thread: pthread_join failed"); } if (pthread_join(preview_thread, NULL) != EXIT_SUCCESS) { LOGW("UVCPreview::terminate preview thread: pthread_join failed"); } clearDisplay(); } clearPreviewFrame(); clearCaptureFrame(); pthread_mutex_lock(&preview_mutex); if (mPreviewWindow) { ANativeWindow_release(mPreviewWindow); mPreviewWindow = NULL; } pthread_mutex_unlock(&preview_mutex); pthread_mutex_lock(&capture_mutex); if (mCaptureWindow) { ANativeWindow_release(mCaptureWindow); mCaptureWindow = NULL; } pthread_mutex_unlock(&capture_mutex); RETURN(0, int); }
void gl_ThreadDestroy() { // If there's thread running. if (GLOBALS.threadCreated) { // Mark exit flag. GLOBALS.threadExit = GL_THREAD_TRUE; // Notify thread. pthread_cond_signal(&GLOBALS.cond); // Wait until thread has exited. pthread_join(GLOBALS.thread, NULL); // If there are pending mutex locks let // them execute before destroying it. // This is needed because otherwise // pthread_mutex_destroy will fail. pthread_mutex_lock(&GLOBALS.mutex); while (GLOBALS.mutexCounter > 0) { pthread_cond_wait(&GLOBALS.cond, &GLOBALS.mutex); } pthread_mutex_unlock(&GLOBALS.mutex); // Release all GLOBALS data. pthread_cond_destroy(&GLOBALS.cond); pthread_mutex_destroy(&GLOBALS.mutex); // If we're holding a window release it. if (GLOBALS.window) { ANativeWindow_release(GLOBALS.window); } memset(&GLOBALS, 0, sizeof GLOBALS); } }
// This function must be called after // decoding is finished void nv_avc_destroy(void) { if (decoder_ctx) { avcodec_close(decoder_ctx); av_free(decoder_ctx); decoder_ctx = NULL; } if (scaler_ctx) { sws_freeContext(scaler_ctx); scaler_ctx = NULL; } if (dec_frame) { av_frame_free(&dec_frame); dec_frame = NULL; } if (yuv_frame) { av_frame_free(&yuv_frame); yuv_frame = NULL; } if (rgb_frame) { av_frame_free(&rgb_frame); rgb_frame = NULL; } if (rgb_frame_buf) { av_free(rgb_frame_buf); rgb_frame_buf = NULL; } #ifdef __ANDROID_API__ if (window) { ANativeWindow_release(window); window = NULL; } #endif pthread_mutex_destroy(&mutex); }
static void SDL_VoutAndroid_SetNativeWindow_l(SDL_Vout *vout, ANativeWindow *native_window) { AMCTRACE("%s(%p, %p)\n", __func__, vout, native_window); SDL_Vout_Opaque *opaque = vout->opaque; if (opaque->native_window == native_window) { if (native_window == NULL) { // always invalidate buffers, if native_window is changed SDL_VoutAndroid_invalidateAllBuffers_l(vout); } return; } else IJK_EGL_terminate(opaque->egl); SDL_VoutAndroid_invalidateAllBuffers_l(vout); if (opaque->native_window) ANativeWindow_release(opaque->native_window); if (native_window) ANativeWindow_acquire(native_window); opaque->native_window = native_window; opaque->null_native_window_warned = 0; }
static pj_status_t deinit_opengl(void * data) { struct andgl_stream *stream = (struct andgl_stream *)data; if (stream->gl_buf) { pjmedia_vid_dev_opengl_destroy_buffers(stream->gl_buf); stream->gl_buf = NULL; } if (stream->display != EGL_NO_DISPLAY) { eglMakeCurrent(stream->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (stream->context != EGL_NO_CONTEXT) eglDestroyContext(stream->display, stream->context); if (stream->surface != EGL_NO_SURFACE) eglDestroySurface(stream->display, stream->surface); eglTerminate(stream->display); } if (stream->window) { ANativeWindow_release(stream->window); stream->window = NULL; } stream->display = EGL_NO_DISPLAY; stream->surface = EGL_NO_SURFACE; stream->context = EGL_NO_CONTEXT; return PJ_SUCCESS; }
void Java_com_test_surfaceview_TestNative_Destroye(JNIEnv* env,jobject obj) { ANativeWindow_release(g_nativeWindow); g_nWidth = 0; g_nHeight = 0; g_nativeWindow = NULL; }
/* * Class: com_mcxiaoke_ndk_Native * Method: initNW * Signature: (JLandroid/view/Surface;)V */ JNIEXPORT void JNICALL Java_com_mcxiaoke_ndk_Native_initNW (JNIEnv *env, jclass clazz, jlong avi, jobject surface) { // Get the native window from the surface ANativeWindow* nativeWindow = ANativeWindow_fromSurface( env, surface); if (0 == nativeWindow) { ThrowException(env, "java/lang/RuntimeException", "Unable to get native window from surface."); goto exit; } // Set the buffers geometry to AVI movie frame dimensions // If these are different than the window's physical size // then the buffer will be scaled to match that size. if (0 > ANativeWindow_setBuffersGeometry(nativeWindow, AVI_video_width((avi_t*) avi), AVI_video_height((avi_t*) avi), WINDOW_FORMAT_RGB_565)) { ThrowException(env, "java/lang/RuntimeException", "Unable to set buffers geometry."); } // Release the native window ANativeWindow_release(nativeWindow); nativeWindow = 0; exit: return; }
void SwViewport::DrawToWindow() { VERBOSE("Releasing native window"); Surface.reset(); ANativeWindow_unlockAndPost(NativeWindow); ANativeWindow_release(NativeWindow); }
void Android_DestroyWindow(_THIS, SDL_Window * window) { SDL_WindowData *data; if (window == Android_Window) { Android_Window = NULL; if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem); if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem); Android_PauseSem = NULL; Android_ResumeSem = NULL; if(window->driverdata) { data = (SDL_WindowData *) window->driverdata; if (data->egl_surface != EGL_NO_SURFACE) { SDL_EGL_DestroySurface(_this, data->egl_surface); } if (data->native_window) { ANativeWindow_release(data->native_window); } SDL_free(window->driverdata); window->driverdata = NULL; } } }
static void com_stainberg_MediaPlayer_MediaPlayer_setSurface(JNIEnv* env, jobject thiz, jobject surface) { // if(surface != NULL) { // if(spWindow != NULL) { // ANativeWindow_release(spWindow); // spWindow = NULL; // } // spWindow = ANativeWindow_fromSurface(env, surface); // if(spMediaPlayer != NULL) { // spMediaPlayer->initSurface(spWindow); // } // } if(spWindow != NULL) { ANativeWindow_release(spWindow); spWindow = NULL; } if(spMediaPlayer != NULL) { spMediaPlayer->initSurface(NULL); } if(surface != NULL) { spWindow = ANativeWindow_fromSurface(env, surface); if(spMediaPlayer != NULL) { spMediaPlayer->initSurface(spWindow); } } }
NDKCamera::~NDKCamera() { valid_ = false; // stop session if it is on: if (captureSessionState_ == CaptureSessionState::ACTIVE) { ACameraCaptureSession_stopRepeating(captureSession_); } ACameraCaptureSession_close(captureSession_); for (auto& req : requests_) { CALL_REQUEST(removeTarget(req.request_, req.target_)); ACaptureRequest_free(req.request_); ACameraOutputTarget_free(req.target_); CALL_CONTAINER(remove(outputContainer_, req.sessionOutput_)); ACaptureSessionOutput_free(req.sessionOutput_); ANativeWindow_release(req.outputNativeWindow_); } requests_.resize(0); ACaptureSessionOutputContainer_free(outputContainer_); for (auto& cam : cameras_) { if (cam.second.device_) { CALL_DEV(close(cam.second.device_)); } } cameras_.clear(); if (cameraMgr_) { CALL_MGR(unregisterAvailabilityCallback(cameraMgr_, GetManagerListener())); ACameraManager_delete(cameraMgr_); cameraMgr_ = nullptr; } }
//rendering JNIEXPORT void JNICALL Java_me_lake_librestreaming_core_ColorHelper_renderingSurface (JNIEnv * env, jobject thiz,jobject javaSurface,jbyteArray pixelsArray,jint w,jint h,jint size) { ANativeWindow* window = ANativeWindow_fromSurface(env, javaSurface); if(window!=NULL) { ANativeWindow_setBuffersGeometry(window,w,h,COLOR_FORMAT_NV21); ANativeWindow_Buffer buffer; if (ANativeWindow_lock(window, &buffer, NULL) == 0) { unsigned char *pixels = (unsigned char*)(*env)->GetByteArrayElements(env,pixelsArray, 0); if(buffer.width==buffer.stride){ memcpy(buffer.bits, pixels, size); }else{ int height = h*3/2; int width = w; int i=0; for(;i<height;++i) memcpy(buffer.bits + buffer.stride * i , pixels + width * i , width); } (*env)->ReleaseByteArrayElements(env,pixelsArray,pixels,JNI_ABORT); ANativeWindow_unlockAndPost(window); } ANativeWindow_release(window); } return; }
void DeleteMCDec(GF_BaseDecoder *ifcg) { MCDec *ctx = (MCDec *)ifcg->privateStack; if(ctx->format && AMediaFormat_delete(ctx->format) != AMEDIA_OK){ GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC,("AMediaFormat_delete failed")); } if(ctx->codec && AMediaCodec_delete(ctx->codec) != AMEDIA_OK) { GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC,("AMediaCodec_delete failed")); } if(ctx->window) { ANativeWindow_release(ctx->window); ctx->window = NULL; } gf_free(ctx); gf_free(ifcg); MCDec_DelParamList(ctx->SPSs); ctx->SPSs = NULL; MCDec_DelParamList(ctx->PPSs); ctx->PPSs = NULL; }
static void func_free_l(SDL_Vout *vout) { if (!vout) return; SDL_Vout_Opaque *opaque = vout->opaque; if (opaque) { SDL_AMediaCodecBufferProxy **begin = (SDL_AMediaCodecBufferProxy **)ISDL_Array__begin(&opaque->overlay_manager); SDL_AMediaCodecBufferProxy **end = (SDL_AMediaCodecBufferProxy **)ISDL_Array__end(&opaque->overlay_manager); for (; begin < end; ++begin) { SDL_AMediaCodecBufferProxy_destroyP(begin); } ISDL_Array__clear(&opaque->overlay_pool); ISDL_Array__clear(&opaque->overlay_manager); if (opaque->native_window) { ANativeWindow_release(opaque->native_window); opaque->native_window = NULL; } IJK_EGL_freep(&opaque->egl); SDL_AMediaCodec_decreaseReferenceP(&opaque->acodec); } SDL_Vout_FreeInternal(vout); }
bool CEGLNativeTypeAndroid::GetNativeResolution(RESOLUTION_INFO *res) const { EGLNativeWindowType *nativeWindow = (EGLNativeWindowType*)CXBMCApp::GetNativeWindow(30000); if (!nativeWindow) return false; if (!m_width || !m_height) { ANativeWindow_acquire(*nativeWindow); res->iWidth = ANativeWindow_getWidth(*nativeWindow); res->iHeight= ANativeWindow_getHeight(*nativeWindow); ANativeWindow_release(*nativeWindow); } else { res->iWidth = m_width; res->iHeight = m_height; } res->fRefreshRate = currentRefreshRate(); res->dwFlags= D3DPRESENTFLAG_PROGRESSIVE; res->iScreen = 0; res->bFullScreen = true; res->iSubtitles = (int)(0.965 * res->iHeight); res->fPixelRatio = 1.0f; res->iScreenWidth = res->iWidth; res->iScreenHeight = res->iHeight; res->strMode = StringUtils::Format("%dx%d @ %.2f%s - Full Screen", res->iScreenWidth, res->iScreenHeight, res->fRefreshRate, res->dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : ""); CLog::Log(LOGNOTICE,"Current resolution: %s\n",res->strMode.c_str()); return true; }
UVCPreview::~UVCPreview() { ENTER(); if (mPreviewWindow) ANativeWindow_release(mPreviewWindow); mPreviewWindow = NULL; if (mCaptureWindow) ANativeWindow_release(mCaptureWindow); mCaptureWindow = NULL; clearPreviewFrame(); clearCaptureFrame(); pthread_mutex_destroy(&preview_mutex); pthread_cond_destroy(&preview_sync); pthread_mutex_destroy(&capture_mutex); pthread_cond_destroy(&capture_sync); EXIT(); }
JNIEXPORT void JNICALL nativeSetSurface(JNIEnv* jenv, jobject obj, jobject surface) { if(surface != 0) { nativeWindow = ANativeWindow_fromSurface(jenv, surface); } else { ANativeWindow_release(nativeWindow); } return; }
extern void GetPlatformWindowDimensions(void* nativeHandle, int* width, int* height) { ANativeWindow* w = ANativeWindow_fromSurface(Jni, (jobject)nativeHandle); VERBOSE("Got native window for measurements %p", w); *width = ANativeWindow_getWidth(w); *height = ANativeWindow_getHeight(w); ANativeWindow_release(w); }
//----------------------------------------------------------------------------- OsWindow::~OsWindow() { if (m_window) { ANativeWindow_release(m_window); } }
static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool first_open, std::optional<std::string> savestate_path = {}, bool delete_savestate = false) { ASSERT(!paths.empty()); __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str()); RegisterMsgAlertHandler(&MsgAlert); Common::AndroidSetReportHandler(&ReportSend); DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue); std::unique_lock<std::mutex> guard(s_host_identity_lock); UICommon::Init(); if (first_open) { DolphinAnalytics::Instance()->ReportDolphinStart(GetAnalyticValue("DEVICE_TYPE")); } WiimoteReal::InitAdapterClass(); // No use running the loop when booting fails s_have_wm_user_stop = false; std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(paths, savestate_path); boot->delete_savestate = delete_savestate; WindowSystemInfo wsi(WindowSystemType::Android, nullptr, s_surf); wsi.render_surface_scale = GetRenderSurfaceScale(env); if (BootManager::BootCore(std::move(boot), wsi)) { ButtonManager::Init(SConfig::GetInstance().GetGameID()); static constexpr int TIMEOUT = 10000; static constexpr int WAIT_STEP = 25; int time_waited = 0; // A Core::CORE_ERROR state would be helpful here. while (!Core::IsRunning() && time_waited < TIMEOUT && !s_have_wm_user_stop) { std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_STEP)); time_waited += WAIT_STEP; } while (Core::IsRunning()) { guard.unlock(); s_update_main_frame_event.Wait(); guard.lock(); Core::HostDispatchJobs(); } } Core::Shutdown(); ButtonManager::Shutdown(); UICommon::Shutdown(); guard.unlock(); if (s_surf) { ANativeWindow_release(s_surf); s_surf = nullptr; } }
int Android_CreateWindow(_THIS, SDL_Window * window) { SDL_WindowData *data; if (Android_Window) { return SDL_SetError("Android only supports one window"); } Android_PauseSem = SDL_CreateSemaphore(0); Android_ResumeSem = SDL_CreateSemaphore(0); /* Adjust the window data to match the screen */ window->x = 0; window->y = 0; window->w = Android_ScreenWidth; window->h = Android_ScreenHeight; window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */ window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */ window->flags &= ~SDL_WINDOW_HIDDEN; window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */ window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */ /* One window, it always has focus */ SDL_SetMouseFocus(window); SDL_SetKeyboardFocus(window); data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data)); if (!data) { return SDL_OutOfMemory(); } data->native_window = Android_JNI_GetNativeWindow(); if (!data->native_window) { SDL_free(data); return SDL_SetError("Could not fetch native window"); } /* Do not create EGLSurface for Vulkan window since it will then make the window incompatible with vkCreateAndroidSurfaceKHR */ if ((window->flags & SDL_WINDOW_VULKAN) == 0) { data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window); if (data->egl_surface == EGL_NO_SURFACE) { ANativeWindow_release(data->native_window); SDL_free(data); return SDL_SetError("Could not create GLES window surface"); } } window->driverdata = data; Android_Window = window; return 0; }
void AndroidEGLGraphicsContext::Shutdown() { delete draw_; draw_ = nullptr; NativeShutdownGraphics(); gl->ClearCurrent(); gl->Shutdown(); delete gl; ANativeWindow_release(wnd_); finalize_glslang(); }
void naSetSurface(JNIEnv *pEnv, jobject pObj, jobject pSurface) { if (0 != pSurface) { // get the native window reference window = ANativeWindow_fromSurface(pEnv, pSurface); // set format and size of window buffer ANativeWindow_setBuffersGeometry(window, 0, 0, WINDOW_FORMAT_RGBA_8888); } else { // release the native window ANativeWindow_release(window); } }
/* * Class: com_mcxiaoke_ndk_Native * Method: renderNW * Signature: (JLandroid/view/Surface;)Z */ JNIEXPORT jboolean JNICALL Java_com_mcxiaoke_ndk_Native_renderNW (JNIEnv *env, jclass clazz, jlong avi, jobject surface) { jboolean isFrameRead = JNI_FALSE; long frameSize = 0; int keyFrame = 0; // Get the native window from the surface ANativeWindow* nativeWindow = ANativeWindow_fromSurface( env, surface); if (0 == nativeWindow) { ThrowException(env, "java/io/RuntimeException", "Unable to get native window from surface."); goto exit; } // Lock the native window and get access to raw buffer ANativeWindow_Buffer windowBuffer; if (0 > ANativeWindow_lock(nativeWindow, &windowBuffer, 0)) { ThrowException(env, "java/io/RuntimeException", "Unable to lock native window."); goto release; } // Read AVI frame bytes to raw buffer frameSize = AVI_read_frame((avi_t*) avi, (char*) windowBuffer.bits, &keyFrame); // Check if frame is successfully read if (0 < frameSize) { isFrameRead = JNI_TRUE; } // Unlock and post the buffer for displaying if (0 > ANativeWindow_unlockAndPost(nativeWindow)) { ThrowException(env, "java/io/RuntimeException", "Unable to unlock and post to native window."); goto release; } release: // Release the native window ANativeWindow_release(nativeWindow); nativeWindow = 0; exit: return isFrameRead; }
// set the surface void Java_com_example_nativecodec_NativeCodec_setSurface(JNIEnv *env, jclass clazz, jobject surface) { // obtain a native window from a Java surface if (data.window) { ANativeWindow_release(data.window); data.window = NULL; } data.window = ANativeWindow_fromSurface(env, surface); LOGV("@@@ setsurface %p", data.window); }
/* * Class: com_ericsson_lispmediaplayer_Player * Method: playerDestroy * Signature: ()I */ JNIEXPORT jint JNICALL Java_com_ericsson_lispmediaplayer_Player_playerDestroy (JNIEnv *env, jobject object) { int ret = Player_Destory(); if (theNativeWindow != NULL) { ANativeWindow_release(theNativeWindow); theNativeWindow = NULL; } return ret; }
void Java_com_oculus_vrappframework_VrApp_nativeSurfaceDestroyed( JNIEnv *jni, jclass clazz, jlong appPtr, jobject surface ) { LOG( "%p nativeSurfaceDestroyed()", (void *)appPtr ); OVR::AppLocal * appLocal = (OVR::AppLocal *)appPtr; appLocal->GetMessageQueue().SendPrintf( "surfaceDestroyed " ); LOG( " ANativeWindow_release( %p )", appLocal->pendingNativeWindow ); ANativeWindow_release( appLocal->pendingNativeWindow ); appLocal->pendingNativeWindow = NULL; }
JNIEXPORT void JNICALL Java_com_orcchg_openglsample_NativeInterface_setSurface (JNIEnv *jenv, jobject, jlong descriptor, jobject surface) { NativeInterface* ptr = (NativeInterface*) descriptor; if (surface == nullptr) { ANativeWindow_release(ptr->window); ptr->window = nullptr; } else { ptr->window = ANativeWindow_fromSurface(jenv, surface); ptr->render->setSurface(ptr->window); ptr->render->draw(); } }
status_t Surface_close(void* window) { LOGI("Surface_close() %p", window); ANativeWindow *native_window = (ANativeWindow *)window; if (native_window) { ANativeWindow_release(native_window); native_window = NULL; } return OK; }