1 /* Copyright (c) 2013, 2016, 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 // JPEG dependencies
34 #include "mm_jpeg.h"
35
36 /** mm_jpeg_get_session:
37 *
38 * Arguments:
39 * @my_obj: jpeg object
40 * @client_idx: client index
41 *
42 * Return:
43 * job index
44 *
45 * Description:
46 * Get job index by client id
47 *
48 **/
mm_jpeg_get_session(mm_jpeg_obj * my_obj,uint32_t job_id)49 static inline mm_jpeg_job_session_t *mm_jpeg_get_session(mm_jpeg_obj *my_obj, uint32_t job_id)
50 {
51 mm_jpeg_job_session_t *p_session = NULL;
52 int client_idx = GET_CLIENT_IDX(job_id);
53 int session_idx= GET_SESSION_IDX(job_id);
54
55 LOGD("client_idx %d session_idx %d",
56 client_idx, session_idx);
57 if ((session_idx >= MM_JPEG_MAX_SESSION) ||
58 (client_idx >= MAX_JPEG_CLIENT_NUM)) {
59 LOGE("invalid job id %x",
60 job_id);
61 return NULL;
62 }
63 pthread_mutex_lock(&my_obj->clnt_mgr[client_idx].lock);
64 p_session = &my_obj->clnt_mgr[client_idx].session[session_idx];
65 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock);
66 return p_session;
67 }
68
69 /** mm_jpeg_get_job_idx:
70 *
71 * Arguments:
72 * @my_obj: jpeg object
73 * @client_idx: client index
74 *
75 * Return:
76 * job index
77 *
78 * Description:
79 * Get job index by client id
80 *
81 **/
mm_jpeg_get_new_session_idx(mm_jpeg_obj * my_obj,int client_idx,mm_jpeg_job_session_t ** pp_session)82 static inline int mm_jpeg_get_new_session_idx(mm_jpeg_obj *my_obj, int client_idx,
83 mm_jpeg_job_session_t **pp_session)
84 {
85 int i = 0;
86 int index = -1;
87 for (i = 0; i < MM_JPEG_MAX_SESSION; i++) {
88 pthread_mutex_lock(&my_obj->clnt_mgr[client_idx].lock);
89 if (!my_obj->clnt_mgr[client_idx].session[i].active) {
90 *pp_session = &my_obj->clnt_mgr[client_idx].session[i];
91 my_obj->clnt_mgr[client_idx].session[i].active = OMX_TRUE;
92 index = i;
93 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock);
94 break;
95 }
96 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock);
97 }
98 return index;
99 }
100
101 /** mm_jpeg_get_job_idx:
102 *
103 * Arguments:
104 * @my_obj: jpeg object
105 * @client_idx: client index
106 *
107 * Return:
108 * job index
109 *
110 * Description:
111 * Get job index by client id
112 *
113 **/
mm_jpeg_remove_session_idx(mm_jpeg_obj * my_obj,uint32_t job_id)114 static inline void mm_jpeg_remove_session_idx(mm_jpeg_obj *my_obj, uint32_t job_id)
115 {
116 int client_idx = GET_CLIENT_IDX(job_id);
117 int session_idx= GET_SESSION_IDX(job_id);
118 LOGD("client_idx %d session_idx %d",
119 client_idx, session_idx);
120 pthread_mutex_lock(&my_obj->clnt_mgr[client_idx].lock);
121 my_obj->clnt_mgr[client_idx].session[session_idx].active = OMX_FALSE;
122 pthread_mutex_unlock(&my_obj->clnt_mgr[client_idx].lock);
123 }
124
125
126
127 #endif /* MM_JPEG_INLINES_H_ */
128