From 7b3a9daba71708d54434c8fb8e967b4853e01707 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Thu, 17 Dec 2015 15:18:04 -0500 Subject: nuplayer: Error checks for PCM format extensions Change-Id: Ie9a3a8c335611d11c84bf24cb50c73c1644ad381 --- .../mediaplayerservice/AVNuUtils.cpp | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'media/libavextensions') diff --git a/media/libavextensions/mediaplayerservice/AVNuUtils.cpp b/media/libavextensions/mediaplayerservice/AVNuUtils.cpp index 3354d23..34abd0a 100644 --- a/media/libavextensions/mediaplayerservice/AVNuUtils.cpp +++ b/media/libavextensions/mediaplayerservice/AVNuUtils.cpp @@ -202,7 +202,8 @@ bool AVNuUtils::isVorbisFormat(const sp &) { int AVNuUtils::updateAudioBitWidth(audio_format_t audioFormat, const sp &format){ int bits = 16; - if (audio_is_linear_pcm(audioFormat) || audio_is_offload_pcm(audioFormat)) { + if (format.get() && + (audio_is_linear_pcm(audioFormat) || audio_is_offload_pcm(audioFormat))) { bits = audio_bytes_per_sample(audioFormat) * 8; format->setInt32("bits-per-sample", bits); } @@ -211,42 +212,45 @@ int AVNuUtils::updateAudioBitWidth(audio_format_t audioFormat, audio_format_t AVNuUtils::getKeyPCMFormat(const sp &meta) { audio_format_t pcmFormat = AUDIO_FORMAT_INVALID; - meta->findInt32('pfmt', (int32_t *)&pcmFormat); + if (meta.get()) + meta->findInt32('pfmt', (int32_t *)&pcmFormat); return pcmFormat; } void AVNuUtils::setKeyPCMFormat(const sp &meta, audio_format_t audioFormat) { - if (meta != NULL && audio_is_linear_pcm(audioFormat)) + if (meta.get() && audio_is_linear_pcm(audioFormat)) meta->setInt32('pfmt', audioFormat); } audio_format_t AVNuUtils::getPCMFormat(const sp &format) { audio_format_t pcmFormat = AUDIO_FORMAT_INVALID; - format->findInt32("pcm-format", (int32_t *)&pcmFormat); + if (format.get()) + format->findInt32("pcm-format", (int32_t *)&pcmFormat); return pcmFormat; } void AVNuUtils::setPCMFormat(const sp &format, audio_format_t audioFormat) { - if (audio_is_linear_pcm(audioFormat) || audio_is_offload_pcm(audioFormat)) + if (format.get() && + (audio_is_linear_pcm(audioFormat) || audio_is_offload_pcm(audioFormat))) format->setInt32("pcm-format", audioFormat); } void AVNuUtils::setSourcePCMFormat(const sp &audioMeta) { - if (!isRAWFormat(audioMeta)) + if (!audioMeta.get() || !isRAWFormat(audioMeta)) return; audio_format_t pcmFormat = getKeyPCMFormat(audioMeta); - ALOGI("setSourcePCMFormat fmt=%x", pcmFormat); - audioMeta->dumpToLog(); if (pcmFormat == AUDIO_FORMAT_INVALID) { int32_t bits = 16; if (audioMeta->findInt32(kKeyBitsPerSample, &bits)) { if (bits == 8) pcmFormat = AUDIO_FORMAT_PCM_8_BIT; - if (bits == 24) + else if (bits == 24) pcmFormat = AUDIO_FORMAT_PCM_32_BIT; - if (bits == 32) + else if (bits == 32) pcmFormat = AUDIO_FORMAT_PCM_FLOAT; + else + pcmFormat = AUDIO_FORMAT_PCM_16_BIT; setKeyPCMFormat(audioMeta, pcmFormat); } } -- cgit v1.1