annotate libmpdemux/demux_mkv.c @ 13361:c9d84342971f

10l
author faust3
date Fri, 17 Sep 2004 10:37:56 +0000
parents dcbdd8ea356d
children 8db5683d2b3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1 /*
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2 * native Matroska demuxer
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3 * Written by Aurelien Jacobs <aurel@gnuage.org>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
4 * Based on the one written by Ronald Bultje for gstreamer
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
5 * and on demux_mkv.cpp from Moritz Bunkus.
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
6 * Licence: GPL
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
7 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
8
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
9 #include "config.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
10 #ifdef HAVE_MATROSKA
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
11
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
12 #include <stdlib.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
13 #include <stdio.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
14 #include <ctype.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
15
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
16 #include "stream.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
17 #include "demuxer.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
18 #include "stheader.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
19 #include "ebml.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
20 #include "matroska.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
21 #include "bswap.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
22
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
23 #include "../subreader.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
24 #include "../libvo/sub.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
25
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
26 #ifdef USE_QTX_CODECS
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
27 #include "qtx/qtxsdk/components.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
28 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
29
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
30 #ifdef HAVE_ZLIB
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
31 #include <zlib.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
32 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
33
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
34 #ifdef USE_LIBLZO
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
35 #include <lzo1x.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
36 #else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
37 #include "../libmpcodecs/native/minilzo.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
38 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
39
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
40 #if !defined(MIN)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
41 #define MIN(a, b) ((a)<(b)?(a):(b))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
42 #endif
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
43 #if !defined(MAX)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
44 #define MAX(a, b) ((a)>(b)?(a):(b))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
45 #endif
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
46
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
47 typedef struct
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
48 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
49 uint32_t order, type, scope;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
50 uint32_t comp_algo;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
51 uint8_t *comp_settings;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
52 int comp_settings_len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
53 } mkv_content_encoding_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
54
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
55 typedef struct mkv_track
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
56 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
57 int tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
58
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
59 char *codec_id;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
60 int ms_compat;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
61 char *language;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
62
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
63 int type;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
64
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
65 uint32_t v_width, v_height, v_dwidth, v_dheight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
66 float v_frate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
67
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
68 uint32_t a_formattag;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
69 uint32_t a_channels, a_bps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
70 float a_sfreq;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
71
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
72 float default_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
73
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
74 int default_track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
75
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
76 void *private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
77 unsigned int private_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
78
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
79 /* for vorbis audio */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
80 unsigned char *headers[3];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
81 uint32_t header_sizes[3];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
82
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
83 /* stuff for realmedia */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
84 int realmedia;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
85 int rv_kf_base, rv_kf_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
86 float rv_pts; /* previous video timestamp */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
87 float ra_pts; /* previous audio timestamp */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
88
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
89 /* stuff for quicktime */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
90 int fix_i_bps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
91 float qt_last_a_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
92
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
93 int subtitle_type;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
94
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
95 /* generic content encoding support */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
96 mkv_content_encoding_t *encodings;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
97 int num_encodings;
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
98
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
99 /* For VobSubs */
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
100 mkv_sh_sub_t sh_sub;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
101 } mkv_track_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
102
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
103 typedef struct mkv_index
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
104 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
105 int tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
106 uint64_t timecode, filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
107 } mkv_index_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
108
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
109 typedef struct mkv_chapter
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
110 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
111 uint64_t start, end;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
112 } mkv_chapter_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
113
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
114 typedef struct mkv_demuxer
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
115 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
116 off_t segment_start;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
117
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
118 float duration, last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
119 uint64_t last_filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
120
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
121 mkv_track_t **tracks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
122 int num_tracks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
123
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
124 uint64_t tc_scale, cluster_tc, first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
125 int has_first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
126
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
127 uint64_t clear_subs_at[SUB_MAX_TEXT];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
128 subtitle subs;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
129
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
130 uint64_t cluster_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
131 uint64_t blockgroup_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
132
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
133 mkv_index_t *indexes;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
134 int num_indexes;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
135
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
136 off_t *parsed_cues;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
137 int parsed_cues_num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
138 off_t *parsed_seekhead;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
139 int parsed_seekhead_num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
140
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
141 uint64_t *cluster_positions;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
142 int num_cluster_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
143
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
144 int64_t skip_to_timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
145 int v_skip_to_keyframe, a_skip_to_keyframe;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
146
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
147 mkv_chapter_t *chapters;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
148 int num_chapters;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
149 int64_t stop_timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
150 } mkv_demuxer_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
151
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
152
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
153 typedef struct
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
154 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
155 uint32_t chunks; /* number of chunks */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
156 uint32_t timestamp; /* timestamp from packet header */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
157 uint32_t len; /* length of actual data */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
158 uint32_t chunktab; /* offset to chunk offset array */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
159 } dp_hdr_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
160
11815
0fa6f4fcfcbb Compiler/system compatibility fixes.
mosu
parents: 11812
diff changeset
161 typedef struct __attribute__((__packed__))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
162 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
163 uint32_t size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
164 uint32_t fourcc1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
165 uint32_t fourcc2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
166 uint16_t width;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
167 uint16_t height;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
168 uint16_t bpp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
169 uint32_t unknown1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
170 uint32_t fps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
171 uint32_t type1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
172 uint32_t type2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
173 } real_video_props_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
174
11815
0fa6f4fcfcbb Compiler/system compatibility fixes.
mosu
parents: 11812
diff changeset
175 typedef struct __attribute__((__packed__))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
176 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
177 uint32_t fourcc1; /* '.', 'r', 'a', 0xfd */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
178 uint16_t version1; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
179 uint16_t unknown1; /* 00 000 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
180 uint32_t fourcc2; /* .ra4 or .ra5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
181 uint32_t unknown2; /* ??? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
182 uint16_t version2; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
183 uint32_t header_size; /* == 0x4e */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
184 uint16_t flavor; /* codec flavor id */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
185 uint32_t coded_frame_size; /* coded frame size */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
186 uint32_t unknown3; /* big number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
187 uint32_t unknown4; /* bigger number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
188 uint32_t unknown5; /* yet another number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
189 uint16_t sub_packet_h;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
190 uint16_t frame_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
191 uint16_t sub_packet_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
192 uint16_t unknown6; /* 00 00 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
193 uint16_t sample_rate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
194 uint16_t unknown8; /* 0 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
195 uint16_t sample_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
196 uint16_t channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
197 } real_audio_v4_props_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
198
11815
0fa6f4fcfcbb Compiler/system compatibility fixes.
mosu
parents: 11812
diff changeset
199 typedef struct __attribute__((__packed__))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
200 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
201 uint32_t fourcc1; /* '.', 'r', 'a', 0xfd */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
202 uint16_t version1; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
203 uint16_t unknown1; /* 00 000 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
204 uint32_t fourcc2; /* .ra4 or .ra5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
205 uint32_t unknown2; /* ??? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
206 uint16_t version2; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
207 uint32_t header_size; /* == 0x4e */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
208 uint16_t flavor; /* codec flavor id */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
209 uint32_t coded_frame_size; /* coded frame size */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
210 uint32_t unknown3; /* big number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
211 uint32_t unknown4; /* bigger number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
212 uint32_t unknown5; /* yet another number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
213 uint16_t sub_packet_h;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
214 uint16_t frame_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
215 uint16_t sub_packet_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
216 uint16_t unknown6; /* 00 00 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
217 uint8_t unknown7[6]; /* 0, srate, 0 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
218 uint16_t sample_rate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
219 uint16_t unknown8; /* 0 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
220 uint16_t sample_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
221 uint16_t channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
222 uint32_t genr; /* "genr" */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
223 uint32_t fourcc3; /* fourcc */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
224 } real_audio_v5_props_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
225
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
226
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
227 /* for e.g. "-slang ger" */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
228 extern char *dvdsub_lang;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
229 extern char *audio_lang;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
230
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
231
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
232 static mkv_track_t *
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
233 demux_mkv_find_track_by_num (mkv_demuxer_t *d, int n, int type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
234 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
235 int i, id;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
236
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
237 for (i=0, id=0; i < d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
238 if (d->tracks[i] != NULL && d->tracks[i]->type == type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
239 if (id++ == n)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
240 return d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
241
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
242 return NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
243 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
244
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
245 static mkv_track_t *
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
246 demux_mkv_find_track_by_language (mkv_demuxer_t *d, char *language, int type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
247 {
12041
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
248 int i, len;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
249
12041
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
250 language += strspn(language,",");
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
251 while((len = strcspn(language,",")) > 0)
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
252 {
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
253 for (i=0; i < d->num_tracks; i++)
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
254 if (d->tracks[i] != NULL && d->tracks[i]->language != NULL &&
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
255 d->tracks[i]->type == type &&
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
256 !strncmp(d->tracks[i]->language, language, len))
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
257 return d->tracks[i];
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
258 language += len;
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
259 language += strspn(language,",");
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
260 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
261
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
262 return NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
263 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
264
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
265 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
266 add_cluster_position (mkv_demuxer_t *mkv_d, uint64_t position)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
267 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
268 int i = mkv_d->num_cluster_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
269
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
270 while (i--)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
271 if (mkv_d->cluster_positions[i] == position)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
272 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
273
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
274 if (!mkv_d->cluster_positions)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
275 mkv_d->cluster_positions = (uint64_t *) malloc (32 * sizeof (uint64_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
276 else if (!(mkv_d->num_cluster_pos % 32))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
277 mkv_d->cluster_positions = (uint64_t *) realloc(mkv_d->cluster_positions,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
278 (mkv_d->num_cluster_pos+32)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
279 * sizeof (uint64_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
280 mkv_d->cluster_positions[mkv_d->num_cluster_pos++] = position;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
281 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
282
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
283
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
284 #define AAC_SYNC_EXTENSION_TYPE 0x02b7
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
285 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
286 aac_get_sample_rate_index (uint32_t sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
287 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
288 if (92017 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
289 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
290 else if (75132 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
291 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
292 else if (55426 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
293 return 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
294 else if (46009 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
295 return 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
296 else if (37566 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
297 return 4;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
298 else if (27713 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
299 return 5;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
300 else if (23004 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
301 return 6;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
302 else if (18783 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
303 return 7;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
304 else if (13856 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
305 return 8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
306 else if (11502 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
307 return 9;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
308 else if (9391 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
309 return 10;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
310 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
311 return 11;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
312 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
313
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
314
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
315 static int
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
316 vobsub_parse_size (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
317 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
318 if (sscanf(&start[6], "%dx%d", &t->sh_sub.width, &t->sh_sub.height) == 2)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
319 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
320 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub size: %ux%u\n",
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
321 t->sh_sub.width, t->sh_sub.height);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
322 return 1;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
323 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
324 return 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
325 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
326
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
327 static int
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
328 vobsub_parse_palette (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
329 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
330 int i, r, g, b, y, u, v, tmp;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
331
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
332 start += 8;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
333 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
334 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
335 for (i = 0; i < 16; i++)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
336 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
337 if (sscanf(start, "%06x", &tmp) != 1)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
338 break;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
339 r = tmp >> 16 & 0xff;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
340 g = tmp >> 8 & 0xff;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
341 b = tmp & 0xff;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
342 y = MIN(MAX((int)(0.1494 * r + 0.6061 * g + 0.2445 * b), 0),
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
343 0xff);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
344 u = MIN(MAX((int)(0.6066 * r - 0.4322 * g - 0.1744 * b) + 128,
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
345 0), 0xff);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
346 v = MIN(MAX((int)(-0.08435 * r - 0.3422 * g + 0.4266 * b) +
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
347 128, 0), 0xff);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
348 t->sh_sub.palette[i] = y << 16 | u << 8 | v;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
349 start += 6;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
350 while ((*start == ',') || isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
351 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
352 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
353 if (i == 16)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
354 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
355 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub palette: %06x,%06x,"
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
356 "%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,"
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
357 "%06x,%06x,%06x\n", t->sh_sub.palette[0],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
358 t->sh_sub.palette[1], t->sh_sub.palette[2],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
359 t->sh_sub.palette[3], t->sh_sub.palette[4],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
360 t->sh_sub.palette[5], t->sh_sub.palette[6],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
361 t->sh_sub.palette[7], t->sh_sub.palette[8],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
362 t->sh_sub.palette[9], t->sh_sub.palette[10],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
363 t->sh_sub.palette[11], t->sh_sub.palette[12],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
364 t->sh_sub.palette[13], t->sh_sub.palette[14],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
365 t->sh_sub.palette[15]);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
366 return 2;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
367 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
368 return 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
369 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
370
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
371 static int
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
372 vobsub_parse_custom_colors (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
373 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
374 int use_custom_colors, i;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
375
13131
ab937f4a17ad Cosmetics: fix some compiler warnings.
mosu
parents: 13129
diff changeset
376 use_custom_colors = 0;
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
377 start += 14;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
378 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
379 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
380 if (!strncasecmp(start, "ON", 2) || (*start == '1'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
381 use_custom_colors = 1;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
382 else if (!strncasecmp(start, "OFF", 3) || (*start == '0'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
383 use_custom_colors = 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
384 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub custom colors: %s\n",
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
385 use_custom_colors ? "ON" : "OFF");
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
386 if ((start = strstr(start, "colors:")) != NULL)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
387 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
388 start += 7;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
389 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
390 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
391 for (i = 0; i < 4; i++)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
392 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
393 if (sscanf(start, "%06x", &t->sh_sub.colors[i]) != 1)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
394 break;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
395 start += 6;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
396 while ((*start == ',') || isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
397 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
398 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
399 if (i == 4)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
400 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
401 t->sh_sub.custom_colors = 4;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
402 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub colors: %06x,"
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
403 "%06x,%06x,%06x\n", t->sh_sub.colors[0],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
404 t->sh_sub.colors[1], t->sh_sub.colors[2],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
405 t->sh_sub.colors[3]);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
406 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
407 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
408 if (!use_custom_colors)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
409 t->sh_sub.custom_colors = 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
410 return 4;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
411 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
412
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
413 static int
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
414 vobsub_parse_forced_subs (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
415 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
416 start += 12;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
417 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
418 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
419 if (!strncasecmp(start, "on", 2) || (*start == '1'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
420 t->sh_sub.forced_subs_only = 1;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
421 else if (!strncasecmp(start, "off", 3) || (*start == '0'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
422 t->sh_sub.forced_subs_only = 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
423 else
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
424 return 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
425 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub forced subs: %d\n",
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
426 t->sh_sub.forced_subs_only);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
427 return 8;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
428 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
429
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
430 static int
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
431 demux_mkv_parse_idx (mkv_track_t *t)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
432 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
433 int things_found, last;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
434 char *buf, *pos, *start;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
435
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
436 if ((t->private_data == NULL) || (t->private_size == 0))
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
437 return 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
438
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
439 things_found = 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
440 buf = (char *)malloc(t->private_size + 1);
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
441 if (buf == NULL)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
442 return 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
443 memcpy(buf, t->private_data, t->private_size);
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
444 buf[t->private_size] = 0;
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
445 t->sh_sub.type = 'v';
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
446
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
447 pos = buf;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
448 start = buf;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
449 last = 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
450 do
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
451 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
452 if ((*pos == 0) || (*pos == '\r') || (*pos == '\n'))
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
453 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
454 if (*pos == 0)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
455 last = 1;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
456 *pos = 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
457
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
458 if (!strncasecmp(start, "size: ", 6))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
459 things_found |= vobsub_parse_size(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
460 else if (!strncasecmp(start, "palette:", 8))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
461 things_found |= vobsub_parse_palette(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
462 else if (!strncasecmp(start, "custom colors:", 14))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
463 things_found |= vobsub_parse_custom_colors(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
464 else if (!strncasecmp(start, "forced subs:", 12))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
465 things_found |= vobsub_parse_forced_subs(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
466
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
467 if (last)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
468 break;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
469 do
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
470 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
471 pos++;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
472 }
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
473 while ((*pos == '\r') || (*pos == '\n'));
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
474 start = pos;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
475 }
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
476 else
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
477 pos++;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
478 }
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
479 while (!last && (*start != 0));
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
480
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
481 free(buf);
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
482
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
483 return (things_found & 3) == 3;
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
484 }
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
485
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
486
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
487 static int
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
488 demux_mkv_decode (mkv_track_t *track, uint8_t *src, uint8_t **dest,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
489 uint32_t *size, uint32_t type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
490 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
491 int i, result;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
492 int modified = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
493
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
494 *dest = src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
495 if (track->num_encodings <= 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
496 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
497
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
498 for (i=0; i<track->num_encodings; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
499 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
500 if (!(track->encodings[i].scope & type))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
501 continue;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
502
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
503 #ifdef HAVE_ZLIB
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
504 if (track->encodings[i].comp_algo == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
505 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
506 /* zlib encoded track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
507 z_stream zstream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
508
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
509 zstream.zalloc = (alloc_func) 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
510 zstream.zfree = (free_func) 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
511 zstream.opaque = (voidpf) 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
512 if (inflateInit (&zstream) != Z_OK)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
513 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
514 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
515 "[mkv] zlib initialization failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
516 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
517 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
518 zstream.next_in = (Bytef *) src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
519 zstream.avail_in = *size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
520
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
521 modified = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
522 *dest = (uint8_t *) malloc (*size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
523 zstream.avail_out = *size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
524 do {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
525 *size += 4000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
526 *dest = (uint8_t *) realloc (*dest, *size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
527 zstream.next_out = (Bytef *) (*dest + zstream.total_out);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
528 result = inflate (&zstream, Z_NO_FLUSH);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
529 if (result != Z_OK && result != Z_STREAM_END)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
530 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
531 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
532 "[mkv] zlib decompression failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
533 free(*dest);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
534 *dest = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
535 inflateEnd (&zstream);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
536 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
537 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
538 zstream.avail_out += 4000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
539 } while (zstream.avail_out == 4000 &&
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
540 zstream.avail_in != 0 && result != Z_STREAM_END);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
541
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
542 *size = zstream.total_out;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
543 inflateEnd (&zstream);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
544 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
545 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
546 if (track->encodings[i].comp_algo == 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
547 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
548 /* lzo encoded track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
549 int dstlen = *size * 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
550
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
551 if (lzo_init () != LZO_E_OK)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
552 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
553 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
554 "[mkv] lzo initialization failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
555 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
556 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
557
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
558 *dest = (uint8_t *) malloc (dstlen);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
559 while (1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
560 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
561 result = lzo1x_decompress_safe (src, *size, *dest, &dstlen,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
562 NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
563 if (result == LZO_E_OK)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
564 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
565 if (result != LZO_E_OUTPUT_OVERRUN)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
566 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
567 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
568 "[mkv] lzo decompression failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
569 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
570 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
571 mp_msg (MSGT_DEMUX, MSGL_DBG2,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
572 "[mkv] lzo decompression buffer too small.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
573 dstlen *= 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
574 *dest = (uint8_t *) realloc (*dest, dstlen);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
575 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
576 *size = dstlen;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
577 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
578 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
579
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
580 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
581 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
582
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
583
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
584 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
585 demux_mkv_read_info (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
586 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
587 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
588 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
589 uint64_t length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
590 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
591
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
592 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
593 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
594 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
595 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
596 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
597 case MATROSKA_ID_TIMECODESCALE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
598 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
599 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
600 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
601 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
602 mkv_d->tc_scale = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
603 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + timecode scale: %llu\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
604 mkv_d->tc_scale);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
605 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
606 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
607
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
608 case MATROSKA_ID_DURATION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
609 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
610 long double num = ebml_read_float (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
611 if (num == EBML_FLOAT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
612 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
613 mkv_d->duration = num * mkv_d->tc_scale / 1000000000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
614 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3fs\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
615 mkv_d->duration);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
616 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
617 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
618
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
619 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
620 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
621 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
622 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
623 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
624 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
625 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
626 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
627
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
628 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
629 demux_mkv_read_trackencodings (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
630 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
631 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
632 mkv_content_encoding_t *ce, e;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
633 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
634 int il, n;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
635
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
636 ce = (mkv_content_encoding_t *) malloc (sizeof (*ce));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
637 n = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
638
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
639 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
640 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
641 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
642 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
643 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
644 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
645 case MATROSKA_ID_CONTENTENCODING:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
646 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
647 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
648 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
649
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
650 memset (&e, 0, sizeof (e));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
651 e.scope = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
652
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
653 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
654 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
655
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
656 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
657 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
658 uint64_t num, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
659 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
660
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
661 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
662 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
663 case MATROSKA_ID_CONTENTENCODINGORDER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
664 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
665 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
666 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
667 e.order = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
668 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
669
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
670 case MATROSKA_ID_CONTENTENCODINGSCOPE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
671 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
672 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
673 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
674 e.scope = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
675 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
676
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
677 case MATROSKA_ID_CONTENTENCODINGTYPE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
678 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
679 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
680 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
681 e.type = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
682 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
683
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
684 case MATROSKA_ID_CONTENTCOMPRESSION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
685 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
686 uint64_t le;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
687
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
688 le = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
689 l = le + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
690
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
691 while (le > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
692 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
693 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
694 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
695
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
696 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
697 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
698 case MATROSKA_ID_CONTENTCOMPALGO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
699 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
700 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
701 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
702 e.comp_algo = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
703 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
704
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
705 case MATROSKA_ID_CONTENTCOMPSETTINGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
706 l = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
707 e.comp_settings = (uint8_t *) malloc (l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
708 stream_read (s, e.comp_settings, l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
709 e.comp_settings_len = l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
710 l += i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
711 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
712
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
713 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
714 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
715 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
716 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
717 le -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
718 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
719
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
720 if (e.type == 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
721 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
722 mp_msg(MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
723 "[mkv] Track number %u has been encrypted "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
724 "and decryption has not yet been implemented."
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
725 " Skipping track.\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
726 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
727 else if (e.type != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
728 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
729 mp_msg(MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
730 "[mkv] Unknown content encoding type for "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
731 "track %u. Skipping track.\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
732 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
733
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
734 if (e.comp_algo != 0 && e.comp_algo != 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
735 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
736 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
737 "[mkv] Track %u has been compressed with an "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
738 "unknown/unsupported compression algorithm "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
739 "(%u). Skipping track.\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
740 track->tnum, e.comp_algo);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
741 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
742 #ifndef HAVE_ZLIB
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
743 else if (e.comp_algo == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
744 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
745 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
746 "Track %u was compressed with zlib but "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
747 "mplayer has not been compiled with support "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
748 "for zlib compression. Skipping track.\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
749 track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
750 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
751 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
752
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
753 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
754 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
755
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
756 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
757 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
758 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
759 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
760 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
761 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
762 for (i=0; i<n; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
763 if (e.order <= ce[i].order)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
764 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
765 ce = (mkv_content_encoding_t *) realloc (ce, (n+1) *sizeof (*ce));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
766 memmove (ce+i+1, ce+i, (n-i) * sizeof (*ce));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
767 memcpy (ce+i, &e, sizeof (e));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
768 n++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
769 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
770 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
771
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
772 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
773 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
774 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
775 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
776
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
777 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
778 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
779
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
780 track->encodings = ce;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
781 track->num_encodings = n;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
782 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
783 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
784
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
785 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
786 demux_mkv_read_trackaudio (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
787 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
788 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
789 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
790 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
791
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
792 track->a_sfreq = 8000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
793 track->a_channels = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
794
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
795 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
796 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
797 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
798 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
799 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
800 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
801 case MATROSKA_ID_AUDIOSAMPLINGFREQ:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
802 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
803 long double num = ebml_read_float (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
804 if (num == EBML_FLOAT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
805 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
806 track->a_sfreq = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
807 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Sampling frequency: %f\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
808 track->a_sfreq);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
809 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
810 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
811
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
812 case MATROSKA_ID_AUDIOBITDEPTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
813 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
814 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
815 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
816 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
817 track->a_bps = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
818 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
819 track->a_bps);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
820 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
821 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
822
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
823 case MATROSKA_ID_AUDIOCHANNELS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
824 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
825 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
826 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
827 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
828 track->a_channels = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
829 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
830 track->a_channels);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
831 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
832 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
833
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
834 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
835 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
836 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
837 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
838 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
839 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
840 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
841 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
842
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
843 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
844 demux_mkv_read_trackvideo (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
845 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
846 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
847 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
848 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
849
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
850 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
851 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
852 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
853 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
854 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
855 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
856 case MATROSKA_ID_VIDEOFRAMERATE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
857 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
858 long double num = ebml_read_float (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
859 if (num == EBML_FLOAT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
860 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
861 track->v_frate = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
862 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
863 track->v_frate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
864 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
865 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
866
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
867 case MATROSKA_ID_VIDEODISPLAYWIDTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
868 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
869 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
870 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
871 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
872 track->v_dwidth = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
873 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
874 track->v_dwidth);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
875 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
876 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
877
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
878 case MATROSKA_ID_VIDEODISPLAYHEIGHT:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
879 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
880 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
881 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
882 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
883 track->v_dheight = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
884 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
885 track->v_dheight);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
886 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
887 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
888
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
889 case MATROSKA_ID_VIDEOPIXELWIDTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
890 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
891 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
892 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
893 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
894 track->v_width = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
895 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
896 track->v_width);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
897 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
898 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
899
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
900 case MATROSKA_ID_VIDEOPIXELHEIGHT:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
901 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
902 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
903 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
904 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
905 track->v_height = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
906 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
907 track->v_height);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
908 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
909 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
910
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
911 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
912 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
913 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
914 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
915 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
916 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
917 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
918 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
919
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
920 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
921 demux_mkv_read_trackentry (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
922 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
923 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
924 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
925 mkv_track_t *track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
926 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
927 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
928
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
929 track = (mkv_track_t *) malloc (sizeof (*track));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
930 memset(track, 0, sizeof(*track));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
931 /* set default values */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
932 track->default_track = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
933 track->language = strdup("eng");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
934
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
935 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
936 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
937 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
938 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
939 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
940 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
941 case MATROSKA_ID_TRACKNUMBER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
942 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
943 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
944 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
945 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
946 track->tnum = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
947 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
948 track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
949 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
950 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
951
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
952 case MATROSKA_ID_TRACKTYPE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
953 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
954 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
955 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
956 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
957 track->type = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
958 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: ");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
959 switch (track->type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
960 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
961 case MATROSKA_TRACK_AUDIO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
962 mp_msg (MSGT_DEMUX, MSGL_V, "Audio\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
963 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
964 case MATROSKA_TRACK_VIDEO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
965 mp_msg (MSGT_DEMUX, MSGL_V, "Video\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
966 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
967 case MATROSKA_TRACK_SUBTITLE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
968 mp_msg (MSGT_DEMUX, MSGL_V, "Subtitle\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
969 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
970 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
971 mp_msg (MSGT_DEMUX, MSGL_V, "unknown\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
972 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
973 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
974 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
975 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
976
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
977 case MATROSKA_ID_TRACKAUDIO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
978 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
979 l = demux_mkv_read_trackaudio (demuxer, track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
980 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
981 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
982 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
983
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
984 case MATROSKA_ID_TRACKVIDEO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
985 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
986 l = demux_mkv_read_trackvideo (demuxer, track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
987 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
988 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
989 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
990
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
991 case MATROSKA_ID_CODECID:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
992 track->codec_id = ebml_read_ascii (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
993 if (track->codec_id == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
994 return 0;
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
995 if (!strcmp (track->codec_id, MKV_V_MSCOMP) ||
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
996 !strcmp (track->codec_id, MKV_A_ACM))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
997 track->ms_compat = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
998 else if (!strcmp (track->codec_id, MKV_S_VOBSUB))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
999 track->subtitle_type = MATROSKA_SUBTYPE_VOBSUB;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1000 else if (!strcmp (track->codec_id, MKV_S_TEXTSSA)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1001 || !strcmp (track->codec_id, MKV_S_TEXTASS)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1002 || !strcmp (track->codec_id, MKV_S_SSA)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1003 || !strcmp (track->codec_id, MKV_S_ASS))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1004 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1005 track->subtitle_type = MATROSKA_SUBTYPE_SSA;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1006 sub_utf8 = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1007 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1008 else if (!strcmp (track->codec_id, MKV_S_TEXTASCII))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1009 track->subtitle_type = MATROSKA_SUBTYPE_TEXT;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1010 if (!strcmp (track->codec_id, MKV_S_TEXTUTF8))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1011 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1012 track->subtitle_type = MATROSKA_SUBTYPE_TEXT;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1013 sub_utf8 = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1014 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1015 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1016 track->codec_id);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1017 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1018
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1019 case MATROSKA_ID_CODECPRIVATE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1020 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1021 int x;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1022 uint64_t num = ebml_read_length (s, &x);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1023 l = x + num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1024 track->private_data = malloc (num);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1025 if (stream_read(s, track->private_data, num) != (int) num)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1026 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1027 track->private_size = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1028 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + CodecPrivate, length "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1029 "%u\n", track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1030 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1031 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1032
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1033 case MATROSKA_ID_TRACKLANGUAGE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1034 track->language = ebml_read_utf8 (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1035 if (track->language == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1036 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1037 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1038 track->language);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1039 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1040
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1041 case MATROSKA_ID_TRACKFLAGDEFAULT:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1042 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1043 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1044 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1045 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1046 track->default_track = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1047 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1048 track->default_track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1049 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1050 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1051
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1052 case MATROSKA_ID_TRACKDEFAULTDURATION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1053 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1054 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1055 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1056 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1057 if (num == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1058 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: 0");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1059 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1060 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1061 track->v_frate = 1000000000.0 / num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1062 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1063 "%.3fms ( = %.3f fps)\n",num/1000000.0,track->v_frate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1064 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1065 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1066 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1067
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1068 case MATROSKA_ID_TRACKENCODINGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1069 l = demux_mkv_read_trackencodings (demuxer, track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1070 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1071 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1072 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1073
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1074 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1075 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1076 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1077 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1078 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1079 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1080
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1081 mkv_d->tracks[mkv_d->num_tracks++] = track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1082 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1083 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1084
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1085 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1086 demux_mkv_read_tracks (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1087 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1088 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1089 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1090 uint64_t length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1091 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1092
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1093 mkv_d->tracks = (mkv_track_t **) malloc (sizeof (*mkv_d->tracks));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1094 mkv_d->num_tracks = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1095
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1096 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1097 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1098 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1099 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1100 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1101 case MATROSKA_ID_TRACKENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1102 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1103 mkv_d->tracks = (mkv_track_t **) realloc (mkv_d->tracks,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1104 (mkv_d->num_tracks+1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1105 *sizeof (*mkv_d->tracks));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1106 l = demux_mkv_read_trackentry (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1107 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1108 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1109 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1110
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1111 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1112 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1113 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1114 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1115 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1116 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1117 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1118 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1119
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1120 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1121 demux_mkv_read_cues (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1122 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1123 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1124 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1125 uint64_t length, l, time, track, pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1126 off_t off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1127 int i, il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1128
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1129 off = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1130 for (i=0; i<mkv_d->parsed_cues_num; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1131 if (mkv_d->parsed_cues[i] == off)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1132 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1133 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1134 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1135 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1136 mkv_d->parsed_cues = (off_t *) realloc (mkv_d->parsed_cues,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1137 (mkv_d->parsed_cues_num+1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1138 * sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1139 mkv_d->parsed_cues[mkv_d->parsed_cues_num++] = off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1140
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1141 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1142 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1143
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1144 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1145 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1146 time = track = pos = EBML_UINT_INVALID;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1147
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1148 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1149 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1150 case MATROSKA_ID_POINTENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1151 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1152 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1153
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1154 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1155 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1156
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1157 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1158 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1159 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1160 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1161
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1162 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1163 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1164 case MATROSKA_ID_CUETIME:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1165 time = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1166 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1167
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1168 case MATROSKA_ID_CUETRACKPOSITION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1169 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1170 uint64_t le;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1171
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1172 le = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1173 l = le + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1174
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1175 while (le > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1176 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1177 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1178 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1179
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1180 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1181 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1182 case MATROSKA_ID_CUETRACK:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1183 track = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1184 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1185
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1186 case MATROSKA_ID_CUECLUSTERPOSITION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1187 pos = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1188 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1189
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1190 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1191 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1192 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1193 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1194 le -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1195 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1196 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1197 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1198
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1199 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1200 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1201 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1202 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1203 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1204 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1205 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1206 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1207
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1208 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1209 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1210 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1211 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1212
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1213 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1214
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1215 if (time != EBML_UINT_INVALID && track != EBML_UINT_INVALID
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1216 && pos != EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1217 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1218 if (mkv_d->indexes == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1219 mkv_d->indexes = (mkv_index_t *) malloc (32*sizeof (mkv_index_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1220 else if (mkv_d->num_indexes % 32 == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1221 mkv_d->indexes = (mkv_index_t *) realloc (mkv_d->indexes,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1222 (mkv_d->num_indexes+32)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1223 *sizeof (mkv_index_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1224 mkv_d->indexes[mkv_d->num_indexes].tnum = track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1225 mkv_d->indexes[mkv_d->num_indexes].timecode = time;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1226 mkv_d->indexes[mkv_d->num_indexes].filepos =mkv_d->segment_start+pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1227 mp_msg (MSGT_DEMUX, MSGL_DBG2, "[mkv] |+ found cue point "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1228 "for track %llu: timecode %llu, filepos: %llu\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1229 track, time, mkv_d->segment_start + pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1230 mkv_d->num_indexes++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1231 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1232 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1233
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1234 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1235 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1236 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1237
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1238 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1239 demux_mkv_read_chapters (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1240 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1241 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1242 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1243 uint64_t length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1244 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1245
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1246 if (mkv_d->chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1247 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1248 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1249 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1250 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1251
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1252 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1253 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1254
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1255 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1256 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1257 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1258 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1259 case MATROSKA_ID_EDITIONENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1260 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1261 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1262 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1263
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1264 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1265 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1266
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1267 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1268 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1269 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1270 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1271
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1272 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1273 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1274 case MATROSKA_ID_CHAPTERATOM:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1275 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1276 uint64_t len, start=0, end=0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1277 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1278
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1279 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1280 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1281
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1282 if (mkv_d->chapters == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1283 mkv_d->chapters = malloc (32*sizeof(*mkv_d->chapters));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1284 else if (!(mkv_d->num_chapters % 32))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1285 mkv_d->chapters = realloc (mkv_d->chapters,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1286 (mkv_d->num_chapters + 32)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1287 * sizeof(*mkv_d->chapters));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1288
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1289 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1290 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1291 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1292 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1293
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1294 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1295 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1296 case MATROSKA_ID_CHAPTERTIMESTART:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1297 start = ebml_read_uint (s, &l) / 1000000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1298 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1299
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1300 case MATROSKA_ID_CHAPTERTIMEEND:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1301 end = ebml_read_uint (s, &l) / 1000000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1302 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1303
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1304 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1305 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1306 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1307 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1308 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1309 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1310
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1311 mkv_d->chapters[mkv_d->num_chapters].start = start;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1312 mkv_d->chapters[mkv_d->num_chapters].end = end;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1313 mp_msg(MSGT_DEMUX, MSGL_V,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1314 "[mkv] Chapter %u from %02d:%02d:%02d."
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1315 "%03d to %02d:%02d:%02d.%03d\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1316 ++mkv_d->num_chapters,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1317 (int) (start / 60 / 60 / 1000),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1318 (int) ((start / 60 / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1319 (int) ((start / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1320 (int) (start % 1000),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1321 (int) (end / 60 / 60 / 1000),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1322 (int) ((end / 60 / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1323 (int) ((end / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1324 (int) (end % 1000));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1325 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1326 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1327
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1328 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1329 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1330 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1331 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1332 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1333 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1334 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1335 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1336
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1337 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1338 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1339 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1340 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1341
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1342 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1343 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1344
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1345 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing chapters ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1346 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1347 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1348
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1349 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1350 demux_mkv_read_tags (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1351 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1352 ebml_read_skip (demuxer->stream, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1353 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1354 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1355
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1356 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1357 demux_mkv_read_seekhead (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1358 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1359 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1360 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1361 uint64_t length, l, seek_pos, saved_pos, num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1362 uint32_t seek_id;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1363 int i, il, res = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1364 off_t off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1365
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1366 off = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1367 for (i=0; i<mkv_d->parsed_seekhead_num; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1368 if (mkv_d->parsed_seekhead[i] == off)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1369 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1370 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1371 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1372 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1373 mkv_d->parsed_seekhead = (off_t *) realloc (mkv_d->parsed_seekhead,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1374 (mkv_d->parsed_seekhead_num+1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1375 * sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1376 mkv_d->parsed_seekhead[mkv_d->parsed_seekhead_num++] = off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1377
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1378 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing seek head ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1379 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1380 while (length > 0 && !res)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1381 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1382
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1383 seek_id = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1384 seek_pos = EBML_UINT_INVALID;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1385
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1386 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1387 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1388 case MATROSKA_ID_SEEKENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1389 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1390 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1391
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1392 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1393 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1394
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1395 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1396 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1397 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1398 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1399
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1400 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1401 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1402 case MATROSKA_ID_SEEKID:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1403 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1404 if (num != EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1405 seek_id = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1406 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1407
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1408 case MATROSKA_ID_SEEKPOSITION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1409 seek_pos = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1410 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1411
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1412 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1413 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1414 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1415 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1416 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1417 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1418
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1419 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1420 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1421
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1422 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1423 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1424 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1425 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1426 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1427
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1428 if (seek_id == 0 || seek_id == MATROSKA_ID_CLUSTER
11899
18bd28454ef6 Do not try to seek beyond the end of the stream when parsing the headers.
mosu
parents: 11856
diff changeset
1429 || seek_pos == EBML_UINT_INVALID ||
18bd28454ef6 Do not try to seek beyond the end of the stream when parsing the headers.
mosu
parents: 11856
diff changeset
1430 ((mkv_d->segment_start + seek_pos) >= (uint64_t)demuxer->movi_end))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1431 continue;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1432
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1433 saved_pos = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1434 if (!stream_seek (s, mkv_d->segment_start + seek_pos))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1435 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1436 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1437 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1438 if (ebml_read_id (s, &il) != seek_id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1439 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1440 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1441 switch (seek_id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1442 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1443 case MATROSKA_ID_CUES:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1444 if (demux_mkv_read_cues (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1445 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1446 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1447
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1448 case MATROSKA_ID_TAGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1449 if (demux_mkv_read_tags (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1450 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1451 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1452
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1453 case MATROSKA_ID_SEEKHEAD:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1454 if (demux_mkv_read_seekhead (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1455 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1456 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1457
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1458 case MATROSKA_ID_CHAPTERS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1459 if (demux_mkv_read_chapters (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1460 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1461 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1462 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1463 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1464
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1465 stream_seek (s, saved_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1466 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1467 if (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1468 stream_seek (s, stream_tell (s) + length);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1469 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing seek head ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1470 return res;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1471 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1472
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1473 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1474 display_tracks (mkv_demuxer_t *mkv_d)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1475 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1476 int i, vid=0, aid=0, sid=0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1477
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1478 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1479 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1480 char *type = "unknown", str[32];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1481 *str = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1482 switch (mkv_d->tracks[i]->type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1483 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1484 case MATROSKA_TRACK_VIDEO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1485 type = "video";
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1486 sprintf (str, "-vid %u", vid++);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1487 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1488 case MATROSKA_TRACK_AUDIO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1489 type = "audio";
12288
8c8c71a02e5a fix exploitable buffer overflow
rfelker
parents: 12101
diff changeset
1490 sprintf (str, "-aid %u, -alang %.5s",aid++,mkv_d->tracks[i]->language);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1491 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1492 case MATROSKA_TRACK_SUBTITLE:
13324
dcbdd8ea356d Spelling. Patch by Jan Minar <jjminar at fastmail onedot fm>.
mosu
parents: 13131
diff changeset
1493 type = "subtitles";
12288
8c8c71a02e5a fix exploitable buffer overflow
rfelker
parents: 12101
diff changeset
1494 sprintf (str, "-sid %u, -slang %.5s",sid++,mkv_d->tracks[i]->language);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1495 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1496 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1497 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Track ID %u: %s (%s), %s\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1498 mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, str);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1499 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1500 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1501
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1502 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1503 demux_mkv_open_video (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1504 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1505 BITMAPINFOHEADER *bih;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1506 void *ImageDesc = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1507 sh_video_t *sh_v;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1508
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1509 if (track->ms_compat) /* MS compatibility mode */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1510 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1511 BITMAPINFOHEADER *src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1512
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1513 if (track->private_data == NULL
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1514 || track->private_size < sizeof (BITMAPINFOHEADER))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1515 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1516
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1517 src = (BITMAPINFOHEADER *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1518 bih = (BITMAPINFOHEADER *) malloc (track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1519 memset (bih, 0, track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1520 bih->biSize = le2me_32 (src->biSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1521 bih->biWidth = le2me_32 (src->biWidth);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1522 bih->biHeight = le2me_32 (src->biHeight);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1523 bih->biPlanes = le2me_16 (src->biPlanes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1524 bih->biBitCount = le2me_16 (src->biBitCount);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1525 bih->biCompression = le2me_32 (src->biCompression);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1526 bih->biSizeImage = le2me_32 (src->biSizeImage);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1527 bih->biXPelsPerMeter = le2me_32 (src->biXPelsPerMeter);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1528 bih->biYPelsPerMeter = le2me_32 (src->biYPelsPerMeter);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1529 bih->biClrUsed = le2me_32 (src->biClrUsed);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1530 bih->biClrImportant = le2me_32 (src->biClrImportant);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1531 memcpy((char *) bih + sizeof (BITMAPINFOHEADER),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1532 (char *) src + sizeof (BITMAPINFOHEADER),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1533 track->private_size - sizeof (BITMAPINFOHEADER));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1534
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1535 if (track->v_width == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1536 track->v_width = bih->biWidth;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1537 if (track->v_height == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1538 track->v_height = bih->biHeight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1539 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1540 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1541 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1542 bih = (BITMAPINFOHEADER *) malloc (sizeof (BITMAPINFOHEADER));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1543 memset (bih, 0, sizeof (BITMAPINFOHEADER));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1544 bih->biSize = sizeof (BITMAPINFOHEADER);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1545 bih->biWidth = track->v_width;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1546 bih->biHeight = track->v_height;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1547 bih->biBitCount = 24;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1548 bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount/8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1549
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1550 if (track->private_size >= sizeof (real_video_props_t)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1551 && (!strcmp (track->codec_id, MKV_V_REALV10)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1552 || !strcmp (track->codec_id, MKV_V_REALV20)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1553 || !strcmp (track->codec_id, MKV_V_REALV30)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1554 || !strcmp (track->codec_id, MKV_V_REALV40)))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1555 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1556 unsigned char *dst, *src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1557 real_video_props_t *rvp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1558 uint32_t type2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1559
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1560 rvp = (real_video_props_t *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1561 src = (unsigned char *) (rvp + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1562
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1563 bih = (BITMAPINFOHEADER *) realloc(bih,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1564 sizeof (BITMAPINFOHEADER)+12);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1565 bih->biSize = 48;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1566 bih->biPlanes = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1567 type2 = be2me_32 (rvp->type2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1568 if (type2 == 0x10003000 || type2 == 0x10003001)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1569 bih->biCompression=mmioFOURCC('R','V','1','3');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1570 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1571 bih->biCompression=mmioFOURCC('R','V',track->codec_id[9],'0');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1572 dst = (unsigned char *) (bih + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1573 ((unsigned int *) dst)[0] = be2me_32 (rvp->type1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1574 ((unsigned int *) dst)[1] = type2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1575
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1576 if (bih->biCompression <= 0x30335652 && type2 >= 0x20200002)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1577 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1578 /* read secondary WxH for the cmsg24[] (see vd_realvid.c) */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1579 ((unsigned short *)(bih+1))[4] = 4 * (unsigned short) src[0];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1580 ((unsigned short *)(bih+1))[5] = 4 * (unsigned short) src[1];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1581 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1582 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1583 memset(&dst[8], 0, 4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1584 track->realmedia = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1585
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1586 #ifdef USE_QTX_CODECS
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1587 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1588 else if (track->private_size >= sizeof (ImageDescription)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1589 && !strcmp(track->codec_id, MKV_V_QUICKTIME))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1590 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1591 ImageDescriptionPtr idesc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1592
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1593 idesc = (ImageDescriptionPtr) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1594 idesc->idSize = be2me_32 (idesc->idSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1595 idesc->cType = be2me_32 (idesc->cType);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1596 idesc->version = be2me_16 (idesc->version);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1597 idesc->revisionLevel = be2me_16 (idesc->revisionLevel);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1598 idesc->vendor = be2me_32 (idesc->vendor);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1599 idesc->temporalQuality = be2me_32 (idesc->temporalQuality);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1600 idesc->spatialQuality = be2me_32 (idesc->spatialQuality);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1601 idesc->width = be2me_16 (idesc->width);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1602 idesc->height = be2me_16 (idesc->height);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1603 idesc->hRes = be2me_32 (idesc->hRes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1604 idesc->vRes = be2me_32 (idesc->vRes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1605 idesc->dataSize = be2me_32 (idesc->dataSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1606 idesc->frameCount = be2me_16 (idesc->frameCount);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1607 idesc->depth = be2me_16 (idesc->depth);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1608 idesc->clutID = be2me_16 (idesc->clutID);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1609 bih->biPlanes = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1610 bih->biCompression = idesc->cType;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1611 ImageDesc = idesc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1612 #endif /* USE_QTX_CODECS */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1613
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1614 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1615 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1616 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1617 mp_msg (MSGT_DEMUX,MSGL_WARN,"[mkv] Unknown/unsupported CodecID "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1618 "(%s) or missing/bad CodecPrivate data (track %u).\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1619 track->codec_id, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1620 free(bih);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1621 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1622 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1623 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1624
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1625 sh_v = new_sh_video (demuxer, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1626 sh_v->bih = bih;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1627 sh_v->format = sh_v->bih->biCompression;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1628 if (track->v_frate == 0.0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1629 track->v_frate = 25.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1630 sh_v->fps = track->v_frate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1631 sh_v->frametime = 1 / track->v_frate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1632 if (!track->realmedia)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1633 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1634 sh_v->disp_w = track->v_width;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1635 sh_v->disp_h = track->v_height;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1636 sh_v->aspect = (float)track->v_dwidth / (float)track->v_dheight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1637 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1638 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1639 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1640 // vd_realvid.c will set aspect to disp_w/disp_h and rederive
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1641 // disp_w and disp_h from the RealVideo stream contents returned
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1642 // by the Real DLLs. If DisplayWidth/DisplayHeight was not set in
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1643 // the Matroska file then it has already been set to PixelWidth/Height
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1644 // by check_track_information.
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1645 sh_v->disp_w = track->v_dwidth;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1646 sh_v->disp_h = track->v_dheight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1647 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1648 sh_v->ImageDesc = ImageDesc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1649 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1650
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1651 sh_v->ds = demuxer->video;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1652 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1653 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1654
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1655 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1656 demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1657 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1658 sh_audio_t *sh_a = new_sh_audio(demuxer, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1659 demux_packet_t *dp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1660 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1661
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1662 sh_a->ds = demuxer->audio;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1663 sh_a->wf = (WAVEFORMATEX *) malloc (sizeof (WAVEFORMATEX));
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1664 if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX)))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1665 {
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1666 WAVEFORMATEX *wf = (WAVEFORMATEX *)track->private_data;
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1667 sh_a->wf = (WAVEFORMATEX *) realloc(sh_a->wf, track->private_size);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1668 sh_a->wf->wFormatTag = le2me_16 (wf->wFormatTag);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1669 sh_a->wf->nChannels = le2me_16 (wf->nChannels);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1670 sh_a->wf->nSamplesPerSec = le2me_32 (wf->nSamplesPerSec);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1671 sh_a->wf->nAvgBytesPerSec = le2me_32 (wf->nAvgBytesPerSec);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1672 sh_a->wf->nBlockAlign = le2me_16 (wf->nBlockAlign);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1673 sh_a->wf->wBitsPerSample = le2me_16 (wf->wBitsPerSample);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1674 sh_a->wf->cbSize = track->private_size - sizeof(WAVEFORMATEX);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1675 memcpy(sh_a->wf + 1, wf + 1, track->private_size - sizeof(WAVEFORMATEX));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1676 if (track->a_sfreq == 0.0)
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1677 track->a_sfreq = sh_a->wf->nSamplesPerSec;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1678 if (track->a_channels == 0)
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1679 track->a_channels = sh_a->wf->nChannels;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1680 if (track->a_bps == 0)
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1681 track->a_bps = sh_a->wf->wBitsPerSample;
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1682 track->a_formattag = sh_a->wf->wFormatTag;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1683 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1684 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1685 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1686 memset(sh_a->wf, 0, sizeof (WAVEFORMATEX));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1687 if (!strcmp(track->codec_id, MKV_A_MP3) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1688 !strcmp(track->codec_id, MKV_A_MP2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1689 track->a_formattag = 0x0055;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1690 else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3)) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1691 !strcmp(track->codec_id, MKV_A_DTS))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1692 track->a_formattag = 0x2000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1693 else if (!strcmp(track->codec_id, MKV_A_PCM) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1694 !strcmp(track->codec_id, MKV_A_PCM_BE))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1695 track->a_formattag = 0x0001;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1696 else if (!strcmp(track->codec_id, MKV_A_AAC_2MAIN) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1697 !strncmp(track->codec_id, MKV_A_AAC_2LC,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1698 strlen(MKV_A_AAC_2LC)) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1699 !strcmp(track->codec_id, MKV_A_AAC_2SSR) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1700 !strcmp(track->codec_id, MKV_A_AAC_4MAIN) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1701 !strncmp(track->codec_id, MKV_A_AAC_4LC,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1702 strlen(MKV_A_AAC_4LC)) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1703 !strcmp(track->codec_id, MKV_A_AAC_4SSR) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1704 !strcmp(track->codec_id, MKV_A_AAC_4LTP))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1705 track->a_formattag = mmioFOURCC('M', 'P', '4', 'A');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1706 else if (!strcmp(track->codec_id, MKV_A_VORBIS))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1707 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1708 unsigned char *c;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1709 uint32_t offset, length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1710
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1711 if (track->private_data == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1712 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1713
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1714 c = (unsigned char *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1715 if (*c != 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1716 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1717 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1718 "contain valid headers.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1719 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1720 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1721
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1722 offset = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1723 for (i=0; i < 2; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1724 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1725 length = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1726 while (c[offset] == (unsigned char) 0xFF
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1727 && length < track->private_size)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1728 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1729 length += 255;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1730 offset++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1731 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1732 if (offset >= (track->private_size - 1))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1733 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1734 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1735 "does not contain valid headers.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1736 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1737 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1738 length += c[offset];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1739 offset++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1740 track->header_sizes[i] = length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1741 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1742
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1743 track->headers[0] = &c[offset];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1744 track->headers[1] = &c[offset + track->header_sizes[0]];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1745 track->headers[2] = &c[offset + track->header_sizes[0] +
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1746 track->header_sizes[1]];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1747 track->header_sizes[2] = track->private_size - offset
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1748 - track->header_sizes[0] - track->header_sizes[1];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1749
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1750 track->a_formattag = 0xFFFE;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1751 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1752 else if (!strcmp(track->codec_id, MKV_A_QDMC))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1753 track->a_formattag = mmioFOURCC('Q', 'D', 'M', 'C');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1754 else if (!strcmp(track->codec_id, MKV_A_QDMC2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1755 track->a_formattag = mmioFOURCC('Q', 'D', 'M', '2');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1756 else if (!strcmp(track->codec_id, MKV_A_FLAC))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1757 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1758 if (track->private_data == NULL || track->private_size == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1759 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1760 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] FLAC track does not "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1761 "contain valid headers.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1762 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1763 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1764 track->a_formattag = mmioFOURCC ('f', 'L', 'a', 'C');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1765 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1766 else if (track->private_size >= sizeof (real_audio_v4_props_t))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1767 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1768 if (!strcmp(track->codec_id, MKV_A_REAL28))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1769 track->a_formattag = mmioFOURCC('2', '8', '_', '8');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1770 else if (!strcmp(track->codec_id, MKV_A_REALATRC))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1771 track->a_formattag = mmioFOURCC('a', 't', 'r', 'c');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1772 else if (!strcmp(track->codec_id, MKV_A_REALCOOK))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1773 track->a_formattag = mmioFOURCC('c', 'o', 'o', 'k');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1774 else if (!strcmp(track->codec_id, MKV_A_REALDNET))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1775 track->a_formattag = mmioFOURCC('d', 'n', 'e', 't');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1776 else if (!strcmp(track->codec_id, MKV_A_REALSIPR))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1777 track->a_formattag = mmioFOURCC('s', 'i', 'p', 'r');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1778 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1779 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1780 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1781 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported audio "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1782 "codec ID '%s' for track %u or missing/faulty private "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1783 "codec data.\n", track->codec_id, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1784 free_sh_audio (sh_a);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1785 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1786 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1787 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1788
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1789 sh_a->format = track->a_formattag;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1790 sh_a->wf->wFormatTag = track->a_formattag;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1791 sh_a->channels = track->a_channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1792 sh_a->wf->nChannels = track->a_channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1793 sh_a->samplerate = (uint32_t) track->a_sfreq;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1794 sh_a->wf->nSamplesPerSec = (uint32_t) track->a_sfreq;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1795 sh_a->samplesize = track->a_bps / 8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1796 if (track->a_formattag == 0x0055) /* MP3 || MP2 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1797 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1798 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1799 sh_a->wf->nBlockAlign = 1152;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1800 sh_a->wf->wBitsPerSample = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1801 sh_a->samplesize = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1802 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1803 else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3)))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1804 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1805 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1806 sh_a->wf->nBlockAlign = 1536;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1807 sh_a->wf->wBitsPerSample = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1808 sh_a->samplesize = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1809 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1810 else if (track->a_formattag == 0x0001) /* PCM || PCM_BE */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1811 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1812 sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate*2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1813 sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1814 sh_a->wf->wBitsPerSample = track->a_bps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1815 if (!strcmp(track->codec_id, MKV_A_PCM_BE))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1816 sh_a->format = mmioFOURCC('t', 'w', 'o', 's');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1817 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1818 else if (!strcmp(track->codec_id, MKV_A_QDMC) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1819 !strcmp(track->codec_id, MKV_A_QDMC2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1820 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1821 sh_a->wf->wBitsPerSample = track->a_bps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1822 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1823 sh_a->wf->nBlockAlign = 1486;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1824 track->fix_i_bps = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1825 track->qt_last_a_pts = 0.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1826 if (track->private_data != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1827 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1828 sh_a->codecdata=(unsigned char *)malloc(track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1829 memcpy (sh_a->codecdata, track->private_data,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1830 track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1831 sh_a->codecdata_len = track->private_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1832 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1833 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1834 else if (track->a_formattag == mmioFOURCC('M', 'P', '4', 'A'))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1835 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1836 int profile, srate_idx;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1837
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1838 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1839 sh_a->wf->nBlockAlign = 1024;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1840 sh_a->wf->wBitsPerSample = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1841 sh_a->samplesize = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1842
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1843 /* Recreate the 'private data' */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1844 /* which faad2 uses in its initialization */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1845 srate_idx = aac_get_sample_rate_index (sh_a->samplerate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1846 if (!strncmp (&track->codec_id[12], "MAIN", 4))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1847 profile = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1848 else if (!strncmp (&track->codec_id[12], "LC", 2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1849 profile = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1850 else if (!strncmp (&track->codec_id[12], "SSR", 3))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1851 profile = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1852 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1853 profile = 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1854 sh_a->codecdata = (unsigned char *) malloc (5);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1855 sh_a->codecdata[0] = ((profile+1) << 3) | ((srate_idx&0xE) >> 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1856 sh_a->codecdata[1] = ((srate_idx&0x1)<<7)|(track->a_channels<<3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1857
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1858 if (strstr(track->codec_id, "SBR") != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1859 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1860 /* HE-AAC (aka SBR AAC) */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1861 sh_a->codecdata_len = 5;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1862
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1863 sh_a->samplerate *= 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1864 sh_a->wf->nSamplesPerSec *= 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1865 srate_idx = aac_get_sample_rate_index(sh_a->samplerate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1866 sh_a->codecdata[2] = AAC_SYNC_EXTENSION_TYPE >> 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1867 sh_a->codecdata[3] = ((AAC_SYNC_EXTENSION_TYPE&0x07)<<5) | 5;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1868 sh_a->codecdata[4] = (1 << 7) | (srate_idx << 3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1869 track->default_duration = 1024.0 / (sh_a->samplerate / 2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1870 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1871 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1872 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1873 sh_a->codecdata_len = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1874 track->default_duration = 1024.0 / (float)sh_a->samplerate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1875 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1876 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1877 else if (track->a_formattag == 0xFFFE) /* VORBIS */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1878 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1879 for (i=0; i < 3; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1880 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1881 dp = new_demux_packet (track->header_sizes[i]);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1882 memcpy (dp->buffer,track->headers[i],track->header_sizes[i]);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1883 dp->pts = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1884 dp->flags = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1885 ds_add_packet (demuxer->audio, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1886 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1887 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1888 else if (track->private_size >= sizeof(real_audio_v4_props_t)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1889 && !strncmp (track->codec_id, MKV_A_REALATRC, 7))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1890 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1891 /* Common initialization for all RealAudio codecs */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1892 real_audio_v4_props_t *ra4p;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1893 real_audio_v5_props_t *ra5p;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1894 unsigned char *src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1895 int codecdata_length, version;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1896
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1897 ra4p = (real_audio_v4_props_t *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1898 ra5p = (real_audio_v5_props_t *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1899
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1900 sh_a->wf->wBitsPerSample = sh_a->samplesize * 8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1901 sh_a->wf->nAvgBytesPerSec = 0; /* FIXME !? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1902 sh_a->wf->nBlockAlign = be2me_16 (ra4p->frame_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1903
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1904 version = be2me_16 (ra4p->version1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1905
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1906 if (version == 4)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1907 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1908 src = (unsigned char *) (ra4p + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1909 src += src[0] + 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1910 src += src[0] + 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1911 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1912 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1913 src = (unsigned char *) (ra5p + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1914
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1915 src += 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1916 if (version == 5)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1917 src++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1918 codecdata_length = be2me_32 (*(uint32_t *)src);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1919 src += 4;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1920 sh_a->wf->cbSize = 10 + codecdata_length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1921 sh_a->wf = (WAVEFORMATEX *) realloc (sh_a->wf,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1922 sizeof (WAVEFORMATEX) +
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1923 sh_a->wf->cbSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1924 ((short *)(sh_a->wf + 1))[0] = be2me_16 (ra4p->sub_packet_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1925 ((short *)(sh_a->wf + 1))[1] = be2me_16 (ra4p->sub_packet_h);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1926 ((short *)(sh_a->wf + 1))[2] = be2me_16 (ra4p->flavor);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1927 ((short *)(sh_a->wf + 1))[3] = be2me_32 (ra4p->coded_frame_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1928 ((short *)(sh_a->wf + 1))[4] = codecdata_length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1929 memcpy(((char *)(sh_a->wf + 1)) + 10, src, codecdata_length);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1930
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1931 track->realmedia = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1932 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1933 else if (!strcmp(track->codec_id, MKV_A_FLAC) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1934 (track->a_formattag == 0xf1ac))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1935 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1936 unsigned char *ptr;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1937 int size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1938 free(sh_a->wf);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1939 sh_a->wf = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1940
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1941 if (track->a_formattag == mmioFOURCC('f', 'L', 'a', 'C'))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1942 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1943 ptr = (unsigned char *)track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1944 size = track->private_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1945 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1946 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1947 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1948 sh_a->format = mmioFOURCC('f', 'L', 'a', 'C');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1949 ptr = (unsigned char *) track->private_data
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1950 + sizeof (WAVEFORMATEX);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1951 size = track->private_size - sizeof (WAVEFORMATEX);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1952 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1953 if (size < 4 || ptr[0] != 'f' || ptr[1] != 'L' ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1954 ptr[2] != 'a' || ptr[3] != 'C')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1955 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1956 dp = new_demux_packet (4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1957 memcpy (dp->buffer, "fLaC", 4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1958 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1959 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1960 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1961 dp = new_demux_packet (size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1962 memcpy (dp->buffer, ptr, size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1963 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1964 dp->pts = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1965 dp->flags = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1966 ds_add_packet (demuxer->audio, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1967 }
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1968 else if (!track->ms_compat || (track->private_size < sizeof(WAVEFORMATEX)))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1969 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1970 free_sh_audio (sh_a);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1971 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1972 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1973
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1974 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1975 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1976
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1977 /** \brief Parse the private data for VobSub subtitle tracks.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1978
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1979 This function tries to parse the private data for all VobSub tracks.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1980 The private data contains the normal text from the original .idx file.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1981 Things like the palette, subtitle dimensions and custom colors are
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1982 stored here.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1983
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1984 \param demuxer The generic demuxer.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1985 */
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1986 static void
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1987 demux_mkv_parse_vobsub_data (demuxer_t *demuxer)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1988 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1989 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1990 mkv_track_t *track;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1991 int i, m, size;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1992 uint8_t *buffer;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1993
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1994 for (i = 0; i < mkv_d->num_tracks; i++)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1995 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1996 track = mkv_d->tracks[i];
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1997 if ((track->type != MATROSKA_TRACK_SUBTITLE) ||
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1998 (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
1999 continue;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2000
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2001 size = track->private_size;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2002 m = demux_mkv_decode (track,track->private_data,&buffer,&size,2);
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2003 if (buffer && m)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2004 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2005 free (track->private_data);
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2006 track->private_data = buffer;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2007 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2008 if (!demux_mkv_parse_idx (track))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2009 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2010 free (track->private_data);
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2011 track->private_data = NULL;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2012 track->private_size = 0;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2013 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2014 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2015 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2016
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2017 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2018 demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2019 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2020 if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2021 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2022 if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2023 {
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2024 if (track->private_data != NULL)
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2025 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2026 demuxer->sub->sh = malloc(sizeof(mkv_sh_sub_t));
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2027 if (demuxer->sub->sh != NULL)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2028 memcpy(demuxer->sub->sh, &track->sh_sub, sizeof(mkv_sh_sub_t));
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2029 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2030 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2031 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2032 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2033 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2034 mp_msg (MSGT_DEMUX, MSGL_ERR, "[mkv] Subtitle type '%s' is not "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2035 "supported.\n", track->codec_id);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2036 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2037 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2038
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2039 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2040 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2041
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2042 void demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, int flags);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2043
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2044 int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2045 demux_mkv_open (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2046 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2047 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2048 mkv_demuxer_t *mkv_d;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2049 mkv_track_t *track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2050 int i, version, cont = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2051 char *str;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2052
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2053 #ifdef USE_ICONV
12909
dc8eba991005 fixes a crash and unchecked string-handling in ENCA code.
reimar
parents: 12721
diff changeset
2054 subcp_open(NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2055 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2056
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2057 stream_seek(s, s->start_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2058 str = ebml_read_header (s, &version);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2059 if (str == NULL || strcmp (str, "matroska") || version > 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2060 {
11856
rfelker
parents: 11832
diff changeset
2061 mp_msg (MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2062 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2063 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2064 free (str);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2065
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2066 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2067
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2068 if (ebml_read_id (s, NULL) != MATROSKA_ID_SEGMENT)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2069 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2070 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2071 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2072 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2073 ebml_read_length (s, NULL); /* return bytes number until EOF */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2074
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2075 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2076
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2077 mkv_d = (mkv_demuxer_t *) malloc (sizeof (mkv_demuxer_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2078 memset (mkv_d, 0, sizeof(mkv_demuxer_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2079 demuxer->priv = mkv_d;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2080 mkv_d->tc_scale = 1000000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2081 mkv_d->segment_start = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2082 mkv_d->parsed_cues = (off_t *) malloc (sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2083 mkv_d->parsed_seekhead = (off_t *) malloc (sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2084
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2085 for (i=0; i < SUB_MAX_TEXT; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2086 mkv_d->subs.text[i] = (char *) malloc (256);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2087
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2088 while (!cont)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2089 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2090 switch (ebml_read_id (s, NULL))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2091 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2092 case MATROSKA_ID_INFO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2093 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2094 cont = demux_mkv_read_info (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2095 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2096
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2097 case MATROSKA_ID_TRACKS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2098 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2099 cont = demux_mkv_read_tracks (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2100 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2101
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2102 case MATROSKA_ID_CUES:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2103 cont = demux_mkv_read_cues (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2104 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2105
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2106 case MATROSKA_ID_TAGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2107 cont = demux_mkv_read_tags (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2108 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2109
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2110 case MATROSKA_ID_SEEKHEAD:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2111 cont = demux_mkv_read_seekhead (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2112 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2113
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2114 case MATROSKA_ID_CHAPTERS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2115 cont = demux_mkv_read_chapters (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2116 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2117
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2118 case MATROSKA_ID_CLUSTER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2119 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2120 int p, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2121 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2122 "parsed completely :)\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2123 /* get the first cluster timecode */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2124 p = stream_tell(s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2125 l = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2126 while (ebml_read_id (s, NULL) != MATROSKA_ID_CLUSTERTIMECODE)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2127 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2128 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2129 if (stream_tell (s) >= p + l)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2130 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2131 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2132 if (stream_tell (s) < p + l)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2133 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2134 uint64_t num = ebml_read_uint (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2135 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2136 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2137 mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2138 mkv_d->has_first_tc = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2139 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2140 stream_seek (s, p - 4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2141 cont = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2142 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2143 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2144
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2145 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2146 cont = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2147 case MATROSKA_ID_ATTACHMENTS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2148 case EBML_ID_VOID:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2149 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2150 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2151 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2152 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2153
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2154 display_tracks (mkv_d);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2155
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2156 /* select video track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2157 track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2158 if (demuxer->video->id == -1) /* automatically select a video track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2159 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2160 /* search for a video track that has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2161 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2162 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2163 && mkv_d->tracks[i]->default_track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2164 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2165 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2166 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2167 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2168
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2169 if (track == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2170 /* no track has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2171 /* let's take the first video track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2172 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2173 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2174 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2175 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2176 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2177 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2178 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2179 else if (demuxer->video->id != -2) /* -2 = no video at all */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2180 track = demux_mkv_find_track_by_num (mkv_d, demuxer->video->id,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2181 MATROSKA_TRACK_VIDEO);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2182
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2183 if (track && !demux_mkv_open_video (demuxer, track))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2184 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2185 mp_msg (MSGT_DEMUX, MSGL_INFO,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2186 "[mkv] Will play video track %u\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2187 demuxer->video->id = track->tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2188 demuxer->video->sh = demuxer->v_streams[track->tnum];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2189 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2190 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2191 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2192 mp_msg (MSGT_DEMUX, MSGL_INFO, "[mkv] No video track found/wanted.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2193 demuxer->video->id = -2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2194 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2195
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2196 /* select audio track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2197 track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2198 if (demuxer->audio->id == -1) /* automatically select an audio track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2199 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2200 /* check if the user specified an audio language */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2201 if (audio_lang != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2202 track = demux_mkv_find_track_by_language(mkv_d, audio_lang,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2203 MATROSKA_TRACK_AUDIO);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2204 if (track == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2205 /* no audio language specified, or language not found */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2206 /* search for an audio track that has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2207 for (i=0; i < mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2208 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2209 && mkv_d->tracks[i]->default_track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2210 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2211 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2212 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2213 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2214
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2215 if (track == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2216 /* no track has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2217 /* let's take the first audio track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2218 for (i=0; i < mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2219 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2220 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2221 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2222 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2223 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2224 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2225 else if (demuxer->audio->id != -2) /* -2 = no audio at all */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2226 track = demux_mkv_find_track_by_num (mkv_d, demuxer->audio->id,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2227 MATROSKA_TRACK_AUDIO);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2228
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2229 if (track && !demux_mkv_open_audio (demuxer, track))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2230 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2231 mp_msg (MSGT_DEMUX, MSGL_INFO,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2232 "[mkv] Will play audio track %u\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2233 demuxer->audio->id = track->tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2234 demuxer->audio->sh = demuxer->a_streams[track->tnum];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2235 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2236 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2237 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2238 mp_msg (MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n");
11832
b9b330154ae1 Do not deactivate the video stream if no audio stream was wanted/found...
mosu
parents: 11815
diff changeset
2239 demuxer->audio->id = -2;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2240 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2241
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2242 demux_mkv_parse_vobsub_data (demuxer);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2243 /* DO NOT automatically select a subtitle track and behave like DVD */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2244 /* playback: only show subtitles if the user explicitely wants them. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2245 track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2246 if (demuxer->sub->id >= 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2247 track = demux_mkv_find_track_by_num (mkv_d, demuxer->sub->id,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2248 MATROSKA_TRACK_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2249 else if (dvdsub_lang != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2250 track = demux_mkv_find_track_by_language (mkv_d, dvdsub_lang,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2251 MATROSKA_TRACK_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2252
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2253 if (track && !demux_mkv_open_sub (demuxer, track))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2254 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2255 mp_msg (MSGT_DEMUX, MSGL_INFO,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2256 "[mkv] Will display subtitle track %u\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2257 demuxer->sub->id = track->tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2258 }
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2259 else
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2260 demuxer->sub->id = -2;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2261
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2262 if (mkv_d->chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2263 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2264 for (i=0; i < (int)mkv_d->num_chapters; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2265 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2266 mkv_d->chapters[i].start -= mkv_d->first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2267 mkv_d->chapters[i].end -= mkv_d->first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2268 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2269 if (dvd_last_chapter > 0 && dvd_last_chapter <= mkv_d->num_chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2270 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2271 if (mkv_d->chapters[dvd_last_chapter-1].end != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2272 mkv_d->stop_timecode = mkv_d->chapters[dvd_last_chapter-1].end;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2273 else if (dvd_last_chapter + 1 <= mkv_d->num_chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2274 mkv_d->stop_timecode = mkv_d->chapters[dvd_last_chapter].start;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2275 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2276 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2277
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2278 if (s->end_pos == 0 || (mkv_d->indexes == NULL && index_mode < 0))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2279 demuxer->seekable = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2280 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2281 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2282 demuxer->movi_start = s->start_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2283 demuxer->movi_end = s->end_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2284 demuxer->seekable = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2285 if (mkv_d->chapters && dvd_chapter>1 && dvd_chapter<=mkv_d->num_chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2286 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2287 if (!mkv_d->has_first_tc)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2288 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2289 mkv_d->first_tc = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2290 mkv_d->has_first_tc = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2291 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2292 demux_mkv_seek (demuxer,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2293 mkv_d->chapters[dvd_chapter-1].start/1000.0, 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2294 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2295 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2296
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2297 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2298 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2299
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2300 void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2301 demux_close_mkv (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2302 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2303 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2304
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2305 if (mkv_d)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2306 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2307 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2308 if (mkv_d->tracks)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2309 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2310 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2311 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2312 if (mkv_d->tracks[i]->codec_id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2313 free (mkv_d->tracks[i]->codec_id);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2314 if (mkv_d->tracks[i]->language)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2315 free (mkv_d->tracks[i]->language);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2316 if (mkv_d->tracks[i]->private_data)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2317 free (mkv_d->tracks[i]->private_data);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2318 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2319 for (i=0; i < SUB_MAX_TEXT; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2320 if (mkv_d->subs.text[i])
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2321 free (mkv_d->subs.text[i]);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2322 free (mkv_d->tracks);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2323 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2324 if (mkv_d->indexes)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2325 free (mkv_d->indexes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2326 if (mkv_d->cluster_positions)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2327 free (mkv_d->cluster_positions);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2328 if (mkv_d->chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2329 free (mkv_d->chapters);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2330 if (mkv_d->parsed_cues)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2331 free (mkv_d->parsed_cues);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2332 if (mkv_d->parsed_seekhead)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2333 free (mkv_d->parsed_seekhead);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2334 free (mkv_d);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2335 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2336 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2337
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2338 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2339 demux_mkv_read_block_lacing (uint8_t *buffer, uint64_t *size,
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2340 uint8_t *laces, uint32_t **all_lace_sizes)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2341 {
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2342 uint32_t total = 0, *lace_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2343 uint8_t flags;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2344 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2345
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2346 *all_lace_sizes = NULL;
13131
ab937f4a17ad Cosmetics: fix some compiler warnings.
mosu
parents: 13129
diff changeset
2347 lace_size = NULL;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2348 /* lacing flags */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2349 flags = *buffer++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2350 (*size)--;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2351
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2352 switch ((flags & 0x06) >> 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2353 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2354 case 0: /* no lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2355 *laces = 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2356 lace_size = (uint32_t *)calloc(*laces, sizeof(uint32_t));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2357 lace_size[0] = *size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2358 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2359
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2360 case 1: /* xiph lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2361 case 2: /* fixed-size lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2362 case 3: /* EBML lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2363 *laces = *buffer++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2364 (*size)--;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2365 (*laces)++;
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2366 lace_size = (uint32_t *)calloc(*laces, sizeof(uint32_t));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2367
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2368 switch ((flags & 0x06) >> 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2369 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2370 case 1: /* xiph lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2371 for (i=0; i < *laces-1; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2372 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2373 lace_size[i] = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2374 do
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2375 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2376 lace_size[i] += *buffer;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2377 (*size)--;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2378 } while (*buffer++ == 0xFF);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2379 total += lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2380 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2381 lace_size[i] = *size - total;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2382 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2383
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2384 case 2: /* fixed-size lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2385 for (i=0; i < *laces; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2386 lace_size[i] = *size / *laces;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2387 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2388
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2389 case 3: /* EBML lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2390 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2391 int l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2392 uint64_t num = ebml_read_vlen_uint (buffer, &l);
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2393 if (num == EBML_UINT_INVALID) {
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2394 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2395 return 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2396 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2397 buffer += l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2398 *size -= l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2399
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2400 total = lace_size[0] = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2401 for (i=1; i < *laces-1; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2402 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2403 int64_t snum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2404 snum = ebml_read_vlen_int (buffer, &l);
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2405 if (snum == EBML_INT_INVALID) {
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2406 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2407 return 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2408 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2409 buffer += l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2410 *size -= l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2411 lace_size[i] = lace_size[i-1] + snum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2412 total += lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2413 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2414 lace_size[i] = *size - total;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2415 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2416 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2417 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2418 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2419 }
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2420 *all_lace_sizes = lace_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2421 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2422 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2423
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2424 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2425 handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2426 int64_t size, uint64_t block_duration, uint64_t timecode)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2427 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2428 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2429 char *ptr1, *ptr2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2430 int state, i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2431
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2432 if (block_duration == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2433 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2434 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: No BlockDuration "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2435 "for subtitle track found.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2436 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2437 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2438
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2439 ptr1 = block;
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2440 while (ptr1 - block <= size && (*ptr1 == '\n' || *ptr1 == '\r'))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2441 ptr1++;
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2442 ptr2 = block + size - 1;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2443 while (ptr2 >= block && (*ptr2 == '\n' || *ptr2 == '\r'))
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2444 {
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2445 *ptr2 = 0;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2446 ptr2--;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2447 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2448
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2449 if (mkv_d->subs.lines > SUB_MAX_TEXT - 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2450 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2451 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: too many sublines "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2452 "to render, skipping\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2453 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2454 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2455 ptr2 = mkv_d->subs.text[mkv_d->subs.lines];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2456 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2457
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2458 if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2459 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2460 /* Find text section. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2461 for (i=0; i < 8 && *ptr1 != '\0'; ptr1++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2462 if (*ptr1 == ',')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2463 i++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2464 if (*ptr1 == '\0') /* Broken line? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2465 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2466
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2467 /* Load text. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2468 while (ptr1 - block < size)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2469 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2470 if (*ptr1 == '{')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2471 state = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2472 else if (*ptr1 == '}' && state == 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2473 state = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2474
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2475 if (state == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2476 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2477 *ptr2++ = *ptr1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2478 if (ptr2 - mkv_d->subs.text[mkv_d->subs.lines] >= 255)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2479 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2480 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2481 ptr1++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2482
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2483 /* Newline */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2484 if (*ptr1 == '\\' && ptr1+1-block < size && (*(ptr1+1)|0x20) == 'n')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2485 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2486 mkv_d->clear_subs_at[mkv_d->subs.lines++]
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2487 = timecode + block_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2488 *ptr2 = '\0';
11808
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2489 if (mkv_d->subs.lines >= SUB_MAX_TEXT)
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2490 {
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2491 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: too many "
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2492 "sublines to render, skipping\n");
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2493 return;
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2494 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2495 ptr2 = mkv_d->subs.text[mkv_d->subs.lines];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2496 ptr1 += 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2497 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2498
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2499 if (state == 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2500 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2501 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2502 *ptr2 = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2503 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2504 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2505 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2506 while (ptr1 - block != size)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2507 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2508 if (*ptr1 == '\n' || *ptr1 == '\r')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2509 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2510 if (state == 0) /* normal char --> newline */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2511 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2512 *ptr2 = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2513 mkv_d->clear_subs_at[mkv_d->subs.lines++]
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2514 = timecode + block_duration;
11808
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2515 if (mkv_d->subs.lines >= SUB_MAX_TEXT)
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2516 {
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2517 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: too many "
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2518 "sublines to render, skipping\n");
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2519 return;
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2520 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2521 ptr2 = mkv_d->subs.text[mkv_d->subs.lines];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2522 state = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2523 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2524 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2525 else if (*ptr1 == '<') /* skip HTML tags */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2526 state = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2527 else if (*ptr1 == '>')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2528 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2529 else if (state != 2) /* normal character */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2530 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2531 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2532 if ((ptr2 - mkv_d->subs.text[mkv_d->subs.lines]) < 255)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2533 *ptr2++ = *ptr1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2534 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2535 ptr1++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2536 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2537 *ptr2 = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2538 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2539 mkv_d->clear_subs_at[mkv_d->subs.lines++] = timecode + block_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2540
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2541 #ifdef USE_ICONV
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2542 subcp_recode1 (&mkv_d->subs);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2543 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2544 vo_sub = &mkv_d->subs;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2545 vo_osd_changed (OSDTYPE_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2546 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2547
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2548 static void
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2549 clear_subtitles(demuxer_t *demuxer, uint64_t timecode, int clear_all)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2550 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2551 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2552 int i, lines_cut = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2553 char *tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2554
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2555 /* Clear all? */
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2556 if (clear_all)
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2557 {
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2558 lines_cut = mkv_d->subs.lines;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2559 mkv_d->subs.lines = 0;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2560 if (lines_cut)
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2561 {
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2562 vo_sub = &mkv_d->subs;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2563 vo_osd_changed (OSDTYPE_SUBTITLE);
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2564 }
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2565 return;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2566 }
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2567
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2568 /* Clear the subtitles if they're obsolete now. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2569 for (i=0; i < mkv_d->subs.lines; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2570 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2571 if (mkv_d->clear_subs_at[i] <= timecode)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2572 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2573 tmp = mkv_d->subs.text[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2574 memmove (mkv_d->subs.text+i, mkv_d->subs.text+i+1,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2575 (mkv_d->subs.lines-i-1) * sizeof (*mkv_d->subs.text));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2576 memmove (mkv_d->clear_subs_at+i, mkv_d->clear_subs_at+i+1,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2577 (mkv_d->subs.lines-i-1) * sizeof (*mkv_d->clear_subs_at));
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2578 mkv_d->subs.text[--mkv_d->subs.lines] = tmp;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2579 i--;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2580 lines_cut = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2581 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2582 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2583 if (lines_cut)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2584 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2585 vo_sub = &mkv_d->subs;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2586 vo_osd_changed (OSDTYPE_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2587 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2588 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2589
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2590 // Taken from demux_real.c. Thanks to the original developpers :)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2591 #define SKIP_BITS(n) buffer <<= n
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2592 #define SHOW_BITS(n) ((buffer) >> (32 - (n)))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2593
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2594 static float real_fix_timestamp(mkv_track_t *track, unsigned char *s,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2595 int timestamp) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2596 float v_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2597 uint32_t buffer = (s[0] << 24) + (s[1] << 16) + (s[2] << 8) + s[3];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2598 int kf = timestamp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2599 int pict_type;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2600 int orig_kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2601
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2602 if (!strcmp(track->codec_id, MKV_V_REALV30) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2603 !strcmp(track->codec_id, MKV_V_REALV40)) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2604
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2605 if (!strcmp(track->codec_id, MKV_V_REALV30)) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2606 SKIP_BITS(3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2607 pict_type = SHOW_BITS(2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2608 SKIP_BITS(2 + 7);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2609 }else{
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2610 SKIP_BITS(1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2611 pict_type = SHOW_BITS(2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2612 SKIP_BITS(2 + 7 + 3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2613 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2614 kf = SHOW_BITS(13); // kf= 2*SHOW_BITS(12);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2615 orig_kf = kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2616 if (pict_type <= 1) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2617 // I frame, sync timestamps:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2618 track->rv_kf_base = timestamp - kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2619 mp_msg(MSGT_DEMUX, MSGL_V, "\nTS: base=%08X\n", track->rv_kf_base);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2620 kf = timestamp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2621 } else {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2622 // P/B frame, merge timestamps:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2623 int tmp = timestamp - track->rv_kf_base;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2624 kf |= tmp & (~0x1fff); // combine with packet timestamp
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2625 if (kf < (tmp - 4096)) // workaround wrap-around problems
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2626 kf += 8192;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2627 else if (kf > (tmp + 4096))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2628 kf -= 8192;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2629 kf += track->rv_kf_base;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2630 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2631 if (pict_type != 3) { // P || I frame -> swap timestamps
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2632 int tmp = kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2633 kf = track->rv_kf_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2634 track->rv_kf_pts = tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2635 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2636 mp_msg(MSGT_DEMUX, MSGL_V, "\nTS: %08X -> %08X (%04X) %d %02X %02X %02X "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2637 "%02X %5d\n", timestamp, kf, orig_kf, pict_type, s[0], s[1], s[2],
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2638 s[3], kf - (int)(1000.0 * track->rv_pts));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2639 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2640 v_pts = kf * 0.001f;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2641 track->rv_pts = v_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2642
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2643 return v_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2644 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2645
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2646 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2647 handle_realvideo (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2648 uint32_t size, int block_bref)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2649 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2650 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2651 demux_packet_t *dp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2652 dp_hdr_t *hdr;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2653 uint8_t chunks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2654 int isize;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2655
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2656 chunks = *buffer++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2657 isize = --size - (chunks+1)*8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2658 dp = new_demux_packet (sizeof (*hdr) + size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2659 memcpy (dp->buffer + sizeof(*hdr), buffer + (chunks+1)*8, isize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2660 memcpy (dp->buffer + sizeof(*hdr) + isize, buffer, (chunks+1)*8);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2661
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2662 hdr = (dp_hdr_t *) dp->buffer;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2663 hdr->len = isize;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2664 hdr->chunks = chunks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2665 hdr->timestamp = mkv_d->last_pts * 1000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2666 hdr->chunktab = sizeof(*hdr) + isize;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2667
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2668 dp->len = sizeof(*hdr) + size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2669 if (mkv_d->v_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2670 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2671 dp->pts = mkv_d->last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2672 track->rv_kf_base = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2673 track->rv_kf_pts = hdr->timestamp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2674 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2675 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2676 dp->pts = real_fix_timestamp (track, dp->buffer + sizeof(*hdr),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2677 hdr->timestamp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2678 dp->pos = demuxer->filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2679 dp->flags = block_bref ? 0 : 0x10;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2680
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2681 ds_add_packet(demuxer->video, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2682 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2683
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2684 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2685 handle_realaudio (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2686 uint32_t size, int block_bref)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2687 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2688 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2689 demux_packet_t *dp = new_demux_packet (size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2690
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2691 memcpy (dp->buffer, buffer, size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2692 if (track->ra_pts == mkv_d->last_pts && !mkv_d->a_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2693 dp->pts = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2694 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2695 dp->pts = mkv_d->last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2696 track->ra_pts = mkv_d->last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2697
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2698 dp->pos = demuxer->filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2699 dp->flags = block_bref ? 0 : 0x10;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2700 ds_add_packet (demuxer->audio, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2701 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2702
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2703 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2704 handle_block (demuxer_t *demuxer, uint8_t *block, uint64_t length,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2705 uint64_t block_duration, int64_t block_bref)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2706 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2707 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2708 mkv_track_t *track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2709 demux_stream_t *ds = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2710 uint64_t old_length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2711 int64_t tc;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2712 uint32_t *lace_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2713 uint8_t laces;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2714 int i, num, tmp, use_this_block = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2715 float current_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2716 int16_t time;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2717
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2718 /* first byte(s): track num */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2719 num = ebml_read_vlen_uint (block, &tmp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2720 block += tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2721 /* time (relative to cluster time) */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2722 time = be2me_16 (* (int16_t *) block);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2723 block += 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2724 length -= tmp + 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2725 old_length = length;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2726 if (demux_mkv_read_block_lacing (block, &length, &laces, &lace_size))
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2727 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2728 block += old_length - length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2729
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2730 tc = ((time*mkv_d->tc_scale+mkv_d->cluster_tc) /1000000.0 - mkv_d->first_tc);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2731 if (tc < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2732 tc = 0;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2733 if (mkv_d->stop_timecode > 0 && tc > mkv_d->stop_timecode) {
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2734 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2735 return -1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2736 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2737 current_pts = tc / 1000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2738
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2739 clear_subtitles(demuxer, tc, 0);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2740
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2741 for (i=0; i<mkv_d->num_tracks; i++)
12721
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2742 if (mkv_d->tracks[i]->tnum == num) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2743 track = mkv_d->tracks[i];
12721
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2744 break;
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2745 }
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2746 if (track == NULL)
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2747 {
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2748 free(lace_size);
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2749 return 1;
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2750 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2751 if (num == demuxer->audio->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2752 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2753 ds = demuxer->audio;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2754
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2755 if (mkv_d->a_skip_to_keyframe && block_bref != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2756 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2757 else if (mkv_d->v_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2758 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2759
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2760 if (track->fix_i_bps && use_this_block)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2761 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2762 sh_audio_t *sh = (sh_audio_t *) ds->sh;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2763
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2764 if (block_duration != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2765 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2766 sh->i_bps = length * 1000 / block_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2767 track->fix_i_bps = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2768 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2769 else if (track->qt_last_a_pts == 0.0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2770 track->qt_last_a_pts = current_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2771 else if(track->qt_last_a_pts != current_pts)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2772 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2773 sh->i_bps = length / (current_pts - track->qt_last_a_pts);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2774 track->fix_i_bps = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2775 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2776 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2777 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2778 else if (tc < mkv_d->skip_to_timecode)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2779 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2780 else if (num == demuxer->video->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2781 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2782 ds = demuxer->video;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2783 if (mkv_d->v_skip_to_keyframe && block_bref != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2784 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2785 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2786 else if (num == demuxer->sub->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2787 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2788 ds = demuxer->sub;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2789 if (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2790 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2791 if (!mkv_d->v_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2792 handle_subtitles (demuxer, track, block, length,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2793 block_duration, tc);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2794 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2795 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2796 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2797 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2798 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2799
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2800 if (use_this_block)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2801 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2802 mkv_d->last_pts = ds->pts = current_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2803 mkv_d->last_filepos = demuxer->filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2804
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2805 for (i=0; i < laces; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2806 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2807 if (ds == demuxer->video && track->realmedia)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2808 handle_realvideo (demuxer, track, block, lace_size[i], block_bref);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2809 else if (ds == demuxer->audio && track->realmedia)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2810 handle_realaudio (demuxer, track, block, lace_size[i], block_bref);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2811 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2812 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2813 int modified, size = lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2814 demux_packet_t *dp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2815 uint8_t *buffer;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2816 modified = demux_mkv_decode (track, block, &buffer, &size, 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2817 if (buffer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2818 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2819 dp = new_demux_packet (size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2820 memcpy (dp->buffer, buffer, size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2821 if (modified)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2822 free (buffer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2823 dp->flags = block_bref == 0 ? 1 : 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2824 dp->pts = mkv_d->last_pts + i * track->default_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2825 ds_add_packet (ds, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2826 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2827 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2828 block += lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2829 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2830
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2831 if (ds == demuxer->video)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2832 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2833 mkv_d->v_skip_to_keyframe = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2834 mkv_d->skip_to_timecode = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2835 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2836 else if (ds == demuxer->audio)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2837 mkv_d->a_skip_to_keyframe = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2838
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2839 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2840 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2841 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2842
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2843 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2844 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2845 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2846
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2847 int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2848 demux_mkv_fill_buffer (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2849 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2850 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2851 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2852 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2853 int il, tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2854
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2855 while (1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2856 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2857 while (mkv_d->cluster_size > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2858 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2859 uint64_t block_duration = 0, block_length = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2860 int64_t block_bref = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2861 uint8_t *block = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2862
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2863 while (mkv_d->blockgroup_size > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2864 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2865 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2866 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2867 case MATROSKA_ID_BLOCKDURATION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2868 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2869 block_duration = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2870 if (block_duration == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2871 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2872 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2873 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2874
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2875 case MATROSKA_ID_BLOCK:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2876 block_length = ebml_read_length (s, &tmp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2877 block = (uint8_t *) malloc (block_length);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2878 demuxer->filepos = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2879 if (stream_read (s,block,block_length) != (int) block_length)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2880 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2881 l = tmp + block_length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2882 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2883
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2884 case MATROSKA_ID_REFERENCEBLOCK:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2885 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2886 int64_t num = ebml_read_int (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2887 if (num == EBML_INT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2888 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2889 if (num < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2890 block_bref = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2891 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2892 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2893
11934
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
2894 case EBML_ID_INVALID:
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
2895 return 0;
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
2896
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2897 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2898 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2899 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2900 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2901 mkv_d->blockgroup_size -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2902 mkv_d->cluster_size -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2903 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2904
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2905 if (block)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2906 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2907 int res = handle_block (demuxer, block, block_length,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2908 block_duration, block_bref);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2909 free (block);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2910 if (res < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2911 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2912 if (res)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2913 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2914 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2915
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2916 if (mkv_d->cluster_size > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2917 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2918 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2919 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2920 case MATROSKA_ID_CLUSTERTIMECODE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2921 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2922 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2923 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2924 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2925 if (!mkv_d->has_first_tc)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2926 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2927 mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2928 mkv_d->has_first_tc = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2929 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2930 mkv_d->cluster_tc = num * mkv_d->tc_scale;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2931 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2932 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2933
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2934 case MATROSKA_ID_BLOCKGROUP:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2935 mkv_d->blockgroup_size = ebml_read_length (s, &tmp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2936 l = tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2937 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2938
11934
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
2939 case EBML_ID_INVALID:
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
2940 return 0;
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
2941
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2942 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2943 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2944 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2945 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2946 mkv_d->cluster_size -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2947 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2948 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2949
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2950 if (ebml_read_id (s, &il) != MATROSKA_ID_CLUSTER)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2951 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2952 add_cluster_position(mkv_d, stream_tell(s)-il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2953 mkv_d->cluster_size = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2954 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2955
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2956 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2957 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2958
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2959 void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2960 demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, int flags)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2961 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2962 if (!(flags & 2)) /* time in secs */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2963 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2964 void resync_audio_stream(sh_audio_t *sh_audio);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2965 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2966 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2967 int64_t target_timecode = 0, diff, min_diff=0xFFFFFFFL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2968 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2969
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2970 if (!(flags & 1)) /* relative seek */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2971 target_timecode = (int64_t) (mkv_d->last_pts * 1000.0);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2972 target_timecode += (int64_t)(rel_seek_secs * 1000.0);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2973 if (target_timecode < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2974 target_timecode = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2975
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2976 if (mkv_d->indexes == NULL) /* no index was found */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2977 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2978 uint64_t target_filepos, cluster_pos, max_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2979
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2980 target_filepos = (uint64_t) (target_timecode * mkv_d->last_filepos
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2981 / (mkv_d->last_pts * 1000.0));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2982
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2983 max_pos = mkv_d->cluster_positions[mkv_d->num_cluster_pos-1];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2984 if (target_filepos > max_pos)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2985 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2986 if ((off_t) max_pos > stream_tell (s))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2987 stream_seek (s, max_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2988 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2989 stream_seek (s, stream_tell (s) + mkv_d->cluster_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2990 /* parse all the clusters upto target_filepos */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2991 while (!s->eof && stream_tell(s) < (off_t) target_filepos)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2992 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2993 switch (ebml_read_id (s, &i))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2994 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2995 case MATROSKA_ID_CLUSTER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2996 add_cluster_position(mkv_d, (uint64_t) stream_tell(s)-i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2997 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2998
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2999 case MATROSKA_ID_CUES:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3000 demux_mkv_read_cues (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3001 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3002 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3003 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3004 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3005 if (s->eof)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3006 stream_reset(s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3007 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3008
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3009 if (mkv_d->indexes == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3010 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3011 cluster_pos = mkv_d->cluster_positions[0];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3012 /* Let's find the nearest cluster */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3013 for (i=0; i < mkv_d->num_cluster_pos; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3014 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3015 diff = mkv_d->cluster_positions[i] - target_filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3016 if (rel_seek_secs < 0 && diff < 0 && -diff < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3017 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3018 cluster_pos = mkv_d->cluster_positions[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3019 min_diff = -diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3020 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3021 else if (rel_seek_secs > 0
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3022 && (diff < 0 ? -1 * diff : diff) < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3023 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3024 cluster_pos = mkv_d->cluster_positions[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3025 min_diff = diff < 0 ? -1 * diff : diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3026 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3027 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3028 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3029 stream_seek (s, cluster_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3030 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3031 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3032 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3033 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3034 mkv_index_t *index = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3035
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3036 /* let's find the entry in the indexes with the smallest */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3037 /* difference to the wanted timecode. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3038 for (i=0; i < mkv_d->num_indexes; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3039 if (mkv_d->indexes[i].tnum == demuxer->video->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3040 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3041 diff = target_timecode - (int64_t) mkv_d->indexes[i].timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3042
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3043 if ((flags & 1 || target_timecode <= mkv_d->last_pts*1000)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3044 && diff >= 0 && diff < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3045 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3046 min_diff = diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3047 index = mkv_d->indexes + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3048 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3049 else if (target_timecode > mkv_d->last_pts*1000
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3050 && diff < 0 && -diff < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3051 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3052 min_diff = -diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3053 index = mkv_d->indexes + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3054 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3055 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3056
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3057 if (index) /* We've found an entry. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3058 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3059 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3060 stream_seek (s, index->filepos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3061 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3062 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3063
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3064 if (demuxer->video->id >= 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3065 mkv_d->v_skip_to_keyframe = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3066 if (rel_seek_secs > 0.0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3067 mkv_d->skip_to_timecode = target_timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3068 mkv_d->a_skip_to_keyframe = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3069
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3070 /* Clear subtitles. */
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3071 if (target_timecode <= mkv_d->last_pts * 1000)
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3072 clear_subtitles(demuxer, 0, 1);
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3073
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3074 demux_mkv_fill_buffer(demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3075
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3076 if(demuxer->audio->sh != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3077 resync_audio_stream((sh_audio_t *) demuxer->audio->sh);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3078 }
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3079 else if ((demuxer->movi_end <= 0) || !(flags & 1))
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3080 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3081 else
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3082 {
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3083 void resync_audio_stream(sh_audio_t *sh_audio);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3084 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3085 stream_t *s = demuxer->stream;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3086 uint64_t target_filepos;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3087 mkv_index_t *index = NULL;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3088 int i;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3089
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3090 if (mkv_d->indexes == NULL) /* no index was found */
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3091 { /* I'm lazy... */
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3092 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3093 return;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3094 }
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3095
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3096 target_filepos = (uint64_t)(demuxer->movi_end * rel_seek_secs);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3097 for (i=0; i < mkv_d->num_indexes; i++)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3098 if (mkv_d->indexes[i].tnum == demuxer->video->id)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3099 if ((index == NULL) ||
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3100 ((mkv_d->indexes[i].filepos >= target_filepos) &&
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3101 ((index->filepos < target_filepos) ||
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3102 (mkv_d->indexes[i].filepos < index->filepos))))
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3103 index = &mkv_d->indexes[i];
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3104
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3105 if (!index)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3106 return;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3107
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3108 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3109 stream_seek (s, index->filepos);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3110
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3111 if (demuxer->video->id >= 0)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3112 mkv_d->v_skip_to_keyframe = 1;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3113 mkv_d->skip_to_timecode = index->timecode;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3114 mkv_d->a_skip_to_keyframe = 1;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3115
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3116 /* Clear subtitles. */
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3117 if (index->timecode <= mkv_d->last_pts * 1000)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3118 clear_subtitles(demuxer, 0, 1);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3119
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3120 demux_mkv_fill_buffer(demuxer);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3121
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3122 if(demuxer->audio->sh != NULL)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3123 resync_audio_stream((sh_audio_t *) demuxer->audio->sh);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3124 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3125 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3126
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3127 int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3128 demux_mkv_control (demuxer_t *demuxer, int cmd, void *arg)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3129 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3130 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3131
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3132 switch (cmd)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3133 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3134 case DEMUXER_CTRL_GET_TIME_LENGTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3135 if (mkv_d->duration == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3136 return DEMUXER_CTRL_DONTKNOW;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3137
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3138 *((unsigned long *)arg) = (unsigned long)mkv_d->duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3139 return DEMUXER_CTRL_OK;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3140
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3141 case DEMUXER_CTRL_GET_PERCENT_POS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3142 if (mkv_d->duration == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3143 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3144 if (demuxer->movi_start == demuxer->movi_end)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3145 return DEMUXER_CTRL_DONTKNOW;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3146
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3147 *((int *)arg) = (int)((demuxer->filepos - demuxer->movi_start) /
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3148 ((demuxer->movi_end-demuxer->movi_start)/100));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3149 return DEMUXER_CTRL_OK;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3150 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3151
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3152 *((int *) arg) = (int) (100 * mkv_d->last_pts / mkv_d->duration);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3153 return DEMUXER_CTRL_OK;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3154
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3155 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3156 return DEMUXER_CTRL_NOTIMPL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3157 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3158 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3159
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3160 /** \brief Return the number of subtitle tracks in the file.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3161
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3162 \param demuxer The demuxer for which the number of subtitle tracks
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3163 should be returned.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3164 */
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3165 int
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3166 demux_mkv_num_subs (demuxer_t *demuxer)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3167 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3168 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3169 int i, num;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3170
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3171 num = 0;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3172 for (i = 0; i < mkv_d->num_tracks; i++)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3173 if ((mkv_d->tracks[i]->type == MATROSKA_TRACK_SUBTITLE) &&
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3174 (mkv_d->tracks[i]->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3175 num++;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3176
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3177 return num;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3178 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3179
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3180 /** \brief Change the current subtitle track and return its ID.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3181
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3182 Changes the current subtitle track. If the new subtitle track is a
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3183 VobSub track then the SPU decoder will be re-initialized.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3184
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3185 \param demuxer The demuxer whose subtitle track will be changed.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3186 \param new_num The number of the new subtitle track. The number must be
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3187 between 0 and demux_mkv_num_subs - 1.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3188
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3189 \returns The Matroska track number of the newly selected track.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3190 */
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3191 int
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3192 demux_mkv_change_subs (demuxer_t *demuxer, int new_num)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3193 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3194 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3195 mkv_track_t *track;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3196 int i, num;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3197
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3198 num = 0;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3199 track = NULL;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3200 for (i = 0; i < mkv_d->num_tracks; i++)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3201 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3202 if ((mkv_d->tracks[i]->type == MATROSKA_TRACK_SUBTITLE) &&
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3203 (mkv_d->tracks[i]->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3204 num++;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3205 if (num == (new_num + 1))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3206 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3207 track = mkv_d->tracks[i];
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3208 break;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3209 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3210 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3211 if (track == NULL)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3212 return -1;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3213
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3214 if (demuxer->sub->sh == NULL)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3215 demuxer->sub->sh = malloc(sizeof(mkv_sh_sub_t));
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3216 if (demuxer->sub->sh != NULL)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3217 memcpy(demuxer->sub->sh, &track->sh_sub, sizeof(mkv_sh_sub_t));
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3218
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3219 return track->tnum;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3220 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3221
13129
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3222 /** \brief Get the language code for a subtitle track.
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3223
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3224 Retrieves the language code for a subtitle track if it is known.
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3225 If the language code is "und" then do not copy it ("und" = "undefined").
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3226
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3227 \param demuxer The demuxer to work on
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3228 \param track_num The n'th subtitle track to get the language from
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3229 \param lang Store the language here
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3230 \param maxlen The maximum number of characters to copy into lang
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3231 */
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3232 void
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3233 demux_mkv_get_sub_lang(demuxer_t *demuxer, int track_num, char *lang,
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3234 int maxlen)
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3235 {
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3236 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3237 mkv_track_t *track;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3238 int i, num;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3239
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3240 num = 0;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3241 for (i = 0; i < mkv_d->num_tracks; i++)
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3242 {
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3243 track = mkv_d->tracks[i];
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3244 if (track->type == MATROSKA_TRACK_SUBTITLE)
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3245 num++;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3246 if (num == (track_num + 1))
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3247 {
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3248 if ((track->language != NULL) &&
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3249 strcmp(track->language, "und"))
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3250 strncpy(lang, track->language, maxlen);
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3251 return;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3252 }
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3253 }
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3254 }
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3255
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3256 #endif /* HAVE_MATROSKA */