1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
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
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.
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.
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 *****************************************************************************/
30 #include "chapter_command.hpp"
31 #include "virtual_segment.hpp"
33 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34 #undef ATTRIBUTE_PACKED
35 #undef PRAGMA_PACK_BEGIN
36 #undef PRAGMA_PACK_END
39 #define ATTRIBUTE_PACKED __attribute__ ((packed))
43 #if !defined(ATTRIBUTE_PACKED)
44 #define ATTRIBUTE_PACKED
52 /*************************************
53 * taken from libdvdnav / libdvdread
54 **************************************/
57 * DVD Time Information.
63 uint8_t frame_u; /* The two high bits are the frame rate. */
64 } ATTRIBUTE_PACKED dvd_time_t;
70 #ifdef WORDS_BIGENDIAN
71 unsigned char zero : 7; /* 25-31 */
72 unsigned char video_pres_mode_change : 1; /* 24 */
74 unsigned char karaoke_audio_pres_mode_change : 1; /* 23 */
75 unsigned char angle_change : 1;
76 unsigned char subpic_stream_change : 1;
77 unsigned char audio_stream_change : 1;
78 unsigned char pause_on : 1;
79 unsigned char still_off : 1;
80 unsigned char button_select_or_activate : 1;
81 unsigned char resume : 1; /* 16 */
83 unsigned char chapter_menu_call : 1; /* 15 */
84 unsigned char angle_menu_call : 1;
85 unsigned char audio_menu_call : 1;
86 unsigned char subpic_menu_call : 1;
87 unsigned char root_menu_call : 1;
88 unsigned char title_menu_call : 1;
89 unsigned char backward_scan : 1;
90 unsigned char forward_scan : 1; /* 8 */
92 unsigned char next_pg_search : 1; /* 7 */
93 unsigned char prev_or_top_pg_search : 1;
94 unsigned char time_or_chapter_search : 1;
95 unsigned char go_up : 1;
96 unsigned char stop : 1;
97 unsigned char title_play : 1;
98 unsigned char chapter_search_or_play : 1;
99 unsigned char title_or_time_play : 1; /* 0 */
101 unsigned char video_pres_mode_change : 1; /* 24 */
102 unsigned char zero : 7; /* 25-31 */
104 unsigned char resume : 1; /* 16 */
105 unsigned char button_select_or_activate : 1;
106 unsigned char still_off : 1;
107 unsigned char pause_on : 1;
108 unsigned char audio_stream_change : 1;
109 unsigned char subpic_stream_change : 1;
110 unsigned char angle_change : 1;
111 unsigned char karaoke_audio_pres_mode_change : 1; /* 23 */
113 unsigned char forward_scan : 1; /* 8 */
114 unsigned char backward_scan : 1;
115 unsigned char title_menu_call : 1;
116 unsigned char root_menu_call : 1;
117 unsigned char subpic_menu_call : 1;
118 unsigned char audio_menu_call : 1;
119 unsigned char angle_menu_call : 1;
120 unsigned char chapter_menu_call : 1; /* 15 */
122 unsigned char title_or_time_play : 1; /* 0 */
123 unsigned char chapter_search_or_play : 1;
124 unsigned char title_play : 1;
125 unsigned char stop : 1;
126 unsigned char go_up : 1;
127 unsigned char time_or_chapter_search : 1;
128 unsigned char prev_or_top_pg_search : 1;
129 unsigned char next_pg_search : 1; /* 7 */
131 } ATTRIBUTE_PACKED user_ops_t;
134 * Type to store per-command data.
138 } ATTRIBUTE_PACKED vm_cmd_t;
139 #define COMMAND_DATA_SIZE 8
142 * PCI General Information
145 uint32_t nv_pck_lbn; /**< sector address of this nav pack */
146 uint16_t vobu_cat; /**< 'category' of vobu */
147 uint16_t zero1; /**< reserved */
148 user_ops_t vobu_uop_ctl; /**< UOP of vobu */
149 uint32_t vobu_s_ptm; /**< start presentation time of vobu */
150 uint32_t vobu_e_ptm; /**< end presentation time of vobu */
151 uint32_t vobu_se_e_ptm; /**< end ptm of sequence end in vobu */
152 dvd_time_t e_eltm; /**< Cell elapsed time */
154 } ATTRIBUTE_PACKED pci_gi_t;
157 * Non Seamless Angle Information
160 uint32_t nsml_agl_dsta[9]; /**< address of destination vobu in AGL_C#n */
161 } ATTRIBUTE_PACKED nsml_agli_t;
164 * Highlight General Information
166 * For btngrX_dsp_ty the bits have the following meaning:
167 * 000b: normal 4/3 only buttons
168 * XX1b: wide (16/9) buttons
169 * X1Xb: letterbox buttons
170 * 1XXb: pan&scan buttons
173 uint16_t hli_ss; /**< status, only low 2 bits 0: no buttons, 1: different 2: equal 3: eual except for button cmds */
174 uint32_t hli_s_ptm; /**< start ptm of hli */
175 uint32_t hli_e_ptm; /**< end ptm of hli */
176 uint32_t btn_se_e_ptm; /**< end ptm of button select */
177 #ifdef WORDS_BIGENDIAN
178 unsigned char zero1 : 2; /**< reserved */
179 unsigned char btngr_ns : 2; /**< number of button groups 1, 2 or 3 with 36/18/12 buttons */
180 unsigned char zero2 : 1; /**< reserved */
181 unsigned char btngr1_dsp_ty : 3; /**< display type of subpic stream for button group 1 */
182 unsigned char zero3 : 1; /**< reserved */
183 unsigned char btngr2_dsp_ty : 3; /**< display type of subpic stream for button group 2 */
184 unsigned char zero4 : 1; /**< reserved */
185 unsigned char btngr3_dsp_ty : 3; /**< display type of subpic stream for button group 3 */
187 unsigned char btngr1_dsp_ty : 3;
188 unsigned char zero2 : 1;
189 unsigned char btngr_ns : 2;
190 unsigned char zero1 : 2;
191 unsigned char btngr3_dsp_ty : 3;
192 unsigned char zero4 : 1;
193 unsigned char btngr2_dsp_ty : 3;
194 unsigned char zero3 : 1;
196 uint8_t btn_ofn; /**< button offset number range 0-255 */
197 uint8_t btn_ns; /**< number of valid buttons <= 36/18/12 (low 6 bits) */
198 uint8_t nsl_btn_ns; /**< number of buttons selectable by U_BTNNi (low 6 bits) nsl_btn_ns <= btn_ns */
199 uint8_t zero5; /**< reserved */
200 uint8_t fosl_btnn; /**< forcedly selected button (low 6 bits) */
201 uint8_t foac_btnn; /**< forcedly activated button (low 6 bits) */
202 } ATTRIBUTE_PACKED hl_gi_t;
206 * Button Color Information Table
207 * Each entry beeing a 32bit word that contains the color indexs and alpha
208 * values to use. They are all represented by 4 bit number and stored
209 * like this [Ci3, Ci2, Ci1, Ci0, A3, A2, A1, A0]. The actual palette
210 * that the indexes reference is in the PGC.
211 * \todo split the uint32_t into a struct
214 uint32_t btn_coli[3][2]; /**< [button color number-1][select:0/action:1] */
215 } ATTRIBUTE_PACKED btn_colit_t;
220 * NOTE: I've had to change the structure from the disk layout to get
221 * the packing to work with Sun's Forte C compiler.
222 * The 4 and 7 bytes are 'rotated' was: ABC DEF GHIJ is: ABCG DEFH IJ
225 #ifdef WORDS_BIGENDIAN
226 uint32 btn_coln : 2; /**< button color number */
227 uint32 x_start : 10; /**< x start offset within the overlay */
228 uint32 zero1 : 2; /**< reserved */
229 uint32 x_end : 10; /**< x end offset within the overlay */
231 uint32 zero3 : 2; /**< reserved */
232 uint32 up : 6; /**< button index when pressing up */
234 uint32 auto_action_mode : 2; /**< 0: no, 1: activated if selected */
235 uint32 y_start : 10; /**< y start offset within the overlay */
236 uint32 zero2 : 2; /**< reserved */
237 uint32 y_end : 10; /**< y end offset within the overlay */
239 uint32 zero4 : 2; /**< reserved */
240 uint32 down : 6; /**< button index when pressing down */
241 unsigned char zero5 : 2; /**< reserved */
242 unsigned char left : 6; /**< button index when pressing left */
243 unsigned char zero6 : 2; /**< reserved */
244 unsigned char right : 6; /**< button index when pressing right */
257 uint32 auto_action_mode : 2;
261 unsigned char left : 6;
262 unsigned char zero5 : 2;
263 unsigned char right : 6;
264 unsigned char zero6 : 2;
267 } ATTRIBUTE_PACKED btni_t;
270 * Highlight Information
274 btn_colit_t btn_colit;
276 } ATTRIBUTE_PACKED hli_t;
283 nsml_agli_t nsml_agli;
286 } ATTRIBUTE_PACKED pci_t;
291 ////////////////////////////////////////
293 class virtual_segment_c;
294 class chapter_item_c;
299 event_thread_t(demux_t *);
300 virtual ~event_thread_t();
302 void SetPci(const pci_t *data);
307 static void *EventThread(void *);
309 static int EventMouse( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );
310 static int EventKey( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );
311 static int EventInput( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );
332 demux_sys_t( demux_t & demux )
339 ,p_current_segment(NULL)
340 ,dvd_interpretor( *this )
345 vlc_mutex_init( &lock_demuxer );
348 virtual ~demux_sys_t();
355 mtime_t i_chapter_time;
359 std::vector<input_title_t*> titles; // matroska editions
360 size_t i_current_title;
362 std::vector<matroska_stream_c*> streams;
363 std::vector<attachment_c*> stored_attachments;
364 std::vector<matroska_segment_c*> opened_segments;
365 std::vector<virtual_segment_c*> used_segments;
366 virtual_segment_c *p_current_segment;
368 dvd_command_interpretor_c dvd_interpretor;
370 /* duration of the stream */
373 matroska_segment_c *FindSegment( const EbmlBinary & uid ) const;
374 virtual_chapter_c *BrowseCodecPrivate( unsigned int codec_id,
375 bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
376 const void *p_cookie,
377 size_t i_cookie_size,
378 virtual_segment_c * & p_segment_found );
379 virtual_chapter_c *FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found );
381 void PreloadFamily( const matroska_segment_c & of_segment );
382 void PreloadLinked();
383 bool PreparePlayback( virtual_segment_c *p_new_segment );
384 matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial = false );
385 void JumpTo( virtual_segment_c & p_segment, virtual_chapter_c * p_chapter );
390 /* for spu variables */
391 input_thread_t *p_input;
392 uint8_t palette[4][4];
393 vlc_mutex_t lock_demuxer;
396 event_thread_t *p_ev;
399 virtual_segment_c *VirtualFromSegments( std::vector<matroska_segment_c*> *p_segments ) const;