Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2007 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_BUFFER_PROVIDER_H
     18 #define ANDROID_AUDIO_BUFFER_PROVIDER_H
     19 
     20 #include <utils/Errors.h>
     21 
     22 namespace android {
     23 // ----------------------------------------------------------------------------
     24 
     25 class AudioBufferProvider
     26 {
     27 public:
     28 
     29     // FIXME merge with AudioTrackShared::Buffer, AudioTrack::Buffer, and AudioRecord::Buffer
     30     //       and rename getNextBuffer() to obtainBuffer()
     31     struct Buffer {
     32         Buffer() : raw(NULL), frameCount(0) { }
     33         union {
     34             void*       raw;
     35             short*      i16;
     36             int8_t*     i8;
     37         };
     38         size_t frameCount;
     39     };
     40 
     41     virtual ~AudioBufferProvider() {}
     42 
     43     // value representing an invalid presentation timestamp
     44     static const int64_t kInvalidPTS = 0x7FFFFFFFFFFFFFFFLL;    // <stdint.h> is too painful
     45 
     46     // pts is the local time when the next sample yielded by getNextBuffer
     47     // will be rendered.
     48     // Pass kInvalidPTS if the PTS is unknown or not applicable.
     49     // On entry:
     50     //  buffer              != NULL
     51     //  buffer->raw         unused
     52     //  buffer->frameCount  maximum number of desired frames
     53     // On successful return:
     54     //  status              NO_ERROR
     55     //  buffer->raw         non-NULL pointer to buffer->frameCount contiguous available frames
     56     //  buffer->frameCount  number of contiguous available frames at buffer->raw,
     57     //                      0 < buffer->frameCount <= entry value
     58     // On error return:
     59     //  status              != NO_ERROR
     60     //  buffer->raw         NULL
     61     //  buffer->frameCount  0
     62     virtual status_t getNextBuffer(Buffer* buffer, int64_t pts = kInvalidPTS) = 0;
     63 
     64     // Release (a portion of) the buffer previously obtained by getNextBuffer().
     65     // It is permissible to call releaseBuffer() multiple times per getNextBuffer().
     66     // On entry:
     67     //  buffer->frameCount  number of frames to release, must be <= number of frames
     68     //                      obtained but not yet released
     69     //  buffer->raw         unused
     70     // On return:
     71     //  buffer->frameCount  0; implementation MUST set to zero
     72     //  buffer->raw         undefined; implementation is PERMITTED to set to any value,
     73     //                      so if caller needs to continue using this buffer it must
     74     //                      keep track of the pointer itself
     75     virtual void releaseBuffer(Buffer* buffer) = 0;
     76 };
     77 
     78 // ----------------------------------------------------------------------------
     79 }; // namespace android
     80 
     81 #endif // ANDROID_AUDIO_BUFFER_PROVIDER_H
     82