[Title] Fixed a problem that first frames of preview are distorted.
authorjinhyung.jo <jinhyung.jo@samsung.com>
Fri, 27 Jul 2012 08:50:03 +0000 (17:50 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Wed, 1 Aug 2012 07:39:09 +0000 (16:39 +0900)
[Type] Enhancement
[Module] Emulator / camera
[Priority] Major
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

tizen/src/hw/maru_camera_common.h
tizen/src/hw/maru_camera_common_pci.c
tizen/src/hw/maru_camera_linux_pci.c
tizen/src/hw/maru_camera_win32_pci.c

index 6d45c39..9abc9f0 100644 (file)
@@ -38,7 +38,7 @@
 #define MARUCAM_CMD_INIT           0x00\r
 #define MARUCAM_CMD_OPEN           0x04\r
 #define MARUCAM_CMD_CLOSE          0x08\r
-#define MARUCAM_CMD_ISSTREAM       0x0C\r
+#define MARUCAM_CMD_ISR            0x0C\r
 #define MARUCAM_CMD_START_PREVIEW  0x10\r
 #define MARUCAM_CMD_STOP_PREVIEW   0x14\r
 #define MARUCAM_CMD_S_PARAM        0x18\r
@@ -54,7 +54,6 @@
 #define MARUCAM_CMD_ENUM_FINTV     0x40\r
 #define MARUCAM_CMD_S_DATA         0x44\r
 #define MARUCAM_CMD_G_DATA         0x48\r
-#define MARUCAM_CMD_CLRIRQ         0x4C\r
 #define MARUCAM_CMD_DATACLR        0x50\r
 #define MARUCAM_CMD_REQFRAME       0x54\r
 \r
@@ -76,6 +75,7 @@ struct MaruCamState {
     QemuCond            thread_cond;\r
 \r
     void                *vaddr;     /* vram ptr */\r
+    uint32_t            isr;\r
     uint32_t            streamon;\r
     uint32_t            buf_size;\r
     uint32_t            req_frame;\r
index 996fa42..4f187c9 100644 (file)
@@ -60,9 +60,11 @@ static inline uint32_t marucam_mmio_read(void *opaque, target_phys_addr_t offset
     MaruCamState *state = (MaruCamState*)opaque;\r
 \r
     switch (offset & 0xFF) {\r
-    case MARUCAM_CMD_ISSTREAM:\r
+    case MARUCAM_CMD_ISR:\r
         qemu_mutex_lock(&state->thread_mutex);\r
-        ret = state->streamon;\r
+        ret = state->isr;\r
+        state->isr = 0;\r
+        qemu_irq_lower(state->dev.irq[2]);\r
         qemu_mutex_unlock(&state->thread_mutex);\r
         break;\r
     case MARUCAM_CMD_G_DATA:\r
@@ -109,6 +111,7 @@ static inline void marucam_mmio_write(void *opaque, target_phys_addr_t offset, u
         break;\r
     case MARUCAM_CMD_STOP_PREVIEW:\r
         marucam_device_stop_preview(state);\r
+        memset(state->vaddr, 0, MARUCAM_MEM_SIZE);\r
         break;\r
     case MARUCAM_CMD_S_PARAM:\r
         marucam_device_s_param(state);\r
@@ -149,9 +152,6 @@ static inline void marucam_mmio_write(void *opaque, target_phys_addr_t offset, u
     case MARUCAM_CMD_DATACLR:\r
         memset(state->param, 0, sizeof(MaruCamParam));\r
         break;\r
-    case MARUCAM_CMD_CLRIRQ:\r
-        qemu_irq_lower(state->dev.irq[2]);\r
-        break;\r
     case MARUCAM_CMD_REQFRAME:\r
         qemu_mutex_lock(&state->thread_mutex);\r
         state->req_frame = value + 1;\r
@@ -191,6 +191,7 @@ static int marucam_initfn(PCIDevice *dev)
 \r
     memory_region_init_ram(&s->vram, NULL, "marucamera.ram", MARUCAM_MEM_SIZE);\r
     s->vaddr = memory_region_get_ram_ptr(&s->vram);\r
+    memset(s->vaddr, 0, MARUCAM_MEM_SIZE);\r
 \r
     memory_region_init_io (&s->mmio, &maru_camera_mmio_ops, s, "maru-camera-mmio", MARUCAM_REG_SIZE);\r
     pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);\r
index 970cfc3..c643a92 100644 (file)
@@ -42,6 +42,7 @@ MULTI_DEBUG_CHANNEL(tizen, camera_linux);
 \r
 static int v4l2_fd;\r
 static int convert_trial;\r
+static int ready_count;\r
 \r
 static struct v4l2_format dst_fmt;\r
 \r
@@ -188,11 +189,17 @@ static int __v4l2_grab(MaruCamState *state)
 \r
     qemu_mutex_lock(&state->thread_mutex);\r
     if (state->streamon) {\r
-        if (state->req_frame) {\r
-            qemu_irq_raise(state->dev.irq[2]);\r
-            state->req_frame = 0;\r
+        if (ready_count >= 4) {\r
+            if (state->req_frame) {\r
+                state->req_frame = 0; // clear request\r
+                state->isr |= 0x01; // set a flag of rasing a interrupt.\r
+                qemu_irq_raise(state->dev.irq[2]);\r
+            }\r
+            ret = 1;\r
+        } else {\r
+            ++ready_count; // skip a frame cause first some frame are distorted.\r
+            ret = 0;\r
         }\r
-        ret = 1;\r
     } else {\r
         ret = -1;\r
     }\r
@@ -273,6 +280,7 @@ void marucam_device_start_preview(MaruCamState* state)
 {\r
     qemu_mutex_lock(&state->thread_mutex);\r
     state->streamon = 1;\r
+    ready_count = 0;\r
     state->buf_size = dst_fmt.fmt.pix.sizeimage;\r
     qemu_cond_signal(&state->thread_cond);\r
     qemu_mutex_unlock(&state->thread_mutex);\r
index d32d3f8..d014f2e 100644 (file)
@@ -1008,6 +1008,7 @@ static struct marucam_qctrl qctrl_tbl[] = {
 \r
 static MaruCamState *g_state = NULL;\r
 \r
+static uint32_t ready_count = 0;\r
 static uint32_t cur_fmt_idx = 0;\r
 static uint32_t cur_frame_idx = 0;\r
 \r
@@ -1079,10 +1080,17 @@ static STDMETHODIMP marucam_device_callbackfn(ULONG dwSize, BYTE *pBuffer)
     }\r
     index = !index;\r
 \r
-    if (g_state->req_frame) {\r
-               mloop_evcmd_raise_intr(g_state->dev.irq[2]);\r
-               g_state->req_frame = 0;\r
+    qemu_mutex_lock(&g_state->thread_mutex);\r
+    if (ready_count >= 4) {\r
+        if (g_state->req_frame) {\r
+            g_state->req_frame = 0; // clear request\r
+            g_state->isr |= 0x01; // set a flag raising a interrupt.\r
+            mloop_evcmd_raise_intr(g_state->dev.irq[2]);\r
+        }\r
+    } else {\r
+        ++ready_count; // skip a frame cause first some frame are distorted.\r
     }\r
+    qemu_mutex_unlock(&g_state->thread_mutex);\r
     return S_OK;\r
 }\r
 \r
@@ -1545,6 +1553,7 @@ void marucam_device_start_preview(MaruCamState* state)
 \r
     qemu_mutex_lock(&state->thread_mutex);\r
     state->streamon = 1;\r
+    ready_count = 0;\r
     qemu_mutex_unlock(&state->thread_mutex);\r
 \r
     width = supported_dst_frames[cur_frame_idx].width;\r