mirror of
https://github.com/defold/extension-camera
synced 2025-06-27 18:37:43 +02:00
Additional state handling cleanup
This commit is contained in:
parent
d5cb318c7d
commit
72ecd460d6
@ -37,9 +37,7 @@
|
|||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>NSCameraUsageDescription</key>
|
<key>NSCameraUsageDescription</key>
|
||||||
<string>App Needs to use camera to take Profile picture</string>
|
<string>{{project.title}} needs to use the camera</string>
|
||||||
<key>NSPhotoLibraryAddUsageDescription</key>
|
|
||||||
<string>App Needs to store your photos</string>
|
|
||||||
{{#display.high_dpi}}
|
{{#display.high_dpi}}
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
@ -34,7 +34,6 @@ struct DefoldCamera
|
|||||||
|
|
||||||
DefoldCamera g_DefoldCamera;
|
DefoldCamera g_DefoldCamera;
|
||||||
|
|
||||||
|
|
||||||
void Camera_QueueMessage(CameraStatus status)
|
void Camera_QueueMessage(CameraStatus status)
|
||||||
{
|
{
|
||||||
DM_MUTEX_SCOPED_LOCK(g_DefoldCamera.m_Mutex);
|
DM_MUTEX_SCOPED_LOCK(g_DefoldCamera.m_Mutex);
|
||||||
@ -58,6 +57,20 @@ static void Camera_ProcessQueue()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CameraStatus status = g_DefoldCamera.m_MessageQueue[i];
|
CameraStatus status = g_DefoldCamera.m_MessageQueue[i];
|
||||||
|
|
||||||
|
if (status == STATUS_STARTED)
|
||||||
|
{
|
||||||
|
// Increase ref count
|
||||||
|
dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
|
||||||
|
dmScript::PushBuffer(L, luabuffer);
|
||||||
|
g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
|
||||||
|
}
|
||||||
|
else if (status == STATUS_STOPPED)
|
||||||
|
{
|
||||||
|
dmScript::Unref(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef); // We want it destroyed by the GC
|
||||||
|
g_DefoldCamera.m_VideoBufferLuaRef = 0;
|
||||||
|
}
|
||||||
|
|
||||||
lua_pushnumber(L, (lua_Number)status);
|
lua_pushnumber(L, (lua_Number)status);
|
||||||
int ret = lua_pcall(L, 2, 0, 0);
|
int ret = lua_pcall(L, 2, 0, 0);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@ -90,11 +103,6 @@ static int StartCapture(lua_State* L)
|
|||||||
|
|
||||||
CameraPlatform_StartCapture(&g_DefoldCamera.m_VideoBuffer, type, quality, g_DefoldCamera.m_Params);
|
CameraPlatform_StartCapture(&g_DefoldCamera.m_VideoBuffer, type, quality, g_DefoldCamera.m_Params);
|
||||||
|
|
||||||
// Increase ref count
|
|
||||||
dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
|
|
||||||
dmScript::PushBuffer(L, luabuffer);
|
|
||||||
g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +112,6 @@ static int StopCapture(lua_State* L)
|
|||||||
|
|
||||||
CameraPlatform_StopCapture();
|
CameraPlatform_StopCapture();
|
||||||
|
|
||||||
dmScript::Unref(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef); // We want it destroyed by the GC
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +139,14 @@ static int GetInfo(lua_State* L)
|
|||||||
static int GetFrame(lua_State* L)
|
static int GetFrame(lua_State* L)
|
||||||
{
|
{
|
||||||
DM_LUA_STACK_CHECK(L, 1);
|
DM_LUA_STACK_CHECK(L, 1);
|
||||||
lua_rawgeti(L,LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef);
|
if (g_DefoldCamera.m_VideoBufferLuaRef != 0)
|
||||||
|
{
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, g_DefoldCamera.m_VideoBufferLuaRef);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,11 +17,10 @@ local function start_capture(self)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local sysinfo = sys.get_sys_info()
|
|
||||||
|
|
||||||
local quality = camera.CAPTURE_QUALITY_HIGH
|
local quality = camera.CAPTURE_QUALITY_HIGH
|
||||||
|
|
||||||
local type = camera.CAMERA_TYPE_FRONT
|
local type = camera.CAMERA_TYPE_FRONT
|
||||||
if sysinfo.system_name == 'iPhone OS' then
|
if sys.get_sys_info().system_name == 'iPhone OS' then
|
||||||
type = camera.CAMERA_TYPE_BACK
|
type = camera.CAMERA_TYPE_BACK
|
||||||
quality = camera.CAPTURE_QUALITY_MEDIUM
|
quality = camera.CAPTURE_QUALITY_MEDIUM
|
||||||
end
|
end
|
||||||
@ -30,11 +29,13 @@ local function start_capture(self)
|
|||||||
if status == camera.STATUS_STARTED then
|
if status == camera.STATUS_STARTED then
|
||||||
self.cameraframe = camera.get_frame()
|
self.cameraframe = camera.get_frame()
|
||||||
self.camerainfo = camera.get_info()
|
self.camerainfo = camera.get_info()
|
||||||
self.cameratextureheader = {width=self.camerainfo.width,
|
self.cameratextureheader = {
|
||||||
height=self.camerainfo.height,
|
width=self.camerainfo.width,
|
||||||
type=resource.TEXTURE_TYPE_2D,
|
height=self.camerainfo.height,
|
||||||
format=resource.TEXTURE_FORMAT_RGB,
|
type=resource.TEXTURE_TYPE_2D,
|
||||||
num_mip_maps=1 }
|
format=resource.TEXTURE_FORMAT_RGB,
|
||||||
|
num_mip_maps=1
|
||||||
|
}
|
||||||
label.set_text("logo#status", "Capture Status: ON")
|
label.set_text("logo#status", "Capture Status: ON")
|
||||||
else
|
else
|
||||||
label.set_text("logo#status", "Capture Status: ERROR")
|
label.set_text("logo#status", "Capture Status: ERROR")
|
||||||
@ -53,19 +54,18 @@ function init(self)
|
|||||||
|
|
||||||
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
|
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
|
||||||
|
|
||||||
|
|
||||||
start_capture(self)
|
start_capture(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function final(self)
|
function final(self)
|
||||||
if self.cameraframe ~= nil then
|
if self.cameraframe then
|
||||||
camera.stop_capture()
|
camera.stop_capture()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function update(self, dt)
|
function update(self, dt)
|
||||||
if self.cameraframe ~= nil then
|
if self.cameraframe then
|
||||||
local pathmodelcamera = go.get("#sprite", "texture0")
|
local pathmodelcamera = go.get("#sprite", "texture0")
|
||||||
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
|
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
|
||||||
end
|
end
|
||||||
@ -74,10 +74,10 @@ end
|
|||||||
|
|
||||||
function on_input(self, action_id, action)
|
function on_input(self, action_id, action)
|
||||||
if (action_id == hash("space") or action_id == hash("touch")) and action.pressed then
|
if (action_id == hash("space") or action_id == hash("touch")) and action.pressed then
|
||||||
if self.cameraframe == nil then
|
if self.cameraframe then
|
||||||
start_capture(self)
|
|
||||||
else
|
|
||||||
stop_capture(self)
|
stop_capture(self)
|
||||||
|
else
|
||||||
|
start_capture(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user