(Apple) Start making camera driver OSX-compatible (OSX 10.7 and up/requires AVFoundation)

This commit is contained in:
Twinaphex 2014-11-18 18:04:17 +01:00
parent 9ea4a0d182
commit 0f43deb6d2
8 changed files with 67 additions and 43 deletions

View File

@ -11,6 +11,9 @@
50351E7F192E5EC100668AB1 /* platform.m in Sources */ = {isa = PBXBuildFile; fileRef = 50351E7E192E5EC100668AB1 /* platform.m */; };
50535530185E0F4000926C26 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5053552F185E0F4000926C26 /* CoreLocation.framework */; };
50C374A919F04F7A00984F8D /* CFExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50C374A819F04F7A00984F8D /* CFExtensions.m */; };
50C61C251A1BB10300A48DD3 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50C61C241A1BB10300A48DD3 /* AVFoundation.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
50C61C271A1BB11D00A48DD3 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50C61C261A1BB11D00A48DD3 /* CoreMedia.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
50C61C291A1BB12F00A48DD3 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50C61C281A1BB12F00A48DD3 /* CoreVideo.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
50D66298199F344700CF54E3 /* Cg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50D66297199F344700CF54E3 /* Cg.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
962EE0E2178B3DF6004224FF /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 962EE0E1178B3DF6004224FF /* IOKit.framework */; };
96355CE31788E72A0010DBFA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96355CE21788E72A0010DBFA /* Cocoa.framework */; };
@ -34,6 +37,9 @@
50351E7E192E5EC100668AB1 /* platform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = platform.m; path = ../platform.m; sourceTree = "<group>"; };
5053552F185E0F4000926C26 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
50C374A819F04F7A00984F8D /* CFExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CFExtensions.m; path = ../../common/CFExtensions.m; sourceTree = SOURCE_ROOT; };
50C61C241A1BB10300A48DD3 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
50C61C261A1BB11D00A48DD3 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
50C61C281A1BB12F00A48DD3 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
50D66295199F28AC00CF54E3 /* Cg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Cg.framework; sourceTree = "<group>"; };
50D66297199F344700CF54E3 /* Cg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cg.framework; path = ../../../../../../../Library/Frameworks/Cg.framework; sourceTree = "<group>"; };
962EE0E1178B3DF6004224FF /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = ../../../../../../../System/Library/Frameworks/IOKit.framework; sourceTree = "<group>"; };
@ -63,6 +69,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
50C61C291A1BB12F00A48DD3 /* CoreVideo.framework in Frameworks */,
50C61C271A1BB11D00A48DD3 /* CoreMedia.framework in Frameworks */,
50C61C251A1BB10300A48DD3 /* AVFoundation.framework in Frameworks */,
50D66298199F344700CF54E3 /* Cg.framework in Frameworks */,
50535530185E0F4000926C26 /* CoreLocation.framework in Frameworks */,
962EE0E2178B3DF6004224FF /* IOKit.framework in Frameworks */,
@ -115,6 +124,9 @@
96355CE11788E72A0010DBFA /* Frameworks */ = {
isa = PBXGroup;
children = (
50C61C281A1BB12F00A48DD3 /* CoreVideo.framework */,
50C61C261A1BB11D00A48DD3 /* CoreMedia.framework */,
50C61C241A1BB10300A48DD3 /* AVFoundation.framework */,
50D66297199F344700CF54E3 /* Cg.framework */,
50D66295199F28AC00CF54E3 /* Cg.framework */,
5053552F185E0F4000926C26 /* CoreLocation.framework */,

View File

@ -20,26 +20,27 @@
/* Define compatibility symbols and categories. */
#ifdef IOS
#ifdef HAVE_CAMERA
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_3_0)
#include <AVFoundation/AVCaptureSession.h>
#include <AVFoundation/AVCaptureDevice.h>
#include <AVFoundation/AVCaptureOutput.h>
#include <AVFoundation/AVCaptureInput.h>
#include <AVFoundation/AVMediaFormat.h>
#ifdef HAVE_OPENGLES
#include <CoreVideo/CVOpenGLESTextureCache.h>
#else
#include <CoreVideo/CVOpenGLTexture.h>
#endif
#endif
#elif defined(OSX)
#if defined(OSX)
/* RAGameView is a container on iOS;
* on OSX these are both the same object
*/
#define g_view g_instance
#endif
#ifdef IOS
#elif defined(IOS)
#include <GLKit/GLKit.h>
#include "../iOS/views.h"
@ -173,10 +174,10 @@ static void apple_gfx_ctx_update(void);
return YES;
}
#ifdef HAVE_CAMERA
#include "contentview_camera_ios.m.inl"
#endif
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_3_0)
#include "contentview_camera_ios.m.inl"
#endif
#ifdef HAVE_LOCATION
@ -185,7 +186,7 @@ static void apple_gfx_ctx_update(void);
@end
#if defined(HAVE_CAMERA) && defined(IOS)
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_3_0)
#include "apple_camera_ios.c.inl"
#endif

View File

