Coverage Report

Created: 2026-05-16 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/mkv/demux.hpp
Line
Count
Source
1
/*****************************************************************************
2
 * demux.hpp : matroska demuxer
3
 *****************************************************************************
4
 * Copyright (C) 2003-2004 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
#ifndef VLC_MKV_DEMUX_HPP_
25
#define VLC_MKV_DEMUX_HPP_
26
27
#include "mkv.hpp"
28
29
#include "chapter_command.hpp"
30
#include "chapter_command_dvd.hpp"
31
#include "chapter_command_script.hpp"
32
#include "events.hpp"
33
34
#include <memory>
35
36
#include <vlc_threads.h>
37
38
namespace mkv {
39
40
class virtual_segment_c;
41
class chapter_item_c;
42
43
struct demux_sys_t : public chapter_codec_vm
44
{
45
public:
46
    demux_sys_t( demux_t & demux, bool trust_cues )
47
622
        :demuxer(demux)
48
622
        ,b_seekable(false)
49
622
        ,b_fastseekable(false)
50
622
        ,i_pts(VLC_TICK_INVALID)
51
622
        ,i_pcr(VLC_TICK_INVALID)
52
622
        ,i_start_pts(VLC_TICK_0)
53
622
        ,i_mk_chapter_time(0)
54
622
        ,meta(NULL)
55
622
        ,i_current_title(0)
56
622
        ,i_current_seekpoint(0)
57
622
        ,i_updates(0)
58
622
        ,i_duration(-1)
59
622
        ,trust_cues(trust_cues)
60
622
        ,ev(&demux)
61
622
    {
62
622
        vlc_mutex_init( &lock_demuxer );
63
622
    }
64
65
    virtual ~demux_sys_t();
66
67
    /* current data */
68
    demux_t                 & demuxer;
69
    bool                    b_seekable;
70
    bool                    b_fastseekable;
71
72
    vlc_tick_t              i_pts;
73
    vlc_tick_t              i_pcr;
74
    vlc_tick_t              i_start_pts;
75
    vlc_tick_t              i_mk_chapter_time;
76
77
    vlc_meta_t              *meta;
78
79
    std::vector<input_title_t*>      titles; // matroska editions
80
    size_t                           i_current_title;
81
    size_t                           i_current_seekpoint;
82
    unsigned                         i_updates;
83
84
    std::vector<matroska_stream_c*>  streams;
85
    std::vector<std::unique_ptr<input_attachment_t,
86
                    void(*)(input_attachment_t*)>> stored_attachments;
87
    std::vector<matroska_segment_c*> opened_segments;
88
    std::vector<virtual_segment_c*>  used_vsegments;
89
90
    /* duration of the stream */
91
    vlc_tick_t              i_duration;
92
93
    const bool              trust_cues;
94
95
    bool SegmentIsOpened( const EbmlBinary & uid ) const;
96
97
    // chapter_codec_vm
98
    virtual_chapter_c *BrowseCodecPrivate( chapter_codec_id codec_id,
99
                                           chapter_cmd_match match,
100
                                           virtual_segment_c * & p_vsegment_found ) override;
101
    void JumpTo( virtual_segment_c & vsegment, virtual_chapter_c & vchapter ) override;
102
    virtual_segment_c *GetCurrentVSegment() override
103
306k
    {
104
306k
        return p_current_vsegment;
105
306k
    }
106
    virtual_chapter_c *FindVChapter( chapter_uid i_find_uid, virtual_segment_c * & p_vsegment_found ) override;
107
    void SetHighlight( vlc_spu_highlight_t & ) override;
108
109
    void PreloadFamily( const matroska_segment_c & of_segment );
110
    bool PreloadLinked();
111
    bool FreeUnused();
112
    bool PreparePlayback( virtual_segment_c & new_vsegment );
113
    bool AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c * );
114
115
    dvd_command_interpretor_c * GetDVDInterpretor()
116
0
    {
117
0
        if (!dvd_interpretor)
118
0
        {
119
0
            try {
120
0
                dvd_interpretor = std::make_unique<dvd_command_interpretor_c>( vlc_object_logger( &demuxer ), *this );
121
0
            } catch ( const std::bad_alloc & ) {
122
0
            }
123
0
        }
124
0
        return dvd_interpretor.get();
125
0
    }
126
127
    matroska_script_interpretor_c * GetMatroskaScriptInterpreter()
128
7
    {
129
7
        if (!ms_interpreter)
130
7
        {
131
7
            try {
132
7
                ms_interpreter = std::make_unique<matroska_script_interpretor_c> ( vlc_object_logger( &demuxer ), *this );
133
7
            } catch ( const std::bad_alloc & ) {
134
0
            }
135
7
        }
136
137
7
        return ms_interpreter.get();
138
7
    }
139
140
    uint8_t        palette[4][4];
141
    vlc_mutex_t    lock_demuxer;
142
143
    /* event */
144
    event_thread_t ev;
145
146
private:
147
    virtual_segment_c                *p_current_vsegment = nullptr;
148
    std::unique_ptr<dvd_command_interpretor_c> dvd_interpretor; // protected by lock_demuxer
149
    std::unique_ptr<matroska_script_interpretor_c> ms_interpreter;
150
};
151
152
} // namespace
153
154
#endif