From 770db5e79d853b1dc185d3010ec08aa69a465019 Mon Sep 17 00:00:00 2001 From: "jinhyung.jo" Date: Fri, 14 Dec 2012 17:03:55 +0900 Subject: [PATCH] maru_camera : remove Sonar violations & fixed a bug remove Sonar violations fixed a bug that unexpected temination when play camera on Windows7 Signed-off-by: Jinhyung Jo --- tizen/src/hw/maru_camera_common.h | 8 +- tizen/src/hw/maru_camera_common_pci.c | 21 +-- tizen/src/hw/maru_camera_darwin_pci.m | 48 +++++-- tizen/src/hw/maru_camera_linux_pci.c | 88 ++++++++---- tizen/src/hw/maru_camera_win32_interface.h | 16 +-- tizen/src/hw/maru_camera_win32_pci.c | 219 ++++++++++++++++++++++++----- 6 files changed, 306 insertions(+), 94 deletions(-) diff --git a/tizen/src/hw/maru_camera_common.h b/tizen/src/hw/maru_camera_common.h index deb0f11..8020308 100644 --- a/tizen/src/hw/maru_camera_common.h +++ b/tizen/src/hw/maru_camera_common.h @@ -76,6 +76,7 @@ struct MaruCamState { QemuCond thread_cond; QEMUBH *tx_bh; + bool destroying; void *vaddr; /* vram ptr */ uint32_t isr; uint32_t streamon; @@ -86,11 +87,12 @@ struct MaruCamState { MemoryRegion mmio; }; -/* ----------------------------------------------------------------------------- */ -/* Fucntion prototype */ -/* ----------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ +/* Fucntion prototype */ +/* ------------------------------------------------------------------------- */ int marucam_device_check(int log_flag); void marucam_device_init(MaruCamState *state); +void marucam_device_exit(MaruCamState *state); void marucam_device_open(MaruCamState *state); void marucam_device_close(MaruCamState *state); void marucam_device_start_preview(MaruCamState *state); diff --git a/tizen/src/hw/maru_camera_common_pci.c b/tizen/src/hw/maru_camera_common_pci.c index 3bdcb01..42d853a 100644 --- a/tizen/src/hw/maru_camera_common_pci.c +++ b/tizen/src/hw/maru_camera_common_pci.c @@ -48,13 +48,14 @@ MULTI_DEBUG_CHANNEL(tizen, camera_pci); #define MARU_PCI_CAMERA_DEVICE_NAME "maru_camera_pci" -#define MARUCAM_MEM_SIZE (4 * 1024 * 1024) // 4MB -#define MARUCAM_REG_SIZE (256) // 64 * 4 +#define MARUCAM_MEM_SIZE (4 * 1024 * 1024) /* 4MB */ +#define MARUCAM_REG_SIZE (256) /* 64 * 4Byte */ /* * I/O functions */ -static inline uint32_t marucam_mmio_read(void *opaque, target_phys_addr_t offset) +static inline uint32_t +marucam_mmio_read(void *opaque, target_phys_addr_t offset) { uint32_t ret = 0; MaruCamState *state = (MaruCamState*)opaque; @@ -91,13 +92,15 @@ static inline uint32_t marucam_mmio_read(void *opaque, target_phys_addr_t offset state->param->errCode = 0; break; default: - WARN("Not supported command!!\n"); + ERR("Not supported command: 0x%x\n", offset); + ret = EINVAL; break; } return ret; } -static inline void marucam_mmio_write(void *opaque, target_phys_addr_t offset, uint32_t value) +static inline void +marucam_mmio_write(void *opaque, target_phys_addr_t offset, uint32_t value) { MaruCamState *state = (MaruCamState*)opaque; @@ -160,7 +163,7 @@ static inline void marucam_mmio_write(void *opaque, target_phys_addr_t offset, u qemu_mutex_unlock(&state->thread_mutex); break; default: - WARN("Not supported command!!\n"); + ERR("Not supported command: 0x%x\n", offset); break; } } @@ -230,11 +233,12 @@ static int marucam_initfn(PCIDevice *dev) /* * Termination function */ -static int marucam_exitfn(PCIDevice *obj) +static void marucam_exitfn(PCIDevice *pci_dev) { MaruCamState *s = - OBJECT_CHECK(MaruCamState, obj, MARU_PCI_CAMERA_DEVICE_NAME); + OBJECT_CHECK(MaruCamState, pci_dev, MARU_PCI_CAMERA_DEVICE_NAME); + marucam_device_exit(s); g_free(s->param); qemu_cond_destroy(&s->thread_cond); qemu_mutex_destroy(&s->thread_mutex); @@ -244,7 +248,6 @@ static int marucam_exitfn(PCIDevice *obj) INFO("[%s] camera device was released.\n", __func__); - return 0; } int maru_camera_pci_init(PCIBus *bus) diff --git a/tizen/src/hw/maru_camera_darwin_pci.m b/tizen/src/hw/maru_camera_darwin_pci.m index e91bbf1..7f590c2 100644 --- a/tizen/src/hw/maru_camera_darwin_pci.m +++ b/tizen/src/hw/maru_camera_darwin_pci.m @@ -472,26 +472,31 @@ static void *marucam_worker_thread(void *thread_param) { //MaruCamState *state = (MaruCamState*)thread_param; - wait_worker_thread: - qemu_mutex_lock(&g_state->thread_mutex); - // Wait on the condition - qemu_cond_wait(&g_state->thread_cond, &g_state->thread_mutex); - qemu_mutex_unlock(&g_state->thread_mutex); + while (1) { + qemu_mutex_lock(&g_state->thread_mutex); + // Wait on the condition + qemu_cond_wait(&g_state->thread_cond, &g_state->thread_mutex); + qemu_mutex_unlock(&g_state->thread_mutex); - /* Loop: capture frame -> convert format -> render to screen */ - while (1) - { - if (g_state->streamon) { - if (marucam_device_read_frame() < 0) { + if (g_state->destroying) { + break; + } + + /* Loop: capture frame -> convert format -> render to screen */ + while (1) { + if (g_state->streamon) { + if (marucam_device_read_frame() < 0) { + INFO("Streaming is off ...\n"); + break; + } + } else { INFO("Streaming is off ...\n"); - goto wait_worker_thread; + break; } - } else { - INFO("Streaming is off ...\n"); - goto wait_worker_thread; + //camera_sleep(50); } - //camera_sleep(50); } + return NULL; } @@ -509,9 +514,19 @@ int marucam_device_check(int log_flag) void marucam_device_init(MaruCamState* state) { g_state = state; + g_state->destroying = false; qemu_thread_create(&state->thread_id, marucam_worker_thread, (void*)g_state, QEMU_THREAD_JOINABLE); } +void marucam_device_exit(MaruCamState *state) +{ + state->destroying = true; + qemu_mutex_lock(&state->thread_mutex); + qemu_cond_signal(&state->thread_cond); + qemu_mutex_unlock(&state->thread_mutex); + qemu_thread_join(&state->thread_id); +} + /* MARUCAM_CMD_OPEN */ void marucam_device_open(MaruCamState* state) { @@ -740,6 +755,9 @@ void marucam_device_enum_fmt(MaruCamState* state) case V4L2_PIX_FMT_YVU420: memcpy(¶m->stack[3], "YV12", 32); break; + default: + param->errCode = EINVAL; + break; } } diff --git a/tizen/src/hw/maru_camera_linux_pci.c b/tizen/src/hw/maru_camera_linux_pci.c index e078bc0..38601ca 100644 --- a/tizen/src/hw/maru_camera_linux_pci.c +++ b/tizen/src/hw/maru_camera_linux_pci.c @@ -504,30 +504,36 @@ static void *marucam_worker_thread(void *thread_param) { MaruCamState *state = (MaruCamState *)thread_param; -wait_worker_thread: - 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); + while (1) { + 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); - convert_trial = 10; - ready_count = 0; - qemu_mutex_lock(&state->thread_mutex); - state->streamon = _MC_THREAD_STREAMON; - qemu_mutex_unlock(&state->thread_mutex); - INFO("Streaming on ......\n"); + if (state->destroying) { + break; + } - while (1) { - if (is_streamon(state)) { - if (__v4l2_streaming(state) < 0) { + convert_trial = 10; + ready_count = 0; + qemu_mutex_lock(&state->thread_mutex); + state->streamon = _MC_THREAD_STREAMON; + qemu_mutex_unlock(&state->thread_mutex); + INFO("Streaming on ......\n"); + + while (1) { + if (is_streamon(state)) { + if (__v4l2_streaming(state) < 0) { + INFO("...... Streaming off\n"); + break; + } + } else { INFO("...... Streaming off\n"); - goto wait_worker_thread; + break; } - } else { - INFO("...... Streaming off\n"); - goto wait_worker_thread; } } + return NULL; } @@ -555,16 +561,27 @@ int marucam_device_check(int log_flag) tmp_fd = open(dev_name, O_RDWR | O_NONBLOCK, 0); if (tmp_fd < 0) { fprintf(stdout, "[Webcam] Camera device open failed: %s\n", dev_name); - goto error; + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time: %lu:%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } if (ioctl(tmp_fd, VIDIOC_QUERYCAP, &cap) < 0) { fprintf(stdout, "[Webcam] Could not qeury video capabilities\n"); - goto error; + close(tmp_fd); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time: %lu:%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) || !(cap.capabilities & V4L2_CAP_STREAMING)) { fprintf(stdout, "[Webcam] Not supported video driver\n"); - goto error; + close(tmp_fd); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time: %lu:%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } ret = 1; @@ -578,7 +595,11 @@ int marucam_device_check(int log_flag) format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (yioctl(tmp_fd, VIDIOC_ENUM_FMT, &format) < 0) { - goto error; + close(tmp_fd); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time: %lu:%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } do { @@ -593,7 +614,11 @@ int marucam_device_check(int log_flag) (char)(format.pixelformat >> 24)); if (yioctl(tmp_fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0) { - goto error; + close(tmp_fd); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time: %lu:%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) { @@ -621,7 +646,7 @@ int marucam_device_check(int log_flag) format.index++; } while (yioctl(tmp_fd, VIDIOC_ENUM_FMT, &format) >= 0); } -error: + close(tmp_fd); gettimeofday(&t2, NULL); fprintf(stdout, "[Webcam] Elapsed time: %lu:%06lu\n", @@ -631,10 +656,20 @@ error: void marucam_device_init(MaruCamState *state) { + state->destroying = false; qemu_thread_create(&state->thread_id, marucam_worker_thread, (void *)state, QEMU_THREAD_JOINABLE); } +void marucam_device_exit(MaruCamState *state) +{ + state->destroying = true; + qemu_mutex_lock(&state->thread_mutex); + qemu_cond_signal(&state->thread_cond); + qemu_mutex_unlock(&state->thread_mutex); + qemu_thread_join(&state->thread_id); +} + void marucam_device_open(MaruCamState *state) { MaruCamParam *param = state->param; @@ -906,6 +941,10 @@ void marucam_device_enum_fmt(MaruCamState *state) case V4L2_PIX_FMT_YVU420: memcpy(¶m->stack[3], "YV12", 32); break; + default: + ERR("Invalid fixel format\n"); + param->errCode = EINVAL; + break; } } @@ -942,6 +981,7 @@ void marucam_device_qctrl(MaruCamState *state) i = 3; break; default: + ERR("Invalid control ID\n"); param->errCode = EINVAL; return; } diff --git a/tizen/src/hw/maru_camera_win32_interface.h b/tizen/src/hw/maru_camera_win32_interface.h index 6ae5e20..9c0e126 100644 --- a/tizen/src/hw/maru_camera_win32_interface.h +++ b/tizen/src/hw/maru_camera_win32_interface.h @@ -40,6 +40,12 @@ FWD_DECL(IFilterGraph); #define MAX_PIN_NAME 128 #define MAX_FILTER_NAME 128 +#define DECLARE_INTERFACE2(i) \ + _COM_interface i { CONST_VTABLE struct i##Vtbl *lpVtbl; }; \ + typedef CONST_VTABLE struct i##Vtbl i##Vtbl; \ + CONST_VTABLE struct i##Vtbl +#define DECLARE_INTERFACE2_(i,b) DECLARE_INTERFACE2(i) + typedef LONGLONG REFERENCE_TIME; typedef long OAFilterState; typedef DWORD_PTR HSEMAPHORE; @@ -308,10 +314,7 @@ DECLARE_INTERFACE_(IMediaFilter, IPersist) }; #undef INTERFACE #define INTERFACE IBaseFilter -//DECLARE_INTERFACE_(IBaseFilter, IMediaFilter) -_COM_interface IBaseFilter { CONST_VTABLE struct IBaseFilterVtbl *lpVtbl; }; -typedef CONST_VTABLE struct IBaseFilterVtbl IBaseFilterVtbl; -CONST_VTABLE struct IBaseFilterVtbl +DECLARE_INTERFACE2_(IBaseFilter, IMediaFilter) { STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; STDMETHOD_(ULONG,AddRef)(THIS) PURE; @@ -331,10 +334,7 @@ CONST_VTABLE struct IBaseFilterVtbl }; #undef INTERFACE #define INTERFACE IFilterGraph -//DECLARE_INTERFACE_(IFilterGraph ,IUnknown) -_COM_interface IFilterGraph { CONST_VTABLE struct IFilterGraphVtbl *lpVtbl; }; -typedef CONST_VTABLE struct IFilterGraphVtbl IFilterGraphVtbl; -CONST_VTABLE struct IFilterGraphVtbl +DECLARE_INTERFACE2_(IFilterGraph, IUnknown) { STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; STDMETHOD_(ULONG,AddRef)(THIS) PURE; diff --git a/tizen/src/hw/maru_camera_win32_pci.c b/tizen/src/hw/maru_camera_win32_pci.c index 4371037..312f86a 100644 --- a/tizen/src/hw/maru_camera_win32_pci.c +++ b/tizen/src/hw/maru_camera_win32_pci.c @@ -116,8 +116,12 @@ static STDMETHODIMP HWCGrabCallback_Grab(IGrabCallback *iface, HWCGrabCallback *This = impl_from_IGrabCallback(iface); if (This->m_pCallback) { - This->m_pCallback(dwSize, pBuffer); - return S_OK; + HRESULT hr = This->m_pCallback(dwSize, pBuffer); + if (FAILED(hr)) { + return E_FAIL; + } else { + return S_OK; + } } return E_FAIL; @@ -1198,11 +1202,17 @@ static long value_convert_to_guest(long min, long max, long value) static STDMETHODIMP marucam_device_callbackfn(ULONG dwSize, BYTE *pBuffer) { void *tmp_buf; - uint32_t width, height, fmt; + uint32_t width, height, fmt, imgsize; width = supported_dst_frames[cur_frame_idx].width; height = supported_dst_frames[cur_frame_idx].height; fmt = supported_dst_pixfmts[cur_fmt_idx].fmt; + imgsize = get_sizeimage(fmt, width, height); + + if (imgsize > (uint32_t)dwSize) { + ERR("Image size is mismatched\n"); + return E_FAIL; + } switch (g_dwSrcFmt) { case V4L2_PIX_FMT_YUYV: @@ -1216,6 +1226,9 @@ static STDMETHODIMP marucam_device_callbackfn(ULONG dwSize, BYTE *pBuffer) case V4L2_PIX_FMT_YUYV: memcpy(grab_buf, (void *)pBuffer, (size_t)dwSize); break; + default: + ERR("Invalid pixel format\n"); + return E_FAIL; } break; case V4L2_PIX_FMT_RGB24: @@ -1229,6 +1242,9 @@ static STDMETHODIMP marucam_device_callbackfn(ULONG dwSize, BYTE *pBuffer) case V4L2_PIX_FMT_YUYV: rgb24_to_yuyv(pBuffer, grab_buf, width, height); break; + default: + ERR("Invalid pixel format\n"); + return E_FAIL; } break; case V4L2_PIX_FMT_YUV420: @@ -1242,8 +1258,14 @@ static STDMETHODIMP marucam_device_callbackfn(ULONG dwSize, BYTE *pBuffer) case V4L2_PIX_FMT_YUYV: yuv420_to_yuyv(pBuffer, grab_buf, width, height); break; + default: + ERR("Invalid pixel format\n"); + return E_FAIL; } break; + default: + ERR("Invalid pixel format\n"); + return E_FAIL; } qemu_mutex_lock(&g_state->thread_mutex); @@ -1724,7 +1746,10 @@ int marucam_device_check(int log_flag) hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (FAILED(hr)) { fprintf(stdout, "[Webcam] failed to CoInitailizeEx\n"); - goto leave_check; + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = CoCreateInstance(&CLSID_FilterGraph, NULL, @@ -1733,7 +1758,11 @@ int marucam_device_check(int log_flag) (void **)&pGB); if (FAILED(hr)) { fprintf(stdout, "[Webcam] Failed to create GraphBuilder, 0x%x\n", hr); - goto leave_check; + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = CoCreateInstance(&CLSID_CaptureGraphBuilder2, NULL, @@ -1743,13 +1772,24 @@ int marucam_device_check(int log_flag) if (FAILED(hr)) { fprintf(stdout, "[Webcam] Failed to create CaptureGraphBuilder2, 0x%x\n", hr); - goto leave_check; + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = pCGB->lpVtbl->SetFiltergraph(pCGB, pGB); if (FAILED(hr)) { fprintf(stdout, "[Webcam] Failed to SetFiltergraph, 0x%x\n", hr); - goto leave_check; + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, @@ -1759,26 +1799,54 @@ int marucam_device_check(int log_flag) if (FAILED(hr)) { fprintf(stdout, "[Webcam] failed to create instance of CLSID_SystemDeviceEnum\n"); - goto leave_check; + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = pCreateDevEnum->lpVtbl->CreateClassEnumerator(pCreateDevEnum, &CLSID_VideoInputDeviceCategory, &pEnumMK, 0); if (FAILED(hr)) { fprintf(stdout, "[Webcam] failed to create class enumerator\n"); - goto leave_check; + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } if (!pEnumMK) { fprintf(stdout, "[Webcam] class enumerator is NULL!!\n"); - goto leave_check; + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } pEnumMK->lpVtbl->Reset(pEnumMK); hr = pEnumMK->lpVtbl->Next(pEnumMK, 1, &pMoniKer, NULL); if (FAILED(hr) || (hr == S_FALSE)) { fprintf(stdout, "[Webcam] enum moniker returns a invalid value.\n"); - goto leave_check; + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } IPropertyBag *pBag = NULL; @@ -1787,7 +1855,15 @@ int marucam_device_check(int log_flag) (void **)&pBag); if (FAILED(hr)) { fprintf(stdout, "[Webcam] failed to bind to storage.\n"); - goto leave_check; + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } else { VARIANT var; var.vt = VT_BSTR; @@ -1798,7 +1874,15 @@ int marucam_device_check(int log_flag) SysFreeString(var.bstrVal); SAFE_RELEASE(pBag); SAFE_RELEASE(pMoniKer); - goto leave_check; + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } device_name = __wchar_to_char(var.bstrVal); fprintf(stdout, "[Webcam] Device name : %s\n", device_name); @@ -1809,7 +1893,18 @@ int marucam_device_check(int log_flag) if (FAILED(hr)) { fprintf(stdout, "[Webcam] Counldn't bind moniker to filter object!!\n"); - goto leave_check; + SysFreeString(var.bstrVal); + SAFE_RELEASE(pBag); + SAFE_RELEASE(pMoniKer); + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } else { pSrcFilter->lpVtbl->AddRef(pSrcFilter); } @@ -1823,7 +1918,16 @@ int marucam_device_check(int log_flag) if (hr != S_OK && hr != S_FALSE) { fprintf(stdout, "[Webcam] Counldn't add Video Capture filter to our graph!\n"); - goto leave_check; + SAFE_RELEASE(pSrcFilter); + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = pCGB->lpVtbl->FindInterface(pCGB, &PIN_CATEGORY_CAPTURE, 0, @@ -1831,13 +1935,32 @@ int marucam_device_check(int log_flag) (void **)&pSConfig); if (FAILED(hr)) { fprintf(stdout, "[Webcam] failed to FindInterface method\n"); - goto leave_check; + SAFE_RELEASE(pSrcFilter); + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } hr = pSConfig->lpVtbl->GetNumberOfCapabilities(pSConfig, &iCount, &iSize); if (FAILED(hr)) { fprintf(stdout, "[Webcam] failed to GetNumberOfCapabilities method\n"); - goto leave_check; + SAFE_RELEASE(pSConfig); + SAFE_RELEASE(pSrcFilter); + SAFE_RELEASE(pEnumMK); + SAFE_RELEASE(pCreateDevEnum); + SAFE_RELEASE(pCGB); + SAFE_RELEASE(pGB); + CoUninitialize(); + gettimeofday(&t2, NULL); + fprintf(stdout, "[Webcam] Elapsed time : %lu.%06lu\n", + t2.tv_sec-t1.tv_sec, t2.tv_usec-t1.tv_usec); + return ret; } if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) { @@ -1878,7 +2001,6 @@ int marucam_device_check(int log_flag) fprintf(stdout, "[Webcam] Failed to remove source filer. 0x%x\n", hr); } -leave_check: SAFE_RELEASE(pSConfig); SAFE_RELEASE(pSrcFilter); SAFE_RELEASE(pCGB); @@ -1899,6 +2021,10 @@ void marucam_device_init(MaruCamState *state) g_state = state; } +void marucam_device_exit(MaruCamState *state) +{ +} + /* MARUCAM_CMD_OPEN */ void marucam_device_open(MaruCamState *state) { @@ -1918,25 +2044,49 @@ void marucam_device_open(MaruCamState *state) hr = GraphBuilder_Init(); if (FAILED(hr)) { ERR("GraphBuilder_Init\n"); - goto error_failed; + DisconnectPins(); + RemoveFilters(); + CloseInterfaces(); + CoUninitialize(); + param->errCode = EINVAL; + ERR("camera device open failed!!!, [HRESULT : 0x%x]\n", hr); + return; } hr = BindSourceFilter(); if (FAILED(hr)) { ERR("BindSourceFilter\n"); - goto error_failed; + DisconnectPins(); + RemoveFilters(); + CloseInterfaces(); + CoUninitialize(); + param->errCode = EINVAL; + ERR("camera device open failed!!!, [HRESULT : 0x%x]\n", hr); + return; } hr = BindTargetFilter(); if (FAILED(hr)) { ERR("BindTargetFilter\n"); - goto error_failed; + DisconnectPins(); + RemoveFilters(); + CloseInterfaces(); + CoUninitialize(); + param->errCode = EINVAL; + ERR("camera device open failed!!!, [HRESULT : 0x%x]\n", hr); + return; } hr = ConnectFilters(); if (FAILED(hr)) { ERR("ConnectFilters\n"); - goto error_failed; + DisconnectPins(); + RemoveFilters(); + CloseInterfaces(); + CoUninitialize(); + param->errCode = EINVAL; + ERR("camera device open failed!!!, [HRESULT : 0x%x]\n", hr); + return; } cur_frame_idx = 0; @@ -1948,19 +2098,17 @@ void marucam_device_open(MaruCamState *state) hr = SetFormat(dwWidth, dwHeight, dwDstFmt, &g_dwSrcFmt); if (hr != S_OK) { ERR("failed to Set default values\n"); - goto error_failed; + DisconnectPins(); + RemoveFilters(); + CloseInterfaces(); + CoUninitialize(); + param->errCode = EINVAL; + ERR("camera device open failed!!!, [HRESULT : 0x%x]\n", hr); + return; } INFO("Opened\n"); return; - -error_failed: - DisconnectPins(); - RemoveFilters(); - CloseInterfaces(); - CoUninitialize(); - param->errCode = EINVAL; - ERR("camera device open failed!!!, [HRESULT : 0x%x]\n", hr); } /* MARUCAM_CMD_CLOSE */ @@ -2234,6 +2382,10 @@ void marucam_device_enum_fmt(MaruCamState *state) case V4L2_PIX_FMT_YVU420: memcpy(¶m->stack[3], "YV12", 32); break; + default: + ERR("Invalid pixel format\n"); + param->errCode = EINVAL; + break; } } @@ -2274,6 +2426,7 @@ void marucam_device_qctrl(MaruCamState *state) i = 3; break; default: + ERR("Invalid control ID\n"); param->errCode = EINVAL; return; } @@ -2499,7 +2652,6 @@ void rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, /* Y */ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { - /* RGB2Y(src[0], src[1], src[2], *dest++); */ RGB2Y(src[2], src[1], src[0], *dest++); src += 3; } @@ -2526,9 +2678,6 @@ void rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, src[bytesperline + 4]) / 4; avg_src[2] = (src[2] + src[5] + src[bytesperline + 2] + src[bytesperline + 5]) / 4; - /* - RGB2UV(avg_src[0], avg_src[1], avg_src[2], *udest++, *vdest++); - */ RGB2UV(avg_src[2], avg_src[1], avg_src[0], *udest++, *vdest++); src += 6; } -- 2.7.4