1 /*****************************************************************************
2 * chapter_command.hpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
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 it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * 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 vlc_delete_all( enter_cmds );
53 vlc_delete_all( leave_cmds );
54 vlc_delete_all( during_cmds );
57 void SetPrivate( const KaxChapterProcessPrivate & private_data )
59 p_private_data = new KaxChapterProcessPrivate( private_data );
62 void AddCommand( const KaxChapterProcessCommand & command );
64 /// \return whether the codec has seeked in the files or not
65 virtual bool Enter() { return false; }
66 virtual bool Leave() { return false; }
67 virtual std::string GetCodecName( bool ) const { return ""; }
68 virtual int16 GetTitleNumber() { return -1; }
70 KaxChapterProcessPrivate *p_private_data;
73 std::vector<KaxChapterProcessData*> enter_cmds;
74 std::vector<KaxChapterProcessData*> during_cmds;
75 std::vector<KaxChapterProcessData*> leave_cmds;
82 class dvd_command_interpretor_c
85 dvd_command_interpretor_c( demux_sys_t & demuxer )
88 memset( p_PRMs, 0, sizeof(p_PRMs) );
89 p_PRMs[ 0x80 + 1 ] = 15;
90 p_PRMs[ 0x80 + 2 ] = 62;
91 p_PRMs[ 0x80 + 3 ] = 1;
92 p_PRMs[ 0x80 + 4 ] = 1;
93 p_PRMs[ 0x80 + 7 ] = 1;
94 p_PRMs[ 0x80 + 8 ] = 1;
95 p_PRMs[ 0x80 + 16 ] = 0xFFFFu;
96 p_PRMs[ 0x80 + 18 ] = 0xFFFFu;
99 bool Interpret( const binary * p_command, size_t i_size = 8 );
101 uint16 GetPRM( size_t index ) const
104 return p_PRMs[ index ];
108 uint16 GetGPRM( size_t index ) const
111 return p_PRMs[ index ];
115 uint16 GetSPRM( size_t index ) const
117 // 21,22,23 reserved for future use
118 if ( index >= 0x80 && index < 0x95 )
119 return p_PRMs[ index ];
123 bool SetPRM( size_t index, uint16 value )
127 p_PRMs[ index ] = value;
133 bool SetGPRM( size_t index, uint16 value )
137 p_PRMs[ index ] = value;
143 bool SetSPRM( size_t index, uint16 value )
145 if ( index > 0x80 && index <= 0x8D && index != 0x8C )
147 p_PRMs[ index ] = value;
154 std::string GetRegTypeName( bool b_value, uint16 value ) const
157 char s_value[6], s_reg_value[6];
158 sprintf( s_value, "%.5d", value );
166 else if ( value < 0x80 )
168 sprintf( s_reg_value, "%.5d", GetPRM( value ) );
172 result += s_reg_value;
177 sprintf( s_reg_value, "%.5d", GetPRM( value ) );
181 result += s_reg_value;
193 // whether it's a comparison on the value or register
194 static const uint16 CMD_DVD_TEST_VALUE = 0x80;
195 static const uint16 CMD_DVD_IF_GPREG_AND = (1 << 4);
196 static const uint16 CMD_DVD_IF_GPREG_EQUAL = (2 << 4);
197 static const uint16 CMD_DVD_IF_GPREG_NOT_EQUAL = (3 << 4);
198 static const uint16 CMD_DVD_IF_GPREG_SUP_EQUAL = (4 << 4);
199 static const uint16 CMD_DVD_IF_GPREG_SUP = (5 << 4);
200 static const uint16 CMD_DVD_IF_GPREG_INF_EQUAL = (6 << 4);
201 static const uint16 CMD_DVD_IF_GPREG_INF = (7 << 4);
203 static const uint16 CMD_DVD_NOP = 0x0000;
204 static const uint16 CMD_DVD_GOTO_LINE = 0x0001;
205 static const uint16 CMD_DVD_BREAK = 0x0002;
207 static const uint16 CMD_DVD_NOP2 = 0x2001;
208 static const uint16 CMD_DVD_LINKPGCN = 0x2004;
209 static const uint16 CMD_DVD_LINKPGN = 0x2006;
210 static const uint16 CMD_DVD_LINKCN = 0x2007;
211 static const uint16 CMD_DVD_JUMP_TT = 0x3002;
212 static const uint16 CMD_DVD_JUMPVTS_TT = 0x3003;
213 static const uint16 CMD_DVD_JUMPVTS_PTT = 0x3005;
214 static const uint16 CMD_DVD_JUMP_SS = 0x3006;
215 static const uint16 CMD_DVD_CALLSS_VTSM1 = 0x3008;
217 static const uint16 CMD_DVD_SET_HL_BTNN2 = 0x4600;
218 static const uint16 CMD_DVD_SET_HL_BTNN_LINKPGCN1 = 0x4604;
219 static const uint16 CMD_DVD_SET_STREAM = 0x5100;
220 static const uint16 CMD_DVD_SET_GPRMMD = 0x5300;
221 static const uint16 CMD_DVD_SET_HL_BTNN1 = 0x5600;
222 static const uint16 CMD_DVD_SET_HL_BTNN_LINKPGCN2 = 0x5604;
223 static const uint16 CMD_DVD_SET_HL_BTNN_LINKCN = 0x5607;
225 static const uint16 CMD_DVD_MOV_SPREG_PREG = 0x6100;
226 static const uint16 CMD_DVD_GPREG_MOV_VALUE = 0x7100;
227 static const uint16 CMD_DVD_SUB_GPREG = 0x7400;
228 static const uint16 CMD_DVD_MULT_GPREG = 0x7500;
229 static const uint16 CMD_DVD_GPREG_DIV_VALUE = 0x7600;
230 static const uint16 CMD_DVD_GPREG_AND_VALUE = 0x7900;
232 // callbacks when browsing inside CodecPrivate
233 static bool MatchIsDomain ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
234 static bool MatchIsVMG ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
235 static bool MatchVTSNumber ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
236 static bool MatchVTSMNumber ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
237 static bool MatchTitleNumber ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
238 static bool MatchPgcType ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
239 static bool MatchPgcNumber ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
240 static bool MatchChapterNumber( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
241 static bool MatchCellNumber ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
247 class dvd_chapter_codec_c : public chapter_codec_cmds_c
250 dvd_chapter_codec_c( demux_sys_t & sys )
251 :chapter_codec_cmds_c( sys, 1 )
256 std::string GetCodecName( bool f_for_title = false ) const;
257 int16 GetTitleNumber();
260 class matroska_script_interpretor_c
263 matroska_script_interpretor_c( demux_sys_t & demuxer )
267 bool Interpret( const binary * p_command, size_t i_size );
270 static const std::string CMD_MS_GOTO_AND_PLAY;
277 class matroska_script_codec_c : public chapter_codec_cmds_c
280 matroska_script_codec_c( demux_sys_t & sys )
281 :chapter_codec_cmds_c( sys, 0 )
289 matroska_script_interpretor_c interpretor;