stream_io_callback.cpp 2.42 KB
Newer Older
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*****************************************************************************
 * mkv.cpp : matroska demuxer
 *****************************************************************************
 * Copyright (C) 2003-2004 the VideoLAN team
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *          Steve Lhomme <steve.lhomme@free.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU 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.
 *****************************************************************************/
25
#include "stream_io_callback.hpp"
26

27
28
#include "matroska_segment.hpp"
#include "demux.hpp"
29
30
31
/*****************************************************************************
 * Stream managment
 *****************************************************************************/
32
vlc_stream_io_callback::vlc_stream_io_callback( stream_t *s_, bool b_owner_ )
33
{
34
35
36
    s = s_;
    b_owner = b_owner_;
    mb_eof = false;
37
38
}

39
uint32 vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
40
{
41
    if( i_size <= 0 || mb_eof )
42
    {
43
        return 0;
44
45
    }

46
47
48
    return stream_Read( s, p_buffer, i_size );
}
void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
49
{
50
    int64_t i_pos;
51

52
    switch( mode )
53
    {
54
55
56
57
58
59
60
61
62
        case seek_beginning:
            i_pos = i_offset;
            break;
        case seek_end:
            i_pos = stream_Size( s ) - i_offset;
            break;
        default:
            i_pos= stream_Tell( s ) + i_offset;
            break;
63
64
    }

65
    if( i_pos < 0 || ( stream_Size( s ) != 0  && i_pos >= stream_Size( s ) ) )
66
    {
67
68
        mb_eof = true;
        return;
69
70
    }

71
72
    mb_eof = false;
    if( stream_Seek( s, i_pos ) )
73
    {
74
        mb_eof = true;
75
    }
76
77
    return;
}
78

79
uint64 vlc_stream_io_callback::getFilePointer( void )
80
{
81
82
83
84
    if ( s == NULL )
        return 0;
    return stream_Tell( s );
}
85