1 /* Copyright (c) 2013, The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef MM_JPEG_INLINES_H_ 31 #define MM_JPEG_INLINES_H_ 32 33 #include "mm_jpeg.h" 34 35 /** mm_jpeg_get_session: 36 * 37 * Arguments: 38 * @my_obj: jpeg object 39 * @client_idx: client index 40 * 41 * Return: 42 * job index 43 * 44 * Description: 45 * Get job index by client id 46 * 47 **/ 48 static inline mm_jpeg_job_session_t *mm_jpeg_get_session(mm_jpeg_obj *my_obj, uint32_t job_id) 49 { 50 mm_jpeg_job_session_t *p_session = NULL; 51 int client_idx = GET_CLIENT_IDX(job_id); 52 int session_idx= GET_SESSION_IDX(job_id); 53 54 CDBG("%s:%d] client_idx %d session_idx %d", __func__, __LINE__, 55 client_idx, session_idx); 56 if ((session_idx >= MM_JPEG_MAX_SESSION) || 57 (client_idx >= MAX_JPEG_CLIENT_NUM)) { 58 CDBG_ERROR("%s:%d] invalid job id %x", __func__, __LINE__, 59 job_id); 60 return NULL; 61 } 62 pthread_mutex_lock(&my_obj->clnt_mgr[client_idx].lock); 63 p_session = &my_obj->clnt_mgr[client_idx].session[session_idx]; 64 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock); 65 return p_session; 66 } 67 68 /** mm_jpeg_get_job_idx: 69 * 70 * Arguments: 71 * @my_obj: jpeg object 72 * @client_idx: client index 73 * 74 * Return: 75 * job index 76 * 77 * Description: 78 * Get job index by client id 79 * 80 **/ 81 static inline int mm_jpeg_get_new_session_idx(mm_jpeg_obj *my_obj, int client_idx, 82 mm_jpeg_job_session_t **pp_session) 83 { 84 int i = 0; 85 int index = -1; 86 for (i = 0; i < MM_JPEG_MAX_SESSION; i++) { 87 pthread_mutex_lock(&my_obj->clnt_mgr[client_idx].lock); 88 if (!my_obj->clnt_mgr[client_idx].session[i].active) { 89 *pp_session = &my_obj->clnt_mgr[client_idx].session[i]; 90 my_obj->clnt_mgr[client_idx].session[i].active = OMX_TRUE; 91 index = i; 92 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock); 93 break; 94 } 95 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock); 96 } 97 return index; 98 } 99 100 /** mm_jpeg_get_job_idx: 101 * 102 * Arguments: 103 * @my_obj: jpeg object 104 * @client_idx: client index 105 * 106 * Return: 107 * job index 108 * 109 * Description: 110 * Get job index by client id 111 * 112 **/ 113 static inline void mm_jpeg_remove_session_idx(mm_jpeg_obj *my_obj, uint32_t job_id) 114 { 115 int client_idx = GET_CLIENT_IDX(job_id); 116 int session_idx= GET_SESSION_IDX(job_id); 117 CDBG("%s:%d] client_idx %d session_idx %d", __func__, __LINE__, 118 client_idx, session_idx); 119 pthread_mutex_lock(&my_obj->clnt_mgr[client_idx].lock); 120 my_obj->clnt_mgr[client_idx].session[session_idx].active = OMX_FALSE; 121 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock); 122 } 123 124 125 126 #endif /* MM_JPEG_INLINES_H_ */ 127