3 *****************************************************************************
4 * Copyright © 2015 - VideoLAN and VLC Authors
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20 #ifndef SOURCESTREAM_HPP
21 #define SOURCESTREAM_HPP
23 #include <vlc_common.h>
24 #include <vlc_block.h>
25 #include <vlc_block_helper.h>
32 class AbstractSourceStream
35 virtual ~AbstractSourceStream() {}
36 virtual stream_t
*makeStream() = 0;
37 virtual void Reset() = 0;
38 virtual size_t Peek(const uint8_t **, size_t) = 0;
41 class AbstractChunksSourceStream
: public AbstractSourceStream
44 AbstractChunksSourceStream(vlc_object_t
*, AbstractSource
*);
45 virtual ~AbstractChunksSourceStream();
46 virtual void Reset() override
;
47 virtual stream_t
*makeStream() override
;
50 virtual ssize_t
Read(uint8_t *, size_t) = 0;
51 virtual int Seek(uint64_t) = 0;
54 AbstractSource
*source
;
57 static ssize_t
read_Callback(stream_t
*, void *, size_t);
58 static int seek_Callback(stream_t
*, uint64_t);
59 static int control_Callback( stream_t
*, int i_query
, va_list );
60 static void delete_Callback( stream_t
* );
63 class ChunksSourceStream
: public AbstractChunksSourceStream
66 ChunksSourceStream(vlc_object_t
*, AbstractSource
*);
67 virtual ~ChunksSourceStream();
68 virtual void Reset() override
;
71 virtual ssize_t
Read(uint8_t *, size_t) override
;
72 virtual int Seek(uint64_t) override
;
73 virtual size_t Peek(const uint8_t **, size_t) override
;
79 class BufferedChunksSourceStream
: public AbstractChunksSourceStream
82 BufferedChunksSourceStream(vlc_object_t
*, AbstractSource
*);
83 virtual ~BufferedChunksSourceStream();
84 virtual void Reset() override
;
87 virtual ssize_t
Read(uint8_t *, size_t) override
;
88 virtual int Seek(uint64_t) override
;
89 virtual size_t Peek(const uint8_t **, size_t) override
;
92 ssize_t
doRead(uint8_t *, size_t);
93 void fillByteStream(size_t);
94 void invalidatePeek();
95 static const int MAX_BACKEND
= 5 * 1024 * 1024;
96 static const int MIN_BACKEND_CLEANUP
= 50 * 1024;
97 uint64_t i_global_offset
;
98 size_t i_bytestream_offset
;
99 block_bytestream_t bs
;
103 #endif // SOURCESTREAM_HPP