matroska_segment_parse.cpp 68 KB
Newer Older
1
/*****************************************************************************
Pere Orga's avatar
Pere Orga committed
2
 * matroska_segment_parse.cpp : matroska demuxer
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2003-2010 VLC authors and VideoLAN
5
6
7
8
9
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *          Steve Lhomme <steve.lhomme@free.fr>
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
10
11
12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13
14
15
16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
17
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
20
21
22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23
 *****************************************************************************/
24
#include "mkv.hpp"
25
26
27
#include "matroska_segment.hpp"
#include "chapters.hpp"
#include "demux.hpp"
28
#include "Ebml_parser.hpp"
29
30
#include "util.hpp"

31
32
extern "C" {
#include "../vobsub.h"
33
#include "../xiph.h"
34
#include "../windows_audio_commons.h"
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
}

#include <vlc_codecs.h>

/* GetFourCC helper */
#define GetFOURCC( p )  __GetFOURCC( (uint8_t*)p )
static vlc_fourcc_t __GetFOURCC( uint8_t *p )
{
    return VLC_FOURCC( p[0], p[1], p[2], p[3] );
}

static inline void fill_extra_data( mkv_track_t *p_tk, unsigned int offset )
{
    if(p_tk->i_extra_data <= offset) return;
    p_tk->fmt.i_extra = p_tk->i_extra_data - offset;
    p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
    if(!p_tk->fmt.p_extra) { p_tk->fmt.i_extra = 0; return; };
    memcpy( p_tk->fmt.p_extra, p_tk->p_extra_data + offset, p_tk->fmt.i_extra );
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
55
56
57
58
59
60
61
62
/*****************************************************************************
 * Some functions to manipulate memory
 *****************************************************************************/
static inline char * ToUTF8( const UTFstring &u )
{
    return strdup( u.GetUTF8().c_str() );
}

63
64
65
66
67
68
69
70
/*****************************************************************************
 * ParseSeekHead:
 *****************************************************************************/
void matroska_segment_c::ParseSeekHead( KaxSeekHead *seekhead )
{
    EbmlParser  *ep;
    EbmlElement *l;
    bool b_seekable;
71

72
    i_seekhead_count++;
73

74
75
76
    stream_Control( sys.demuxer.s, STREAM_CAN_SEEK, &b_seekable );
    if( !b_seekable )
        return;
77

78
    ep = new EbmlParser( &es, seekhead, &sys.demuxer );
79

80
81
82
83
    while( ( l = ep->Get() ) != NULL )
    {
        if( MKV_IS_ID( l, KaxSeek ) )
        {
Steve Lhomme's avatar
Steve Lhomme committed
84
            EbmlId id = EBML_ID(EbmlVoid);
85
            int64_t i_pos = -1;
86

87
#ifdef MKV_DEBUG
88
            msg_Dbg( &sys.demuxer, "|   |   + Seek" );
89
#endif
90
            ep->Down();
91
            try
92
            {
93
                while( ( l = ep->Get() ) != NULL )
94
                {
95
96
97
98
99
                    if( unlikely( l->GetSize() >= SIZE_MAX ) )
                    {
                        msg_Err( &sys.demuxer,"%s too big... skipping it",  typeid(*l).name() );
                        continue;
                    }
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
                    if( MKV_IS_ID( l, KaxSeekID ) )
                    {
                        KaxSeekID &sid = *(KaxSeekID*)l;
                        sid.ReadData( es.I_O() );
                        id = EbmlId( sid.GetBuffer(), sid.GetSize() );
                    }
                    else if( MKV_IS_ID( l, KaxSeekPosition ) )
                    {
                        KaxSeekPosition &spos = *(KaxSeekPosition*)l;
                        spos.ReadData( es.I_O() );
                        i_pos = (int64_t)segment->GetGlobalPosition( uint64( spos ) );
                    }
                    else
                    {
                        /* Many mkvmerge files hit this case. It seems to be a broken SeekHead */
                        msg_Dbg( &sys.demuxer, "|   |   + Unknown (%s)", typeid(*l).name() );
                    }
117
118
                }
            }
119
120
121
122
            catch(...)
            {
                msg_Err( &sys.demuxer,"Error while reading %s",  typeid(*l).name() );
            }
123
            ep->Up();
124

125
126
            if( i_pos >= 0 )
            {
Steve Lhomme's avatar
Steve Lhomme committed
127
                if( id == EBML_ID(KaxCues) )
128
129
                {
                    msg_Dbg( &sys.demuxer, "|   - cues at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
130
                    LoadSeekHeadItem( EBML_INFO(KaxCues), i_pos );
131
                }
Steve Lhomme's avatar
Steve Lhomme committed
132
                else if( id == EBML_ID(KaxInfo) )
133
134
                {
                    msg_Dbg( &sys.demuxer, "|   - info at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
135
                    LoadSeekHeadItem( EBML_INFO(KaxInfo), i_pos );
136
                }
Steve Lhomme's avatar
Steve Lhomme committed
137
                else if( id == EBML_ID(KaxChapters) )
138
139
                {
                    msg_Dbg( &sys.demuxer, "|   - chapters at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
140
                    LoadSeekHeadItem( EBML_INFO(KaxChapters), i_pos );
141
                }
Steve Lhomme's avatar
Steve Lhomme committed
142
                else if( id == EBML_ID(KaxTags) )
143
144
                {
                    msg_Dbg( &sys.demuxer, "|   - tags at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
145
                    LoadSeekHeadItem( EBML_INFO(KaxTags), i_pos );
146
                }
Steve Lhomme's avatar
Steve Lhomme committed
147
                else if( id == EBML_ID(KaxSeekHead) )
148
149
                {
                    msg_Dbg( &sys.demuxer, "|   - chained seekhead at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
150
                    LoadSeekHeadItem( EBML_INFO(KaxSeekHead), i_pos );
151
                }
Steve Lhomme's avatar
Steve Lhomme committed
152
                else if( id == EBML_ID(KaxTracks) )
153
154
                {
                    msg_Dbg( &sys.demuxer, "|   - tracks at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
155
                    LoadSeekHeadItem( EBML_INFO(KaxTracks), i_pos );
156
                }
Steve Lhomme's avatar
Steve Lhomme committed
157
                else if( id == EBML_ID(KaxAttachments) )
158
159
                {
                    msg_Dbg( &sys.demuxer, "|   - attachments at %"PRId64, i_pos );
Steve Lhomme's avatar
Steve Lhomme committed
160
                    LoadSeekHeadItem( EBML_INFO(KaxAttachments), i_pos );
161
                }
162
#ifdef MKV_DEBUG
163
164
                else
                    msg_Dbg( &sys.demuxer, "|   - unknown seekhead reference at %"PRId64, i_pos );
165
#endif
166
167
168
169
170
171
            }
        }
        else
            msg_Dbg( &sys.demuxer, "|   |   + ParseSeekHead Unknown (%s)", typeid(*l).name() );
    }
    delete ep;
172
173
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
174
175
176
177
178
179
180
181
182

/**
 * Helper function to print the mkv parse tree
 */
static void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, ... )
{
    va_list args;
    if( i_level > 9 )
    {
183
        msg_Err( &demuxer, "MKV tree is too deep" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
184
185
186
187
188
189
190
191
192
        return;
    }
    va_start( args, psz_format );
    static const char psz_foo[] = "|   |   |   |   |   |   |   |   |   |";
    char *psz_foo2 = (char*)malloc( i_level * 4 + 3 + strlen( psz_format ) );
    strncpy( psz_foo2, psz_foo, 4 * i_level );
    psz_foo2[ 4 * i_level ] = '+';
    psz_foo2[ 4 * i_level + 1 ] = ' ';
    strcpy( &psz_foo2[ 4 * i_level + 2 ], psz_format );
193
    msg_GenericVa( &demuxer,VLC_MSG_DBG, "mkv", psz_foo2, args );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
194
195
196
197
198
    free( psz_foo2 );
    va_end( args );
}


199
/*****************************************************************************
200
 * ParseTrackEntry:
201
 *****************************************************************************/
202
203
204
void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
{
    bool bSupported = true;
205

206
    /* Init the track */
207
    mkv_track_t *tk = new mkv_track_t();
208
    memset( tk, 0, sizeof( mkv_track_t ) );
209

210
    es_format_Init( &tk->fmt, UNKNOWN_ES, 0 );
211
    tk->p_es = NULL;
212
213
214
215
216
    tk->fmt.psz_language       = strdup("English");
    tk->fmt.psz_description    = NULL;

    tk->b_default              = true;
    tk->b_enabled              = true;
217
    tk->b_forced               = false;
218
219
220
221
222
223
224
    tk->b_silent               = false;
    tk->i_number               = tracks.size() - 1;
    tk->i_extra_data           = 0;
    tk->p_extra_data           = NULL;
    tk->psz_codec              = NULL;
    tk->b_dts_only             = false;
    tk->i_default_duration     = 0;
225
    tk->b_no_duration          = false;
226
227
228
229
230
231
232
233
234
    tk->f_timecodescale        = 1.0;

    tk->b_inited               = false;
    tk->i_data_init            = 0;
    tk->p_data_init            = NULL;

    tk->psz_codec_name         = NULL;
    tk->psz_codec_settings     = NULL;
    tk->psz_codec_info_url     = NULL;
235
    tk->psz_codec_download_url = NULL;
236

237
    tk->i_compression_type     = MATROSKA_COMPRESSION_NONE;
238
    tk->i_encoding_scope       = MATROSKA_ENCODING_SCOPE_ALL_FRAMES;
239
240
241
    tk->p_compression_data     = NULL;

    msg_Dbg( &sys.demuxer, "|   |   + Track Entry" );
242

243
    for( size_t i = 0; i < m->ListSize(); i++ )
244
245
    {
        EbmlElement *l = (*m)[i];
246

247
248
249
        if( MKV_IS_ID( l, KaxTrackNumber ) )
        {
            KaxTrackNumber &tnum = *(KaxTrackNumber*)l;
250

251
252
253
254
255
256
            tk->i_number = uint32( tnum );
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Number=%u", uint32( tnum ) );
        }
        else  if( MKV_IS_ID( l, KaxTrackUID ) )
        {
            KaxTrackUID &tuid = *(KaxTrackUID*)l;
257

258
259
260
261
262
263
            msg_Dbg( &sys.demuxer, "|   |   |   + Track UID=%u",  uint32( tuid ) );
        }
        else  if( MKV_IS_ID( l, KaxTrackType ) )
        {
            const char *psz_type;
            KaxTrackType &ttype = *(KaxTrackType*)l;
264

265
266
267
268
269
            switch( uint8(ttype) )
            {
                case track_audio:
                    psz_type = "audio";
                    tk->fmt.i_cat = AUDIO_ES;
270
271
                    tk->fmt.audio.i_channels = 1;
                    tk->fmt.audio.i_rate = 8000;
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
                    break;
                case track_video:
                    psz_type = "video";
                    tk->fmt.i_cat = VIDEO_ES;
                    break;
                case track_subtitle:
                    psz_type = "subtitle";
                    tk->fmt.i_cat = SPU_ES;
                    break;
                case track_buttons:
                    psz_type = "buttons";
                    tk->fmt.i_cat = SPU_ES;
                    break;
                default:
                    psz_type = "unknown";
                    tk->fmt.i_cat = UNKNOWN_ES;
                    break;
            }
290

291
292
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Type=%s", psz_type );
        }
293
294
295
        else  if( MKV_IS_ID( l, KaxTrackFlagEnabled ) ) // UNUSED
        {
            KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)l;
296

297
            tk->b_enabled = uint32( fenb );
298
299
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Enabled=%u", uint32( fenb ) );
        }
300
301
302
        else  if( MKV_IS_ID( l, KaxTrackFlagDefault ) )
        {
            KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)l;
303

304
            tk->b_default = uint32( fdef );
305
306
307
308
309
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Default=%u", uint32( fdef ) );
        }
        else  if( MKV_IS_ID( l, KaxTrackFlagForced ) ) // UNUSED
        {
            KaxTrackFlagForced &ffor = *(KaxTrackFlagForced*)l;
310
            tk->b_forced = uint32( ffor );
311
312

            msg_Dbg( &sys.demuxer, "|   |   |   + Track Forced=%u", uint32( ffor ) );
313
        }
314
        else  if( MKV_IS_ID( l, KaxTrackFlagLacing ) ) // UNUSED
315
316
        {
            KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)l;
317

318
319
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Lacing=%d", uint32( lac ) );
        }
320
        else  if( MKV_IS_ID( l, KaxTrackMinCache ) ) // UNUSED
321
322
        {
            KaxTrackMinCache &cmin = *(KaxTrackMinCache*)l;
323

324
325
            msg_Dbg( &sys.demuxer, "|   |   |   + Track MinCache=%d", uint32( cmin ) );
        }
326
        else  if( MKV_IS_ID( l, KaxTrackMaxCache ) ) // UNUSED
327
328
        {
            KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)l;
329

330
331
332
            msg_Dbg( &sys.demuxer, "|   |   |   + Track MaxCache=%d", uint32( cmax ) );
        }
        else  if( MKV_IS_ID( l, KaxTrackDefaultDuration ) )
333
        {
334
335
336
337
            KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)l;

            tk->i_default_duration = uint64(defd);
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Default Duration=%"PRId64, uint64(defd) );
338
        }
339
340
341
        else  if( MKV_IS_ID( l, KaxTrackTimecodeScale ) )
        {
            KaxTrackTimecodeScale &ttcs = *(KaxTrackTimecodeScale*)l;
342

343
            tk->f_timecodescale = float( ttcs );
344
            if ( tk->f_timecodescale <= 0 ) tk->f_timecodescale = 1.0;
345
346
            msg_Dbg( &sys.demuxer, "|   |   |   + Track TimeCodeScale=%f", tk->f_timecodescale );
        }
347
348
349
350
351
352
        else  if( MKV_IS_ID( l, KaxMaxBlockAdditionID ) ) // UNUSED
        {
            KaxMaxBlockAdditionID &mbl = *(KaxMaxBlockAdditionID*)l;

            msg_Dbg( &sys.demuxer, "|   |   |   + Track Max BlockAdditionID=%d", uint32( mbl ) );
        }
353
354
355
        else if( MKV_IS_ID( l, KaxTrackName ) )
        {
            KaxTrackName &tname = *(KaxTrackName*)l;
356

357
358
359
360
361
362
            tk->fmt.psz_description = ToUTF8( UTFstring( tname ) );
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Name=%s", tk->fmt.psz_description );
        }
        else  if( MKV_IS_ID( l, KaxTrackLanguage ) )
        {
            KaxTrackLanguage &lang = *(KaxTrackLanguage*)l;
363

364
            free( tk->fmt.psz_language );
365
366
367
368
369
370
371
            tk->fmt.psz_language = strdup( string( lang ).c_str() );
            msg_Dbg( &sys.demuxer,
                     "|   |   |   + Track Language=`%s'", tk->fmt.psz_language );
        }
        else  if( MKV_IS_ID( l, KaxCodecID ) )
        {
            KaxCodecID &codecid = *(KaxCodecID*)l;
372

373
374
            tk->psz_codec = strdup( string( codecid ).c_str() );
            msg_Dbg( &sys.demuxer, "|   |   |   + Track CodecId=%s", string( codecid ).c_str() );
375
        }
376
        else  if( MKV_IS_ID( l, KaxCodecPrivate ) )
377
        {
378
            KaxCodecPrivate &cpriv = *(KaxCodecPrivate*)l;
379

380
381
            tk->i_extra_data = cpriv.GetSize();
            if( tk->i_extra_data > 0 )
382
            {
383
384
                tk->p_extra_data = (uint8_t*)malloc( tk->i_extra_data );
                memcpy( tk->p_extra_data, cpriv.GetBuffer(), tk->i_extra_data );
385
            }
386
            msg_Dbg( &sys.demuxer, "|   |   |   + Track CodecPrivate size=%"PRId64, cpriv.GetSize() );
387
        }
388
        else if( MKV_IS_ID( l, KaxCodecName ) )
389
        {
390
            KaxCodecName &cname = *(KaxCodecName*)l;
391

392
393
            tk->psz_codec_name = ToUTF8( UTFstring( cname ) );
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Codec Name=%s", tk->psz_codec_name );
394
        }
395
396
397
398
399
400
401
402
403
404
405
406
407
        //AttachmentLink
        else if( MKV_IS_ID( l, KaxCodecDecodeAll ) ) // UNUSED
        {
            KaxCodecDecodeAll &cdall = *(KaxCodecDecodeAll*)l;

            msg_Dbg( &sys.demuxer, "|   |   |   + Track Codec Decode All=%u", uint8( cdall ) );
        }
        else if( MKV_IS_ID( l, KaxTrackOverlay ) ) // UNUSED
        {
            KaxTrackOverlay &tovr = *(KaxTrackOverlay*)l;

            msg_Dbg( &sys.demuxer, "|   |   |   + Track Overlay=%u", uint32( tovr ) );
        }
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#if LIBMATROSKA_VERSION >= 0x010401
        else if( MKV_IS_ID( l, KaxCodecDelay ) )
        {
            KaxCodecDelay &codecdelay = *(KaxCodecDelay*)l;
            tk->i_codec_delay = uint64_t( codecdelay ) / 1000;
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Codec Delay =%"PRIu64,
                     tk->i_codec_delay );
        }
        else if( MKV_IS_ID( l, KaxSeekPreRoll ) )
        {
            KaxSeekPreRoll &spr = *(KaxSeekPreRoll*)l;
            tk->i_seek_preroll = uint64_t(spr) / 1000;
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Seek Preroll =%"PRIu64, tk->i_seek_preroll );
        }
#endif
423
        else if( MKV_IS_ID( l, KaxContentEncodings ) )
424
        {
425
426
427
            EbmlMaster *cencs = static_cast<EbmlMaster*>(l);
            MkvTree( sys.demuxer, 3, "Content Encodings" );
            if ( cencs->ListSize() > 1 )
428
            {
429
430
                msg_Err( &sys.demuxer, "Multiple Compression method not supported" );
                bSupported = false;
431
            }
432
            for( size_t j = 0; j < cencs->ListSize(); j++ )
433
            {
434
435
436
437
438
                EbmlElement *l2 = (*cencs)[j];
                if( MKV_IS_ID( l2, KaxContentEncoding ) )
                {
                    MkvTree( sys.demuxer, 4, "Content Encoding" );
                    EbmlMaster *cenc = static_cast<EbmlMaster*>(l2);
439
                    for( size_t k = 0; k < cenc->ListSize(); k++ )
440
441
442
443
444
445
446
447
448
449
                    {
                        EbmlElement *l3 = (*cenc)[k];
                        if( MKV_IS_ID( l3, KaxContentEncodingOrder ) )
                        {
                            KaxContentEncodingOrder &encord = *(KaxContentEncodingOrder*)l3;
                            MkvTree( sys.demuxer, 5, "Order: %i", uint32( encord ) );
                        }
                        else if( MKV_IS_ID( l3, KaxContentEncodingScope ) )
                        {
                            KaxContentEncodingScope &encscope = *(KaxContentEncodingScope*)l3;
450
                            tk->i_encoding_scope = uint32( encscope );
451
452
453
454
455
456
457
458
459
460
461
                            MkvTree( sys.demuxer, 5, "Scope: %i", uint32( encscope ) );
                        }
                        else if( MKV_IS_ID( l3, KaxContentEncodingType ) )
                        {
                            KaxContentEncodingType &enctype = *(KaxContentEncodingType*)l3;
                            MkvTree( sys.demuxer, 5, "Type: %i", uint32( enctype ) );
                        }
                        else if( MKV_IS_ID( l3, KaxContentCompression ) )
                        {
                            EbmlMaster *compr = static_cast<EbmlMaster*>(l3);
                            MkvTree( sys.demuxer, 5, "Content Compression" );
462
463
                            //Default compression type is 0 (Zlib)
                            tk->i_compression_type = MATROSKA_COMPRESSION_ZLIB;
464
                            for( size_t n = 0; n < compr->ListSize(); n++ )
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
                            {
                                EbmlElement *l4 = (*compr)[n];
                                if( MKV_IS_ID( l4, KaxContentCompAlgo ) )
                                {
                                    KaxContentCompAlgo &compalg = *(KaxContentCompAlgo*)l4;
                                    MkvTree( sys.demuxer, 6, "Compression Algorithm: %i", uint32(compalg) );
                                    tk->i_compression_type = uint32( compalg );
                                    if ( ( tk->i_compression_type != MATROSKA_COMPRESSION_ZLIB ) &&
                                         ( tk->i_compression_type != MATROSKA_COMPRESSION_HEADER ) )
                                    {
                                        msg_Err( &sys.demuxer, "Track Compression method %d not supported", tk->i_compression_type );
                                        bSupported = false;
                                    }
                                }
                                else if( MKV_IS_ID( l4, KaxContentCompSettings ) )
                                {
                                    tk->p_compression_data = new KaxContentCompSettings( *(KaxContentCompSettings*)l4 );
                                }
                                else
                                {
                                    MkvTree( sys.demuxer, 6, "Unknown (%s)", typeid(*l4).name() );
                                }
                            }
                        }
489
                        // ContentEncryption Unsupported
490
491
492
493
494
495
496
497
498
499
                        else
                        {
                            MkvTree( sys.demuxer, 5, "Unknown (%s)", typeid(*l3).name() );
                        }
                    }
                }
                else
                {
                    MkvTree( sys.demuxer, 4, "Unknown (%s)", typeid(*l2).name() );
                }
500
501
            }
        }
Steve Lhomme's avatar
Steve Lhomme committed
502
//        else if( MKV_IS_ID( l, KaxCodecSettings) ) DEPRECATED by matroska
503
504
//        {
//            KaxCodecSettings &cset = *(KaxCodecSettings*)l;
505

506
507
508
//            tk->psz_codec_settings = ToUTF8( UTFstring( cset ) );
//            msg_Dbg( &sys.demuxer, "|   |   |   + Track Codec Settings=%s", tk->psz_codec_settings );
//        }
Steve Lhomme's avatar
Steve Lhomme committed
509
//        else if( MKV_IS_ID( l, KaxCodecInfoURL) ) DEPRECATED by matroska
510
511
//        {
//            KaxCodecInfoURL &ciurl = *(KaxCodecInfoURL*)l;
512

513
514
515
//            tk->psz_codec_info_url = strdup( string( ciurl ).c_str() );
//            msg_Dbg( &sys.demuxer, "|   |   |   + Track Codec Info URL=%s", tk->psz_codec_info_url );
//        }
Steve Lhomme's avatar
Steve Lhomme committed
516
//        else if( MKV_IS_ID( l, KaxCodecDownloadURL) ) DEPRECATED by matroska
517
518
//        {
//            KaxCodecDownloadURL &cdurl = *(KaxCodecDownloadURL*)l;
519

520
521
522
523
524
525
526
527
//            tk->psz_codec_download_url = strdup( string( cdurl ).c_str() );
//            msg_Dbg( &sys.demuxer, "|   |   |   + Track Codec Info URL=%s", tk->psz_codec_download_url );
//        }
        else  if( MKV_IS_ID( l, KaxTrackVideo ) )
        {
            EbmlMaster *tkv = static_cast<EbmlMaster*>(l);
            unsigned int i_crop_right = 0, i_crop_left = 0, i_crop_top = 0, i_crop_bottom = 0;
            unsigned int i_display_unit = 0, i_display_width = 0, i_display_height = 0;
528

529
530
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Video" );
            tk->f_fps = 0.0;
531

532
533
            tk->fmt.video.i_frame_rate_base = (unsigned int)(tk->i_default_duration / 1000);
            tk->fmt.video.i_frame_rate = 1000000;
534
535

            for( unsigned int j = 0; j < tkv->ListSize(); j++ )
536
            {
537
                EbmlElement *l = (*tkv)[j];
538
539
540
                if( MKV_IS_ID( l, KaxVideoFlagInterlaced ) ) // UNUSED
                {
                    KaxVideoFlagInterlaced &fint = *(KaxVideoFlagInterlaced*)l;
541

542
543
544
545
546
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + Track Video Interlaced=%u", uint8( fint ) );
                }
                else if( MKV_IS_ID( l, KaxVideoStereoMode ) ) // UNUSED
                {
                    KaxVideoStereoMode &stereo = *(KaxVideoStereoMode*)l;
547

548
549
550
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + Track Video Stereo Mode=%u", uint8( stereo ) );
                }
                else if( MKV_IS_ID( l, KaxVideoPixelWidth ) )
551
                {
552
553
554
555
                    KaxVideoPixelWidth &vwidth = *(KaxVideoPixelWidth*)l;

                    tk->fmt.video.i_width += uint16( vwidth );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + width=%d", uint16( vwidth ) );
556
                }
557
                else if( MKV_IS_ID( l, KaxVideoPixelHeight ) )
558
                {
559
560
561
562
                    KaxVideoPixelWidth &vheight = *(KaxVideoPixelWidth*)l;

                    tk->fmt.video.i_height += uint16( vheight );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + height=%d", uint16( vheight ) );
563
                }
564
565
566
                else if( MKV_IS_ID( l, KaxVideoDisplayWidth ) )
                {
                    KaxVideoDisplayWidth &vwidth = *(KaxVideoDisplayWidth*)l;
567

568
569
570
571
572
573
                    i_display_width = uint16( vwidth );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + display width=%d", uint16( vwidth ) );
                }
                else if( MKV_IS_ID( l, KaxVideoDisplayHeight ) )
                {
                    KaxVideoDisplayWidth &vheight = *(KaxVideoDisplayWidth*)l;
574

575
576
577
578
579
580
                    i_display_height = uint16( vheight );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + display height=%d", uint16( vheight ) );
                }
                else if( MKV_IS_ID( l, KaxVideoPixelCropBottom ) )
                {
                    KaxVideoPixelCropBottom &cropval = *(KaxVideoPixelCropBottom*)l;
581

582
583
584
585
586
587
                    i_crop_bottom = uint16( cropval );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + crop pixel bottom=%d", uint16( cropval ) );
                }
                else if( MKV_IS_ID( l, KaxVideoPixelCropTop ) )
                {
                    KaxVideoPixelCropTop &cropval = *(KaxVideoPixelCropTop*)l;
588

589
590
591
592
593
594
                    i_crop_top = uint16( cropval );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + crop pixel top=%d", uint16( cropval ) );
                }
                else if( MKV_IS_ID( l, KaxVideoPixelCropRight ) )
                {
                    KaxVideoPixelCropRight &cropval = *(KaxVideoPixelCropRight*)l;
595

596
597
598
599
600
601
                    i_crop_right = uint16( cropval );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + crop pixel right=%d", uint16( cropval ) );
                }
                else if( MKV_IS_ID( l, KaxVideoPixelCropLeft ) )
                {
                    KaxVideoPixelCropLeft &cropval = *(KaxVideoPixelCropLeft*)l;
602

603
604
605
                    i_crop_left = uint16( cropval );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + crop pixel left=%d", uint16( cropval ) );
                }
606
                else if( MKV_IS_ID( l, KaxVideoDisplayUnit ) )
607
608
                {
                    KaxVideoDisplayUnit &vdmode = *(KaxVideoDisplayUnit*)l;
609

610
611
                    i_display_unit = uint8( vdmode );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + Track Video Display Unit=%s",
612
                             i_display_unit == 0 ? "pixels" : ( i_display_unit == 1 ? "centimeters": "inches" ) );
613
                }
614
615
616
                else if( MKV_IS_ID( l, KaxVideoAspectRatio ) ) // UNUSED
                {
                    KaxVideoAspectRatio &ratio = *(KaxVideoAspectRatio*)l;
617

618
619
620
621
622
623
624
                    msg_Dbg( &sys.demuxer, "   |   |   |   + Track Video Aspect Ratio Type=%u", uint8( ratio ) );
                }
                // ColourSpace UNUSED
                else if( MKV_IS_ID( l, KaxVideoFrameRate ) )
                {
                    KaxVideoFrameRate &vfps = *(KaxVideoFrameRate*)l;

625
                    tk->f_fps = __MAX( float( vfps ), 1 );
626
627
                    msg_Dbg( &sys.demuxer, "   |   |   |   + fps=%f", float( vfps ) );
                }
Steve Lhomme's avatar
Steve Lhomme committed
628
//                else if( MKV_IS_ID( l, KaxVideoGamma) ) //DEPRECATED by Matroska
629
630
//                {
//                    KaxVideoGamma &gamma = *(KaxVideoGamma*)l;
631

632
633
634
635
636
637
638
639
//                    msg_Dbg( &sys.demuxer, "   |   |   |   + gamma=%f", float( gamma ) );
//                }
                else
                {
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + Unknown (%s)", typeid(*l).name() );
                }
            }
            if( i_display_height && i_display_width )
Laurent Aimar's avatar
Laurent Aimar committed
640
641
642
643
            {
                tk->fmt.video.i_sar_num = i_display_width  * tk->fmt.video.i_height;
                tk->fmt.video.i_sar_den = i_display_height * tk->fmt.video.i_width;
            }
644
645
            if( i_crop_left || i_crop_right || i_crop_top || i_crop_bottom )
            {
646
647
648
649
650
                tk->fmt.video.i_visible_width   = tk->fmt.video.i_width;
                tk->fmt.video.i_visible_height  = tk->fmt.video.i_height;
                tk->fmt.video.i_x_offset        = i_crop_left;
                tk->fmt.video.i_y_offset        = i_crop_top;
                tk->fmt.video.i_visible_width  -= i_crop_left + i_crop_right;
651
652
653
654
                tk->fmt.video.i_visible_height -= i_crop_top + i_crop_bottom;
            }
            /* FIXME: i_display_* allows you to not only set DAR, but also a zoom factor.
               we do not support this atm */
655
        }
656
        else  if( MKV_IS_ID( l, KaxTrackAudio ) )
657
        {
658
            EbmlMaster *tka = static_cast<EbmlMaster*>(l);
659

660
661
662
663
            /* Initialize default values */
            tk->fmt.audio.i_channels = 1;
            tk->fmt.audio.i_rate = 8000;

664
            msg_Dbg( &sys.demuxer, "|   |   |   + Track Audio" );
665

666
            for( unsigned int j = 0; j < tka->ListSize(); j++ )
667
            {
668
                EbmlElement *l = (*tka)[j];
669

670
671
672
                if( MKV_IS_ID( l, KaxAudioSamplingFreq ) )
                {
                    KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)l;
673

674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
                    tk->i_original_rate = tk->fmt.audio.i_rate = (int)float( afreq );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + afreq=%d", tk->fmt.audio.i_rate );
                }
                else if( MKV_IS_ID( l, KaxAudioOutputSamplingFreq ) )
                {
                    KaxAudioOutputSamplingFreq &afreq = *(KaxAudioOutputSamplingFreq*)l;

                    tk->fmt.audio.i_rate = (int)float( afreq );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + aoutfreq=%d", tk->fmt.audio.i_rate );
                }
                else if( MKV_IS_ID( l, KaxAudioChannels ) )
                {
                    KaxAudioChannels &achan = *(KaxAudioChannels*)l;

                    tk->fmt.audio.i_channels = uint8( achan );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + achan=%u", uint8( achan ) );
                }
                else if( MKV_IS_ID( l, KaxAudioBitDepth ) )
692
                {
693
694
695
696
                    KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)l;

                    tk->fmt.audio.i_bitspersample = uint8( abits );
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + abits=%u", uint8( abits ) );
697
                }
698
                else
699
                {
700
                    msg_Dbg( &sys.demuxer, "|   |   |   |   + Unknown (%s)", typeid(*l).name() );
701
702
703
                }
            }
        }
704
705
706
707
708
        else
        {
            msg_Dbg( &sys.demuxer, "|   |   |   + Unknown (%s)",
                     typeid(*l).name() );
        }
709
710
    }

