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_OUT_SINK_H |
| 18 | #define ANDROID_AUDIO_STREAM_OUT_SINK_H |
| 19 | |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 20 | #include "NBAIO.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 24 | class StreamOutHalInterface; |
| 25 | |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 26 | // not multi-thread safe |
| 27 | class AudioStreamOutSink : public NBAIO_Sink { |
| 28 | |
| 29 | public: |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 30 | AudioStreamOutSink(sp<StreamOutHalInterface> stream); |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 31 | virtual ~AudioStreamOutSink(); |
| 32 | |
| 33 | // NBAIO_Port interface |
| 34 | |
| 35 | virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers, |
| 36 | NBAIO_Format counterOffers[], size_t& numCounterOffers); |
| 37 | //virtual NBAIO_Format format(); |
| 38 | |
| 39 | // NBAIO_Sink interface |
| 40 | |
| 41 | //virtual size_t framesWritten() const; |
| 42 | //virtual size_t framesUnderrun() const; |
| 43 | //virtual size_t underruns() const; |
| 44 | |
| 45 | // This is an over-estimate, and could dupe the caller into making a blocking write() |
| 46 | // FIXME Use an audio HAL API to query the buffer emptying status when it's available. |
Glenn Kasten | ed99c2b | 2016-12-12 08:31:24 -0800 | [diff] [blame] | 47 | virtual ssize_t availableToWrite() { return mStreamBufferSizeBytes / mFrameSize; } |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 48 | |
| 49 | virtual ssize_t write(const void *buffer, size_t count); |
| 50 | |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 51 | virtual status_t getTimestamp(ExtendedTimestamp ×tamp); |
Glenn Kasten | 767094d | 2013-08-23 13:51:43 -0700 | [diff] [blame] | 52 | |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 53 | // NBAIO_Sink end |
| 54 | |
| 55 | #if 0 // until necessary |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 56 | sp<StreamOutHalInterface> stream() const { return mStream; } |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 57 | #endif |
| 58 | |
| 59 | private: |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 60 | sp<StreamOutHalInterface> mStream; |
Glenn Kasten | 0106623 | 2012-02-27 11:50:44 -0800 | [diff] [blame] | 61 | size_t mStreamBufferSizeBytes; // as reported by get_buffer_size() |
| 62 | }; |
| 63 | |
| 64 | } // namespace android |
| 65 | |
| 66 | #endif // ANDROID_AUDIO_STREAM_OUT_SINK_H |