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) {
246 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 av_packet_unref(&pkt);
1101 //a negative error code is returned if an error occurred during decoding
1103 ALOGW("ffmpeg audio decoder err, we skip the frame and play silence instead");
1104 mResampledData = mSilenceBuffer;
1105 mResampledDataSize = kOutputBufferSize;
1109 ALOGV("ffmpeg audio decoder, consume pkt len: %d", len);
1113 ALOGI("ffmpeg audio decoder failed to get frame.");
1115 //stop sending empty packets if the decoder is finished
1116 if (is_flush && mCtx->codec->capabilities & CODEC_CAP_DELAY) {
1117 ALOGI("ffmpeg audio decoder failed to get more frames when flush.");
1123 ret = resampleAudio();
1129 //if error, we skip the frame
1130 inputBufferUsedLength = mInputBufferSize;
1132 inputBufferUsedLength = len;
1135 CHECK_GE(inHeader->nFilledLen, inputBufferUsedLength);
1136 inHeader->nOffset += inputBufferUsedLength;
1137 inHeader->nFilledLen -= inputBufferUsedLength;
1138 mInputBufferSize -= inputBufferUsedLength;
1140 if (inHeader->nFilledLen == 0) {
1141 CHECK_EQ(mInputBufferSize, 0);
1142 inQueue.erase(inQueue.begin());
1143 inInfo->mOwnedByUs = false;
1144 notifyEmptyBufferDone(inHeader);
1151 int32_t SoftFFmpegAudio::resampleAudio() {
1153 int64_t channelLayout = 0;
1154 size_t dataSize = 0;
1156 dataSize = av_samples_get_buffer_size(NULL, av_frame_get_channels(mFrame),
1157 mFrame->nb_samples, (enum AVSampleFormat)mFrame->format, 1);
1160 ALOGV("ffmpeg audio decoder, nb_samples:%d, get buffer size:%d",
1161 mFrame->nb_samples, dataSize);
1164 channels = av_get_channel_layout_nb_channels(mFrame->channel_layout);
1166 (mFrame->channel_layout && av_frame_get_channels(mFrame) == channels) ?
1167 mFrame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(mFrame));
1169 // Create if we're reconfiguring, if the format changed mid-stream, or
1170 // if the output format is actually different
1171 if ((mReconfiguring && mSwrCtx) || (!mSwrCtx
1172 && (mFrame->format != mAudioSrcFmt
1173 || channelLayout != mAudioSrcChannelLayout
1174 || (unsigned int)mFrame->sample_rate != mAudioSrcFreq
1175 || mAudioSrcFmt != mAudioTgtFmt
1176 || mAudioSrcChannelLayout != mAudioTgtChannelLayout
1177 || mAudioSrcFreq != mAudioTgtFreq))) {
1181 mSwrCtx = swr_alloc_set_opts(NULL,
1182 mAudioTgtChannelLayout, mAudioTgtFmt, mAudioTgtFreq,
1183 channelLayout, (enum AVSampleFormat)mFrame->format, mFrame->sample_rate,
1185 if (!mSwrCtx || swr_init(mSwrCtx) < 0) {
1186 ALOGE("Cannot create sample rate converter for conversion "
1187 "of %d Hz %s %d channels to %d Hz %s %d channels!",
1188 mFrame->sample_rate,
1189 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1190 av_frame_get_channels(mFrame),
1192 av_get_sample_fmt_name(mAudioTgtFmt),
1194 return ERR_SWR_INIT_FAILED;
1197 char src_layout_name[1024] = {0};
1198 char tgt_layout_name[1024] = {0};
1199 av_get_channel_layout_string(src_layout_name, sizeof(src_layout_name),
1200 mCtx->channels, channelLayout);
1201 av_get_channel_layout_string(tgt_layout_name, sizeof(tgt_layout_name),
1202 mAudioTgtChannels, mAudioTgtChannelLayout);
1203 ALOGI("Create sample rate converter for conversion "
1204 "of %d Hz %s %d channels(%s) "
1205 "to %d Hz %s %d channels(%s)!",
1206 mFrame->sample_rate,
1207 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1208 av_frame_get_channels(mFrame),
1211 av_get_sample_fmt_name(mAudioTgtFmt),
1215 mAudioSrcChannelLayout = channelLayout;
1216 mAudioSrcChannels = av_frame_get_channels(mFrame);
1217 mAudioSrcFreq = mFrame->sample_rate;
1218 mAudioSrcFmt = (enum AVSampleFormat)mFrame->format;
1219 mReconfiguring = false;
1223 const uint8_t **in = (const uint8_t **)mFrame->extended_data;
1224 uint8_t *out[] = {mAudioBuffer};
1225 int out_count = sizeof(mAudioBuffer) / mAudioTgtChannels / av_get_bytes_per_sample(mAudioTgtFmt);
1226 int out_size = av_samples_get_buffer_size(NULL, mAudioTgtChannels, out_count, mAudioTgtFmt, 0);
1229 ALOGE("av_samples_get_buffer_size() failed");
1230 return ERR_INVALID_PARAM;
1233 len2 = swr_convert(mSwrCtx, out, out_count, in, mFrame->nb_samples);
1235 ALOGE("audio_resample() failed");
1236 return ERR_RESAMPLE_FAILED;
1238 if (len2 == out_count) {
1239 ALOGE("warning: audio buffer is probably too small");
1242 mResampledData = mAudioBuffer;
1243 mResampledDataSize = len2 * mAudioTgtChannels * av_get_bytes_per_sample(mAudioTgtFmt);
1246 ALOGV("ffmpeg audio decoder(resample), mFrame->nb_samples:%d, len2:%d, mResampledDataSize:%d, "
1247 "src channel:%u, src fmt:%s, tgt channel:%u, tgt fmt:%s",
1248 mFrame->nb_samples, len2, mResampledDataSize,
1249 av_frame_get_channels(mFrame),
1250 av_get_sample_fmt_name((enum AVSampleFormat)mFrame->format),
1252 av_get_sample_fmt_name(mAudioTgtFmt));
1255 mResampledData = mFrame->data[0];
1256 mResampledDataSize = dataSize;
1259 ALOGV("ffmpeg audio decoder(no resample),"
1260 "nb_samples(before resample):%d, mResampledDataSize:%d",
1261 mFrame->nb_samples, mResampledDataSize);
1268 void SoftFFmpegAudio::drainOneOutputBuffer() {
1269 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1270 BufferInfo *outInfo = *outQueue.begin();
1271 CHECK(outInfo != NULL);
1272 OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
1273 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1274 BufferInfo *inInfo = *inQueue.begin();
1275 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1277 if (inHeader != NULL) {
1278 inHeader = inInfo->mHeader;
1281 CHECK_GT(mResampledDataSize, 0);
1283 size_t copy = mResampledDataSize;
1284 if (mResampledDataSize > kOutputBufferSize) {
1285 copy = kOutputBufferSize;
1288 outHeader->nOffset = 0;
1289 outHeader->nFilledLen = copy;
1290 outHeader->nTimeStamp = getAudioClock();
1291 memcpy(outHeader->pBuffer, mResampledData, copy);
1292 outHeader->nFlags = 0;
1294 //update mResampledSize
1295 mResampledData += copy;
1296 mResampledDataSize -= copy;
1299 size_t frames = copy / (av_get_bytes_per_sample(mAudioTgtFmt) * mAudioTgtChannels);
1300 setAudioClock(getAudioClock() + ((frames * 1000000ll) / mAudioTgtFreq));
1303 ALOGV("ffmpeg audio decoder, fill out buffer, copy:%u, pts: %lld, clock: %lld",
1304 copy, outHeader->nTimeStamp, getAudioClock());
1307 outQueue.erase(outQueue.begin());
1308 outInfo->mOwnedByUs = false;
1309 notifyFillBufferDone(outHeader);
1312 void SoftFFmpegAudio::drainEOSOutputBuffer() {
1313 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1314 BufferInfo *outInfo = *outQueue.begin();
1315 CHECK(outInfo != NULL);
1316 OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
1318 // CHECK_EQ(mResampledDataSize, 0);
1320 ALOGD("ffmpeg audio decoder fill eos outbuf");
1322 outHeader->nTimeStamp = getAudioClock();
1323 outHeader->nFilledLen = 0;
1324 outHeader->nFlags = OMX_BUFFERFLAG_EOS;
1326 outQueue.erase(outQueue.begin());
1327 outInfo->mOwnedByUs = false;
1328 notifyFillBufferDone(outHeader);
1330 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1333 void SoftFFmpegAudio::drainAllOutputBuffers() {
1334 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1336 if (!mCodecAlreadyOpened) {
1337 drainEOSOutputBuffer();
1338 mEOSStatus = OUTPUT_FRAMES_FLUSHED;
1342 while (!outQueue.empty()) {
1343 if (mResampledDataSize == 0) {
1344 int32_t err = decodeAudio();
1346 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1347 mSignalledError = true;
1349 } else if (err == ERR_FLUSHED) {
1350 drainEOSOutputBuffer();
1353 CHECK_EQ(err, ERR_OK);
1357 if (mResampledDataSize > 0) {
1358 drainOneOutputBuffer();
1363 void SoftFFmpegAudio::onQueueFilled(OMX_U32 /* portIndex */) {
1364 BufferInfo *inInfo = NULL;
1365 OMX_BUFFERHEADERTYPE *inHeader = NULL;
1367 if (mSignalledError || mOutputPortSettingsChange != NONE) {
1371 if (mEOSStatus == OUTPUT_FRAMES_FLUSHED) {
1375 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
1376 List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
1378 while (((mEOSStatus != INPUT_DATA_AVAILABLE) || !inQueue.empty())
1379 && !outQueue.empty()) {
1381 if (mEOSStatus == INPUT_EOS_SEEN) {
1382 drainAllOutputBuffers();
1386 inInfo = *inQueue.begin();
1387 inHeader = inInfo->mHeader;
1389 if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
1390 ALOGD("ffmpeg audio decoder eos");
1391 mEOSStatus = INPUT_EOS_SEEN;
1395 if (inHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
1396 if (handleExtradata() != ERR_OK) {
1397 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1398 mSignalledError = true;
1404 if (!mCodecAlreadyOpened) {
1405 if (openDecoder() != ERR_OK) {
1406 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1407 mSignalledError = true;
1412 if (mResampledDataSize == 0) {
1413 int32_t err = decodeAudio();
1415 notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
1416 mSignalledError = true;
1418 } else if (err == ERR_NO_FRM) {
1419 CHECK_EQ(mResampledDataSize, 0);
1422 CHECK_EQ(err, ERR_OK);
1426 if (mResampledDataSize > 0) {
1427 drainOneOutputBuffer();
1432 void SoftFFmpegAudio::onPortFlushCompleted(OMX_U32 portIndex) {
1433 ALOGV("ffmpeg audio decoder flush port(%u)", portIndex);
1434 if (portIndex == kInputPortIndex) {
1435 if (mCtx && avcodec_is_open(mCtx)) {
1436 //Make sure that the next buffer output does not still
1437 //depend on fragments from the last one decoded.
1438 avcodec_flush_buffers(mCtx);
1442 mInputBufferSize = 0;
1443 mResampledDataSize = 0;
1444 mResampledData = NULL;
1445 mEOSStatus = INPUT_DATA_AVAILABLE;
1449 void SoftFFmpegAudio::onPortEnableCompleted(OMX_U32 portIndex, bool enabled) {
1450 if (portIndex != kOutputPortIndex) {
1454 switch (mOutputPortSettingsChange) {
1458 case AWAITING_DISABLED:
1461 mOutputPortSettingsChange = AWAITING_ENABLED;
1467 CHECK_EQ((int)mOutputPortSettingsChange, (int)AWAITING_ENABLED);
1469 mOutputPortSettingsChange = NONE;
1475 int64_t SoftFFmpegAudio::getAudioClock() {
1476 if (sAudioClock == NULL) {
1477 sAudioClock = (int64_t*) malloc(sizeof(int64_t));
1480 ALOGV("getAudioClock: %lld", *sAudioClock);
1481 return *sAudioClock;
1484 void SoftFFmpegAudio::setAudioClock(int64_t ticks) {
1485 if (sAudioClock == NULL) {
1486 sAudioClock = (int64_t*) malloc(sizeof(int64_t));
1488 *sAudioClock = ticks;
1491 void SoftFFmpegAudio::onReset() {
1492 enum AVCodecID codecID = mCtx->codec_id;
1494 initDecoder(codecID);
1495 mSignalledError = false;
1496 mOutputPortSettingsChange = NONE;
1497 mEOSStatus = INPUT_DATA_AVAILABLE;
1500 SoftOMXComponent* SoftFFmpegAudio::createSoftOMXComponent(
1501 const char *name, const OMX_CALLBACKTYPE *callbacks,
1502 OMX_PTR appData, OMX_COMPONENTTYPE **component) {
1503 OMX_AUDIO_CODINGTYPE codingType = OMX_AUDIO_CodingAutoDetect;
1504 char *componentRole = NULL;
1505 enum AVCodecID codecID = AV_CODEC_ID_NONE;
1507 for (size_t i = 0; i < kNumAudioComponents; ++i) {
1508 if (!strcasecmp(name, kAudioComponents[i].mName)) {
1509 componentRole = strdup(kAudioComponents[i].mRole);
1510 codingType = kAudioComponents[i].mAudioCodingType;
1511 codecID = kAudioComponents[i].mCodecID;
1516 return new SoftFFmpegAudio(name, componentRole, codingType, codecID,
1517 callbacks, appData, component);
1520 } // namespace android