Coverage Report

Created: 2025-08-29 07:30

/src/vlc/modules/demux/mkv/matroska_segment_seeker.hpp
Line
Count
Source
1
/*****************************************************************************
2
 * matroska_segment.hpp : matroska demuxer
3
 *****************************************************************************
4
 * Copyright (C) 2016 VLC authors and VideoLAN
5
 *
6
 * Authors: Filip Roséen <filip@videolabs.io>
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
#ifndef MKV_MATROSKA_SEGMENT_SEEKER_HPP_
24
#define MKV_MATROSKA_SEGMENT_SEEKER_HPP_
25
26
#include "mkv.hpp"
27
28
#include <algorithm>
29
#include <vector>
30
#include <map>
31
#include <limits>
32
33
namespace mkv {
34
35
class matroska_segment_c;
36
37
class SegmentSeeker
38
{
39
    public:
40
        typedef uint64_t fptr_t;
41
        typedef mkv_track_t::track_id_t track_id_t;
42
43
        struct Range
44
        {
45
            Range (fptr_t start, fptr_t end)
46
98
                : start( start ), end( end )
47
98
            { }
48
49
            fptr_t start, end;
50
51
            bool operator<( Range const& rhs ) const
52
65
            {
53
65
                return start < rhs.start;
54
65
            }
55
        };
56
57
        struct Seekpoint
58
        {
59
            enum TrustLevel {
60
                TRUSTED = +3,
61
                QUESTIONABLE = +2,
62
                DISABLED = -1,
63
            };
64
65
            Seekpoint( fptr_t fpos, vlc_tick_t pts, TrustLevel trust_level = TRUSTED )
66
375
                : fpos( fpos ), pts( pts ), trust_level( trust_level )
67
375
            { }
68
69
            Seekpoint()
70
48
                : Seekpoint( std::numeric_limits<fptr_t>::max(), -1, DISABLED )
71
48
            { }
72
73
            bool operator<( Seekpoint const& rhs ) const
74
926
            {
75
926
                return pts < rhs.pts;
76
926
            }
77
78
            fptr_t fpos;
79
            vlc_tick_t pts;
80
            TrustLevel trust_level;
81
        };
82
83
        struct Cluster {
84
            fptr_t  fpos;
85
            vlc_tick_t pts;
86
            vlc_tick_t duration;
87
            fptr_t  size;
88
        };
89
90
    public:
91
        typedef std::vector<track_id_t> track_ids_t;
92
        typedef std::vector<Range> ranges_t;
93
        typedef std::vector<Seekpoint> seekpoints_t;
94
        typedef std::vector<fptr_t> cluster_positions_t;
95
96
        typedef std::map<track_id_t, Seekpoint> tracks_seekpoint_t;
97
        typedef std::map<track_id_t, seekpoints_t> tracks_seekpoints_t;
98
        typedef std::map<vlc_tick_t, Cluster> cluster_map_t;
99
100
        typedef std::pair<Seekpoint, Seekpoint> seekpoint_pair_t;
101
102
        void add_seekpoint( track_id_t, Seekpoint );
103
104
        seekpoint_pair_t get_seekpoints_around( vlc_tick_t, seekpoints_t const& );
105
        Seekpoint get_first_seekpoint_around( vlc_tick_t, seekpoints_t const&, Seekpoint::TrustLevel = Seekpoint::TRUSTED );
106
        seekpoint_pair_t get_seekpoints_around( vlc_tick_t, track_ids_t const& );
107
108
        tracks_seekpoint_t get_seekpoints( matroska_segment_c&, vlc_tick_t, track_ids_t const&, track_ids_t const& );
109
        tracks_seekpoint_t find_greatest_seekpoints_in_range( fptr_t , vlc_tick_t, track_ids_t const& filter_tracks );
110
111
        cluster_positions_t::iterator add_cluster_position( fptr_t pos );
112
        cluster_map_t      ::iterator add_cluster( KaxCluster * const );
113
114
        void mkv_jump_to( matroska_segment_c&, fptr_t );
115
116
        void index_range( matroska_segment_c& matroska_segment, Range search_area, vlc_tick_t max_pts );
117
        void index_unsearched_range( matroska_segment_c& matroska_segment, Range search_area, vlc_tick_t max_pts );
118
119
        void mark_range_as_searched( Range );
120
        ranges_t get_search_areas( fptr_t start, fptr_t end ) const;
121
122
    public:
123
        ranges_t            _ranges_searched;
124
        tracks_seekpoints_t _tracks_seekpoints;
125
        cluster_positions_t _cluster_positions;
126
        cluster_map_t       _clusters;
127
};
128
129
} // namespace
130
131
#endif /* include-guard */