Commit 42880f79 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: add SourceStream

parent fe5049dd
......@@ -307,8 +307,11 @@ libadaptative_plugin_la_SOURCES = \
demux/adaptative/plumbing/FakeESOut.hpp \
demux/adaptative/plumbing/FakeESOutID.cpp \
demux/adaptative/plumbing/FakeESOutID.hpp \
demux/adaptative/plumbing/SourceStream.cpp \
demux/adaptative/plumbing/SourceStream.hpp \
demux/adaptative/plumbing/StreamOutput.cpp \
demux/adaptative/plumbing/StreamOutput.hpp \
demux/adaptative/ChunksSource.hpp \
demux/adaptative/PlaylistManager.cpp \
demux/adaptative/PlaylistManager.h \
demux/adaptative/SegmentTracker.cpp \
......
/*
* ChunksSource.hpp
*****************************************************************************
* Copyright © 2015 - VideoLAN and VLC Authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef CHUNKSSOURCE_HPP
#define CHUNKSSOURCE_HPP
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
namespace adaptative
{
class ChunksSource
{
public:
virtual block_t *readNextBlock(size_t) = 0;
};
}
#endif // CHUNKSSOURCE_HPP
/*
* SourceStream.cpp
*****************************************************************************
* Copyright © 2015 - VideoLAN and VLC Authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "SourceStream.hpp"
#include "../ChunksSource.hpp"
#include <vlc_stream.h>
#include <vlc_demux.h>
using namespace adaptative;
ChunksSourceStream::ChunksSourceStream(vlc_object_t *p_obj, ChunksSource *source_)
{
p_block = NULL;
b_eof = false;
custom_stream = stream_CustomNew( p_obj, delete_Callback );
if(!custom_stream)
throw VLC_EGENERIC;
custom_stream->pf_control = control_Callback;
custom_stream->pf_read = read_Callback;
custom_stream->pf_readdir = NULL;
custom_stream->pf_seek = seek_Callback;
custom_stream->p_sys = reinterpret_cast<stream_sys_t*>(this);
source = source_;
}
ChunksSourceStream::~ChunksSourceStream()
{
if (custom_stream)
stream_Delete(custom_stream);
Reset();
}
void ChunksSourceStream::Reset()
{
if(p_block)
block_Release(p_block);
p_block = NULL;
b_eof = false;
}
stream_t * ChunksSourceStream::getStream()
{
return custom_stream;
}
ssize_t ChunksSourceStream::Read(uint8_t *buf, size_t size)
{
size_t i_copied = 0;
size_t i_toread = size;
while(i_toread && !b_eof)
{
if(!p_block && !(p_block = source->readNextBlock(i_toread)))
{
b_eof = true;
break;
}
if(p_block->i_buffer > i_toread)
{
if(buf)
memcpy(buf + i_copied, p_block->p_buffer, i_toread);
i_copied += i_toread;
p_block->p_buffer += i_toread;
p_block->i_buffer -= i_toread;
i_toread = 0;
}
else
{
if(buf)
memcpy(buf + i_copied, p_block->p_buffer, p_block->i_buffer);
i_copied += p_block->i_buffer;
i_toread -= p_block->i_buffer;
block_Release(p_block);
p_block = NULL;
}
}
return i_copied;
}
ssize_t ChunksSourceStream::read_Callback(stream_t *s, void *buf, size_t size)
{
ChunksSourceStream *me = reinterpret_cast<ChunksSourceStream *>(s->p_sys);
return me->Read(reinterpret_cast<uint8_t *>(buf), size);
}
int ChunksSourceStream::seek_Callback(stream_t *, uint64_t)
{
return VLC_EGENERIC;
}
int ChunksSourceStream::control_Callback(stream_t *, int i_query, va_list args)
{
switch( i_query )
{
case STREAM_GET_SIZE:
*(va_arg( args, uint64_t * )) = 0;
return VLC_SUCCESS;
case STREAM_CAN_SEEK:
case STREAM_CAN_FASTSEEK:
case STREAM_CAN_PAUSE:
case STREAM_CAN_CONTROL_PACE:
*va_arg( args, bool * ) = false;
return VLC_SUCCESS;
case STREAM_GET_PTS_DELAY:
*(va_arg( args, uint64_t * )) = DEFAULT_PTS_DELAY;
return VLC_SUCCESS;
default:
return VLC_EGENERIC;
}
}
void ChunksSourceStream::delete_Callback(stream_t *)
{
}
/*
* SourceStream.hpp
*****************************************************************************
* Copyright © 2015 - VideoLAN and VLC Authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef SOURCESTREAM_HPP
#define SOURCESTREAM_HPP
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_block.h>
namespace adaptative
{
class ChunksSource;
class AbstractSourceStream
{
public:
virtual ~AbstractSourceStream() {}
virtual stream_t *getStream() = 0;
virtual void Reset() = 0;
};
class ChunksSourceStream : public AbstractSourceStream
{
public:
ChunksSourceStream(vlc_object_t *, ChunksSource *);
virtual ~ChunksSourceStream();
virtual stream_t *getStream(); /* impl */
virtual void Reset(); /* impl */
protected:
ssize_t Read(uint8_t *, size_t);
private:
block_t *p_block;
bool b_eof;
static ssize_t read_Callback(stream_t *, void *, size_t);
static int seek_Callback(stream_t *, uint64_t);
static int control_Callback( stream_t *, int i_query, va_list );
static void delete_Callback( stream_t * );
stream_t *custom_stream;
ChunksSource *source;
};
}
#endif // SOURCESTREAM_HPP
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment