PcmBufferProvider.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /****************************************************************************
  2. Copyright (c) 2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #pragma once
  22. #include "audio/android/AudioBufferProvider.h"
  23. #include <stddef.h>
  24. #include <stdio.h>
  25. namespace cocos2d { namespace experimental {
  26. class PcmBufferProvider : public AudioBufferProvider
  27. {
  28. public:
  29. PcmBufferProvider();
  30. bool init(const void *addr, size_t frames, size_t frameSize);
  31. virtual status_t getNextBuffer(Buffer *buffer, int64_t pts = kInvalidPTS) override ;
  32. virtual void releaseBuffer(Buffer *buffer) override ;
  33. void reset();
  34. protected:
  35. const void *_addr; // base address
  36. size_t _numFrames; // total frames
  37. size_t _frameSize; // size of each frame in bytes
  38. size_t _nextFrame; // index of next frame to provide
  39. size_t _unrel; // number of frames not yet released
  40. };
  41. }} // namespace cocos2d { namespace experimental {