demux: adaptive: use nullptr
[vlc.git] / modules / demux / smooth / playlist / MemoryChunk.cpp
blob4df94597898406c7fbab5ddcd62b4f886d8adbc5
1 /*
2 * MemoryChunk.cpp
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 *****************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
24 #include "MemoryChunk.hpp"
26 #include <vlc_block.h>
28 using namespace smooth::http;
30 MemoryChunkSource::MemoryChunkSource(block_t *block)
32 data = block;
33 i_read = 0;
34 contentLength = data->i_buffer;
37 MemoryChunkSource::~MemoryChunkSource()
39 if(data)
40 block_Release(data);
43 bool MemoryChunkSource::hasMoreData() const
45 return i_read > contentLength;
48 block_t * MemoryChunkSource::readBlock()
50 block_t *p_block = nullptr;
51 if(data)
53 p_block = data;
54 data = nullptr;
56 return p_block;
59 block_t * MemoryChunkSource::read(size_t toread)
61 if(!data)
62 return nullptr;
64 block_t * p_block = nullptr;
66 toread = __MIN(data->i_buffer - i_read, toread);
67 if(toread > 0)
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;
73 i_read += toread;
77 return p_block;