blob: 3c59da29f08ca13b63cc41180ccb540b24de6793 [file] [log] [blame]
Glenn Kasten01066232012-02-27 11:50:44 -08001/*
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
20#include <hardware/audio.h>
21#include "NBAIO.h"
22
23namespace android {
24
Mikhail Naganova0c91332016-09-19 10:01:12 -070025class StreamOutHalInterface;
26
Glenn Kasten01066232012-02-27 11:50:44 -080027// not multi-thread safe
28class AudioStreamOutSink : public NBAIO_Sink {
29
30public:
Mikhail Naganova0c91332016-09-19 10:01:12 -070031 AudioStreamOutSink(sp<StreamOutHalInterface> stream);
Glenn Kasten01066232012-02-27 11:50:44 -080032 virtual ~AudioStreamOutSink();
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();
39
40 // NBAIO_Sink interface
41
42 //virtual size_t framesWritten() const;
43 //virtual size_t framesUnderrun() const;
44 //virtual size_t underruns() const;
45
46 // This is an over-estimate, and could dupe the caller into making a blocking write()
47 // FIXME Use an audio HAL API to query the buffer emptying status when it's available.
Glenn Kasten4d693d62014-03-06 07:53:11 -080048 virtual ssize_t availableToWrite() const { return mStreamBufferSizeBytes / mFrameSize; }
Glenn Kasten01066232012-02-27 11:50:44 -080049
50 virtual ssize_t write(const void *buffer, size_t count);
51
Andy Hung818e7a32016-02-16 18:08:07 -080052 virtual status_t getTimestamp(ExtendedTimestamp &timestamp);
Glenn Kasten767094d2013-08-23 13:51:43 -070053
Glenn Kasten01066232012-02-27 11:50:44 -080054 // NBAIO_Sink end
55
56#if 0 // until necessary
Mikhail Naganova0c91332016-09-19 10:01:12 -070057 sp<StreamOutHalInterface> stream() const { return mStream; }
Glenn Kasten01066232012-02-27 11:50:44 -080058#endif
59
60private:
Mikhail Naganova0c91332016-09-19 10:01:12 -070061 sp<StreamOutHalInterface> mStream;
Glenn Kasten01066232012-02-27 11:50:44 -080062 size_t mStreamBufferSizeBytes; // as reported by get_buffer_size()
63};
64
65} // namespace android
66
67#endif // ANDROID_AUDIO_STREAM_OUT_SINK_H