Home | History | Annotate | Download | only in nbaio
      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 // Implementation of AudioBufferProvider that wraps an NBAIO_Source
     18 
     19 #ifndef ANDROID_SOURCE_AUDIO_BUFFER_PROVIDER_H
     20 #define ANDROID_SOURCE_AUDIO_BUFFER_PROVIDER_H
     21 
     22 #include "NBAIO.h"
     23 #include <media/ExtendedAudioBufferProvider.h>
     24 
     25 namespace android {
     26 
     27 class SourceAudioBufferProvider : public ExtendedAudioBufferProvider {
     28 
     29 public:
     30     SourceAudioBufferProvider(const sp<NBAIO_Source>& source);
     31     virtual ~SourceAudioBufferProvider();
     32 
     33     // AudioBufferProvider interface
     34     virtual status_t getNextBuffer(Buffer *buffer, int64_t pts);
     35     virtual void     releaseBuffer(Buffer *buffer);
     36 
     37     // ExtendedAudioBufferProvider interface
     38     virtual size_t   framesReady() const;
     39     virtual size_t   framesReleased() const;
     40     virtual void     onTimestamp(const AudioTimestamp& timestamp);
     41 
     42 private:
     43     const sp<NBAIO_Source> mSource;     // the wrapped source
     44     /*const*/ size_t    mFrameBitShift; // log2(frame size in bytes)
     45     void*               mAllocated; // pointer to base of allocated memory
     46     size_t              mSize;      // size of mAllocated in frames
     47     size_t              mOffset;    // frame offset within mAllocated of valid data
     48     size_t              mRemaining; // frame count within mAllocated of valid data
     49     size_t              mGetCount;  // buffer.frameCount of the most recent getNextBuffer
     50     uint32_t            mFramesReleased;    // counter of the total number of frames released
     51 };
     52 
     53 }   // namespace android
     54 
     55 #endif  // ANDROID_SOURCE_AUDIO_BUFFER_PROVIDER_H
     56