void SoftMP3::initPorts() { OMX_PARAM_PORTDEFINITIONTYPE def; InitOMXParams(&def); def.nPortIndex = 0; def.eDir = OMX_DirInput; def.nBufferCountMin = kNumBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 8192; def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainAudio; def.bBuffersContiguous = OMX_FALSE; def.nBufferAlignment = 1; def.format.audio.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_AUDIO_MPEG); def.format.audio.pNativeRender = NULL; def.format.audio.bFlagErrorConcealment = OMX_FALSE; def.format.audio.eEncoding = OMX_AUDIO_CodingMP3; addPort(def); def.nPortIndex = 1; def.eDir = OMX_DirOutput; def.nBufferCountMin = kNumBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = kOutputBufferSize; def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainAudio; def.bBuffersContiguous = OMX_FALSE; def.nBufferAlignment = 2; def.format.audio.cMIMEType = const_cast<char *>("audio/raw"); def.format.audio.pNativeRender = NULL; def.format.audio.bFlagErrorConcealment = OMX_FALSE; def.format.audio.eEncoding = OMX_AUDIO_CodingPCM; addPort(def); }
// static bool IsFlexibleColorFormat( const sp<IOMXNode> &omxNode, uint32_t colorFormat, bool usingNativeBuffers, OMX_U32 *flexibleEquivalent) { DescribeColorFormat2Params describeParams; InitOMXParams(&describeParams); describeParams.eColorFormat = (OMX_COLOR_FORMATTYPE)colorFormat; // reasonable dummy values describeParams.nFrameWidth = 128; describeParams.nFrameHeight = 128; describeParams.nStride = 128; describeParams.nSliceHeight = 128; describeParams.bUsingNativeBuffers = (OMX_BOOL)usingNativeBuffers; CHECK(flexibleEquivalent != NULL); if (!DescribeColorFormat(omxNode, describeParams)) { return false; } const MediaImage2 &img = describeParams.sMediaImage; if (img.mType == MediaImage2::MEDIA_IMAGE_TYPE_YUV) { if (img.mNumPlanes != 3 || img.mPlane[img.Y].mHorizSubsampling != 1 || img.mPlane[img.Y].mVertSubsampling != 1) { return false; } // YUV 420 if (img.mPlane[img.U].mHorizSubsampling == 2 && img.mPlane[img.U].mVertSubsampling == 2 && img.mPlane[img.V].mHorizSubsampling == 2 && img.mPlane[img.V].mVertSubsampling == 2) { // possible flexible YUV420 format if (img.mBitDepth <= 8) { *flexibleEquivalent = OMX_COLOR_FormatYUV420Flexible; return true; } } } return false; }
status_t FFMPEGSoftCodec::setRAFormat( const sp<AMessage> &msg, sp<IOMX> OMXhandle, IOMX::node_id nodeID) { int32_t numChannels = 0; int32_t bitRate = 0; int32_t sampleRate = 0; int32_t blockAlign = 0; OMX_AUDIO_PARAM_RATYPE paramRA; CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeyChannelCount), &numChannels)); CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeySampleRate), &sampleRate)); msg->findInt32(ExtendedCodec::getMsgKey(kKeyBitRate), &bitRate); CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeyBlockAlign), &blockAlign)); ALOGV("Channels: %d, SampleRate: %d, BitRate: %d, blockAlign: %d", numChannels, sampleRate, bitRate, blockAlign); status_t err = setRawAudioFormat(msg, OMXhandle, nodeID); if (err != OK) return err; InitOMXParams(¶mRA); paramRA.nPortIndex = kPortIndexInput; err = OMXhandle->getParameter( nodeID, OMX_IndexParamAudioRa, ¶mRA, sizeof(paramRA)); if (err != OK) return err; paramRA.eFormat = OMX_AUDIO_RAFormatUnused; // FIXME, cook only??? paramRA.nChannels = numChannels; paramRA.nSamplingRate = sampleRate; // FIXME, HACK!!!, I use the nNumRegions parameter pass blockAlign!!! // the cook audio codec need blockAlign! paramRA.nNumRegions = blockAlign; return OMXhandle->setParameter( nodeID, OMX_IndexParamAudioRa, ¶mRA, sizeof(paramRA)); }
status_t ExtendedCodec::setDIVXFormat( const sp<AMessage> &msg, const char* mime, sp<IOMX> OMXhandle, IOMX::node_id nodeID, int port_index) { status_t err = OK; if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX, mime) || !strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX4, mime) || !strcasecmp(MEDIA_MIMETYPE_VIDEO_DIVX311, mime)) { ALOGV("Setting the QOMX_VIDEO_PARAM_DIVXTYPE params "); QOMX_VIDEO_PARAM_DIVXTYPE paramDivX; InitOMXParams(¶mDivX); paramDivX.nPortIndex = port_index; int32_t DivxVersion = 0; CHECK(msg->findInt32(getMsgKey(kKeyDivXVersion),&DivxVersion)); ALOGV("Divx Version Type %d\n",DivxVersion); if(DivxVersion == kTypeDivXVer_4) { paramDivX.eFormat = QOMX_VIDEO_DIVXFormat4; } else if(DivxVersion == kTypeDivXVer_5) { paramDivX.eFormat = QOMX_VIDEO_DIVXFormat5; } else if(DivxVersion == kTypeDivXVer_6) { paramDivX.eFormat = QOMX_VIDEO_DIVXFormat6; } else if(DivxVersion == kTypeDivXVer_3_11 ) { paramDivX.eFormat = QOMX_VIDEO_DIVXFormat311; } else { paramDivX.eFormat = QOMX_VIDEO_DIVXFormatUnused; } paramDivX.eProfile = (QOMX_VIDEO_DIVXPROFILETYPE)0; //Not used for now. err = OMXhandle->setParameter(nodeID, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoDivx, ¶mDivX, sizeof(paramDivX)); } return err; }
void ExtendedCodec::setAC3Format( int32_t numChannels, int32_t sampleRate, sp<IOMX> OMXhandle, IOMX::node_id nodeID) { QOMX_AUDIO_PARAM_AC3TYPE profileAC3; QOMX_AUDIO_PARAM_AC3PP profileAC3PP; OMX_INDEXTYPE indexTypeAC3; OMX_INDEXTYPE indexTypeAC3PP; OMX_PARAM_PORTDEFINITIONTYPE portParam; //configure input port ALOGV("setAC3Format samplerate %d, numChannels %d", sampleRate, numChannels); InitOMXParams(&portParam); portParam.nPortIndex = 0; status_t err = OMXhandle->getParameter( nodeID, OMX_IndexParamPortDefinition, &portParam, sizeof(portParam)); CHECK_EQ(err, (status_t)OK); err = OMXhandle->setParameter( nodeID, OMX_IndexParamPortDefinition, &portParam, sizeof(portParam)); CHECK_EQ(err, (status_t)OK); //configure output port portParam.nPortIndex = 1; err = OMXhandle->getParameter( nodeID, OMX_IndexParamPortDefinition, &portParam, sizeof(portParam)); CHECK_EQ(err, (status_t)OK); err = OMXhandle->setParameter( nodeID, OMX_IndexParamPortDefinition, &portParam, sizeof(portParam)); CHECK_EQ(err, (status_t)OK); err = OMXhandle->getExtensionIndex(nodeID, OMX_QCOM_INDEX_PARAM_AC3TYPE, &indexTypeAC3); InitOMXParams(&profileAC3); profileAC3.nPortIndex = kPortIndexInput; err = OMXhandle->getParameter(nodeID, indexTypeAC3, &profileAC3, sizeof(profileAC3)); CHECK_EQ(err,(status_t)OK); profileAC3.nSamplingRate = sampleRate; profileAC3.nChannels = 2; profileAC3.eChannelConfig = OMX_AUDIO_AC3_CHANNEL_CONFIG_2_0; ALOGV("numChannels = %d, profileAC3.nChannels = %d", numChannels, profileAC3.nChannels); err = OMXhandle->setParameter(nodeID, indexTypeAC3, &profileAC3, sizeof(profileAC3)); CHECK_EQ(err,(status_t)OK); //for output port OMX_AUDIO_PARAM_PCMMODETYPE profilePcm; InitOMXParams(&profilePcm); profilePcm.nPortIndex = kPortIndexOutput; err = OMXhandle->getParameter( nodeID, OMX_IndexParamAudioPcm, &profilePcm, sizeof(profilePcm)); CHECK_EQ(err, (status_t)OK); profilePcm.nSamplingRate = sampleRate; err = OMXhandle->setParameter( nodeID, OMX_IndexParamAudioPcm, &profilePcm, sizeof(profilePcm)); CHECK_EQ(err, (status_t)OK); OMXhandle->getExtensionIndex(nodeID, OMX_QCOM_INDEX_PARAM_AC3PP, &indexTypeAC3PP); InitOMXParams(&profileAC3PP); profileAC3PP.nPortIndex = kPortIndexInput; err = OMXhandle->getParameter( nodeID, indexTypeAC3PP, &profileAC3PP, sizeof(profileAC3PP)); CHECK_EQ(err, (status_t)OK); int i; int channel_routing[6] = {0}; for (i=0; i<6; i++) { channel_routing[i] = -1; } for (i=0; i<6; i++) { profileAC3PP.eChannelRouting[i] = (OMX_AUDIO_AC3_CHANNEL_ROUTING)channel_routing[i]; } profileAC3PP.eChannelRouting[0] = OMX_AUDIO_AC3_CHANNEL_LEFT; profileAC3PP.eChannelRouting[1] = OMX_AUDIO_AC3_CHANNEL_RIGHT; err = OMXhandle->setParameter(nodeID, indexTypeAC3PP, &profileAC3PP, sizeof(profileAC3PP)); CHECK_EQ(err, (status_t)OK); }
status_t ExtendedCodec::setWMAFormat( const sp<AMessage> &msg, sp<IOMX> OMXhandle, IOMX::node_id nodeID, bool isEncoder ) { ALOGV("setWMAFormat Called"); if (isEncoder) { ALOGE("WMA encoding not supported"); return OK; } else { int32_t version; OMX_AUDIO_PARAM_WMATYPE paramWMA; QOMX_AUDIO_PARAM_WMA10PROTYPE paramWMA10; CHECK(msg->findInt32(getMsgKey(kKeyWMAVersion), &version)); int32_t numChannels; int32_t bitRate; int32_t sampleRate; int32_t encodeOptions; int32_t blockAlign; int32_t bitspersample; int32_t formattag; int32_t advencopt1; int32_t advencopt2; int32_t VirtualPktSize; if(version==kTypeWMAPro || version==kTypeWMALossLess) { CHECK(msg->findInt32(getMsgKey(kKeyWMABitspersample), &bitspersample)); CHECK(msg->findInt32(getMsgKey(kKeyWMAFormatTag), &formattag)); CHECK(msg->findInt32(getMsgKey(kKeyWMAAdvEncOpt1), &advencopt1)); CHECK(msg->findInt32(getMsgKey(kKeyWMAAdvEncOpt2), &advencopt2)); CHECK(msg->findInt32(getMsgKey(kKeyWMAVirPktSize), &VirtualPktSize)); } if(version==kTypeWMA) { InitOMXParams(¶mWMA); paramWMA.nPortIndex = kPortIndexInput; } else if(version==kTypeWMAPro || version==kTypeWMALossLess) { InitOMXParams(¶mWMA10); paramWMA10.nPortIndex = kPortIndexInput; } CHECK(msg->findInt32("channel-count", &numChannels)); CHECK(msg->findInt32("sample-rate", &sampleRate)); CHECK(msg->findInt32(getMsgKey(kKeyBitRate), &bitRate)); CHECK(msg->findInt32(getMsgKey(kKeyWMAEncodeOpt), &encodeOptions)); CHECK(msg->findInt32(getMsgKey(kKeyWMABlockAlign), &blockAlign)); ALOGV("Channels: %d, SampleRate: %d, BitRate; %d" "EncodeOptions: %d, blockAlign: %d", numChannels, sampleRate, bitRate, encodeOptions, blockAlign); if(sampleRate>48000 || numChannels>2) { ALOGE("Unsupported samplerate/channels"); return ERROR_UNSUPPORTED; } if(version==kTypeWMAPro || version==kTypeWMALossLess) { ALOGV("Bitspersample: %d, wmaformattag: %d," "advencopt1: %d, advencopt2: %d VirtualPktSize %d", bitspersample, formattag, advencopt1, advencopt2, VirtualPktSize); } status_t err = OK; OMX_INDEXTYPE index; if(version==kTypeWMA) { err = OMXhandle->getParameter( nodeID, OMX_IndexParamAudioWma, ¶mWMA, sizeof(paramWMA)); } else if(version==kTypeWMAPro || version==kTypeWMALossLess) { OMXhandle->getExtensionIndex(nodeID,"OMX.Qualcomm.index.audio.wma10Pro",&index); err = OMXhandle->getParameter( nodeID, index, ¶mWMA10, sizeof(paramWMA10)); } CHECK_EQ(err, (status_t)OK); if(version==kTypeWMA) { paramWMA.nChannels = numChannels; paramWMA.nSamplingRate = sampleRate; paramWMA.nEncodeOptions = encodeOptions; paramWMA.nBitRate = bitRate; paramWMA.nBlockAlign = blockAlign; } else if(version==kTypeWMAPro || version==kTypeWMALossLess) { paramWMA10.nChannels = numChannels; paramWMA10.nSamplingRate = sampleRate; paramWMA10.nEncodeOptions = encodeOptions; paramWMA10.nBitRate = bitRate; paramWMA10.nBlockAlign = blockAlign; } if(version==kTypeWMAPro || version==kTypeWMALossLess) { paramWMA10.advancedEncodeOpt = advencopt1; paramWMA10.advancedEncodeOpt2 = advencopt2; paramWMA10.formatTag = formattag; paramWMA10.validBitsPerSample = bitspersample; paramWMA10.nVirtualPktSize = VirtualPktSize; } if(version==kTypeWMA) { err = OMXhandle->setParameter( nodeID, OMX_IndexParamAudioWma, ¶mWMA, sizeof(paramWMA)); } else if(version==kTypeWMAPro || version==kTypeWMALossLess) { err = OMXhandle->setParameter( nodeID, index, ¶mWMA10, sizeof(paramWMA10)); } return err; } return OK; }
status_t ExtendedCodec::setSupportedRole( const sp<IOMX> &omx, IOMX::node_id node, bool isEncoder, const char *mime){ ALOGV("setSupportedRole Called %s", mime); struct MimeToRole { const char *mime; const char *decoderRole; const char *encoderRole; }; static const MimeToRole kQCMimeToRole[] = { { MEDIA_MIMETYPE_AUDIO_EVRC, "audio_decoder.evrchw", "audio_encoder.evrc" }, { MEDIA_MIMETYPE_AUDIO_QCELP, "audio_decoder,qcelp13Hw", "audio_encoder.qcelp13" }, { MEDIA_MIMETYPE_VIDEO_DIVX, "video_decoder.divx", NULL }, { MEDIA_MIMETYPE_VIDEO_DIVX4, "video_decoder.divx", NULL }, { MEDIA_MIMETYPE_VIDEO_DIVX311, "video_decoder.divx", NULL }, { MEDIA_MIMETYPE_VIDEO_WMV, "video_decoder.vc1", NULL }, { MEDIA_MIMETYPE_AUDIO_AC3, "audio_decoder.ac3", NULL }, { MEDIA_MIMETYPE_AUDIO_WMA, "audio_decoder.wma" , NULL }, { MEDIA_MIMETYPE_VIDEO_HEVC, "video_decoder.hevc" , NULL }, }; static const size_t kNumMimeToRole = sizeof(kQCMimeToRole) / sizeof(kQCMimeToRole[0]); size_t i; for (i = 0; i < kNumMimeToRole; ++i) { if (!strcasecmp(mime, kQCMimeToRole[i].mime)) { break; } } if (i == kNumMimeToRole) { return ERROR_UNSUPPORTED; } const char *role = isEncoder ? kQCMimeToRole[i].encoderRole : kQCMimeToRole[i].decoderRole; if (role != NULL) { OMX_PARAM_COMPONENTROLETYPE roleParams; InitOMXParams(&roleParams); strncpy((char *)roleParams.cRole, role, OMX_MAX_STRINGNAME_SIZE - 1); roleParams.cRole[OMX_MAX_STRINGNAME_SIZE - 1] = '\0'; status_t err = omx->setParameter( node, OMX_IndexParamStandardComponentRole, &roleParams, sizeof(roleParams)); if (err != OK) { ALOGW("Failed to set standard component role '%s'.", role); return err; } } return OK; }
void SoftMPEG4::initPorts() { OMX_PARAM_PORTDEFINITIONTYPE def; InitOMXParams(&def); def.nPortIndex = 0; def.eDir = OMX_DirInput; def.nBufferCountMin = kNumInputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 8192; def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainVideo; def.bBuffersContiguous = OMX_FALSE; def.nBufferAlignment = 1; def.format.video.cMIMEType = (mMode == MODE_MPEG4) ? const_cast<char *>(MEDIA_MIMETYPE_VIDEO_MPEG4) : const_cast<char *>(MEDIA_MIMETYPE_VIDEO_H263); def.format.video.pNativeRender = NULL; def.format.video.nFrameWidth = mWidth; def.format.video.nFrameHeight = mHeight; def.format.video.nStride = def.format.video.nFrameWidth; def.format.video.nSliceHeight = def.format.video.nFrameHeight; def.format.video.nBitrate = 0; def.format.video.xFramerate = 0; def.format.video.bFlagErrorConcealment = OMX_FALSE; def.format.video.eCompressionFormat = mMode == MODE_MPEG4 ? OMX_VIDEO_CodingMPEG4 : OMX_VIDEO_CodingH263; def.format.video.eColorFormat = OMX_COLOR_FormatUnused; def.format.video.pNativeWindow = NULL; addPort(def); def.nPortIndex = 1; def.eDir = OMX_DirOutput; def.nBufferCountMin = kNumOutputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainVideo; def.bBuffersContiguous = OMX_FALSE; def.nBufferAlignment = 2; def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_RAW); def.format.video.pNativeRender = NULL; def.format.video.nFrameWidth = mWidth; def.format.video.nFrameHeight = mHeight; def.format.video.nStride = def.format.video.nFrameWidth; def.format.video.nSliceHeight = def.format.video.nFrameHeight; def.format.video.nBitrate = 0; def.format.video.xFramerate = 0; def.format.video.bFlagErrorConcealment = OMX_FALSE; def.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; def.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar; def.format.video.pNativeWindow = NULL; def.nBufferSize = (def.format.video.nFrameWidth * def.format.video.nFrameHeight * 3) / 2; addPort(def); }
void ExtendedCodec::configureVideoCodec( const sp<MetaData> &meta, sp<IOMX> OMXhandle, const uint32_t flags, IOMX::node_id nodeID, char* componentName ) { if (strncmp(componentName, "OMX.qcom.", 9)) { //do nothing for non QC component return; } int32_t arbitraryMode = 0; bool success = meta->findInt32(kKeyUseArbitraryMode, &arbitraryMode); bool useFrameByFrameMode = true; //default option if (success && arbitraryMode) { useFrameByFrameMode = false; } if (useFrameByFrameMode) { ALOGI("Enable frame by frame mode"); OMX_QCOM_PARAM_PORTDEFINITIONTYPE portFmt; portFmt.nPortIndex = kPortIndexInput; portFmt.nFramePackingFormat = OMX_QCOM_FramePacking_OnlyOneCompleteFrame; status_t err = OMXhandle->setParameter( nodeID, (OMX_INDEXTYPE)OMX_QcomIndexPortDefn, (void *)&portFmt, sizeof(portFmt)); if(err != OK) { ALOGW("Failed to set frame packing format on component"); } } else { ALOGI("Decoder should be in arbitrary mode"); } // Enable timestamp reordering for AVI file type, mpeg4 and vc1 codec types const char *fileFormat; success = meta->findCString(kKeyFileFormat, &fileFormat); if (!strcmp(componentName, "OMX.qcom.video.decoder.vc1") || !strcmp(componentName, "OMX.qcom.video.decoder.mpeg4") || (success && !strncmp(fileFormat, "video/avi", 9))) { ALOGI("Enabling timestamp reordering"); QOMX_INDEXTIMESTAMPREORDER reorder; InitOMXParams(&reorder); reorder.nPortIndex = kPortIndexOutput; reorder.bEnable = OMX_TRUE; status_t err = OMXhandle->setParameter(nodeID, (OMX_INDEXTYPE)OMX_QcomIndexParamEnableTimeStampReorder, (void *)&reorder, sizeof(reorder)); if(err != OK) { ALOGW("Failed to enable timestamp reordering"); } } // Enable Sync-frame decode mode for thumbnails if (flags & OMXCodec::kClientNeedsFramebuffer) { ALOGV("Enabling thumbnail mode."); QOMX_ENABLETYPE enableType; OMX_INDEXTYPE indexType; status_t err = OMXhandle->getExtensionIndex( nodeID, OMX_QCOM_INDEX_PARAM_VIDEO_SYNCFRAMEDECODINGMODE, &indexType); if(err != OK) { ALOGW("Failed to get extension for SYNCFRAMEDECODINGMODE"); return; } enableType.bEnable = OMX_TRUE; err = OMXhandle->setParameter(nodeID,indexType, (void *)&enableType, sizeof(enableType)); if(err != OK) { ALOGW("Failed to get extension for SYNCFRAMEDECODINGMODE"); return; } ALOGI("Thumbnail mode enabled."); } }
void SoftFFmpegVideo::initPorts() { OMX_PARAM_PORTDEFINITIONTYPE def; InitOMXParams(&def); def.nPortIndex = 0; def.eDir = OMX_DirInput; def.nBufferCountMin = kNumInputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.nBufferSize = 1280 * 720; // 256 * 1024? def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainVideo; def.bBuffersContiguous = OMX_FALSE; def.nBufferAlignment = 1; switch (mMode) { case MODE_H264: def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_AVC); def.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; break; case MODE_MPEG4: def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_MPEG4); def.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; break; case MODE_MPEG2: def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_MPEG2); def.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2; break; case MODE_H263: def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_H263); def.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; break; case MODE_VC1: def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_VC1); def.format.video.eCompressionFormat = OMX_VIDEO_CodingWMV; break; default: CHECK(!"Should not be here. Unsupported mime type and compression format"); break; } def.format.video.pNativeRender = NULL; def.format.video.nFrameWidth = mWidth; def.format.video.nFrameHeight = mHeight; def.format.video.nStride = def.format.video.nFrameWidth; def.format.video.nSliceHeight = def.format.video.nFrameHeight; def.format.video.nBitrate = 0; def.format.video.xFramerate = 0; def.format.video.bFlagErrorConcealment = OMX_FALSE; def.format.video.eColorFormat = OMX_COLOR_FormatUnused; def.format.video.pNativeWindow = NULL; addPort(def); def.nPortIndex = 1; def.eDir = OMX_DirOutput; def.nBufferCountMin = kNumOutputBuffers; def.nBufferCountActual = def.nBufferCountMin; def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainVideo; def.bBuffersContiguous = OMX_FALSE; def.nBufferAlignment = 2; def.format.video.cMIMEType = const_cast<char *>(MEDIA_MIMETYPE_VIDEO_RAW); def.format.video.pNativeRender = NULL; def.format.video.nFrameWidth = mWidth; def.format.video.nFrameHeight = mHeight; def.format.video.nStride = def.format.video.nFrameWidth; def.format.video.nSliceHeight = def.format.video.nFrameHeight; def.format.video.nBitrate = 0; def.format.video.xFramerate = 0; def.format.video.bFlagErrorConcealment = OMX_FALSE; def.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; def.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar; def.format.video.pNativeWindow = NULL; def.nBufferSize = (def.format.video.nFrameWidth * def.format.video.nFrameHeight * 3) / 2; addPort(def); }
//audio status_t FFMPEGSoftCodec::setRawAudioFormat( const sp<AMessage> &msg, sp<IOMX> OMXhandle, IOMX::node_id nodeID) { int32_t numChannels = 0; int32_t sampleRate = 0; int32_t bitsPerSample = 0; CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeyChannelCount), &numChannels)); CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeySampleRate), &sampleRate)); if (!msg->findInt32(ExtendedCodec::getMsgKey(kKeyBitsPerSample), &bitsPerSample)) { ALOGD("No PCM format specified, let decoder decide"); } OMX_PARAM_PORTDEFINITIONTYPE def; InitOMXParams(&def); def.nPortIndex = kPortIndexOutput; status_t err = OMXhandle->getParameter( nodeID, OMX_IndexParamPortDefinition, &def, sizeof(def)); if (err != OK) { return err; } def.format.audio.eEncoding = OMX_AUDIO_CodingPCM; err = OMXhandle->setParameter( nodeID, OMX_IndexParamPortDefinition, &def, sizeof(def)); if (err != OK) { return err; } OMX_AUDIO_PARAM_PCMMODETYPE pcmParams; InitOMXParams(&pcmParams); pcmParams.nPortIndex = kPortIndexOutput; err = OMXhandle->getParameter( nodeID, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams)); if (err != OK) { return err; } pcmParams.nChannels = numChannels; pcmParams.eNumData = OMX_NumericalDataSigned; pcmParams.bInterleaved = OMX_TRUE; if (bitsPerSample > 0) { pcmParams.nBitPerSample = bitsPerSample; } pcmParams.nSamplingRate = sampleRate; pcmParams.ePCMMode = OMX_AUDIO_PCMModeLinear; if (getOMXChannelMapping(numChannels, pcmParams.eChannelMapping) != OK) { return OMX_ErrorNone; } err = OMXhandle->setParameter( nodeID, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams)); if (err != OK) { return err; } msg->setInt32("bits-per-sample", pcmParams.nBitPerSample); return OK; }
status_t FFMPEGSoftCodec::setSupportedRole( const sp<IOMX> &omx, IOMX::node_id node, bool isEncoder, const char *mime) { ALOGV("setSupportedRole Called %s", mime); struct MimeToRole { const char *mime; const char *decoderRole; const char *encoderRole; }; static const MimeToRole kFFMPEGMimeToRole[] = { { MEDIA_MIMETYPE_AUDIO_AAC, "audio_decoder.aac", NULL }, { MEDIA_MIMETYPE_AUDIO_MPEG, "audio_decoder.mp3", NULL }, { MEDIA_MIMETYPE_AUDIO_VORBIS, "audio_decoder.vorbis", NULL }, { MEDIA_MIMETYPE_AUDIO_WMA, "audio_decoder.wma", NULL }, { MEDIA_MIMETYPE_AUDIO_RA, "audio_decoder.ra" , NULL }, { MEDIA_MIMETYPE_AUDIO_FLAC, "audio_decoder.flac", NULL }, { MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II, "audio_decoder.mp2", NULL }, { MEDIA_MIMETYPE_AUDIO_AC3, "audio_decoder.ac3", NULL }, { MEDIA_MIMETYPE_AUDIO_APE, "audio_decoder.ape", NULL }, { MEDIA_MIMETYPE_AUDIO_DTS, "audio_decoder.dts", NULL }, { MEDIA_MIMETYPE_VIDEO_MPEG2, "video_decoder.mpeg2", NULL }, { MEDIA_MIMETYPE_VIDEO_DIVX, "video_decoder.divx", NULL }, { MEDIA_MIMETYPE_VIDEO_DIVX4, "video_decoder.divx", NULL }, { MEDIA_MIMETYPE_VIDEO_DIVX311, "video_decoder.divx", NULL }, { MEDIA_MIMETYPE_VIDEO_WMV, "video_decoder.wmv", NULL }, { MEDIA_MIMETYPE_VIDEO_RV, "video_decoder.rv", NULL }, { MEDIA_MIMETYPE_VIDEO_FLV1, "video_decoder.flv1", NULL }, { MEDIA_MIMETYPE_VIDEO_HEVC, "video_decoder.hevc", NULL }, { MEDIA_MIMETYPE_AUDIO_FFMPEG, "audio_decoder.trial", NULL }, { MEDIA_MIMETYPE_VIDEO_FFMPEG, "video_decoder.trial", NULL }, }; static const size_t kNumMimeToRole = sizeof(kFFMPEGMimeToRole) / sizeof(kFFMPEGMimeToRole[0]); size_t i; for (i = 0; i < kNumMimeToRole; ++i) { if (!strcasecmp(mime, kFFMPEGMimeToRole[i].mime)) { break; } } if (i == kNumMimeToRole) { return ERROR_UNSUPPORTED; } const char *role = isEncoder ? kFFMPEGMimeToRole[i].encoderRole : kFFMPEGMimeToRole[i].decoderRole; if (role != NULL) { OMX_PARAM_COMPONENTROLETYPE roleParams; InitOMXParams(&roleParams); strncpy((char *)roleParams.cRole, role, OMX_MAX_STRINGNAME_SIZE - 1); roleParams.cRole[OMX_MAX_STRINGNAME_SIZE - 1] = '\0'; status_t err = omx->setParameter( node, OMX_IndexParamStandardComponentRole, &roleParams, sizeof(roleParams)); if (err != OK) { ALOGW("Failed to set standard component role '%s'.", role); return err; } } return OK; }