static int s3c_jpeg_release(struct inode *inode, struct file *file) { DWORD ret; S3C6400_JPG_CTX *JPGRegCtx; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_release", "JPG_Close\n"); ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_release", "DD::JPG Mutex Lock Fail\r\n"); return FALSE; } JPGRegCtx = (S3C6400_JPG_CTX *)file->private_data; if(!JPGRegCtx){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_release", "DD::JPG Invalid Input Handle\r\n"); return FALSE; } if((--instanceNo) < 0) instanceNo = 0; kfree(JPGRegCtx); UnlockJPGMutex(); clk_jpeg_disable(); #ifdef USE_JPEG_DOMAIN_GATING regulator_disable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ return 0; }
/*---------------------------------------------------------------------------- *Function: JPG_Open *Parameters: InitHandle :Handle to JPEG context dwAccess : dwShareMode :File share mode of JPEG *Return Value: This function returns a handle that identifies the open context of JPEG to the calling application. *Implementation Notes: Opens JPEG CODEC device for reading, writing, or both -----------------------------------------------------------------------------*/ DWORD JPG_Open( DWORD InitHandle, DWORD dwAccess, DWORD dwShareMode ) { S3C6410_JPG_CTX *JPGRegCtx; DWORD ret; RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_open().\r\n"))); JPGPowerControl(TRUE); JPGRegCtx = (S3C6410_JPG_CTX *)InitHandle; if(!JPGRegCtx) { RETAILMSG(ZONE_ERROR, (TEXT("JPG Invalid Input Handle\r\n"))); return FALSE; } ret = LockJPGMutex(); if(!ret) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Mutex Lock Fail\r\n"))); return FALSE; } // check the number of instance if(instanceNo > MAX_INSTANCE_NUM) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::Instance Number error-JPEG is running\r\n"))); UnlockJPGMutex(); return FALSE; } instanceNo++; PowerChange = FALSE; RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_Open instanceNo = %d\r\n"),instanceNo)); UnlockJPGMutex(); return (DWORD)JPGRegCtx; }
static void __exit s3c_jpeg_exit(void) { DWORD ret; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_exit", "JPG_Deinit\n"); ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_exit", "DD::JPG Mutex Lock Fail\r\n"); } JPGMemFree(&JPGMem); UnlockJPGMutex(); DeleteJPGMutex(); platform_driver_unregister(&s3c_jpeg_driver); printk("S3C JPEG driver module exit\n"); }
static int s3c_jpeg_open(struct inode *inode, struct file *file) { S3C6400_JPG_CTX *JPGRegCtx; DWORD ret; #ifdef USE_JPEG_DOMAIN_GATING regulator_enable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ clk_jpeg_enable(); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_open", "JPG_open \r\n"); ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_open", "DD::JPG Mutex Lock Fail\r\n"); UnlockJPGMutex(); return FALSE; } JPGRegCtx = (S3C6400_JPG_CTX *)MemAlloc(sizeof(S3C6400_JPG_CTX)); memset(JPGRegCtx, 0x00, sizeof(S3C6400_JPG_CTX)); JPGRegCtx->v_pJPG_REG = JPGMem.v_pJPG_REG; if (instanceNo > MAX_INSTANCE_NUM){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_open", "DD::Instance Number error-JPEG is running, instance number is %d\n", instanceNo); UnlockJPGMutex(); return FALSE; } instanceNo++; UnlockJPGMutex(); file->private_data = (S3C6400_JPG_CTX *)JPGRegCtx; return 0; }
/*---------------------------------------------------------------------------- *Function: JPG_DeInit *Parameters: InitHandle : *Return Value: True/False *Implementation Notes: Deinitialize JPEG Hardware -----------------------------------------------------------------------------*/ BOOL JPG_Deinit( DWORD InitHandle ) { DWORD ret; S3C6410_JPG_CTX *JPGRegCtx; RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Deinit().\r\n"))); JPGRegCtx = (S3C6410_JPG_CTX *)InitHandle; if(!JPGRegCtx) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Invalid Input Handle\r\n"))); return FALSE; } ret = LockJPGMutex(); if(!ret) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Mutex Lock Fail\r\n"))); return FALSE; } JPGBuffFree(JPGRegCtx); JPGMemFree(JPGRegCtx); free(JPGRegCtx); UnlockJPGMutex(); DeleteJPGMutex(); if (hPwrControl) CloseHandle(hPwrControl); if (s6410PWR) FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return TRUE; }
static int s3c_jpeg_probe(struct platform_device *pdev) { struct resource *res; static int size; static int ret; HANDLE h_Mutex; #ifdef USE_JPEG_DOMAIN_GATING jpeg_domain = regulator_get(&pdev->dev, "pd"); if (IS_ERR(jpeg_domain)) { printk(KERN_ERR "failed to get power domain regulator\n"); return -ENOENT; } regulator_enable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ // JPEG clock enable jpeg_hclk = clk_get(NULL, "jpeg_hclk"); if (IS_ERR(jpeg_hclk)) { printk(KERN_ERR "failed to get jpeg hclk source\n"); return -ENOENT; } // JPEG clock enable jpeg_sclk = clk_get(NULL, "jpeg"); if (IS_ERR(jpeg_sclk)) { printk(KERN_ERR "failed to get jpeg sclk source\n"); return -ENOENT; } clk_jpeg_enable(); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { printk(KERN_INFO "failed to get memory region resouce\n"); return -ENOENT; } size = (res->end-res->start)+1; jpeg_mem = request_mem_region(res->start, size, pdev->name); if (jpeg_mem == NULL) { printk(KERN_INFO "failed to get memory region\n"); return -ENOENT; } res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res == NULL) { printk(KERN_INFO "failed to get irq resource\n"); return -ENOENT; } irq_no = res->start; ret = request_irq(res->start, s3c_jpeg_irq, 0, pdev->name, pdev); if (ret != 0) { printk(KERN_INFO "failed to install irq (%d)\n", ret); return ret; } jpeg_base = ioremap(res->start, size); if (jpeg_base == 0) { printk(KERN_INFO "failed to ioremap() region\n"); return -EINVAL; } // Set JPEG clock to 66 MHz clk_set_rate(jpeg_sclk, 66 * 1000 * 1000); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_probe", "JPG_Init\n"); // Mutex initialization h_Mutex = CreateJPGmutex(); if (h_Mutex == NULL) { JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPG Mutex Initialize error\r\n"); return FALSE; } ret = LockJPGMutex(); if (!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPG Mutex Lock Fail\n"); return FALSE; } // Memory initialization if( !JPGMemMapping(&JPGMem) ){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPEG-HOST-MEMORY Initialize error\r\n"); UnlockJPGMutex(); return FALSE; } /* else { if (!JPGBuffMapping(&JPGMem)){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_probe", "DD::JPEG-DATA-MEMORY Initialize error : %d\n"); UnlockJPGMutex(); return FALSE; } }*/ instanceNo = 0; UnlockJPGMutex(); ret = misc_register(&s3c_jpeg_miscdev); clk_jpeg_disable(); #ifdef USE_JPEG_DOMAIN_GATING regulator_disable(jpeg_domain); #endif /* USE_JPEG_DOMAIN_GATING */ return 0; }
static long s3c_jpeg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { S3C6400_JPG_CTX *JPGRegCtx; s3c_jpeg_t *s3c_jpeg_buf; JPG_DEC_PROC_PARAM * DecParam; JPG_ENC_PROC_PARAM * EncParam; BOOL result = TRUE; DWORD ret; ret = LockJPGMutex(); if(!ret){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_ioctl", "DD::JPG Mutex Lock Fail\r\n"); return FALSE; } JPGRegCtx = (S3C6400_JPG_CTX *)file->private_data; if(!JPGRegCtx){ JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_ioctl", "DD::JPG Invalid Input Handle\r\n"); return FALSE; } switch (cmd) { case IOCTL_JPG_DECODE: JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPEG_DECODE\n"); DecParam = (JPG_DEC_PROC_PARAM *)arg; //JPEG_Copy_From_User(&DecParam, (JPG_DEC_PROC_PARAM *)arg, sizeof(JPG_DEC_PROC_PARAM)); // JPGRegCtx->v_pJPGData_Buff = JPGMem.v_pJPGData_Buff; // JPGRegCtx->p_pJPGData_Buff = JPGMem.p_pJPGData_Buff; // JPGRegCtx->v_pYUVData_Buff = JPGMem.v_pYUVData_Buff; // JPGRegCtx->p_pYUVData_Buff = JPGMem.p_pYUVData_Buff; result = decodeJPG(JPGRegCtx, DecParam); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "width : %d hegiht : %d size : %d\n", DecParam->width, DecParam->height, DecParam->dataSize); //JPEG_Copy_To_User((void *)arg, (void *)&DecParam, sizeof(JPG_DEC_PROC_PARAM)); break; case IOCTL_JPG_ENCODE: JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPEG_ENCODE\n"); EncParam = (JPG_ENC_PROC_PARAM *)arg; //JPEG_Copy_From_User(&EncParam, (JPG_ENC_PROC_PARAM *)arg, sizeof(JPG_ENC_PROC_PARAM)); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "width : %d hegiht : %d\n", EncParam->width, EncParam->height); /* if(EncParam.encType == JPG_MAIN) { JPGRegCtx->v_pJPGData_Buff = JPGMem.v_pJPGData_Buff; JPGRegCtx->p_pJPGData_Buff = JPGMem.p_pJPGData_Buff; JPGRegCtx->v_pYUVData_Buff = JPGMem.v_pYUVData_Buff; JPGRegCtx->p_pYUVData_Buff = JPGMem.p_pYUVData_Buff; } else { JPGRegCtx->v_pJPGData_Buff = JPGMem.frmUserThumbBuf; JPGRegCtx->p_pJPGData_Buff = JPGMem.p_frmUserThumbBuf; JPGRegCtx->v_pYUVData_Buff = JPGMem.strUserThumbBuf; JPGRegCtx->p_pYUVData_Buff = JPGMem.p_strUserThumbBuf; } */ result = encodeJPG(JPGRegCtx, EncParam); JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "encoded file size : %d\n", EncParam->fileSize); //JPEG_Copy_To_User((void *)arg, (void *)&EncParam, sizeof(JPG_ENC_PROC_PARAM)); break; case IOCTL_JPG_SET_STRBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(&s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_pJPGData_Buff = (unsigned int)s3c_jpeg_buf->phys_addr; //JPGMem.v_pJPGData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_pJPGData_Buff = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->v_pJPGData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_STRBUF\n"); break; case IOCTL_JPG_SET_FRMBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_pYUVData_Buff = (unsigned int) s3c_jpeg_buf->phys_addr; //JPGMem.v_pYUVData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_pYUVData_Buff = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->v_pYUVData_Buff = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_FRMBUF\n"); break; case IOCTL_JPG_SET_THUMB_STRBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_strUserThumbBuf = (unsigned int)s3c_jpeg_buf->phys_addr; //JPGMem.strUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_strUserThumbBuf = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->strUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_STRBUF\n"); break; case IOCTL_JPG_SET_THUMB_FRMBUF: s3c_jpeg_buf = (s3c_jpeg_t *)arg; //JPEG_Copy_From_User(s3c_jpeg_buf, (s3c_jpeg_t *)arg, sizeof(s3c_jpeg_t)); //JPGMem.p_frmUserThumbBuf = (unsigned int)s3c_jpeg_buf->phys_addr; //JPGMem.frmUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPGRegCtx->p_frmUserThumbBuf = (unsigned int) s3c_jpeg_buf->phys_addr; JPGRegCtx->frmUserThumbBuf = (unsigned char *)s3c_jpeg_buf->virt_addr; JPEG_LOG_MSG(LOG_TRACE, "s3c_jpeg_ioctl", "IOCTL_JPG_GET_STRBUF\n"); break; default : JPEG_LOG_MSG(LOG_ERROR, "s3c_jpeg_ioctl", "DD::JPG Invalid ioctl : 0x%X\r\n", cmd); } UnlockJPGMutex(); return result; }
/*---------------------------------------------------------------------------- *Function: JPG_Init *Parameters: dwContext : *Return Value: True/False *Implementation Notes: Initialize JPEG Hardware -----------------------------------------------------------------------------*/ DWORD JPG_Init( DWORD dwContext ) { S3C6410_JPG_CTX *JPGRegCtx; HANDLE h_Mutex; DWORD ret; RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Init().\r\n"))); // PWM clock Virtual alloc s6410PWR = (S3C6410_SYSCON_REG *)Phy2VirAddr(S3C6410_BASE_REG_PA_SYSCON, sizeof(S3C6410_SYSCON_REG)); if (s6410PWR == NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG::For s6410PWR: MmMapIoSpace failed!\r\n"))); return FALSE;; } hPwrControl = CreateFile( L"PWC0:", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); if (INVALID_HANDLE_VALUE == hPwrControl ) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::PWC0 Open Device Failed\r\n"))); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } if(JPGSetClkDiv(JPG_CLOCK_DIVIDER_RATIO_QUARTER) == FALSE) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG :: Set Clock Divider Failed\r\n"))); CloseHandle(hPwrControl); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } // Mutex initialization h_Mutex = CreateJPGmutex(); if (h_Mutex == NULL) { RETAILMSG(ZONE_ERROR,(TEXT("JPG_Init: JJPG Mutex Initialize error : %d\n"),GetLastError())); CloseHandle(hPwrControl); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } ret = LockJPGMutex(); if(!ret) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Mutex Lock Fail\r\n"))); DeleteJPGMutex(); CloseHandle(hPwrControl); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } // Register/Memory initialization JPGRegCtx = (S3C6410_JPG_CTX *)malloc(sizeof(S3C6410_JPG_CTX)); if (!JPGRegCtx) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Memory Context Allocation Fail\r\n"))); UnlockJPGMutex(); DeleteJPGMutex(); CloseHandle(hPwrControl); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } memset(JPGRegCtx, 0x00, sizeof(S3C6410_JPG_CTX)); if( !JPGMemMapping(JPGRegCtx) ) { RETAILMSG(ZONE_ERROR,(TEXT("JPG_Init: JPEG-HOST-MEMORY Initialize error : %d\r\n"),GetLastError())); free(JPGRegCtx); UnlockJPGMutex(); DeleteJPGMutex(); CloseHandle(hPwrControl); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } else { if(!JPGBuffMapping(JPGRegCtx)) { RETAILMSG(ZONE_ERROR,(TEXT("JPG_Init: JPEG-DATA-MEMORY Initialize error : %d\r\n"),GetLastError())); JPGMemFree(JPGRegCtx); free(JPGRegCtx); UnlockJPGMutex(); DeleteJPGMutex(); CloseHandle(hPwrControl); FreeVirAddr(s6410PWR, sizeof(S3C6410_SYSCON_REG)); return FALSE; } } instanceNo = 0; UnlockJPGMutex(); return (DWORD)JPGRegCtx; }
/*---------------------------------------------------------------------------- *Function: JPG_IOControl *Parameters: OpenHandle : dwIoControlCode : *Return Value: True/False *Implementation Notes: JPEG_IOControl sends commands to initiate different * operations like Init,Decode and Deinit.The test * application uses the DeviceIOControl function to * specify an operation to perform -----------------------------------------------------------------------------*/ BOOL JPG_IOControl( DWORD OpenHandle, DWORD dwIoControlCode, PBYTE pInBuf, DWORD nInBufSize, PBYTE pOutBuf, DWORD nOutBufSize, PDWORD pBytesReturned ) { S3C6410_JPG_CTX *JPGRegCtx; JPG_DEC_PROC_PARAM *DecReturn; JPG_ENC_PROC_PARAM *EncParam; BOOL result = TRUE; DWORD ret; DWORD dwSize = 0; PVOID pMarshalledBuf = NULL; RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl().\r\n"))); if(PowerChange == TRUE) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPEG ::Power state is changed after open\r\n"))); return FALSE; } JPGRegCtx = (S3C6410_JPG_CTX *)OpenHandle; if(!JPGRegCtx) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::Invalid Input Handle\r\n"))); return FALSE; } ret = LockJPGMutex(); if(!ret) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::Mutex Lock Fail\r\n"))); return FALSE; } switch ( dwIoControlCode ) { case IOCTL_JPG_DECODE: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl::IOCTL_JPEG_DECODE\r\n"))); // NOTE: Using pBytesReturned to pass in parameters is incorrect // This is not being changed right now due to the problem of breaking existing callers // // For now, at least check if the caller has access to the passed in buffer // and duplicate it for use if(FAILED(CeOpenCallerBuffer(&pMarshalledBuf, pInBuf, sizeof(JPG_DEC_PROC_PARAM), ARG_IO_PTR, TRUE))) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: CeOpenCallerBuffer failed in IOCTL_JPG_DECODE.\r\n"))); result = FALSE; break; } DecReturn = (JPG_DEC_PROC_PARAM *)pMarshalledBuf; result = decodeJPG(JPGRegCtx, DecReturn); RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: width : %d hegiht : %d size : %d\n"),DecReturn->width, DecReturn->height, DecReturn->dataSize)); if(FAILED(CeCloseCallerBuffer(pMarshalledBuf, pInBuf, sizeof(JPG_DEC_PROC_PARAM), ARG_IO_PTR))) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: CeCloseCallerBuffer failed in IOCTL_JPG_DECODE.\r\n"))); result = FALSE; break; } break; case IOCTL_JPG_ENCODE: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl:: IOCTL_JPEG_ENCODE\r\n"))); // NOTE: Using pBytesReturned to pass in parameters is incorrect // This is not being changed right now due to the problem of breaking existing callers // // For now, at least check if the caller has access to the passed in buffer // and duplicate it for use if(FAILED(CeOpenCallerBuffer(&pMarshalledBuf, pInBuf, sizeof(JPG_ENC_PROC_PARAM), ARG_IO_PTR, TRUE))) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: CeOpenCallerBuffer failed in IOCTL_JPG_ENCODE..\r\n"))); result = FALSE; break; } EncParam = (JPG_ENC_PROC_PARAM *)pMarshalledBuf; RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: width : %d height : %d enctype : %d quality : %d\n"),EncParam->width, EncParam->height, EncParam->encType, EncParam->quality)); result = encodeJPG(JPGRegCtx, EncParam); RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: encoded file size : %d\n"),EncParam->fileSize)); if(FAILED(CeCloseCallerBuffer(pMarshalledBuf, pInBuf, sizeof(JPG_ENC_PROC_PARAM), ARG_IO_PTR))) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: CeCloseCallerBuffer failed in IOCTL_JPG_ENCODE.\r\n"))); result = FALSE; break; } break; case IOCTL_JPG_GET_STRBUF: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_STRBUF\r\n"))); if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: IOCTL_JPG_GET_STRBUF Error: invalid parameter.\r\n"))); SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } if(JPGRegCtx->strUserBuf == NULL) { JPGRegCtx->callerProcess = (HANDLE) GetDirectCallerProcessId(); dwSize = JPG_STREAM_BUF_SIZE; if (dwSize > IMAGE_JPG_BUFFER_SIZE) // Upper bound the size { JPGRegCtx->strUserBuf = NULL; } else { result = AllocateAndMapToUserMemory(JPGRegCtx->callerProcess, (LPVOID)JPGRegCtx->v_pJPGData_Buff, dwSize, (LPVOID*)&JPGRegCtx->strUserBuf); } if (JPGRegCtx->strUserBuf == NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: JPG Memory Allocation Fail.\r\n"))); result = FALSE; } } RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: strUserBuf : 0x%x CallerProcessID : 0x%x\r\n"),JPGRegCtx->strUserBuf, JPGRegCtx->callerProcess)); __try { *((UINT *)pOutBuf) = (UINT) JPGRegCtx->strUserBuf; } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl: JPG IOCTL_JPG_GET_STRBUF exception.\r\n"))) ; result = FALSE; } break; case IOCTL_JPG_GET_THUMB_STRBUF: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl:: IOCTL_JPG_GET_THUMB_STRBUF\r\n"))); if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_THUMB_STRBUF Error: invalid parameter.\r\n"))) ; SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } if(JPGRegCtx->strUserThumbBuf == NULL) { JPGRegCtx->callerProcess = (HANDLE) GetDirectCallerProcessId(); dwSize = JPG_STREAM_THUMB_BUF_SIZE; if (dwSize > IMAGE_JPG_BUFFER_SIZE) // Upper bound the size { JPGRegCtx->strUserBuf = NULL; } else { result = AllocateAndMapToUserMemory(JPGRegCtx->callerProcess, (LPVOID)(JPGRegCtx->v_pJPGData_Buff+ JPG_STREAM_BUF_SIZE), dwSize, (LPVOID*)&JPGRegCtx->strUserThumbBuf); } if (JPGRegCtx->strUserThumbBuf == NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG Memory Allocation Fail\r\n"))) ; result = FALSE; } } RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: strUserThumbBuf : 0x%x CallerProcessID : 0x%x\r\n"),JPGRegCtx->strUserThumbBuf, JPGRegCtx->callerProcess)); __try { *((UINT *)pOutBuf) = (UINT) JPGRegCtx->strUserThumbBuf; } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_THUMB_STRBUF exception\r\n"))) ; result = FALSE; } break; case IOCTL_JPG_GET_FRMBUF: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl:: IOCTL_JPG_GET_FRMBUF\r\n"))); if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_FRMBUF Error: invalid parameter\r\n"))) ; SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } if(JPGRegCtx->frmUserBuf == NULL) { JPGRegCtx->callerProcess = (HANDLE) GetDirectCallerProcessId(); dwSize = JPG_FRAME_BUF_SIZE; if (dwSize > IMAGE_JPG_BUFFER_SIZE) // Upper bound the size { JPGRegCtx->strUserBuf = NULL; } else { result = AllocateAndMapToUserMemory(JPGRegCtx->callerProcess, (LPVOID)(JPGRegCtx->v_pJPGData_Buff + JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE), dwSize, (LPVOID*)&JPGRegCtx->frmUserBuf); } if (JPGRegCtx->frmUserBuf == NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG Memory Allocation Fail\r\n"))) ; result = FALSE; } } RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: frmUserBuf : 0x%x CallerProcessID : 0x%x\r\n"),JPGRegCtx->frmUserBuf, JPGRegCtx->callerProcess)); __try { *((UINT *)pOutBuf) = (UINT) JPGRegCtx->frmUserBuf; } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_FRMBUF exception\r\n"))) ; result = FALSE; } break; case IOCTL_JPG_GET_PHY_FRMBUF: if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_PHY_FRMBUF Error: invalid parameter.\r\n"))) ; SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } __try { *((UINT *)pOutBuf) = (UINT)JPG_DATA_BASE_ADDR + JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE; RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: IOCTL_JPG_GET_PHY_FRMBUF : 0x%x\r\n"),JPG_DATA_BASE_ADDR + JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE)); } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_PHY_FRMBUF exception.\r\n"))) ; result = FALSE; } break; case IOCTL_JPG_GET_THUMB_FRMBUF: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl:: IOCTL_JPG_GET_THUMB_FRMBUF\r\n"))); if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_THUMB_FRMBUF Error: invalid parameter.\r\n"))) ; SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } if(JPGRegCtx->frmUserThumbBuf == NULL) { JPGRegCtx->callerProcess = (HANDLE) GetDirectCallerProcessId(); dwSize = JPG_FRAME_THUMB_BUF_SIZE; if (dwSize > IMAGE_JPG_BUFFER_SIZE) // Upper bound the size { JPGRegCtx->strUserBuf = NULL; } else { result = AllocateAndMapToUserMemory(JPGRegCtx->callerProcess, (LPVOID)(JPGRegCtx->v_pJPGData_Buff+ JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE + JPG_FRAME_BUF_SIZE), dwSize, (LPVOID*)&JPGRegCtx->frmUserThumbBuf); } if (JPGRegCtx->frmUserThumbBuf == NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG Memory Allocation Fail\r\n"))) ; result = FALSE; } } RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: frmUserBuf : 0x%x CallerProcessID : 0x%x\r\n"),JPGRegCtx->frmUserThumbBuf, JPGRegCtx->callerProcess)); __try { *((UINT *)pOutBuf) = (UINT) JPGRegCtx->frmUserThumbBuf; } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_THUMB_FRMBUF exception\r\n"))) ; result = FALSE; } break; case IOCTL_JPG_GET_RGBBUF: RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_IOControl:: IOCTL_JPG_GET_RGBBUF\r\n"))); if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_RGBBUF Error: invalid parameter\r\n"))) ; SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } if(JPGRegCtx->rgbBuf == NULL) { JPGRegCtx->callerProcess = (HANDLE) GetDirectCallerProcessId(); dwSize = JPG_RGB_BUF_SIZE; if (dwSize > IMAGE_JPG_BUFFER_SIZE) // Upper bound the size { JPGRegCtx->strUserBuf = NULL; } else { result = AllocateAndMapToUserMemory(JPGRegCtx->callerProcess, (LPVOID)(JPGRegCtx->v_pJPGData_Buff+ JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE+ JPG_FRAME_BUF_SIZE + JPG_FRAME_THUMB_BUF_SIZE), dwSize, (LPVOID*)&JPGRegCtx->rgbBuf); } if (JPGRegCtx->rgbBuf == NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG Memory Allocation Fail\r\n"))) ; result = FALSE; } } RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: frmUserBuf : 0x%x CallerProcessID : 0x%x\r\n"), JPGRegCtx->rgbBuf, JPGRegCtx->callerProcess)); __try { *((UINT *)pOutBuf) = (UINT) JPGRegCtx->rgbBuf; } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_RGBBUF exception\r\n"))) ; result = FALSE; } break; case IOCTL_JPG_GET_PHY_RGBBUF: if (!pOutBuf || nOutBufSize < sizeof(UINT*)) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_PHY_RGBBUF Error: invalid parameter\r\n"))) ; SetLastError(ERROR_INVALID_PARAMETER); result = FALSE; break; } __try { *((UINT *)pOutBuf) = (UINT)JPG_DATA_BASE_ADDR + JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE+ JPG_FRAME_BUF_SIZE + JPG_FRAME_THUMB_BUF_SIZE; RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_IOControl: IOCTL_JPG_GET_PHY_RGBBUF : 0x%x\r\n"), JPG_DATA_BASE_ADDR + JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE + JPG_FRAME_BUF_SIZE + JPG_FRAME_THUMB_BUF_SIZE)); } __except(EXCEPTION_EXECUTE_HANDLER) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG IOCTL_JPG_GET_PHY_RGBBUF exception\r\n"))) ; result = FALSE; } break; default : RETAILMSG(ZONE_ERROR, (TEXT("JPG_IOControl:: JPG Invalid IOControl\r\n"))) ; } UnlockJPGMutex(); return result; }
/*---------------------------------------------------------------------------- *Function: JPG_Close *Parameters: OpenHandle : *Return Value: True/False *Implementation Notes: This function closes the device context identified by OpenHandle -----------------------------------------------------------------------------*/ BOOL JPG_Close( DWORD OpenHandle ) { DWORD ret; S3C6410_JPG_CTX *JPGRegCtx; BOOL result = TRUE; RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Close().\r\n"))); if(PowerChange == TRUE) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPEG ::Power state is changed after open\r\n"))); return FALSE; } JPGRegCtx = (S3C6410_JPG_CTX *)OpenHandle; if(!JPGRegCtx) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Invalid Input Handle\r\n"))); return FALSE; } ret = LockJPGMutex(); if(!ret) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG Mutex Lock Fail\r\n"))); return FALSE; } if((--instanceNo) < 0) instanceNo = 0; RETAILMSG(ZONE_FUNCTION,(TEXT("JPG_Close: JPGRegCtx->callerProcess : = 0x%x\n"),JPGRegCtx->callerProcess)); if(JPGRegCtx->strUserBuf != NULL) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Close: decommit strUserBuf\r\n"))); if(!VirtualFreeEx(JPGRegCtx->callerProcess, // HANDLE hProcess JPGRegCtx->strUserBuf, 0, MEM_RELEASE)) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::JPG VirtualFreeEx(strUserBuf) returns FALSE\r\n"))); } JPGRegCtx->strUserBuf = NULL; } if(JPGRegCtx->strUserThumbBuf != NULL) { RETAILMSG(ZONE_ERROR, (TEXT("JPG_Close: decommit strUserThumbBuf\r\n"))); if(!VirtualFreeEx(JPGRegCtx->callerProcess, // HANDLE hProcess JPGRegCtx->strUserThumbBuf, 0, MEM_RELEASE)) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPEG ::VirtualFreeEx(strUserThumbBuf) returns FALSE\r\n"))); } JPGRegCtx->strUserThumbBuf = NULL; } if(JPGRegCtx->frmUserBuf != NULL) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Close:decommit frmUserBuf\r\n"))); if(!VirtualFreeEx(JPGRegCtx->callerProcess, // HANDLE hProcess JPGRegCtx->frmUserBuf, 0, MEM_RELEASE)) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::VirtualFreeEx(STRM_BUF) returns FALSE.\r\n"))); } JPGRegCtx->frmUserBuf = NULL; } if(JPGRegCtx->frmUserThumbBuf != NULL) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Close:decommit frmUserThumbBuf\r\n"))); if(!VirtualFreeEx(JPGRegCtx->callerProcess, // HANDLE hProcess JPGRegCtx->frmUserThumbBuf, 0, MEM_RELEASE)) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::VirtualFreeEx(frmUserThumbBuf) returns FALSE.\r\n"))); } JPGRegCtx->frmUserThumbBuf = NULL; } if(JPGRegCtx->rgbBuf != NULL) { RETAILMSG(ZONE_FUNCTION, (TEXT("JPG_Close:decommit rgbBuf\r\n"))); if(!VirtualFreeEx(JPGRegCtx->callerProcess, // HANDLE hProcess JPGRegCtx->rgbBuf, 0, MEM_RELEASE)) { RETAILMSG(ZONE_ERROR, (TEXT("JPEG ::VirtualFreeEx(rgbBuf) returns FALSE\r\n"))); } JPGRegCtx->rgbBuf = NULL; } UnlockJPGMutex(); JPGPowerControl(FALSE); return TRUE; }