diff --git a/app/src/main/java/com/hmwl/face_sdk/FaceActivity.java b/app/src/main/java/com/hmwl/face_sdk/FaceActivity.java index 36e6856..effe851 100644 --- a/app/src/main/java/com/hmwl/face_sdk/FaceActivity.java +++ b/app/src/main/java/com/hmwl/face_sdk/FaceActivity.java @@ -94,12 +94,12 @@ public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.L { detectFace(image); } - else - { - image.close(); - } +// else +// { +// image.close(); +// } } finally { - //image.close(); // 确保在这里关闭 + image.close(); // 确保在这里关闭 //Log.d("Camera", "Image closed, ready for next frame"); } } diff --git a/app/src/main/java/com/hmwl/face_sdk/FaceLandmarkerHelper.kt b/app/src/main/java/com/hmwl/face_sdk/FaceLandmarkerHelper.kt index 4925b83..c9f0cba 100644 --- a/app/src/main/java/com/hmwl/face_sdk/FaceLandmarkerHelper.kt +++ b/app/src/main/java/com/hmwl/face_sdk/FaceLandmarkerHelper.kt @@ -192,7 +192,7 @@ class FaceLandmarkerHelper( Bitmap.Config.ARGB_8888 ) imageProxy.use { bitmapBuffer.copyPixelsFromBuffer(imageProxy.planes[0].buffer) } - imageProxy.close() + //imageProxy.close() val matrix = Matrix().apply { // Rotate the frame received from the camera to be in the same direction as it'll be shown diff --git a/example/build.gradle b/example/build.gradle index 8f67eac..c81bf46 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -9,7 +9,7 @@ android { compileSdk 36 defaultConfig { - applicationId "com.inewme.uvmirror.f20251129" + applicationId "com.inewme.uvmirror.f20260113" minSdk 30 targetSdk 36 versionCode 1 diff --git a/example/src/main/java/com/inewme/uvmirror/MotionManager.kt b/example/src/main/java/com/inewme/uvmirror/MotionManager.kt index 3036b60..f3a61f0 100644 --- a/example/src/main/java/com/inewme/uvmirror/MotionManager.kt +++ b/example/src/main/java/com/inewme/uvmirror/MotionManager.kt @@ -8,7 +8,6 @@ import com.hmwl.face_sdk.Frame import com.hmwl.face_sdk.InitArg import com.hmwl.face_sdk.Motion import com.hmwl.face_sdk.MotionList -import org.checkerframework.checker.units.qual.radians import org.json.JSONObject import java.io.BufferedReader import java.io.InputStreamReader diff --git a/example/src/main/res/values/strings.xml b/example/src/main/res/values/strings.xml index 724e42d..ad5cc65 100644 --- a/example/src/main/res/values/strings.xml +++ b/example/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - f20251129 + f20260113 \ No newline at end of file diff --git a/vulkan/Application.cpp b/vulkan/Application.cpp index 65a8410..3eb1719 100644 --- a/vulkan/Application.cpp +++ b/vulkan/Application.cpp @@ -582,23 +582,20 @@ void Application::drawFrame(long long frameTime) submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = signalSemaphores; - // graphicsQueue 与主线程 drawFrame、FaceApp::endSingleTimeCommands(JNI/worker 线程)共用,必须串行 - { - std::lock_guard lock(mtx); - if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) { - throw std::runtime_error("failed to submit draw command buffer!"); - } - // 7. 呈现图像 - VkPresentInfoKHR presentInfo{}; - presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; - presentInfo.waitSemaphoreCount = 1; - presentInfo.pWaitSemaphores = signalSemaphores; - VkSwapchainKHR swapChains[] = { swapChain }; - presentInfo.swapchainCount = 1; - presentInfo.pSwapchains = swapChains; - presentInfo.pImageIndices = &imageIndex; - result = vkQueuePresentKHR(presentQueue, &presentInfo); + if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) { + throw std::runtime_error("failed to submit draw command buffer!"); } + // 7. 呈现图像 + VkPresentInfoKHR presentInfo{}; + presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + presentInfo.waitSemaphoreCount = 1; + presentInfo.pWaitSemaphores = signalSemaphores; + VkSwapchainKHR swapChains[] = { swapChain }; + presentInfo.swapchainCount = 1; + presentInfo.pSwapchains = swapChains; + presentInfo.pImageIndices = &imageIndex; + result = vkQueuePresentKHR(presentQueue, &presentInfo); + if (result != VK_SUCCESS) { throw std::runtime_error("failed to present swap chain image!"); } @@ -854,7 +851,7 @@ void Application::createTexture(VkDevice device, VkPhysicalDevice physicalDevice void Application::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path) { - std::unique_lock lock(mtx); + std::unique_lock lock(createTextureMtx); if (texture.image == VK_NULL_HANDLE) { createTexture(device, physicalDevice, width, height, texture, srgb, tex_path, dataSize); diff --git a/vulkan/Application.h b/vulkan/Application.h index 187536a..7ea5d2e 100644 --- a/vulkan/Application.h +++ b/vulkan/Application.h @@ -47,7 +47,7 @@ public: virtual void drawFrame(long long frameTime); virtual void render(VkCommandBuffer commandBuffer, long long frameTime); virtual bool isInited() { return _applicationInited; } - + std::mutex createTextureMtx; void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path); protected: @@ -96,10 +96,7 @@ protected: void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool, VkQueue queue, VkCommandBuffer commandBuffer); void transitionImageLayout(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout); void destroy_texture(Texture texture); - std::mutex mtx; + long long _lastDrawFrameTime; - - std::mutex changeMotionMtx; - }; \ No newline at end of file diff --git a/vulkan/FaceApp.cpp b/vulkan/FaceApp.cpp index b1038cd..620d04f 100644 --- a/vulkan/FaceApp.cpp +++ b/vulkan/FaceApp.cpp @@ -683,10 +683,6 @@ void FaceApp::update_descriptor_set(vector& texs, vector lock(mtx); - std::unique_lock lock_point(mtx_point); - std::unique_lock lock_changeMotion(changeMotionMtx); - //Application::render(commandBuffer); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout_bg, 0, 1, &m_descriptor_set_bg, 0, NULL); @@ -984,12 +980,8 @@ void FaceApp::endSingleTimeCommands(VkCommandBuffer commandBuffer) { submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &commandBuffer; - // 与 Application::drawFrame 共用 graphicsQueue,必须串行,避免驱动内 SIGSEGV - { - std::lock_guard lock(mtx); - vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); - vkQueueWaitIdle(graphicsQueue); - } + vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); + vkQueueWaitIdle(graphicsQueue); vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer); } @@ -1460,7 +1452,9 @@ void FaceApp::drawFrame(long long frameTime) game_time = game_time - actionTime; } } - + std::unique_lock lock_point(mtx_point); + std::unique_lock lock_changeMotion(changeMotionMtx); + std::unique_lock lock_Texture(createTextureMtx); Application::drawFrame(frameTime); } @@ -1620,3 +1614,4 @@ void FaceApp::StopMotion() { void FaceApp::ResumeMotion() { _playMotion = true; } + diff --git a/vulkan/FaceApp.h b/vulkan/FaceApp.h index 266b8cd..f6df3c7 100644 --- a/vulkan/FaceApp.h +++ b/vulkan/FaceApp.h @@ -153,6 +153,7 @@ private: std::map vertices_map_3dmax; std::mutex mtx_point; + std::mutex changeMotionMtx; long long last_update_time; VkBuffer uniform_buffer_vs;