2 * Copyright 2012 Michael Chen <omxcodec@gmail.com>
3 * Copyright 2015 The CyanogenMod Project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 //#define LOG_NDEBUG 0
19 #define LOG_TAG "SoftFFmpegAudio"
20 #include <utils/Log.h>
21 #include <cutils/properties.h>
23 #include "SoftFFmpegAudio.h"
24 #include "FFmpegComponents.h"
26 #include <media/stagefright/foundation/ADebug.h>
27 #include <media/stagefright/foundation/hexdump.h>
28 #include <media/stagefright/MediaDefs.h>
29 #include <media/stagefright/OMXCodec.h>
31 #include <OMX_AudioExt.h>
32 #include <OMX_IndexExt.h>
40 static void InitOMXParams(T *params) {
41 params->nSize = sizeof(T);
42 params->nVersion.s.nVersionMajor = 1;
43 params->nVersion.s.nVersionMinor = 0;
44 params->nVersion.s.nRevision = 0;
45 params->nVersion.s.nStep = 0;
48 int64_t *SoftFFmpegAudio::sAudioClock;
50 SoftFFmpegAudio::SoftFFmpegAudio(
52 const char *componentRole,
53 OMX_AUDIO_CODINGTYPE codingType,
54 enum AVCodecID codecID,
55 const OMX_CALLBACKTYPE *callbacks,
57 OMX_COMPONENTTYPE **component)
58 : SimpleSoftOMXComponent(name, callbacks, appData, component),
60 mCodingType(codingType),
61 mFFmpegAlreadyInited(false),
62 mCodecAlreadyOpened(false),
63 mExtradataReady(false),
64 mIgnoreExtradata(false),
68 mEOSStatus(INPUT_DATA_AVAILABLE),
69 mSignalledError(false),
72 mResampledDataSize(0),
73 mOutputPortSettingsChange(NONE),
74 mReconfiguring(false) {
78 ALOGD("SoftFFmpegAudio component: %s mCodingType: %d",
82 CHECK_EQ(initDecoder(codecID), (status_t)OK);
85 SoftFFmpegAudio::~SoftFFmpegAudio() {
86 ALOGV("~SoftFFmpegAudio");
88 if (mFFmpegAlreadyInited) {
93 void SoftFFmpegAudio::initPorts() {
94 OMX_PARAM_PORTDEFINITIONTYPE def;
98 def.eDir = OMX_DirInput;
99 def.nBufferCountMin = kNumInputBuffers;
100 def.nBufferCountActual = def.nBufferCountMin;
102 if (mCodingType == (OMX_AUDIO_CODINGTYPE)OMX_AUDIO_CodingAPE) {
103 def.nBufferSize = 1000000; // ape!
104 } else if (mCodingType == (OMX_AUDIO_CODINGTYPE)OMX_AUDIO_CodingDTS) {
105 def.nBufferSize = 1000000; // dts!
107 // max aggregated buffer size from nuplayer
108 def.nBufferSize = 24 * 1024;
111 def.bEnabled = OMX_TRUE;
112 def.bPopulated = OMX_FALSE;
113 def.eDomain = OMX_PortDomainAudio;
114 def.bBuffersContiguous = OMX_FALSE;
115 def.nBufferAlignment = 1;
117 //def.format.audio.cMIMEType = const_cast<char *>("audio/raw");
118 def.format.audio.pNativeRender = NULL;
119 def.format.audio.bFlagErrorConcealment = OMX_FALSE;
120 def.format.audio.eEncoding = mCodingType;
125 def.eDir = OMX_DirOutput;
126 def.nBufferCountMin = kNumOutputBuffers;
127 def.nBufferCountActual = def.nBufferCountMin;
128 def.nBufferSize = kOutputBufferSize;
129 def.bEnabled = OMX_TRUE;
130 def.bPopulated = OMX_FALSE;
131 def.eDomain = OMX_PortDomainAudio;
132 def.bBuffersContiguous = OMX_FALSE;
133 def.nBufferAlignment = 2;
135 def.format.audio.cMIMEType = const_cast<char *>("audio/raw");
136 def.format.audio.pNativeRender = NULL;
137 def.format.audio.bFlagErrorConcealment = OMX_FALSE;
138 def.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
143 void SoftFFmpegAudio::setDefaultCtx(AVCodecContext *avctx, const AVCodec *codec) {
146 avctx->workaround_bugs = 1;
148 if(avctx->lowres > codec->max_lowres){
149 ALOGW("The maximum value for lowres supported by the decoder is %d",
151 avctx->lowres= codec->max_lowres;
153 avctx->idct_algo = 0;
154 avctx->skip_frame = AVDISCARD_DEFAULT;
155 avctx->skip_idct = AVDISCARD_DEFAULT;
156 avctx->skip_loop_filter = AVDISCARD_DEFAULT;
157 avctx->error_concealment = 3;
159 avctx->flags |= CODEC_FLAG_BITEXACT;
161 if(avctx->lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE;
162 if (fast) avctx->flags2 |= CODEC_FLAG2_FAST;
163 if(codec->capabilities & CODEC_CAP_DR1)
164 avctx->flags |= CODEC_FLAG_EMU_EDGE;
167 bool SoftFFmpegAudio::isConfigured() {
168 return mCtx->channels > 0;
171 void SoftFFmpegAudio::resetCtx() {
173 mCtx->sample_rate = 44100;
175 mCtx->sample_fmt = AV_SAMPLE_FMT_NONE;
177 mAudioSrcChannels = mAudioTgtChannels = 2;
178 mAudioSrcFreq = mAudioTgtFreq = 44100;
179 mAudioSrcFmt = mAudioTgtFmt = AV_SAMPLE_FMT_NONE;
180 mAudioSrcChannelLayout = mAudioTgtChannelLayout =
181 av_get_default_channel_layout(mAudioSrcChannels);
184 void SoftFFmpegAudio::initVorbisHdr() {
186 for (i = 0; i < 3; i++) {
187 mVorbisHeaderStart[i] = NULL;
188 mVorbisHeaderLen[i] = 0;
192 void SoftFFmpegAudio::deinitVorbisHdr() {
194 for (i = 0; i < 3; i++) {
195 if (mVorbisHeaderLen[i] > 0) {
196 av_free(mVorbisHeaderStart[i]);
197 mVorbisHeaderStart[i] = NULL;
198 mVorbisHeaderLen[i] = 0;
203 status_t SoftFFmpegAudio::initDecoder(enum AVCodecID codecID) {
206 status = initFFmpeg();
210 mFFmpegAlreadyInited = true;
212 mCtx = avcodec_alloc_context3(NULL);
214 ALOGE("avcodec_alloc_context failed.");
218 mCtx->codec_type = AVMEDIA_TYPE_AUDIO;
219 mCtx->codec_id = codecID;
224 mCtx->extradata = NULL;
225 mCtx->extradata_size = 0;
229 memset(mSilenceBuffer, 0, kOutputBufferSize);
234 void SoftFFmpegAudio::deInitDecoder() {
236 if (!mCtx->extradata) {
237 av_free(mCtx->extradata);
238 mCtx->extradata = NULL;
239 mCtx->extradata_size = 0;
244 if (mCodecAlreadyOpened) {
260 OMX_ERRORTYPE SoftFFmpegAudio::internalGetParameter(
261 OMX_INDEXTYPE index, OMX_PTR params) {
262 ALOGV("internalGetParameter index:0x%x", index);
263 switch ((int)index) {
264 case OMX_IndexParamAudioPcm:
266 OMX_AUDIO_PARAM_PCMMODETYPE *profile =
267 (OMX_AUDIO_PARAM_PCMMODETYPE *)params;
269 if (profile->nPortIndex > kOutputPortIndex) {
270 return OMX_ErrorUndefined;
273 profile->eNumData = OMX_NumericalDataSigned;
274 profile->eEndian = OMX_EndianBig;
275 profile->bInterleaved = OMX_TRUE;
276 profile->ePCMMode = OMX_AUDIO_PCMModeLinear;
278 if (isConfigured()) {
279 AVSampleFormat packed = av_get_packed_sample_fmt(mAudioTgtFmt);
280 if (packed == AV_SAMPLE_FMT_U8)
281 profile->nBitPerSample = 8;
282 else if (packed == AV_SAMPLE_FMT_S16)
283 profile->nBitPerSample = 16;
284 else if (packed == AV_SAMPLE_FMT_S32)
285 profile->nBitPerSample = 24;
287 profile->nBitPerSample = av_get_bytes_per_sample(mAudioTgtFmt) * 8;
289 profile->nBitPerSample = 32;
292 if (getOMXChannelMapping(mAudioTgtChannels, profile->eChannelMapping) != OK) {
293 return OMX_ErrorNone;
296 profile->nChannels = mAudioTgtChannels;
297 profile->nSamplingRate = mAudioTgtFreq;
299 //mCtx has been updated(adjustAudioParams)!
300 ALOGV("get pcm params, nChannels:%lu, nSamplingRate:%lu, nBitsPerSample:%lu",
301 profile->nChannels, profile->nSamplingRate, profile->nBitPerSample);
303 return OMX_ErrorNone;
306 case OMX_IndexParamAudioAac:
308 OMX_AUDIO_PARAM_AACPROFILETYPE *profile =
309 (OMX_AUDIO_PARAM_AACPROFILETYPE *)params;
311 if (profile->nPortIndex != kInputPortIndex) {
312 return OMX_ErrorUndefined;
315 profile->nBitRate = 0;
316 profile->nAudioBandWidth = 0;
317 profile->nAACtools = 0;
318 profile->nAACERtools = 0;
319 profile->eAACProfile = OMX_AUDIO_AACObjectMain;
320 profile->eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4FF;
321 profile->eChannelMode = OMX_AUDIO_ChannelModeStereo;
323 profile->nChannels = mCtx->channels;
324 profile->nSampleRate = mCtx->sample_rate;
326 return OMX_ErrorNone;
329 case OMX_IndexParamAudioMp3:
331 OMX_AUDIO_PARAM_MP3TYPE *profile =
332 (OMX_AUDIO_PARAM_MP3TYPE *)params;
334 if (profile->nPortIndex != kInputPortIndex) {
335 return OMX_ErrorUndefined;
338 profile->nBitRate = 0;
339 profile->nAudioBandWidth = 0;
340 profile->eChannelMode = OMX_AUDIO_ChannelModeStereo;
341 profile->eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3;
343 profile->nChannels = mCtx->channels;
344 profile->nSampleRate = mCtx->sample_rate;
346 return OMX_ErrorNone;
348 case OMX_IndexParamAudioVorbis:
350 OMX_AUDIO_PARAM_VORBISTYPE *profile =
351 (OMX_AUDIO_PARAM_VORBISTYPE *)params;
353 if (profile->nPortIndex != kInputPortIndex) {
354 return OMX_ErrorUndefined;
357 profile->nBitRate = 0;
358 profile->nMinBitRate = 0;
359 profile->nMaxBitRate = 0;
360 profile->nAudioBandWidth = 0;
361 profile->nQuality = 3;
362 profile->bManaged = OMX_FALSE;
363 profile->bDownmix = OMX_FALSE;
365 profile->nChannels = mCtx->channels;
366 profile->nSampleRate = mCtx->sample_rate;
368 return OMX_ErrorNone;
371 case OMX_IndexParamAudioWma:
373 OMX_AUDIO_PARAM_WMATYPE *profile =
374 (OMX_AUDIO_PARAM_WMATYPE *)params;
376 if (profile->nPortIndex != kInputPortIndex) {
377 return OMX_ErrorUndefined;
380 profile->eFormat = OMX_AUDIO_WMAFormatUnused;
382 profile->nChannels = mCtx->channels;
383 profile->nSamplingRate = mCtx->sample_rate;
385 profile->nBlockAlign = mCtx->block_align;
386 profile->nBitRate = mCtx->bit_rate;
388 return OMX_ErrorNone;
391 case OMX_IndexParamAudioRa:
393 OMX_AUDIO_PARAM_RATYPE *profile =
394 (OMX_AUDIO_PARAM_RATYPE *)params;
396 if (profile->nPortIndex != kInputPortIndex) {
397 return OMX_ErrorUndefined;
400 profile->eFormat = OMX_AUDIO_RAFormatUnused;
402 profile->nChannels = mCtx->channels;
403 profile->nSamplingRate = mCtx->sample_rate;
405 profile->nNumRegions = mCtx->block_align;
407 return OMX_ErrorNone;
410 case OMX_IndexParamAudioFlac:
412 OMX_AUDIO_PARAM_FLACTYPE *profile =
413 (OMX_AUDIO_PARAM_FLACTYPE *)params;
415 if (profile->nPortIndex != kInputPortIndex) {
416 return OMX_ErrorUndefined;
419 profile->nChannels = mCtx->channels;
420 profile->nSampleRate = mCtx->sample_rate;
422 return OMX_ErrorNone;
425 case OMX_IndexParamAudioMp2:
427 OMX_AUDIO_PARAM_MP2TYPE *profile =
428 (OMX_AUDIO_PARAM_MP2TYPE *)params;
430 if (profile->nPortIndex != kInputPortIndex) {
431 return OMX_ErrorUndefined;
434 profile->nChannels = mCtx->channels;
435 profile->nSampleRate = mCtx->sample_rate;
437 return OMX_ErrorNone;
440 case OMX_IndexParamAudioAndroidAc3:
442 OMX_AUDIO_PARAM_ANDROID_AC3TYPE *profile =
443 (OMX_AUDIO_PARAM_ANDROID_AC3TYPE *)params;
445 if (profile->nPortIndex != kInputPortIndex) {
446 return OMX_ErrorUndefined;
449 profile->nChannels = mCtx->channels;
450 profile->nSampleRate = mCtx->sample_rate;
452 return OMX_ErrorNone;
456 case OMX_IndexParamAudioAc3:
458 OMX_AUDIO_PARAM_AC3TYPE *profile =
459 (OMX_AUDIO_PARAM_AC3TYPE *)params;
461 if (profile->nPortIndex != kInputPortIndex) {
462 return OMX_ErrorUndefined;
465 profile->nChannels = mCtx->channels;
466 profile->nSamplingRate = mCtx->sample_rate;
468 return OMX_ErrorNone;
471 case OMX_IndexParamAudioApe:
473 OMX_AUDIO_PARAM_APETYPE *profile =
474 (OMX_AUDIO_PARAM_APETYPE *)params;
476 if (profile->nPortIndex != kInputPortIndex) {
477 return OMX_ErrorUndefined;
480 profile->nChannels = mCtx->channels;
481 profile->nSamplingRate = mCtx->sample_rate;
483 profile->nBitsPerSample = mCtx->bits_per_coded_sample;
485 return OMX_ErrorNone;
488 case OMX_IndexParamAudioDts:
490 OMX_AUDIO_PARAM_DTSTYPE *profile =
491 (OMX_AUDIO_PARAM_DTSTYPE *)params;
493 if (profile->nPortIndex != kInputPortIndex) {
494 return OMX_ErrorUndefined;
497 profile->nChannels = mCtx->channels;
498 profile->nSamplingRate = mCtx->sample_rate;
500 return OMX_ErrorNone;
503 case OMX_IndexParamAudioFFmpeg:
505 OMX_AUDIO_PARAM_FFMPEGTYPE *profile =
506 (OMX_AUDIO_PARAM_FFMPEGTYPE *)params;
508 if (profile->nPortIndex != kInputPortIndex) {
509 return OMX_ErrorUndefined;
512 profile->eCodecId = mCtx->codec_id;
513 profile->nBitRate = mCtx->bit_rate;
514 profile->nBlockAlign = mCtx->block_align;
516 profile->nBitsPerSample = mCtx->bits_per_raw_sample;
517 profile->eSampleFormat = mCtx->sample_fmt;
519 profile->nChannels = mCtx->channels;
520 profile->nSampleRate = mCtx->sample_rate;
522 return OMX_ErrorNone;
527 return SimpleSoftOMXComponent::internalGetParameter(index, params);
531 OMX_ERRORTYPE SoftFFmpegAudio::isRoleSupported(
532 const OMX_PARAM_COMPONENTROLETYPE *roleParams) {
533 for (size_t i = 0; i < kNumAudioComponents; i++) {
534 if (mCodingType == kAudioComponents[i].mAudioCodingType &&
535 strncmp((const char *)roleParams->cRole,
536 kAudioComponents[i].mRole, OMX_MAX_STRINGNAME_SIZE - 1) == 0) {
537 return OMX_ErrorNone;
540 ALOGE("unsupported role: %s", (const char *)roleParams->cRole);
541 return OMX_ErrorUndefined;
544 void SoftFFmpegAudio::adjustAudioParams() {
546 uint32_t max_rate = 192000;
548 mReconfiguring = isConfigured();
550 // let android audio mixer to downmix if there is no multichannel output
551 // and use number of channels from the source file, useful for HDMI/offload output
552 mAudioTgtChannels = mCtx->channels;
554 mAudioTgtFreq = FFMIN(max_rate, FFMAX(8000, mCtx->sample_rate));
556 mAudioTgtChannels = mCtx->channels;
557 mAudioTgtFreq = mCtx->sample_rate;
559 mAudioTgtChannelLayout = av_get_default_channel_layout(mAudioTgtChannels);
561 ALOGV("adjustAudioParams: [channels=%d freq=%d fmt=%s]",
562 mCtx->channels, mCtx->sample_rate, av_get_sample_fmt_name(mAudioTgtFmt));
565 OMX_ERRORTYPE SoftFFmpegAudio::internalSetParameter(
566 OMX_INDEXTYPE index, const OMX_PTR params) {
567 //ALOGV("internalSetParameter index:0x%x", index);
568 switch ((int)index) {
569 case OMX_IndexParamStandardComponentRole:
571 const OMX_PARAM_COMPONENTROLETYPE *roleParams =
572 (const OMX_PARAM_COMPONENTROLETYPE *)params;
573 return isRoleSupported(roleParams);
576 case OMX_IndexParamAudioPcm:
578 const OMX_AUDIO_PARAM_PCMMODETYPE *profile =
579 (const OMX_AUDIO_PARAM_PCMMODETYPE *)params;
581 if (profile->nPortIndex != kOutputPortIndex) {
582 return OMX_ErrorUndefined;
585 if (profile->nBitPerSample == 24) {
586 mAudioTgtFmt = AV_SAMPLE_FMT_S32;
587 } else if (profile->nBitPerSample == 32) {
588 mAudioTgtFmt = AV_SAMPLE_FMT_FLT;
589 } else if (profile->nBitPerSample == 8) {
590 mAudioTgtFmt = AV_SAMPLE_FMT_U8;
592 mAudioTgtFmt = AV_SAMPLE_FMT_S16;
595 mAudioTgtFreq = profile->nSamplingRate;
596 mAudioTgtChannels = profile->nChannels;
598 ALOGV("set OMX_IndexParamAudioPcm, nChannels:%lu, "
599 "nSampleRate:%lu, nBitsPerSample:%lu",
600 profile->nChannels, profile->nSamplingRate,
601 profile->nBitPerSample);
603 return OMX_ErrorNone;
606 case OMX_IndexParamAudioAac:
608 const OMX_AUDIO_PARAM_AACPROFILETYPE *profile =
609 (const OMX_AUDIO_PARAM_AACPROFILETYPE *)params;
611 if (profile->nPortIndex != kInputPortIndex) {
612 return OMX_ErrorUndefined;
615 mCtx->channels = profile->nChannels;
616 mCtx->sample_rate = profile->nSampleRate;
620 ALOGV("set OMX_IndexParamAudioAac, nChannels:%lu, nSampleRate:%lu",
621 profile->nChannels, profile->nSampleRate);
623 return OMX_ErrorNone;
626 case OMX_IndexParamAudioMp3:
628 const OMX_AUDIO_PARAM_MP3TYPE *profile =
629 (const OMX_AUDIO_PARAM_MP3TYPE *)params;
631 if (profile->nPortIndex != kInputPortIndex) {
632 return OMX_ErrorUndefined;
635 mCtx->channels = profile->nChannels;
636 mCtx->sample_rate = profile->nSampleRate;
640 ALOGV("set OMX_IndexParamAudioMp3, nChannels:%lu, nSampleRate:%lu",
641 profile->nChannels, profile->nSampleRate);
643 return OMX_ErrorNone;
646 case OMX_IndexParamAudioVorbis:
648 const OMX_AUDIO_PARAM_VORBISTYPE *profile =
649 (const OMX_AUDIO_PARAM_VORBISTYPE *)params;
651 if (profile->nPortIndex != kInputPortIndex) {
652 return OMX_ErrorUndefined;
655 mCtx->channels = profile->nChannels;
656 mCtx->sample_rate = profile->nSampleRate;
660 ALOGD("set OMX_IndexParamAudioVorbis, "
661 "nChannels=%lu, nSampleRate=%lu, nBitRate=%lu, "
662 "nMinBitRate=%lu, nMaxBitRate=%lu",
663 profile->nChannels, profile->nSampleRate,
664 profile->nBitRate, profile->nMinBitRate,
665 profile->nMaxBitRate);
667 return OMX_ErrorNone;
670 case OMX_IndexParamAudioWma:
672 OMX_AUDIO_PARAM_WMATYPE *profile =
673 (OMX_AUDIO_PARAM_WMATYPE *)params;
675 if (profile->nPortIndex != kInputPortIndex) {
676 return OMX_ErrorUndefined;
679 if (profile->eFormat == OMX_AUDIO_WMAFormat7) {
680 mCtx->codec_id = AV_CODEC_ID_WMAV2;
681 } else if (profile->eFormat == OMX_AUDIO_WMAFormat8) {
682 mCtx->codec_id = AV_CODEC_ID_WMAPRO;
683 } else if (profile->eFormat == OMX_AUDIO_WMAFormat9) {
684 mCtx->codec_id = AV_CODEC_ID_WMALOSSLESS;
686 ALOGE("unsupported wma codec: 0x%x", profile->eFormat);
687 return OMX_ErrorUndefined;
690 mCtx->channels = profile->nChannels;
691 mCtx->sample_rate = profile->nSamplingRate;
693 // wmadec needs bitrate, block_align
694 mCtx->bit_rate = profile->nBitRate;
695 mCtx->block_align = profile->nBlockAlign;
699 ALOGV("set OMX_IndexParamAudioWma, nChannels:%u, "
700 "nSampleRate:%lu, nBitRate:%lu, nBlockAlign:%u",
701 profile->nChannels, profile->nSamplingRate,
702 profile->nBitRate, profile->nBlockAlign);
704 return OMX_ErrorNone;
707 case OMX_IndexParamAudioRa:
709 OMX_AUDIO_PARAM_RATYPE *profile =
710 (OMX_AUDIO_PARAM_RATYPE *)params;
712 if (profile->nPortIndex != kInputPortIndex) {
713 return OMX_ErrorUndefined;
716 mCtx->channels = profile->nChannels;
717 mCtx->sample_rate = profile->nSamplingRate;
719 // FIXME, HACK!!!, I use the nNumRegions parameter pass blockAlign!!!
720 // the cook audio codec need blockAlign!
721 mCtx->block_align = profile->nNumRegions;
725 ALOGV("set OMX_IndexParamAudioRa, nChannels:%lu, "
726 "nSampleRate:%lu, nBlockAlign:%d",
727 profile->nChannels, profile->nSamplingRate, mCtx->block_align);
729 return OMX_ErrorNone;
732 case OMX_IndexParamAudioFlac:
734 OMX_AUDIO_PARAM_FLACTYPE *profile =
735 (OMX_AUDIO_PARAM_FLACTYPE *)params;
737 if (profile->nPortIndex != kInputPortIndex) {
738 return OMX_ErrorUndefined;
741 mCtx->channels = profile->nChannels;
742 mCtx->sample_rate = profile->nSampleRate;
746 ALOGV("set OMX_IndexParamAudioFlac, nChannels:%lu, nSampleRate:%lu ",
747 profile->nChannels, profile->nSampleRate);
749 return OMX_ErrorNone;
752 case OMX_IndexParamAudioMp2:
754 OMX_AUDIO_PARAM_MP2TYPE *profile =
755 (OMX_AUDIO_PARAM_MP2TYPE *)params;
757 if (profile->nPortIndex != kInputPortIndex) {
758 return OMX_ErrorUndefined;
761 mCtx->channels = profile->nChannels;
762 mCtx->sample_rate = profile->nSampleRate;
766 ALOGV("set OMX_IndexParamAudioMp2, nChannels:%lu, nSampleRate:%lu",
767 profile->nChannels, profile->nSampleRate);
769 return OMX_ErrorNone;
772 case OMX_IndexParamAudioAc3:
774 OMX_AUDIO_PARAM_AC3TYPE *profile =
775 (OMX_AUDIO_PARAM_AC3TYPE *)params;
777 if (profile->nPortIndex != kInputPortIndex) {
778 return OMX_ErrorUndefined;
781 mCtx->channels = profile->nChannels;
782 mCtx->sample_rate = profile->nSamplingRate;
786 ALOGV("set OMX_IndexParamAudioAc3, nChannels:%lu, nSampleRate:%lu",
787 profile->nChannels, profile->nSamplingRate);
789 return OMX_ErrorNone;
792 case OMX_IndexParamAudioAndroidAc3:
794 OMX_AUDIO_PARAM_ANDROID_AC3TYPE *profile =
795 (OMX_AUDIO_PARAM_ANDROID_AC3TYPE *)params;
797 if (profile->nPortIndex != kInputPortIndex) {
798 return OMX_ErrorUndefined;
801 mCtx->channels = profile->nChannels;
802 mCtx->sample_rate = profile->nSampleRate;
806 ALOGV("set OMX_IndexParamAudioAndroidAc3, nChannels:%lu, nSampleRate:%lu",
807 profile->nChannels, profile->nSampleRate);
809 return OMX_ErrorNone;
813 case OMX_IndexParamAudioApe:
815 OMX_AUDIO_PARAM_APETYPE *profile =
816 (OMX_AUDIO_PARAM_APETYPE *)params;
818 if (profile->nPortIndex != kInputPortIndex) {
819 return OMX_ErrorUndefined;
822 mCtx->channels = profile->nChannels;
823 mCtx->sample_rate = profile->nSamplingRate;
824 mCtx->bits_per_coded_sample = profile->nBitsPerSample;
828 ALOGV("set OMX_IndexParamAudioApe, nChannels:%lu, "
829 "nSampleRate:%lu, nBitsPerSample:%lu",
830 profile->nChannels, profile->nSamplingRate,
831 profile->nBitsPerSample);
833 return OMX_ErrorNone;
836 case OMX_IndexParamAudioDts:
838 OMX_AUDIO_PARAM_DTSTYPE *profile =
839 (OMX_AUDIO_PARAM_DTSTYPE *)params;
841 if (profile->nPortIndex != kInputPortIndex) {
842 return OMX_ErrorUndefined;
845 mCtx->channels = profile->nChannels;
846 mCtx->sample_rate = profile->nSamplingRate;
850 ALOGV("set OMX_IndexParamAudioDts, nChannels:%lu, nSampleRate:%lu",
851 profile->nChannels, profile->nSamplingRate);
853 return OMX_ErrorNone;
856 case OMX_IndexParamAudioFFmpeg:
858 OMX_AUDIO_PARAM_FFMPEGTYPE *profile =
859 (OMX_AUDIO_PARAM_FFMPEGTYPE *)params;
861 if (profile->nPortIndex != kInputPortIndex) {
862 return OMX_ErrorUndefined;
865 mCtx->codec_id = (enum AVCodecID)profile->eCodecId;
866 mCtx->channels = profile->nChannels;
867 mCtx->bit_rate = profile->nBitRate;
868 mCtx->sample_rate = profile->nSampleRate;
869 mCtx->block_align = profile->nBlockAlign;
870 mCtx->bits_per_coded_sample = profile->nBitsPerSample;
871 mCtx->sample_fmt = (AVSampleFormat)profile->eSampleFormat;
875 ALOGD("set OMX_IndexParamAudioFFmpeg, "
876 "eCodecId:%ld(%s), nChannels:%lu, nBitRate:%lu, "
877 "nBitsPerSample:%lu, nSampleRate:%lu, "
878 "nBlockAlign:%lu, eSampleFormat:%lu(%s)",
879 profile->eCodecId, avcodec_get_name(mCtx->codec_id),
880 profile->nChannels, profile->nBitRate,
881 profile->nBitsPerSample, profile->nSampleRate,
882 profile->nBlockAlign, profile->eSampleFormat,
883 av_get_sample_fmt_name(mCtx->sample_fmt));
884 return OMX_ErrorNone;
889 return SimpleSoftOMXComponent::internalSetParameter(index, params);
893 int32_t SoftFFmpegAudio::handleVorbisExtradata(OMX_BUFFERHEADERTYPE *inHeader)
895 uint8_t *p = inHeader->pBuffer + inHeader->nOffset;
896 int len = inHeader->nFilledLen;
901 } else if (p[0] == 3) {
903 } else if (p[0] == 5) {
906 ALOGE("error vorbis codec config");
907 return ERR_INVALID_PARAM;
910 mVorbisHeaderStart[index] = (uint8_t *)av_mallocz(len);
911 if (!mVorbisHeaderStart[index]) {
912 ALOGE("oom for vorbis extradata");
915 memcpy(mVorbisHeaderStart[index], p, len);
916 mVorbisHeaderLen[index] = inHeader->nFilledLen;
921 int32_t SoftFFmpegAudio::handleExtradata() {
922 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
923 BufferInfo *inInfo = *inQueue.begin();
924 OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;
926 ALOGI("got extradata, ignore: %d, size: %lu",
927 mIgnoreExtradata, inHeader->nFilledLen);
928 hexdump(inHeader->pBuffer + inHeader->nOffset, inHeader->nFilledLen);
930 if (mIgnoreExtradata) {
931 ALOGI("got extradata, size: %lu, but ignore it", inHeader->nFilledLen);
933 if (!mExtradataReady) {
934 uint32_t ret = ERR_OK;
935 if (mCtx->codec_id == AV_CODEC_ID_VORBIS) {
936 if ((ret = handleVorbisExtradata(inHeader)) != ERR_OK) {
937 ALOGE("ffmpeg audio decoder failed to alloc vorbis extradata memory.");
941 int orig_extradata_size = mCtx->extradata_size;
942 mCtx->extradata_size += inHeader->nFilledLen;
943 mCtx->extradata = (uint8_t *)av_realloc(mCtx->extradata,
944 mCtx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
945 if (!mCtx->extradata) {
946 ALOGE("ffmpeg audio decoder failed to alloc extradata memory.");
950 memcpy(mCtx->extradata + orig_extradata_size,
951 inHeader->pBuffer + inHeader->nOffset, inHeader->nFilledLen);
952 memset(mCtx->extradata + mCtx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
957 inInfo->mOwnedByUs = false;
958 inQueue.erase(inQueue.begin());
960 notifyEmptyBufferDone(inHeader);
966 int32_t SoftFFmpegAudio::openDecoder() {
967 if (mCodecAlreadyOpened) {
971 if (!mExtradataReady && !mIgnoreExtradata) {
972 if (mCtx->codec_id == AV_CODEC_ID_VORBIS) {
973 if (!setup_vorbis_extradata(&mCtx->extradata,
974 &mCtx->extradata_size,
975 (const uint8_t **)mVorbisHeaderStart,
981 ALOGI("extradata is ready, size: %d", mCtx->extradata_size);
982 hexdump(mCtx->extradata, mCtx->extradata_size);
983 mExtradataReady = true;
987 mCtx->codec = avcodec_find_decoder(mCtx->codec_id);
989 ALOGE("ffmpeg audio decoder failed to find codec");
990 return ERR_CODEC_NOT_FOUND;
993 setDefaultCtx(mCtx, mCtx->codec);
995 ALOGD("begin to open ffmpeg audio decoder(%s), mCtx sample_rate: %d, channels: %d",
996 avcodec_get_name(mCtx->codec_id),
997 mCtx->sample_rate, mCtx->channels);
999 int err = avcodec_open2(mCtx, mCtx->codec, NULL);
1001 ALOGE("ffmpeg audio decoder failed to initialize.(%s)", av_err2str(err));
1002 return ERR_DECODER_OPEN_FAILED;
1004 mCodecAlreadyOpened = true;
1006 ALOGD("open ffmpeg audio decoder(%s) success, mCtx sample_rate: %d, "
1007 "channels: %d, sample_fmt: %s, bits_per_coded_sample: %d, bits_per_raw_sample: %d",
1008 avcodec_get_name(mCtx->codec_id),
1009 mCtx->sample_rate, mCtx->channels,
1010 av_get_sample_fmt_name(mCtx->sample_fmt),
1011 mCtx->bits_per_coded_sample, mCtx->bits_per_raw_sample);
1013 mFrame = av_frame_alloc();
1015 ALOGE("oom for video frame");
1019 mAudioSrcFmt = mCtx->sample_fmt;
1020 mAudioSrcChannels = mCtx->channels;
1021 mAudioSrcFreq = mCtx->sample_rate;
1022 mAudioSrcChannelLayout = av_get_default_channel_layout(mCtx->channels);
1027 void SoftFFmpegAudio::updateTimeStamp(OMX_BUFFERHEADERTYPE *inHeader) {
1028 CHECK_EQ(mInputBufferSize, 0);
1030 //XXX reset to AV_NOPTS_VALUE if the pts is invalid
1031 if (inHeader->nTimeStamp == SF_NOPTS_VALUE) {
1032 inHeader->nTimeStamp = AV_NOPTS_VALUE;
1035 //update the audio clock if the pts is valid
1036 if (inHeader->nTimeStamp != AV_NOPTS_VALUE) {
1037 setAudioClock(inHeader->nTimeStamp);
1041 void SoftFFmpegAudio::initPacket(AVPacket *pkt,
1042 OMX_BUFFERHEADERTYPE *inHeader) {
1043 memset(pkt, 0, sizeof(AVPacket));
1044 av_init_packet(pkt);
1047 pkt->data = (uint8_t *)inHeader->pBuffer + inHeader->nOffset;
1048 pkt->size = inHeader->nFilledLen;
1049 pkt->pts = inHeader->nTimeStamp; //ingore it, we will compute it
1053 pkt->pts = AV_NOPTS_VALUE;
1057 if (pkt->pts != AV_NOPTS_VALUE)
1059 ALOGV("pkt size:%d, pts:%lld", pkt->size, pkt->pts);
1061 ALOGV("pkt size:%d, pts:N/A", pkt->size);
1066 int32_t SoftFFmpegAudio::decodeAudio() {
1069 int32_t ret = ERR_OK;
1070 int32_t inputBufferUsedLength = 0;
1071 bool is_flush = (mEOSStatus != INPUT_DATA_AVAILABLE);
1072 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1073 BufferInfo *inInfo = NULL;
1074 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1076 CHECK_EQ(mResampledDataSize, 0);
1079 inInfo = *inQueue.begin();
1080 CHECK(inInfo != NULL);
1081 inHeader = inInfo->mHeader;
1083 if (mInputBufferSize == 0) {
1084 updateTimeStamp(inHeader);
1085 mInputBufferSize = inHeader->nFilledLen;
1090 initPacket(&pkt, inHeader);
1091 av_frame_unref(mFrame);
1093 len = avcodec_decode_audio4(mCtx, mFrame, &gotFrm, &pkt);
1094 //a negative error code is returned if an error occurred during decoding
1096 ALOGW("ffmpeg audio decoder err, we skip the frame and play silence instead");
1097 mResampledData = mSilenceBuffer;
1098 mResampledDataSize = kOutputBufferSize;
1102 ALOGV("ffmpeg audio decoder, consume pkt len: %d", len);
1106 ALOGI("ffmpeg audio decoder failed to get frame.");
1108 //stop sending empty packets if the decoder is finished
1109 if (is_flush && mCtx->codec->capabilities & CODEC_CAP_DELAY) {
1110 ALOGI("ffmpeg audio decoder failed to get more frames when flush.");
1116 ret = resampleAudio();
1122 //if error, we skip the frame
1123 inputBufferUsedLength = mInputBufferSize;
1125 inputBufferUsedLength = len;
1128 CHECK_GE(inHeader->nFilledLen, inputBufferUsedLength);
1129 inHeader->nOffset += inputBufferUsedLength;
1130 inHeader->nFilledLen -= inputBufferUsedLength;
1131 mInputBufferSize -= inputBufferUsedLength;
1133 if (inHeader->nFilledLen == 0) {
1134 CHECK_EQ(mInputBufferSize, 0);
1135 inQueue.erase(inQueue.begin());
1136 inInfo->mOwnedByUs = false;
1137 notifyEmptyBufferDone(inHeader);
1144 int32_t SoftFFmpegAudio::resampleAudio() {
1146 int64_t channelLayout = 0;
1147 size_t dataSize = 0;
1149 dataSize = av_samples_get_buffer_size(NULL, av_frame_get_channels(mFrame),
1150 mFrame->nb_samples, (enum AVSampleFormat)mFrame->format, 1);
1153 ALOGV("ffmpeg audio decoder, nb_samples:%d, get buffer size:%d",
1154 mFrame->nb_samples, dataSize);
1157 channels = av_get_channel_layout_nb_channels(mFrame->channel_layout);
1159 (mFrame->channel_layout && av_frame_get_channels(mFrame) == channels) ?
1160 mFrame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(mFrame));
1162 // Create if we're reconfiguring, if the format changed mid-stream, or
1163 // if the output format is actually different
1164 if ((mReconfiguring && mSwrCtx) || (!mSwrCtx
1165 && (mFrame->format != mAudioSrcFmt
1166 || channelLayout != mAudioSrcChannelLayout
1167 || (unsigned int)mFrame->sample_rate != mAudioSrcFreq
1168 || mAudioSrcFmt != mAudioTgtFmt
1169 || mAudioSrcChannelLayout != mAudioTgtChannelLayout
1170 || mAudioSrcFreq != mAudioTgtFreq))) {
1174 mSwrCtx = swr_alloc_set_opts(NULL,
1175 mAudioTgtChannelLayout, mAudioTgtFmt, mAudioTgtFreq,
1176 channelLayout, (enum AVSampleFormat)mFrame->format, mFrame->sample_rate,
1178 if (!mSwrCtx || swr_init(mSwrCtx) < 0) {
1179 ALOGE("Cannot create sample rate converter for conversion "
1180 "of %d Hz %s %d channels to %d Hz %s %d channels!",
1181 mFrame->sample_rate,
1182 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1183 av_frame_get_channels(mFrame),
1185 av_get_sample_fmt_name(mAudioTgtFmt),
1187 return ERR_SWR_INIT_FAILED;
1190 char src_layout_name[1024] = {0};
1191 char tgt_layout_name[1024] = {0};
1192 av_get_channel_layout_string(src_layout_name, sizeof(src_layout_name),
1193 mCtx->channels, channelLayout);
1194 av_get_channel_layout_string(tgt_layout_name, sizeof(tgt_layout_name),
1195 mAudioTgtChannels, mAudioTgtChannelLayout);
1196 ALOGI("Create sample rate converter for conversion "
1197 "of %d Hz %s %d channels(%s) "
1198 "to %d Hz %s %d channels(%s)!",
1199 mFrame->sample_rate,
1200 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1201 av_frame_get_channels(mFrame),
1204 av_get_sample_fmt_name(mAudioTgtFmt),
1208 mAudioSrcChannelLayout = channelLayout;
1209 mAudioSrcChannels = av_frame_get_channels(mFrame);
1210 mAudioSrcFreq = mFrame->sample_rate;
1211 mAudioSrcFmt = (enum AVSampleFormat)mFrame->format;
1212 mReconfiguring = false;
1216 const uint8_t **in = (const uint8_t **)mFrame->extended_data;
1217 uint8_t *out[] = {mAudioBuffer};
1218 int out_count = sizeof(mAudioBuffer) / mAudioTgtChannels / av_get_bytes_per_sample(mAudioTgtFmt);
1219 int out_size = av_samples_get_buffer_size(NULL, mAudioTgtChannels, out_count, mAudioTgtFmt, 0);
1222 ALOGE("av_samples_get_buffer_size() failed");
1223 return ERR_INVALID_PARAM;
1226 len2 = swr_convert(mSwrCtx, out, out_count, in, mFrame->nb_samples);
1228 ALOGE("audio_resample() failed");
1229 return ERR_RESAMPLE_FAILED;
1231 if (len2 == out_count) {
1232 ALOGE("warning: audio buffer is probably too small");
1235 mResampledData = mAudioBuffer;
1236 mResampledDataSize = len2 * mAudioTgtChannels * av_get_bytes_per_sample(mAudioTgtFmt);
1239 ALOGV("ffmpeg audio decoder(resample), mFrame->nb_samples:%d, len2:%d, mResampledDataSize:%d, "
1240 "src channel:%u, src fmt:%s, tgt channel:%u, tgt fmt:%s",
1241 mFrame->nb_samples, len2, mResampledDataSize,
1242 av_frame_get_channels(mFrame),
1243 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1245 av_get_sample_fmt_name(mAudioTgtFmt));
1248 mResampledData = mFrame->data[0];
1249 mResampledDataSize = dataSize;
1252 ALOGV("ffmpeg audio decoder(no resample),"
1253 "nb_samples(before resample):%d, mResampledDataSize:%d",
1254 mFrame->nb_samples, mResampledDataSize);
1261 void SoftFFmpegAudio::drainOneOutputBuffer() {
1262 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1263 BufferInfo *outInfo = *outQueue.begin();
1264 CHECK(outInfo != NULL);
1265 OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
1266 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1267 BufferInfo *inInfo = *inQueue.begin();
1268 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1270 if (inHeader != NULL) {
1271 inHeader = inInfo->mHeader;
1274 CHECK_GT(mResampledDataSize, 0);
1276 size_t copy = mResampledDataSize;
1277 if (mResampledDataSize > kOutputBufferSize) {
1278 copy = kOutputBufferSize;
1281 outHeader->nOffset = 0;
1282 outHeader->nFilledLen = copy;
1283 outHeader->nTimeStamp = getAudioClock();
1284 memcpy(outHeader->pBuffer, mResampledData, copy);
1285 outHeader->nFlags = 0;
1287 //update mResampledSize
1288 mResampledData += copy;
1289 mResampledDataSize -= copy;
1292 size_t frames = copy / (av_get_bytes_per_sample(mAudioTgtFmt) * mAudioTgtChannels);
1293 setAudioClock(getAudioClock() + ((frames * 1000000ll) / mAudioTgtFreq));
1296 ALOGV("ffmpeg audio decoder, fill out buffer, copy:%u, pts: %lld, clock: %lld",
1297 copy, outHeader->nTimeStamp, getAudioClock());
1300 outQueue.erase(outQueue.begin());
1301 outInfo->mOwnedByUs = false;
1302 notifyFillBufferDone(outHeader);
1305 void SoftFFmpegAudio::drainEOSOutputBuffer() {
1306 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1307 BufferInfo *outInfo = *outQueue.begin();
1308 CHECK(outInfo != NULL);
1309 OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
1311 // CHECK_EQ(mResampledDataSize, 0);
1313 ALOGD("ffmpeg audio decoder fill eos outbuf");
1315 outHeader->nTimeStamp = getAudioClock();
1316 outHeader->nFilledLen = 0;
1317 outHeader->nFlags = OMX_BUFFERFLAG_EOS;
1319 outQueue.erase(outQueue.begin());
1320 outInfo->mOwnedByUs = false;
1321 notifyFillBufferDone(outHeader);
1323 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1326 void SoftFFmpegAudio::drainAllOutputBuffers() {
1327 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1329 if (!mCodecAlreadyOpened) {
1330 drainEOSOutputBuffer();
1331 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1335 if(!(mCtx->codec->capabilities & CODEC_CAP_DELAY)) {
1336 drainEOSOutputBuffer();
1337 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1341 while (!outQueue.empty()) {
1342 if (mResampledDataSize == 0) {
1343 int32_t err = decodeAudio();
1345 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1346 mSignalledError = true;
1348 } else if (err == ERR_FLUSHED) {
1349 drainEOSOutputBuffer();
1352 CHECK_EQ(err, ERR_OK);
1356 if (mResampledDataSize > 0) {
1357 drainOneOutputBuffer();
1362 void SoftFFmpegAudio::onQueueFilled(OMX_U32 /* portIndex */) {
1363 BufferInfo *inInfo = NULL;
1364 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1366 if (mSignalledError || mOutputPortSettingsChange != NONE) {
1370 if (mEOSStatus == OUTPUT_FRAMES_FLUSHED) {
1374 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1375 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1377 while (((mEOSStatus != INPUT_DATA_AVAILABLE) || !inQueue.empty())
1378 && !outQueue.empty()) {
1380 if (mEOSStatus == INPUT_EOS_SEEN) {
1381 drainAllOutputBuffers();
1385 inInfo = *inQueue.begin();
1386 inHeader = inInfo->mHeader;
1388 if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
1389 ALOGD("ffmpeg audio decoder empty eos inbuf");
1390 inQueue.erase(inQueue.begin());
1391 inInfo->mOwnedByUs = false;
1392 notifyEmptyBufferDone(inHeader);
1393 mEOSStatus = INPUT_EOS_SEEN;
1397 if (inHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
1398 if (handleExtradata() != ERR_OK) {
1399 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1400 mSignalledError = true;
1406 if (!mCodecAlreadyOpened) {
1407 if (openDecoder() != ERR_OK) {
1408 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1409 mSignalledError = true;
1414 if (mResampledDataSize == 0) {
1415 int32_t err = decodeAudio();
1417 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1418 mSignalledError = true;
1420 } else if (err == ERR_NO_FRM) {
1421 CHECK_EQ(mResampledDataSize, 0);
1424 CHECK_EQ(err, ERR_OK);
1428 if (mResampledDataSize > 0) {
1429 drainOneOutputBuffer();
1434 void SoftFFmpegAudio::onPortFlushCompleted(OMX_U32 portIndex) {
1435 ALOGV("ffmpeg audio decoder flush port(%lu)", portIndex);
1436 if (portIndex == kInputPortIndex) {
1437 if (mCtx && mCtx->codec) {
1438 //Make sure that the next buffer output does not still
1439 //depend on fragments from the last one decoded.
1440 avcodec_flush_buffers(mCtx);
1444 mInputBufferSize = 0;
1445 mResampledDataSize = 0;
1446 mResampledData = NULL;
1447 mEOSStatus = INPUT_DATA_AVAILABLE;
1451 void SoftFFmpegAudio::onPortEnableCompleted(OMX_U32 portIndex, bool enabled) {
1452 if (portIndex != kOutputPortIndex) {
1456 switch (mOutputPortSettingsChange) {
1460 case AWAITING_DISABLED:
1463 mOutputPortSettingsChange = AWAITING_ENABLED;
1469 CHECK_EQ((int)mOutputPortSettingsChange, (int)AWAITING_ENABLED);
1471 mOutputPortSettingsChange = NONE;
1477 int64_t SoftFFmpegAudio::getAudioClock() {
1478 if (sAudioClock == NULL) {
1479 sAudioClock = (int64_t*) malloc(sizeof(int64_t));
1482 ALOGV("getAudioClock: %lld", *sAudioClock);
1483 return *sAudioClock;
1486 void SoftFFmpegAudio::setAudioClock(int64_t ticks) {
1487 if (sAudioClock == NULL) {
1488 sAudioClock = (int64_t*) malloc(sizeof(int64_t));
1490 *sAudioClock = ticks;
1493 void SoftFFmpegAudio::onReset() {
1494 enum AVCodecID codecID = mCtx->codec_id;
1496 initDecoder(codecID);
1497 mSignalledError = false;
1498 mOutputPortSettingsChange = NONE;
1501 SoftOMXComponent* SoftFFmpegAudio::createSoftOMXComponent(
1502 const char *name, const OMX_CALLBACKTYPE *callbacks,
1503 OMX_PTR appData, OMX_COMPONENTTYPE **component) {
1504 OMX_AUDIO_CODINGTYPE codingType = OMX_AUDIO_CodingAutoDetect;
1505 char *componentRole = NULL;
1506 enum AVCodecID codecID = AV_CODEC_ID_NONE;
1508 for (size_t i = 0; i < kNumAudioComponents; ++i) {
1509 if (!strcasecmp(name, kAudioComponents[i].mName)) {
1510 componentRole = strdup(kAudioComponents[i].mRole);
1511 codingType = kAudioComponents[i].mAudioCodingType;
1512 codecID = kAudioComponents[i].mCodecID;
1517 return new SoftFFmpegAudio(name, componentRole, codingType, codecID,
1518 callbacks, appData, component);
1521 } // namespace android