1 /*
2 * Copyright (c) 2009-2011 Intel Corporation.  All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #define LOG_NDEBUG 1
18 #define LOG_TAG "OMXComponentCodecBase"
19 #include <wrs_omxil_core/log.h>
20 #include "OMXComponentCodecBase.h"
21 
22 
OMXComponentCodecBase()23 OMXComponentCodecBase::OMXComponentCodecBase()
24     : mHandlerList(NULL) {
25     pthread_mutex_init(&mSerializationLock, NULL);
26 }
27 
~OMXComponentCodecBase()28 OMXComponentCodecBase::~OMXComponentCodecBase(){
29     HandlerEntry *p = NULL;
30     while (mHandlerList) {
31         p = mHandlerList->next;
32         delete mHandlerList;
33         mHandlerList = p;
34     }
35 
36     if (this->ports) {
37         delete this->ports;
38         this->ports = NULL;
39     }
40 
41     pthread_mutex_destroy(&mSerializationLock);
42 }
43 
ComponentAllocatePorts(void)44 OMX_ERRORTYPE OMXComponentCodecBase::ComponentAllocatePorts(void) {
45     OMX_ERRORTYPE ret = OMX_ErrorNone;
46 
47     this->ports = new PortBase* [NUMBER_PORTS];
48     if (this->ports == NULL) {
49         return OMX_ErrorInsufficientResources;
50     }
51 
52     ret = InitInputPort();
53     CHECK_RETURN_VALUE("InitInputPort");
54 
55     ret = InitOutputPort();
56     CHECK_RETURN_VALUE("InitOutputPort");
57 
58     this->nr_ports = NUMBER_PORTS;
59 
60     // OMX_PORT_PARAM_TYPE
61     // Return to OMX client through index OMX_IndexParamVideoInit/OMX_IndexParamAudioInit
62     // TODO: replace portparam with mPortParam
63     memset(&this->portparam, 0, sizeof(this->portparam));
64     SetTypeHeader(&this->portparam, sizeof(this->portparam));
65     this->portparam.nPorts = NUMBER_PORTS;
66     this->portparam.nStartPortNumber = INPORT_INDEX;
67 
68     return ret;
69 }
70 
71 
ComponentGetParameter(OMX_INDEXTYPE nIndex,OMX_PTR pComponentParameterStructure)72 OMX_ERRORTYPE OMXComponentCodecBase::ComponentGetParameter(
73     OMX_INDEXTYPE nIndex,
74     OMX_PTR pComponentParameterStructure) {
75 
76     OMXHANDLER handler = FindHandler(nIndex, true);
77     if (handler == NULL) {
78         LOGE("ComponentGetParameter: No handler for index %d", nIndex);
79         return OMX_ErrorUnsupportedIndex;
80     }
81 
82     LOGV("ComponentGetParameter: Index = 0x%x", nIndex);
83     return (*handler)(this, pComponentParameterStructure);
84 }
85 
ComponentSetParameter(OMX_INDEXTYPE nIndex,OMX_PTR pComponentParameterStructure)86 OMX_ERRORTYPE OMXComponentCodecBase::ComponentSetParameter(
87     OMX_INDEXTYPE nIndex,
88     OMX_PTR pComponentParameterStructure) {
89 
90     OMXHANDLER handler = FindHandler(nIndex, false);
91     if (handler == NULL) {
92         LOGE("ComponentSetParameter: No handler for index %d", nIndex);
93         return OMX_ErrorUnsupportedIndex;
94     }
95 
96     LOGV("ComponentSetParameter: Index = 0x%x", nIndex);
97     return (*handler)(this, pComponentParameterStructure);
98 }
99 
ComponentGetConfig(OMX_INDEXTYPE nIndex,OMX_PTR pComponentConfigStructure)100 OMX_ERRORTYPE OMXComponentCodecBase::ComponentGetConfig(
101     OMX_INDEXTYPE nIndex,
102     OMX_PTR pComponentConfigStructure) {
103 
104     OMXHANDLER handler = FindHandler(nIndex, true);
105     if (handler == NULL) {
106         LOGE("ComponentGetConfig: No handler for index %d", nIndex);
107         return OMX_ErrorUnsupportedIndex;
108     }
109 
110     LOGV("ComponentGetConfig: Index = 0x%x", nIndex);
111     return (*handler)(this, pComponentConfigStructure);
112 }
113 
ComponentSetConfig(OMX_INDEXTYPE nIndex,OMX_PTR pComponentConfigStructure)114 OMX_ERRORTYPE OMXComponentCodecBase::ComponentSetConfig(
115     OMX_INDEXTYPE nIndex,
116     OMX_PTR pComponentConfigStructure) {
117 
118     OMX_ERRORTYPE ret = OMX_ErrorNone;
119 
120     OMXHANDLER handler = FindHandler(nIndex, false);
121     if (handler == NULL) {
122         LOGE("ComponentSetConfig: No handler for index %d", nIndex);
123         return OMX_ErrorUnsupportedIndex;
124     }
125 
126     LOGV("ComponentSetConfig: Index = 0x%x", nIndex);
127     pthread_mutex_lock(&mSerializationLock);
128     ret = (*handler)(this, pComponentConfigStructure);
129     pthread_mutex_unlock(&mSerializationLock);
130     return ret;
131 }
132 
GetOutputColorFormat(int width)133 OMX_COLOR_FORMATTYPE OMXComponentCodecBase::GetOutputColorFormat(int width) {
134     LOGD("%s: width = %d", __func__, width);
135     return OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar;
136 }
137 
ProcessorInit(void)138 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorInit(void) {
139     LOGV("OMXComponentCodecBase::ProcessorInit");
140 
141     return OMX_ErrorNone;
142 }
143 
ProcessorDeinit(void)144 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorDeinit(void) {
145     LOGV("OMXComponentCodecBase::ProcessorDeinit");
146     return OMX_ErrorNone;
147 }
148 
ProcessorStart(void)149 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorStart(void) {
150     LOGV("OMXComponentCodecBase::ProcessorStart");
151     return OMX_ErrorNone;
152 }
153 
ProcessorStop(void)154 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorStop(void) {
155     LOGV("OMXComponentCodecBase::ProcessorStop");
156     return OMX_ErrorNone;
157 }
158 
ProcessorPause(void)159 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorPause(void) {
160     LOGV("OMXComponentCodecBase::ProcessorPause");
161     return OMX_ErrorNone;
162 }
163 
ProcessorResume(void)164 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorResume(void) {
165     LOGV("OMXComponentCodecBase::ProcessorResume");
166     return OMX_ErrorNone;
167 }
168 
AddHandler(OMX_INDEXTYPE type,OMXComponentCodecBase::OMXHANDLER getter,OMXComponentCodecBase::OMXHANDLER setter)169 OMX_ERRORTYPE OMXComponentCodecBase::AddHandler(
170         OMX_INDEXTYPE type,
171         OMXComponentCodecBase::OMXHANDLER getter,
172         OMXComponentCodecBase::OMXHANDLER setter) {
173 
174     HandlerEntry *p = mHandlerList;
175     HandlerEntry *last = NULL;
176     while (p) {
177         if (p->type == type) {
178             p->getter = getter;
179             p->setter = setter;
180             return OMX_ErrorNone;
181         }
182         last = p;
183         p = p->next;
184     }
185     p = new HandlerEntry;
186     if (p == NULL) {
187         return OMX_ErrorInsufficientResources;
188     }
189     p->type = type;
190     p->getter = getter;
191     p->setter = setter;
192     p->next = NULL;
193 
194     if (last) {
195         last->next = p;
196     } else {
197         mHandlerList = p;
198     }
199     return OMX_ErrorNone;
200 }
201 
FindHandler(OMX_INDEXTYPE type,bool get)202 OMXComponentCodecBase::OMXHANDLER OMXComponentCodecBase::FindHandler(OMX_INDEXTYPE type, bool get) {
203     HandlerEntry *p = mHandlerList;
204     while (p) {
205         if (p->type == type) {
206             return get ? p->getter : p->setter;
207         }
208         p = p->next;
209     }
210     return NULL;
211 }
212 
BuildHandlerList(void)213 OMX_ERRORTYPE OMXComponentCodecBase::BuildHandlerList(void) {
214     return OMX_ErrorNone;
215 }
216 
217 
218