1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_AUDIO_STREAM_IN_SOURCE_H 18 #define ANDROID_AUDIO_STREAM_IN_SOURCE_H 19 20 #include <hardware/audio.h> 21 #include "NBAIO.h" 22 23 namespace android { 24 25 // not multi-thread safe 26 class AudioStreamInSource : public NBAIO_Source { 27 28 public: 29 AudioStreamInSource(audio_stream_in *stream); 30 virtual ~AudioStreamInSource(); 31 32 // NBAIO_Port interface 33 34 virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers, 35 NBAIO_Format counterOffers[], size_t& numCounterOffers); 36 //virtual NBAIO_Format format() const; 37 38 // NBAIO_Sink interface 39 40 //virtual size_t framesRead() const; 41 virtual size_t framesOverrun(); 42 virtual size_t overruns() { (void) framesOverrun(); return mOverruns; } 43 44 // This is an over-estimate, and could dupe the caller into making a blocking read() 45 // FIXME Use an audio HAL API to query the buffer filling status when it's available. 46 virtual ssize_t availableToRead() { return mStreamBufferSizeBytes / mFrameSize; } 47 48 virtual ssize_t read(void *buffer, size_t count, int64_t readPTS); 49 50 // NBAIO_Sink end 51 52 #if 0 // until necessary 53 audio_stream_in *stream() const { return mStream; } 54 #endif 55 56 private: 57 audio_stream_in * const mStream; 58 size_t mStreamBufferSizeBytes; // as reported by get_buffer_size() 59 size_t mFramesOverrun; 60 size_t mOverruns; 61 }; 62 63 } // namespace android 64 65 #endif // ANDROID_AUDIO_STREAM_IN_SOURCE_H 66