maru-camera: Removed unnecessary memory copy
authorJinhyung Jo <jinhyung.jo@samsung.com>
Tue, 4 Aug 2015 04:58:06 +0000 (13:58 +0900)
committerJinhyung Jo <jinhyung.jo@samsung.com>
Tue, 4 Aug 2015 07:50:57 +0000 (16:50 +0900)
In the Win32 Module, converted directly image into the device memory
instead  of using a temporary buffer.

Change-Id: If2f765d7a7d826adffb369e2a382bc991b0afc3d
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
tizen/src/hw/pci/maru_camera_win32.c

index 038d2ed..07d5df6 100644 (file)
@@ -1105,7 +1105,6 @@ typedef struct MCBackendWin {
     uint32_t dst_width;
     uint32_t dst_height;
     uint32_t dst_fmt;
-    void *buf;
 } MCBackendWin;
 
 /*
@@ -1154,24 +1153,13 @@ static STDMETHODIMP GrabFrameCallback(MaruCamState *state,
                                               ULONG dwSize, BYTE *pBuffer)
 {
     void *tmp_buf;
-    uint32_t imgsize;
     MCBackendWin *backend = (MCBackendWin *)(state->backend);
 
-    imgsize = get_sizeimage(backend->dst_fmt,
-                            backend->dst_width,
-                            backend->dst_height);
-
-    if (imgsize > (uint32_t)dwSize) {
+    if (state->buf_size > (uint32_t)dwSize) {
         ERR("Image size is mismatched\n");
         return E_FAIL;
     }
 
-    if (convert_frame(backend->src_fmt, backend->dst_fmt,
-                      backend->dst_width, backend->dst_height,
-                      (size_t)dwSize, pBuffer, backend->buf, true) > 0) {
-        return E_FAIL;
-    }
-
     qemu_mutex_lock(&state->thread_mutex);
     if (state->streamon) {
         if (backend->ready_count < MARUCAM_SKIPFRAMES) {
@@ -1187,7 +1175,15 @@ static STDMETHODIMP GrabFrameCallback(MaruCamState *state,
             return S_OK;
         }
         tmp_buf = state->fb_ptr + state->buf_size * (state->req_frame - 1);
-        memcpy(tmp_buf, backend->buf, state->buf_size);
+        if (convert_frame(backend->src_fmt, backend->dst_fmt,
+                          backend->dst_width, backend->dst_height,
+                          (size_t)dwSize, pBuffer, tmp_buf, true) > 0) {
+            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(&state->thread_mutex);
+            return E_FAIL;
+        }
         state->req_frame = 0; /* clear request */
         state->isr |= 0x01;   /* set a flag of rasing a interrupt */
         qemu_bh_schedule(state->tx_bh);
@@ -2035,19 +2031,16 @@ static void backend_win_close(MaruCamState *state)
 static void backend_win_stream_on(MaruCamState *state)
 {
     HRESULT hr;
-    uint32_t pixfmt, width, height;
     MCBackendWin *backend = (MCBackendWin *)(state->backend);
 
     backend->ready_count = 0;
-    width = backend->dst_width;
-    height = backend->dst_height;
-    pixfmt = backend->dst_fmt;
-    state->buf_size = get_sizeimage(pixfmt, width, height);
-
-    INFO("Pixfmt(%c%c%c%c), W:H(%d:%d), buf size(%u)\n",
-         (char)(pixfmt), (char)(pixfmt >> 8),
-         (char)(pixfmt >> 16), (char)(pixfmt >> 24),
-         width, height, state->buf_size);
+    state->buf_size = get_sizeimage(backend->dst_fmt,
+                                    backend->dst_width,
+                                    backend->dst_height);
+
+    INFO("Pixfmt(%.4s), W:H(%d:%d), buf size(%u)\n",
+         (const char *)&backend->dst_fmt, backend->dst_width,
+         backend->dst_height, state->buf_size);
     INFO("Starting preview\n");
 
     assert(backend->pCallback != NULL);
@@ -2058,16 +2051,6 @@ static void backend_win_stream_on(MaruCamState *state)
         return;
     }
 
-    if (backend->buf) {
-        g_free(backend->buf);
-        backend->buf = NULL;
-    }
-    backend->buf = (void *)g_malloc0(state->buf_size);
-    if (backend->buf == NULL) {
-        state->ret_val = ENOMEM;
-        return;
-    }
-
     hr = IMediaControl_Run(backend->pMC);
     if (FAILED(hr)) {
         ERR("Failed to run media control. hr=0x%x\n", hr);
@@ -2106,10 +2089,6 @@ static void backend_win_stream_off(MaruCamState *state)
         return;
     }
 
-    if (backend->buf) {
-        g_free(backend->buf);
-        backend->buf = NULL;
-    }
     state->buf_size = 0;
 
     INFO("Stopping preview\n");
@@ -2158,8 +2137,9 @@ static void backend_win_s_fmt(MaruCamState *state)
         return;
     }
 
-    if ((backend->dst_width != f->width) &&
-        (backend->dst_height != f->height)) {
+    if (backend->dst_width != f->width ||
+        backend->dst_height != f->height ||
+        backend->dst_fmt != f->pixelformat) {
         HRESULT hr = SetFormat(backend, f->width, f->height, f->pixelformat);
         if (FAILED(hr)) {
             state->ret_val = EINVAL;