PipeReader.h revision fc7992bd8220824f1404c0c54ac516d9e28b58c2
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_PIPE_READER_H
18#define ANDROID_AUDIO_PIPE_READER_H
19
20#include "Pipe.h"
21
22namespace android {
23
24// PipeReader is safe for only a single thread
25class PipeReader : public NBAIO_Source {
26
27public:
28
29    // Construct a PipeReader and associate it with a Pipe
30    // FIXME make this constructor a factory method of Pipe.
31    PipeReader(Pipe& pipe);
32    virtual ~PipeReader();
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() const;
39
40    // NBAIO_Source interface
41
42    //virtual size_t framesRead() const;
43    virtual size_t framesOverrun() { return mFramesOverrun; }
44    virtual size_t overruns()  { return mOverruns; }
45
46    virtual ssize_t availableToRead();
47
48    virtual ssize_t read(void *buffer, size_t count, int64_t readPTS);
49
50    // NBAIO_Source end
51
52#if 0   // until necessary
53    Pipe& pipe() const { return mPipe; }
54#endif
55
56private:
57    Pipe&       mPipe;
58    int32_t     mFront;         // follows behind mPipe.mRear
59    size_t      mFramesOverrun;
60    size_t      mOverruns;
61};
62
63}   // namespace android
64
65#endif  // ANDROID_AUDIO_PIPE_READER_H
66