1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
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.
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.
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 *****************************************************************************/
25 #ifndef _CHAPTER_COMMAND_H_
26 #define _CHAPTER_COMMAND_H_
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;
40 class chapter_codec_cmds_c
43 chapter_codec_cmds_c( demux_sys_t & demuxer, int codec_id = -1)
45 ,i_codec_id( codec_id )
49 virtual ~chapter_codec_cmds_c()
51 delete p_private_data;
52 std::vector<KaxChapterProcessData*>::iterator indexe = enter_cmds.begin();
53 while ( indexe != enter_cmds.end() )
58 std::vector<KaxChapterProcessData*>::iterator indexl = leave_cmds.begin();
59 while ( indexl != leave_cmds.end() )
64 std::vector<KaxChapterProcessData*>::iterator indexd = during_cmds.begin();
65 while ( indexd != during_cmds.end() )
72 void SetPrivate( const KaxChapterProcessPrivate & private_data )
74 p_private_data = new KaxChapterProcessPrivate( private_data );
77 void AddCommand( const KaxChapterProcessCommand & command );
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 ) const { return ""; }
83 virtual int16 GetTitleNumber() { return -1; }
85 KaxChapterProcessPrivate *p_private_data;
88 std::vector<KaxChapterProcessData*> enter_cmds;
89 std::vector<KaxChapterProcessData*> during_cmds;
90 std::vector<KaxChapterProcessData*> leave_cmds;
97 class dvd_command_interpretor_c
100 dvd_command_interpretor_c( demux_sys_t & demuxer )
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;
114 bool Interpret( const binary * p_command, size_t i_size = 8 );
116 uint16 GetPRM( size_t index ) const
119 return p_PRMs[ index ];
123 uint16 GetGPRM( size_t index ) const
126 return p_PRMs[ index ];
130 uint16 GetSPRM( size_t index ) const
132 // 21,22,23 reserved for future use
133 if ( index >= 0x80 && index < 0x95 )
134 return p_PRMs[ index ];
138 bool SetPRM( size_t index, uint16 value )
142 p_PRMs[ index ] = value;
148 bool SetGPRM( size_t index, uint16 value )
152 p_PRMs[ index ] = value;
158 bool SetSPRM( size_t index, uint16 value )
160 if ( index > 0x80 && index <= 0x8D && index != 0x8C )
162 p_PRMs[ index ] = value;
169 std::string GetRegTypeName( bool b_value, uint16 value ) const
172 char s_value[6], s_reg_value[6];
173 sprintf( s_value, "%.5d", value );
181 else if ( value < 0x80 )
183 sprintf( s_reg_value, "%.5d", GetPRM( value ) );
187 result += s_reg_value;
192 sprintf( s_reg_value, "%.5d", GetPRM( value ) );
196 result += s_reg_value;
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);
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;
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;
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;
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;
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 );
262 class dvd_chapter_codec_c : public chapter_codec_cmds_c
265 dvd_chapter_codec_c( demux_sys_t & sys )
266 :chapter_codec_cmds_c( sys, 1 )
271 std::string GetCodecName( bool f_for_title = false ) const;
272 int16 GetTitleNumber();
275 class matroska_script_interpretor_c
278 matroska_script_interpretor_c( demux_sys_t & demuxer )
282 bool Interpret( const binary * p_command, size_t i_size );
285 static const std::string CMD_MS_GOTO_AND_PLAY;
292 class matroska_script_codec_c : public chapter_codec_cmds_c
295 matroska_script_codec_c( demux_sys_t & sys )
296 :chapter_codec_cmds_c( sys, 0 )
304 matroska_script_interpretor_c interpretor;