chapter_command.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * mkv.cpp : matroska demuxer
00003  *****************************************************************************
00004  * Copyright (C) 2003-2004 the VideoLAN team
00005  * $Id: 98316a2ab00955464c50e03a384e8bba572eafd4 $
00006  *
00007  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00008  *          Steve Lhomme <steve.lhomme@free.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef _CHAPTER_COMMAND_H_
00026 #define _CHAPTER_COMMAND_H_
00027 
00028 #include "mkv.hpp"
00029 
00030 const binary MATROSKA_DVD_LEVEL_SS   = 0x30;
00031 const binary MATROSKA_DVD_LEVEL_LU   = 0x2A;
00032 const binary MATROSKA_DVD_LEVEL_TT   = 0x28;
00033 const binary MATROSKA_DVD_LEVEL_PGC  = 0x20;
00034 const binary MATROSKA_DVD_LEVEL_PG   = 0x18;
00035 const binary MATROSKA_DVD_LEVEL_PTT  = 0x10;
00036 const binary MATROSKA_DVD_LEVEL_CN   = 0x08;
00037 
00038 class demux_sys_t;
00039 
00040 class chapter_codec_cmds_c
00041 {
00042 public:
00043     chapter_codec_cmds_c( demux_sys_t & demuxer, int codec_id = -1)
00044     :p_private_data(NULL)
00045     ,i_codec_id( codec_id )
00046     ,sys( demuxer )
00047     {}
00048  
00049     virtual ~chapter_codec_cmds_c()
00050     {
00051         delete p_private_data;
00052         std::vector<KaxChapterProcessData*>::iterator indexe = enter_cmds.begin();
00053         while ( indexe != enter_cmds.end() )
00054         {
00055             delete (*indexe);
00056             indexe++;
00057         }
00058         std::vector<KaxChapterProcessData*>::iterator indexl = leave_cmds.begin();
00059         while ( indexl != leave_cmds.end() )
00060         {
00061             delete (*indexl);
00062             indexl++;
00063         }
00064         std::vector<KaxChapterProcessData*>::iterator indexd = during_cmds.begin();
00065         while ( indexd != during_cmds.end() )
00066         {
00067             delete (*indexd);
00068             indexd++;
00069         }
00070     }
00071 
00072     void SetPrivate( const KaxChapterProcessPrivate & private_data )
00073     {
00074         p_private_data = new KaxChapterProcessPrivate( private_data );
00075     }
00076 
00077     void AddCommand( const KaxChapterProcessCommand & command );
00078  
00079     /// \return wether the codec has seeked in the files or not
00080     virtual bool Enter() { return false; }
00081     virtual bool Leave() { return false; }
00082     virtual std::string GetCodecName( bool f_for_title = false ) const { return ""; }
00083     virtual int16 GetTitleNumber() { return -1; }
00084 
00085     KaxChapterProcessPrivate *p_private_data;
00086 
00087 protected:
00088     std::vector<KaxChapterProcessData*> enter_cmds;
00089     std::vector<KaxChapterProcessData*> during_cmds;
00090     std::vector<KaxChapterProcessData*> leave_cmds;
00091 
00092     int i_codec_id;
00093     demux_sys_t & sys;
00094 };
00095 
00096 
00097 class dvd_command_interpretor_c
00098 {
00099 public:
00100     dvd_command_interpretor_c( demux_sys_t & demuxer )
00101     :sys( demuxer )
00102     {
00103         memset( p_PRMs, 0, sizeof(p_PRMs) );
00104         p_PRMs[ 0x80 + 1 ] = 15;
00105         p_PRMs[ 0x80 + 2 ] = 62;
00106         p_PRMs[ 0x80 + 3 ] = 1;
00107         p_PRMs[ 0x80 + 4 ] = 1;
00108         p_PRMs[ 0x80 + 7 ] = 1;
00109         p_PRMs[ 0x80 + 8 ] = 1;
00110         p_PRMs[ 0x80 + 16 ] = 0xFFFFu;
00111         p_PRMs[ 0x80 + 18 ] = 0xFFFFu;
00112     }
00113  
00114     bool Interpret( const binary * p_command, size_t i_size = 8 );
00115  
00116     uint16 GetPRM( size_t index ) const
00117     {
00118         if ( index < 256 )
00119             return p_PRMs[ index ];
00120         else return 0;
00121     }
00122 
00123     uint16 GetGPRM( size_t index ) const
00124     {
00125         if ( index < 16 )
00126             return p_PRMs[ index ];
00127         else return 0;
00128     }
00129 
00130     uint16 GetSPRM( size_t index ) const
00131     {
00132         // 21,22,23 reserved for future use
00133         if ( index >= 0x80 && index < 0x95 )
00134             return p_PRMs[ index ];
00135         else return 0;
00136     }
00137 
00138     bool SetPRM( size_t index, uint16 value )
00139     {
00140         if ( index < 16 )
00141         {
00142             p_PRMs[ index ] = value;
00143             return true;
00144         }
00145         return false;
00146     }
00147  
00148     bool SetGPRM( size_t index, uint16 value )
00149     {
00150         if ( index < 16 )
00151         {
00152             p_PRMs[ index ] = value;
00153             return true;
00154         }
00155         return false;
00156     }
00157 
00158     bool SetSPRM( size_t index, uint16 value )
00159     {
00160         if ( index > 0x80 && index <= 0x8D && index != 0x8C )
00161         {
00162             p_PRMs[ index ] = value;
00163             return true;
00164         }
00165         return false;
00166     }
00167 
00168 protected:
00169     std::string GetRegTypeName( bool b_value, uint16 value ) const
00170     {
00171         std::string result;
00172         char s_value[6], s_reg_value[6];
00173         sprintf( s_value, "%.5d", value );
00174 
00175         if ( b_value )
00176         {
00177             result = "value (";
00178             result += s_value;
00179             result += ")";
00180         }
00181         else if ( value < 0x80 )
00182         {
00183             sprintf( s_reg_value, "%.5d", GetPRM( value ) );
00184             result = "GPreg[";
00185             result += s_value;
00186             result += "] (";
00187             result += s_reg_value;
00188             result += ")";
00189         }
00190         else
00191         {
00192             sprintf( s_reg_value, "%.5d", GetPRM( value ) );
00193             result = "SPreg[";
00194             result += s_value;
00195             result += "] (";
00196             result += s_reg_value;
00197             result += ")";
00198         }
00199         return result;
00200     }
00201 
00202     uint16       p_PRMs[256];
00203     demux_sys_t  & sys;
00204  
00205     // DVD command IDs
00206 
00207     // Tests
00208     // wether it's a comparison on the value or register
00209     static const uint16 CMD_DVD_TEST_VALUE          = 0x80;
00210     static const uint16 CMD_DVD_IF_GPREG_AND        = (1 << 4);
00211     static const uint16 CMD_DVD_IF_GPREG_EQUAL      = (2 << 4);
00212     static const uint16 CMD_DVD_IF_GPREG_NOT_EQUAL  = (3 << 4);
00213     static const uint16 CMD_DVD_IF_GPREG_SUP_EQUAL  = (4 << 4);
00214     static const uint16 CMD_DVD_IF_GPREG_SUP        = (5 << 4);
00215     static const uint16 CMD_DVD_IF_GPREG_INF_EQUAL  = (6 << 4);
00216     static const uint16 CMD_DVD_IF_GPREG_INF        = (7 << 4);
00217  
00218     static const uint16 CMD_DVD_NOP                    = 0x0000;
00219     static const uint16 CMD_DVD_GOTO_LINE              = 0x0001;
00220     static const uint16 CMD_DVD_BREAK                  = 0x0002;
00221     // Links
00222     static const uint16 CMD_DVD_NOP2                   = 0x2001;
00223     static const uint16 CMD_DVD_LINKPGCN               = 0x2004;
00224     static const uint16 CMD_DVD_LINKPGN                = 0x2006;
00225     static const uint16 CMD_DVD_LINKCN                 = 0x2007;
00226     static const uint16 CMD_DVD_JUMP_TT                = 0x3002;
00227     static const uint16 CMD_DVD_JUMPVTS_TT             = 0x3003;
00228     static const uint16 CMD_DVD_JUMPVTS_PTT            = 0x3005;
00229     static const uint16 CMD_DVD_JUMP_SS                = 0x3006;
00230     static const uint16 CMD_DVD_CALLSS_VTSM1           = 0x3008;
00231     //
00232     static const uint16 CMD_DVD_SET_HL_BTNN2           = 0x4600;
00233     static const uint16 CMD_DVD_SET_HL_BTNN_LINKPGCN1  = 0x4604;
00234     static const uint16 CMD_DVD_SET_STREAM             = 0x5100;
00235     static const uint16 CMD_DVD_SET_GPRMMD             = 0x5300;
00236     static const uint16 CMD_DVD_SET_HL_BTNN1           = 0x5600;
00237     static const uint16 CMD_DVD_SET_HL_BTNN_LINKPGCN2  = 0x5604;
00238     static const uint16 CMD_DVD_SET_HL_BTNN_LINKCN     = 0x5607;
00239     // Operations
00240     static const uint16 CMD_DVD_MOV_SPREG_PREG         = 0x6100;
00241     static const uint16 CMD_DVD_GPREG_MOV_VALUE        = 0x7100;
00242     static const uint16 CMD_DVD_SUB_GPREG              = 0x7400;
00243     static const uint16 CMD_DVD_MULT_GPREG             = 0x7500;
00244     static const uint16 CMD_DVD_GPREG_DIV_VALUE        = 0x7600;
00245     static const uint16 CMD_DVD_GPREG_AND_VALUE        = 0x7900;
00246  
00247     // callbacks when browsing inside CodecPrivate
00248     static bool MatchIsDomain     ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00249     static bool MatchIsVMG        ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00250     static bool MatchVTSNumber    ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00251     static bool MatchVTSMNumber   ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00252     static bool MatchTitleNumber  ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00253     static bool MatchPgcType      ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00254     static bool MatchPgcNumber    ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00255     static bool MatchChapterNumber( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00256     static bool MatchCellNumber   ( const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size );
00257 };
00258 
00259 
00260 #include "demux.hpp"
00261 
00262 class dvd_chapter_codec_c : public chapter_codec_cmds_c
00263 {
00264 public:
00265     dvd_chapter_codec_c( demux_sys_t & sys )
00266     :chapter_codec_cmds_c( sys, 1 )
00267     {}
00268 
00269     bool Enter();
00270     bool Leave();
00271     std::string GetCodecName( bool f_for_title = false ) const;
00272     int16 GetTitleNumber();
00273 };
00274 
00275 class matroska_script_interpretor_c
00276 {
00277 public:
00278     matroska_script_interpretor_c( demux_sys_t & demuxer )
00279     :sys( demuxer )
00280     {}
00281 
00282     bool Interpret( const binary * p_command, size_t i_size );
00283  
00284     // DVD command IDs
00285     static const std::string CMD_MS_GOTO_AND_PLAY;
00286  
00287 protected:
00288     demux_sys_t  & sys;
00289 };
00290 
00291 
00292 class matroska_script_codec_c : public chapter_codec_cmds_c
00293 {
00294 public:
00295     matroska_script_codec_c( demux_sys_t & sys )
00296     :chapter_codec_cmds_c( sys, 0 )
00297     ,interpretor( sys )
00298     {}
00299 
00300     bool Enter();
00301     bool Leave();
00302 
00303 protected:
00304     matroska_script_interpretor_c interpretor;
00305 };
00306 
00307 
00308 #endif

Generated on Tue May 25 08:04:55 2010 for VLC by  doxygen 1.5.6