711
    if ( bSupported )
712
    {
713
714
715
716
717
718
719
#ifdef HAVE_ZLIB_H
        if( tk->i_compression_type == MATROSKA_COMPRESSION_ZLIB &&
            tk->i_encoding_scope & MATROSKA_ENCODING_SCOPE_PRIVATE &&
            tk->i_extra_data && tk->p_extra_data &&
            zlib_decompress_extra( &sys.demuxer, tk) )
            return;
#endif
720
721
722
723
724
725
726
        if( TrackInit( tk ) )
        {
            msg_Err(&sys.demuxer, "Couldn't init track %d", tk->i_number );
            free(tk->p_extra_data);
            delete tk;
            return;
        }
727

728
729
730
731
732
        tracks.push_back( tk );
    }
    else
    {
        msg_Err( &sys.demuxer, "Track Entry %d not supported", tk->i_number );
733
        free(tk->p_extra_data);
734
        delete tk;
735
736
737
    }
}

738
739
740
741
/*****************************************************************************
 * ParseTracks:
 *****************************************************************************/
void matroska_segment_c::ParseTracks( KaxTracks *tracks )
742
{
743
744
745
746
    EbmlElement *el;
    int i_upper_level = 0;

    /* Master elements */
747
748
749
750
751
    if( unlikely( tracks->GetSize() >= SIZE_MAX ) )
    {
        msg_Err( &sys.demuxer, "Track too big, aborting" );
        return;
    }
752
753
754
755
756
757
758
759
760
    try
    {
        tracks->Read( es, EBML_CONTEXT(tracks), i_upper_level, el, true );
    }
    catch(...)
    {
        msg_Err( &sys.demuxer, "Couldn't read tracks" );
        return;
    }
761

762
    for( size_t i = 0; i < tracks->ListSize(); i++ )
763
    {
764
        EbmlElement *l = (*tracks)[i];
765

766
        if( MKV_IS_ID( l, KaxTrackEntry ) )
767
        {
768
769
770
771
772
            ParseTrackEntry( static_cast<KaxTrackEntry *>(l) );
        }
        else
        {
            msg_Dbg( &sys.demuxer, "|   |   + Unknown (%s)", typeid(*l).name() );
773
774
775
776
        }
    }
}

