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 = 32 * 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) {
248 mCodecAlreadyOpened = false;
261 OMX_ERRORTYPE SoftFFmpegAudio::internalGetParameter(
262 OMX_INDEXTYPE index, OMX_PTR params) {
263 ALOGV("internalGetParameter index:0x%x", index);
264 switch ((int)index) {
265 case OMX_IndexParamAudioPcm:
267 OMX_AUDIO_PARAM_PCMMODETYPE *profile =
268 (OMX_AUDIO_PARAM_PCMMODETYPE *)params;
270 if (profile->nPortIndex > kOutputPortIndex) {
271 return OMX_ErrorUndefined;
274 profile->eNumData = OMX_NumericalDataSigned;
275 profile->eEndian = OMX_EndianBig;
276 profile->bInterleaved = OMX_TRUE;
277 profile->ePCMMode = OMX_AUDIO_PCMModeLinear;
279 if (isConfigured()) {
280 AVSampleFormat packed = av_get_packed_sample_fmt(mAudioTgtFmt);
281 if (packed == AV_SAMPLE_FMT_U8)
282 profile->nBitPerSample = 8;
283 else if (packed == AV_SAMPLE_FMT_S16)
284 profile->nBitPerSample = 16;
285 else if (packed == AV_SAMPLE_FMT_S32)
286 profile->nBitPerSample = 24;
288 profile->nBitPerSample = av_get_bytes_per_sample(mAudioTgtFmt) * 8;
290 profile->nBitPerSample = 32;
293 if (getOMXChannelMapping(mAudioTgtChannels, profile->eChannelMapping) != OK) {
294 return OMX_ErrorNone;
297 profile->nChannels = mAudioTgtChannels;
298 profile->nSamplingRate = mAudioTgtFreq;
300 //mCtx has been updated(adjustAudioParams)!
301 ALOGV("get pcm params, nChannels:%u, nSamplingRate:%u, nBitsPerSample:%u",
302 profile->nChannels, profile->nSamplingRate, profile->nBitPerSample);
304 return OMX_ErrorNone;
307 case OMX_IndexParamAudioAac:
309 OMX_AUDIO_PARAM_AACPROFILETYPE *profile =
310 (OMX_AUDIO_PARAM_AACPROFILETYPE *)params;
312 if (profile->nPortIndex != kInputPortIndex) {
313 return OMX_ErrorUndefined;
316 profile->nBitRate = 0;
317 profile->nAudioBandWidth = 0;
318 profile->nAACtools = 0;
319 profile->nAACERtools = 0;
320 profile->eAACProfile = OMX_AUDIO_AACObjectMain;
321 profile->eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4FF;
322 profile->eChannelMode = OMX_AUDIO_ChannelModeStereo;
324 profile->nChannels = mCtx->channels;
325 profile->nSampleRate = mCtx->sample_rate;
327 return OMX_ErrorNone;
330 case OMX_IndexParamAudioMp3:
332 OMX_AUDIO_PARAM_MP3TYPE *profile =
333 (OMX_AUDIO_PARAM_MP3TYPE *)params;
335 if (profile->nPortIndex != kInputPortIndex) {
336 return OMX_ErrorUndefined;
339 profile->nBitRate = 0;
340 profile->nAudioBandWidth = 0;
341 profile->eChannelMode = OMX_AUDIO_ChannelModeStereo;
342 profile->eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3;
344 profile->nChannels = mCtx->channels;
345 profile->nSampleRate = mCtx->sample_rate;
347 return OMX_ErrorNone;
349 case OMX_IndexParamAudioVorbis:
351 OMX_AUDIO_PARAM_VORBISTYPE *profile =
352 (OMX_AUDIO_PARAM_VORBISTYPE *)params;
354 if (profile->nPortIndex != kInputPortIndex) {
355 return OMX_ErrorUndefined;
358 profile->nBitRate = 0;
359 profile->nMinBitRate = 0;
360 profile->nMaxBitRate = 0;
361 profile->nAudioBandWidth = 0;
362 profile->nQuality = 3;
363 profile->bManaged = OMX_FALSE;
364 profile->bDownmix = OMX_FALSE;
366 profile->nChannels = mCtx->channels;
367 profile->nSampleRate = mCtx->sample_rate;
369 return OMX_ErrorNone;
372 case OMX_IndexParamAudioWma:
374 OMX_AUDIO_PARAM_WMATYPE *profile =
375 (OMX_AUDIO_PARAM_WMATYPE *)params;
377 if (profile->nPortIndex != kInputPortIndex) {
378 return OMX_ErrorUndefined;
381 profile->eFormat = OMX_AUDIO_WMAFormatUnused;
383 profile->nChannels = mCtx->channels;
384 profile->nSamplingRate = mCtx->sample_rate;
386 profile->nBlockAlign = mCtx->block_align;
387 profile->nBitRate = mCtx->bit_rate;
389 return OMX_ErrorNone;
392 case OMX_IndexParamAudioRa:
394 OMX_AUDIO_PARAM_RATYPE *profile =
395 (OMX_AUDIO_PARAM_RATYPE *)params;
397 if (profile->nPortIndex != kInputPortIndex) {
398 return OMX_ErrorUndefined;
401 profile->eFormat = OMX_AUDIO_RAFormatUnused;
403 profile->nChannels = mCtx->channels;
404 profile->nSamplingRate = mCtx->sample_rate;
406 profile->nNumRegions = mCtx->block_align;
408 return OMX_ErrorNone;
411 case OMX_IndexParamAudioFlac:
413 OMX_AUDIO_PARAM_FLACTYPE *profile =
414 (OMX_AUDIO_PARAM_FLACTYPE *)params;
416 if (profile->nPortIndex != kInputPortIndex) {
417 return OMX_ErrorUndefined;
420 profile->nChannels = mCtx->channels;
421 profile->nSampleRate = mCtx->sample_rate;
423 return OMX_ErrorNone;
426 case OMX_IndexParamAudioMp2:
428 OMX_AUDIO_PARAM_MP2TYPE *profile =
429 (OMX_AUDIO_PARAM_MP2TYPE *)params;
431 if (profile->nPortIndex != kInputPortIndex) {
432 return OMX_ErrorUndefined;
435 profile->nChannels = mCtx->channels;
436 profile->nSampleRate = mCtx->sample_rate;
438 return OMX_ErrorNone;
441 case OMX_IndexParamAudioAndroidAc3:
443 OMX_AUDIO_PARAM_ANDROID_AC3TYPE *profile =
444 (OMX_AUDIO_PARAM_ANDROID_AC3TYPE *)params;
446 if (profile->nPortIndex != kInputPortIndex) {
447 return OMX_ErrorUndefined;
450 profile->nChannels = mCtx->channels;
451 profile->nSampleRate = mCtx->sample_rate;
453 return OMX_ErrorNone;
457 case OMX_IndexParamAudioAc3:
459 OMX_AUDIO_PARAM_AC3TYPE *profile =
460 (OMX_AUDIO_PARAM_AC3TYPE *)params;
462 if (profile->nPortIndex != kInputPortIndex) {
463 return OMX_ErrorUndefined;
466 profile->nChannels = mCtx->channels;
467 profile->nSamplingRate = mCtx->sample_rate;
469 return OMX_ErrorNone;
472 case OMX_IndexParamAudioApe:
474 OMX_AUDIO_PARAM_APETYPE *profile =
475 (OMX_AUDIO_PARAM_APETYPE *)params;
477 if (profile->nPortIndex != kInputPortIndex) {
478 return OMX_ErrorUndefined;
481 profile->nChannels = mCtx->channels;
482 profile->nSamplingRate = mCtx->sample_rate;
484 profile->nBitsPerSample = mCtx->bits_per_coded_sample;
486 return OMX_ErrorNone;
489 case OMX_IndexParamAudioDts:
491 OMX_AUDIO_PARAM_DTSTYPE *profile =
492 (OMX_AUDIO_PARAM_DTSTYPE *)params;
494 if (profile->nPortIndex != kInputPortIndex) {
495 return OMX_ErrorUndefined;
498 profile->nChannels = mCtx->channels;
499 profile->nSamplingRate = mCtx->sample_rate;
501 return OMX_ErrorNone;
504 case OMX_IndexParamAudioFFmpeg:
506 OMX_AUDIO_PARAM_FFMPEGTYPE *profile =
507 (OMX_AUDIO_PARAM_FFMPEGTYPE *)params;
509 if (profile->nPortIndex != kInputPortIndex) {
510 return OMX_ErrorUndefined;
513 profile->eCodecId = mCtx->codec_id;
514 profile->nBitRate = mCtx->bit_rate;
515 profile->nBlockAlign = mCtx->block_align;
517 profile->nBitsPerSample = mCtx->bits_per_raw_sample;
518 profile->eSampleFormat = mCtx->sample_fmt;
520 profile->nChannels = mCtx->channels;
521 profile->nSampleRate = mCtx->sample_rate;
523 return OMX_ErrorNone;
528 return SimpleSoftOMXComponent::internalGetParameter(index, params);
532 OMX_ERRORTYPE SoftFFmpegAudio::isRoleSupported(
533 const OMX_PARAM_COMPONENTROLETYPE *roleParams) {
534 for (size_t i = 0; i < kNumAudioComponents; i++) {
535 if (mCodingType == kAudioComponents[i].mAudioCodingType &&
536 strncmp((const char *)roleParams->cRole,
537 kAudioComponents[i].mRole, OMX_MAX_STRINGNAME_SIZE - 1) == 0) {
538 return OMX_ErrorNone;
541 ALOGE("unsupported role: %s", (const char *)roleParams->cRole);
542 return OMX_ErrorUndefined;
545 void SoftFFmpegAudio::adjustAudioParams() {
547 mReconfiguring = isConfigured();
549 // let android audio mixer to downmix if there is no multichannel output
550 // and use number of channels from the source file, useful for HDMI/offload output
551 mAudioTgtChannels = mCtx->channels;
553 mAudioTgtFreq = FFMIN(192000, FFMAX(8000, mCtx->sample_rate));
555 mAudioTgtChannels = mCtx->channels;
556 mAudioTgtFreq = mCtx->sample_rate;
558 mAudioTgtChannelLayout = av_get_default_channel_layout(mAudioTgtChannels);
560 ALOGV("adjustAudioParams: [channels=%d freq=%d fmt=%s]",
561 mCtx->channels, mCtx->sample_rate, av_get_sample_fmt_name(mAudioTgtFmt));
564 OMX_ERRORTYPE SoftFFmpegAudio::internalSetParameter(
565 OMX_INDEXTYPE index, const OMX_PTR params) {
566 //ALOGV("internalSetParameter index:0x%x", index);
567 switch ((int)index) {
568 case OMX_IndexParamStandardComponentRole:
570 const OMX_PARAM_COMPONENTROLETYPE *roleParams =
571 (const OMX_PARAM_COMPONENTROLETYPE *)params;
572 return isRoleSupported(roleParams);
575 case OMX_IndexParamAudioPcm:
577 const OMX_AUDIO_PARAM_PCMMODETYPE *profile =
578 (const OMX_AUDIO_PARAM_PCMMODETYPE *)params;
580 if (profile->nPortIndex != kOutputPortIndex) {
581 return OMX_ErrorUndefined;
584 if (profile->nBitPerSample == 24) {
585 mAudioTgtFmt = AV_SAMPLE_FMT_S32;
586 } else if (profile->nBitPerSample == 32) {
587 mAudioTgtFmt = AV_SAMPLE_FMT_FLT;
588 } else if (profile->nBitPerSample == 8) {
589 mAudioTgtFmt = AV_SAMPLE_FMT_U8;
591 mAudioTgtFmt = AV_SAMPLE_FMT_S16;
594 mAudioTgtFreq = profile->nSamplingRate;
595 mAudioTgtChannels = profile->nChannels;
597 ALOGV("set OMX_IndexParamAudioPcm, nChannels:%u, "
598 "nSampleRate:%u, nBitsPerSample:%u",
599 profile->nChannels, profile->nSamplingRate,
600 profile->nBitPerSample);
602 return OMX_ErrorNone;
605 case OMX_IndexParamAudioAac:
607 const OMX_AUDIO_PARAM_AACPROFILETYPE *profile =
608 (const OMX_AUDIO_PARAM_AACPROFILETYPE *)params;
610 if (profile->nPortIndex != kInputPortIndex) {
611 return OMX_ErrorUndefined;
614 mCtx->channels = profile->nChannels;
615 mCtx->sample_rate = profile->nSampleRate;
619 ALOGV("set OMX_IndexParamAudioAac, nChannels:%u, nSampleRate:%u",
620 profile->nChannels, profile->nSampleRate);
622 return OMX_ErrorNone;
625 case OMX_IndexParamAudioMp3:
627 const OMX_AUDIO_PARAM_MP3TYPE *profile =
628 (const OMX_AUDIO_PARAM_MP3TYPE *)params;
630 if (profile->nPortIndex != kInputPortIndex) {
631 return OMX_ErrorUndefined;
634 mCtx->channels = profile->nChannels;
635 mCtx->sample_rate = profile->nSampleRate;
639 ALOGV("set OMX_IndexParamAudioMp3, nChannels:%u, nSampleRate:%u",
640 profile->nChannels, profile->nSampleRate);
642 return OMX_ErrorNone;
645 case OMX_IndexParamAudioVorbis:
647 const OMX_AUDIO_PARAM_VORBISTYPE *profile =
648 (const OMX_AUDIO_PARAM_VORBISTYPE *)params;
650 if (profile->nPortIndex != kInputPortIndex) {
651 return OMX_ErrorUndefined;
654 mCtx->channels = profile->nChannels;
655 mCtx->sample_rate = profile->nSampleRate;
659 ALOGD("set OMX_IndexParamAudioVorbis, "
660 "nChannels=%u, nSampleRate=%u, nBitRate=%u, "
661 "nMinBitRate=%u, nMaxBitRate=%u",
662 profile->nChannels, profile->nSampleRate,
663 profile->nBitRate, profile->nMinBitRate,
664 profile->nMaxBitRate);
666 return OMX_ErrorNone;
669 case OMX_IndexParamAudioWma:
671 OMX_AUDIO_PARAM_WMATYPE *profile =
672 (OMX_AUDIO_PARAM_WMATYPE *)params;
674 if (profile->nPortIndex != kInputPortIndex) {
675 return OMX_ErrorUndefined;
678 if (profile->eFormat == OMX_AUDIO_WMAFormat7) {
679 mCtx->codec_id = AV_CODEC_ID_WMAV2;
680 } else if (profile->eFormat == OMX_AUDIO_WMAFormat8) {
681 mCtx->codec_id = AV_CODEC_ID_WMAPRO;
682 } else if (profile->eFormat == OMX_AUDIO_WMAFormat9) {
683 mCtx->codec_id = AV_CODEC_ID_WMALOSSLESS;
685 ALOGE("unsupported wma codec: 0x%x", profile->eFormat);
686 return OMX_ErrorUndefined;
689 mCtx->channels = profile->nChannels;
690 mCtx->sample_rate = profile->nSamplingRate;
692 // wmadec needs bitrate, block_align
693 mCtx->bit_rate = profile->nBitRate;
694 mCtx->block_align = profile->nBlockAlign;
698 ALOGV("set OMX_IndexParamAudioWma, nChannels:%u, "
699 "nSampleRate:%u, nBitRate:%u, nBlockAlign:%u",
700 profile->nChannels, profile->nSamplingRate,
701 profile->nBitRate, profile->nBlockAlign);
703 return OMX_ErrorNone;
706 case OMX_IndexParamAudioRa:
708 OMX_AUDIO_PARAM_RATYPE *profile =
709 (OMX_AUDIO_PARAM_RATYPE *)params;
711 if (profile->nPortIndex != kInputPortIndex) {
712 return OMX_ErrorUndefined;
715 mCtx->channels = profile->nChannels;
716 mCtx->sample_rate = profile->nSamplingRate;
718 // FIXME, HACK!!!, I use the nNumRegions parameter pass blockAlign!!!
719 // the cook audio codec need blockAlign!
720 mCtx->block_align = profile->nNumRegions;
724 ALOGV("set OMX_IndexParamAudioRa, nChannels:%u, "
725 "nSampleRate:%u, nBlockAlign:%d",
726 profile->nChannels, profile->nSamplingRate, mCtx->block_align);
728 return OMX_ErrorNone;
731 case OMX_IndexParamAudioFlac:
733 OMX_AUDIO_PARAM_FLACTYPE *profile =
734 (OMX_AUDIO_PARAM_FLACTYPE *)params;
736 if (profile->nPortIndex != kInputPortIndex) {
737 return OMX_ErrorUndefined;
740 mCtx->channels = profile->nChannels;
741 mCtx->sample_rate = profile->nSampleRate;
745 ALOGV("set OMX_IndexParamAudioFlac, nChannels:%u, nSampleRate:%u ",
746 profile->nChannels, profile->nSampleRate);
748 return OMX_ErrorNone;
751 case OMX_IndexParamAudioMp2:
753 OMX_AUDIO_PARAM_MP2TYPE *profile =
754 (OMX_AUDIO_PARAM_MP2TYPE *)params;
756 if (profile->nPortIndex != kInputPortIndex) {
757 return OMX_ErrorUndefined;
760 mCtx->channels = profile->nChannels;
761 mCtx->sample_rate = profile->nSampleRate;
765 ALOGV("set OMX_IndexParamAudioMp2, nChannels:%u, nSampleRate:%u",
766 profile->nChannels, profile->nSampleRate);
768 return OMX_ErrorNone;
771 case OMX_IndexParamAudioAc3:
773 OMX_AUDIO_PARAM_AC3TYPE *profile =
774 (OMX_AUDIO_PARAM_AC3TYPE *)params;
776 if (profile->nPortIndex != kInputPortIndex) {
777 return OMX_ErrorUndefined;
780 mCtx->channels = profile->nChannels;
781 mCtx->sample_rate = profile->nSamplingRate;
785 ALOGV("set OMX_IndexParamAudioAc3, nChannels:%u, nSampleRate:%u",
786 profile->nChannels, profile->nSamplingRate);
788 return OMX_ErrorNone;
791 case OMX_IndexParamAudioAndroidAc3:
793 OMX_AUDIO_PARAM_ANDROID_AC3TYPE *profile =
794 (OMX_AUDIO_PARAM_ANDROID_AC3TYPE *)params;
796 if (profile->nPortIndex != kInputPortIndex) {
797 return OMX_ErrorUndefined;
800 mCtx->channels = profile->nChannels;
801 mCtx->sample_rate = profile->nSampleRate;
805 ALOGV("set OMX_IndexParamAudioAndroidAc3, nChannels:%u, nSampleRate:%u",
806 profile->nChannels, profile->nSampleRate);
808 return OMX_ErrorNone;
812 case OMX_IndexParamAudioApe:
814 OMX_AUDIO_PARAM_APETYPE *profile =
815 (OMX_AUDIO_PARAM_APETYPE *)params;
817 if (profile->nPortIndex != kInputPortIndex) {
818 return OMX_ErrorUndefined;
821 mCtx->channels = profile->nChannels;
822 mCtx->sample_rate = profile->nSamplingRate;
823 mCtx->bits_per_coded_sample = profile->nBitsPerSample;
827 ALOGV("set OMX_IndexParamAudioApe, nChannels:%u, "
828 "nSampleRate:%u, nBitsPerSample:%u",
829 profile->nChannels, profile->nSamplingRate,
830 profile->nBitsPerSample);
832 return OMX_ErrorNone;
835 case OMX_IndexParamAudioDts:
837 OMX_AUDIO_PARAM_DTSTYPE *profile =
838 (OMX_AUDIO_PARAM_DTSTYPE *)params;
840 if (profile->nPortIndex != kInputPortIndex) {
841 return OMX_ErrorUndefined;
844 mCtx->channels = profile->nChannels;
845 mCtx->sample_rate = profile->nSamplingRate;
849 ALOGV("set OMX_IndexParamAudioDts, nChannels:%u, nSampleRate:%u",
850 profile->nChannels, profile->nSamplingRate);
852 return OMX_ErrorNone;
855 case OMX_IndexParamAudioFFmpeg:
857 OMX_AUDIO_PARAM_FFMPEGTYPE *profile =
858 (OMX_AUDIO_PARAM_FFMPEGTYPE *)params;
860 if (profile->nPortIndex != kInputPortIndex) {
861 return OMX_ErrorUndefined;
864 mCtx->codec_id = (enum AVCodecID)profile->eCodecId;
865 mCtx->channels = profile->nChannels;
866 mCtx->bit_rate = profile->nBitRate;
867 mCtx->sample_rate = profile->nSampleRate;
868 mCtx->block_align = profile->nBlockAlign;
869 mCtx->bits_per_coded_sample = profile->nBitsPerSample;
870 mCtx->sample_fmt = (AVSampleFormat)profile->eSampleFormat;
874 ALOGD("set OMX_IndexParamAudioFFmpeg, "
875 "eCodecId:%d(%s), nChannels:%u, nBitRate:%u, "
876 "nBitsPerSample:%u, nSampleRate:%u, "
877 "nBlockAlign:%u, eSampleFormat:%u(%s)",
878 profile->eCodecId, avcodec_get_name(mCtx->codec_id),
879 profile->nChannels, profile->nBitRate,
880 profile->nBitsPerSample, profile->nSampleRate,
881 profile->nBlockAlign, profile->eSampleFormat,
882 av_get_sample_fmt_name(mCtx->sample_fmt));
883 return OMX_ErrorNone;
888 return SimpleSoftOMXComponent::internalSetParameter(index, params);
892 int32_t SoftFFmpegAudio::handleVorbisExtradata(OMX_BUFFERHEADERTYPE *inHeader)
894 uint8_t *p = inHeader->pBuffer + inHeader->nOffset;
895 int len = inHeader->nFilledLen;
900 } else if (p[0] == 3) {
902 } else if (p[0] == 5) {
905 ALOGE("error vorbis codec config");
906 return ERR_INVALID_PARAM;
909 mVorbisHeaderStart[index] = (uint8_t *)av_mallocz(len);
910 if (!mVorbisHeaderStart[index]) {
911 ALOGE("oom for vorbis extradata");
914 memcpy(mVorbisHeaderStart[index], p, len);
915 mVorbisHeaderLen[index] = inHeader->nFilledLen;
920 int32_t SoftFFmpegAudio::handleExtradata() {
921 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
922 BufferInfo *inInfo = *inQueue.begin();
923 OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;
925 ALOGI("got extradata, ignore: %d, size: %u",
926 mIgnoreExtradata, inHeader->nFilledLen);
927 hexdump(inHeader->pBuffer + inHeader->nOffset, inHeader->nFilledLen);
929 if (mIgnoreExtradata) {
930 ALOGI("got extradata, size: %u, but ignore it", inHeader->nFilledLen);
932 if (!mExtradataReady) {
933 uint32_t ret = ERR_OK;
934 if (mCtx->codec_id == AV_CODEC_ID_VORBIS) {
935 if ((ret = handleVorbisExtradata(inHeader)) != ERR_OK) {
936 ALOGE("ffmpeg audio decoder failed to alloc vorbis extradata memory.");
940 int orig_extradata_size = mCtx->extradata_size;
941 mCtx->extradata_size += inHeader->nFilledLen;
942 mCtx->extradata = (uint8_t *)av_realloc(mCtx->extradata,
943 mCtx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
944 if (!mCtx->extradata) {
945 ALOGE("ffmpeg audio decoder failed to alloc extradata memory.");
949 memcpy(mCtx->extradata + orig_extradata_size,
950 inHeader->pBuffer + inHeader->nOffset, inHeader->nFilledLen);
951 memset(mCtx->extradata + mCtx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
956 inInfo->mOwnedByUs = false;
957 inQueue.erase(inQueue.begin());
959 notifyEmptyBufferDone(inHeader);
965 int32_t SoftFFmpegAudio::openDecoder() {
966 if (mCodecAlreadyOpened) {
970 if (!mExtradataReady && !mIgnoreExtradata) {
971 if (mCtx->codec_id == AV_CODEC_ID_VORBIS) {
972 if (!setup_vorbis_extradata(&mCtx->extradata,
973 &mCtx->extradata_size,
974 (const uint8_t **)mVorbisHeaderStart,
980 ALOGI("extradata is ready, size: %d", mCtx->extradata_size);
981 hexdump(mCtx->extradata, mCtx->extradata_size);
982 mExtradataReady = true;
986 mCtx->codec = avcodec_find_decoder(mCtx->codec_id);
988 ALOGE("ffmpeg audio decoder failed to find codec");
989 return ERR_CODEC_NOT_FOUND;
992 setDefaultCtx(mCtx, mCtx->codec);
994 ALOGD("begin to open ffmpeg audio decoder(%s), mCtx sample_rate: %d, channels: %d",
995 avcodec_get_name(mCtx->codec_id),
996 mCtx->sample_rate, mCtx->channels);
998 int err = avcodec_open2(mCtx, mCtx->codec, NULL);
1000 ALOGE("ffmpeg audio decoder failed to initialize.(%s)", av_err2str(err));
1001 return ERR_DECODER_OPEN_FAILED;
1003 mCodecAlreadyOpened = true;
1005 ALOGD("open ffmpeg audio decoder(%s) success, mCtx sample_rate: %d, "
1006 "channels: %d, sample_fmt: %s, bits_per_coded_sample: %d, bits_per_raw_sample: %d",
1007 avcodec_get_name(mCtx->codec_id),
1008 mCtx->sample_rate, mCtx->channels,
1009 av_get_sample_fmt_name(mCtx->sample_fmt),
1010 mCtx->bits_per_coded_sample, mCtx->bits_per_raw_sample);
1012 mFrame = av_frame_alloc();
1014 ALOGE("oom for video frame");
1018 mAudioSrcFmt = mCtx->sample_fmt;
1019 mAudioSrcChannels = mCtx->channels;
1020 mAudioSrcFreq = mCtx->sample_rate;
1021 mAudioSrcChannelLayout = av_get_default_channel_layout(mCtx->channels);
1026 void SoftFFmpegAudio::updateTimeStamp(OMX_BUFFERHEADERTYPE *inHeader) {
1027 CHECK_EQ(mInputBufferSize, 0);
1029 //XXX reset to AV_NOPTS_VALUE if the pts is invalid
1030 if (inHeader->nTimeStamp == SF_NOPTS_VALUE) {
1031 inHeader->nTimeStamp = AV_NOPTS_VALUE;
1034 //update the audio clock if the pts is valid
1035 if (inHeader->nTimeStamp != AV_NOPTS_VALUE) {
1036 setAudioClock(inHeader->nTimeStamp);
1040 void SoftFFmpegAudio::initPacket(AVPacket *pkt,
1041 OMX_BUFFERHEADERTYPE *inHeader) {
1042 memset(pkt, 0, sizeof(AVPacket));
1043 av_init_packet(pkt);
1046 pkt->data = (uint8_t *)inHeader->pBuffer + inHeader->nOffset;
1047 pkt->size = inHeader->nFilledLen;
1048 pkt->pts = inHeader->nTimeStamp; //ingore it, we will compute it
1052 pkt->pts = AV_NOPTS_VALUE;
1056 if (pkt->pts != AV_NOPTS_VALUE)
1058 ALOGV("pkt size:%d, pts:%lld", pkt->size, pkt->pts);
1060 ALOGV("pkt size:%d, pts:N/A", pkt->size);
1065 int32_t SoftFFmpegAudio::decodeAudio() {
1068 int32_t ret = ERR_OK;
1069 int32_t inputBufferUsedLength = 0;
1070 bool is_flush = (mEOSStatus == OUTPUT_FRAMES_FLUSHED);
1071 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1072 BufferInfo *inInfo = NULL;
1073 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1075 CHECK_EQ(mResampledDataSize, 0);
1077 if (!is_flush && !inQueue.empty()) {
1078 inInfo = *inQueue.begin();
1079 if (inInfo != NULL) {
1080 inHeader = inInfo->mHeader;
1082 if (mInputBufferSize == 0) {
1083 updateTimeStamp(inHeader);
1084 mInputBufferSize = inHeader->nFilledLen;
1089 if (mEOSStatus == INPUT_EOS_SEEN && (!inHeader || inHeader->nFilledLen == 0)
1090 && !(mCtx->codec->capabilities & CODEC_CAP_DELAY)) {
1095 initPacket(&pkt, inHeader);
1096 av_frame_unref(mFrame);
1098 len = avcodec_decode_audio4(mCtx, mFrame, &gotFrm, &pkt);
1099 //a negative error code is returned if an error occurred during decoding
1101 ALOGW("ffmpeg audio decoder err, we skip the frame and play silence instead");
1102 mResampledData = mSilenceBuffer;
1103 mResampledDataSize = kOutputBufferSize;
1107 ALOGV("ffmpeg audio decoder, consume pkt len: %d", len);
1111 ALOGI("ffmpeg audio decoder failed to get frame.");
1113 //stop sending empty packets if the decoder is finished
1114 if (is_flush && mCtx->codec->capabilities & CODEC_CAP_DELAY) {
1115 ALOGI("ffmpeg audio decoder failed to get more frames when flush.");
1121 ret = resampleAudio();
1127 //if error, we skip the frame
1128 inputBufferUsedLength = mInputBufferSize;
1130 inputBufferUsedLength = len;
1133 CHECK_GE(inHeader->nFilledLen, inputBufferUsedLength);
1134 inHeader->nOffset += inputBufferUsedLength;
1135 inHeader->nFilledLen -= inputBufferUsedLength;
1136 mInputBufferSize -= inputBufferUsedLength;
1138 if (inHeader->nFilledLen == 0) {
1139 CHECK_EQ(mInputBufferSize, 0);
1140 inQueue.erase(inQueue.begin());
1141 inInfo->mOwnedByUs = false;
1142 notifyEmptyBufferDone(inHeader);
1149 int32_t SoftFFmpegAudio::resampleAudio() {
1151 int64_t channelLayout = 0;
1152 size_t dataSize = 0;
1154 dataSize = av_samples_get_buffer_size(NULL, av_frame_get_channels(mFrame),
1155 mFrame->nb_samples, (enum AVSampleFormat)mFrame->format, 1);
1158 ALOGV("ffmpeg audio decoder, nb_samples:%d, get buffer size:%d",
1159 mFrame->nb_samples, dataSize);
1162 channels = av_get_channel_layout_nb_channels(mFrame->channel_layout);
1164 (mFrame->channel_layout && av_frame_get_channels(mFrame) == channels) ?
1165 mFrame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(mFrame));
1167 // Create if we're reconfiguring, if the format changed mid-stream, or
1168 // if the output format is actually different
1169 if ((mReconfiguring && mSwrCtx) || (!mSwrCtx
1170 && (mFrame->format != mAudioSrcFmt
1171 || channelLayout != mAudioSrcChannelLayout
1172 || (unsigned int)mFrame->sample_rate != mAudioSrcFreq
1173 || mAudioSrcFmt != mAudioTgtFmt
1174 || mAudioSrcChannelLayout != mAudioTgtChannelLayout
1175 || mAudioSrcFreq != mAudioTgtFreq))) {
1179 mSwrCtx = swr_alloc_set_opts(NULL,
1180 mAudioTgtChannelLayout, mAudioTgtFmt, mAudioTgtFreq,
1181 channelLayout, (enum AVSampleFormat)mFrame->format, mFrame->sample_rate,
1183 if (!mSwrCtx || swr_init(mSwrCtx) < 0) {
1184 ALOGE("Cannot create sample rate converter for conversion "
1185 "of %d Hz %s %d channels to %d Hz %s %d channels!",
1186 mFrame->sample_rate,
1187 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1188 av_frame_get_channels(mFrame),
1190 av_get_sample_fmt_name(mAudioTgtFmt),
1192 return ERR_SWR_INIT_FAILED;
1195 char src_layout_name[1024] = {0};
1196 char tgt_layout_name[1024] = {0};
1197 av_get_channel_layout_string(src_layout_name, sizeof(src_layout_name),
1198 mCtx->channels, channelLayout);
1199 av_get_channel_layout_string(tgt_layout_name, sizeof(tgt_layout_name),
1200 mAudioTgtChannels, mAudioTgtChannelLayout);
1201 ALOGI("Create sample rate converter for conversion "
1202 "of %d Hz %s %d channels(%s) "
1203 "to %d Hz %s %d channels(%s)!",
1204 mFrame->sample_rate,
1205 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1206 av_frame_get_channels(mFrame),
1209 av_get_sample_fmt_name(mAudioTgtFmt),
1213 mAudioSrcChannelLayout = channelLayout;
1214 mAudioSrcChannels = av_frame_get_channels(mFrame);
1215 mAudioSrcFreq = mFrame->sample_rate;
1216 mAudioSrcFmt = (enum AVSampleFormat)mFrame->format;
1217 mReconfiguring = false;
1221 const uint8_t **in = (const uint8_t **)mFrame->extended_data;
1222 uint8_t *out[] = {mAudioBuffer};
1223 int out_count = sizeof(mAudioBuffer) / mAudioTgtChannels / av_get_bytes_per_sample(mAudioTgtFmt);
1224 int out_size = av_samples_get_buffer_size(NULL, mAudioTgtChannels, out_count, mAudioTgtFmt, 0);
1227 ALOGE("av_samples_get_buffer_size() failed");
1228 return ERR_INVALID_PARAM;
1231 len2 = swr_convert(mSwrCtx, out, out_count, in, mFrame->nb_samples);
1233 ALOGE("audio_resample() failed");
1234 return ERR_RESAMPLE_FAILED;
1236 if (len2 == out_count) {
1237 ALOGE("warning: audio buffer is probably too small");
1240 mResampledData = mAudioBuffer;
1241 mResampledDataSize = len2 * mAudioTgtChannels * av_get_bytes_per_sample(mAudioTgtFmt);
1244 ALOGV("ffmpeg audio decoder(resample), mFrame->nb_samples:%d, len2:%d, mResampledDataSize:%d, "
1245 "src channel:%u, src fmt:%s, tgt channel:%u, tgt fmt:%s",
1246 mFrame->nb_samples, len2, mResampledDataSize,
1247 av_frame_get_channels(mFrame),
1248 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1250 av_get_sample_fmt_name(mAudioTgtFmt));
1253 mResampledData = mFrame->data[0];
1254 mResampledDataSize = dataSize;
1257 ALOGV("ffmpeg audio decoder(no resample),"
1258 "nb_samples(before resample):%d, mResampledDataSize:%d",
1259 mFrame->nb_samples, mResampledDataSize);
1266 void SoftFFmpegAudio::drainOneOutputBuffer() {
1267 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1268 BufferInfo *outInfo = *outQueue.begin();
1269 CHECK(outInfo != NULL);
1270 OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
1271 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1272 BufferInfo *inInfo = *inQueue.begin();
1273 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1275 if (inHeader != NULL) {
1276 inHeader = inInfo->mHeader;
1279 CHECK_GT(mResampledDataSize, 0);
1281 size_t copy = mResampledDataSize;
1282 if (mResampledDataSize > kOutputBufferSize) {
1283 copy = kOutputBufferSize;
1286 outHeader->nOffset = 0;
1287 outHeader->nFilledLen = copy;
1288 outHeader->nTimeStamp = getAudioClock();
1289 memcpy(outHeader->pBuffer, mResampledData, copy);
1290 outHeader->nFlags = 0;
1292 //update mResampledSize
1293 mResampledData += copy;
1294 mResampledDataSize -= copy;
1297 size_t frames = copy / (av_get_bytes_per_sample(mAudioTgtFmt) * mAudioTgtChannels);
1298 setAudioClock(getAudioClock() + ((frames * 1000000ll) / mAudioTgtFreq));
1301 ALOGV("ffmpeg audio decoder, fill out buffer, copy:%u, pts: %lld, clock: %lld",
1302 copy, outHeader->nTimeStamp, getAudioClock());
1305 outQueue.erase(outQueue.begin());
1306 outInfo->mOwnedByUs = false;
1307 notifyFillBufferDone(outHeader);
1310 void SoftFFmpegAudio::drainEOSOutputBuffer() {
1311 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1312 BufferInfo *outInfo = *outQueue.begin();
1313 CHECK(outInfo != NULL);
1314 OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
1316 // CHECK_EQ(mResampledDataSize, 0);
1318 ALOGD("ffmpeg audio decoder fill eos outbuf");
1320 outHeader->nTimeStamp = getAudioClock();
1321 outHeader->nFilledLen = 0;
1322 outHeader->nFlags = OMX_BUFFERFLAG_EOS;
1324 outQueue.erase(outQueue.begin());
1325 outInfo->mOwnedByUs = false;
1326 notifyFillBufferDone(outHeader);
1328 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1331 void SoftFFmpegAudio::drainAllOutputBuffers() {
1332 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1334 if (!mCodecAlreadyOpened) {
1335 drainEOSOutputBuffer();
1336 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1340 while (!outQueue.empty()) {
1341 if (mResampledDataSize == 0) {
1342 int32_t err = decodeAudio();
1344 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1345 mSignalledError = true;
1347 } else if (err == ERR_FLUSHED) {
1348 drainEOSOutputBuffer();
1351 CHECK_EQ(err, ERR_OK);
1355 if (mResampledDataSize > 0) {
1356 drainOneOutputBuffer();
1361 void SoftFFmpegAudio::onQueueFilled(OMX_U32 /* portIndex */) {
1362 BufferInfo *inInfo = NULL;
1363 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1365 if (mSignalledError || mOutputPortSettingsChange != NONE) {
1369 if (mEOSStatus == OUTPUT_FRAMES_FLUSHED) {
1373 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1374 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1376 while (((mEOSStatus != INPUT_DATA_AVAILABLE) || !inQueue.empty())
1377 && !outQueue.empty()) {
1379 if (mEOSStatus == INPUT_EOS_SEEN) {
1380 drainAllOutputBuffers();
1384 inInfo = *inQueue.begin();
1385 inHeader = inInfo->mHeader;
1387 if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
1388 ALOGD("ffmpeg audio decoder eos");
1389 mEOSStatus = INPUT_EOS_SEEN;
1393 if (inHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
1394 if (handleExtradata() != ERR_OK) {
1395 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1396 mSignalledError = true;
1402 if (!mCodecAlreadyOpened) {
1403 if (openDecoder() != ERR_OK) {
1404 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1405 mSignalledError = true;
1410 if (mResampledDataSize == 0) {
1411 int32_t err = decodeAudio();
1413 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1414 mSignalledError = true;
1416 } else if (err == ERR_NO_FRM) {
1417 CHECK_EQ(mResampledDataSize, 0);
1420 CHECK_EQ(err, ERR_OK);
1424 if (mResampledDataSize > 0) {
1425 drainOneOutputBuffer();
1430 void SoftFFmpegAudio::onPortFlushCompleted(OMX_U32 portIndex) {
1431 ALOGV("ffmpeg audio decoder flush port(%u)", portIndex);
1432 if (portIndex == kInputPortIndex) {
1433 if (mCtx && avcodec_is_open(mCtx)) {
1434 //Make sure that the next buffer output does not still
1435 //depend on fragments from the last one decoded.
1436 avcodec_flush_buffers(mCtx);
1440 mInputBufferSize = 0;
1441 mResampledDataSize = 0;
1442 mResampledData = NULL;
1443 mEOSStatus = INPUT_DATA_AVAILABLE;
1447 void SoftFFmpegAudio::onPortEnableCompleted(OMX_U32 portIndex, bool enabled) {
1448 if (portIndex != kOutputPortIndex) {
1452 switch (mOutputPortSettingsChange) {
1456 case AWAITING_DISABLED:
1459 mOutputPortSettingsChange = AWAITING_ENABLED;
1465 CHECK_EQ((int)mOutputPortSettingsChange, (int)AWAITING_ENABLED);
1467 mOutputPortSettingsChange = NONE;
1473 int64_t SoftFFmpegAudio::getAudioClock() {
1474 if (sAudioClock == NULL) {
1475 sAudioClock = (int64_t*) malloc(sizeof(int64_t));
1478 ALOGV("getAudioClock: %lld", *sAudioClock);
1479 return *sAudioClock;
1482 void SoftFFmpegAudio::setAudioClock(int64_t ticks) {
1483 if (sAudioClock == NULL) {
1484 sAudioClock = (int64_t*) malloc(sizeof(int64_t));
1486 *sAudioClock = ticks;
1489 void SoftFFmpegAudio::onReset() {
1490 enum AVCodecID codecID = mCtx->codec_id;
1492 initDecoder(codecID);
1493 mSignalledError = false;
1494 mOutputPortSettingsChange = NONE;
1495 mEOSStatus = INPUT_DATA_AVAILABLE;
1498 SoftOMXComponent* SoftFFmpegAudio::createSoftOMXComponent(
1499 const char *name, const OMX_CALLBACKTYPE *callbacks,
1500 OMX_PTR appData, OMX_COMPONENTTYPE **component) {
1501 OMX_AUDIO_CODINGTYPE codingType = OMX_AUDIO_CodingAutoDetect;
1502 char *componentRole = NULL;
1503 enum AVCodecID codecID = AV_CODEC_ID_NONE;
1505 for (size_t i = 0; i < kNumAudioComponents; ++i) {
1506 if (!strcasecmp(name, kAudioComponents[i].mName)) {
1507 componentRole = strdup(kAudioComponents[i].mRole);
1508 codingType = kAudioComponents[i].mAudioCodingType;
1509 codecID = kAudioComponents[i].mCodecID;
1514 return new SoftFFmpegAudio(name, componentRole, codingType, codecID,
1515 callbacks, appData, component);
1518 } // namespace android