3 *****************************************************************************
4 * Copyright (C) 2015 - VideoLAN 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 *****************************************************************************/
24 #include "MemoryChunk.hpp"
26 #include <vlc_block.h>
28 using namespace smooth::http
;
30 MemoryChunkSource::MemoryChunkSource(block_t
*block
)
34 contentLength
= data
->i_buffer
;
37 MemoryChunkSource::~MemoryChunkSource()
43 bool MemoryChunkSource::hasMoreData() const
45 return i_read
> contentLength
;
48 block_t
* MemoryChunkSource::readBlock()
50 block_t
*p_block
= nullptr;
59 block_t
* MemoryChunkSource::read(size_t toread
)
64 block_t
* p_block
= nullptr;
66 toread
= __MIN(data
->i_buffer
- i_read
, toread
);
69 if((p_block
= block_Alloc(toread
)))
71 memcpy(p_block
->p_buffer
, &data
->p_buffer
[i_read
], toread
);
72 p_block
->i_buffer
= toread
;