777
778
779
780
/*****************************************************************************
 * ParseInfo:
 *****************************************************************************/
void matroska_segment_c::ParseInfo( KaxInfo *info )
781
{
782
783
784
785
786
787
    EbmlElement *el;
    EbmlMaster  *m;
    int i_upper_level = 0;

    /* Master elements */
    m = static_cast<EbmlMaster *>(info);
788
789
790
791
792
    if( unlikely( m->GetSize() >= SIZE_MAX ) )
    {
        msg_Err( &sys.demuxer, "Info too big, aborting" );
        return;
    }
793
794
795
796
797
798
799
800
801
    try
    {
        m->Read( es, EBML_CONTEXT(info), i_upper_level, el, true );
    }
    catch(...)
    {
        msg_Err( &sys.demuxer, "Couldn't read info" );
        return;
    }   
802

803
    for( size_t i = 0; i < m->ListSize(); i++ )
804
805
806
807
808
809
810
811
812
813
814
815
816
    {
        EbmlElement *l = (*m)[i];

        if( MKV_IS_ID( l, KaxSegmentUID ) )
        {
            if ( p_segment_uid == NULL )
                p_segment_uid = new KaxSegmentUID(*static_cast<KaxSegmentUID*>(l));

            msg_Dbg( &sys.demuxer, "|   |   + UID=%d", *(uint32*)p_segment_uid->GetBuffer() );
        }
        else if( MKV_IS_ID( l, KaxPrevUID ) )
        {
            if ( p_prev_segment_uid == NULL )
817
            {
818
                p_prev_segment_uid = new KaxPrevUID(*static_cast<KaxPrevUID*>(l));
819
820
                b_ref_external_segments = true;
            }
821

822
            msg_Dbg( &sys.demuxer, "|   |   + PrevUID=%d", *(uint32*)p_prev_segment_uid->GetBuffer() );
823
        }
824
        else if( MKV_IS_ID( l, KaxNextUID ) )
825
        {
826
            if ( p_next_segment_uid == NULL )
827
            {
828
                p_next_segment_uid = new KaxNextUID(*static_cast<KaxNextUID*>(l));
829
830
                b_ref_external_segments = true;
            }
831

832
833
834
835
836
            msg_Dbg( &sys.demuxer, "|   |   + NextUID=%d", *(uint32*)p_next_segment_uid->GetBuffer() );
        }
        else if( MKV_IS_ID( l, KaxTimecodeScale ) )
        {
            KaxTimecodeScale &tcs = *(KaxTimecodeScale*)l;
837

838
            i_timescale = uint64(tcs);
839

840
841
842
843
844
845
            msg_Dbg( &sys.demuxer, "|   |   + TimecodeScale=%"PRId64,
                     i_timescale );
        }
        else if( MKV_IS_ID( l, KaxDuration ) )
        {
            KaxDuration &dur = *(KaxDuration*)l;
846

847
            i_duration = mtime_t( double( dur ) );
848

849
850
851
852
853
854
            msg_Dbg( &sys.demuxer, "|   |   + Duration=%"PRId64,
                     i_duration );
        }
        else if( MKV_IS_ID( l, KaxMuxingApp ) )
        {
            KaxMuxingApp &mapp = *(KaxMuxingApp*)l;
855

856
            psz_muxing_application = ToUTF8( UTFstring( mapp ) );
857

858
859
            msg_Dbg( &sys.demuxer, "|   |   + Muxing Application=%s",
                     psz_muxing_application );
860
        }
861
862
863
        else if( MKV_IS_ID( l, KaxWritingApp ) )
        {
            KaxWritingApp &wapp = *(KaxWritingApp*)l;
864

865
            psz_writing_application = ToUTF8( UTFstring( wapp ) );
866

867
868
            msg_Dbg( &sys.demuxer, "|   |   + Writing Application=%s",
                     psz_writing_application );
869
        }
870
871
872
        else if( MKV_IS_ID( l, KaxSegmentFilename ) )
        {
            KaxSegmentFilename &sfn = *(KaxSegmentFilename*)l;
873

874
            psz_segment_filename = ToUTF8( UTFstring( sfn ) );
875

876
877
            msg_Dbg( &sys.demuxer, "|   |   + Segment Filename=%s",
                     psz_segment_filename );
878
        }
879
880
881
        else if( MKV_IS_ID( l, KaxTitle ) )
        {
            KaxTitle &title = *(KaxTitle*)l;
882

883
            psz_title = ToUTF8( UTFstring( title ) );
884

885
            msg_Dbg( &sys.demuxer, "|   |   + Title=%s", psz_title );
886
        }
887
888
889
        else if( MKV_IS_ID( l, KaxSegmentFamily ) )
        {
            KaxSegmentFamily *uid = static_cast<KaxSegmentFamily*>(l);
890

891
            families.push_back( new KaxSegmentFamily(*uid) );
892

893
894
895
896
897
898
899
            msg_Dbg( &sys.demuxer, "|   |   + family=%d", *(uint32*)uid->GetBuffer() );
        }
        else if( MKV_IS_ID( l, KaxDateUTC ) )
        {
            KaxDateUTC &date = *(KaxDateUTC*)l;
            time_t i_date;
            struct tm tmres;
900
            char   buffer[25];
901

902
903
            i_date = date.GetEpochDate();
            if( gmtime_r( &i_date, &tmres ) &&
904
905
                strftime( buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y",
                          &tmres ) )
906
907
            {
                psz_date_utc = strdup( buffer );
908
                msg_Dbg( &sys.demuxer, "|   |   + Date=%s", buffer );
909
910
911
            }
        }
        else if( MKV_IS_ID( l, KaxChapterTranslate ) )
912
        {
913
            KaxChapterTranslate *p_trans = static_cast<KaxChapterTranslate*>( l );
914
            try
915
            {
916
917
918
919
920
921
                if( unlikely( p_trans->GetSize() >= SIZE_MAX ) )
                {
                    msg_Err( &sys.demuxer, "Chapter translate too big, aborting" );
                    continue;
                }

922
923
                p_trans->Read( es, EBML_CONTEXT(p_trans), i_upper_level, el, true );
                chapter_translation_c *p_translate = new chapter_translation_c();
924

925
                for( size_t j = 0; j < p_trans->ListSize(); j++ )
926
                {
927
928
929
930
931
932
933
934
935
936
937
938
939
940
                    EbmlElement *l = (*p_trans)[j];

                    if( MKV_IS_ID( l, KaxChapterTranslateEditionUID ) )
                    {
                        p_translate->editions.push_back( uint64( *static_cast<KaxChapterTranslateEditionUID*>( l ) ) );
                    }
                    else if( MKV_IS_ID( l, KaxChapterTranslateCodec ) )
                    {
                        p_translate->codec_id = uint32( *static_cast<KaxChapterTranslateCodec*>( l ) );
                    }
                    else if( MKV_IS_ID( l, KaxChapterTranslateID ) )
                    {
                        p_translate->p_translated = new KaxChapterTranslateID( *static_cast<KaxChapterTranslateID*>( l ) );
                    }
941
942
                }

943
944
945
946
947
948
                translations.push_back( p_translate );
            }
            catch(...)
            {
                msg_Err( &sys.demuxer, "Error while reading Chapter Tranlate");
            }
949
        }
950
        else
951
        {
952
            msg_Dbg( &sys.demuxer, "|   |   + Unknown (%s)", typeid(*l).name() );
953
954
        }
    }
955
956
957

    double f_dur = double(i_duration) * double(i_timescale) / 1000000.0;
    i_duration = mtime_t(f_dur);
958
    if( !i_duration ) i_duration = -1;
959
960
961
}


