]> git.sesse.net Git - vlc/blob - modules/demux/mkv/demux.hpp
Qt: NetOpenPanel: add drop-down list
[vlc] / modules / demux / mkv / demux.hpp
1 /*****************************************************************************
2  * mkv.cpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2004 the VideoLAN team
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
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.
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 General Public License for more details.
19  *
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  *****************************************************************************/
24
25 #ifndef _DEMUX_SYS_H
26 #define _DEMUX_SYS_H
27
28 #include "mkv.hpp"
29
30 #include "chapter_command.hpp"
31 #include "virtual_segment.hpp"
32
33 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34 #undef ATTRIBUTE_PACKED
35 #undef PRAGMA_PACK_BEGIN
36 #undef PRAGMA_PACK_END
37
38 #if defined(__GNUC__)
39 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
40 #define ATTRIBUTE_PACKED __attribute__ ((packed))
41 #define PRAGMA_PACK 0
42 #endif
43 #endif
44
45 #if !defined(ATTRIBUTE_PACKED)
46 #define ATTRIBUTE_PACKED
47 #define PRAGMA_PACK 1
48 #endif
49
50 #if PRAGMA_PACK
51 #pragma pack(1)
52 #endif
53
54 /*************************************
55 *  taken from libdvdnav / libdvdread
56 **************************************/
57
58 /**
59  * DVD Time Information.
60  */
61 typedef struct {
62   uint8_t hour;
63   uint8_t minute;
64   uint8_t second;
65   uint8_t frame_u; /* The two high bits are the frame rate. */
66 } ATTRIBUTE_PACKED dvd_time_t;
67
68 /**
69  * User Operations.
70  */
71 typedef struct {
72 #ifdef WORDS_BIGENDIAN
73   unsigned char zero                           : 7; /* 25-31 */
74   unsigned char video_pres_mode_change         : 1; /* 24 */
75  
76   unsigned char karaoke_audio_pres_mode_change : 1; /* 23 */
77   unsigned char angle_change                   : 1;
78   unsigned char subpic_stream_change           : 1;
79   unsigned char audio_stream_change            : 1;
80   unsigned char pause_on                       : 1;
81   unsigned char still_off                      : 1;
82   unsigned char button_select_or_activate      : 1;
83   unsigned char resume                         : 1; /* 16 */
84  
85   unsigned char chapter_menu_call              : 1; /* 15 */
86   unsigned char angle_menu_call                : 1;
87   unsigned char audio_menu_call                : 1;
88   unsigned char subpic_menu_call               : 1;
89   unsigned char root_menu_call                 : 1;
90   unsigned char title_menu_call                : 1;
91   unsigned char backward_scan                  : 1;
92   unsigned char forward_scan                   : 1; /* 8 */
93  
94   unsigned char next_pg_search                 : 1; /* 7 */
95   unsigned char prev_or_top_pg_search          : 1;
96   unsigned char time_or_chapter_search         : 1;
97   unsigned char go_up                          : 1;
98   unsigned char stop                           : 1;
99   unsigned char title_play                     : 1;
100   unsigned char chapter_search_or_play         : 1;
101   unsigned char title_or_time_play             : 1; /* 0 */
102 #else
103   unsigned char video_pres_mode_change         : 1; /* 24 */
104   unsigned char zero                           : 7; /* 25-31 */
105  
106   unsigned char resume                         : 1; /* 16 */
107   unsigned char button_select_or_activate      : 1;
108   unsigned char still_off                      : 1;
109   unsigned char pause_on                       : 1;
110   unsigned char audio_stream_change            : 1;
111   unsigned char subpic_stream_change           : 1;
112   unsigned char angle_change                   : 1;
113   unsigned char karaoke_audio_pres_mode_change : 1; /* 23 */
114  
115   unsigned char forward_scan                   : 1; /* 8 */
116   unsigned char backward_scan                  : 1;
117   unsigned char title_menu_call                : 1;
118   unsigned char root_menu_call                 : 1;
119   unsigned char subpic_menu_call               : 1;
120   unsigned char audio_menu_call                : 1;
121   unsigned char angle_menu_call                : 1;
122   unsigned char chapter_menu_call              : 1; /* 15 */
123  
124   unsigned char title_or_time_play             : 1; /* 0 */
125   unsigned char chapter_search_or_play         : 1;
126   unsigned char title_play                     : 1;
127   unsigned char stop                           : 1;
128   unsigned char go_up                          : 1;
129   unsigned char time_or_chapter_search         : 1;
130   unsigned char prev_or_top_pg_search          : 1;
131   unsigned char next_pg_search                 : 1; /* 7 */
132 #endif
133 } ATTRIBUTE_PACKED user_ops_t;
134
135 /**
136  * Type to store per-command data.
137  */
138 typedef struct {
139   uint8_t bytes[8];
140 } ATTRIBUTE_PACKED vm_cmd_t;
141 #define COMMAND_DATA_SIZE 8
142
143 /**
144  * PCI General Information
145  */
146 typedef struct {
147   uint32_t nv_pck_lbn;      /**< sector address of this nav pack */
148   uint16_t vobu_cat;        /**< 'category' of vobu */
149   uint16_t zero1;           /**< reserved */
150   user_ops_t vobu_uop_ctl;  /**< UOP of vobu */
151   uint32_t vobu_s_ptm;      /**< start presentation time of vobu */
152   uint32_t vobu_e_ptm;      /**< end presentation time of vobu */
153   uint32_t vobu_se_e_ptm;   /**< end ptm of sequence end in vobu */
154   dvd_time_t e_eltm;        /**< Cell elapsed time */
155   char vobu_isrc[32];
156 } ATTRIBUTE_PACKED pci_gi_t;
157
158 /**
159  * Non Seamless Angle Information
160  */
161 typedef struct {
162   uint32_t nsml_agl_dsta[9];  /**< address of destination vobu in AGL_C#n */
163 } ATTRIBUTE_PACKED nsml_agli_t;
164
165 /**
166  * Highlight General Information
167  *
168  * For btngrX_dsp_ty the bits have the following meaning:
169  * 000b: normal 4/3 only buttons
170  * XX1b: wide (16/9) buttons
171  * X1Xb: letterbox buttons
172  * 1XXb: pan&scan buttons
173  */
174 typedef struct {
175   uint16_t hli_ss; /**< status, only low 2 bits 0: no buttons, 1: different 2: equal 3: eual except for button cmds */
176   uint32_t hli_s_ptm;              /**< start ptm of hli */
177   uint32_t hli_e_ptm;              /**< end ptm of hli */
178   uint32_t btn_se_e_ptm;           /**< end ptm of button select */
179 #ifdef WORDS_BIGENDIAN
180   unsigned char zero1 : 2;          /**< reserved */
181   unsigned char btngr_ns : 2;       /**< number of button groups 1, 2 or 3 with 36/18/12 buttons */
182   unsigned char zero2 : 1;          /**< reserved */
183   unsigned char btngr1_dsp_ty : 3;  /**< display type of subpic stream for button group 1 */
184   unsigned char zero3 : 1;          /**< reserved */
185   unsigned char btngr2_dsp_ty : 3;  /**< display type of subpic stream for button group 2 */
186   unsigned char zero4 : 1;          /**< reserved */
187   unsigned char btngr3_dsp_ty : 3;  /**< display type of subpic stream for button group 3 */
188 #else
189   unsigned char btngr1_dsp_ty : 3;
190   unsigned char zero2 : 1;
191   unsigned char btngr_ns : 2;
192   unsigned char zero1 : 2;
193   unsigned char btngr3_dsp_ty : 3;
194   unsigned char zero4 : 1;
195   unsigned char btngr2_dsp_ty : 3;
196   unsigned char zero3 : 1;
197 #endif
198   uint8_t btn_ofn;     /**< button offset number range 0-255 */
199   uint8_t btn_ns;      /**< number of valid buttons  <= 36/18/12 (low 6 bits) */
200   uint8_t nsl_btn_ns;  /**< number of buttons selectable by U_BTNNi (low 6 bits)   nsl_btn_ns <= btn_ns */
201   uint8_t zero5;       /**< reserved */
202   uint8_t fosl_btnn;   /**< forcedly selected button  (low 6 bits) */
203   uint8_t foac_btnn;   /**< forcedly activated button (low 6 bits) */
204 } ATTRIBUTE_PACKED hl_gi_t;
205
206
207 /**
208  * Button Color Information Table
209  * Each entry beeing a 32bit word that contains the color indexs and alpha
210  * values to use.  They are all represented by 4 bit number and stored
211  * like this [Ci3, Ci2, Ci1, Ci0, A3, A2, A1, A0].   The actual palette
212  * that the indexes reference is in the PGC.
213  * \todo split the uint32_t into a struct
214  */
215 typedef struct {
216   uint32_t btn_coli[3][2];  /**< [button color number-1][select:0/action:1] */
217 } ATTRIBUTE_PACKED btn_colit_t;
218
219 /**
220  * Button Information
221  *
222  * NOTE: I've had to change the structure from the disk layout to get
223  * the packing to work with Sun's Forte C compiler.
224  * The 4 and 7 bytes are 'rotated' was: ABC DEF GHIJ  is: ABCG DEFH IJ
225  */
226 typedef struct {
227 #ifdef WORDS_BIGENDIAN
228   uint32        btn_coln         : 2;  /**< button color number */
229   uint32        x_start          : 10; /**< x start offset within the overlay */
230   uint32        zero1            : 2;  /**< reserved */
231   uint32        x_end            : 10; /**< x end offset within the overlay */
232
233   uint32        zero3            : 2;  /**< reserved */
234   uint32        up               : 6;  /**< button index when pressing up */
235
236   uint32        auto_action_mode : 2;  /**< 0: no, 1: activated if selected */
237   uint32        y_start          : 10; /**< y start offset within the overlay */
238   uint32        zero2            : 2;  /**< reserved */
239   uint32        y_end            : 10; /**< y end offset within the overlay */
240
241   uint32        zero4            : 2;  /**< reserved */
242   uint32        down             : 6;  /**< button index when pressing down */
243   unsigned char zero5            : 2;  /**< reserved */
244   unsigned char left             : 6;  /**< button index when pressing left */
245   unsigned char zero6            : 2;  /**< reserved */
246   unsigned char right            : 6;  /**< button index when pressing right */
247 #else
248   uint32        x_end            : 10;
249   uint32        zero1            : 2;
250   uint32        x_start          : 10;
251   uint32        btn_coln         : 2;
252
253   uint32        up               : 6;
254   uint32        zero3            : 2;
255
256   uint32        y_end            : 10;
257   uint32        zero2            : 2;
258   uint32        y_start          : 10;
259   uint32        auto_action_mode : 2;
260
261   uint32        down             : 6;
262   uint32        zero4            : 2;
263   unsigned char left             : 6;
264   unsigned char zero5            : 2;
265   unsigned char right            : 6;
266   unsigned char zero6            : 2;
267 #endif
268   vm_cmd_t cmd;
269 } ATTRIBUTE_PACKED btni_t;
270
271 /**
272  * Highlight Information
273  */
274 typedef struct {
275   hl_gi_t     hl_gi;
276   btn_colit_t btn_colit;
277   btni_t      btnit[36];
278 } ATTRIBUTE_PACKED hli_t;
279
280 /**
281  * PCI packet
282  */
283 typedef struct {
284   pci_gi_t    pci_gi;
285   nsml_agli_t nsml_agli;
286   hli_t       hli;
287   uint8_t     zero1[189];
288 } ATTRIBUTE_PACKED pci_t;
289
290 #if PRAGMA_PACK
291 #pragma pack()
292 #endif
293 ////////////////////////////////////////
294
295 class virtual_segment_c;
296 class chapter_item_c;
297
298 typedef struct
299 {
300     VLC_COMMON_MEMBERS
301
302     demux_t        *p_demux;
303     vlc_mutex_t     lock;
304
305     bool            b_moved;
306     bool            b_clicked;
307     int             i_key_action;
308
309 } event_thread_t;
310
311
312 class demux_sys_t
313 {
314 public:
315     demux_sys_t( demux_t & demux )
316         :demuxer(demux)
317         ,i_pts(0)
318         ,i_start_pts(0)
319         ,i_chapter_time(0)
320         ,meta(NULL)
321         ,i_current_title(0)
322         ,p_current_segment(NULL)
323         ,dvd_interpretor( *this )
324         ,f_duration(-1.0)
325         ,b_ui_hooked(false)
326         ,p_input(NULL)
327         ,b_pci_packet_set(false)
328         ,p_ev(NULL)
329     {
330         vlc_mutex_init( &lock_demuxer );
331     }
332
333     virtual ~demux_sys_t();
334
335     /* current data */
336     demux_t                 & demuxer;
337
338     mtime_t                 i_pts;
339     mtime_t                 i_start_pts;
340     mtime_t                 i_chapter_time;
341
342     vlc_meta_t              *meta;
343
344     std::vector<input_title_t*>      titles; // matroska editions
345     size_t                           i_current_title;
346
347     std::vector<matroska_stream_c*>  streams;
348     std::vector<attachment_c*>       stored_attachments;
349     std::vector<matroska_segment_c*> opened_segments;
350     std::vector<virtual_segment_c*>  used_segments;
351     virtual_segment_c                *p_current_segment;
352
353     dvd_command_interpretor_c        dvd_interpretor;
354
355     /* duration of the stream */
356     float                   f_duration;
357
358     matroska_segment_c *FindSegment( const EbmlBinary & uid ) const;
359     chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
360                                         bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
361                                         const void *p_cookie,
362                                         size_t i_cookie_size,
363                                         virtual_segment_c * & p_segment_found );
364     chapter_item_c *FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found );
365
366     void PreloadFamily( const matroska_segment_c & of_segment );
367     void PreloadLinked( matroska_segment_c *p_segment );
368     bool PreparePlayback( virtual_segment_c *p_new_segment );
369     matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial = false );
370     void JumpTo( virtual_segment_c & p_segment, chapter_item_c * p_chapter );
371
372     void StartUiThread();
373     void StopUiThread();
374     bool b_ui_hooked;
375     void SwapButtons();
376
377     /* for spu variables */
378     input_thread_t *p_input;
379     pci_t          pci_packet;
380     bool           b_pci_packet_set;
381     uint8_t        palette[4][4];
382     vlc_mutex_t    lock_demuxer;
383
384     /* event */
385     event_thread_t *p_ev;
386     static void * EventThread( vlc_object_t *p_this );
387     static int EventMouse( vlc_object_t *p_this, char const *psz_var,
388                        vlc_value_t oldval, vlc_value_t newval, void *p_data );
389     static int EventKey( vlc_object_t *p_this, char const *psz_var,
390                      vlc_value_t oldval, vlc_value_t newval, void *p_data );
391
392
393
394 protected:
395     virtual_segment_c *VirtualFromSegments( matroska_segment_c *p_segment ) const;
396     bool IsUsedSegment( matroska_segment_c &p_segment ) const;
397 };
398
399
400 #endif