@ -1,39 +1,39 @@
typedef struct ios_camera
typedef struct apple_camera
{
void *empty;
} ioscamera_t;
} applecamera_t;
static void *ios_camera_init(const char *device, uint64_t caps, unsigned width, unsigned height)
static void *apple_camera_init(const char *device, uint64_t caps, unsigned width, unsigned height)
{
ioscamera_t *ioscamera;
applecamera_t *applecamera;
if ((caps & (1ULL << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE)) == 0)
{
RARCH_ERR("ioscamera returns OpenGL texture.\n");
RARCH_ERR("applecamera returns OpenGL texture.\n");
return NULL;
}
ioscamera = (ioscamera_t*)calloc(1, sizeof(ioscamera_t));
if (!ioscamera)
applecamera = (applecamera_t*)calloc(1, sizeof(applecamera_t));
if (!applecamera)
return NULL;
[[RAGameView get] onCameraInit];
return ioscamera;
return applecamera;
}
static void ios_camera_free(void *data)
static void apple_camera_free(void *data)
{
ioscamera_t *ioscamera = (ioscamera_t*)data;
applecamera_t *applecamera = (applecamera_t*)data;
[[RAGameView get] onCameraFree];
if (ioscamera)
free(ioscamera);
ioscamera = NULL;
if (applecamera)
free(applecamera);
applecamera = NULL;
}
static bool ios_camera_start(void *data)
static bool apple_camera_start(void *data)
{
(void)data;
@ -42,12 +42,12 @@ static bool ios_camera_start(void *data)
return true;
}
static void ios_camera_stop(void *data)
static void apple_camera_stop(void *data)
{
[[RAGameView get] onCameraStop];
}
static bool ios_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t frame_raw_cb,
static bool apple_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t frame_raw_cb,
retro_camera_frame_opengl_texture_t frame_gl_cb)
{
@ -70,11 +70,11 @@ static bool ios_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t fra
return true;
}
camera_driver_t camera_ios = {
ios_camera_init,
ios_camera_free,
ios_camera_start,
ios_camera_stop,
ios_camera_poll,
"ios",
camera_driver_t camera_apple = {
apple_camera_init,
apple_camera_free,
apple_camera_start,
apple_camera_stop,
apple_camera_poll,
"apple",
};

View File

@ -21,7 +21,7 @@
#define RCVOpenGLTextureCacheCreate CVOpenGLTextureCacheCreate
#define RCVOpenGLTextureRef CVOpenGLTextureRef
#define RCVOpenGLTextureCacheRef CVOpenGLTextureCacheRef
#define RCVOpenGLGetCurrentContext() CGLGetCurrentContext()
#define RCVOpenGLGetCurrentContext() CGLGetCurrentContext(), CGLGetPixelFormat(CGLGetCurrentContext())
#endif
static AVCaptureSession *_session;
@ -30,6 +30,8 @@ RCVOpenGLTextureCacheRef textureCache;
GLuint outputTexture;
static bool newFrame = false;
extern void event_process_camera_frame(void* pixelBufferPtr);
void event_process_camera_frame(void* pixelBufferPtr)
{
CVReturn ret;
@ -40,15 +42,24 @@ void event_process_camera_frame(void* pixelBufferPtr)
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
(void)width;
(void)height;
/*TODO - rewrite all this.
*
* create a texture from our render target.
* textureCache will be what you previously
* made with RCVOpenGLTextureCacheCreate.
*/
#ifdef HAVE_OPENGLES
ret = RCVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
textureCache, pixelBuffer, NULL, GL_TEXTURE_2D,
GL_RGBA, (GLsizei)width, (GLsizei)height, GL_BGRA, GL_UNSIGNED_BYTE, 0, &renderTexture);
textureCache, pixelBuffer, NULL, GL_TEXTURE_2D,
GL_RGBA, (GLsizei)width, (GLsizei)height,
GL_BGRA, GL_UNSIGNED_BYTE, 0, &renderTexture);
#else
ret = RCVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
textureCache, pixelBuffer, 0, &renderTexture);
#endif
if (!renderTexture || ret)
{

View File

@ -106,7 +106,7 @@ enum
CAMERA_V4L2,
CAMERA_RWEBCAM,
CAMERA_ANDROID,
CAMERA_IOS,
CAMERA_APPLE,
CAMERA_NULL,
LOCATION_ANDROID,
@ -275,8 +275,8 @@ enum
#define CAMERA_DEFAULT_DRIVER CAMERA_RWEBCAM
#elif defined(ANDROID)
#define CAMERA_DEFAULT_DRIVER CAMERA_ANDROID
#elif defined(IOS)
#define CAMERA_DEFAULT_DRIVER CAMERA_IOS
#elif defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_3_0)
#define CAMERA_DEFAULT_DRIVER CAMERA_APPLE
#else
#define CAMERA_DEFAULT_DRIVER CAMERA_NULL
#endif

View File

@ -242,8 +242,8 @@ static const camera_driver_t *camera_drivers[] = {
#ifdef ANDROID
&camera_android,
#endif
#ifdef IOS
&camera_ios,
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_3_0)
&camera_apple,
#endif
&camera_null,
NULL,

View File

@ -680,7 +680,7 @@ extern input_driver_t input_null;
extern camera_driver_t camera_v4l2;
extern camera_driver_t camera_android;
extern camera_driver_t camera_rwebcam;
extern camera_driver_t camera_ios;
extern camera_driver_t camera_apple;
extern camera_driver_t camera_null;
extern location_driver_t location_apple;

View File

@ -265,8 +265,8 @@ const char *config_get_default_camera(void)
return "rwebcam";
case CAMERA_ANDROID:
return "android";
case CAMERA_IOS:
return "ios";
case CAMERA_APPLE:
return "apple";
case CAMERA_NULL:
return "null";
}