Coverage Report

Created: 2026-01-17 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
7.49k
                       : s( s_), b_owner( b_owner_ )
33
7.49k
{
34
7.49k
    mb_eof = false;
35
7.49k
}
36
37
uint32 vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
38
22.8M
{
39
22.8M
    if( i_size <= 0 || mb_eof )
40
240k
        return 0;
41
42
22.6M
    int i_ret = vlc_stream_Read( s, p_buffer, i_size );
43
22.6M
    return i_ret < 0 || i_ret < i_size ? 0 : i_ret;
44
22.8M
}
45
46
void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
47
2.58M
{
48
2.58M
    int64_t i_pos, i_size;
49
2.58M
    int64_t i_current = vlc_stream_Tell( s );
50
51
2.58M
    switch( mode )
52
2.58M
    {
53
2.58M
        case seek_beginning:
54
2.58M
            i_pos = i_offset;
55
2.58M
            break;
56
0
        case seek_end:
57
0
            i_pos = stream_Size( s ) - i_offset;
58
0
            break;
59
17
        default:
60
17
            i_pos= i_current + i_offset;
61
17
            break;
62
2.58M
    }
63
64
2.58M
    if(i_pos == i_current)
65
2.23M
    {
66
2.23M
        if (mb_eof)
67
8.83k
        {
68
            // if previous setFilePointer() failed we may be back in the available data
69
8.83k
            i_size = stream_Size( s );
70
8.83k
            if ( i_size != 0 && i_pos < i_size )
71
8.78k
                mb_eof = vlc_stream_Seek( s, i_pos ) != VLC_SUCCESS;
72
8.83k
        }
73
2.23M
        return;
74
2.23M
    }
75
76
347k
    if( i_pos < 0 || ( ( i_size = stream_Size( s ) ) != 0 && i_pos >= i_size ) )
77
30.1k
    {
78
30.1k
        mb_eof = true;
79
30.1k
        return;
80
30.1k
    }
81
82
317k
    mb_eof = false;
83
317k
    if( vlc_stream_Seek( s, i_pos ) )
84
0
    {
85
0
        mb_eof = true;
86
0
    }
87
317k
    return;
88
347k
}
89
90
uint64_t vlc_stream_io_callback::getFilePointer( void )
91
2.43M
{
92
2.43M
    if ( s == NULL )
93
0
        return 0;
94
2.43M
    return vlc_stream_Tell( s );
95
2.43M
}
96
97
size_t vlc_stream_io_callback::write(const void *, size_t )
98
0
{
99
0
    return 0;
100
0
}
101
102
} // namespace