*
*/
+/*********************************************/
+/* Must Translate to AVFoundation */
+/*********************************************/
+
+
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#import <CoreAudio/CoreAudio.h>
#include "qemu-common.h"
#include "maru_camera.h"
#include "maru_camera_convert.h"
+#include "videodev2_min.h"
#include "debug_ch.h"
MULTI_DEBUG_CHANNEL(tizen, camera);
-#define MARUCAM_THREAD_NAME "marucam_worker_thread"
-
-typedef struct tagMaruCamConvertPixfmt {
- uint32_t fmt; /* fourcc */
- uint32_t bpp; /* bits per pixel, 0 for compressed formats */
- uint32_t needs_conversion;
-} MaruCamConvertPixfmt;
-
-
-static MaruCamConvertPixfmt supported_dst_pixfmts[] = {
- { V4L2_PIX_FMT_YUYV, 16, 0 },
- { V4L2_PIX_FMT_UYVY, 16, 0 },
- { V4L2_PIX_FMT_YUV420, 12, 0 },
- { V4L2_PIX_FMT_YVU420, 12, 0 },
+static uint32_t support_fmts[] = {
+ V4L2_PIX_FMT_YUYV,
+ V4L2_PIX_FMT_UYVY,
+ V4L2_PIX_FMT_YUV420,
+ V4L2_PIX_FMT_YVU420,
};
-typedef struct tagMaruCamConvertFrameInfo {
+struct MCFrame {
uint32_t width;
uint32_t height;
-} MaruCamConvertFrameInfo;
+};
-static MaruCamConvertFrameInfo supported_dst_frames[] = {
+static struct MCFrame support_frames[] = {
{ 640, 480 },
{ 352, 288 },
{ 320, 240 },
{ 160, 120 },
};
-#define MARUCAM_CTRL_VALUE_MAX 20
-#define MARUCAM_CTRL_VALUE_MIN 1
-#define MARUCAM_CTRL_VALUE_MID 10
-#define MARUCAM_CTRL_VALUE_STEP 1
-
-enum {
- _MC_THREAD_PAUSED,
- _MC_THREAD_STREAMON,
- _MC_THREAD_STREAMOFF,
-};
-
-#if 0
-struct marucam_qctrl {
- uint32_t id;
- uint32_t hit;
- long min;
- long max;
- long step;
- long init_val;
-};
-
-static struct marucam_qctrl qctrl_tbl[] = {
- { V4L2_CID_BRIGHTNESS, 0, },
- { V4L2_CID_CONTRAST, 0, },
- { V4L2_CID_SATURATION, 0, },
- { V4L2_CID_SHARPNESS, 0, },
-};
-#endif
-
-static MaruCamState *g_state;
-
-static uint32_t ready_count;
-static uint32_t cur_fmt_idx;
-static uint32_t cur_frame_idx;
-
/***********************************
* Mac camera helper functions
***********************************/
BOOL mCaptureIsStarted;
}
-- (MaruCameraDriver *)init;
-- (int)startCapture:(int)width :(int)height;
+- (id)init;
+- (int)startCapture:(int)width setHeight:(int)height;
- (void)stopCapture;
- (int)readFrame:(void *)video_buf;
-- (int)setCaptureFormat:(int)width :(int)height :(int)pix_format;
-- (int)getCaptureFormat:(int)width :(int)height :(int)pix_format;
+- (int)setCaptureFormat:(int)width setHeight:(int)height setFormat:(int)format;
+- (int)getCaptureFormat:(int)width setHeight:(int)height setFormat:(int)format;
- (BOOL)deviceStatus;
@end
@implementation MaruCameraDriver
-- (MaruCameraDriver *)init
+- (id)init
{
BOOL success = NO;
NSError *error;
}
}
-- (int)startCapture:(int)width :(int)height
+- (int)startCapture:(int)width setHeight:(int)height
{
int ret = -1;
if (![mCaptureSession isRunning]) {
/* Set width & height, using default pixel format to capture */
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt: width], (id)kCVPixelBufferWidthKey,
- [NSNumber numberWithInt: height], (id)kCVPixelBufferHeightKey,
- nil];
+ [NSNumber numberWithInt:width], (id)kCVPixelBufferWidthKey,
+ [NSNumber numberWithInt:height], (id)kCVPixelBufferHeightKey,
+ nil];
[mCaptureVideoPreviewOutput setPixelBufferAttributes:attributes];
[mCaptureSession startRunning];
} else {
}
if ([mCaptureSession isRunning]) {
- while(!mCaptureIsStarted) {
+ while (!mCaptureIsStarted) {
/* Wait Until Capture is started */
- [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
+ [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
}
ret = 0;
}
{
if ([mCaptureSession isRunning]) {
[mCaptureSession stopRunning];
- while([mCaptureSession isRunning]) {
+ while ([mCaptureSession isRunning]) {
/* Wait Until Capture is stopped */
- [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
+ [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
}
return -1;
}
-- (int)setCaptureFormat:(int)width :(int)height :(int)pix_format
+- (int)setCaptureFormat:(int)width setHeight:(int)height setFormat:(int)format
{
int ret = -1;
NSDictionary *attributes;
/* Set the pixel buffer attributes before running the capture session */
if (![mCaptureSession isRunning]) {
- if (pix_format) {
+ if (format) {
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt: width], (id)kCVPixelBufferWidthKey,
- [NSNumber numberWithInt: height], (id)kCVPixelBufferHeightKey,
- [NSNumber numberWithInt: pix_format], (id)kCVPixelBufferPixelFormatTypeKey,
- nil];
+ [NSNumber numberWithInt:width], (id)kCVPixelBufferWidthKey,
+ [NSNumber numberWithInt:height], (id)kCVPixelBufferHeightKey,
+ [NSNumber numberWithInt:format], (id)kCVPixelBufferPixelFormatTypeKey,
+ nil];
} else {
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt: width], (id)kCVPixelBufferWidthKey,
- [NSNumber numberWithInt: height], (id)kCVPixelBufferHeightKey,
- nil];
+ [NSNumber numberWithInt:width], (id)kCVPixelBufferWidthKey,
+ [NSNumber numberWithInt:height], (id)kCVPixelBufferHeightKey,
+ nil];
}
[mCaptureVideoPreviewOutput setPixelBufferAttributes:attributes];
ret = 0;
return ret;
}
-- (int)getCaptureFormat:(int)width :(int)height :(int)pix_format
+- (int)getCaptureFormat:(int)width setHeight:(int)height setFormat:(int)format
{
return 0;
}
** Maru Camera APIs
*****************************************************************/
-typedef struct MaruCameraDevice MaruCameraDevice;
-struct MaruCameraDevice {
+typedef struct MCBackendMac {
+ MaruCamBackend base;
+
/* Maru camera device object. */
MaruCameraDriver *driver;
-};
-/* Golbal representation of the Maru camera */
-MaruCameraDevice *mcd = NULL;
+ uint32_t src_fmt;
+ uint32_t dst_width;
+ uint32_t dst_height;
+ uint32_t dst_fmt;
+} MCBackendMac;
-static int is_streamon()
+static int is_streamon(MaruCamState *state)
{
int st;
- qemu_mutex_lock(&g_state->thread_mutex);
- st = g_state->streamon;
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_lock(&state->thread_mutex);
+ st = state->streamon;
+ qemu_mutex_unlock(&state->thread_mutex);
return (st == _MC_THREAD_STREAMON);
}
-static void __raise_err_intr()
+static void __raise_err_intr(MaruCamState *state)
{
- qemu_mutex_lock(&g_state->thread_mutex);
- if (g_state->streamon == _MC_THREAD_STREAMON) {
- g_state->req_frame = 0; /* clear request */
- g_state->isr = 0x08; /* set a error flag of rasing a interrupt */
- qemu_bh_schedule(g_state->tx_bh);
+ qemu_mutex_lock(&state->thread_mutex);
+ if (state->streamon == _MC_THREAD_STREAMON) {
+ state->req_frame = 0; /* clear request */
+ state->isr = 0x08; /* set a error flag of rasing a interrupt */
+ qemu_bh_schedule(state->tx_bh);
}
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_unlock(&state->thread_mutex);
}
-static int marucam_device_read_frame()
+static int backend_mac_read_frame(MaruCamState *state)
{
int ret;
void *tmp_buf;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- qemu_mutex_lock(&g_state->thread_mutex);
- if (g_state->streamon == _MC_THREAD_STREAMON) {
-#if 0
- if (ready_count < MARUCAM_SKIPFRAMES) {
- /* skip a frame cause first some frame are distorted */
- ++ready_count;
- TRACE("Skip %d frame\n", ready_count);
- qemu_mutex_unlock(&g_state->thread_mutex);
- return 0;
- }
-#endif
- if (g_state->req_frame == 0) {
+ qemu_mutex_lock(&state->thread_mutex);
+ if (state->streamon == _MC_THREAD_STREAMON) {
+ if (state->req_frame == 0) {
TRACE("There is no request\n");
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_unlock(&state->thread_mutex);
return 0;
}
/* Grab the camera frame into temp buffer */
- tmp_buf = g_state->vaddr + g_state->buf_size * (g_state->req_frame - 1);
- ret = [mcd->driver readFrame: tmp_buf];
+ tmp_buf = state->fb_ptr + state->buf_size * (state->req_frame - 1);
+ ret = [backend->driver readFrame: tmp_buf];
if (ret < 0) {
ERR("%s, Capture error\n", __func__);
- qemu_mutex_unlock(&g_state->thread_mutex);
- __raise_err_intr();
+ qemu_mutex_unlock(&state->thread_mutex);
+ __raise_err_intr(state);
return -1;
} else if (!ret) {
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_unlock(&state->thread_mutex);
return 0;
}
- g_state->req_frame = 0; /* clear request */
- g_state->isr |= 0x01; /* set a flag of rasing a interrupt */
- qemu_bh_schedule(g_state->tx_bh);
+ state->req_frame = 0; /* clear request */
+ state->isr |= 0x01; /* set a flag of rasing a interrupt */
+ qemu_bh_schedule(state->tx_bh);
} else {
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_unlock(&state->thread_mutex);
return -1;
}
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_unlock(&state->thread_mutex);
return 0;
}
/* Worker thread to grab frames to the preview window */
static void *marucam_worker_thread(void *thread_param)
{
+ MaruCamState *state = (MaruCamState *)thread_param;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
+
while (1) {
- qemu_mutex_lock(&g_state->thread_mutex);
- g_state->streamon = _MC_THREAD_PAUSED;
- qemu_cond_wait(&g_state->thread_cond, &g_state->thread_mutex);
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_lock(&state->thread_mutex);
+ state->streamon = _MC_THREAD_PAUSED;
+ qemu_cond_wait(&state->thread_cond, &state->thread_mutex);
+ qemu_mutex_unlock(&state->thread_mutex);
- if (g_state->destroying) {
+ if (state->destroying) {
break;
}
- ready_count = 0;
- qemu_mutex_lock(&g_state->thread_mutex);
- g_state->streamon = _MC_THREAD_STREAMON;
- qemu_mutex_unlock(&g_state->thread_mutex);
+ qemu_mutex_lock(&state->thread_mutex);
+ state->streamon = _MC_THREAD_STREAMON;
+ qemu_mutex_unlock(&state->thread_mutex);
INFO("Streaming on ......\n");
/* Loop: capture frame -> convert format -> render to screen */
while (1) {
- if (is_streamon()) {
- if (marucam_device_read_frame() < 0) {
+ if (is_streamon(state)) {
+ if (backend_mac_read_frame(state) < 0) {
INFO("Streaming is off ...\n");
break;
} else {
return NULL;
}
-int marucam_device_check(int log_flag)
+int marucam_device_check()
{
/* FIXME: check the device parameters */
- INFO("Checking camera device\n");
+ INFO("[%s][Not Implemented] Checking camera device\n", __func__);
return 1;
}
/**********************************************
* MARU camera routines
**********************************************/
-void marucam_device_init(MaruCamState *state)
+static void backend_mac__init(MaruCamState *state)
{
- g_state = state;
- g_state->destroying = false;
+ state->destroying = false;
qemu_thread_create(&state->thread_id,
MARUCAM_THREAD_NAME,
marucam_worker_thread,
- NULL,
+ (void *)state,
QEMU_THREAD_JOINABLE);
}
-void marucam_device_exit(MaruCamState *state)
+static void backend_mac_reset(MaruCamState *state)
+{
+}
+
+static void backend_mac_exit(MaruCamState *state)
{
state->destroying = true;
qemu_mutex_lock(&state->thread_mutex);
qemu_thread_join(&state->thread_id);
}
-/* MARUCAM_CMD_OPEN */
-void marucam_device_open(MaruCamState *state)
+static void backend_mac_open(MaruCamState *state)
{
- MaruCamParam *param = state->param;
- param->top = 0;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- mcd = (MaruCameraDevice *)malloc(sizeof(MaruCameraDevice));
- if (mcd == NULL) {
- ERR("%s: MaruCameraDevice allocate failed\n", __func__);
- param->errCode = EINVAL;
+ backend->driver = [[MaruCameraDriver alloc] init];
+ if (backend->driver == nil) {
+ ERR("Camera device open failed\n");
+ [backend->driver dealloc];
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- memset(mcd, 0, sizeof(MaruCameraDevice));
- mcd->driver = [[MaruCameraDriver alloc] init];
- if (mcd->driver == nil) {
- ERR("Camera device open failed\n");
- [mcd->driver dealloc];
- free(mcd);
- param->errCode = EINVAL;
+
+ /* Set default values, TODO: can be smart? */
+ backend->dst_height = support_frames[0].height;
+ backend->dst_width = support_frames[0].width;
+ backend->dst_fmt = support_fmts[0];
+ if ([backend->driver setCaptureFormat: backend->dst_width: backend->dst_height: 0] < 0) {
+ ERR("Set pixel format failed\n");
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- INFO("Camera opened!\n");
+
+
+ INFO("Opend\n");
}
-/* MARUCAM_CMD_CLOSE */
-void marucam_device_close(MaruCamState *state)
+static void backend_mac_close(MaruCamState *state)
{
- MaruCamParam *param = state->param;
- param->top = 0;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- if (mcd != NULL) {
- if (is_streamon()) {
- marucam_device_stop_preview(state);
- }
- [mcd->driver dealloc];
- free(mcd);
- mcd = NULL;
+ if (is_streamon(state)) {
+ state->backend->stream_off(state);
+ }
+ if (backend->driver != nil) {
+ [backend->driver dealloc];
}
- /* marucam_reset_controls(); */
- INFO("Camera closed\n");
+ INFO("Closed\n");
}
-/* MARUCAM_CMD_START_PREVIEW */
-void marucam_device_start_preview(MaruCamState *state)
+static void backend_mac_stream_on(MaruCamState *state)
{
- uint32_t width, height, pixfmt;
- MaruCamParam *param = state->param;
- param->top = 0;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- width = supported_dst_frames[cur_frame_idx].width;
- height = supported_dst_frames[cur_frame_idx].height;
- pixfmt = supported_dst_pixfmts[cur_fmt_idx].fmt;
- state->buf_size = get_sizeimage(pixfmt, width, height);
+ state->buf_size = get_sizeimage(backend->dst_fmt,
+ backend->dst_width,
+ backend->dst_height);
- INFO("Pixfmt(%c%c%c%c), W:H(%d:%d), buf size(%u), frame idx(%d), fmt idx(%d)\n",
+ INFO("Pixfmt(%c%c%c%c), W:H(%u:%u), buf size(%u)\n",
(char)(pixfmt), (char)(pixfmt >> 8),
(char)(pixfmt >> 16), (char)(pixfmt >> 24),
- width, height, state->buf_size,
- cur_frame_idx, cur_fmt_idx);
+ backend->dst_width, backend->dst_height, state->buf_size);
+ INFO("Starting preview\n");
- if (mcd->driver == nil) {
- ERR("%s: Start capture failed: vaild device", __func__);
- param->errCode = EINVAL;
+ if (backend->driver == nil) {
+ ERR("%s: Start capture failed: invaild device", __func__);
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- INFO("Starting preview ...\n");
- [mcd->driver startCapture: width: height];
+ [backend->driver startCapture: width: height];
/* Enable the condition to capture frames now */
qemu_mutex_lock(&state->thread_mutex);
qemu_cond_signal(&state->thread_cond);
qemu_mutex_unlock(&state->thread_mutex);
- while (!is_streamon()) {
+ while (!is_streamon(state)) {
usleep(10000);
}
+
+ INFO("Streaming on ......\n");
}
-/* MARUCAM_CMD_STOP_PREVIEW */
-void marucam_device_stop_preview(MaruCamState *state)
+static void backend_mac_stream_off(MaruCamState *state)
{
- MaruCamParam *param = state->param;
- param->top = 0;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- if (is_streamon()) {
+ INFO("...... Streaming off\n");
+ if (is_streamon(state)) {
qemu_mutex_lock(&state->thread_mutex);
state->streamon = _MC_THREAD_STREAMOFF;
qemu_mutex_unlock(&state->thread_mutex);
- while (is_streamon()) {
+ while (is_streamon(state)) {
usleep(10000);
}
}
- if (mcd->driver != nil) {
- [mcd->driver stopCapture];
+ if (backend->driver != nil) {
+ [backend->driver stopCapture];
}
-
state->buf_size = 0;
- INFO("Stopping preview ...\n");
+
+ INFO("Stopping preview\n");
}
-/* MARUCAM_CMD_S_PARAM */
-void marucam_device_s_param(MaruCamState *state)
+static void backend_mac_s_parm(MaruCamState *state)
{
- MaruCamParam *param = state->param;
-
/* We use default FPS of the webcam */
- param->top = 0;
}
-/* MARUCAM_CMD_G_PARAM */
-void marucam_device_g_param(MaruCamState *state)
+static void backend_mac_g_parm(MaruCamState *state)
{
- MaruCamParam *param = state->param;
+ struct v4l2_captureparm *cp =
+ (struct v4l2_captureparm *)state->io_ptr->data;
/* We use default FPS of the webcam
* return a fixed value on guest ini file (1/30).
*/
- param->top = 0;
- param->stack[0] = 0x1000; /* V4L2_CAP_TIMEPERFRAME */
- param->stack[1] = 1; /* numerator */
- param->stack[2] = 30; /* denominator */
+ cp->capability = V3L2_CAP_TIMEPERFRAME;
+ cp->timeperframe.numerator = 1;
+ cp->timeperframe.denominator = 30;
}
-/* MARUCAM_CMD_S_FMT */
-void marucam_device_s_fmt(MaruCamState *state)
+static void backend_mac_s_fmt(MaruCamState *state)
{
- MaruCamParam *param = state->param;
- uint32_t width, height, pixfmt, pidx, fidx;
-
- param->top = 0;
- width = param->stack[0];
- height = param->stack[1];
- pixfmt = param->stack[2];
+ uint32_t pidx, fidx;
+ struct v4l2_format *f = (struct v4l2_format *)state->io_ptr->data;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- TRACE("Set format: width(%d), height(%d), pixfmt(%d, %.4s)\n",
- width, height, pixfmt, (const char*)&pixfmt);
+ TRACE("Set format: w:h(%u:%u), pixfmt(%u, %.4s)\n",
+ f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat,
+ (const char*)&(f->fmt.pix.pixelformat));
- for (fidx = 0; fidx < ARRAY_SIZE(supported_dst_frames); fidx++) {
- if ((supported_dst_frames[fidx].width == width) &&
- (supported_dst_frames[fidx].height == height)) {
+ for (fidx = 0; fidx < ARRAY_SIZE(support_frames); fidx++) {
+ if ((support_frames[fidx].width == f->fmt.pix.width) &&
+ (support_frames[fidx].height == f->fmt.pix.height)) {
break;
}
}
- if (fidx == ARRAY_SIZE(supported_dst_frames)) {
- param->errCode = EINVAL;
+ if (fidx == ARRAY_SIZE(support_frames)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
-
- for (pidx = 0; pidx < ARRAY_SIZE(supported_dst_pixfmts); pidx++) {
- if (supported_dst_pixfmts[pidx].fmt == pixfmt) {
- TRACE("pixfmt index is match: %d\n", pidx);
+ for (pidx = 0; pidx < ARRAY_SIZE(support_fmts); pidx++) {
+ if (support_fmts[pidx] == f->fmt.pix.pixelformat) {
+ TRACE("pixfmt index is match: index(%u)\n", pidx);
break;
}
}
- if (pidx == ARRAY_SIZE(supported_dst_pixfmts)) {
- param->errCode = EINVAL;
+ if (pidx == ARRAY_SIZE(support_fmts)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- if ((supported_dst_frames[cur_frame_idx].width != width) &&
- (supported_dst_frames[cur_frame_idx].height != height)) {
- if (mcd->driver == nil || [mcd->driver setCaptureFormat: width: height: 0] < 0) {
+ if ((backend->dst_width != f->fmt.pix.width) &&
+ (backend->dst_height != f->fmt.pix.height)) {
+ if ([backend->driver setCaptureFormat: f->fmt.pix.width: f->fmt.pix.height: 0] < 0) {
ERR("Set pixel format failed\n");
- param->errCode = EINVAL;
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
-
- TRACE("cur_frame_idx:%d, supported_dst_frames[cur_frame_idx].width:%d\n",
- cur_frame_idx, supported_dst_frames[cur_frame_idx].width);
}
- cur_frame_idx = fidx;
- cur_fmt_idx = pidx;
-
- pixfmt = supported_dst_pixfmts[cur_fmt_idx].fmt;
- width = supported_dst_frames[cur_frame_idx].width;
- height = supported_dst_frames[cur_frame_idx].height;
+ f->fmt.pix.width = backend->dst_width = support_frames[fidx].width;
+ f->fmt.pix.height = backend->dst_height = support_frames[fidx].height;
+ f->fmt.pix.pixelformat = backend->dst_fmt = support_fmts[pidx];
- param->stack[0] = width;
- param->stack[1] = height;
- param->stack[2] = 1; /* V4L2_FIELD_NONE */
- param->stack[3] = pixfmt;
- param->stack[4] = get_bytesperline(pixfmt, width);
- param->stack[5] = get_sizeimage(pixfmt, width, height);
- param->stack[6] = 0;
- param->stack[7] = 0;
+ f->fmt.pix.field = V4L2_FIELD_NONE;
+ f->fmt.pix.bytesperline = get_bytesperline(backend->dst_fmt,
+ backend->dst_width);
+ f->fmt.pix.sizeimage = get_sizeimage(backend->dst_fmt,
+ backend->dst_width,
+ backend->dst_height);
+ f->fmt.pix.colorspace = 0;
+ f->fmt.pix.priv = 0;
- TRACE("Set device pixel format ...\n");
+ TRACE("Set the format: w:h(%dx%d), fmt(0x%x), "
+ "bytesperline(%d), sizeimage(%d), colorspace(%d)\n",
+ f->fmt.pix.width, f->fmt.pix.height,
+ f->fmt.pix.pixelformat, f->fmt.pix.bytesperline,
+ f->fmt.pix.sizeimage, f->fmt.pix.colorspace);
}
-/* MARUCAM_CMD_G_FMT */
-void marucam_device_g_fmt(MaruCamState *state)
+static void backend_mac_g_fmt(MaruCamState *state)
{
- uint32_t width, height, pixfmt;
- MaruCamParam *param = state->param;
+ struct v4l2_format *f = (struct v4l2_format *)state->io_ptr->data;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- param->top = 0;
- pixfmt = supported_dst_pixfmts[cur_fmt_idx].fmt;
- width = supported_dst_frames[cur_frame_idx].width;
- height = supported_dst_frames[cur_frame_idx].height;
+ f->fmt.pix.width = backend->dst_width;
+ f->fmt.pix.height = backend->dst_height;
+ f->fmt.pix.pixelformat = backend->dst_fmt;
+ f->fmt.pix.field = V4L2_FIELD_NONE;
+ f->fmt.pix.bytesperline = get_bytesperline(backend->dst_fmt,
+ backend->dst_width);
+ f->fmt.pix.sizeimage = get_sizeimage(backend->dst_fmt,
+ backend->dst_width,
+ backend->dst_height);
+ f->fmt.pix.colorspace = 0;
+ f->fmt.pix.priv = 0;
- param->stack[0] = width;
- param->stack[1] = height;
- param->stack[2] = 1; /* V4L2_FIELD_NONE */
- param->stack[3] = pixfmt;
- param->stack[4] = get_bytesperline(pixfmt, width);
- param->stack[5] = get_sizeimage(pixfmt, width, height);
- param->stack[6] = 0;
- param->stack[7] = 0;
-
- TRACE("Get device frame format ...\n");
+ TRACE("Get the format: w:h(%dx%d), fmt(0x%x), "
+ "bytesperline(%d), sizeimage(%d), colorspace(%d)\n",
+ f->fmt.pix.width, f->fmt.pix.height,
+ f->fmt.pix.pixelformat, f->fmt.pix.bytesperline,
+ f->fmt.pix.sizeimage, f->fmt.pix.colorspace);
}
-void marucam_device_try_fmt(MaruCamState *state)
+static void backend_mac_try_fmt(MaruCamState *state)
{
- TRACE("Try device frame format, use default setting ...\n");
+ uint32_t i;
+ struct v4l2_format *f = (struct v4l2_format *)state->io_ptr->data;
+
+ for (i = 0; i < ARRAY_SIZE(support_frames); i++) {
+ if ((support_frames[i].width == f->fmt.pix.width) &&
+ (support_frames[i].height == f->fmt.pix.height)) {
+ break;
+ }
+ }
+ if (i == ARRAY_SIZE(support_frames)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
+ return;
+ }
+ for (i = 0; i < ARRAY_SIZE(support_fmts); i++) {
+ if (support_fmts[i] == f->fmt.pix.pixelformat) {
+ break;
+ }
+ }
+ if (i == ARRAY_SIZE(support_fmts)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
+ return;
+ }
+
+ f->fmt.pix.field = V4L2_FIELD_NONE;
+ f->fmt.pix.bytesperline = get_bytesperline(f->fmt.pix.pixelformat,
+ f->fmt.pix.width);
+ f->fmt.pix.sizeimage = get_sizeimage(f->fmt.pix.pixelformat,
+ f->fmt.pix.width,
+ f->fmt.pix.height);
+ f->fmt.pix.colorspace = 0;
+ f->fmt.pix.priv = 0;
+
+ TRACE("Check the format: w:h(%dx%d), pix_fmt(0x%x), "
+ "bytesperline(%d), sizeimage(%d), colorspace(%d)\n",
+ f->fmt.pix.width, f->fmt.pix.height,
+ f->fmt.pix.pixelformat, f->fmt.pix.bytesperline,
+ f->fmt.pix.sizeimage, f->fmt.pix.colorspace);
}
/* Get specific pixelformat description */
-void marucam_device_enum_fmt(MaruCamState *state)
+static void backend_mac_enum_fmt(MaruCamState *state)
{
- uint32_t index;
- MaruCamParam *param = state->param;
-
- param->top = 0;
- index = param->stack[0];
+ struct v4l2_fmtdesc *f = (struct v4l2_fmtdesc *)state->io_ptr->data;
- if (index >= ARRAY_SIZE(supported_dst_pixfmts)) {
- param->errCode = EINVAL;
+ if (f->index >= ARRAY_SIZE(support_fmts)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- param->stack[1] = 0; /* flags = NONE */
- param->stack[2] = supported_dst_pixfmts[index].fmt; /* pixelformat */
- switch (supported_dst_pixfmts[index].fmt) {
+
+ f->flags = 0; /* flags = NONE */
+ f->pixelformat = support_fmts[f->index];
+
+ /* set description */
+ switch (support_fmts[f->index]) {
case V4L2_PIX_FMT_YUYV:
- memcpy(¶m->stack[3], "YUYV", 32);
- break;
- case V4L2_PIX_FMT_UYVY:
- memcpy(¶m->stack[3], "UYVY", 32);
+ pstrcpy((char *)f->description, sizeof(f->description), "YUYV");
break;
case V4L2_PIX_FMT_YUV420:
- memcpy(¶m->stack[3], "YU12", 32);
+ pstrcpy((char *)f->description, sizeof(f->description), "YU12");
break;
case V4L2_PIX_FMT_YVU420:
- memcpy(¶m->stack[3], "YV12", 32);
+ pstrcpy((char *)f->description, sizeof(f->description), "YV12");
break;
default:
- param->errCode = EINVAL;
+ ERR("Invalid fixel format\n");
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
break;
}
}
/*
* QTKit don't support setting brightness, contrast, saturation & sharpness
*/
-void marucam_device_qctrl(MaruCamState *state)
+static void backend_mac_query_ctrl(MaruCamState *state)
{
- uint32_t id, i;
- /* long property, min, max, step, def_val, set_val; */
- char name[32] = {0,};
- MaruCamParam *param = state->param;
-
- param->top = 0;
- id = param->stack[0];
+ uint32_t i;
+ struct v4l2_queryctrl *qc = (struct v4l2_queryctrl *)state->io_ptr->data;
+ MCBackendMac *backend = (MCBackendMac *)(state->backend);
- switch (id) {
+ /* NOTICE: Tizen MMFW hardcoded for control name
+ Do Not Modified the name
+ */
+ switch (qc->id) {
case V4L2_CID_BRIGHTNESS:
- TRACE("V4L2_CID_BRIGHTNESS\n");
- memcpy((void *)name, (void *)"brightness", 32);
+ TRACE("Query : BRIGHTNESS\n");
+ pstrcpy((char *)qc->name, sizeof(qc->name), "brightness");
i = 0;
break;
case V4L2_CID_CONTRAST:
- TRACE("V4L2_CID_CONTRAST\n");
- memcpy((void *)name, (void *)"contrast", 32);
+ TRACE("Query : CONTRAST\n");
+ pstrcpy((char *)qc->name, sizeof(qc->name), "contrast");
i = 1;
break;
case V4L2_CID_SATURATION:
- TRACE("V4L2_CID_SATURATION\n");
- memcpy((void *)name, (void *)"saturation", 32);
+ TRACE("Query : SATURATION\n");
+ pstrcpy((char *)qc->name, sizeof(qc->name), "saturation");
i = 2;
break;
case V4L2_CID_SHARPNESS:
- TRACE("V4L2_CID_SHARPNESS\n");
- memcpy((void *)name, (void *)"sharpness", 32);
+ TRACE("Query : SHARPNESS\n");
+ pstrcpy((char *)qc->name, sizeof(qc->name), "sharpness");
i = 3;
break;
default:
- param->errCode = EINVAL;
+ ERR("Invalid control ID\n");
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- param->stack[0] = id;
- param->stack[1] = MARUCAM_CTRL_VALUE_MIN; /* minimum */
- param->stack[2] = MARUCAM_CTRL_VALUE_MAX; /* maximum */
- param->stack[3] = MARUCAM_CTRL_VALUE_STEP; /* step */
- param->stack[4] = MARUCAM_CTRL_VALUE_MID; /* default_value */
- param->stack[5] = V4L2_CTRL_FLAG_SLIDER;
- /* name field setting */
- memcpy(¶m->stack[6], (void *)name, sizeof(name)/sizeof(name[0]));
+ /* set fixed values by FW configuration file */
+ qc->minimum = MARUCAM_CTRL_VALUE_MIN; /* minimum */
+ qc->maximum = MARUCAM_CTRL_VALUE_MAX; /* maximum */
+ qc->step = MARUCAM_CTRL_VALUE_STEP; /* step */
+ qc->default_value = MARUCAM_CTRL_VALUE_MID; /* default_value */
+ qc->flags = V4L2_CTRL_FLAG_SLIDER;
}
-void marucam_device_s_ctrl(MaruCamState *state)
+static void backend_mac_s_ctrl(MaruCamState *state)
{
- INFO("Set control\n");
+ INFO("[%s][Not Implemented] QTKit don't support setting "
+ " brightness, contrast, saturation & sharpness\n", __func__);
}
-void marucam_device_g_ctrl(MaruCamState *state)
+static void backend_mac_g_ctrl(MaruCamState *state)
{
- INFO("Get control\n");
+ INFO("[%s][Not Implemented] QTKit don't support getting "
+ " brightness, contrast, saturation & sharpness\n", __func__);
}
/* Get frame width & height */
-void marucam_device_enum_fsizes(MaruCamState *state)
+static void backend_mac_enum_fsizes(MaruCamState *state)
{
- uint32_t index, pixfmt, i;
- MaruCamParam *param = state->param;
-
- param->top = 0;
- index = param->stack[0];
- pixfmt = param->stack[1];
+ uint32_t i;
+ struct v4l2_frmsizeenum *fsize =
+ (struct v4l2_frmsizeenum *)state->io_ptr->data;
- if (index >= ARRAY_SIZE(supported_dst_frames)) {
- param->errCode = EINVAL;
+ if (fsize->index >= ARRAY_SIZE(support_frames)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- for (i = 0; i < ARRAY_SIZE(supported_dst_pixfmts); i++) {
- if (supported_dst_pixfmts[i].fmt == pixfmt) {
+ for (i = 0; i < ARRAY_SIZE(support_fmts); i++) {
+ if (support_fmts[i] == fsize->pixel_format) {
break;
}
}
- if (i == ARRAY_SIZE(supported_dst_pixfmts)) {
- param->errCode = EINVAL;
+ if (i == ARRAY_SIZE(support_fmts)) {
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- param->stack[0] = supported_dst_frames[index].width;
- param->stack[1] = supported_dst_frames[index].height;
+ fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+ fsize->discrete.width = support_frames[fsize->index].width;
+ fsize->discrete.height = support_frames[fsize->index].height;
}
-void marucam_device_enum_fintv(MaruCamState *state)
+static void backend_mac_enum_fintv(MaruCamState *state)
{
- MaruCamParam *param = state->param;
- param->top = 0;
+ struct v4l2_frmivalenum *fival =
+ (struct v4l2_frmivalenum *)state->io_ptr->data;
- /* switch by index(param->stack[0]) */
- switch (param->stack[0]) {
+ /* switch by index) */
+ switch (fival->index) {
case 0:
- param->stack[1] = 30; /* denominator */
+ /* we only use 1/30 frame interval */
+ fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+ fival->discrete.numerator = 1;
+ fival->discrete.denominator = 30;
break;
default:
- param->errCode = EINVAL;
+ state->io_ptr->err_code = EINVAL;
+ state->io_ptr->ret_val = -1;
return;
}
- param->stack[0] = 1; /* numerator */
+}
+
+MaruCamBackend *marucam_backend_create(MaruCamState *state)
+{
+ MCBackendMac *backend_mac;
+
+ backend_mac = g_new0(MCBackendMac, 1);
+
+ backend_mac->base.state = state;
+ backend_mac->base.init = backend_mac_init;
+ backend_mac->base.reset = backend_mac_reset;
+ backend_mac->base.release = backend_mac_release;
+ backend_mac->base.open = backend_mac_open;
+ backend_mac->base.close = backend_mac_close;
+ backend_mac->base.stream_on = backend_mac_stream_on;
+ backend_mac->base.stream_off = backend_mac_stream_off;
+ backend_mac->base.enum_fmt = backend_mac_enum_fmt;
+ backend_mac->base.try_fmt = backend_mac_try_fmt;
+ backend_mac->base.s_fmt = backend_mac_s_fmt;
+ backend_mac->base.g_fmt = backend_mac_g_fmt;
+ backend_mac->base.s_parm = backend_mac_s_parm;
+ backend_mac->base.g_parm = backend_mac_g_parm;
+ backend_mac->base.query_ctrl = backend_mac_query_ctrl;
+ backend_mac->base.s_ctrl = backend_mac_s_ctrl;
+ backend_mac->base.g_ctrl = backend_mac_g_ctrl;
+ backend_mac->base.enum_framesizes = backend_mac_enum_fsizes;
+ backend_mac->base.enum_frameintervals = backend_mac_enum_fintv;
+
+ return &backend_mac->base;
}