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 23 OMXComponentCodecBase::OMXComponentCodecBase() 24 : mHandlerList(NULL) { 25 pthread_mutex_init(&mSerializationLock, NULL); 26 } 27 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 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 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 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 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 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 133 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorInit(void) { 134 LOGV("OMXComponentCodecBase::ProcessorInit"); 135 136 return OMX_ErrorNone; 137 } 138 139 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorDeinit(void) { 140 LOGV("OMXComponentCodecBase::ProcessorDeinit"); 141 return OMX_ErrorNone; 142 } 143 144 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorStart(void) { 145 LOGV("OMXComponentCodecBase::ProcessorStart"); 146 return OMX_ErrorNone; 147 } 148 149 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorStop(void) { 150 LOGV("OMXComponentCodecBase::ProcessorStop"); 151 return OMX_ErrorNone; 152 } 153 154 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorPause(void) { 155 LOGV("OMXComponentCodecBase::ProcessorPause"); 156 return OMX_ErrorNone; 157 } 158 159 OMX_ERRORTYPE OMXComponentCodecBase::ProcessorResume(void) { 160 LOGV("OMXComponentCodecBase::ProcessorResume"); 161 return OMX_ErrorNone; 162 } 163 164 OMX_ERRORTYPE OMXComponentCodecBase::AddHandler( 165 OMX_INDEXTYPE type, 166 OMXComponentCodecBase::OMXHANDLER getter, 167 OMXComponentCodecBase::OMXHANDLER setter) { 168 169 HandlerEntry *p = mHandlerList; 170 HandlerEntry *last = NULL; 171 while (p) { 172 if (p->type == type) { 173 p->getter = getter; 174 p->setter = setter; 175 return OMX_ErrorNone; 176 } 177 last = p; 178 p = p->next; 179 } 180 p = new HandlerEntry; 181 if (p == NULL) { 182 return OMX_ErrorInsufficientResources; 183 } 184 p->type = type; 185 p->getter = getter; 186 p->setter = setter; 187 p->next = NULL; 188 189 if (last) { 190 last->next = p; 191 } else { 192 mHandlerList = p; 193 } 194 return OMX_ErrorNone; 195 } 196 197 OMXComponentCodecBase::OMXHANDLER OMXComponentCodecBase::FindHandler(OMX_INDEXTYPE type, bool get) { 198 HandlerEntry *p = mHandlerList; 199 while (p) { 200 if (p->type == type) { 201 return get ? p->getter : p->setter; 202 } 203 p = p->next; 204 } 205 return NULL; 206 } 207 208 OMX_ERRORTYPE OMXComponentCodecBase::BuildHandlerList(void) { 209 return OMX_ErrorNone; 210 } 211 212 213