AudioBufferProvider.h 3.1 KB

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