(V4L2) Fill in raw_framebuffer code - experimental

This commit is contained in:
twinaphex 2013-11-13 15:36:10 +01:00
parent 921327c7ab
commit 3c70302fb6
1 changed files with 16 additions and 19 deletions

View File

@ -66,6 +66,7 @@ typedef struct video4linux
#define YUV_SHIFT(y, cb, cr) ((y << 16) | (cb << 8) | (cr << 0)) #define YUV_SHIFT(y, cb, cr) ((y << 16) | (cb << 8) | (cr << 0))
#define RGB_SHIFT(r, g, b) ((r << 16) | (g << 8) | (b << 0)) #define RGB_SHIFT(r, g, b) ((r << 16) | (g << 8) | (b << 0))
static uint32_t *YCbCr_to_RGB; static uint32_t *YCbCr_to_RGB;
static uint32_t *buffer_output;
static void generate_YCbCr_to_RGB_lookup(void) static void generate_YCbCr_to_RGB_lookup(void)
{ {
@ -125,25 +126,16 @@ static inline void YUV422_to_RGB(uint32_t *output, const uint8_t *input)
output[1] = YCbCr_to_RGB[YUV_SHIFT(y1, cb, cr)]; output[1] = YCbCr_to_RGB[YUV_SHIFT(y1, cb, cr)];
} }
static void process_image(const void *p) static void process_image(void *data, const void *p)
{ {
(void)p; video4linux_t *v4l = (video4linux_t*)data;
//FIXME - fill in here how we are going to render
//this - could have two codepaths - one for GL
//and one non-GL
#if 0
const uint8_t *buffer_yuv = p; const uint8_t *buffer_yuv = p;
size_t x, y;
size_t x; for (y = 0; y < v4l->height; y++)
size_t y; for (x = 0; x < v4l->width; x += 2)
YUV422_to_RGB(buffer_output + (y * v4l->width + x) * 3,
for (y = 0; y < height; y++) buffer_yuv + (y * v4l->width + x) * 2);
for (x = 0; x < width; x += 2)
YUV422_to_RGB(buffer_sdl + (y * width + x) * 3,
buffer_yuv + (y * width + x) * 2);
render(data_sf);
#endif
} }
static int xioctl(int fd, int request, void *args) static int xioctl(int fd, int request, void *args)
@ -419,6 +411,8 @@ static void *v4l_init(const char *device, uint64_t caps, unsigned width, unsigne
if (init_device(v4l) == -1) if (init_device(v4l) == -1)
goto error; goto error;
buffer_output = (uint32_t*)malloc( v4l->width * v4l->height * sizeof(uint32_t));
return v4l; return v4l;
error: error:
@ -443,6 +437,10 @@ static void v4l_free(void *data)
// Assumes one instance. LUT will be gone at some point anyways. // Assumes one instance. LUT will be gone at some point anyways.
free(YCbCr_to_RGB); free(YCbCr_to_RGB);
YCbCr_to_RGB = NULL; YCbCr_to_RGB = NULL;
if (buffer_output)
free(buffer_output);
buffer_output = NULL;
} }
static bool preprocess_image(void *data) static bool preprocess_image(void *data)
@ -475,7 +473,7 @@ static bool preprocess_image(void *data)
assert(buf.index < v4l->n_buffers); assert(buf.index < v4l->n_buffers);
process_image(v4l->buffers[buf.index].start); process_image(v4l, v4l->buffers[buf.index].start);
if (xioctl(v4l->fd, VIDIOC_QBUF, &buf) == -1) if (xioctl(v4l->fd, VIDIOC_QBUF, &buf) == -1)
RARCH_ERR("VIDIOC_QBUF\n"); RARCH_ERR("VIDIOC_QBUF\n");
@ -490,12 +488,11 @@ static bool v4l_poll(void *data, retro_camera_frame_raw_framebuffer_t frame_raw_
if (!v4l->ready) if (!v4l->ready)
return false; return false;
(void)frame_raw_cb;
(void)frame_gl_cb; (void)frame_gl_cb;
if (preprocess_image(data)) if (preprocess_image(data))
{ {
// TODO: Call frame_raw_cb() here with updated data if new data was processed. frame_raw_cb(buffer_output, v4l->width, v4l->height, v4l->width);
return true; return true;
} }
else else