Commit 7fc90608 authored by Frédéric Yhuel's avatar Frédéric Yhuel Committed by Hugo Beauzée-Luyssen

DASH: implement Seek()

This is needed for DASH module to work with (not yet ready) VLC MP4
demux. Forward seeking is implemented by calling Read() with a NULL
argument (= skipping), while backward seeking is limited to the current
block in the block_bytestream_t upon which is built the internal buffer.
This limitation is not really a problem because backward seeking will be
needed only for the parsing of the initialization fragment.
Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent 4605535b
......@@ -74,6 +74,11 @@ int DASHManager::read( void *p_buffer, size_t len )
return this->buffer->get(p_buffer, len);
}
int DASHManager::seekBackwards( unsigned i_len )
{
return this->buffer->seekBackwards( i_len );
}
int DASHManager::peek( const uint8_t **pp_peek, size_t i_peek )
{
return this->buffer->peek(pp_peek, i_peek);
......
......@@ -47,6 +47,7 @@ namespace dash
bool start ();
int read ( void *p_buffer, size_t len );
int peek ( const uint8_t **pp_peek, size_t i_peek );
int seekBackwards ( unsigned len );
const mpd::IMPDManager* getMpdManager () const;
const logic::IAdaptationLogic* getAdaptionLogic() const;
......
......@@ -85,6 +85,22 @@ int BlockBuffer::peek (const uint8_t **pp_peek, unsigned int
vlc_mutex_unlock(&this->monitorMutex);
return ret;
}
int BlockBuffer::seekBackwards (unsigned len)
{
vlc_mutex_lock(&this->monitorMutex);
if( this->buffer.i_offset > len )
{
this->buffer.i_offset -= len;
this->sizeBytes += len;
vlc_mutex_unlock(&this->monitorMutex);
return VLC_SUCCESS;
}
vlc_mutex_unlock(&this->monitorMutex);
return VLC_EGENERIC;
}
int BlockBuffer::get (void *p_data, unsigned int len)
{
vlc_mutex_lock(&this->monitorMutex);
......
......@@ -49,6 +49,7 @@ namespace dash
void put (block_t *block);
int get (void *p_data, unsigned int len);
int peek (const uint8_t **pp_peek, unsigned int i_peek);
int seekBackwards (unsigned len);
void setEOF (bool value);
bool getEOF ();
mtime_t size ();
......
......@@ -77,7 +77,7 @@ struct stream_sys_t
dash::DASHManager *p_dashManager;
dash::http::HTTPConnectionManager *p_conManager;
dash::mpd::MPD *p_mpd;
int position;
uint64_t position;
bool isLive;
};
......@@ -160,6 +160,46 @@ static void Close(vlc_object_t *p_obj)
/*****************************************************************************
* Callbacks:
*****************************************************************************/
static int Seek ( stream_t *p_stream, uint64_t pos )
{
stream_sys_t *p_sys = (stream_sys_t *) p_stream->p_sys;
dash::DASHManager *p_dashManager = p_sys->p_dashManager;
int i_ret = 0;
unsigned i_len = 0;
long i_read = 0;
if( pos < p_sys->position )
{
if( p_sys->position - pos > UINT_MAX )
{
msg_Err( p_stream, "Cannot seek backward that far!" );
return VLC_EGENERIC;
}
i_len = p_sys->position - pos;
i_ret = p_dashManager->seekBackwards( i_len );
if( i_ret == VLC_EGENERIC )
{
msg_Err( p_stream, "Cannot seek backward outside the current block :-/" );
return VLC_EGENERIC;
}
else
return VLC_SUCCESS;
}
/* Seek forward */
if( pos - p_sys->position > UINT_MAX )
{
msg_Err( p_stream, "Cannot seek forward that far!" );
return VLC_EGENERIC;
}
i_len = pos - p_sys->position;
i_read = Read( p_stream, (void *)NULL, i_len );
if( (unsigned)i_read == i_len )
return VLC_SUCCESS;
else
return VLC_EGENERIC;
}
static int Read (stream_t *p_stream, void *p_ptr, unsigned int i_len)
{
stream_sys_t *p_sys = (stream_sys_t *) p_stream->p_sys;
......@@ -221,7 +261,16 @@ static int Control (stream_t *p_stream, int i_query, va_list args)
*(va_arg (args, uint64_t *)) = p_sys->position;
break;
case STREAM_SET_POSITION:
{
uint64_t pos = (uint64_t)va_arg(args, uint64_t);
if(Seek(p_stream, pos) == VLC_SUCCESS)
{
p_sys->position = pos;
break;
}
else
return VLC_EGENERIC;
}
case STREAM_GET_SIZE:
{
uint64_t* res = (va_arg (args, uint64_t *));
......
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