962
963
964
965
966
967
/*****************************************************************************
 * ParseChapterAtom
 *****************************************************************************/
void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters )
{
    msg_Dbg( &sys.demuxer, "|   |   |   + ChapterAtom (level=%d)", i_level );
968
    for( size_t i = 0; i < ca->ListSize(); i++ )
969
    {
970
        EbmlElement *l = (*ca)[i];
971

972
        if( MKV_IS_ID( l, KaxChapterUID ) )
973
        {
974
            chapters.i_uid = uint64_t(*(KaxChapterUID*)l);
975
            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterUID: %"PRIu64"", chapters.i_uid );
976
        }
977
        else if( MKV_IS_ID( l, KaxChapterFlagHidden ) )
978
        {
979
980
981
982
            KaxChapterFlagHidden &flag =*(KaxChapterFlagHidden*)l;
            chapters.b_display_seekpoint = uint8( flag ) == 0;

            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterFlagHidden: %s", chapters.b_display_seekpoint ? "no":"yes" );
983
        }
Denis Charmet's avatar
Denis Charmet committed
984
985
986
        else if( MKV_IS_ID( l, KaxChapterSegmentUID ) )
        {
            chapters.p_segment_uid = new KaxChapterSegmentUID( *static_cast<KaxChapterSegmentUID*>(l) );
987
            b_ref_external_segments = true;
Denis Charmet's avatar
Denis Charmet committed
988
989
990
991
992
            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterSegmentUID= %u", *(uint32*)chapters.p_segment_uid->GetBuffer() );
        }
        else if( MKV_IS_ID( l, KaxChapterSegmentEditionUID ) )
        {
            chapters.p_segment_edition_uid = new KaxChapterSegmentEditionUID( *static_cast<KaxChapterSegmentEditionUID*>(l) );
993
994
            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterSegmentEditionUID= %u",
#if LIBMATROSKA_VERSION < 0x010300
995
                     *(uint32*)chapters.p_segment_edition_uid->GetBuffer()
996
#else
997
                     *(uint32*)chapters.p_segment_edition_uid
998
#endif
999
                   );
Denis Charmet's avatar
Denis Charmet committed
1000
        }
1001
        else if( MKV_IS_ID( l, KaxChapterTimeStart ) )
1002
        {
1003
1004
            KaxChapterTimeStart &start =*(KaxChapterTimeStart*)l;
            chapters.i_start_time = uint64( start ) / INT64_C(1000);
1005

1006
            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterTimeStart: %"PRId64"", chapters.i_start_time );
1007
        }
1008
        else if( MKV_IS_ID( l, KaxChapterTimeEnd ) )
1009
        {
1010
1011
1012
            KaxChapterTimeEnd &end =*(KaxChapterTimeEnd*)l;
            chapters.i_end_time = uint64( end ) / INT64_C(1000);

1013
            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterTimeEnd: %"PRId64"", chapters.i_end_time );
1014
        }
1015
        else if( MKV_IS_ID( l, KaxChapterDisplay ) )
1016
        {
1017
            EbmlMaster *cd =