BufferReader.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  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. /**
  18. * @file BufferReader.h
  19. * @ingroup util
  20. * The BufferReader class.
  21. */
  22. #include "IReader.h"
  23. #include <memory>
  24. AUD_NAMESPACE_BEGIN
  25. class Buffer;
  26. /**
  27. * This class represents a simple reader from a buffer that exists in memory.
  28. * \warning Notice that the buffer is not multi-threading ready, so changing the
  29. * buffer while the reader is reading is potentially dangerous.
  30. */
  31. class AUD_API BufferReader : public IReader
  32. {
  33. private:
  34. /**
  35. * The current position in the buffer.
  36. */
  37. int m_position;
  38. /**
  39. * The buffer that is read.
  40. */
  41. std::shared_ptr<Buffer> m_buffer;
  42. /**
  43. * The specification of the sample data in the buffer.
  44. */
  45. Specs m_specs;
  46. // delete copy constructor and operator=
  47. BufferReader(const BufferReader&) = delete;
  48. BufferReader& operator=(const BufferReader&) = delete;
  49. public:
  50. /**
  51. * Creates a new buffer reader.
  52. * \param buffer The buffer to read from.
  53. * \param specs The specification of the sample data in the buffer.
  54. */
  55. BufferReader(std::shared_ptr<Buffer> buffer, Specs specs);
  56. virtual bool isSeekable() const;
  57. virtual void seek(int position);
  58. virtual int getLength() const;
  59. virtual int getPosition() const;
  60. virtual Specs getSpecs() const;
  61. virtual void read(int& length, bool& eos, sample_t* buffer);
  62. };
  63. AUD_NAMESPACE_END