| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | #include <OMX_Core.h> |
| 7 | |
| 8 | #include <cmodule.h> |
| 9 | #include <portaudio.h> |
| 10 | #include <componentbase.h> |
| 11 | |
| 12 | #include "sst.h" |
| 13 | |
| 14 | #define LOG_NDEBUG 1 |
| 15 | |
| 16 | #define LOG_TAG "mrst_sst" |
| 17 | #include <log.h> |
| 18 | |
| 19 | /* |
| 20 | * constructor & destructor |
| 21 | */ |
| 22 | MrstSstComponent::MrstSstComponent() |
| 23 | { |
| 24 | LOGV("%s(): enter\n", __func__); |
| 25 | |
| 26 | LOGV("%s(),%d: exit (ret = void)\n", __func__, __LINE__); |
| 27 | } |
| 28 | |
| 29 | MrstSstComponent::~MrstSstComponent() |
| 30 | { |
| 31 | LOGV("%s(): enter\n", __func__); |
| 32 | |
| 33 | LOGV("%s(),%d: exit (ret = void)\n", __func__, __LINE__); |
| 34 | } |
| 35 | |
| 36 | /* end of constructor & destructor */ |
| 37 | |
| 38 | /* core methods & helpers */ |
| 39 | OMX_ERRORTYPE MrstSstComponent::ComponentAllocatePorts(void) |
| 40 | { |
| 41 | OMX_ERRORTYPE ret = OMX_ErrorUndefined; |
| 42 | |
| 43 | LOGV("%s(): enter\n", __func__); |
| 44 | |
| 45 | if (!strcmp(GetWorkingRole(), "audio_decoder.mp3")) |
| 46 | ret = __AllocateMp3RolePorts(false); |
| 47 | |
| 48 | LOGV("%s(): exit (ret = 0x%08x)\n", __func__, ret); |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | OMX_ERRORTYPE MrstSstComponent::__AllocateMp3RolePorts(bool isencoder) |
| 54 | { |
| 55 | PortBase **ports; |
| 56 | |
| 57 | OMX_U32 mp3_port_index, pcm_port_index; |
| 58 | OMX_DIRTYPE mp3_port_dir, pcm_port_dir; |
| 59 | |
| 60 | OMX_PORT_PARAM_TYPE portparam; |
| 61 | OMX_U32 i; |
| 62 | OMX_ERRORTYPE ret; |
| 63 | |
| 64 | LOGV("%s(): enter\n", __func__); |
| 65 | |
| 66 | ports = new PortBase *[NR_PORTS]; |
| 67 | if (!ports) |
| 68 | return OMX_ErrorInsufficientResources; |
| 69 | this->nr_ports = NR_PORTS; |
| 70 | this->ports = ports; |
| 71 | |
| 72 | if (isencoder) { |
| 73 | pcm_port_index = INPORT_INDEX; |
| 74 | mp3_port_index = OUTPORT_INDEX; |
| 75 | pcm_port_dir = OMX_DirInput; |
| 76 | mp3_port_dir = OMX_DirOutput; |
| 77 | } |
| 78 | else { |
| 79 | mp3_port_index = INPORT_INDEX; |
| 80 | pcm_port_index = OUTPORT_INDEX; |
| 81 | mp3_port_dir = OMX_DirInput; |
| 82 | pcm_port_dir = OMX_DirOutput; |
| 83 | } |
| 84 | |
| 85 | ret = __AllocateMp3Port(mp3_port_index, mp3_port_dir); |
| 86 | if (ret != OMX_ErrorNone) |
| 87 | goto free_ports; |
| 88 | |
| 89 | ret = __AllocatePcmPort(pcm_port_index, pcm_port_dir); |
| 90 | if (ret != OMX_ErrorNone) |
| 91 | goto free_mp3port; |
| 92 | |
| 93 | /* OMX_PORT_PARAM_TYPE */ |
| 94 | memset(&portparam, 0, sizeof(portparam)); |
| 95 | SetTypeHeader(&portparam, sizeof(portparam)); |
| 96 | portparam.nPorts = NR_PORTS; |
| 97 | portparam.nStartPortNumber = INPORT_INDEX; |
| 98 | |
| 99 | memcpy(&this->portparam, &portparam, sizeof(portparam)); |
| 100 | /* end of OMX_PORT_PARAM_TYPE */ |
| 101 | |
| 102 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 103 | return OMX_ErrorNone; |
| 104 | |
| 105 | free_mp3port: |
| 106 | delete ports[mp3_port_index]; |
| 107 | |
| 108 | free_ports: |
| 109 | delete []ports; |
| 110 | |
| 111 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | OMX_ERRORTYPE MrstSstComponent::__AllocateMp3Port(OMX_U32 port_index, |
| 116 | OMX_DIRTYPE dir) |
| 117 | { |
| 118 | PortMp3 *mp3port; |
| 119 | |
| 120 | OMX_PARAM_PORTDEFINITIONTYPE mp3portdefinition; |
| 121 | OMX_AUDIO_PARAM_MP3TYPE mp3portparam; |
| 122 | OMX_U32 i; |
| 123 | |
| 124 | LOGV("%s(): enter\n", __func__); |
| 125 | |
| 126 | ports[port_index] = new PortMp3; |
| 127 | if (!ports[port_index]) { |
| 128 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 129 | OMX_ErrorInsufficientResources); |
| 130 | return OMX_ErrorInsufficientResources; |
| 131 | } |
| 132 | |
| 133 | mp3port = static_cast<PortMp3 *>(this->ports[port_index]); |
| 134 | |
| 135 | /* MP3 - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 136 | memset(&mp3portdefinition, 0, sizeof(mp3portdefinition)); |
| 137 | SetTypeHeader(&mp3portdefinition, sizeof(mp3portdefinition)); |
| 138 | mp3portdefinition.nPortIndex = port_index; |
| 139 | mp3portdefinition.eDir = dir; |
| 140 | if (dir == OMX_DirInput) { |
| 141 | mp3portdefinition.nBufferCountActual = INPORT_MP3_ACTUAL_BUFFER_COUNT; |
| 142 | mp3portdefinition.nBufferCountMin = INPORT_MP3_MIN_BUFFER_COUNT; |
| 143 | mp3portdefinition.nBufferSize = INPORT_MP3_BUFFER_SIZE; |
| 144 | } |
| 145 | else { |
| 146 | mp3portdefinition.nBufferCountActual = OUTPORT_MP3_ACTUAL_BUFFER_COUNT; |
| 147 | mp3portdefinition.nBufferCountMin = OUTPORT_MP3_MIN_BUFFER_COUNT; |
| 148 | mp3portdefinition.nBufferSize = OUTPORT_MP3_BUFFER_SIZE; |
| 149 | } |
| 150 | mp3portdefinition.bEnabled = OMX_TRUE; |
| 151 | mp3portdefinition.bPopulated = OMX_FALSE; |
| 152 | mp3portdefinition.eDomain = OMX_PortDomainAudio; |
| 153 | mp3portdefinition.format.audio.cMIMEType = "audio/mpeg"; |
| 154 | mp3portdefinition.format.audio.pNativeRender = NULL; |
| 155 | mp3portdefinition.format.audio.bFlagErrorConcealment = OMX_FALSE; |
| 156 | mp3portdefinition.format.audio.eEncoding = OMX_AUDIO_CodingMP3; |
| 157 | mp3portdefinition.bBuffersContiguous = OMX_FALSE; |
| 158 | mp3portdefinition.nBufferAlignment = 0; |
| 159 | |
| 160 | mp3port->SetPortDefinition(&mp3portdefinition, true); |
| 161 | |
| 162 | /* end of MP3 - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 163 | |
| 164 | /* OMX_AUDIO_PARAM_MP3TYPE */ |
| 165 | memset(&mp3portparam, 0, sizeof(mp3portparam)); |
| 166 | SetTypeHeader(&mp3portparam, sizeof(mp3portparam)); |
| 167 | mp3portparam.nPortIndex = port_index; |
| 168 | mp3portparam.nChannels = 2; |
| 169 | mp3portparam.nBitRate = 0; |
| 170 | mp3portparam.nSampleRate = 0; |
| 171 | mp3portparam.nAudioBandWidth = 0; |
| 172 | mp3portparam.eChannelMode = OMX_AUDIO_ChannelModeStereo; |
| 173 | mp3portparam.eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3; |
| 174 | |
| 175 | mp3port->SetPortMp3Param(&mp3portparam, true); |
| 176 | /* end of OMX_AUDIO_PARAM_MP3TYPE */ |
| 177 | |
| 178 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 179 | return OMX_ErrorNone; |
| 180 | } |
| 181 | |
| 182 | OMX_ERRORTYPE MrstSstComponent::__AllocatePcmPort(OMX_U32 port_index, |
| 183 | OMX_DIRTYPE dir) |
| 184 | { |
| 185 | PortPcm *pcmport; |
| 186 | |
| 187 | OMX_PARAM_PORTDEFINITIONTYPE pcmportdefinition; |
| 188 | OMX_AUDIO_PARAM_PCMMODETYPE pcmportparam; |
| 189 | OMX_U32 i; |
| 190 | |
| 191 | LOGV("%s(): enter\n", __func__); |
| 192 | |
| 193 | ports[port_index] = new PortPcm; |
| 194 | if (!ports[port_index]) { |
| 195 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 196 | OMX_ErrorInsufficientResources); |
| 197 | return OMX_ErrorInsufficientResources; |
| 198 | } |
| 199 | pcmport = static_cast<PortPcm *>(this->ports[port_index]); |
| 200 | |
| 201 | /* PCM - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 202 | memset(&pcmportdefinition, 0, sizeof(pcmportdefinition)); |
| 203 | SetTypeHeader(&pcmportdefinition, sizeof(pcmportdefinition)); |
| 204 | pcmportdefinition.nPortIndex = port_index; |
| 205 | pcmportdefinition.eDir = dir; |
| 206 | if (dir == OMX_DirInput) { |
| 207 | pcmportdefinition.nBufferCountActual = INPORT_PCM_ACTUAL_BUFFER_COUNT; |
| 208 | pcmportdefinition.nBufferCountMin = INPORT_PCM_MIN_BUFFER_COUNT; |
| 209 | pcmportdefinition.nBufferSize = INPORT_PCM_BUFFER_SIZE; |
| 210 | } |
| 211 | else { |
| 212 | pcmportdefinition.nBufferCountActual = OUTPORT_PCM_ACTUAL_BUFFER_COUNT; |
| 213 | pcmportdefinition.nBufferCountMin = OUTPORT_PCM_MIN_BUFFER_COUNT; |
| 214 | pcmportdefinition.nBufferSize = OUTPORT_PCM_BUFFER_SIZE; |
| 215 | } |
| 216 | pcmportdefinition.bEnabled = OMX_TRUE; |
| 217 | pcmportdefinition.bPopulated = OMX_FALSE; |
| 218 | pcmportdefinition.eDomain = OMX_PortDomainAudio; |
| 219 | pcmportdefinition.format.audio.cMIMEType = "raw"; |
| 220 | pcmportdefinition.format.audio.pNativeRender = NULL; |
| 221 | pcmportdefinition.format.audio.bFlagErrorConcealment = OMX_FALSE; |
| 222 | pcmportdefinition.format.audio.eEncoding = OMX_AUDIO_CodingPCM; |
| 223 | pcmportdefinition.bBuffersContiguous = OMX_FALSE; |
| 224 | pcmportdefinition.nBufferAlignment = 0; |
| 225 | |
| 226 | pcmport->SetPortDefinition(&pcmportdefinition, true); |
| 227 | /* end of PCM - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 228 | |
| 229 | /* OMX_AUDIO_PARAM_PCMMODETYPE */ |
| 230 | memset(&pcmportparam, 0, sizeof(pcmportparam)); |
| 231 | SetTypeHeader(&pcmportparam, sizeof(pcmportparam)); |
| 232 | pcmportparam.nPortIndex = port_index; |
| 233 | pcmportparam.nChannels = 2; |
| 234 | pcmportparam.eNumData = OMX_NumericalDataUnsigned; |
| 235 | pcmportparam.eEndian = OMX_EndianLittle; |
| 236 | pcmportparam.bInterleaved = OMX_FALSE; |
| 237 | pcmportparam.nBitPerSample = 16; |
| 238 | pcmportparam.nSamplingRate = 44100; |
| 239 | pcmportparam.ePCMMode = OMX_AUDIO_PCMModeLinear; |
| 240 | pcmportparam.eChannelMapping[0] = OMX_AUDIO_ChannelLF; |
| 241 | pcmportparam.eChannelMapping[1] = OMX_AUDIO_ChannelRF; |
| 242 | |
| 243 | pcmport->SetPortPcmParam(&pcmportparam, true); |
| 244 | /* end of OMX_AUDIO_PARAM_PCMMODETYPE */ |
| 245 | |
| 246 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 247 | return OMX_ErrorNone; |
| 248 | } |
| 249 | |
| 250 | /* end of core methods & helpers */ |
| 251 | |
| 252 | /* |
| 253 | * component methods & helpers |
| 254 | */ |
| 255 | /* Get/SetParameter */ |
| 256 | OMX_ERRORTYPE MrstSstComponent::ComponentGetParameter( |
| 257 | OMX_INDEXTYPE nParamIndex, |
| 258 | OMX_PTR pComponentParameterStructure) |
| 259 | { |
| 260 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 261 | |
| 262 | LOGV("%s(): enter (index = 0x%08x)\n", __func__, nParamIndex); |
| 263 | |
| 264 | switch (nParamIndex) { |
| 265 | case OMX_IndexParamAudioPortFormat: { |
| 266 | OMX_AUDIO_PARAM_PORTFORMATTYPE *p = |
| 267 | (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; |
| 268 | OMX_U32 index = p->nPortIndex; |
| 269 | PortAudio *port = NULL; |
| 270 | |
| 271 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 272 | if (ret != OMX_ErrorNone) { |
| 273 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 274 | return ret; |
| 275 | } |
| 276 | |
| 277 | if (index < nr_ports) |
| 278 | port = static_cast<PortAudio *>(ports[index]); |
| 279 | |
| 280 | if (!port) { |
| 281 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 282 | OMX_ErrorBadPortIndex); |
| 283 | return OMX_ErrorBadPortIndex; |
| 284 | } |
| 285 | |
| 286 | memcpy(p, port->GetPortAudioParam(), sizeof(*p)); |
| 287 | break; |
| 288 | } |
| 289 | case OMX_IndexParamAudioPcm: { |
| 290 | OMX_AUDIO_PARAM_PCMMODETYPE *p = |
| 291 | (OMX_AUDIO_PARAM_PCMMODETYPE *)pComponentParameterStructure; |
| 292 | OMX_U32 index = p->nPortIndex; |
| 293 | PortPcm *port = NULL; |
| 294 | |
| 295 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3")) { |
| 296 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 297 | OMX_ErrorUnsupportedIndex); |
| 298 | return OMX_ErrorUnsupportedIndex; |
| 299 | } |
| 300 | |
| 301 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 302 | if (ret != OMX_ErrorNone) { |
| 303 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | if (index < nr_ports) |
| 308 | port = static_cast<PortPcm *>(ports[index]); |
| 309 | |
| 310 | if (!port) { |
| 311 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 312 | OMX_ErrorBadPortIndex); |
| 313 | return OMX_ErrorBadPortIndex; |
| 314 | } |
| 315 | |
| 316 | memcpy(p, port->GetPortPcmParam(), sizeof(*p)); |
| 317 | break; |
| 318 | } |
| 319 | case OMX_IndexParamAudioMp3: { |
| 320 | OMX_AUDIO_PARAM_MP3TYPE *p = |
| 321 | (OMX_AUDIO_PARAM_MP3TYPE *)pComponentParameterStructure; |
| 322 | OMX_U32 index = p->nPortIndex; |
| 323 | PortMp3 *port = NULL; |
| 324 | |
| 325 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3")) { |
| 326 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 327 | OMX_ErrorUnsupportedIndex); |
| 328 | return OMX_ErrorUnsupportedIndex; |
| 329 | } |
| 330 | |
| 331 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 332 | if (ret != OMX_ErrorNone) { |
| 333 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 334 | return ret; |
| 335 | } |
| 336 | |
| 337 | if (index < nr_ports) |
| 338 | port = static_cast<PortMp3 *>(ports[index]); |
| 339 | |
| 340 | if (!port) { |
| 341 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 342 | OMX_ErrorBadPortIndex); |
| 343 | return OMX_ErrorBadPortIndex; |
| 344 | } |
| 345 | |
| 346 | memcpy(p, port->GetPortMp3Param(), sizeof(*p)); |
| 347 | break; |
| 348 | } |
| 349 | default: |
| 350 | ret = OMX_ErrorUnsupportedIndex; |
| 351 | } /* switch */ |
| 352 | |
| 353 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 354 | return ret; |
| 355 | } |
| 356 | |
| 357 | OMX_ERRORTYPE MrstSstComponent::ComponentSetParameter( |
| 358 | OMX_INDEXTYPE nIndex, |
| 359 | OMX_PTR pComponentParameterStructure) |
| 360 | { |
| 361 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 362 | |
| 363 | LOGV("%s(): enter (index = 0x%08x)\n", __func__, nIndex); |
| 364 | |
| 365 | switch (nIndex) { |
| 366 | case OMX_IndexParamAudioPortFormat: { |
| 367 | OMX_AUDIO_PARAM_PORTFORMATTYPE *p = |
| 368 | (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; |
| 369 | OMX_U32 index = p->nPortIndex; |
| 370 | PortAudio *port = NULL; |
| 371 | |
| 372 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 373 | if (ret != OMX_ErrorNone) { |
| 374 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 375 | return ret; |
| 376 | } |
| 377 | |
| 378 | if (index < nr_ports) |
| 379 | port = static_cast<PortPcm *>(ports[index]); |
| 380 | |
| 381 | if (!port) { |
| 382 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 383 | OMX_ErrorBadPortIndex); |
| 384 | return OMX_ErrorBadPortIndex; |
| 385 | } |
| 386 | |
| 387 | if (port->IsEnabled()) { |
| 388 | OMX_STATETYPE state; |
| 389 | |
| 390 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 391 | if (state != OMX_StateLoaded && |
| 392 | state != OMX_StateWaitForResources) { |
| 393 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 394 | OMX_ErrorIncorrectStateOperation); |
| 395 | return OMX_ErrorIncorrectStateOperation; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | ret = port->SetPortAudioParam(p, false); |
| 400 | break; |
| 401 | } |
| 402 | case OMX_IndexParamAudioPcm: { |
| 403 | OMX_AUDIO_PARAM_PCMMODETYPE *p = |
| 404 | (OMX_AUDIO_PARAM_PCMMODETYPE *)pComponentParameterStructure; |
| 405 | OMX_U32 index = p->nPortIndex; |
| 406 | PortPcm *port = NULL; |
| 407 | |
| 408 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3")) { |
| 409 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 410 | OMX_ErrorUnsupportedIndex); |
| 411 | return OMX_ErrorUnsupportedIndex; |
| 412 | } |
| 413 | |
| 414 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 415 | if (ret != OMX_ErrorNone) { |
| 416 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 417 | return ret; |
| 418 | } |
| 419 | |
| 420 | if (index < nr_ports) |
| 421 | port = static_cast<PortPcm *>(ports[index]); |
| 422 | |
| 423 | if (!port) { |
| 424 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 425 | OMX_ErrorBadPortIndex); |
| 426 | return OMX_ErrorBadPortIndex; |
| 427 | } |
| 428 | |
| 429 | if (port->IsEnabled()) { |
| 430 | OMX_STATETYPE state; |
| 431 | |
| 432 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 433 | if (state != OMX_StateLoaded && |
| 434 | state != OMX_StateWaitForResources) { |
| 435 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 436 | OMX_ErrorIncorrectStateOperation); |
| 437 | return OMX_ErrorIncorrectStateOperation; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | ret = port->SetPortPcmParam(p, false); |
| 442 | break; |
| 443 | } |
| 444 | case OMX_IndexParamAudioMp3: { |
| 445 | OMX_AUDIO_PARAM_MP3TYPE *p = |
| 446 | (OMX_AUDIO_PARAM_MP3TYPE *)pComponentParameterStructure; |
| 447 | OMX_U32 index = p->nPortIndex; |
| 448 | PortMp3 *port = NULL; |
| 449 | |
| 450 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3")) { |
| 451 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 452 | OMX_ErrorUnsupportedIndex); |
| 453 | return OMX_ErrorUnsupportedIndex; |
| 454 | } |
| 455 | |
| 456 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 457 | if (ret != OMX_ErrorNone) { |
| 458 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 459 | return ret; |
| 460 | } |
| 461 | |
| 462 | if (index < nr_ports) |
| 463 | port = static_cast<PortMp3 *>(ports[index]); |
| 464 | |
| 465 | if (!port) { |
| 466 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 467 | OMX_ErrorBadPortIndex); |
| 468 | return OMX_ErrorBadPortIndex; |
| 469 | } |
| 470 | |
| 471 | if (port->IsEnabled()) { |
| 472 | OMX_STATETYPE state; |
| 473 | |
| 474 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 475 | if (state != OMX_StateLoaded && |
| 476 | state != OMX_StateWaitForResources) { |
| 477 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 478 | OMX_ErrorIncorrectStateOperation); |
| 479 | return OMX_ErrorIncorrectStateOperation; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | ret = port->SetPortMp3Param(p, false); |
| 484 | break; |
| 485 | } |
| 486 | default: |
| 487 | ret = OMX_ErrorUnsupportedIndex; |
| 488 | } /* switch */ |
| 489 | |
| 490 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | /* Get/SetConfig */ |
| 495 | OMX_ERRORTYPE MrstSstComponent::ComponentGetConfig( |
| 496 | OMX_INDEXTYPE nIndex, |
| 497 | OMX_PTR pComponentConfigStructure) |
| 498 | { |
| 499 | OMX_ERRORTYPE ret = OMX_ErrorUnsupportedIndex; |
| 500 | LOGV("%s(): enter\n", __func__); |
| 501 | |
| 502 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | OMX_ERRORTYPE MrstSstComponent::ComponentSetConfig( |
| 507 | OMX_INDEXTYPE nParamIndex, |
| 508 | OMX_PTR pComponentConfigStructure) |
| 509 | { |
| 510 | OMX_ERRORTYPE ret = OMX_ErrorUnsupportedIndex; |
| 511 | LOGV("%s(): enter\n", __func__); |
| 512 | |
| 513 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | /* implement ComponentBase::Processor[*] */ |
| 518 | OMX_ERRORTYPE MrstSstComponent::ProcessorInit(void) |
| 519 | { |
| 520 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 521 | LOGV("%s(): enter\n", __func__); |
| 522 | |
| 523 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | OMX_ERRORTYPE MrstSstComponent::ProcessorDeinit(void) |
| 528 | { |
| 529 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 530 | LOGV("%s(): enter\n", __func__); |
| 531 | |
| 532 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | OMX_ERRORTYPE MrstSstComponent::ProcessorStart(void) |
| 537 | { |
| 538 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 539 | LOGV("%s(): enter\n", __func__); |
| 540 | |
| 541 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | OMX_ERRORTYPE MrstSstComponent::ProcessorStop(void) |
| 546 | { |
| 547 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 548 | LOGV("%s(): enter\n", __func__); |
| 549 | |
| 550 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 551 | return ret; |
| 552 | } |
| 553 | |
| 554 | OMX_ERRORTYPE MrstSstComponent::ProcessorPause(void) |
| 555 | { |
| 556 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 557 | LOGV("%s(): enter\n", __func__); |
| 558 | |
| 559 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | OMX_ERRORTYPE MrstSstComponent::ProcessorResume(void) |
| 564 | { |
| 565 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 566 | LOGV("%s(): enter\n", __func__); |
| 567 | |
| 568 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 569 | return ret; |
| 570 | } |
| 571 | |
| 572 | /* implement ComponentBase::ProcessorProcess */ |
| 573 | void MrstSstComponent::ProcessorProcess( |
| 574 | OMX_BUFFERHEADERTYPE **buffers, |
| 575 | bool *retain, |
| 576 | OMX_U32 nr_buffers) |
| 577 | { |
| 578 | LOGV("%s(): enter\n", __func__); |
| 579 | |
| 580 | /* dummy processing */ |
| 581 | buffers[OUTPORT_INDEX]->nFilledLen = buffers[OUTPORT_INDEX]->nAllocLen; |
| 582 | buffers[OUTPORT_INDEX]->nTimeStamp = buffers[INPORT_INDEX]->nTimeStamp; |
| 583 | |
| 584 | buffers[INPORT_INDEX]->nFilledLen = 0; |
| 585 | |
| 586 | LOGV("%s(),%d: exit (ret = void)\n", __func__, __LINE__); |
| 587 | } |
| 588 | |
| 589 | /* end of implement ComponentBase::Processor[*] */ |
| 590 | |
| 591 | /* end of component methods & helpers */ |
| 592 | |
| 593 | /* |
| 594 | * CModule Interface |
| 595 | */ |
| 596 | static const OMX_STRING g_roles[] = |
| 597 | { |
| 598 | "audio_decoder.mp3", |
| 599 | }; |
| 600 | |
| 601 | static const OMX_STRING g_compname = "OMX.Intel.MrstSST"; |
| 602 | |
| 603 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 604 | |
| 605 | OMX_ERRORTYPE omx_component_module_instantiate(OMX_PTR *instance) |
| 606 | { |
| 607 | ComponentBase *cbase; |
| 608 | |
| 609 | cbase = new MrstSstComponent; |
| 610 | if (!cbase) { |
| 611 | *instance = NULL; |
| 612 | return OMX_ErrorInsufficientResources; |
| 613 | } |
| 614 | |
| 615 | *instance = cbase; |
| 616 | return OMX_ErrorNone; |
| 617 | } |
| 618 | |
| 619 | OMX_ERRORTYPE omx_component_module_query_name(OMX_STRING name, OMX_U32 len) |
| 620 | { |
| 621 | if (!name) |
| 622 | return OMX_ErrorBadParameter; |
| 623 | |
| 624 | strncpy(name, g_compname, len); |
| 625 | return OMX_ErrorNone; |
| 626 | } |
| 627 | |
| 628 | OMX_ERRORTYPE omx_component_module_query_roles(OMX_U32 *nr_roles, |
| 629 | OMX_U8 **roles) |
| 630 | { |
| 631 | return ComponentBase::QueryRolesHelper(ARRAY_SIZE(g_roles), |
| 632 | (const OMX_U8 **)g_roles, |
| 633 | nr_roles, roles); |
| 634 | } |