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 ) ...@@ -74,6 +74,11 @@ int DASHManager::read( void *p_buffer, size_t len )
return this->buffer->get(p_buffer, 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 ) int DASHManager::peek( const uint8_t **pp_peek, size_t i_peek )
{ {
return this->buffer->peek(pp_peek, i_peek); return this->buffer->peek(pp_peek, i_peek);
......
...@@ -47,6 +47,7 @@ namespace dash ...@@ -47,6 +47,7 @@ namespace dash
bool start (); bool start ();
int read ( void *p_buffer, size_t len ); int read ( void *p_buffer, size_t len );
int peek ( const uint8_t **pp_peek, size_t i_peek ); int peek ( const uint8_t **pp_peek, size_t i_peek );
int seekBackwards ( unsigned len );
const mpd::IMPDManager* getMpdManager () const; const mpd::IMPDManager* getMpdManager () const;
const logic::IAdaptationLogic* getAdaptionLogic() const; const logic::IAdaptationLogic* getAdaptionLogic() const;
......
...@@ -85,6 +85,22 @@ int BlockBuffer::peek (const uint8_t **pp_peek, unsigned int ...@@ -85,6 +85,22 @@ int BlockBuffer::peek (const uint8_t **pp_peek, unsigned int
vlc_mutex_unlock(&this->monitorMutex); vlc_mutex_unlock(&this->monitorMutex);
return ret; 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) int BlockBuffer::get (void *p_data, unsigned int len)
{ {
vlc_mutex_lock(&this->monitorMutex); vlc_mutex_lock(&this->monitorMutex);
......
...@@ -49,6 +49,7 @@ namespace dash ...@@ -49,6 +49,7 @@ namespace dash
void put (block_t *block); void put (block_t *block);
int get (void *p_data, unsigned int len); int get (void *p_data, unsigned int len);
int peek (const uint8_t **pp_peek, unsigned int i_peek); int peek (const uint8_t **pp_peek, unsigned int i_peek);
int seekBackwards (unsigned len);
void setEOF (bool value); void setEOF (bool value);
bool getEOF (); bool getEOF ();
mtime_t size (); mtime_t size ();
......
...@@ -77,7 +77,7 @@ struct stream_sys_t ...@@ -77,7 +77,7 @@ struct stream_sys_t
dash::DASHManager *p_dashManager; dash::DASHManager *p_dashManager;
dash::http::HTTPConnectionManager *p_conManager; dash::http::HTTPConnectionManager *p_conManager;
dash::mpd::MPD *p_mpd; dash::mpd::MPD *p_mpd;
int position; uint64_t position;
bool isLive; bool isLive;
}; };
...@@ -160,6 +160,46 @@ static void Close(vlc_object_t *p_obj) ...@@ -160,6 +160,46 @@ static void Close(vlc_object_t *p_obj)
/***************************************************************************** /*****************************************************************************
* Callbacks: * 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) 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; 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) ...@@ -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; *(va_arg (args, uint64_t *)) = p_sys->position;
break; break;
case STREAM_SET_POSITION: 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; return VLC_EGENERIC;
}
case STREAM_GET_SIZE: case STREAM_GET_SIZE:
{ {
uint64_t* res = (va_arg (args, uint64_t *)); 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