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 
20 #include <audio_utils/MelProcessor.h>
21 #include <media/nbaio/NBAIO.h>
22 #include <mediautils/Synchronization.h>
23 
24 namespace android {
25 
26 class StreamOutHalInterface;
27 
28 // not multi-thread safe
29 class AudioStreamOutSink : public NBAIO_Sink {
30 
31 public:
32     AudioStreamOutSink(sp<StreamOutHalInterface> stream);
33     virtual ~AudioStreamOutSink();
34 
35     // NBAIO_Port interface
36 
37     virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
38                               NBAIO_Format counterOffers[], size_t& numCounterOffers);
39     //virtual NBAIO_Format format();
40 
41     // NBAIO_Sink interface
42 
43     //virtual size_t framesWritten() const;
44     //virtual size_t framesUnderrun() const;
45     //virtual size_t underruns() const;
46 
47     virtual ssize_t write(const void *buffer, size_t count);
48 
49     virtual status_t getTimestamp(ExtendedTimestamp &timestamp);
50 
51     // NBAIO_Sink end
52 
53     void startMelComputation(const sp<audio_utils::MelProcessor>& processor);
54 
55     void stopMelComputation();
56 
57 #if 0   // until necessary
58     sp<StreamOutHalInterface> stream() const { return mStream; }
59 #endif
60 
61 private:
62     sp<StreamOutHalInterface> mStream;
63     size_t              mStreamBufferSizeBytes; // as reported by get_buffer_size()
64     mediautils::atomic_sp<audio_utils::MelProcessor> mMelProcessor;
65 };
66 
67 }   // namespace android
68 
69 #endif  // ANDROID_AUDIO_STREAM_OUT_SINK_H
70