| Ho-Eun Ryu | 0592b1b | 2009-10-16 15:26:16 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Wind River Systems |
| 3 | * Author: Keun-O Park <keun-o.park@windriver.com> |
| 4 | * Ho-Eun Ryu <ho-eun.ryu@windriver.com> |
| 5 | * Min-Su Kim <min-su.kim@windriver.com> |
| 6 | */ |
| 7 | |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | #include <unistd.h> |
| 12 | |
| 13 | #include <OMX_Core.h> |
| 14 | |
| 15 | #include <cmodule.h> |
| 16 | #include <portaudio.h> |
| 17 | #include <componentbase.h> |
| 18 | |
| 19 | #include "sst.h" |
| 20 | |
| 21 | #define LOG_NDEBUG 1 |
| 22 | |
| 23 | #define LOG_TAG "mrst_sst" |
| 24 | #include <log.h> |
| 25 | |
| 26 | /* |
| 27 | * constructor & destructor |
| 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 | MrstSstComponent::~MrstSstComponent() |
| 37 | { |
| 38 | LOGV("%s(): enter\n", __func__); |
| 39 | |
| 40 | LOGV("%s(),%d: exit (ret = void)\n", __func__, __LINE__); |
| 41 | } |
| 42 | |
| 43 | /* end of constructor & destructor */ |
| 44 | |
| 45 | /* core methods & helpers */ |
| 46 | OMX_ERRORTYPE MrstSstComponent::ComponentAllocatePorts(void) |
| 47 | { |
| 48 | OMX_ERRORTYPE ret = OMX_ErrorUndefined; |
| 49 | |
| 50 | LOGV("%s(): enter\n", __func__); |
| 51 | |
| 52 | if (!strcmp(GetWorkingRole(), "audio_decoder.mp3")) |
| 53 | ret = __AllocateMp3RolePorts(false); |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 54 | else if(!strcmp(GetWorkingRole(), "audio_decoder.aac")) |
| 55 | ret = __AllocateAacRolePorts(false); |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 56 | |
| 57 | LOGV("%s(): exit (ret = 0x%08x)\n", __func__, ret); |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | OMX_ERRORTYPE MrstSstComponent::__AllocateMp3RolePorts(bool isencoder) |
| 63 | { |
| 64 | PortBase **ports; |
| 65 | |
| 66 | OMX_U32 mp3_port_index, pcm_port_index; |
| 67 | OMX_DIRTYPE mp3_port_dir, pcm_port_dir; |
| 68 | |
| 69 | OMX_PORT_PARAM_TYPE portparam; |
| 70 | OMX_U32 i; |
| 71 | OMX_ERRORTYPE ret; |
| 72 | |
| 73 | LOGV("%s(): enter\n", __func__); |
| 74 | |
| 75 | ports = new PortBase *[NR_PORTS]; |
| 76 | if (!ports) |
| 77 | return OMX_ErrorInsufficientResources; |
| 78 | this->nr_ports = NR_PORTS; |
| 79 | this->ports = ports; |
| 80 | |
| 81 | if (isencoder) { |
| 82 | pcm_port_index = INPORT_INDEX; |
| 83 | mp3_port_index = OUTPORT_INDEX; |
| 84 | pcm_port_dir = OMX_DirInput; |
| 85 | mp3_port_dir = OMX_DirOutput; |
| 86 | } |
| 87 | else { |
| 88 | mp3_port_index = INPORT_INDEX; |
| 89 | pcm_port_index = OUTPORT_INDEX; |
| 90 | mp3_port_dir = OMX_DirInput; |
| 91 | pcm_port_dir = OMX_DirOutput; |
| 92 | } |
| 93 | |
| 94 | ret = __AllocateMp3Port(mp3_port_index, mp3_port_dir); |
| 95 | if (ret != OMX_ErrorNone) |
| 96 | goto free_ports; |
| 97 | |
| 98 | ret = __AllocatePcmPort(pcm_port_index, pcm_port_dir); |
| 99 | if (ret != OMX_ErrorNone) |
| 100 | goto free_mp3port; |
| 101 | |
| 102 | /* OMX_PORT_PARAM_TYPE */ |
| 103 | memset(&portparam, 0, sizeof(portparam)); |
| 104 | SetTypeHeader(&portparam, sizeof(portparam)); |
| 105 | portparam.nPorts = NR_PORTS; |
| 106 | portparam.nStartPortNumber = INPORT_INDEX; |
| 107 | |
| 108 | memcpy(&this->portparam, &portparam, sizeof(portparam)); |
| 109 | /* end of OMX_PORT_PARAM_TYPE */ |
| 110 | |
| 111 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 112 | return OMX_ErrorNone; |
| 113 | |
| 114 | free_mp3port: |
| 115 | delete ports[mp3_port_index]; |
| 116 | |
| 117 | free_ports: |
| 118 | delete []ports; |
| 119 | |
| 120 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 121 | return ret; |
| 122 | } |
| 123 | |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 124 | |
| 125 | OMX_ERRORTYPE MrstSstComponent::__AllocateAacRolePorts(bool isencoder) |
| 126 | { |
| 127 | PortBase **ports; |
| 128 | |
| 129 | OMX_U32 aac_port_index, pcm_port_index; |
| 130 | OMX_DIRTYPE aac_port_dir, pcm_port_dir; |
| 131 | |
| 132 | OMX_PORT_PARAM_TYPE portparam; |
| 133 | OMX_U32 i; |
| 134 | OMX_ERRORTYPE ret; |
| 135 | |
| 136 | LOGV("%s(): enter\n", __func__); |
| 137 | |
| 138 | ports = new PortBase *[NR_PORTS]; |
| 139 | if (!ports) |
| 140 | return OMX_ErrorInsufficientResources; |
| 141 | this->nr_ports = NR_PORTS; |
| 142 | this->ports = ports; |
| 143 | |
| 144 | if (isencoder) { |
| 145 | pcm_port_index = INPORT_INDEX; |
| 146 | aac_port_index = OUTPORT_INDEX; |
| 147 | pcm_port_dir = OMX_DirInput; |
| 148 | aac_port_dir = OMX_DirOutput; |
| 149 | } |
| 150 | else { |
| 151 | aac_port_index = INPORT_INDEX; |
| 152 | pcm_port_index = OUTPORT_INDEX; |
| 153 | aac_port_dir = OMX_DirInput; |
| 154 | pcm_port_dir = OMX_DirOutput; |
| 155 | } |
| 156 | |
| 157 | ret = __AllocateAacPort(aac_port_index, aac_port_dir); |
| 158 | if (ret != OMX_ErrorNone) |
| 159 | goto free_ports; |
| 160 | |
| 161 | ret = __AllocatePcmPort(pcm_port_index, pcm_port_dir); |
| 162 | if (ret != OMX_ErrorNone) |
| 163 | goto free_aacport; |
| 164 | |
| 165 | /* OMX_PORT_PARAM_TYPE */ |
| 166 | memset(&portparam, 0, sizeof(portparam)); |
| 167 | SetTypeHeader(&portparam, sizeof(portparam)); |
| 168 | portparam.nPorts = NR_PORTS; |
| 169 | portparam.nStartPortNumber = INPORT_INDEX; |
| 170 | |
| 171 | memcpy(&this->portparam, &portparam, sizeof(portparam)); |
| 172 | /* end of OMX_PORT_PARAM_TYPE */ |
| 173 | |
| 174 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 175 | return OMX_ErrorNone; |
| 176 | |
| 177 | free_aacport: |
| 178 | delete ports[aac_port_index]; |
| 179 | |
| 180 | free_ports: |
| 181 | delete []ports; |
| 182 | |
| 183 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 184 | return ret; |
| 185 | } |
| 186 | |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 187 | OMX_ERRORTYPE MrstSstComponent::__AllocateMp3Port(OMX_U32 port_index, |
| 188 | OMX_DIRTYPE dir) |
| 189 | { |
| 190 | PortMp3 *mp3port; |
| 191 | |
| 192 | OMX_PARAM_PORTDEFINITIONTYPE mp3portdefinition; |
| 193 | OMX_AUDIO_PARAM_MP3TYPE mp3portparam; |
| 194 | OMX_U32 i; |
| 195 | |
| 196 | LOGV("%s(): enter\n", __func__); |
| 197 | |
| 198 | ports[port_index] = new PortMp3; |
| 199 | if (!ports[port_index]) { |
| 200 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 201 | OMX_ErrorInsufficientResources); |
| 202 | return OMX_ErrorInsufficientResources; |
| 203 | } |
| 204 | |
| 205 | mp3port = static_cast<PortMp3 *>(this->ports[port_index]); |
| 206 | |
| 207 | /* MP3 - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 208 | memset(&mp3portdefinition, 0, sizeof(mp3portdefinition)); |
| 209 | SetTypeHeader(&mp3portdefinition, sizeof(mp3portdefinition)); |
| 210 | mp3portdefinition.nPortIndex = port_index; |
| 211 | mp3portdefinition.eDir = dir; |
| 212 | if (dir == OMX_DirInput) { |
| 213 | mp3portdefinition.nBufferCountActual = INPORT_MP3_ACTUAL_BUFFER_COUNT; |
| 214 | mp3portdefinition.nBufferCountMin = INPORT_MP3_MIN_BUFFER_COUNT; |
| 215 | mp3portdefinition.nBufferSize = INPORT_MP3_BUFFER_SIZE; |
| 216 | } |
| 217 | else { |
| 218 | mp3portdefinition.nBufferCountActual = OUTPORT_MP3_ACTUAL_BUFFER_COUNT; |
| 219 | mp3portdefinition.nBufferCountMin = OUTPORT_MP3_MIN_BUFFER_COUNT; |
| 220 | mp3portdefinition.nBufferSize = OUTPORT_MP3_BUFFER_SIZE; |
| 221 | } |
| 222 | mp3portdefinition.bEnabled = OMX_TRUE; |
| 223 | mp3portdefinition.bPopulated = OMX_FALSE; |
| 224 | mp3portdefinition.eDomain = OMX_PortDomainAudio; |
| 225 | mp3portdefinition.format.audio.cMIMEType = "audio/mpeg"; |
| 226 | mp3portdefinition.format.audio.pNativeRender = NULL; |
| 227 | mp3portdefinition.format.audio.bFlagErrorConcealment = OMX_FALSE; |
| 228 | mp3portdefinition.format.audio.eEncoding = OMX_AUDIO_CodingMP3; |
| 229 | mp3portdefinition.bBuffersContiguous = OMX_FALSE; |
| 230 | mp3portdefinition.nBufferAlignment = 0; |
| 231 | |
| 232 | mp3port->SetPortDefinition(&mp3portdefinition, true); |
| 233 | |
| 234 | /* end of MP3 - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 235 | |
| 236 | /* OMX_AUDIO_PARAM_MP3TYPE */ |
| 237 | memset(&mp3portparam, 0, sizeof(mp3portparam)); |
| 238 | SetTypeHeader(&mp3portparam, sizeof(mp3portparam)); |
| 239 | mp3portparam.nPortIndex = port_index; |
| 240 | mp3portparam.nChannels = 2; |
| 241 | mp3portparam.nBitRate = 0; |
| 242 | mp3portparam.nSampleRate = 0; |
| 243 | mp3portparam.nAudioBandWidth = 0; |
| 244 | mp3portparam.eChannelMode = OMX_AUDIO_ChannelModeStereo; |
| 245 | mp3portparam.eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3; |
| 246 | |
| 247 | mp3port->SetPortMp3Param(&mp3portparam, true); |
| 248 | /* end of OMX_AUDIO_PARAM_MP3TYPE */ |
| 249 | |
| 250 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 251 | return OMX_ErrorNone; |
| 252 | } |
| 253 | |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 254 | OMX_ERRORTYPE MrstSstComponent::__AllocateAacPort(OMX_U32 port_index, |
| 255 | OMX_DIRTYPE dir) |
| 256 | { |
| 257 | PortAac *aacport; |
| 258 | |
| 259 | OMX_PARAM_PORTDEFINITIONTYPE aacportdefinition; |
| 260 | OMX_AUDIO_PARAM_AACPROFILETYPE aacportparam; |
| 261 | OMX_U32 i; |
| 262 | |
| 263 | LOGV("%s(): enter\n", __func__); |
| 264 | |
| 265 | ports[port_index] = new PortAac; |
| 266 | if (!ports[port_index]) { |
| 267 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 268 | OMX_ErrorInsufficientResources); |
| 269 | return OMX_ErrorInsufficientResources; |
| 270 | } |
| 271 | |
| 272 | aacport = static_cast<PortAac *>(this->ports[port_index]); |
| 273 | |
| 274 | /* AAC - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 275 | memset(&aacportdefinition, 0, sizeof(aacportdefinition)); |
| 276 | SetTypeHeader(&aacportdefinition, sizeof(aacportdefinition)); |
| 277 | aacportdefinition.nPortIndex = port_index; |
| 278 | aacportdefinition.eDir = dir; |
| 279 | if (dir == OMX_DirInput) { |
| 280 | aacportdefinition.nBufferCountActual = INPORT_AAC_ACTUAL_BUFFER_COUNT; |
| 281 | aacportdefinition.nBufferCountMin = INPORT_AAC_MIN_BUFFER_COUNT; |
| 282 | aacportdefinition.nBufferSize = INPORT_AAC_BUFFER_SIZE; |
| 283 | } |
| 284 | else { |
| 285 | aacportdefinition.nBufferCountActual = OUTPORT_AAC_ACTUAL_BUFFER_COUNT; |
| 286 | aacportdefinition.nBufferCountMin = OUTPORT_AAC_MIN_BUFFER_COUNT; |
| 287 | aacportdefinition.nBufferSize = OUTPORT_AAC_BUFFER_SIZE; |
| 288 | } |
| 289 | aacportdefinition.bEnabled = OMX_TRUE; |
| 290 | aacportdefinition.bPopulated = OMX_FALSE; |
| 291 | aacportdefinition.eDomain = OMX_PortDomainAudio; |
| 292 | aacportdefinition.format.audio.cMIMEType = "audio/mpeg"; |
| 293 | aacportdefinition.format.audio.pNativeRender = NULL; |
| 294 | aacportdefinition.format.audio.bFlagErrorConcealment = OMX_FALSE; |
| 295 | aacportdefinition.format.audio.eEncoding = OMX_AUDIO_CodingAAC; |
| 296 | aacportdefinition.bBuffersContiguous = OMX_FALSE; |
| 297 | aacportdefinition.nBufferAlignment = 0; |
| 298 | |
| 299 | aacport->SetPortDefinition(&aacportdefinition, true); |
| 300 | |
| 301 | /* end of AAC - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 302 | |
| 303 | /* OMX_AUDIO_PARAM_AACPROFILETYPE */ |
| 304 | memset(&aacportparam, 0, sizeof(aacportparam)); |
| 305 | SetTypeHeader(&aacportparam, sizeof(aacportparam)); |
| 306 | aacportparam.nPortIndex = port_index; |
| 307 | aacportparam.nChannels = 2; |
| 308 | aacportparam.nBitRate = 0; |
| 309 | aacportparam.nSampleRate = 0; |
| 310 | aacportparam.nAudioBandWidth = 0; |
| 311 | aacportparam.nFrameLength = 1024; /* default for LC */ |
| 312 | aacportparam.nAACtools = OMX_AUDIO_AACToolNone; |
| 313 | aacportparam.nAACERtools = OMX_AUDIO_AACERNone; |
| 314 | aacportparam.eAACProfile = OMX_AUDIO_AACObjectLC; |
| 315 | aacportparam.eChannelMode = OMX_AUDIO_ChannelModeStereo; |
| 316 | |
| 317 | aacport->SetPortAacParam(&aacportparam, true); |
| 318 | /* end of OMX_AUDIO_PARAM_AACPROFILETYPE */ |
| 319 | |
| 320 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 321 | return OMX_ErrorNone; |
| 322 | } |
| 323 | |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 324 | OMX_ERRORTYPE MrstSstComponent::__AllocatePcmPort(OMX_U32 port_index, |
| 325 | OMX_DIRTYPE dir) |
| 326 | { |
| 327 | PortPcm *pcmport; |
| 328 | |
| 329 | OMX_PARAM_PORTDEFINITIONTYPE pcmportdefinition; |
| 330 | OMX_AUDIO_PARAM_PCMMODETYPE pcmportparam; |
| 331 | OMX_U32 i; |
| 332 | |
| 333 | LOGV("%s(): enter\n", __func__); |
| 334 | |
| 335 | ports[port_index] = new PortPcm; |
| 336 | if (!ports[port_index]) { |
| 337 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 338 | OMX_ErrorInsufficientResources); |
| 339 | return OMX_ErrorInsufficientResources; |
| 340 | } |
| 341 | pcmport = static_cast<PortPcm *>(this->ports[port_index]); |
| 342 | |
| 343 | /* PCM - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 344 | memset(&pcmportdefinition, 0, sizeof(pcmportdefinition)); |
| 345 | SetTypeHeader(&pcmportdefinition, sizeof(pcmportdefinition)); |
| 346 | pcmportdefinition.nPortIndex = port_index; |
| 347 | pcmportdefinition.eDir = dir; |
| 348 | if (dir == OMX_DirInput) { |
| 349 | pcmportdefinition.nBufferCountActual = INPORT_PCM_ACTUAL_BUFFER_COUNT; |
| 350 | pcmportdefinition.nBufferCountMin = INPORT_PCM_MIN_BUFFER_COUNT; |
| 351 | pcmportdefinition.nBufferSize = INPORT_PCM_BUFFER_SIZE; |
| 352 | } |
| 353 | else { |
| 354 | pcmportdefinition.nBufferCountActual = OUTPORT_PCM_ACTUAL_BUFFER_COUNT; |
| 355 | pcmportdefinition.nBufferCountMin = OUTPORT_PCM_MIN_BUFFER_COUNT; |
| 356 | pcmportdefinition.nBufferSize = OUTPORT_PCM_BUFFER_SIZE; |
| 357 | } |
| 358 | pcmportdefinition.bEnabled = OMX_TRUE; |
| 359 | pcmportdefinition.bPopulated = OMX_FALSE; |
| 360 | pcmportdefinition.eDomain = OMX_PortDomainAudio; |
| 361 | pcmportdefinition.format.audio.cMIMEType = "raw"; |
| 362 | pcmportdefinition.format.audio.pNativeRender = NULL; |
| 363 | pcmportdefinition.format.audio.bFlagErrorConcealment = OMX_FALSE; |
| 364 | pcmportdefinition.format.audio.eEncoding = OMX_AUDIO_CodingPCM; |
| 365 | pcmportdefinition.bBuffersContiguous = OMX_FALSE; |
| 366 | pcmportdefinition.nBufferAlignment = 0; |
| 367 | |
| 368 | pcmport->SetPortDefinition(&pcmportdefinition, true); |
| 369 | /* end of PCM - OMX_PARAM_PORTDEFINITIONTYPE */ |
| 370 | |
| 371 | /* OMX_AUDIO_PARAM_PCMMODETYPE */ |
| 372 | memset(&pcmportparam, 0, sizeof(pcmportparam)); |
| 373 | SetTypeHeader(&pcmportparam, sizeof(pcmportparam)); |
| 374 | pcmportparam.nPortIndex = port_index; |
| 375 | pcmportparam.nChannels = 2; |
| 376 | pcmportparam.eNumData = OMX_NumericalDataUnsigned; |
| 377 | pcmportparam.eEndian = OMX_EndianLittle; |
| 378 | pcmportparam.bInterleaved = OMX_FALSE; |
| 379 | pcmportparam.nBitPerSample = 16; |
| 380 | pcmportparam.nSamplingRate = 44100; |
| 381 | pcmportparam.ePCMMode = OMX_AUDIO_PCMModeLinear; |
| 382 | pcmportparam.eChannelMapping[0] = OMX_AUDIO_ChannelLF; |
| 383 | pcmportparam.eChannelMapping[1] = OMX_AUDIO_ChannelRF; |
| 384 | |
| 385 | pcmport->SetPortPcmParam(&pcmportparam, true); |
| 386 | /* end of OMX_AUDIO_PARAM_PCMMODETYPE */ |
| 387 | |
| 388 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, OMX_ErrorNone); |
| 389 | return OMX_ErrorNone; |
| 390 | } |
| 391 | |
| 392 | /* end of core methods & helpers */ |
| 393 | |
| 394 | /* |
| 395 | * component methods & helpers |
| 396 | */ |
| 397 | /* Get/SetParameter */ |
| 398 | OMX_ERRORTYPE MrstSstComponent::ComponentGetParameter( |
| 399 | OMX_INDEXTYPE nParamIndex, |
| 400 | OMX_PTR pComponentParameterStructure) |
| 401 | { |
| 402 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 403 | |
| 404 | LOGV("%s(): enter (index = 0x%08x)\n", __func__, nParamIndex); |
| 405 | |
| 406 | switch (nParamIndex) { |
| 407 | case OMX_IndexParamAudioPortFormat: { |
| 408 | OMX_AUDIO_PARAM_PORTFORMATTYPE *p = |
| 409 | (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; |
| 410 | OMX_U32 index = p->nPortIndex; |
| 411 | PortAudio *port = NULL; |
| 412 | |
| 413 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 414 | if (ret != OMX_ErrorNone) { |
| 415 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | if (index < nr_ports) |
| 420 | port = static_cast<PortAudio *>(ports[index]); |
| 421 | |
| 422 | if (!port) { |
| 423 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 424 | OMX_ErrorBadPortIndex); |
| 425 | return OMX_ErrorBadPortIndex; |
| 426 | } |
| 427 | |
| 428 | memcpy(p, port->GetPortAudioParam(), sizeof(*p)); |
| 429 | break; |
| 430 | } |
| 431 | case OMX_IndexParamAudioPcm: { |
| 432 | OMX_AUDIO_PARAM_PCMMODETYPE *p = |
| 433 | (OMX_AUDIO_PARAM_PCMMODETYPE *)pComponentParameterStructure; |
| 434 | OMX_U32 index = p->nPortIndex; |
| 435 | PortPcm *port = NULL; |
| 436 | |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 437 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3") && |
| 438 | strcmp(GetWorkingRole(), "audio_decoder.aac")) { |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 439 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 440 | OMX_ErrorUnsupportedIndex); |
| 441 | return OMX_ErrorUnsupportedIndex; |
| 442 | } |
| 443 | |
| 444 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 445 | if (ret != OMX_ErrorNone) { |
| 446 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | if (index < nr_ports) |
| 451 | port = static_cast<PortPcm *>(ports[index]); |
| 452 | |
| 453 | if (!port) { |
| 454 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 455 | OMX_ErrorBadPortIndex); |
| 456 | return OMX_ErrorBadPortIndex; |
| 457 | } |
| 458 | |
| 459 | memcpy(p, port->GetPortPcmParam(), sizeof(*p)); |
| 460 | break; |
| 461 | } |
| 462 | case OMX_IndexParamAudioMp3: { |
| 463 | OMX_AUDIO_PARAM_MP3TYPE *p = |
| 464 | (OMX_AUDIO_PARAM_MP3TYPE *)pComponentParameterStructure; |
| 465 | OMX_U32 index = p->nPortIndex; |
| 466 | PortMp3 *port = NULL; |
| 467 | |
| 468 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3")) { |
| 469 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 470 | OMX_ErrorUnsupportedIndex); |
| 471 | return OMX_ErrorUnsupportedIndex; |
| 472 | } |
| 473 | |
| 474 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 475 | if (ret != OMX_ErrorNone) { |
| 476 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | if (index < nr_ports) |
| 481 | port = static_cast<PortMp3 *>(ports[index]); |
| 482 | |
| 483 | if (!port) { |
| 484 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 485 | OMX_ErrorBadPortIndex); |
| 486 | return OMX_ErrorBadPortIndex; |
| 487 | } |
| 488 | |
| 489 | memcpy(p, port->GetPortMp3Param(), sizeof(*p)); |
| 490 | break; |
| 491 | } |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 492 | case OMX_IndexParamAudioAac: { |
| 493 | OMX_AUDIO_PARAM_AACPROFILETYPE *p = |
| 494 | (OMX_AUDIO_PARAM_AACPROFILETYPE *)pComponentParameterStructure; |
| 495 | OMX_U32 index = p->nPortIndex; |
| 496 | PortAac *port = NULL; |
| 497 | |
| 498 | if (strcmp(GetWorkingRole(), "audio_decoder.aac")) { |
| 499 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 500 | OMX_ErrorUnsupportedIndex); |
| 501 | return OMX_ErrorUnsupportedIndex; |
| 502 | } |
| 503 | |
| 504 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 505 | if (ret != OMX_ErrorNone) { |
| 506 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 507 | return ret; |
| 508 | } |
| 509 | |
| 510 | if (index < nr_ports) |
| 511 | port = static_cast<PortAac *>(ports[index]); |
| 512 | |
| 513 | if (!port) { |
| 514 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 515 | OMX_ErrorBadPortIndex); |
| 516 | return OMX_ErrorBadPortIndex; |
| 517 | } |
| 518 | |
| 519 | memcpy(p, port->GetPortAacParam(), sizeof(*p)); |
| 520 | break; |
| 521 | } |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 522 | default: |
| 523 | ret = OMX_ErrorUnsupportedIndex; |
| 524 | } /* switch */ |
| 525 | |
| 526 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 527 | return ret; |
| 528 | } |
| 529 | |
| 530 | OMX_ERRORTYPE MrstSstComponent::ComponentSetParameter( |
| 531 | OMX_INDEXTYPE nIndex, |
| 532 | OMX_PTR pComponentParameterStructure) |
| 533 | { |
| 534 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 535 | |
| 536 | LOGV("%s(): enter (index = 0x%08x)\n", __func__, nIndex); |
| 537 | |
| 538 | switch (nIndex) { |
| 539 | case OMX_IndexParamAudioPortFormat: { |
| 540 | OMX_AUDIO_PARAM_PORTFORMATTYPE *p = |
| 541 | (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pComponentParameterStructure; |
| 542 | OMX_U32 index = p->nPortIndex; |
| 543 | PortAudio *port = NULL; |
| 544 | |
| 545 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 546 | if (ret != OMX_ErrorNone) { |
| 547 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | if (index < nr_ports) |
| 552 | port = static_cast<PortPcm *>(ports[index]); |
| 553 | |
| 554 | if (!port) { |
| 555 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 556 | OMX_ErrorBadPortIndex); |
| 557 | return OMX_ErrorBadPortIndex; |
| 558 | } |
| 559 | |
| 560 | if (port->IsEnabled()) { |
| 561 | OMX_STATETYPE state; |
| 562 | |
| 563 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 564 | if (state != OMX_StateLoaded && |
| 565 | state != OMX_StateWaitForResources) { |
| 566 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 567 | OMX_ErrorIncorrectStateOperation); |
| 568 | return OMX_ErrorIncorrectStateOperation; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | ret = port->SetPortAudioParam(p, false); |
| 573 | break; |
| 574 | } |
| 575 | case OMX_IndexParamAudioPcm: { |
| 576 | OMX_AUDIO_PARAM_PCMMODETYPE *p = |
| 577 | (OMX_AUDIO_PARAM_PCMMODETYPE *)pComponentParameterStructure; |
| 578 | OMX_U32 index = p->nPortIndex; |
| 579 | PortPcm *port = NULL; |
| 580 | |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 581 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3") && |
| 582 | strcmp(GetWorkingRole(), "audio_decoder.aac")) { |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 583 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 584 | OMX_ErrorUnsupportedIndex); |
| 585 | return OMX_ErrorUnsupportedIndex; |
| 586 | } |
| 587 | |
| 588 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 589 | if (ret != OMX_ErrorNone) { |
| 590 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 591 | return ret; |
| 592 | } |
| 593 | |
| 594 | if (index < nr_ports) |
| 595 | port = static_cast<PortPcm *>(ports[index]); |
| 596 | |
| 597 | if (!port) { |
| 598 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 599 | OMX_ErrorBadPortIndex); |
| 600 | return OMX_ErrorBadPortIndex; |
| 601 | } |
| 602 | |
| 603 | if (port->IsEnabled()) { |
| 604 | OMX_STATETYPE state; |
| 605 | |
| 606 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 607 | if (state != OMX_StateLoaded && |
| 608 | state != OMX_StateWaitForResources) { |
| 609 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 610 | OMX_ErrorIncorrectStateOperation); |
| 611 | return OMX_ErrorIncorrectStateOperation; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | ret = port->SetPortPcmParam(p, false); |
| 616 | break; |
| 617 | } |
| 618 | case OMX_IndexParamAudioMp3: { |
| 619 | OMX_AUDIO_PARAM_MP3TYPE *p = |
| 620 | (OMX_AUDIO_PARAM_MP3TYPE *)pComponentParameterStructure; |
| 621 | OMX_U32 index = p->nPortIndex; |
| 622 | PortMp3 *port = NULL; |
| 623 | |
| 624 | if (strcmp(GetWorkingRole(), "audio_decoder.mp3")) { |
| 625 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 626 | OMX_ErrorUnsupportedIndex); |
| 627 | return OMX_ErrorUnsupportedIndex; |
| 628 | } |
| 629 | |
| 630 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 631 | if (ret != OMX_ErrorNone) { |
| 632 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | if (index < nr_ports) |
| 637 | port = static_cast<PortMp3 *>(ports[index]); |
| 638 | |
| 639 | if (!port) { |
| 640 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 641 | OMX_ErrorBadPortIndex); |
| 642 | return OMX_ErrorBadPortIndex; |
| 643 | } |
| 644 | |
| 645 | if (port->IsEnabled()) { |
| 646 | OMX_STATETYPE state; |
| 647 | |
| 648 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 649 | if (state != OMX_StateLoaded && |
| 650 | state != OMX_StateWaitForResources) { |
| 651 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 652 | OMX_ErrorIncorrectStateOperation); |
| 653 | return OMX_ErrorIncorrectStateOperation; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | ret = port->SetPortMp3Param(p, false); |
| 658 | break; |
| 659 | } |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 660 | case OMX_IndexParamAudioAac: { |
| 661 | OMX_AUDIO_PARAM_AACPROFILETYPE *p = |
| 662 | (OMX_AUDIO_PARAM_AACPROFILETYPE *)pComponentParameterStructure; |
| 663 | OMX_U32 index = p->nPortIndex; |
| 664 | PortAac *port = NULL; |
| 665 | |
| 666 | if (strcmp(GetWorkingRole(), "audio_decoder.aac")) { |
| 667 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 668 | OMX_ErrorUnsupportedIndex); |
| 669 | return OMX_ErrorUnsupportedIndex; |
| 670 | } |
| 671 | |
| 672 | ret = CheckTypeHeader(p, sizeof(*p)); |
| 673 | if (ret != OMX_ErrorNone) { |
| 674 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 675 | return ret; |
| 676 | } |
| 677 | |
| 678 | if (index < nr_ports) |
| 679 | port = static_cast<PortAac *>(ports[index]); |
| 680 | |
| 681 | if (!port) { |
| 682 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 683 | OMX_ErrorBadPortIndex); |
| 684 | return OMX_ErrorBadPortIndex; |
| 685 | } |
| 686 | |
| 687 | if (port->IsEnabled()) { |
| 688 | OMX_STATETYPE state; |
| 689 | |
| 690 | CBaseGetState((void *)GetComponentHandle(), &state); |
| 691 | if (state != OMX_StateLoaded && |
| 692 | state != OMX_StateWaitForResources) { |
| 693 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, |
| 694 | OMX_ErrorIncorrectStateOperation); |
| 695 | return OMX_ErrorIncorrectStateOperation; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | ret = port->SetPortAacParam(p, false); |
| 700 | break; |
| 701 | } |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 702 | default: |
| 703 | ret = OMX_ErrorUnsupportedIndex; |
| 704 | } /* switch */ |
| 705 | |
| 706 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 707 | return ret; |
| 708 | } |
| 709 | |
| 710 | /* Get/SetConfig */ |
| 711 | OMX_ERRORTYPE MrstSstComponent::ComponentGetConfig( |
| 712 | OMX_INDEXTYPE nIndex, |
| 713 | OMX_PTR pComponentConfigStructure) |
| 714 | { |
| 715 | OMX_ERRORTYPE ret = OMX_ErrorUnsupportedIndex; |
| 716 | LOGV("%s(): enter\n", __func__); |
| 717 | |
| 718 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 719 | return ret; |
| 720 | } |
| 721 | |
| 722 | OMX_ERRORTYPE MrstSstComponent::ComponentSetConfig( |
| 723 | OMX_INDEXTYPE nParamIndex, |
| 724 | OMX_PTR pComponentConfigStructure) |
| 725 | { |
| 726 | OMX_ERRORTYPE ret = OMX_ErrorUnsupportedIndex; |
| 727 | LOGV("%s(): enter\n", __func__); |
| 728 | |
| 729 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 730 | return ret; |
| 731 | } |
| 732 | |
| 733 | /* implement ComponentBase::Processor[*] */ |
| 734 | OMX_ERRORTYPE MrstSstComponent::ProcessorInit(void) |
| 735 | { |
| 736 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 737 | LOGV("%s(): enter\n", __func__); |
| 738 | |
| 739 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 740 | return ret; |
| 741 | } |
| 742 | |
| 743 | OMX_ERRORTYPE MrstSstComponent::ProcessorDeinit(void) |
| 744 | { |
| 745 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 746 | LOGV("%s(): enter\n", __func__); |
| 747 | |
| 748 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | OMX_ERRORTYPE MrstSstComponent::ProcessorStart(void) |
| 753 | { |
| 754 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 755 | LOGV("%s(): enter\n", __func__); |
| 756 | |
| 757 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 758 | return ret; |
| 759 | } |
| 760 | |
| 761 | OMX_ERRORTYPE MrstSstComponent::ProcessorStop(void) |
| 762 | { |
| 763 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 764 | LOGV("%s(): enter\n", __func__); |
| 765 | |
| 766 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | OMX_ERRORTYPE MrstSstComponent::ProcessorPause(void) |
| 771 | { |
| 772 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 773 | LOGV("%s(): enter\n", __func__); |
| 774 | |
| 775 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 776 | return ret; |
| 777 | } |
| 778 | |
| 779 | OMX_ERRORTYPE MrstSstComponent::ProcessorResume(void) |
| 780 | { |
| 781 | OMX_ERRORTYPE ret = OMX_ErrorNone; |
| 782 | LOGV("%s(): enter\n", __func__); |
| 783 | |
| 784 | LOGV("%s(),%d: exit (ret = 0x%08x)\n", __func__, __LINE__, ret); |
| 785 | return ret; |
| 786 | } |
| 787 | |
| 788 | /* implement ComponentBase::ProcessorProcess */ |
| 789 | void MrstSstComponent::ProcessorProcess( |
| 790 | OMX_BUFFERHEADERTYPE **buffers, |
| 791 | bool *retain, |
| 792 | OMX_U32 nr_buffers) |
| 793 | { |
| 794 | LOGV("%s(): enter\n", __func__); |
| 795 | |
| 796 | /* dummy processing */ |
| 797 | buffers[OUTPORT_INDEX]->nFilledLen = buffers[OUTPORT_INDEX]->nAllocLen; |
| 798 | buffers[OUTPORT_INDEX]->nTimeStamp = buffers[INPORT_INDEX]->nTimeStamp; |
| 799 | |
| 800 | buffers[INPORT_INDEX]->nFilledLen = 0; |
| 801 | |
| 802 | LOGV("%s(),%d: exit (ret = void)\n", __func__, __LINE__); |
| 803 | } |
| 804 | |
| 805 | /* end of implement ComponentBase::Processor[*] */ |
| 806 | |
| 807 | /* end of component methods & helpers */ |
| 808 | |
| 809 | /* |
| 810 | * CModule Interface |
| 811 | */ |
| 812 | static const OMX_STRING g_roles[] = |
| 813 | { |
| 814 | "audio_decoder.mp3", |
| Ho-Eun Ryu | f796f98 | 2009-10-19 17:01:09 +0900 | [diff] [blame^] | 815 | "audio_decoder.aac", |
| Ho-Eun Ryu | 2046ff9 | 2009-10-16 12:27:28 +0900 | [diff] [blame] | 816 | }; |
| 817 | |
| 818 | static const OMX_STRING g_compname = "OMX.Intel.MrstSST"; |
| 819 | |
| 820 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 821 | |
| 822 | OMX_ERRORTYPE omx_component_module_instantiate(OMX_PTR *instance) |
| 823 | { |
| 824 | ComponentBase *cbase; |
| 825 | |
| 826 | cbase = new MrstSstComponent; |
| 827 | if (!cbase) { |
| 828 | *instance = NULL; |
| 829 | return OMX_ErrorInsufficientResources; |
| 830 | } |
| 831 | |
| 832 | *instance = cbase; |
| 833 | return OMX_ErrorNone; |
| 834 | } |
| 835 | |
| 836 | OMX_ERRORTYPE omx_component_module_query_name(OMX_STRING name, OMX_U32 len) |
| 837 | { |
| 838 | if (!name) |
| 839 | return OMX_ErrorBadParameter; |
| 840 | |
| 841 | strncpy(name, g_compname, len); |
| 842 | return OMX_ErrorNone; |
| 843 | } |
| 844 | |
| 845 | OMX_ERRORTYPE omx_component_module_query_roles(OMX_U32 *nr_roles, |
| 846 | OMX_U8 **roles) |
| 847 | { |
| 848 | return ComponentBase::QueryRolesHelper(ARRAY_SIZE(g_roles), |
| 849 | (const OMX_U8 **)g_roles, |
| 850 | nr_roles, roles); |
| 851 | } |