AudioStreamOutSink.h revision 010662326b9c43c703725f933e95e0897f8a6bdd
1010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten/*
2010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * Copyright (C) 2012 The Android Open Source Project
3010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten *
4010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * Licensed under the Apache License, Version 2.0 (the "License");
5010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * you may not use this file except in compliance with the License.
6010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * You may obtain a copy of the License at
7010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten *
8010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten *      http://www.apache.org/licenses/LICENSE-2.0
9010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten *
10010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * Unless required by applicable law or agreed to in writing, software
11010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * distributed under the License is distributed on an "AS IS" BASIS,
12010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * See the License for the specific language governing permissions and
14010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten * limitations under the License.
15010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten */
16010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
17010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#ifndef ANDROID_AUDIO_STREAM_OUT_SINK_H
18010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#define ANDROID_AUDIO_STREAM_OUT_SINK_H
19010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
20010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#include <hardware/audio.h>
21010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#include "NBAIO.h"
22010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
23010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastennamespace android {
24010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
25010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten// not multi-thread safe
26010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastenclass AudioStreamOutSink : public NBAIO_Sink {
27010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
28010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastenpublic:
29010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    AudioStreamOutSink(audio_stream_out *stream);
30010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    virtual ~AudioStreamOutSink();
31010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
32010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // NBAIO_Port interface
33010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
34010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
35010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten                              NBAIO_Format counterOffers[], size_t& numCounterOffers);
36010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual NBAIO_Format format();
37010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
38010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // NBAIO_Sink interface
39010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
40010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual size_t framesWritten() const;
41010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual size_t framesUnderrun() const;
42010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual size_t underruns() const;
43010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
44010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // This is an over-estimate, and could dupe the caller into making a blocking write()
45010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // FIXME Use an audio HAL API to query the buffer emptying status when it's available.
46010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    virtual ssize_t availableToWrite() const { return mStreamBufferSizeBytes >> mBitShift; }
47010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
48010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    virtual ssize_t write(const void *buffer, size_t count);
49010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
50010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // NBAIO_Sink end
51010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
52010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#if 0   // until necessary
53010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    audio_stream_out *stream() const { return mStream; }
54010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#endif
55010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
56010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastenprivate:
57010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    audio_stream_out * const mStream;
58010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    size_t              mStreamBufferSizeBytes; // as reported by get_buffer_size()
59010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten};
60010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
61010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten}   // namespace android
62010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
63010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#endif  // ANDROID_AUDIO_STREAM_OUT_SINK_H
64