| Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 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 |  | 
| Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 20 | #include <utils/Errors.h> | 
 | 21 |  | 
 | 22 | namespace android { | 
 | 23 | // ---------------------------------------------------------------------------- | 
 | 24 |  | 
 | 25 | class AudioBufferProvider | 
 | 26 | { | 
 | 27 | public: | 
 | 28 |  | 
| Glenn Kasten | 9f80dd2 | 2012-12-18 15:57:32 -0800 | [diff] [blame] | 29 |     // FIXME merge with AudioTrackShared::Buffer, AudioTrack::Buffer, and AudioRecord::Buffer | 
 | 30 |     //       and rename getNextBuffer() to obtainBuffer() | 
| Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 31 |     struct Buffer { | 
| Glenn Kasten | 01c4ebf | 2012-02-22 10:47:35 -0800 | [diff] [blame] | 32 |         Buffer() : raw(NULL), frameCount(0) { } | 
| Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 33 |         union { | 
 | 34 |             void*       raw; | 
 | 35 |             short*      i16; | 
 | 36 |             int8_t*     i8; | 
 | 37 |         }; | 
 | 38 |         size_t frameCount; | 
 | 39 |     }; | 
 | 40 |  | 
| Glenn Kasten | 409e374 | 2013-02-27 09:39:39 -0800 | [diff] [blame] | 41 |     virtual ~AudioBufferProvider() {} | 
| John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 42 |  | 
| Glenn Kasten | 9f80dd2 | 2012-12-18 15:57:32 -0800 | [diff] [blame] | 43 |     // On entry: | 
 | 44 |     //  buffer              != NULL | 
 | 45 |     //  buffer->raw         unused | 
 | 46 |     //  buffer->frameCount  maximum number of desired frames | 
 | 47 |     // On successful return: | 
 | 48 |     //  status              NO_ERROR | 
 | 49 |     //  buffer->raw         non-NULL pointer to buffer->frameCount contiguous available frames | 
 | 50 |     //  buffer->frameCount  number of contiguous available frames at buffer->raw, | 
 | 51 |     //                      0 < buffer->frameCount <= entry value | 
 | 52 |     // On error return: | 
 | 53 |     //  status              != NO_ERROR | 
 | 54 |     //  buffer->raw         NULL | 
 | 55 |     //  buffer->frameCount  0 | 
| Glenn Kasten | d79072e | 2016-01-06 08:41:20 -0800 | [diff] [blame] | 56 |     virtual status_t getNextBuffer(Buffer* buffer) = 0; | 
| John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 57 |  | 
| Glenn Kasten | 47f3f5a | 2013-12-17 16:14:04 -0800 | [diff] [blame] | 58 |     // Release (a portion of) the buffer previously obtained by getNextBuffer(). | 
 | 59 |     // It is permissible to call releaseBuffer() multiple times per getNextBuffer(). | 
 | 60 |     // On entry: | 
 | 61 |     //  buffer->frameCount  number of frames to release, must be <= number of frames | 
 | 62 |     //                      obtained but not yet released | 
 | 63 |     //  buffer->raw         unused | 
 | 64 |     // On return: | 
 | 65 |     //  buffer->frameCount  0; implementation MUST set to zero | 
 | 66 |     //  buffer->raw         undefined; implementation is PERMITTED to set to any value, | 
 | 67 |     //                      so if caller needs to continue using this buffer it must | 
 | 68 |     //                      keep track of the pointer itself | 
| Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 69 |     virtual void releaseBuffer(Buffer* buffer) = 0; | 
| Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 70 | }; | 
 | 71 |  | 
 | 72 | // ---------------------------------------------------------------------------- | 
 | 73 | }; // namespace android | 
 | 74 |  | 
 | 75 | #endif // ANDROID_AUDIO_BUFFER_PROVIDER_H |