Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 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 | |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 25 | class StreamInHalInterface; |
| 26 | |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 27 | // not multi-thread safe |
| 28 | class AudioStreamInSource : public NBAIO_Source { |
| 29 | |
| 30 | public: |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 31 | AudioStreamInSource(sp<StreamInHalInterface> stream); |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 32 | virtual ~AudioStreamInSource(); |
| 33 | |
| 34 | // NBAIO_Port interface |
| 35 | |
| 36 | virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers, |
| 37 | NBAIO_Format counterOffers[], size_t& numCounterOffers); |
| 38 | //virtual NBAIO_Format format() const; |
| 39 | |
| 40 | // NBAIO_Sink interface |
| 41 | |
| 42 | //virtual size_t framesRead() const; |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 43 | virtual int64_t framesOverrun(); |
| 44 | virtual int64_t overruns() { (void) framesOverrun(); return mOverruns; } |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 45 | |
| 46 | // This is an over-estimate, and could dupe the caller into making a blocking read() |
| 47 | // FIXME Use an audio HAL API to query the buffer filling status when it's available. |
Glenn Kasten | 4d693d6 | 2014-03-06 07:53:11 -0800 | [diff] [blame] | 48 | virtual ssize_t availableToRead() { return mStreamBufferSizeBytes / mFrameSize; } |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 49 | |
Glenn Kasten | d79072e | 2016-01-06 08:41:20 -0800 | [diff] [blame] | 50 | virtual ssize_t read(void *buffer, size_t count); |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 51 | |
| 52 | // NBAIO_Sink end |
| 53 | |
| 54 | #if 0 // until necessary |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 55 | sp<StreamInHalInterface> stream() const { return mStream; } |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 56 | #endif |
| 57 | |
| 58 | private: |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 59 | sp<StreamInHalInterface> mStream; |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 60 | size_t mStreamBufferSizeBytes; // as reported by get_buffer_size() |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 61 | int64_t mFramesOverrun; |
| 62 | int64_t mOverruns; |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace android |
| 66 | |
| 67 | #endif // ANDROID_AUDIO_STREAM_IN_SOURCE_H |