blob: 508e0fe9bb0123a0561aad07d15c81d0aecd1431 [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_IN_SOURCE_H
18#define ANDROID_AUDIO_STREAM_IN_SOURCE_H
19
Glenn Kasten01066232012-02-27 11:50:44 -080020#include "NBAIO.h"
21
22namespace android {
23
Mikhail Naganova0c91332016-09-19 10:01:12 -070024class StreamInHalInterface;
25
Glenn Kasten01066232012-02-27 11:50:44 -080026// not multi-thread safe
27class AudioStreamInSource : public NBAIO_Source {
28
29public:
Mikhail Naganova0c91332016-09-19 10:01:12 -070030 AudioStreamInSource(sp<StreamInHalInterface> stream);
Glenn Kasten01066232012-02-27 11:50:44 -080031 virtual ~AudioStreamInSource();
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() const;
38
39 // NBAIO_Sink interface
40
41 //virtual size_t framesRead() const;
Andy Hung818e7a32016-02-16 18:08:07 -080042 virtual int64_t framesOverrun();
43 virtual int64_t overruns() { (void) framesOverrun(); return mOverruns; }
Glenn Kasten01066232012-02-27 11:50:44 -080044
45 // This is an over-estimate, and could dupe the caller into making a blocking read()
46 // FIXME Use an audio HAL API to query the buffer filling status when it's available.
Glenn Kasten4d693d62014-03-06 07:53:11 -080047 virtual ssize_t availableToRead() { return mStreamBufferSizeBytes / mFrameSize; }
Glenn Kasten01066232012-02-27 11:50:44 -080048
Glenn Kastend79072e2016-01-06 08:41:20 -080049 virtual ssize_t read(void *buffer, size_t count);
Glenn Kasten01066232012-02-27 11:50:44 -080050
51 // NBAIO_Sink end
52
53#if 0 // until necessary
Mikhail Naganova0c91332016-09-19 10:01:12 -070054 sp<StreamInHalInterface> stream() const { return mStream; }
Glenn Kasten01066232012-02-27 11:50:44 -080055#endif
56
57private:
Mikhail Naganova0c91332016-09-19 10:01:12 -070058 sp<StreamInHalInterface> mStream;
Glenn Kasten01066232012-02-27 11:50:44 -080059 size_t mStreamBufferSizeBytes; // as reported by get_buffer_size()
Andy Hung818e7a32016-02-16 18:08:07 -080060 int64_t mFramesOverrun;
61 int64_t mOverruns;
Glenn Kasten01066232012-02-27 11:50:44 -080062};
63
64} // namespace android
65
66#endif // ANDROID_AUDIO_STREAM_IN_SOURCE_H