Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Sep 8, 2016
1 parent bc5c757 commit cbba2f5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 48 deletions.
31 changes: 18 additions & 13 deletions camera/drivers/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ typedef struct android_camera
static void *android_camera_init(const char *device, uint64_t caps,
unsigned width, unsigned height)
{
JNIEnv *env;
jclass class;
androidcamera_t *androidcamera = NULL;
JNIEnv *env = NULL;
struct android_app *android_app = (struct android_app*)g_android;

(void)device;
(void)width;
(void)height;
Expand All @@ -45,9 +48,7 @@ static void *android_camera_init(const char *device, uint64_t caps,
return NULL;
}

struct android_app *android_app = (struct android_app*)g_android;
androidcamera_t *androidcamera = (androidcamera_t*)
calloc(1, sizeof(androidcamera_t));
androidcamera = (androidcamera_t*)calloc(1, sizeof(androidcamera_t));
if (!androidcamera)
return NULL;

Expand Down Expand Up @@ -102,8 +103,9 @@ static void *android_camera_init(const char *device, uint64_t caps,
static void android_camera_free(void *data)
{
struct android_app *android_app = (struct android_app*)g_android;
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();

if (!env)
return;

Expand All @@ -116,8 +118,9 @@ static void android_camera_free(void *data)
static bool android_camera_start(void *data)
{
struct android_app *android_app = (struct android_app*)g_android;
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();

if (!env)
return NULL;

Expand All @@ -141,8 +144,9 @@ static bool android_camera_start(void *data)
static void android_camera_stop(void *data)
{
struct android_app *android_app = (struct android_app*)g_android;
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();

if (!env)
return;

Expand All @@ -157,15 +161,16 @@ static bool android_camera_poll(void *data,
retro_camera_frame_raw_framebuffer_t frame_raw_cb,
retro_camera_frame_opengl_texture_t frame_gl_cb)
{
jboolean newFrame;
struct android_app *android_app = (struct android_app*)g_android;
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();
androidcamera_t *androidcamera = (androidcamera_t*)data;
JNIEnv *env = jni_thread_getenv();

if (!env)
return NULL;

(void)frame_raw_cb;

jboolean newFrame;
CALL_BOOLEAN_METHOD(env, newFrame, android_app->activity->clazz,
androidcamera->onCameraPoll);

Expand Down
61 changes: 26 additions & 35 deletions camera/drivers/video4linux2.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ static int xioctl(int fd, int request, void *args)

static bool init_mmap(void *data)
{
struct v4l2_requestbuffers req;
video4linux_t *v4l = (video4linux_t*)data;

memset(&req, 0, sizeof(req));
struct v4l2_requestbuffers req = {0};
video4linux_t *v4l = (video4linux_t*)data;

req.count = 4;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
req.count = 4;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;

if (xioctl(v4l->fd, (uint8_t)VIDIOC_REQBUFS, &req) == -1)
{
Expand All @@ -124,13 +122,11 @@ static bool init_mmap(void *data)

for (v4l->n_buffers = 0; v4l->n_buffers < req.count; v4l->n_buffers++)
{
struct v4l2_buffer buf;
struct v4l2_buffer buf = {0};

memset(&buf, 0, sizeof(buf));

buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = v4l->n_buffers;
buf.index = v4l->n_buffers;

if (xioctl(v4l->fd, (uint8_t)VIDIOC_QUERYBUF, &buf) == -1)
{
Expand All @@ -139,7 +135,7 @@ static bool init_mmap(void *data)
}

v4l->buffers[v4l->n_buffers].length = buf.length;
v4l->buffers[v4l->n_buffers].start = mmap(NULL,
v4l->buffers[v4l->n_buffers].start = mmap(NULL,
buf.length, PROT_READ | PROT_WRITE,
MAP_SHARED,
v4l->fd, buf.m.offset);
Expand All @@ -156,11 +152,11 @@ static bool init_mmap(void *data)

static bool init_device(void *data)
{
struct v4l2_capability cap;
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
struct v4l2_format fmt;
video4linux_t *v4l = (video4linux_t*)data;
struct v4l2_capability cap;
struct v4l2_format fmt = {0};
struct v4l2_cropcap cropcap = {0};
video4linux_t *v4l = (video4linux_t*)data;

if (xioctl(v4l->fd, (uint8_t)VIDIOC_QUERYCAP, &cap) < 0)
{
Expand All @@ -184,24 +180,21 @@ static bool init_device(void *data)
return false;
}

memset(&cropcap, 0, sizeof(cropcap));
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

if (xioctl(v4l->fd, (uint8_t)VIDIOC_CROPCAP, &cropcap) == 0)
{
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop.c = cropcap.defrect;
crop.c = cropcap.defrect;
/* Ignore errors here. */
xioctl(v4l->fd, VIDIOC_S_CROP, &crop);
}

memset(&fmt, 0, sizeof(fmt));

fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = v4l->width;
fmt.fmt.pix.height = v4l->height;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = v4l->width;
fmt.fmt.pix.height = v4l->height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_NONE;
fmt.fmt.pix.field = V4L2_FIELD_NONE;

if (xioctl(v4l->fd, (uint8_t)VIDIOC_S_FMT, &fmt) < 0)
{
Expand Down Expand Up @@ -255,9 +248,7 @@ static bool v4l_start(void *data)

for (i = 0; i < v4l->n_buffers; i++)
{
struct v4l2_buffer buf;

memset(&buf, 0, sizeof(buf));
struct v4l2_buffer buf = {0};

buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
Expand Down Expand Up @@ -372,24 +363,24 @@ static void *v4l_init(const char *device, uint64_t caps,

static bool preprocess_image(void *data)
{
video4linux_t *v4l = (video4linux_t*)data;
struct v4l2_buffer buf;
video4linux_t *v4l = (video4linux_t*)data;
struct v4l2_buffer buf = {0};

memset(&buf, 0, sizeof(buf));

buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;

if (xioctl(v4l->fd, (uint8_t)VIDIOC_DQBUF, &buf) == -1)
{
switch (errno)
{
case EAGAIN:
return false;
break;
default:
RARCH_ERR("VIDIOC_DQBUF.\n");
return false;
break;
}

return false;
}

retro_assert(buf.index < v4l->n_buffers);
Expand Down

0 comments on commit cbba2f5

Please sign in to comment.