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