1 | /********** |
2 | This library is free software; you can redistribute it and/or modify it under |
3 | the terms of the GNU Lesser General Public License as published by the |
4 | Free Software Foundation; either version 3 of the License, or (at your |
5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
6 | |
7 | This library is distributed in the hope that it will be useful, but WITHOUT |
8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
10 | more details. |
11 | |
12 | You should have received a copy of the GNU Lesser General Public License |
13 | along with this library; if not, write to the Free Software Foundation, Inc., |
14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
15 | **********/ |
16 | // "liveMedia" |
17 | // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. |
18 | // A class for streaming data from a (static) memory buffer, as if it were a file. |
19 | // C++ header |
20 | |
21 | #ifndef _BYTE_STREAM_MEMORY_BUFFER_SOURCE_HH |
22 | #define _BYTE_STREAM_MEMORY_BUFFER_SOURCE_HH |
23 | |
24 | #ifndef _FRAMED_SOURCE_HH |
25 | #include "FramedSource.hh" |
26 | #endif |
27 | |
28 | class ByteStreamMemoryBufferSource: public FramedSource { |
29 | public: |
30 | static ByteStreamMemoryBufferSource* createNew(UsageEnvironment& env, |
31 | u_int8_t* buffer, u_int64_t bufferSize, |
32 | Boolean deleteBufferOnClose = True, |
33 | unsigned preferredFrameSize = 0, |
34 | unsigned playTimePerFrame = 0); |
35 | // "preferredFrameSize" == 0 means 'no preference' |
36 | // "playTimePerFrame" is in microseconds |
37 | |
38 | u_int64_t bufferSize() const { return fBufferSize; } |
39 | |
40 | void seekToByteAbsolute(u_int64_t byteNumber, u_int64_t numBytesToStream = 0); |
41 | // if "numBytesToStream" is >0, then we limit the stream to that number of bytes, before treating it as EOF |
42 | void seekToByteRelative(int64_t offset, u_int64_t numBytesToStream = 0); |
43 | |
44 | protected: |
45 | ByteStreamMemoryBufferSource(UsageEnvironment& env, |
46 | u_int8_t* buffer, u_int64_t bufferSize, |
47 | Boolean deleteBufferOnClose, |
48 | unsigned preferredFrameSize, |
49 | unsigned playTimePerFrame); |
50 | // called only by createNew() |
51 | |
52 | virtual ~ByteStreamMemoryBufferSource(); |
53 | |
54 | private: |
55 | // redefined virtual functions: |
56 | virtual void doGetNextFrame(); |
57 | |
58 | private: |
59 | u_int8_t* fBuffer; |
60 | u_int64_t fBufferSize; |
61 | u_int64_t fCurIndex; |
62 | Boolean fDeleteBufferOnClose; |
63 | unsigned fPreferredFrameSize; |
64 | unsigned fPlayTimePerFrame; |
65 | unsigned fLastPlayTime; |
66 | Boolean fLimitNumBytesToStream; |
67 | u_int64_t fNumBytesToStream; // used iff "fLimitNumBytesToStream" is True |
68 | }; |
69 | |
70 | #endif |
71 | |