]> git.sesse.net Git - vlc/blob - modules/demux/mkv/chapter_command.hpp
Initialize codecs after track parsing and not before the selection.
[vlc] / modules / demux / mkv / chapter_command.hpp
1 /*****************************************************************************
2  * chapter_command.hpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2004 VLC authors and VideoLAN
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 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.
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 Lesser General Public License for more details.
19  *
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  *****************************************************************************/
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         vlc_delete_all( enter_cmds );
53         vlc_delete_all( leave_cmds );
54         vlc_delete_all( during_cmds );
55     }
56
57     void SetPrivate( const KaxChapterProcessPrivate & private_data )
58     {
59         p_private_data = new KaxChapterProcessPrivate( private_data );
60     }
61
62     void AddCommand( const KaxChapterProcessCommand & command );
63
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; }
69
70     KaxChapterProcessPrivate *p_private_data;
71
72 protected:
73     std::vector<KaxChapterProcessData*> enter_cmds;
74     std::vector<KaxChapterProcessData*> during_cmds;
75     std::vector<KaxChapterProcessData*> leave_cmds;
76
77     int i_codec_id;
78     demux_sys_t & sys;
79 };
80
81
82 class dvd_command_interpretor_c
83 {
84 public:
85     dvd_command_interpretor_c( demux_sys_t & demuxer )
86     :sys( demuxer )
87     {
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;
97     }
98
99     bool Interpret( const binary * p_command, size_t i_size = 8 );
100
101     uint16 GetPRM( size_t index ) const
102     {
103         if ( index < 256 )
104             return p_PRMs[ index ];
105         else return 0;
106     }
107
108     uint16 GetGPRM( size_t index ) const
109     {
110         if ( index < 16 )
111             return p_PRMs[ index ];
112         else return 0;
113     }
114
115     uint16 GetSPRM( size_t index ) const
116     {
117         // 21,22,23 reserved for future use
118         if ( index >= 0x80 && index < 0x95 )
119             return p_PRMs[ index ];
120         else return 0;
121     }
122
123     bool SetPRM( size_t index, uint16 value )
124     {
125         if ( index < 16 )
126         {
127             p_PRMs[ index ] = value;
128             return true;
129         }
130         return false;
131     }
132
133     bool SetGPRM( size_t index, uint16 value )
134     {
135         if ( index < 16 )
136         {
137             p_PRMs[ index ] = value;
138             return true;
139         }
140         return false;
141     }
142
143     bool SetSPRM( size_t index, uint16 value )
144     {
145         if ( index > 0x80 && index <= 0x8D && index != 0x8C )
146         {
147             p_PRMs[ index ] = value;
148             return true;
149         }
150         return false;
151     }
152
153 protected:
154     std::string GetRegTypeName( bool b_value, uint16 value ) const
155     {
156         std::string result;
157         char s_value[6], s_reg_value[6];
158         sprintf( s_value, "%.5d", value );
159
160         if ( b_value )
161         {
162             result = "value (";
163             result += s_value;
164             result += ")";
165         }
166         else if ( value < 0x80 )
167         {
168             sprintf( s_reg_value, "%.5d", GetPRM( value ) );
169             result = "GPreg[";
170             result += s_value;
171             result += "] (";
172             result += s_reg_value;
173             result += ")";
174         }
175         else
176         {
177             sprintf( s_reg_value, "%.5d", GetPRM( value ) );
178             result = "SPreg[";
179             result += s_value;
180             result += "] (";
181             result += s_reg_value;
182             result += ")";
183         }
184         return result;
185     }
186
187     uint16       p_PRMs[256];
188     demux_sys_t  & sys;
189
190     // DVD command IDs
191
192     // Tests
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);
202
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;
206     // Links
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;
216     //
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;
224     // Operations
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;
231
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 );
242 };
243
244
245 #include "demux.hpp"
246
247 class dvd_chapter_codec_c : public chapter_codec_cmds_c
248 {
249 public:
250     dvd_chapter_codec_c( demux_sys_t & sys )
251     :chapter_codec_cmds_c( sys, 1 )
252     {}
253
254     bool Enter();
255     bool Leave();
256     std::string GetCodecName( bool f_for_title = false ) const;
257     int16 GetTitleNumber();
258 };
259
260 class matroska_script_interpretor_c
261 {
262 public:
263     matroska_script_interpretor_c( demux_sys_t & demuxer )
264     :sys( demuxer )
265     {}
266
267     bool Interpret( const binary * p_command, size_t i_size );
268
269     // DVD command IDs
270     static const std::string CMD_MS_GOTO_AND_PLAY;
271
272 protected:
273     demux_sys_t  & sys;
274 };
275
276
277 class matroska_script_codec_c : public chapter_codec_cmds_c
278 {
279 public:
280     matroska_script_codec_c( demux_sys_t & sys )
281     :chapter_codec_cmds_c( sys, 0 )
282     ,interpretor( sys )
283     {}
284
285     bool Enter();
286     bool Leave();
287
288 protected:
289     matroska_script_interpretor_c interpretor;
290 };
291
292
293 #endif