1 /*****************************************************************************
2 * stream_io_callback.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004, 2010 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "stream_io_callback.hpp"
27 #include "matroska_segment.hpp"
30 /*****************************************************************************
32 *****************************************************************************/
33 vlc_stream_io_callback::vlc_stream_io_callback( stream_t *s_, bool b_owner_ )
34 : s( s_), b_owner( b_owner_ )
39 uint32 vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
41 if( i_size <= 0 || mb_eof )
44 return stream_Read( s, p_buffer, i_size );
47 void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
49 int64_t i_pos, i_size;
57 i_pos = stream_Size( s ) - i_offset;
60 i_pos= stream_Tell( s ) + i_offset;
64 if( i_pos < 0 || ( ( i_size = stream_Size( s ) ) != 0 && i_pos >= i_size ) )
71 if( stream_Seek( s, i_pos ) )
78 uint64 vlc_stream_io_callback::getFilePointer( void )
82 return stream_Tell( s );
85 size_t vlc_stream_io_callback::write(const void *, size_t )
90 uint64 vlc_stream_io_callback::toRead( void )
97 stream_Control( s, STREAM_GET_SIZE, &i_size );
102 return (uint64) i_size - stream_Tell( s );