Coverage Report

Created: 2025-12-14 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/mkv/chapter_command_dvd.hpp
Line
Count
Source
1
// Copyright (C) 2003-2024 VLC authors and VideoLAN
2
// SPDX-License-Identifier: LGPL-2.1-or-later
3
//
4
// chapter_command_dvd.hpp : DVD codec for Matroska Chapter Codecs
5
// Authors: Laurent Aimar <fenrir@via.ecp.fr>
6
//          Steve Lhomme <steve.lhomme@free.fr>
7
8
9
#ifndef VLC_MKV_CHAPTER_COMMAND_DVD_HPP_
10
#define VLC_MKV_CHAPTER_COMMAND_DVD_HPP_
11
12
#include "chapter_command.hpp"
13
14
#include "dvd_types.hpp"
15
16
namespace mkv {
17
18
class dvd_command_interpretor_c
19
{
20
public:
21
    dvd_command_interpretor_c( struct vlc_logger *log, chapter_codec_vm & vm_ )
22
0
    :l( log )
23
0
    ,vm( vm_ )
24
0
    {
25
0
        memset( p_PRMs, 0, sizeof(p_PRMs) );
26
0
        p_PRMs[ 0x80 + 1 ] = 15;
27
0
        p_PRMs[ 0x80 + 2 ] = 62;
28
0
        p_PRMs[ 0x80 + 3 ] = 1;
29
0
        p_PRMs[ 0x80 + 4 ] = 1;
30
0
        p_PRMs[ 0x80 + 7 ] = 1;
31
0
        p_PRMs[ 0x80 + 8 ] = 1;
32
0
        p_PRMs[ 0x80 + 16 ] = 0xFFFFu;
33
0
        p_PRMs[ 0x80 + 18 ] = 0xFFFFu;
34
0
    }
35
36
    bool Interpret( const binary * p_command, size_t i_size = 8 );
37
38
    bool HandleKeyEvent( NavivationKey );
39
    void HandleMousePressed( unsigned x, unsigned y );
40
41
    void SetPci(const uint8_t *, unsigned size);
42
protected:
43
    uint16_t GetPRM( size_t index ) const
44
0
    {
45
0
        if ( index < 256 )
46
0
            return p_PRMs[ index ];
47
0
        else return 0;
48
0
    }
49
50
    uint16_t GetGPRM( size_t index ) const
51
0
    {
52
0
        if ( index < 16 )
53
0
            return p_PRMs[ index ];
54
0
        else return 0;
55
0
    }
56
57
    uint16_t GetSPRM( size_t index ) const
58
0
    {
59
        // 21,22,23 reserved for future use
60
0
        if ( index >= 0x80 && index < 0x95 )
61
0
            return p_PRMs[ index ];
62
0
        else return 0;
63
0
    }
64
65
    bool SetPRM( size_t index, uint16_t value )
66
0
    {
67
0
        if ( index < 16 )
68
0
        {
69
0
            p_PRMs[ index ] = value;
70
0
            return true;
71
0
        }
72
0
        return false;
73
0
    }
74
75
    bool SetGPRM( size_t index, uint16_t value )
76
0
    {
77
0
        if ( index < 16 )
78
0
        {
79
0
            p_PRMs[ index ] = value;
80
0
            return true;
81
0
        }
82
0
        return false;
83
0
    }
84
85
    bool SetSPRM( size_t index, uint16_t value )
86
0
    {
87
0
        if ( index > 0x80 && index <= 0x8D && index != 0x8C )
88
0
        {
89
0
            p_PRMs[ index ] = value;
90
0
            return true;
91
0
        }
92
0
        return false;
93
0
    }
94
95
    bool ProcessNavAction( uint16_t button );
96
97
    std::string GetRegTypeName( bool b_value, uint16_t value ) const
98
0
    {
99
0
        std::string result;
100
0
        char s_value[6], s_reg_value[6];
101
0
        snprintf( s_value, ARRAY_SIZE(s_value), "%.5d", value );
102
103
0
        if ( b_value )
104
0
        {
105
0
            result = "value (";
106
0
            result += s_value;
107
0
            result += ")";
108
0
        }
109
0
        else if ( value < 0x80 )
110
0
        {
111
0
            snprintf( s_reg_value, ARRAY_SIZE(s_reg_value), "%.5d", GetPRM( value ) );
112
0
            result = "GPreg[";
113
0
            result += s_value;
114
0
            result += "] (";
115
0
            result += s_reg_value;
116
0
            result += ")";
117
0
        }
118
0
        else
119
0
        {
120
0
            snprintf( s_reg_value, ARRAY_SIZE(s_reg_value), "%.5d", GetPRM( value ) );
121
0
            result = "SPreg[";
122
0
            result += s_value;
123
0
            result += "] (";
124
0
            result += s_reg_value;
125
0
            result += ")";
126
0
        }
127
0
        return result;
128
0
    }
129
130
    uint16_t       p_PRMs[256];
131
    struct vlc_logger *l;
132
    chapter_codec_vm & vm;
133
    pci_t          pci_packet = {};
134
135
    // DVD command IDs
136
137
    // Tests
138
    // whether it's a comparison on the value or register
139
    static const uint16_t CMD_DVD_TEST_VALUE          = 0x80;
140
    static const uint16_t CMD_DVD_IF_GPREG_AND        = (1 << 4);
141
    static const uint16_t CMD_DVD_IF_GPREG_EQUAL      = (2 << 4);
142
    static const uint16_t CMD_DVD_IF_GPREG_NOT_EQUAL  = (3 << 4);
143
    static const uint16_t CMD_DVD_IF_GPREG_SUP_EQUAL  = (4 << 4);
144
    static const uint16_t CMD_DVD_IF_GPREG_SUP        = (5 << 4);
145
    static const uint16_t CMD_DVD_IF_GPREG_INF_EQUAL  = (6 << 4);
146
    static const uint16_t CMD_DVD_IF_GPREG_INF        = (7 << 4);
147
148
    static const uint16_t CMD_DVD_NOP                    = 0x0000;
149
    static const uint16_t CMD_DVD_GOTO_LINE              = 0x0001;
150
    static const uint16_t CMD_DVD_BREAK                  = 0x0002;
151
    // Links
152
    static const uint16_t CMD_DVD_NOP2                   = 0x2001;
153
    static const uint16_t CMD_DVD_LINKPGCN               = 0x2004;
154
    static const uint16_t CMD_DVD_LINKPGN                = 0x2006;
155
    static const uint16_t CMD_DVD_LINKCN                 = 0x2007;
156
    static const uint16_t CMD_DVD_JUMP_TT                = 0x3002;
157
    static const uint16_t CMD_DVD_JUMPVTS_TT             = 0x3003;
158
    static const uint16_t CMD_DVD_JUMPVTS_PTT            = 0x3005;
159
    static const uint16_t CMD_DVD_JUMP_SS                = 0x3006;
160
    static const uint16_t CMD_DVD_CALLSS_VTSM1           = 0x3008;
161
    //
162
    static const uint16_t CMD_DVD_SET_HL_BTNN2           = 0x4600;
163
    static const uint16_t CMD_DVD_SET_HL_BTNN_LINKPGCN1  = 0x4604;
164
    static const uint16_t CMD_DVD_SET_STREAM             = 0x5100;
165
    static const uint16_t CMD_DVD_SET_GPRMMD             = 0x5300;
166
    static const uint16_t CMD_DVD_SET_HL_BTNN1           = 0x5600;
167
    static const uint16_t CMD_DVD_SET_HL_BTNN_LINKPGCN2  = 0x5604;
168
    static const uint16_t CMD_DVD_SET_HL_BTNN_LINKCN     = 0x5607;
169
    // Operations
170
    static const uint16_t CMD_DVD_MOV_SPREG_PREG         = 0x6100;
171
    static const uint16_t CMD_DVD_GPREG_MOV_VALUE        = 0x7100;
172
    static const uint16_t CMD_DVD_SUB_GPREG              = 0x7400;
173
    static const uint16_t CMD_DVD_MULT_GPREG             = 0x7500;
174
    static const uint16_t CMD_DVD_GPREG_DIV_VALUE        = 0x7600;
175
    static const uint16_t CMD_DVD_GPREG_AND_VALUE        = 0x7900;
176
177
    // callbacks when browsing inside CodecPrivate
178
    static bool MatchIsDomain     ( const chapter_codec_cmds_c & );
179
    static bool MatchIsVMG        ( const chapter_codec_cmds_c & );
180
    static bool MatchVTSNumber    ( const chapter_codec_cmds_c &, uint16_t i_title );
181
    static bool MatchVTSMNumber   ( const chapter_codec_cmds_c &, uint8_t i_title );
182
    static bool MatchTitleNumber  ( const chapter_codec_cmds_c &, uint8_t i_title );
183
    static bool MatchPgcType      ( const chapter_codec_cmds_c &, uint8_t i_pgc );
184
    static bool MatchPgcNumber    ( const chapter_codec_cmds_c &, uint16_t i_pgc_n );
185
    static bool MatchChapterNumber( const chapter_codec_cmds_c &, uint8_t i_ptt );
186
    static bool MatchCellNumber   ( const chapter_codec_cmds_c &, uint8_t i_cell_n );
187
};
188
189
class dvd_chapter_codec_c : public chapter_codec_cmds_c
190
{
191
public:
192
    dvd_chapter_codec_c( struct vlc_logger *log, chapter_codec_vm & vm_, dvd_command_interpretor_c & intepretor_ )
193
0
    :chapter_codec_cmds_c( log, vm_, MATROSKA_CHAPTER_CODEC_DVD )
194
0
    ,intepretor(intepretor_)
195
0
    {}
196
197
    bool Enter() override;
198
    bool Leave() override;
199
200
    std::string GetCodecName( bool f_for_title = false ) const override;
201
    int16_t GetTitleNumber() const override;
202
203
protected:
204
    bool EnterLeaveHelper( char const*, ChapterProcess & );
205
    dvd_command_interpretor_c & intepretor;
206
};
207
208
} // namespace
209
210
#endif // VLC_MKV_CHAPTER_COMMAND_DVD_HPP_