1062e67a26e0553dd142be622821f493df541f0c6Phil Burk/* 2062e67a26e0553dd142be622821f493df541f0c6Phil Burk** 3062e67a26e0553dd142be622821f493df541f0c6Phil Burk** Copyright 2015, The Android Open Source Project 4062e67a26e0553dd142be622821f493df541f0c6Phil Burk** 5062e67a26e0553dd142be622821f493df541f0c6Phil Burk** Licensed under the Apache License, Version 2.0 (the "License"); 6062e67a26e0553dd142be622821f493df541f0c6Phil Burk** you may not use this file except in compliance with the License. 7062e67a26e0553dd142be622821f493df541f0c6Phil Burk** You may obtain a copy of the License at 8062e67a26e0553dd142be622821f493df541f0c6Phil Burk** 9062e67a26e0553dd142be622821f493df541f0c6Phil Burk** http://www.apache.org/licenses/LICENSE-2.0 10062e67a26e0553dd142be622821f493df541f0c6Phil Burk** 11062e67a26e0553dd142be622821f493df541f0c6Phil Burk** Unless required by applicable law or agreed to in writing, software 12062e67a26e0553dd142be622821f493df541f0c6Phil Burk** distributed under the License is distributed on an "AS IS" BASIS, 13062e67a26e0553dd142be622821f493df541f0c6Phil Burk** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14062e67a26e0553dd142be622821f493df541f0c6Phil Burk** See the License for the specific language governing permissions and 15062e67a26e0553dd142be622821f493df541f0c6Phil Burk** limitations under the License. 16062e67a26e0553dd142be622821f493df541f0c6Phil Burk*/ 17062e67a26e0553dd142be622821f493df541f0c6Phil Burk 18062e67a26e0553dd142be622821f493df541f0c6Phil Burk#ifndef ANDROID_AUDIO_STREAM_OUT_H 19062e67a26e0553dd142be622821f493df541f0c6Phil Burk#define ANDROID_AUDIO_STREAM_OUT_H 20062e67a26e0553dd142be622821f493df541f0c6Phil Burk 21062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <stdint.h> 22062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <sys/types.h> 23062e67a26e0553dd142be622821f493df541f0c6Phil Burk 24062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <system/audio.h> 25062e67a26e0553dd142be622821f493df541f0c6Phil Burk 26062e67a26e0553dd142be622821f493df541f0c6Phil Burknamespace android { 27062e67a26e0553dd142be622821f493df541f0c6Phil Burk 28062e67a26e0553dd142be622821f493df541f0c6Phil Burkclass AudioHwDevice; 29e4f1f63a2c54ee8687ad8cca18df0f6639ad7c81Mikhail Naganovclass DeviceHalInterface; 301dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganovclass StreamOutHalInterface; 31062e67a26e0553dd142be622821f493df541f0c6Phil Burk 32062e67a26e0553dd142be622821f493df541f0c6Phil Burk/** 33062e67a26e0553dd142be622821f493df541f0c6Phil Burk * Managed access to a HAL output stream. 34062e67a26e0553dd142be622821f493df541f0c6Phil Burk */ 35062e67a26e0553dd142be622821f493df541f0c6Phil Burkclass AudioStreamOut { 36062e67a26e0553dd142be622821f493df541f0c6Phil Burkpublic: 37062e67a26e0553dd142be622821f493df541f0c6Phil Burk// AudioStreamOut is immutable, so its fields are const. 38062e67a26e0553dd142be622821f493df541f0c6Phil Burk// For emphasis, we could also make all pointers to them be "const *", 39062e67a26e0553dd142be622821f493df541f0c6Phil Burk// but that would clutter the code unnecessarily. 40062e67a26e0553dd142be622821f493df541f0c6Phil Burk AudioHwDevice * const audioHwDev; 411dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov sp<StreamOutHalInterface> stream; 42062e67a26e0553dd142be622821f493df541f0c6Phil Burk const audio_output_flags_t flags; 43062e67a26e0553dd142be622821f493df541f0c6Phil Burk 44e4f1f63a2c54ee8687ad8cca18df0f6639ad7c81Mikhail Naganov sp<DeviceHalInterface> hwDev() const; 45062e67a26e0553dd142be622821f493df541f0c6Phil Burk 46062e67a26e0553dd142be622821f493df541f0c6Phil Burk AudioStreamOut(AudioHwDevice *dev, audio_output_flags_t flags); 47062e67a26e0553dd142be622821f493df541f0c6Phil Burk 48062e67a26e0553dd142be622821f493df541f0c6Phil Burk virtual status_t open( 49062e67a26e0553dd142be622821f493df541f0c6Phil Burk audio_io_handle_t handle, 50062e67a26e0553dd142be622821f493df541f0c6Phil Burk audio_devices_t devices, 51062e67a26e0553dd142be622821f493df541f0c6Phil Burk struct audio_config *config, 52062e67a26e0553dd142be622821f493df541f0c6Phil Burk const char *address); 53062e67a26e0553dd142be622821f493df541f0c6Phil Burk 541dc98674f701dada94143b4d31b7221c58346c6cMikhail Naganov virtual ~AudioStreamOut(); 55062e67a26e0553dd142be622821f493df541f0c6Phil Burk 5690eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk // Get the bottom 32-bits of the 64-bit render position. 5790eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk status_t getRenderPosition(uint32_t *frames); 5890eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk 5990eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk virtual status_t getRenderPosition(uint64_t *frames); 60062e67a26e0553dd142be622821f493df541f0c6Phil Burk 61062e67a26e0553dd142be622821f493df541f0c6Phil Burk virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp); 62062e67a26e0553dd142be622821f493df541f0c6Phil Burk 63062e67a26e0553dd142be622821f493df541f0c6Phil Burk /** 64062e67a26e0553dd142be622821f493df541f0c6Phil Burk * Write audio buffer to driver. Returns number of bytes written, or a 65062e67a26e0553dd142be622821f493df541f0c6Phil Burk * negative status_t. If at least one frame was written successfully prior to the error, 66062e67a26e0553dd142be622821f493df541f0c6Phil Burk * it is suggested that the driver return that successful (short) byte count 67062e67a26e0553dd142be622821f493df541f0c6Phil Burk * and then return an error in the subsequent call. 68062e67a26e0553dd142be622821f493df541f0c6Phil Burk * 69062e67a26e0553dd142be622821f493df541f0c6Phil Burk * If set_callback() has previously been called to enable non-blocking mode 70062e67a26e0553dd142be622821f493df541f0c6Phil Burk * the write() is not allowed to block. It must write only the number of 71062e67a26e0553dd142be622821f493df541f0c6Phil Burk * bytes that currently fit in the driver/hardware buffer and then return 72062e67a26e0553dd142be622821f493df541f0c6Phil Burk * this byte count. If this is less than the requested write size the 73062e67a26e0553dd142be622821f493df541f0c6Phil Burk * callback function must be called when more space is available in the 74062e67a26e0553dd142be622821f493df541f0c6Phil Burk * driver/hardware buffer. 75062e67a26e0553dd142be622821f493df541f0c6Phil Burk */ 76062e67a26e0553dd142be622821f493df541f0c6Phil Burk virtual ssize_t write(const void *buffer, size_t bytes); 77062e67a26e0553dd142be622821f493df541f0c6Phil Burk 78ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk /** 79ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk * @return frame size from the perspective of the application and the AudioFlinger. 80ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk */ 81ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk virtual size_t getFrameSize() const { return mHalFrameSize; } 82ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk 83ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk /** 84ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk * @return format from the perspective of the application and the AudioFlinger. 85ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk */ 86ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk virtual audio_format_t getFormat() const; 87ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk 88ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk /** 89ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk * The HAL may be running at a higher sample rate if, for example, playing wrapped EAC3. 90ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk * @return sample rate from the perspective of the application and the AudioFlinger. 91ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk */ 92ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk virtual uint32_t getSampleRate() const; 93ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk 94ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk /** 95ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk * The HAL is in stereo mode when playing multi-channel compressed audio over HDMI. 96ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk * @return channel mask from the perspective of the application and the AudioFlinger. 97ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk */ 98ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk virtual audio_channel_mask_t getChannelMask() const; 99ca5e6143740299c877d69e97f7968cd04476d32cPhil Burk 100062e67a26e0553dd142be622821f493df541f0c6Phil Burk 101062e67a26e0553dd142be622821f493df541f0c6Phil Burk virtual status_t flush(); 102062e67a26e0553dd142be622821f493df541f0c6Phil Burk virtual status_t standby(); 10390eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk 10490eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burkprotected: 10590eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk uint64_t mFramesWritten; // reset by flush 10690eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk uint64_t mFramesWrittenAtStandby; 10790eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk uint64_t mRenderPosition; // reset by flush or standby 10890eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk int mRateMultiplier; 109fdb3c07db5d44535eb8c3ec46dc78ad8446c01ebPhil Burk bool mHalFormatHasProportionalFrames; 11090eea7631b07117e46ae8b84889a2baa3eee7aeaPhil Burk size_t mHalFrameSize; 111062e67a26e0553dd142be622821f493df541f0c6Phil Burk}; 112062e67a26e0553dd142be622821f493df541f0c6Phil Burk 113062e67a26e0553dd142be622821f493df541f0c6Phil Burk} // namespace android 114062e67a26e0553dd142be622821f493df541f0c6Phil Burk 115062e67a26e0553dd142be622821f493df541f0c6Phil Burk#endif // ANDROID_AUDIO_STREAM_OUT_H 116