Mercurial > mplayer.hg
annotate libmpdemux/demux_ogg.c @ 12321:a7221e8a5a76
English messages removed, comments summarized.
author | diego |
---|---|
date | Tue, 27 Apr 2004 16:24:31 +0000 |
parents | c9e1fe032d10 |
children | af557de9daee |
rev | line source |
---|---|
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
2 #include "config.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
3 |
7413 | 4 #ifdef HAVE_OGGVORBIS |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
5 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
6 #include <stdlib.h> |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
7 #include <stdio.h> |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
8 #include <string.h> |
10092 | 9 #include <assert.h> |
10 #include <math.h> | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
11 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
12 #include "../mp_msg.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
13 #include "../help_mp.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
14 #include "stream.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
15 #include "demuxer.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
16 #include "stheader.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
17 |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8123
diff
changeset
|
18 #ifdef TREMOR |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8123
diff
changeset
|
19 #include <tremor/ogg.h> |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8123
diff
changeset
|
20 #include <tremor/ivorbiscodec.h> |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8123
diff
changeset
|
21 #else |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
22 #include <ogg/ogg.h> |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
23 #include <vorbis/codec.h> |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8123
diff
changeset
|
24 #endif |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
25 |
10092 | 26 #ifdef HAVE_OGGTHEORA |
27 #include <theora/theora.h> | |
28 #endif | |
29 | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
30 #define BLOCK_SIZE 4096 |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
31 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
32 /// Vorbis decoder context : we need the vorbis_info for vorbis timestamping |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
33 /// Shall we put this struct def in a common header ? |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
34 typedef struct ov_struct_st { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
35 vorbis_info vi; /* struct that stores all the static vorbis bitstream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
36 settings */ |
8375
22cbd7bcc6bf
Really (!) sync ov_struct_st between demux_ogg.c and ad_libvorbis.c
rguyom
parents:
8374
diff
changeset
|
37 vorbis_comment vc; /* struct that stores all the bitstream user comments */ |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
38 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
39 vorbis_block vb; /* local working space for packet->PCM decode */ |
8374
99ac11458d23
Sync ov_struct_st between demux_ogg.c and ad_libvorbis.c
rguyom
parents:
8342
diff
changeset
|
40 float rg_scale; /* replaygain scale */ |
99ac11458d23
Sync ov_struct_st between demux_ogg.c and ad_libvorbis.c
rguyom
parents:
8342
diff
changeset
|
41 #ifdef TREMOR |
99ac11458d23
Sync ov_struct_st between demux_ogg.c and ad_libvorbis.c
rguyom
parents:
8342
diff
changeset
|
42 int rg_scale_int; |
99ac11458d23
Sync ov_struct_st between demux_ogg.c and ad_libvorbis.c
rguyom
parents:
8342
diff
changeset
|
43 #endif |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
44 } ov_struct_t; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
45 |
10092 | 46 /* Theora decoder context : we won't be able to interpret granule positions |
47 * without using theora_granule_time with the theora_state of the stream. | |
48 * This is duplicated in `vd_theora.c'; put this in a common header? | |
49 */ | |
50 #ifdef HAVE_OGGTHEORA | |
51 typedef struct theora_struct_st { | |
52 theora_state st; | |
10658
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
53 theora_comment cc; |
10092 | 54 theora_info inf; |
55 } theora_struct_t; | |
56 #endif | |
57 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
58 //// OggDS headers |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
59 // Header for the new header format |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
60 typedef struct stream_header_video |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
61 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
62 ogg_int32_t width; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
63 ogg_int32_t height; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
64 } stream_header_video; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
65 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
66 typedef struct stream_header_audio |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
67 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
68 ogg_int16_t channels; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
69 ogg_int16_t blockalign; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
70 ogg_int32_t avgbytespersec; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
71 } stream_header_audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
72 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
73 typedef struct stream_header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
74 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
75 char streamtype[8]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
76 char subtype[4]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
77 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
78 ogg_int32_t size; // size of the structure |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
79 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
80 ogg_int64_t time_unit; // in reference time |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
81 ogg_int64_t samples_per_unit; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
82 ogg_int32_t default_len; // in media time |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
83 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
84 ogg_int32_t buffersize; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
85 ogg_int16_t bits_per_sample; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
86 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
87 union |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
88 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
89 // Video specific |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
90 stream_header_video video; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
91 // Audio specific |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
92 stream_header_audio audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
93 } sh; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
94 } stream_header; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
95 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
96 /// Our private datas |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
97 |
5732 | 98 typedef struct ogg_syncpoint { |
99 int64_t granulepos; | |
100 off_t page_pos; | |
101 } ogg_syncpoint_t; | |
102 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
103 /// A logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
104 typedef struct ogg_stream { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
105 /// Timestamping stuff |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
106 float samplerate; /// granulpos 2 time |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
107 int64_t lastpos; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
108 int32_t lastsize; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
109 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
110 // Logical stream state |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
111 ogg_stream_state stream; |
5732 | 112 int hdr_packets; |
113 int vorbis; | |
10092 | 114 int theora; |
11004 | 115 int flac; |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
116 int text; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
117 } ogg_stream_t; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
118 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
119 typedef struct ogg_demuxer { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
120 /// Physical stream state |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
121 ogg_sync_state sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
122 /// Current page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
123 ogg_page page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
124 /// Logical streams |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
125 ogg_stream_t *subs; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
126 int num_sub; |
5732 | 127 ogg_syncpoint_t* syncpoints; |
128 int num_syncpoint; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
129 off_t pos, last_size; |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
130 int64_t final_granulepos; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
131 } ogg_demuxer_t; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
132 |
5732 | 133 #define NUM_VORBIS_HDR_PACKETS 3 |
134 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
135 /// Some defines from OggDS |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
136 #define PACKET_TYPE_HEADER 0x01 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
137 #define PACKET_TYPE_BITS 0x07 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
138 #define PACKET_LEN_BITS01 0xc0 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
139 #define PACKET_LEN_BITS2 0x02 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
140 #define PACKET_IS_SYNCPOINT 0x08 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
141 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
142 extern int index_mode; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
143 |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
144 extern char *dvdsub_lang, *audio_lang; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
145 |
7010 | 146 //-------- subtitle support - should be moved to decoder layer, and queue |
147 // - subtitles up in demuxer buffer... | |
148 | |
149 #include "../subreader.h" | |
150 #include "../libvo/sub.h" | |
151 #define OGG_SUB_MAX_LINE 128 | |
152 | |
153 static subtitle ogg_sub; | |
154 extern subtitle* vo_sub; | |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
155 static float clear_sub; |
7010 | 156 //FILE* subout; |
157 | |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
158 static |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
159 uint16_t get_uint16 (const void *buf) |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
160 { |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
161 uint16_t ret; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
162 unsigned char *tmp; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
163 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
164 tmp = (unsigned char *) buf; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
165 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
166 ret = tmp[1] & 0xff; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
167 ret = (ret << 8) + (tmp[0] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
168 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
169 return (ret); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
170 } |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
171 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
172 static |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
173 uint32_t get_uint32 (const void *buf) |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
174 { |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
175 uint32_t ret; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
176 unsigned char *tmp; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
177 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
178 tmp = (unsigned char *) buf; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
179 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
180 ret = tmp[3] & 0xff; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
181 ret = (ret << 8) + (tmp[2] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
182 ret = (ret << 8) + (tmp[1] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
183 ret = (ret << 8) + (tmp[0] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
184 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
185 return (ret); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
186 } |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
187 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
188 static |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
189 uint64_t get_uint64 (const void *buf) |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
190 { |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
191 uint64_t ret; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
192 unsigned char *tmp; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
193 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
194 tmp = (unsigned char *) buf; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
195 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
196 ret = tmp[7] & 0xff; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
197 ret = (ret << 8) + (tmp[6] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
198 ret = (ret << 8) + (tmp[5] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
199 ret = (ret << 8) + (tmp[4] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
200 ret = (ret << 8) + (tmp[3] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
201 ret = (ret << 8) + (tmp[2] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
202 ret = (ret << 8) + (tmp[1] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
203 ret = (ret << 8) + (tmp[0] & 0xff); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
204 |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
205 return (ret); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
206 } |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
207 |
7010 | 208 void demux_ogg_init_sub () { |
209 int lcv; | |
210 if(!ogg_sub.text[0]) // not yet allocated | |
211 for (lcv = 0; lcv < SUB_MAX_TEXT; lcv++) { | |
212 ogg_sub.text[lcv] = (char*)malloc(OGG_SUB_MAX_LINE); | |
213 } | |
214 } | |
215 | |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
216 void demux_ogg_add_sub (ogg_stream_t* os,ogg_packet* pack) { |
7010 | 217 int lcv; |
218 int line_pos = 0; | |
219 int ignoring = 0; | |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
220 char *packet = pack->packet; |
7010 | 221 |
222 mp_msg(MSGT_DEMUX,MSGL_DBG2,"\ndemux_ogg_add_sub %02X %02X %02X '%s'\n", | |
223 (unsigned char)packet[0], | |
224 (unsigned char)packet[1], | |
225 (unsigned char)packet[2], | |
226 &packet[3]); | |
227 | |
228 ogg_sub.lines = 0; | |
229 if (((unsigned char)packet[0]) == 0x88) { // some subtitle text | |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
230 // Find data start |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
231 int32_t duration = 0; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
232 int16_t hdrlen = (*packet & PACKET_LEN_BITS01)>>6, i; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
233 hdrlen |= (*packet & PACKET_LEN_BITS2) <<1; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
234 lcv = 1 + hdrlen; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
235 for (i = hdrlen; i > 0; i--) { |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
236 duration <<= 8; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
237 duration |= (unsigned char)packet[i]; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
238 } |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
239 if ((hdrlen > 0) && (duration > 0)) { |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
240 float pts; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
241 if(pack->granulepos == -1) |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
242 pack->granulepos = os->lastpos + os->lastsize; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
243 pts = (float)pack->granulepos/(float)os->samplerate; |
12264
070cc45bef28
Clear subs in broken OGM files (those without empty subtitle packets) a bit later in order to avoid flickering if there are more subs following immediately. Patch by Michael Reinsch <mr at uue adot org>
mosu
parents:
12263
diff
changeset
|
244 clear_sub = 1.0 + pts + (float)duration/1000.0; |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
245 } |
7010 | 246 while (1) { |
247 int c = packet[lcv++]; | |
7115
55716603988c
fixes problems when new line is just '\n' and not '\r\n' and enabled html-markup ignore. Patch by Piotr Krukowiecki <piotr@pingu.ii.uj.edu.pl>
alex
parents:
7010
diff
changeset
|
248 if(c=='\n' || c==0 || line_pos >= OGG_SUB_MAX_LINE-1){ |
7010 | 249 ogg_sub.text[ogg_sub.lines][line_pos] = 0; // close sub |
250 if(line_pos) ogg_sub.lines++; | |
251 if(!c || ogg_sub.lines>=SUB_MAX_TEXT) break; // EOL or TooMany | |
252 line_pos = 0; | |
253 } | |
254 switch (c) { | |
255 case '\r': | |
256 case '\n': // just ignore linefeeds for now | |
257 // their placement seems rather haphazard | |
258 break; | |
259 case '<': // some html markup, ignore for now | |
260 ignoring = 1; | |
261 break; | |
262 case '>': | |
263 ignoring = 0; | |
264 break; | |
265 default: | |
7115
55716603988c
fixes problems when new line is just '\n' and not '\r\n' and enabled html-markup ignore. Patch by Piotr Krukowiecki <piotr@pingu.ii.uj.edu.pl>
alex
parents:
7010
diff
changeset
|
266 if(!ignoring) |
7010 | 267 ogg_sub.text[ogg_sub.lines][line_pos++] = c; |
268 break; | |
269 } | |
270 } | |
271 } | |
272 | |
273 mp_msg(MSGT_DEMUX,MSGL_DBG2,"ogg sub lines: %d first: '%s'\n", | |
274 ogg_sub.lines, ogg_sub.text[0]); | |
8618
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
275 #ifdef USE_ICONV |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
276 subcp_recode1(&ogg_sub); |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
277 #endif |
7010 | 278 vo_sub = &ogg_sub; |
279 vo_osd_changed(OSDTYPE_SUBTITLE); | |
280 } | |
281 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
282 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
283 // get the logical stream of the current page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
284 // fill os if non NULL and return the stream id |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
285 static int demux_ogg_get_page_stream(ogg_demuxer_t* ogg_d,ogg_stream_state** os) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
286 int id,s_no; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
287 ogg_page* page = &ogg_d->page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
288 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
289 s_no = ogg_page_serialno(page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
290 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
291 for(id= 0; id < ogg_d->num_sub ; id++) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
292 if(s_no == ogg_d->subs[id].stream.serialno) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
293 break; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
294 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
295 |
10363 | 296 if(id == ogg_d->num_sub) { |
297 // If we have only one vorbis stream allow the stream id to change | |
298 // it's normal on radio stream (each song have an different id). | |
299 // But we (or the codec?) should check that the samplerate, etc | |
300 // doesn't change (for radio stream it's ok) | |
301 if(ogg_d->num_sub == 1 && ogg_d->subs[0].vorbis) { | |
302 ogg_stream_reset(&ogg_d->subs[0].stream); | |
303 ogg_stream_init(&ogg_d->subs[0].stream,s_no); | |
304 id = 0; | |
305 } else | |
306 return -1; | |
307 } | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
308 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
309 if(os) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
310 *os = &ogg_d->subs[id].stream; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
311 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
312 return id; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
313 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
314 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
315 |
10092 | 316 static unsigned char* demux_ogg_read_packet(ogg_stream_t* os,ogg_packet* pack,void *context,float* pts,int* flags) { |
5732 | 317 unsigned char* data; |
318 | |
319 *pts = 0; | |
320 *flags = 0; | |
321 | |
322 if(os->vorbis) { | |
323 data = pack->packet; | |
324 if(*pack->packet & PACKET_TYPE_HEADER) | |
325 os->hdr_packets++; | |
10092 | 326 else if (context ) |
327 { | |
328 vorbis_info *vi = &((ov_struct_t*)context)->vi; | |
329 | |
11000 | 330 // When we dump the audio, there is no vi, but we don't care of timestamp in this case |
10092 | 331 int32_t blocksize = vorbis_packet_blocksize(vi,pack) / vi->channels; |
332 // Calculate the timestamp if the packet don't have any | |
333 if(pack->granulepos == -1) { | |
334 pack->granulepos = os->lastpos; | |
335 if(os->lastsize > 0) | |
336 pack->granulepos += os->lastsize; | |
337 } | |
338 *pts = pack->granulepos / (float)vi->rate; | |
339 os->lastsize = blocksize; | |
340 os->lastpos = pack->granulepos; | |
5732 | 341 } |
10092 | 342 # ifdef HAVE_OGGTHEORA |
343 } else if (os->theora) { | |
344 /* we pass complete packets to theora, mustn't strip the header! */ | |
345 data = pack->packet; | |
346 os->lastsize = 1; | |
347 | |
10711
bc1aad87439a
Fix for Theora files without audio. Patch by David Kuehling <dvdkhlng@gmx.de>.
mosu
parents:
10658
diff
changeset
|
348 /* header packets beginn on 1-bit: thus check (*data&0x80). We don't |
bc1aad87439a
Fix for Theora files without audio. Patch by David Kuehling <dvdkhlng@gmx.de>.
mosu
parents:
10658
diff
changeset
|
349 have theora_state st, until all header packets were passed to the |
bc1aad87439a
Fix for Theora files without audio. Patch by David Kuehling <dvdkhlng@gmx.de>.
mosu
parents:
10658
diff
changeset
|
350 decoder. */ |
bc1aad87439a
Fix for Theora files without audio. Patch by David Kuehling <dvdkhlng@gmx.de>.
mosu
parents:
10658
diff
changeset
|
351 if (context != NULL && !(*data&0x80)) |
10092 | 352 { |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
353 theora_info *thi = ((theora_struct_t*)context)->st.i; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
354 int keyframe_granule_shift=_ilog(thi->keyframe_frequency_force-1); |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
355 int64_t iframemask = (1 << keyframe_granule_shift) - 1; |
10092 | 356 |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
357 if (pack->granulepos >= 0) |
10092 | 358 { |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
359 os->lastpos = pack->granulepos >> keyframe_granule_shift; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
360 os->lastpos += pack->granulepos & iframemask; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
361 *flags = ((pack->granulepos & iframemask) == 0); |
10092 | 362 } |
363 else | |
364 { | |
365 os->lastpos++; | |
366 } | |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
367 pack->granulepos = os->lastpos; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
368 *pts = (double)os->lastpos / (double)os->samplerate; |
10092 | 369 } |
370 #endif /* HAVE_OGGTHEORA */ | |
11004 | 371 # ifdef HAVE_FLAC |
372 } else if (os->flac) { | |
373 /* we pass complete packets to flac, mustn't strip the header! */ | |
374 data = pack->packet; | |
375 #endif /* HAVE_FLAC */ | |
5732 | 376 } else { |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
377 if(*pack->packet & PACKET_TYPE_HEADER) |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
378 os->hdr_packets++; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
379 else { |
5732 | 380 // Find data start |
381 int16_t hdrlen = (*pack->packet & PACKET_LEN_BITS01)>>6; | |
382 hdrlen |= (*pack->packet & PACKET_LEN_BITS2) <<1; | |
383 data = pack->packet + 1 + hdrlen; | |
384 // Calculate the timestamp | |
385 if(pack->granulepos == -1) | |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
386 pack->granulepos = os->lastpos + (os->lastsize ? os->lastsize : 1); |
5732 | 387 // If we alredy have a timestamp it can be a syncpoint |
388 if(*pack->packet & PACKET_IS_SYNCPOINT) | |
389 *flags = 1; | |
390 *pts = pack->granulepos/os->samplerate; | |
391 // Save the packet length and timestamp | |
392 os->lastsize = 0; | |
393 while(hdrlen) { | |
394 os->lastsize <<= 8; | |
395 os->lastsize |= pack->packet[hdrlen]; | |
396 hdrlen--; | |
397 } | |
398 os->lastpos = pack->granulepos; | |
399 } | |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
400 } |
5732 | 401 return data; |
402 } | |
403 | |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
404 // check if clang has substring from comma separated langlist |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
405 static int demux_ogg_check_lang(char *clang, char *langlist) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
406 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
407 char *c; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
408 |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
409 if (!langlist || !*langlist) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
410 return 0; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
411 while ((c = strchr(langlist, ','))) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
412 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
413 if (!strncasecmp(clang, langlist, c - langlist)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
414 return 1; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
415 langlist = &c[1]; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
416 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
417 if (!strncasecmp(clang, langlist, strlen(langlist))) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
418 return 1; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
419 return 0; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
420 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
421 |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
422 /// Try to print out comments and also check for LANGUAGE= tag |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
423 static void demux_ogg_check_comments(demuxer_t *d, ogg_stream_t *os, int id, vorbis_comment *vc) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
424 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
425 char *hdr, *val; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
426 char **cmt = vc->user_comments; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
427 |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
428 while(*cmt) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
429 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
430 hdr = NULL; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
431 if (!strncasecmp(*cmt, "ENCODED_USING=", 14)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
432 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
433 hdr = "Software"; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
434 val = *cmt + 14; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
435 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
436 else if (!strncasecmp(*cmt, "LANGUAGE=", 9)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
437 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
438 val = *cmt + 9; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
439 // check for -slang if subs are uninitialized yet |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
440 if (os->text && d->sub->id == -1 && demux_ogg_check_lang(val, dvdsub_lang)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
441 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
442 d->sub->id = id; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
443 mp_msg(MSGT_DEMUX, MSGL_V, "Stream language matched -slang: %s\n", val); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
444 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
445 else |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
446 hdr = "Language"; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
447 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
448 else if (!strncasecmp(*cmt, "ENCODER_URL=", 12)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
449 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
450 hdr = "Encoder URL"; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
451 val = *cmt + 12; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
452 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
453 else if (!strncasecmp(*cmt, "TITLE=", 6)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
454 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
455 hdr = "Name"; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
456 val = *cmt + 6; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
457 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
458 if (hdr) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
459 mp_msg(MSGT_DEMUX, MSGL_V, " %s: %s\n", hdr, val); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
460 cmt++; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
461 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
462 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
463 |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
464 /// Calculate the timestamp and add the packet to the demux stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
465 // return 1 if the packet was added, 0 otherwise |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
466 static int demux_ogg_add_packet(demux_stream_t* ds,ogg_stream_t* os,int id,ogg_packet* pack) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
467 demuxer_t* d = ds->demuxer; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
468 demux_packet_t* dp; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
469 unsigned char* data; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
470 float pts = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
471 int flags = 0; |
10092 | 472 void *context = NULL; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
473 |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
474 // If packet is an comment header then we try to get comments at first |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
475 if (pack->bytes >= 7 && !memcmp(pack->packet, "\003vorbis", 7)) |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
476 { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
477 vorbis_info vi; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
478 vorbis_comment vc; |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
479 |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
480 vorbis_info_init(&vi); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
481 vorbis_comment_init(&vc); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
482 vi.rate = 1L; // it's checked by vorbis_synthesis_headerin() |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
483 if(vorbis_synthesis_headerin(&vi, &vc, pack) == 0) // if no errors |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
484 demux_ogg_check_comments(d, os, id, &vc); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
485 vorbis_comment_clear(&vc); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
486 vorbis_info_clear(&vi); |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
487 } |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
488 if (os->text) { |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
489 if (id == d->sub->id) // don't want to add subtitles to the demuxer for now |
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
490 demux_ogg_add_sub(os,pack); |
7010 | 491 return 0; |
492 } | |
10092 | 493 // If packet is an header we jump it except for vorbis and theora |
494 // (PACKET_TYPE_HEADER bit doesn't even exist for theora ?!) | |
11464
1efd0f9a946d
For FLAC-in-Ogg the packets are NEVER skipped, and there's no such thing as a "packet header byte" like in Ogm streams. Basically the handling for Vorbis != Theora != FLAC != Ogm.
mosu
parents:
11128
diff
changeset
|
495 // We jump nothing for FLAC. Ain't this great? Packet contents have to be |
1efd0f9a946d
For FLAC-in-Ogg the packets are NEVER skipped, and there's no such thing as a "packet header byte" like in Ogm streams. Basically the handling for Vorbis != Theora != FLAC != Ogm.
mosu
parents:
11128
diff
changeset
|
496 // handled differently for each and every stream type. The joy! The joy! |
1efd0f9a946d
For FLAC-in-Ogg the packets are NEVER skipped, and there's no such thing as a "packet header byte" like in Ogm streams. Basically the handling for Vorbis != Theora != FLAC != Ogm.
mosu
parents:
11128
diff
changeset
|
497 if(!os->flac && ((*pack->packet & PACKET_TYPE_HEADER) && |
10092 | 498 (ds != d->audio || ( ((sh_audio_t*)ds->sh)->format != 0xFFFE || os->hdr_packets >= NUM_VORBIS_HDR_PACKETS ) ) && |
11464
1efd0f9a946d
For FLAC-in-Ogg the packets are NEVER skipped, and there's no such thing as a "packet header byte" like in Ogm streams. Basically the handling for Vorbis != Theora != FLAC != Ogm.
mosu
parents:
11128
diff
changeset
|
499 (ds != d->video || (((sh_video_t*)ds->sh)->format != 0xFFFC)))) |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
500 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
501 |
10092 | 502 // For vorbis packet the packet is the data, for other codec we must jump |
503 // the header | |
5732 | 504 if(ds == d->audio && ((sh_audio_t*)ds->sh)->format == 0xFFFE) |
10092 | 505 context = ((sh_audio_t *)ds->sh)->context; |
506 if (ds == d->video && ((sh_audio_t*)ds->sh)->format == 0xFFFC) | |
507 context = ((sh_video_t *)ds->sh)->context; | |
508 data = demux_ogg_read_packet(os,pack,context,&pts,&flags); | |
11756
5c55de920ac0
Properly set the file duration for audio-only Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11577
diff
changeset
|
509 if(d->video->id < 0) |
5c55de920ac0
Properly set the file duration for audio-only Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11577
diff
changeset
|
510 ((sh_audio_t*)ds->sh)->delay = pts; |
5732 | 511 |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
512 /// Clear subtitles if necessary (for broken files) |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
513 if ((clear_sub > 0) && (pts >= clear_sub)) { |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
514 ogg_sub.lines = 0; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
515 vo_sub = &ogg_sub; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
516 vo_osd_changed(OSDTYPE_SUBTITLE); |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
517 clear_sub = -1; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
518 } |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
519 /// Send the packet |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
520 dp = new_demux_packet(pack->bytes-(data-pack->packet)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
521 memcpy(dp->buffer,data,pack->bytes-(data-pack->packet)); |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
522 dp->pts = pts; |
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
523 dp->flags = flags; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
524 ds_add_packet(ds,dp); |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
525 mp_msg(MSGT_DEMUX,MSGL_DBG2,"New dp: %p ds=%p pts=%5.3f len=%d flag=%d \n", |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
526 dp, ds, pts, dp->len, flags); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
527 return 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
528 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
529 |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
530 /// if -forceidx build a table of all syncpoints to make seeking easier |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
531 /// otherwise try to get at least the final_granulepos |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
532 void demux_ogg_scan_stream(demuxer_t* demuxer) { |
5732 | 533 ogg_demuxer_t* ogg_d = demuxer->priv; |
534 stream_t *s = demuxer->stream; | |
535 ogg_sync_state* sync = &ogg_d->sync; | |
536 ogg_page* page= &ogg_d->page; | |
537 ogg_stream_state* oss; | |
538 ogg_stream_t* os; | |
539 ogg_packet op; | |
540 int np,sid,p; | |
10092 | 541 void *context = NULL; |
5732 | 542 off_t pos, last_pos; |
543 pos = last_pos = demuxer->movi_start; | |
544 | |
545 // Reset the stream | |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
546 if(index_mode == 2) { |
5732 | 547 stream_seek(s,demuxer->movi_start); |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
548 } else { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
549 //the 270000 are just a wild guess |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
550 stream_seek(s,max(ogg_d->pos,demuxer->movi_end-270000)); |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
551 } |
5732 | 552 ogg_sync_reset(sync); |
553 | |
554 // Get the serial number of the stream we use | |
10092 | 555 if(demuxer->video->id >= 0) { |
5732 | 556 sid = demuxer->video->id; |
10092 | 557 /* demux_ogg_read_packet needs decoder context for Theora streams */ |
558 if (((sh_video_t*)demuxer->video->sh)->format == 0xFFFC) | |
559 context = ((sh_video_t*)demuxer->video->sh)->context; | |
560 } | |
5732 | 561 else { |
562 sid = demuxer->audio->id; | |
10092 | 563 /* demux_ogg_read_packet needs decoder context for Vorbis streams */ |
5732 | 564 if(((sh_audio_t*)demuxer->audio->sh)->format == 0xFFFE) |
10092 | 565 context = ((sh_audio_t*)demuxer->audio->sh)->context; |
5732 | 566 } |
567 os = &ogg_d->subs[sid]; | |
568 oss = &os->stream; | |
569 | |
570 while(1) { | |
571 np = ogg_sync_pageseek(sync,page); | |
572 if(np < 0) { // We had to skip some bytes | |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
573 if(index_mode == 2) mp_msg(MSGT_DEMUX,MSGL_ERR,"Bad page sync while building syncpoints table (%d)\n",-np); |
5732 | 574 pos += -np; |
575 continue; | |
576 } | |
577 if(np <= 0) { // We need more data | |
578 char* buf = ogg_sync_buffer(sync,BLOCK_SIZE); | |
579 int len = stream_read(s,buf,BLOCK_SIZE); | |
580 if(len == 0 && s->eof) | |
581 break; | |
582 ogg_sync_wrote(sync,len); | |
583 continue; | |
584 } | |
585 // The page is ready | |
586 //ogg_sync_pageout(sync,page); | |
587 if(ogg_page_serialno(page) != os->stream.serialno) { // It isn't a page from the stream we want | |
588 pos += np; | |
589 continue; | |
590 } | |
591 if(ogg_stream_pagein(oss,page) != 0) { | |
592 mp_msg(MSGT_DEMUX,MSGL_ERR,"Pagein error ????\n"); | |
593 pos += np; | |
594 continue; | |
595 } | |
596 p = 0; | |
597 while(ogg_stream_packetout(oss,&op) == 1) { | |
598 float pts; | |
599 int flags; | |
10092 | 600 demux_ogg_read_packet(os,&op,context,&pts,&flags); |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
601 if(op.granulepos >= 0) ogg_d->final_granulepos = op.granulepos; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
602 if(index_mode == 2 && (flags || (os->vorbis && op.granulepos >= 0))) { |
5732 | 603 ogg_d->syncpoints = (ogg_syncpoint_t*)realloc(ogg_d->syncpoints,(ogg_d->num_syncpoint+1)*sizeof(ogg_syncpoint_t)); |
604 ogg_d->syncpoints[ogg_d->num_syncpoint].granulepos = op.granulepos; | |
605 ogg_d->syncpoints[ogg_d->num_syncpoint].page_pos = (ogg_page_continued(page) && p == 0) ? last_pos : pos; | |
606 ogg_d->num_syncpoint++; | |
607 } | |
608 p++; | |
609 } | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
610 if(p > 1 || (p == 1 && ! ogg_page_continued(page))) |
5732 | 611 last_pos = pos; |
612 pos += np; | |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
613 if(index_mode == 2) mp_msg(MSGT_DEMUX,MSGL_INFO,"Building syncpoint table %d%%\r",(int)(pos*100/s->end_pos)); |
5732 | 614 } |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
615 if(index_mode == 2) mp_msg(MSGT_DEMUX,MSGL_INFO,"\n"); |
5732 | 616 |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
617 if(index_mode == 2) mp_msg(MSGT_DEMUX,MSGL_V,"Ogg syncpoints table builed: %d syncpoints\n",ogg_d->num_syncpoint); |
11576 | 618 mp_msg(MSGT_DEMUX,MSGL_V,"Ogg stream length (granulepos): %lld\n",ogg_d->final_granulepos); |
5732 | 619 |
620 stream_reset(s); | |
621 stream_seek(s,demuxer->movi_start); | |
622 ogg_sync_reset(sync); | |
623 for(np = 0 ; np < ogg_d->num_sub ; np++) { | |
624 ogg_stream_reset(&ogg_d->subs[np].stream); | |
625 ogg_d->subs[np].lastpos = ogg_d->subs[np].lastsize = ogg_d->subs[np].hdr_packets = 0; | |
626 } | |
627 | |
628 | |
629 // Get the first page | |
630 while(1) { | |
631 np = ogg_sync_pageout(sync,page); | |
632 if(np <= 0) { // We need more data | |
633 char* buf = ogg_sync_buffer(sync,BLOCK_SIZE); | |
634 int len = stream_read(s,buf,BLOCK_SIZE); | |
635 if(len == 0 && s->eof) { | |
636 mp_msg(MSGT_DEMUX,MSGL_ERR,"EOF while trying to get the first page !!!!\n"); | |
637 break; | |
638 } | |
639 | |
640 ogg_sync_wrote(sync,len); | |
641 continue; | |
642 } | |
643 demux_ogg_get_page_stream(ogg_d,&oss); | |
644 ogg_stream_pagein(oss,page); | |
645 break; | |
646 } | |
647 | |
648 } | |
649 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
650 extern void print_wave_header(WAVEFORMATEX *h); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
651 extern void print_video_header(BITMAPINFOHEADER *h); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
652 |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
653 /// Open an ogg physical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
654 int demux_ogg_open(demuxer_t* demuxer) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
655 ogg_demuxer_t* ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
656 stream_t *s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
657 char* buf; |
7010 | 658 int np,s_no, n_audio = 0, n_video = 0, n_text = 0; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
659 int audio_id = -1, video_id = -1, text_id = -1; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
660 ogg_sync_state* sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
661 ogg_page* page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
662 ogg_packet pack; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
663 sh_audio_t* sh_a; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
664 sh_video_t* sh_v; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
665 |
8618
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
666 #ifdef USE_ICONV |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
667 subcp_open(); |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
668 #endif |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
669 |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
670 clear_sub = -1; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
671 s = demuxer->stream; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
672 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
673 ogg_d = (ogg_demuxer_t*)calloc(1,sizeof(ogg_demuxer_t)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
674 sync = &ogg_d->sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
675 page = &ogg_d->page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
676 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
677 ogg_sync_init(sync); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
678 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
679 while(1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
680 /// Try to get a page |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
681 ogg_d->pos += ogg_d->last_size; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
682 np = ogg_sync_pageseek(sync,page); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
683 /// Error |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
684 if(np < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
685 mp_msg(MSGT_DEMUX,MSGL_DBG2,"OGG demuxer : Bad page sync\n"); |
7760 | 686 free(ogg_d); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
687 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
688 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
689 /// Need some more data |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
690 if(np == 0) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
691 int len; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
692 buf = ogg_sync_buffer(sync,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
693 len = stream_read(s,buf,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
694 if(len == 0 && s->eof) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
695 free(ogg_d); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
696 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
697 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
698 ogg_sync_wrote(sync,len); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
699 continue; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
700 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
701 ogg_d->last_size = np; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
702 // We got one page now |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
703 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
704 if( ! ogg_page_bos(page) ) { // It's not a begining page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
705 // Header parsing end here, we need to get the page otherwise it will be lost |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
706 int id = demux_ogg_get_page_stream(ogg_d,NULL); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
707 if(id >= 0) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
708 ogg_stream_pagein(&ogg_d->subs[id].stream,page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
709 else |
10397 | 710 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG : Warning found none bos page from unknown stream %d\n",ogg_page_serialno(page)); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
711 break; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
712 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
713 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
714 /// Init the data structure needed for a logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
715 ogg_d->subs = (ogg_stream_t*)realloc(ogg_d->subs,(ogg_d->num_sub+1)*sizeof(ogg_stream_t)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
716 memset(&ogg_d->subs[ogg_d->num_sub],0,sizeof(ogg_stream_t)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
717 /// Get the stream serial number |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
718 s_no = ogg_page_serialno(page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
719 ogg_stream_init(&ogg_d->subs[ogg_d->num_sub].stream,s_no); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
720 mp_msg(MSGT_DEMUX,MSGL_DBG2,"OGG : Found a stream with serial=%d\n",s_no); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
721 // Take the first page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
722 ogg_stream_pagein(&ogg_d->subs[ogg_d->num_sub].stream,page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
723 // Get first packet of the page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
724 ogg_stream_packetout(&ogg_d->subs[ogg_d->num_sub].stream,&pack); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
725 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
726 // Reset our vars |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
727 sh_a = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
728 sh_v = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
729 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
730 // Check for Vorbis |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
731 if(pack.bytes >= 7 && ! strncmp(&pack.packet[1],"vorbis", 6) ) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
732 sh_a = new_sh_audio(demuxer,ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
733 sh_a->format = 0xFFFE; |
5732 | 734 ogg_d->subs[ogg_d->num_sub].vorbis = 1; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
735 n_audio++; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
736 mp_msg(MSGT_DEMUX,MSGL_V,"OGG : stream %d is vorbis\n",ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
737 |
10092 | 738 // check for Theora |
739 # ifdef HAVE_OGGTHEORA | |
740 } else if (pack.bytes >= 7 && !strncmp (&pack.packet[1], "theora", 6)) { | |
741 int errorCode = 0; | |
742 theora_info inf; | |
10658
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
743 theora_comment cc; |
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
744 |
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
745 theora_info_init (&inf); |
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
746 theora_comment_init (&cc); |
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
747 |
c5e7b34bfc19
Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents:
10608
diff
changeset
|
748 errorCode = theora_decode_header (&inf, &cc, &pack); |
10092 | 749 if (errorCode) |
750 mp_msg(MSGT_DEMUX,MSGL_ERR,"Theora header parsing failed: %i \n", | |
751 errorCode); | |
752 else | |
753 { | |
754 sh_v = new_sh_video(demuxer,ogg_d->num_sub); | |
755 | |
756 sh_v->context = NULL; | |
757 sh_v->bih = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); | |
758 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
759 sh_v->bih->biCompression= sh_v->format = 0xFFFC; | |
760 sh_v->fps = ((double)inf.fps_numerator)/ | |
761 (double)inf.fps_denominator; | |
762 sh_v->frametime = ((double)inf.fps_denominator)/ | |
763 (double)inf.fps_numerator; | |
764 sh_v->disp_w = sh_v->bih->biWidth = inf.width; | |
765 sh_v->disp_h = sh_v->bih->biHeight = inf.height; | |
766 sh_v->bih->biBitCount = 24; | |
767 sh_v->bih->biPlanes = 3; | |
768 sh_v->bih->biSizeImage = ((sh_v->bih->biBitCount/8) * | |
769 sh_v->bih->biWidth*sh_v->bih->biHeight); | |
770 ogg_d->subs[ogg_d->num_sub].samplerate = sh_v->fps; | |
771 ogg_d->subs[ogg_d->num_sub].theora = 1; | |
772 n_video++; | |
773 mp_msg(MSGT_DEMUX,MSGL_V, | |
774 "OGG : stream %d is theora v%i.%i.%i %i:%i, %.3f FPS," | |
775 " aspect %i:%i\n", ogg_d->num_sub, | |
776 (int)inf.version_major, | |
777 (int)inf.version_minor, | |
778 (int)inf.version_subminor, | |
779 inf.width, inf.height, | |
780 sh_v->fps, | |
781 inf.aspect_numerator, inf.aspect_denominator); | |
782 if(verbose>0) print_video_header(sh_v->bih); | |
783 } | |
784 # endif /* HAVE_OGGTHEORA */ | |
11004 | 785 # ifdef HAVE_FLAC |
786 } else if (pack.bytes >= 4 && !strncmp (&pack.packet[0], "fLaC", 4)) { | |
787 sh_a = new_sh_audio(demuxer,ogg_d->num_sub); | |
788 sh_a->format = mmioFOURCC('f', 'L', 'a', 'C'); | |
789 n_audio++; | |
790 ogg_d->subs[ogg_d->num_sub].flac = 1; | |
791 sh_a->wf = NULL; | |
792 mp_msg(MSGT_DEMUX,MSGL_V,"OGG : stream %d is FLAC\n",ogg_d->num_sub); | |
793 # endif /* HAVE_FLAC */ | |
794 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
795 /// Check for old header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
796 } else if(pack.bytes >= 142 && ! strncmp(&pack.packet[1],"Direct Show Samples embedded in Ogg",35) ) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
797 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
798 // Old video header |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
799 if(get_uint32 (pack.packet+96) == 0x05589f80 && pack.bytes >= 184) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
800 sh_v = new_sh_video(demuxer,ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
801 sh_v->bih = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
802 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
803 sh_v->bih->biCompression= |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
804 sh_v->format = mmioFOURCC(pack.packet[68],pack.packet[69], |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
805 pack.packet[70],pack.packet[71]); |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
806 sh_v->frametime = get_uint64(pack.packet+164)*0.0000001; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
807 sh_v->fps = 1/sh_v->frametime; |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
808 sh_v->disp_w = sh_v->bih->biWidth = get_uint32(pack.packet+176); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
809 sh_v->disp_h = sh_v->bih->biHeight = get_uint32(pack.packet+180); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
810 sh_v->bih->biBitCount = get_uint16(pack.packet+182); |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
811 if(!sh_v->bih->biBitCount) sh_v->bih->biBitCount=24; // hack, FIXME |
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
812 sh_v->bih->biPlanes=1; |
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
813 sh_v->bih->biSizeImage=(sh_v->bih->biBitCount>>3)*sh_v->bih->biWidth*sh_v->bih->biHeight; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
814 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
815 ogg_d->subs[ogg_d->num_sub].samplerate = sh_v->fps; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
816 n_video++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
817 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is video (old hdr)\n",ogg_d->num_sub); |
8027 | 818 if(verbose>0) print_video_header(sh_v->bih); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
819 // Old audio header |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
820 } else if(get_uint32(pack.packet+96) == 0x05589F81) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
821 unsigned int extra_size; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
822 sh_a = new_sh_audio(demuxer,ogg_d->num_sub); |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
823 extra_size = get_uint16(pack.packet+140); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
824 sh_a->wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)+extra_size); |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
825 sh_a->format = sh_a->wf->wFormatTag = get_uint16(pack.packet+124); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
826 sh_a->channels = sh_a->wf->nChannels = get_uint16(pack.packet+126); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
827 sh_a->samplerate = sh_a->wf->nSamplesPerSec = get_uint32(pack.packet+128); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
828 sh_a->wf->nAvgBytesPerSec = get_uint32(pack.packet+132); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
829 sh_a->wf->nBlockAlign = get_uint16(pack.packet+136); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
830 sh_a->wf->wBitsPerSample = get_uint16(pack.packet+138); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
831 sh_a->samplesize = (sh_a->wf->wBitsPerSample+7)/8; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
832 sh_a->wf->cbSize = extra_size; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
833 if(extra_size > 0) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
834 memcpy(sh_a->wf+sizeof(WAVEFORMATEX),pack.packet+142,extra_size); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
835 |
7396
cfb1bc3925eb
The granule position of pages contining Vorbis audio is in units of
arpi
parents:
7115
diff
changeset
|
836 ogg_d->subs[ogg_d->num_sub].samplerate = sh_a->samplerate; // * sh_a->channels; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
837 n_audio++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
838 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is audio (old hdr)\n",ogg_d->num_sub); |
8027 | 839 if(verbose>0) print_wave_header(sh_a->wf); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
840 } else |
10397 | 841 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG stream %d contains an old header but the header type is unknown\n",ogg_d->num_sub); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
842 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
843 // Check new header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
844 } else if ( (*pack.packet & PACKET_TYPE_BITS ) == PACKET_TYPE_HEADER && |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
845 pack.bytes >= (int)sizeof(stream_header)+1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
846 stream_header *st = (stream_header*)(pack.packet+1); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
847 /// New video header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
848 if(strncmp(st->streamtype,"video",5) == 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
849 sh_v = new_sh_video(demuxer,ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
850 sh_v->bih = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); |
5430 | 851 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
852 sh_v->bih->biCompression= | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
853 sh_v->format = mmioFOURCC(st->subtype[0],st->subtype[1], |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
854 st->subtype[2],st->subtype[3]); |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
855 sh_v->frametime = get_uint64(&st->time_unit)*0.0000001; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
856 sh_v->fps = 1.0/sh_v->frametime; |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
857 sh_v->bih->biBitCount = get_uint16(&st->bits_per_sample); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
858 sh_v->disp_w = sh_v->bih->biWidth = get_uint32(&st->sh.video.width); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
859 sh_v->disp_h = sh_v->bih->biHeight = get_uint32(&st->sh.video.height); |
5430 | 860 if(!sh_v->bih->biBitCount) sh_v->bih->biBitCount=24; // hack, FIXME |
861 sh_v->bih->biPlanes=1; | |
862 sh_v->bih->biSizeImage=(sh_v->bih->biBitCount>>3)*sh_v->bih->biWidth*sh_v->bih->biHeight; | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
863 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
864 ogg_d->subs[ogg_d->num_sub].samplerate= sh_v->fps; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
865 n_video++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
866 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is video (new hdr)\n",ogg_d->num_sub); |
8027 | 867 if(verbose>0) print_video_header(sh_v->bih); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
868 /// New audio header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
869 } else if(strncmp(st->streamtype,"audio",5) == 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
870 char buffer[5]; |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
871 unsigned int extra_size = get_uint32 (&st->size) - sizeof(stream_header); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
872 memcpy(buffer,st->subtype,4); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
873 buffer[4] = '\0'; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
874 sh_a = new_sh_audio(demuxer,ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
875 sh_a->wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)+extra_size); |
6850 | 876 sh_a->format = sh_a->wf->wFormatTag = strtol(buffer, NULL, 16); |
7845
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
877 sh_a->channels = sh_a->wf->nChannels = get_uint16(&st->sh.audio.channels); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
878 sh_a->samplerate = sh_a->wf->nSamplesPerSec = get_uint64(&st->samples_per_unit); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
879 sh_a->wf->nAvgBytesPerSec = get_uint32(&st->sh.audio.avgbytespersec); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
880 sh_a->wf->nBlockAlign = get_uint16(&st->sh.audio.blockalign); |
86420d5d7283
endianess independency (using get int 16/32/64 func instead of typecasting pointer)
arpi
parents:
7760
diff
changeset
|
881 sh_a->wf->wBitsPerSample = get_uint16(&st->bits_per_sample); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
882 sh_a->samplesize = (sh_a->wf->wBitsPerSample+7)/8; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
883 sh_a->wf->cbSize = extra_size; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
884 if(extra_size) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
885 memcpy(sh_a->wf+sizeof(WAVEFORMATEX),st+1,extra_size); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
886 |
7396
cfb1bc3925eb
The granule position of pages contining Vorbis audio is in units of
arpi
parents:
7115
diff
changeset
|
887 ogg_d->subs[ogg_d->num_sub].samplerate = sh_a->samplerate; // * sh_a->channels; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
888 n_audio++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
889 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is audio (new hdr)\n",ogg_d->num_sub); |
8027 | 890 if(verbose>0) print_wave_header(sh_a->wf); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
891 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
892 /// Check for text (subtitles) header |
7010 | 893 } else if (strncmp(st->streamtype, "text", 4) == 0) { |
894 mp_msg(MSGT_DEMUX, MSGL_V, "OGG stream %d is text\n", ogg_d->num_sub); | |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
895 ogg_d->subs[ogg_d->num_sub].samplerate= get_uint64(&st->time_unit)/10; |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
896 ogg_d->subs[ogg_d->num_sub].text = 1; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
897 if (demuxer->sub->id == n_text) |
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
898 text_id = ogg_d->num_sub; |
7010 | 899 n_text++; |
900 demux_ogg_init_sub(); | |
10397 | 901 //// Unknown header type |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
902 } else |
10397 | 903 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG stream %d has a header marker but is of an unknown type\n",ogg_d->num_sub); |
10608 | 904 /// Unknown (invalid ?) header |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
905 } else |
10397 | 906 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG stream %d is of an unknown type\n",ogg_d->num_sub); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
907 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
908 if(sh_a || sh_v) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
909 demux_stream_t* ds = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
910 if(sh_a) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
911 // If the audio stream is not defined we took the first one |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
912 if(demuxer->audio->id == -1) { |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
913 demuxer->audio->id = n_audio - 1; |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
914 // if(sh_a->wf) print_wave_header(sh_a->wf); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
915 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
916 /// Is it the stream we want |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
917 if(demuxer->audio->id == (n_audio - 1)) { |
6124
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
918 demuxer->audio->sh = sh_a; |
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
919 sh_a->ds = demuxer->audio; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
920 ds = demuxer->audio; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
921 audio_id = ogg_d->num_sub; |
6156 | 922 } |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
923 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
924 if(sh_v) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
925 /// Also for video |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
926 if(demuxer->video->id == -1) { |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
927 demuxer->video->id = n_video - 1; |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
928 // if(sh_v->bih) print_video_header(sh_v->bih); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
929 } |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
930 if(demuxer->video->id == (n_video - 1)) { |
6124
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
931 demuxer->video->sh = sh_v; |
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
932 sh_v->ds = demuxer->video; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
933 ds = demuxer->video; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
934 video_id = ogg_d->num_sub; |
6156 | 935 } |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
936 } |
5732 | 937 /// Add the header packets if the stream isn't seekable |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
938 if(ds && !s->end_pos) { |
5732 | 939 /// Finish the page, otherwise packets will be lost |
940 do { | |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
941 demux_ogg_add_packet(ds,&ogg_d->subs[ogg_d->num_sub],ogg_d->num_sub,&pack); |
5732 | 942 } while(ogg_stream_packetout(&ogg_d->subs[ogg_d->num_sub].stream,&pack) == 1); |
943 } | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
944 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
945 ogg_d->num_sub++; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
946 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
947 |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
948 if(!n_video && !n_audio) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
949 free(ogg_d); |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
950 return 0; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
951 } |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
952 |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
953 /// Finish to setup the demuxer |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
954 demuxer->priv = ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
955 |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
956 if(!n_video || (video_id < 0)) |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
957 demuxer->video->id = -2; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
958 else |
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
959 demuxer->video->id = video_id; |
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
960 if(!n_audio || (audio_id < 0)) |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
961 demuxer->audio->id = -2; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
962 else |
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
963 demuxer->audio->id = audio_id; |
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
964 if(!n_text || (text_id < 0)) |
7010 | 965 demuxer->sub->id = -2; |
12135
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
966 else |
ec3c9fe261b9
Changed -sid/-aid/-vid to be zero based and select the n'th stream of its type, e.g. -sid 1 will select the second subtitle stream.
mosu
parents:
12104
diff
changeset
|
967 demuxer->sub->id = text_id; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
968 |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
969 ogg_d->final_granulepos=0; |
5732 | 970 if(!s->end_pos) |
971 demuxer->seekable = 0; | |
972 else { | |
8795
b4512aa07711
mosu: Fixed OGG/OGM seeking for XCDs in which the OGG/OGM does not start at pos 0 in the stream
mosu
parents:
8788
diff
changeset
|
973 demuxer->movi_start = s->start_pos; // Needed for XCD (Ogg written in MODE2) |
5732 | 974 demuxer->movi_end = s->end_pos; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
975 demuxer->seekable = 1; |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
976 demux_ogg_scan_stream(demuxer); |
5732 | 977 } |
978 | |
7010 | 979 mp_msg(MSGT_DEMUX,MSGL_V,"OGG demuxer : found %d audio stream%s, %d video stream%s and %d text stream%s\n",n_audio,n_audio>1?"s":"",n_video,n_video>1?"s":"",n_text,n_text>1?"s":""); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
980 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
981 return 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
982 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
983 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
984 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
985 int demux_ogg_fill_buffer(demuxer_t *d) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
986 ogg_demuxer_t* ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
987 stream_t *s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
988 demux_stream_t *ds; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
989 ogg_sync_state* sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
990 ogg_stream_state* os; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
991 ogg_page* page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
992 ogg_packet pack; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
993 int np = 0, id=0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
994 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
995 s = d->stream; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
996 ogg_d = d->priv; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
997 sync = &ogg_d->sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
998 page = &ogg_d->page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
999 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1000 /// Find the stream we are working on |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1001 if ( (id = demux_ogg_get_page_stream(ogg_d,&os)) < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1002 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG demuxer : can't get current stream\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1003 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1004 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1005 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1006 while(1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1007 np = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1008 ds = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1009 /// Try to get some packet from the current page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1010 while( (np = ogg_stream_packetout(os,&pack)) != 1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1011 /// No packet we go the next page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1012 if(np == 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1013 while(1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1014 int pa,len; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1015 char *buf; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1016 ogg_d->pos += ogg_d->last_size; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1017 /// Get the next page from the physical stream |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1018 while( (pa = ogg_sync_pageseek(sync,page)) <= 0) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1019 /// Error : we skip some bytes |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1020 if(pa < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1021 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG : Page out not synced, we skip some bytes\n"); |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1022 ogg_d->pos -= pa; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1023 continue; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1024 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1025 /// We need more data |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1026 buf = ogg_sync_buffer(sync,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1027 len = stream_read(s,buf,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1028 if(len == 0 && s->eof) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1029 mp_msg(MSGT_DEMUX,MSGL_DBG2,"OGG : Stream EOF !!!!\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1030 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1031 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1032 ogg_sync_wrote(sync,len); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1033 } /// Page loop |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1034 ogg_d->last_size = pa; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1035 /// Find the page's logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1036 if( (id = demux_ogg_get_page_stream(ogg_d,&os)) < 0) { |
10397 | 1037 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG demuxer error : we met an unknown stream\n"); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1038 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1039 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1040 /// Take the page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1041 if(ogg_stream_pagein(os,page) == 0) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1042 break; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1043 /// Page was invalid => retry |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1044 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG demuxer : got invalid page !!!!!\n"); |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1045 ogg_d->pos += ogg_d->last_size; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1046 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1047 } else /// Packet was corrupted |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1048 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG : bad packet in stream %d\n",id); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1049 } /// Packet loop |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1050 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1051 /// Is the actual logical stream in use ? |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1052 if(id == d->audio->id) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1053 ds = d->audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1054 else if(id == d->video->id) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1055 ds = d->video; |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
1056 else if (ogg_d->subs[id].text) |
7010 | 1057 ds = d->sub; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1058 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1059 if(ds) { |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
1060 if(!demux_ogg_add_packet(ds,&ogg_d->subs[id],id,&pack)) |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1061 continue; /// Unuseful packet, get another |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1062 d->filepos = ogg_d->pos; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1063 return 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1064 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1065 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1066 } /// while(1) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1067 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1068 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1069 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1070 /// For avi with Ogg audio stream we have to create an ogg demuxer for this |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1071 // stream, then we join the avi and ogg demuxer with a demuxers demuxer |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1072 demuxer_t* init_avi_with_ogg(demuxer_t* demuxer) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1073 demuxer_t *od; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1074 ogg_demuxer_t *ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1075 stream_t* s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1076 uint32_t hdrsizes[3]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1077 demux_packet_t *dp; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1078 sh_audio_t *sh_audio = demuxer->audio->sh; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1079 int np; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1080 unsigned char *p = NULL,*buf; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1081 int plen; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1082 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1083 /// Check that the cbSize is enouth big for the following reads |
9163 | 1084 if(sh_audio->wf->cbSize < 22+3*sizeof(uint32_t)) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1085 mp_msg(MSGT_DEMUX,MSGL_ERR,"AVI OGG : Initial audio header is too small !!!!!\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1086 goto fallback; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1087 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1088 /// Get the size of the 3 header packet |
9163 | 1089 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+22+sizeof(WAVEFORMATEX), 3*sizeof(uint32_t)); |
1090 // printf("\n!!!!!! hdr sizes: %d %d %d \n",hdrsizes[0],hdrsizes[1],hdrsizes[2]); | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1091 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1092 /// Check the size |
9163 | 1093 if(sh_audio->wf->cbSize < 22+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1] + hdrsizes[2]) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1094 mp_msg(MSGT_DEMUX,MSGL_ERR,"AVI OGG : Audio header is too small !!!!!\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1095 goto fallback; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1096 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1097 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1098 // Build the ogg demuxer private datas |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1099 ogg_d = (ogg_demuxer_t*)calloc(1,sizeof(ogg_demuxer_t)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1100 ogg_d->num_sub = 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1101 ogg_d->subs = (ogg_stream_t*)malloc(sizeof(ogg_stream_t)); |
5812 | 1102 ogg_d->subs[0].vorbis = 1; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1103 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1104 // Init the ogg physical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1105 ogg_sync_init(&ogg_d->sync); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1106 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1107 // Get the first page of the stream : we assume there only 1 logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1108 while((np = ogg_sync_pageout(&ogg_d->sync,&ogg_d->page)) <= 0 ) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1109 if(np < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1110 mp_msg(MSGT_DEMUX,MSGL_ERR,"AVI OGG error : Can't init using first stream packets\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1111 free(ogg_d); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1112 goto fallback; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1113 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1114 // Add some data |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1115 plen = ds_get_packet(demuxer->audio,&p); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1116 buf = ogg_sync_buffer(&ogg_d->sync,plen); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1117 memcpy(buf,p,plen); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1118 ogg_sync_wrote(&ogg_d->sync,plen); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1119 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1120 // Init the logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1121 mp_msg(MSGT_DEMUX,MSGL_DBG2,"AVI OGG found page with serial %d\n",ogg_page_serialno(&ogg_d->page)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1122 ogg_stream_init(&ogg_d->subs[0].stream,ogg_page_serialno(&ogg_d->page)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1123 // Write the page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1124 ogg_stream_pagein(&ogg_d->subs[0].stream,&ogg_d->page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1125 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1126 // Create the ds_stream and the ogg demuxer |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1127 s = new_ds_stream(demuxer->audio); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1128 od = new_demuxer(s,DEMUXER_TYPE_OGG,0,-2,-2); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1129 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1130 /// Add the header packets in the ogg demuxer audio stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1131 // Initial header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1132 dp = new_demux_packet(hdrsizes[0]); |
9163 | 1133 memcpy(dp->buffer,((unsigned char*)sh_audio->wf)+22+sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdrsizes[0]); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1134 ds_add_packet(od->audio,dp); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1135 /// Comments |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1136 dp = new_demux_packet(hdrsizes[1]); |
9163 | 1137 memcpy(dp->buffer,((unsigned char*)sh_audio->wf)+22+sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdrsizes[1]); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1138 ds_add_packet(od->audio,dp); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1139 /// Code book |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1140 dp = new_demux_packet(hdrsizes[2]); |
9163 | 1141 memcpy(dp->buffer,((unsigned char*)sh_audio->wf)+22+sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdrsizes[2]); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1142 ds_add_packet(od->audio,dp); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1143 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1144 // Finish setting up the ogg demuxer |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1145 od->priv = ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1146 sh_audio = new_sh_audio(od,0); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1147 od->audio->id = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1148 od->video->id = -2; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1149 od->audio->sh = sh_audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1150 sh_audio->ds = od->audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1151 sh_audio->format = 0xFFFE; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1152 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1153 /// Return the joined demuxers |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1154 return new_demuxers_demuxer(demuxer,od,demuxer); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1155 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1156 fallback: |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1157 demuxer->audio->id = -2; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1158 return demuxer; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1159 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1160 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1161 |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
1162 extern void resync_audio_stream(sh_audio_t *sh_audio); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
1163 |
5732 | 1164 void demux_ogg_seek(demuxer_t *demuxer,float rel_seek_secs,int flags) { |
1165 ogg_demuxer_t* ogg_d = demuxer->priv; | |
1166 ogg_sync_state* sync = &ogg_d->sync; | |
1167 ogg_page* page= &ogg_d->page; | |
1168 ogg_stream_state* oss; | |
1169 ogg_stream_t* os; | |
1170 demux_stream_t* ds; | |
1171 sh_audio_t* sh_audio = demuxer->audio->sh; | |
1172 ogg_packet op; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1173 float rate; |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1174 int i,sp,first,precision=1,do_seek=1; |
5732 | 1175 vorbis_info* vi = NULL; |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1176 int64_t gp = 0, old_gp; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1177 void *context = NULL; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1178 off_t pos, old_pos; |
12265 | 1179 int np; |
1180 int is_gp_valid; | |
1181 float pts; | |
1182 int is_keyframe; | |
5732 | 1183 |
1184 if(demuxer->video->id >= 0) { | |
1185 ds = demuxer->video; | |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1186 /* demux_ogg_read_packet needs decoder context for Theora streams */ |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1187 if (((sh_video_t*)demuxer->video->sh)->format == 0xFFFC) |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1188 context = ((sh_video_t*)demuxer->video->sh)->context; |
5732 | 1189 rate = ogg_d->subs[ds->id].samplerate; |
1190 } else { | |
1191 ds = demuxer->audio; | |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1192 /* demux_ogg_read_packet needs decoder context for Vorbis streams */ |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1193 if(((sh_audio_t*)demuxer->audio->sh)->format == 0xFFFE) |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1194 context = ((sh_audio_t*)demuxer->audio->sh)->context; |
5732 | 1195 vi = &((ov_struct_t*)((sh_audio_t*)ds->sh)->context)->vi; |
1196 rate = (float)vi->rate; | |
1197 } | |
1198 | |
1199 os = &ogg_d->subs[ds->id]; | |
1200 oss = &os->stream; | |
1201 | |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1202 old_gp = os->lastpos; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1203 old_pos = ogg_d->pos; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1204 |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1205 //calculate the granulepos to seek to |
11898
41efae8120b6
Cleanup and small improvement in seeking if the final_granulepos is known. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11756
diff
changeset
|
1206 gp = flags & 1 ? 0 : os->lastpos; |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1207 if(flags & 2) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1208 if (ogg_d->final_granulepos > 0) |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1209 gp += ogg_d->final_granulepos * rel_seek_secs; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1210 else |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1211 gp += rel_seek_secs * (demuxer->movi_end - demuxer->movi_start) * os->lastpos / ogg_d->pos; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1212 } else |
11898
41efae8120b6
Cleanup and small improvement in seeking if the final_granulepos is known. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11756
diff
changeset
|
1213 gp += rel_seek_secs * rate; |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1214 if (gp < 0) gp = 0; |
5732 | 1215 |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1216 //calculate the filepos to seek to |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1217 if(ogg_d->syncpoints) { |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1218 for(sp = 0; sp < ogg_d->num_syncpoint ; sp++) { |
11898
41efae8120b6
Cleanup and small improvement in seeking if the final_granulepos is known. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11756
diff
changeset
|
1219 if(ogg_d->syncpoints[sp].granulepos >= gp) break; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1220 } |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1221 |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1222 if(sp >= ogg_d->num_syncpoint) return; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1223 if (sp > 0 && ogg_d->syncpoints[sp].granulepos - gp > gp - ogg_d->syncpoints[sp-1].granulepos) |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1224 sp--; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1225 if (ogg_d->syncpoints[sp].granulepos == os->lastpos) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1226 if (sp > 0 && gp < os->lastpos) sp--; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1227 if (sp < ogg_d->num_syncpoint-1 && gp > os->lastpos) sp++; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1228 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1229 pos = ogg_d->syncpoints[sp].page_pos; |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1230 precision = 0; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1231 } else { |
8795
b4512aa07711
mosu: Fixed OGG/OGM seeking for XCDs in which the OGG/OGM does not start at pos 0 in the stream
mosu
parents:
8788
diff
changeset
|
1232 pos = flags & 1 ? 0 : ogg_d->pos; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1233 if(flags & 2) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1234 pos += (demuxer->movi_end - demuxer->movi_start) * rel_seek_secs; |
11898
41efae8120b6
Cleanup and small improvement in seeking if the final_granulepos is known. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11756
diff
changeset
|
1235 else { |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1236 if (ogg_d->final_granulepos > 0) { |
11898
41efae8120b6
Cleanup and small improvement in seeking if the final_granulepos is known. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11756
diff
changeset
|
1237 pos += rel_seek_secs * (demuxer->movi_end - demuxer->movi_start) / (ogg_d->final_granulepos / rate); |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1238 } else if (os->lastpos > 0) { |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1239 pos += rel_seek_secs * ogg_d->pos / (os->lastpos / rate); |
11898
41efae8120b6
Cleanup and small improvement in seeking if the final_granulepos is known. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>
mosu
parents:
11756
diff
changeset
|
1240 } |
5732 | 1241 } |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1242 if (pos < 0) pos = 0; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1243 if (pos > (demuxer->movi_end - demuxer->movi_start)) return; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1244 } // if(ogg_d->syncpoints) |
5732 | 1245 |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1246 while(1) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1247 if (do_seek) { |
8795
b4512aa07711
mosu: Fixed OGG/OGM seeking for XCDs in which the OGG/OGM does not start at pos 0 in the stream
mosu
parents:
8788
diff
changeset
|
1248 stream_seek(demuxer->stream,pos+demuxer->movi_start); |
5732 | 1249 ogg_sync_reset(sync); |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1250 for(i = 0 ; i < ogg_d->num_sub ; i++) { |
5732 | 1251 ogg_stream_reset(&ogg_d->subs[i].stream); |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1252 ogg_d->subs[i].lastpos = ogg_d->subs[i].lastsize = 0; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1253 } |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1254 ogg_d->pos = pos; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1255 ogg_d->last_size = 0; |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1256 /* we just guess that we reached correct granulepos, in case a |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1257 subsequent search occurs before we read a valid granulepos */ |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1258 os->lastpos = gp; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1259 first = !(ogg_d->syncpoints); |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1260 do_seek=0; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1261 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1262 ogg_d->pos += ogg_d->last_size; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1263 ogg_d->last_size = 0; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1264 np = ogg_sync_pageseek(sync,page); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1265 |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1266 if(np < 0) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1267 ogg_d->pos -= np; |
5732 | 1268 if(np <= 0) { // We need more data |
1269 char* buf = ogg_sync_buffer(sync,BLOCK_SIZE); | |
1270 int len = stream_read(demuxer->stream,buf,BLOCK_SIZE); | |
1271 if(len == 0 && demuxer->stream->eof) { | |
1272 mp_msg(MSGT_DEMUX,MSGL_ERR,"EOF while trying to seek !!!!\n"); | |
1273 break; | |
1274 } | |
1275 ogg_sync_wrote(sync,len); | |
1276 continue; | |
1277 } | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1278 ogg_d->last_size = np; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1279 if(ogg_page_serialno(page) != oss->serialno) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1280 continue; |
5732 | 1281 |
1282 if(ogg_stream_pagein(oss,page) != 0) | |
1283 continue; | |
1284 | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1285 while(1) { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1286 np = ogg_stream_packetout(oss,&op); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1287 if(np < 0) |
5732 | 1288 continue; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1289 else if(np == 0) |
5732 | 1290 break; |
8655
f8e53f8cb8b2
bunkus: Fixed Ogg/Ogm seeking by discarding the first packet after the seek which may be incomplete
mosu
parents:
8618
diff
changeset
|
1291 if (first) { /* Discard the first packet as it's probably broken, |
f8e53f8cb8b2
bunkus: Fixed Ogg/Ogm seeking by discarding the first packet after the seek which may be incomplete
mosu
parents:
8618
diff
changeset
|
1292 and we don't have any other means to decide whether it is |
f8e53f8cb8b2
bunkus: Fixed Ogg/Ogm seeking by discarding the first packet after the seek which may be incomplete
mosu
parents:
8618
diff
changeset
|
1293 complete or not. */ |
f8e53f8cb8b2
bunkus: Fixed Ogg/Ogm seeking by discarding the first packet after the seek which may be incomplete
mosu
parents:
8618
diff
changeset
|
1294 first = 0; |
f8e53f8cb8b2
bunkus: Fixed Ogg/Ogm seeking by discarding the first packet after the seek which may be incomplete
mosu
parents:
8618
diff
changeset
|
1295 break; |
f8e53f8cb8b2
bunkus: Fixed Ogg/Ogm seeking by discarding the first packet after the seek which may be incomplete
mosu
parents:
8618
diff
changeset
|
1296 } |
12265 | 1297 is_gp_valid = (op.granulepos >= 0); |
12263
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1298 demux_ogg_read_packet(os,&op,context,&pts,&is_keyframe); |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1299 if (precision && is_gp_valid) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1300 precision--; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1301 if (abs(gp - op.granulepos) > rate && (op.granulepos != old_gp)) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1302 //prepare another seek because we are off by more than 1s |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1303 pos += (gp - op.granulepos) * (pos - old_pos) / (op.granulepos - old_gp); |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1304 if (pos < 0) pos = 0; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1305 if (pos < (demuxer->movi_end - demuxer->movi_start)) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1306 do_seek=1; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1307 break; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1308 } |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1309 } |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1310 } |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1311 if (is_gp_valid && (pos > 0) && (old_gp > gp) |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1312 && (2 * (old_gp - op.granulepos) < old_gp - gp)) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1313 /* prepare another seek because looking for a syncpoint |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1314 destroyed the backward search */ |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1315 pos = old_pos - 1.5 * (old_pos - pos); |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1316 if (pos < 0) pos = 0; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1317 if (pos < (demuxer->movi_end - demuxer->movi_start)) { |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1318 do_seek=1; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1319 break; |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1320 } |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1321 } |
26be0fd618b5
Much improved seeking. Patch by Michael Behrich <behrisch at informatik adot hu-berlin anotherdot de>
mosu
parents:
12135
diff
changeset
|
1322 if(!precision && (is_keyframe || os->vorbis) ) { |
8788
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
1323 ogg_sub.lines = 0; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
1324 vo_sub = &ogg_sub; |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
1325 vo_osd_changed(OSDTYPE_SUBTITLE); |
ee443da1cef3
mosu: subtitles will be cleared after their life time as given in the packet's header has expired and after seeking
mosu
parents:
8655
diff
changeset
|
1326 clear_sub = -1; |
12104
fdce1dd97638
Support for selecting subtitles with -slang. Patch by Andriy N Gritsenko <andrej at lucky onedot net>
mosu
parents:
11898
diff
changeset
|
1327 demux_ogg_add_packet(ds,os,ds->id,&op); |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1328 if(sh_audio) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1329 resync_audio_stream(sh_audio); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1330 return; |
5732 | 1331 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
1332 } |
5732 | 1333 } |
1334 | |
1335 mp_msg(MSGT_DEMUX,MSGL_ERR,"Can't find the good packet :(\n"); | |
1336 | |
1337 } | |
1338 | |
5812 | 1339 void demux_close_ogg(demuxer_t* demuxer) { |
1340 ogg_demuxer_t* ogg_d = demuxer->priv; | |
1341 | |
1342 if(!ogg_d) | |
1343 return; | |
1344 | |
8618
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
1345 #ifdef USE_ICONV |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
1346 subcp_close(); |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
1347 #endif |
a879b231b7e3
This patch adds a call to subcp_recode1(), so this subtitles too are
arpi
parents:
8375
diff
changeset
|
1348 |
5812 | 1349 if(ogg_d->subs) |
1350 free(ogg_d->subs); | |
1351 if(ogg_d->syncpoints) | |
1352 free(ogg_d->syncpoints); | |
1353 free(ogg_d); | |
1354 } | |
1355 | |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1356 int demux_ogg_control(demuxer_t *demuxer,int cmd, void *arg){ |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1357 ogg_demuxer_t* ogg_d = demuxer->priv; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1358 ogg_stream_t* os; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1359 float rate; |
11577 | 1360 |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1361 if(demuxer->video->id >= 0) { |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1362 os = &ogg_d->subs[demuxer->video->id]; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1363 rate = os->samplerate; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1364 } else { |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1365 os = &ogg_d->subs[demuxer->audio->id]; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1366 rate = (float)((ov_struct_t*)((sh_audio_t*)demuxer->audio->sh)->context)->vi.rate; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1367 } |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1368 |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1369 |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1370 switch(cmd) { |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1371 case DEMUXER_CTRL_GET_TIME_LENGTH: |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1372 if (ogg_d->final_granulepos<=0) return DEMUXER_CTRL_DONTKNOW; |
11577 | 1373 *((unsigned long *)arg)=ogg_d->final_granulepos / rate; |
11575
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1374 return DEMUXER_CTRL_GUESS; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1375 |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1376 case DEMUXER_CTRL_GET_PERCENT_POS: |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1377 if (ogg_d->final_granulepos<=0) return DEMUXER_CTRL_DONTKNOW; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1378 *((int *)arg)=(int)( (os->lastpos*100) / ogg_d->final_granulepos); |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1379 return DEMUXER_CTRL_OK; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1380 |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1381 default: |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1382 return DEMUXER_CTRL_NOTIMPL; |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1383 } |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1384 } |
0ac7fe8f3af8
Get the total length for Ogg files. Patch by Michael Behrisch <behrisch@informatik.hu-berlin.de>.
mosu
parents:
11467
diff
changeset
|
1385 |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
1386 #endif |