]> git.sesse.net Git - vlc/blob - modules/demux/mkv/chapter_command.hpp
Fix compilation
[vlc] / modules / demux / mkv / chapter_command.hpp
1 /*****************************************************************************
2  * mkv.cpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Steve Lhomme <steve.lhomme@free.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef _CHAPTER_COMMAND_H_
26 #define _CHAPTER_COMMAND_H_
27
28 #include "mkv.hpp"
29
30 const binary MATROSKA_DVD_LEVEL_SS   = 0x30;
31 const binary MATROSKA_DVD_LEVEL_LU   = 0x2A;
32 const binary MATROSKA_DVD_LEVEL_TT   = 0x28;
33 const binary MATROSKA_DVD_LEVEL_PGC  = 0x20;
34 const binary MATROSKA_DVD_LEVEL_PG   = 0x18;
35 const binary MATROSKA_DVD_LEVEL_PTT  = 0x10;
36 const binary MATROSKA_DVD_LEVEL_CN   = 0x08;
37
38 class demux_sys_t;
39
40 class chapter_codec_cmds_c
41 {
42 public:
43     chapter_codec_cmds_c( demux_sys_t & demuxer, int codec_id = -1)
44     :p_private_data(NULL)
45     ,i_codec_id( codec_id )
46     ,sys( demuxer )
47     {}
48  
49     virtual ~chapter_codec_cmds_c()
50     {
51         delete p_private_data;
52         std::vector<KaxChapterProcessData*>::iterator indexe = enter_cmds.begin();
53         while ( indexe != enter_cmds.end() )
54         {
55             delete (*indexe);
56             indexe++;
57         }
58         std::vector<KaxChapterProcessData*>::iterator indexl = leave_cmds.begin();
59         while ( indexl != leave_cmds.end() )
60         {
61             delete (*indexl);
62             indexl++;
63         }
64         std::vector<KaxChapterProcessData*>::iterator indexd = during_cmds.begin();
65         while ( indexd != during_cmds.end() )
66         {
67             delete (*indexd);
68             indexd++;
69         }
70     }
71
72     void SetPrivate( const KaxChapterProcessPrivate & private_data )
73     {
74         p_private_data = new KaxChapterProcessPrivate( private_data );
75     }
76
77     void AddCommand( const KaxChapterProcessCommand & command );
78  
79     /// \return wether the codec has seeked in the files or not
80     virtual bool Enter() { return false; }
81     virtual bool Leave() { return false; }
82     virtual std::string GetCodecName( bool f_for_title = false ) const { return ""; }
83     virtual int16 GetTitleNumber() { return -1; }
84
85     KaxChapterProcessPrivate *p_private_data;
86
87 protected:
88     std::vector<KaxChapterProcessData*> enter_cmds;
89     std::vector<KaxChapterProcessData*> during_cmds;
90     std::vector<KaxChapterProcessData*> leave_cmds;
91
92     int i_codec_id;
93     demux_sys_t & sys;
94 };
95
96
97 class dvd_command_interpretor_c
98 {
99 public:
100     dvd_command_interpretor_c( demux_sys_t & demuxer )
101     :sys( demuxer )
102     {
103         memset( p_PRMs, 0, sizeof(p_PRMs) );
104         p_PRMs[ 0x80 + 1 ] = 15;
105         p_PRMs[ 0x80 + 2 ] = 62;
106         p_PRMs[ 0x80 + 3 ] = 1;
107         p_PRMs[ 0x80 + 4 ] = 1;
108         p_PRMs[ 0x80 + 7 ] = 1;
109         p_PRMs[ 0x80 + 8 ] = 1;
110         p_PRMs[ 0x80 + 16 ] = 0xFFFFu;
111         p_PRMs[ 0x80 + 18 ] = 0xFFFFu;
112     }
113  
114     bool Interpret( const binary * p_command, size_t i_size = 8 );
115  
116     uint16 GetPRM( size_t index ) const
117     {
118         if ( index < 256 )
119             return p_PRMs[ index ];
120         else return 0;
121     }
122
123     uint16 GetGPRM( size_t index ) const
124     {
125         if ( index >= 0 && index < 16 )
126             return p_PRMs[ index ];
127         else return 0;
128     }
129
130     uint16 GetSPRM( size_t index ) const
131     {
132         // 21,22,23 reserved for future use
133         if ( index >= 0x80 && index < 0x95 )
134             return p_PRMs[ index ];
135         else return 0;
136     }
137
138     bool SetPRM( size_t index, uint16 value )
139     {
140         if ( index >= 0 && index < 16 )
141         {
142             p_PRMs[ index ] = value;
143             return true;
144         }
145         return false;
146     }
147  
148     bool SetGPRM( size_t index, uint16 value )
149     {
150         if ( index >= 0 && index < 16 )
151         {
152             p_PRMs[ index ] = value;
153             return true;
154         }
155         return false;
156     }
157
158     bool SetSPRM( size_t index, uint16 value )
159     {
160         if ( index > 0x80 && index <= 0x8D && index != 0x8C )
161         {
162             p_PRMs[ index ] = value;
163             return true;
164         }
165         return false;
166     }
167
168 protected:
169     std::string GetRegTypeName( bool b_value, uint16 value ) const
170     {
171         std::string result;
172         char s_value[6], s_reg_value[6];
173         sprintf( s_value, "%.5d", value );
174
175         if ( b_value )
176         {
177             result = "value (";
178             result += s_value;
179             result += ")";
180         }
181         else if ( value < 0x80 )
182         {
183             sprintf( s_reg_value, "%.5d", GetPRM( value ) );
184             result = "GPreg[";
185             result += s_value;
186             result += "] (";
187             result += s_reg_value;
188             result += ")";
189         }
190         else
191         {
192             sprintf( s_reg_value, "%.5d", GetPRM( value ) );
193             result = "SPreg[";
194             result += s_value;
195             result += "] (";
196             result += s_reg_value;
197             result += ")";
198         }
199         return result;
200     }
201
202     uint16       p_PRMs[256];
203     demux_sys_t  & sys;
204  
205     // DVD command IDs
206
207     // Tests
208     // wether it's a comparison on the value or register
209     static const uint16 CMD_DVD_TEST_VALUE          = 0x80;
210     static const uint16 CMD_DVD_IF_GPREG_AND        = (1 << 4);
211     static const uint16 CMD_DVD_IF_GPREG_EQUAL      = (2 << 4);
212     static const uint16 CMD_DVD_IF_GPREG_NOT_EQUAL  = (3 << 4);
213     static const uint16 CMD_DVD_IF_GPREG_SUP_EQUAL  = (4 << 4);
214     static const uint16 CMD_DVD_IF_GPREG_SUP        = (5 << 4);
215     static const uint16 CMD_DVD_IF_GPREG_INF_EQUAL  = (6 << 4);
216     static const uint16 CMD_DVD_IF_GPREG_INF        = (7 << 4);
217  
218     static const uint16 CMD_DVD_NOP                    = 0x0000;
219     static const uint16 CMD_DVD_GOTO_LINE              = 0x0001;
220     static const uint16 CMD_DVD_BREAK                  = 0x0002;
221     // Links
222     static const uint16 CMD_DVD_NOP2                   = 0x2001;
223     static const uint16 CMD_DVD_LINKPGCN               = 0x2004;
224     static const uint16 CMD_DVD_LINKPGN                = 0x2006;
225     static const uint16 CMD_DVD_LINKCN                 = 0x2007;
226     static const uint16 CMD_DVD_JUMP_TT                = 0x3002;
227     static const uint16 CMD_DVD_JUMPVTS_TT             = 0x3003;
228     static const uint16 CMD_DVD_JUMPVTS_PTT            = 0x3005;
229     static const uint16 CMD_DVD_JUMP_SS                = 0x3006;
230     static const uint16 CMD_DVD_CALLSS_VTSM1           = 0x3008;
231     //
232     static const uint16 CMD_DVD_SET_HL_BTNN2           = 0x4600;
233     static const uint16 CMD_DVD_SET_HL_BTNN_LINKPGCN1  = 0x4604;
234     static const uint16 CMD_DVD_SET_STREAM             = 0x5100;
235     static const uint16 CMD_DVD_SET_GPRMMD             = 0x5300;
236     static const uint16 CMD_DVD_SET_HL_BTNN1           = 0x5600;
237     static const uint16 CMD_DVD_SET_HL_BTNN_LINKPGCN2  = 0x5604;
238     static const uint16 CMD_DVD_SET_HL_BTNN_LINKCN     = 0x5607;
239     // Operations
240     static const uint16 CMD_DVD_MOV_SPREG_PREG         = 0x6100;
241     static const uint16 CMD_DVD_GPREG_MOV_VALUE        = 0x7100;
242     static const uint16 CMD_DVD_SUB_GPREG              = 0x7400;
243     static const uint16 CMD_DVD_MULT_GPREG             = 0x7500;
244     static const uint16 CMD_DVD_GPREG_DIV_VALUE        = 0x7600;
245     static const uint16 CMD_DVD_GPREG_AND_VALUE        = 0x7900;
246  
247     // callbacks when browsing inside CodecPrivate
248     static bool MatchIsDomain     ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
249     static bool MatchIsVMG        ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
250     static bool MatchVTSNumber    ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
251     static bool MatchVTSMNumber   ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
252     static bool MatchTitleNumber  ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
253     static bool MatchPgcType      ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
254     static bool MatchPgcNumber    ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
255     static bool MatchChapterNumber( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
256     static bool MatchCellNumber   ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
257 };
258
259
260 #include "demux.hpp"
261
262 class dvd_chapter_codec_c : public chapter_codec_cmds_c
263 {
264 public:
265     dvd_chapter_codec_c( demux_sys_t & sys )
266     :chapter_codec_cmds_c( sys, 1 )
267     {}
268
269     bool Enter();
270     bool Leave();
271     std::string GetCodecName( bool f_for_title = false ) const;
272     int16 GetTitleNumber();
273 };
274
275 class matroska_script_interpretor_c
276 {
277 public:
278     matroska_script_interpretor_c( demux_sys_t & demuxer )
279     :sys( demuxer )
280     {}
281
282     bool Interpret( const binary * p_command, size_t i_size );
283  
284     // DVD command IDs
285     static const std::string CMD_MS_GOTO_AND_PLAY;
286  
287 protected:
288     demux_sys_t  & sys;
289 };
290
291
292 class matroska_script_codec_c : public chapter_codec_cmds_c
293 {
294 public:
295     matroska_script_codec_c( demux_sys_t & sys )
296     :chapter_codec_cmds_c( sys, 0 )
297     ,interpretor( sys )
298     {}
299
300     bool Enter();
301     bool Leave();
302
303 protected:
304     matroska_script_interpretor_c interpretor;
305 };
306
307
308 #endif