/src/vlc/modules/demux/mkv/stream_io_callback.cpp
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * stream_io_callback.cpp : matroska demuxer |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2003-2004, 2010 VLC authors and VideoLAN |
5 | | * |
6 | | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
7 | | * Steve Lhomme <steve.lhomme@free.fr> |
8 | | * |
9 | | * This program is free software; you can redistribute it and/or modify it |
10 | | * under the terms of the GNU Lesser General Public License as published by |
11 | | * the Free Software Foundation; either version 2.1 of the License, or |
12 | | * (at your option) any later version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with this program; if not, write to the Free Software Foundation, |
21 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
22 | | *****************************************************************************/ |
23 | | |
24 | | #include "stream_io_callback.hpp" |
25 | | |
26 | | namespace mkv { |
27 | | |
28 | | /***************************************************************************** |
29 | | * Stream management |
30 | | *****************************************************************************/ |
31 | | vlc_stream_io_callback::vlc_stream_io_callback( stream_t *s_, bool b_owner_ ) |
32 | 3.99k | : s( s_), b_owner( b_owner_ ) |
33 | 3.99k | { |
34 | 3.99k | mb_eof = false; |
35 | 3.99k | } |
36 | | |
37 | | uint32 vlc_stream_io_callback::read( void *p_buffer, size_t i_size ) |
38 | 11.1M | { |
39 | 11.1M | if( i_size <= 0 || mb_eof ) |
40 | 14.4k | return 0; |
41 | | |
42 | 11.1M | int i_ret = vlc_stream_Read( s, p_buffer, i_size ); |
43 | 11.1M | return i_ret < 0 || i_ret < i_size ? 0 : i_ret; |
44 | 11.1M | } |
45 | | |
46 | | void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode ) |
47 | 1.69M | { |
48 | 1.69M | int64_t i_pos, i_size; |
49 | 1.69M | int64_t i_current = vlc_stream_Tell( s ); |
50 | | |
51 | 1.69M | switch( mode ) |
52 | 1.69M | { |
53 | 1.69M | case seek_beginning: |
54 | 1.69M | i_pos = i_offset; |
55 | 1.69M | break; |
56 | 0 | case seek_end: |
57 | 0 | i_pos = stream_Size( s ) - i_offset; |
58 | 0 | break; |
59 | 6 | default: |
60 | 6 | i_pos= i_current + i_offset; |
61 | 6 | break; |
62 | 1.69M | } |
63 | | |
64 | 1.69M | if(i_pos == i_current) |
65 | 1.20M | { |
66 | 1.20M | if (mb_eof) |
67 | 11.9k | { |
68 | | // if previous setFilePointer() failed we may be back in the available data |
69 | 11.9k | i_size = stream_Size( s ); |
70 | 11.9k | if ( i_size != 0 && i_pos < i_size ) |
71 | 11.9k | mb_eof = vlc_stream_Seek( s, i_pos ) != VLC_SUCCESS; |
72 | 11.9k | } |
73 | 1.20M | return; |
74 | 1.20M | } |
75 | | |
76 | 490k | if( i_pos < 0 || ( ( i_size = stream_Size( s ) ) != 0 && i_pos >= i_size ) ) |
77 | 25.9k | { |
78 | 25.9k | mb_eof = true; |
79 | 25.9k | return; |
80 | 25.9k | } |
81 | | |
82 | 464k | mb_eof = false; |
83 | 464k | if( vlc_stream_Seek( s, i_pos ) ) |
84 | 0 | { |
85 | 0 | mb_eof = true; |
86 | 0 | } |
87 | 464k | return; |
88 | 490k | } |
89 | | |
90 | | uint64_t vlc_stream_io_callback::getFilePointer( void ) |
91 | 993k | { |
92 | 993k | if ( s == NULL ) |
93 | 0 | return 0; |
94 | 993k | return vlc_stream_Tell( s ); |
95 | 993k | } |
96 | | |
97 | | size_t vlc_stream_io_callback::write(const void *, size_t ) |
98 | 0 | { |
99 | 0 | return 0; |
100 | 0 | } |
101 | | |
102 | | } // namespace |