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_PIPE_READER_H
18010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#define ANDROID_AUDIO_PIPE_READER_H
19010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
20010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#include "Pipe.h"
21010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
22010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastennamespace android {
23010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
24010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten// PipeReader is safe for only a single thread
25010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastenclass PipeReader : public NBAIO_Source {
26010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
27010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastenpublic:
28010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
29010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // Construct a PipeReader and associate it with a Pipe
30010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // FIXME make this constructor a factory method of Pipe.
31010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    PipeReader(Pipe& pipe);
32010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    virtual ~PipeReader();
33010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
34010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // NBAIO_Port interface
35010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
36010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
37010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //                          NBAIO_Format counterOffers[], size_t& numCounterOffers);
38010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual NBAIO_Format format() const;
39010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
40010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // NBAIO_Source interface
41010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
42010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    //virtual size_t framesRead() const;
43818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    virtual int64_t framesOverrun() { return mFramesOverrun; }
44818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    virtual int64_t overruns()  { return mOverruns; }
45010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
46010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    virtual ssize_t availableToRead();
47010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
48d79072e9dff59f767cce2cda1caab80ce5a0815bGlenn Kasten    virtual ssize_t read(void *buffer, size_t count);
49010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
50ad6d52d38917069e3d8e68cec1625855b9d96200Andy Hung    virtual ssize_t flush();
51ad6d52d38917069e3d8e68cec1625855b9d96200Andy Hung
52010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    // NBAIO_Source end
53010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
54010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#if 0   // until necessary
55010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    Pipe& pipe() const { return mPipe; }
56010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#endif
57010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
58010662326b9c43c703725f933e95e0897f8a6bddGlenn Kastenprivate:
59010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten    Pipe&       mPipe;
60ed99c2b5a99a8bfc163a6ffa0b767c82032b09b5Glenn Kasten    audio_utils_fifo_reader mFifoReader;
61818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    int64_t     mFramesOverrun;
62818e7a32ce3633980138aff2c2bfcc5158b3cfccAndy Hung    int64_t     mOverruns;
63010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten};
64010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
65010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten}   // namespace android
66010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten
67010662326b9c43c703725f933e95e0897f8a6bddGlenn Kasten#endif  // ANDROID_AUDIO_PIPE_READER_H
68