demux.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$
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 _DEMUX_SYS_H
00026 #define _DEMUX_SYS_H
00027 
00028 #include "mkv.hpp"
00029 
00030 #include "chapter_command.hpp"
00031 #include "virtual_segment.hpp"
00032 
00033 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00034 #undef ATTRIBUTE_PACKED
00035 #undef PRAGMA_PACK_BEGIN
00036 #undef PRAGMA_PACK_END
00037 
00038 #if defined(__GNUC__)
00039 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
00040 #define ATTRIBUTE_PACKED __attribute__ ((packed))
00041 #define PRAGMA_PACK 0
00042 #endif
00043 #endif
00044 
00045 #if !defined(ATTRIBUTE_PACKED)
00046 #define ATTRIBUTE_PACKED
00047 #define PRAGMA_PACK 1
00048 #endif
00049 
00050 #if PRAGMA_PACK
00051 #pragma pack(1)
00052 #endif
00053 
00054 /*************************************
00055 *  taken from libdvdnav / libdvdread
00056 **************************************/
00057 
00058 /**
00059  * DVD Time Information.
00060  */
00061 typedef struct {
00062   uint8_t hour;
00063   uint8_t minute;
00064   uint8_t second;
00065   uint8_t frame_u; /* The two high bits are the frame rate. */
00066 } ATTRIBUTE_PACKED dvd_time_t;
00067 
00068 /**
00069  * User Operations.
00070  */
00071 typedef struct {
00072 #ifdef WORDS_BIGENDIAN
00073   unsigned char zero                           : 7; /* 25-31 */
00074   unsigned char video_pres_mode_change         : 1; /* 24 */
00075  
00076   unsigned char karaoke_audio_pres_mode_change : 1; /* 23 */
00077   unsigned char angle_change                   : 1;
00078   unsigned char subpic_stream_change           : 1;
00079   unsigned char audio_stream_change            : 1;
00080   unsigned char pause_on                       : 1;
00081   unsigned char still_off                      : 1;
00082   unsigned char button_select_or_activate      : 1;
00083   unsigned char resume                         : 1; /* 16 */
00084  
00085   unsigned char chapter_menu_call              : 1; /* 15 */
00086   unsigned char angle_menu_call                : 1;
00087   unsigned char audio_menu_call                : 1;
00088   unsigned char subpic_menu_call               : 1;
00089   unsigned char root_menu_call                 : 1;
00090   unsigned char title_menu_call                : 1;
00091   unsigned char backward_scan                  : 1;
00092   unsigned char forward_scan                   : 1; /* 8 */
00093  
00094   unsigned char next_pg_search                 : 1; /* 7 */
00095   unsigned char prev_or_top_pg_search          : 1;
00096   unsigned char time_or_chapter_search         : 1;
00097   unsigned char go_up                          : 1;
00098   unsigned char stop                           : 1;
00099   unsigned char title_play                     : 1;
00100   unsigned char chapter_search_or_play         : 1;
00101   unsigned char title_or_time_play             : 1; /* 0 */
00102 #else
00103   unsigned char video_pres_mode_change         : 1; /* 24 */
00104   unsigned char zero                           : 7; /* 25-31 */
00105  
00106   unsigned char resume                         : 1; /* 16 */
00107   unsigned char button_select_or_activate      : 1;
00108   unsigned char still_off                      : 1;
00109   unsigned char pause_on                       : 1;
00110   unsigned char audio_stream_change            : 1;
00111   unsigned char subpic_stream_change           : 1;
00112   unsigned char angle_change                   : 1;
00113   unsigned char karaoke_audio_pres_mode_change : 1; /* 23 */
00114  
00115   unsigned char forward_scan                   : 1; /* 8 */
00116   unsigned char backward_scan                  : 1;
00117   unsigned char title_menu_call                : 1;
00118   unsigned char root_menu_call                 : 1;
00119   unsigned char subpic_menu_call               : 1;
00120   unsigned char audio_menu_call                : 1;
00121   unsigned char angle_menu_call                : 1;
00122   unsigned char chapter_menu_call              : 1; /* 15 */
00123  
00124   unsigned char title_or_time_play             : 1; /* 0 */
00125   unsigned char chapter_search_or_play         : 1;
00126   unsigned char title_play                     : 1;
00127   unsigned char stop                           : 1;
00128   unsigned char go_up                          : 1;
00129   unsigned char time_or_chapter_search         : 1;
00130   unsigned char prev_or_top_pg_search          : 1;
00131   unsigned char next_pg_search                 : 1; /* 7 */
00132 #endif
00133 } ATTRIBUTE_PACKED user_ops_t;
00134 
00135 /**
00136  * Type to store per-command data.
00137  */
00138 typedef struct {
00139   uint8_t bytes[8];
00140 } ATTRIBUTE_PACKED vm_cmd_t;
00141 #define COMMAND_DATA_SIZE 8
00142 
00143 /**
00144  * PCI General Information
00145  */
00146 typedef struct {
00147   uint32_t nv_pck_lbn;      /**< sector address of this nav pack */
00148   uint16_t vobu_cat;        /**< 'category' of vobu */
00149   uint16_t zero1;           /**< reserved */
00150   user_ops_t vobu_uop_ctl;  /**< UOP of vobu */
00151   uint32_t vobu_s_ptm;      /**< start presentation time of vobu */
00152   uint32_t vobu_e_ptm;      /**< end presentation time of vobu */
00153   uint32_t vobu_se_e_ptm;   /**< end ptm of sequence end in vobu */
00154   dvd_time_t e_eltm;        /**< Cell elapsed time */
00155   char vobu_isrc[32];
00156 } ATTRIBUTE_PACKED pci_gi_t;
00157 
00158 /**
00159  * Non Seamless Angle Information
00160  */
00161 typedef struct {
00162   uint32_t nsml_agl_dsta[9];  /**< address of destination vobu in AGL_C#n */
00163 } ATTRIBUTE_PACKED nsml_agli_t;
00164 
00165 /**
00166  * Highlight General Information
00167  *
00168  * For btngrX_dsp_ty the bits have the following meaning:
00169  * 000b: normal 4/3 only buttons
00170  * XX1b: wide (16/9) buttons
00171  * X1Xb: letterbox buttons
00172  * 1XXb: pan&scan buttons
00173  */
00174 typedef struct {
00175   uint16_t hli_ss; /**< status, only low 2 bits 0: no buttons, 1: different 2: equal 3: eual except for button cmds */
00176   uint32_t hli_s_ptm;              /**< start ptm of hli */
00177   uint32_t hli_e_ptm;              /**< end ptm of hli */
00178   uint32_t btn_se_e_ptm;           /**< end ptm of button select */
00179 #ifdef WORDS_BIGENDIAN
00180   unsigned char zero1 : 2;          /**< reserved */
00181   unsigned char btngr_ns : 2;       /**< number of button groups 1, 2 or 3 with 36/18/12 buttons */
00182   unsigned char zero2 : 1;          /**< reserved */
00183   unsigned char btngr1_dsp_ty : 3;  /**< display type of subpic stream for button group 1 */
00184   unsigned char zero3 : 1;          /**< reserved */
00185   unsigned char btngr2_dsp_ty : 3;  /**< display type of subpic stream for button group 2 */
00186   unsigned char zero4 : 1;          /**< reserved */
00187   unsigned char btngr3_dsp_ty : 3;  /**< display type of subpic stream for button group 3 */
00188 #else
00189   unsigned char btngr1_dsp_ty : 3;
00190   unsigned char zero2 : 1;
00191   unsigned char btngr_ns : 2;
00192   unsigned char zero1 : 2;
00193   unsigned char btngr3_dsp_ty : 3;
00194   unsigned char zero4 : 1;
00195   unsigned char btngr2_dsp_ty : 3;
00196   unsigned char zero3 : 1;
00197 #endif
00198   uint8_t btn_ofn;     /**< button offset number range 0-255 */
00199   uint8_t btn_ns;      /**< number of valid buttons  <= 36/18/12 (low 6 bits) */
00200   uint8_t nsl_btn_ns;  /**< number of buttons selectable by U_BTNNi (low 6 bits)   nsl_btn_ns <= btn_ns */
00201   uint8_t zero5;       /**< reserved */
00202   uint8_t fosl_btnn;   /**< forcedly selected button  (low 6 bits) */
00203   uint8_t foac_btnn;   /**< forcedly activated button (low 6 bits) */
00204 } ATTRIBUTE_PACKED hl_gi_t;
00205 
00206 
00207 /**
00208  * Button Color Information Table
00209  * Each entry beeing a 32bit word that contains the color indexs and alpha
00210  * values to use.  They are all represented by 4 bit number and stored
00211  * like this [Ci3, Ci2, Ci1, Ci0, A3, A2, A1, A0].   The actual palette
00212  * that the indexes reference is in the PGC.
00213  * \todo split the uint32_t into a struct
00214  */
00215 typedef struct {
00216   uint32_t btn_coli[3][2];  /**< [button color number-1][select:0/action:1] */
00217 } ATTRIBUTE_PACKED btn_colit_t;
00218 
00219 /**
00220  * Button Information
00221  *
00222  * NOTE: I've had to change the structure from the disk layout to get
00223  * the packing to work with Sun's Forte C compiler.
00224  * The 4 and 7 bytes are 'rotated' was: ABC DEF GHIJ  is: ABCG DEFH IJ
00225  */
00226 typedef struct {
00227 #ifdef WORDS_BIGENDIAN
00228   uint32        btn_coln         : 2;  /**< button color number */
00229   uint32        x_start          : 10; /**< x start offset within the overlay */
00230   uint32        zero1            : 2;  /**< reserved */
00231   uint32        x_end            : 10; /**< x end offset within the overlay */
00232 
00233   uint32        zero3            : 2;  /**< reserved */
00234   uint32        up               : 6;  /**< button index when pressing up */
00235 
00236   uint32        auto_action_mode : 2;  /**< 0: no, 1: activated if selected */
00237   uint32        y_start          : 10; /**< y start offset within the overlay */
00238   uint32        zero2            : 2;  /**< reserved */
00239   uint32        y_end            : 10; /**< y end offset within the overlay */
00240 
00241   uint32        zero4            : 2;  /**< reserved */
00242   uint32        down             : 6;  /**< button index when pressing down */
00243   unsigned char zero5            : 2;  /**< reserved */
00244   unsigned char left             : 6;  /**< button index when pressing left */
00245   unsigned char zero6            : 2;  /**< reserved */
00246   unsigned char right            : 6;  /**< button index when pressing right */
00247 #else
00248   uint32        x_end            : 10;
00249   uint32        zero1            : 2;
00250   uint32        x_start          : 10;
00251   uint32        btn_coln         : 2;
00252 
00253   uint32        up               : 6;
00254   uint32        zero3            : 2;
00255 
00256   uint32        y_end            : 10;
00257   uint32        zero2            : 2;
00258   uint32        y_start          : 10;
00259   uint32        auto_action_mode : 2;
00260 
00261   uint32        down             : 6;
00262   uint32        zero4            : 2;
00263   unsigned char left             : 6;
00264   unsigned char zero5            : 2;
00265   unsigned char right            : 6;
00266   unsigned char zero6            : 2;
00267 #endif
00268   vm_cmd_t cmd;
00269 } ATTRIBUTE_PACKED btni_t;
00270 
00271 /**
00272  * Highlight Information
00273  */
00274 typedef struct {
00275   hl_gi_t     hl_gi;
00276   btn_colit_t btn_colit;
00277   btni_t      btnit[36];
00278 } ATTRIBUTE_PACKED hli_t;
00279 
00280 /**
00281  * PCI packet
00282  */
00283 typedef struct {
00284   pci_gi_t    pci_gi;
00285   nsml_agli_t nsml_agli;
00286   hli_t       hli;
00287   uint8_t     zero1[189];
00288 } ATTRIBUTE_PACKED pci_t;
00289 
00290 #if PRAGMA_PACK
00291 #pragma pack()
00292 #endif
00293 ////////////////////////////////////////
00294 
00295 class virtual_segment_c;
00296 class chapter_item_c;
00297 
00298 typedef struct
00299 {
00300     VLC_COMMON_MEMBERS
00301 
00302     demux_t        *p_demux;
00303     vlc_mutex_t     lock;
00304 
00305     bool            b_moved;
00306     bool            b_clicked;
00307     int             i_key_action;
00308 
00309 } event_thread_t;
00310 
00311 
00312 class demux_sys_t
00313 {
00314 public:
00315     demux_sys_t( demux_t & demux )
00316         :demuxer(demux)
00317         ,i_pts(0)
00318         ,i_start_pts(0)
00319         ,i_chapter_time(0)
00320         ,meta(NULL)
00321         ,i_current_title(0)
00322         ,p_current_segment(NULL)
00323         ,dvd_interpretor( *this )
00324         ,f_duration(-1.0)
00325         ,b_ui_hooked(false)
00326         ,p_input(NULL)
00327         ,b_pci_packet_set(false)
00328         ,p_ev(NULL)
00329     {
00330         vlc_mutex_init( &lock_demuxer );
00331     }
00332 
00333     virtual ~demux_sys_t();
00334 
00335     /* current data */
00336     demux_t                 & demuxer;
00337 
00338     mtime_t                 i_pts;
00339     mtime_t                 i_start_pts;
00340     mtime_t                 i_chapter_time;
00341 
00342     vlc_meta_t              *meta;
00343 
00344     std::vector<input_title_t*>      titles; // matroska editions
00345     size_t                           i_current_title;
00346 
00347     std::vector<matroska_stream_c*>  streams;
00348     std::vector<attachment_c*>       stored_attachments;
00349     std::vector<matroska_segment_c*> opened_segments;
00350     std::vector<virtual_segment_c*>  used_segments;
00351     virtual_segment_c                *p_current_segment;
00352 
00353     dvd_command_interpretor_c        dvd_interpretor;
00354 
00355     /* duration of the stream */
00356     float                   f_duration;
00357 
00358     matroska_segment_c *FindSegment( const EbmlBinary & uid ) const;
00359     chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
00360                                         bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
00361                                         const void *p_cookie,
00362                                         size_t i_cookie_size,
00363                                         virtual_segment_c * & p_segment_found );
00364     chapter_item_c *FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found );
00365 
00366     void PreloadFamily( const matroska_segment_c & of_segment );
00367     void PreloadLinked( matroska_segment_c *p_segment );
00368     bool PreparePlayback( virtual_segment_c *p_new_segment );
00369     matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial = false );
00370     void JumpTo( virtual_segment_c & p_segment, chapter_item_c * p_chapter );
00371 
00372     void StartUiThread();
00373     void StopUiThread();
00374     bool b_ui_hooked;
00375     void SwapButtons();
00376 
00377     /* for spu variables */
00378     input_thread_t *p_input;
00379     pci_t          pci_packet;
00380     bool           b_pci_packet_set;
00381     uint8_t        palette[4][4];
00382     vlc_mutex_t    lock_demuxer;
00383 
00384     /* event */
00385     event_thread_t *p_ev;
00386     static void * EventThread( vlc_object_t *p_this );
00387     static int EventMouse( vlc_object_t *p_this, char const *psz_var,
00388                        vlc_value_t oldval, vlc_value_t newval, void *p_data );
00389     static int EventKey( vlc_object_t *p_this, char const *psz_var,
00390                      vlc_value_t oldval, vlc_value_t newval, void *p_data );
00391 
00392 
00393 
00394 protected:
00395     virtual_segment_c *VirtualFromSegments( matroska_segment_c *p_segment ) const;
00396     bool IsUsedSegment( matroska_segment_c &p_segment ) const;
00397 };
00398 
00399 
00400 #endif

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