1 /* 2 ** 3 ** Copyright 2014, The Android Open Source Project 4 ** 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 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 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. 16 */ 17 18 #define LOG_TAG "AudioHAL:HDMIAudioOutput" 19 20 #include <utils/Log.h> 21 22 #include <stdint.h> 23 24 #include "AudioHardwareOutput.h" 25 #include "AudioStreamOut.h" 26 #include "HDMIAudioOutput.h" 27 28 namespace android { 29 30 extern AudioHardwareOutput gAudioHardwareOutput; 31 32 HDMIAudioOutput::HDMIAudioOutput() 33 : AudioOutput(kHDMI_ALSADeviceName, PCM_FORMAT_S24_LE) 34 { 35 } 36 37 HDMIAudioOutput::~HDMIAudioOutput() 38 { 39 } 40 41 status_t HDMIAudioOutput::setupForStream(const AudioStreamOut& stream) 42 { 43 mFramesPerChunk = stream.framesPerChunk(); 44 mFramesPerSec = stream.outputSampleRate(); 45 mBufferChunks = stream.nomChunksInFlight(); 46 mChannelCnt = audio_channel_count_from_out_mask(stream.chanMask()); 47 48 ALOGI("setupForStream format %08x, rate = %u", stream.format(), mFramesPerSec); 49 50 if (!gAudioHardwareOutput.getHDMIAudioCaps().supportsFormat( 51 stream.format(), 52 stream.sampleRate(), 53 mChannelCnt)) { 54 ALOGE("HDMI Sink does not support format = 0x%0X, srate = %d, #channels = 0%d", 55 stream.format(), mFramesPerSec, mChannelCnt); 56 return BAD_VALUE; 57 } 58 59 if (stream.isEncoded()) { 60 ALOGI("HDMIAudioOutput::setupForStream() use %d channels for playing encoded data!", 61 SPDIF_ENCODED_CHANNEL_COUNT); 62 mChannelCnt = SPDIF_ENCODED_CHANNEL_COUNT; 63 } 64 65 setupInternal(); 66 67 // TODO Maybe set SPDIF channel status to compressed mode. 68 // Some receivers do not need the bit set. But some might. 69 70 return initCheck(); 71 } 72 73 #define IEC958_AES0_NONAUDIO (1<<1) /* 0 = audio, 1 = non-audio */ 74 75 void HDMIAudioOutput::applyPendingVolParams() 76 { 77 } 78 79 void HDMIAudioOutput::dump(String8& result) 80 { 81 const size_t SIZE = 256; 82 char buffer[SIZE]; 83 84 snprintf(buffer, SIZE, 85 "\t%s Audio Output\n" 86 "\t\tSample Rate : %d\n" 87 "\t\tChannel Count : %d\n" 88 "\t\tState : %d\n", 89 getOutputName(), 90 mFramesPerSec, 91 mChannelCnt, 92 mState); 93 result.append(buffer); 94 } 95 96 } // namespace android 97