Mercurial > mplayer.hg
annotate libmpdemux/demux_ogg.c @ 7535:37bc382a61e6
no fix window size
author | pontscho |
---|---|
date | Sat, 28 Sep 2002 19:00:50 +0000 |
parents | 7d83ac879f51 |
children | 5262223af043 |
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> |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
8 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
9 #include "../mp_msg.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
10 #include "../help_mp.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
11 #include "stream.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
12 #include "demuxer.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
13 #include "stheader.h" |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
14 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
15 #include <ogg/ogg.h> |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
16 #include <vorbis/codec.h> |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
17 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
18 #define BLOCK_SIZE 4096 |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
19 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
20 /// 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
|
21 /// 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
|
22 typedef struct ov_struct_st { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
23 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
|
24 settings */ |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
25 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
|
26 vorbis_block vb; /* local working space for packet->PCM decode */ |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
27 } ov_struct_t; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
28 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
29 //// OggDS headers |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
30 // Header for the new header format |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
31 typedef struct stream_header_video |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
32 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
33 ogg_int32_t width; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
34 ogg_int32_t height; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
35 } stream_header_video; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
36 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
37 typedef struct stream_header_audio |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
38 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
39 ogg_int16_t channels; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
40 ogg_int16_t blockalign; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
41 ogg_int32_t avgbytespersec; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
42 } stream_header_audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
43 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
44 typedef struct stream_header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
45 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
46 char streamtype[8]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
47 char subtype[4]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
48 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
49 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
|
50 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
51 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
|
52 ogg_int64_t samples_per_unit; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
53 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
|
54 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
55 ogg_int32_t buffersize; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
56 ogg_int16_t bits_per_sample; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
57 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
58 union |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
59 { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
60 // Video specific |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
61 stream_header_video video; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
62 // Audio specific |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
63 stream_header_audio audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
64 } sh; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
65 } stream_header; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
66 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
67 /// Our private datas |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
68 |
5732 | 69 typedef struct ogg_syncpoint { |
70 int64_t granulepos; | |
71 off_t page_pos; | |
72 } ogg_syncpoint_t; | |
73 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
74 /// A logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
75 typedef struct ogg_stream { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
76 /// Timestamping stuff |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
77 float samplerate; /// granulpos 2 time |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
78 int64_t lastpos; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
79 int32_t lastsize; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
80 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
81 // Logical stream state |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
82 ogg_stream_state stream; |
5732 | 83 int hdr_packets; |
84 int vorbis; | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
85 } ogg_stream_t; |
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 typedef struct ogg_demuxer { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
88 /// Physical stream state |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
89 ogg_sync_state sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
90 /// Current page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
91 ogg_page page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
92 /// Logical streams |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
93 ogg_stream_t *subs; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
94 int num_sub; |
5732 | 95 ogg_syncpoint_t* syncpoints; |
96 int num_syncpoint; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
97 off_t pos, last_size; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
98 } ogg_demuxer_t; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
99 |
5732 | 100 #define NUM_VORBIS_HDR_PACKETS 3 |
101 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
102 /// Some defines from OggDS |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
103 #define PACKET_TYPE_HEADER 0x01 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
104 #define PACKET_TYPE_BITS 0x07 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
105 #define PACKET_LEN_BITS01 0xc0 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
106 #define PACKET_LEN_BITS2 0x02 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
107 #define PACKET_IS_SYNCPOINT 0x08 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
108 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
109 extern int index_mode; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
110 |
7010 | 111 //-------- subtitle support - should be moved to decoder layer, and queue |
112 // - subtitles up in demuxer buffer... | |
113 | |
114 #include "../subreader.h" | |
115 #include "../libvo/sub.h" | |
116 #define OGG_SUB_MAX_LINE 128 | |
117 | |
118 static subtitle ogg_sub; | |
119 extern subtitle* vo_sub; | |
120 //FILE* subout; | |
121 | |
122 void demux_ogg_init_sub () { | |
123 int lcv; | |
124 if(!ogg_sub.text[0]) // not yet allocated | |
125 for (lcv = 0; lcv < SUB_MAX_TEXT; lcv++) { | |
126 ogg_sub.text[lcv] = (char*)malloc(OGG_SUB_MAX_LINE); | |
127 } | |
128 } | |
129 | |
130 void demux_ogg_add_sub (char* packet) { | |
131 int lcv; | |
132 int line_pos = 0; | |
133 int ignoring = 0; | |
134 | |
135 mp_msg(MSGT_DEMUX,MSGL_DBG2,"\ndemux_ogg_add_sub %02X %02X %02X '%s'\n", | |
136 (unsigned char)packet[0], | |
137 (unsigned char)packet[1], | |
138 (unsigned char)packet[2], | |
139 &packet[3]); | |
140 | |
141 ogg_sub.lines = 0; | |
142 if (((unsigned char)packet[0]) == 0x88) { // some subtitle text | |
143 lcv = 3; | |
144 while (1) { | |
145 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
|
146 if(c=='\n' || c==0 || line_pos >= OGG_SUB_MAX_LINE-1){ |
7010 | 147 ogg_sub.text[ogg_sub.lines][line_pos] = 0; // close sub |
148 if(line_pos) ogg_sub.lines++; | |
149 if(!c || ogg_sub.lines>=SUB_MAX_TEXT) break; // EOL or TooMany | |
150 line_pos = 0; | |
151 } | |
152 switch (c) { | |
153 case '\r': | |
154 case '\n': // just ignore linefeeds for now | |
155 // their placement seems rather haphazard | |
156 break; | |
157 case '<': // some html markup, ignore for now | |
158 ignoring = 1; | |
159 break; | |
160 case '>': | |
161 ignoring = 0; | |
162 break; | |
163 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
|
164 if(!ignoring) |
7010 | 165 ogg_sub.text[ogg_sub.lines][line_pos++] = c; |
166 break; | |
167 } | |
168 } | |
169 } | |
170 | |
171 mp_msg(MSGT_DEMUX,MSGL_DBG2,"ogg sub lines: %d first: '%s'\n", | |
172 ogg_sub.lines, ogg_sub.text[0]); | |
173 vo_sub = &ogg_sub; | |
174 vo_osd_changed(OSDTYPE_SUBTITLE); | |
175 } | |
176 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
177 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
178 // 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
|
179 // 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
|
180 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
|
181 int id,s_no; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
182 ogg_page* page = &ogg_d->page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
183 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
184 s_no = ogg_page_serialno(page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
185 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
186 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
|
187 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
|
188 break; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
189 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
190 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
191 if(id == ogg_d->num_sub) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
192 return -1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
193 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
194 if(os) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
195 *os = &ogg_d->subs[id].stream; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
196 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
197 return id; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
198 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
199 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
200 |
5732 | 201 static unsigned char* demux_ogg_read_packet(ogg_stream_t* os,ogg_packet* pack,vorbis_info* vi,float* pts,int* flags) { |
202 unsigned char* data; | |
203 | |
204 *pts = 0; | |
205 *flags = 0; | |
206 | |
207 if(os->vorbis) { | |
208 data = pack->packet; | |
209 if(*pack->packet & PACKET_TYPE_HEADER) | |
210 os->hdr_packets++; | |
211 else if(vi) { | |
212 // When we dump the audio, there is no vi, but we dont care of timestamp in this case | |
213 int32_t blocksize = vorbis_packet_blocksize(vi,pack) / vi->channels; | |
214 // Calculate the timestamp if the packet don't have any | |
215 if(pack->granulepos == -1) { | |
216 pack->granulepos = os->lastpos; | |
217 if(os->lastsize > 0) | |
218 pack->granulepos += os->lastsize; | |
219 } | |
220 *pts = pack->granulepos / (float)vi->rate; | |
221 os->lastsize = blocksize; | |
222 os->lastpos = pack->granulepos; | |
223 } | |
224 } else { | |
225 // Find data start | |
226 int16_t hdrlen = (*pack->packet & PACKET_LEN_BITS01)>>6; | |
227 hdrlen |= (*pack->packet & PACKET_LEN_BITS2) <<1; | |
228 data = pack->packet + 1 + hdrlen; | |
229 // Calculate the timestamp | |
230 if(pack->granulepos == -1) | |
231 pack->granulepos = os->lastpos + os->lastsize; | |
232 // If we alredy have a timestamp it can be a syncpoint | |
233 if(*pack->packet & PACKET_IS_SYNCPOINT) | |
234 *flags = 1; | |
235 *pts = pack->granulepos/os->samplerate; | |
236 // Save the packet length and timestamp | |
237 os->lastsize = 0; | |
238 while(hdrlen) { | |
239 os->lastsize <<= 8; | |
240 os->lastsize |= pack->packet[hdrlen]; | |
241 hdrlen--; | |
242 } | |
243 os->lastpos = pack->granulepos; | |
244 } | |
245 return data; | |
246 } | |
247 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
248 /// 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
|
249 // return 1 if the packet was added, 0 otherwise |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
250 static int demux_ogg_add_packet(demux_stream_t* ds,ogg_stream_t* os,ogg_packet* pack) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
251 demuxer_t* d = ds->demuxer; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
252 demux_packet_t* dp; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
253 unsigned char* data; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
254 float pts = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
255 int flags = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
256 |
7010 | 257 if (ds == d->sub) { // don't want to add subtitles to the demuxer for now |
258 demux_ogg_add_sub(pack->packet); | |
259 return 0; | |
260 } | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
261 // If packet is an header we jump it except for vorbis |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
262 if((*pack->packet & PACKET_TYPE_HEADER) && |
5732 | 263 (ds == d->video || (ds == d->audio && ( ((sh_audio_t*)ds->sh)->format != 0xFFFE || os->hdr_packets >= NUM_VORBIS_HDR_PACKETS ) ) )) |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
264 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
265 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
266 // For vorbis packet the packet is the data, for other codec we must jump the header |
5732 | 267 if(ds == d->audio && ((sh_audio_t*)ds->sh)->format == 0xFFFE) |
268 data = demux_ogg_read_packet(os,pack,&((ov_struct_t*)((sh_audio_t*)ds->sh)->context)->vi, | |
269 &pts,&flags); | |
270 else | |
271 data = demux_ogg_read_packet(os,pack,NULL,&pts,&flags); | |
272 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
273 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
274 /// Send the packet |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
275 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
|
276 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
|
277 dp->pts = pts; |
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
278 dp->flags = flags; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
279 ds_add_packet(ds,dp); |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
280 if(verbose>1)printf("New dp: %p ds=%p pts=%5.3f len=%d flag=%d \n", |
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
281 dp, ds, pts, dp->len, flags); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
282 return 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
283 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
284 |
5732 | 285 /// Build a table of all syncpoints to make seeking easier |
286 void demux_ogg_build_syncpoints_table(demuxer_t* demuxer) { | |
287 ogg_demuxer_t* ogg_d = demuxer->priv; | |
288 stream_t *s = demuxer->stream; | |
289 ogg_sync_state* sync = &ogg_d->sync; | |
290 ogg_page* page= &ogg_d->page; | |
291 ogg_stream_state* oss; | |
292 ogg_stream_t* os; | |
293 ogg_packet op; | |
294 int np,sid,p; | |
295 vorbis_info* vi = NULL; | |
296 off_t pos, last_pos; | |
297 pos = last_pos = demuxer->movi_start; | |
298 | |
299 // Reset the stream | |
300 stream_seek(s,demuxer->movi_start); | |
301 ogg_sync_reset(sync); | |
302 | |
303 // Get the serial number of the stream we use | |
304 if(demuxer->video->id >= 0) | |
305 sid = demuxer->video->id; | |
306 else { | |
307 sid = demuxer->audio->id; | |
308 if(((sh_audio_t*)demuxer->audio->sh)->format == 0xFFFE) | |
309 vi = &((ov_struct_t*)((sh_audio_t*)demuxer->audio->sh)->context)->vi; | |
310 } | |
311 os = &ogg_d->subs[sid]; | |
312 oss = &os->stream; | |
313 | |
314 while(1) { | |
315 np = ogg_sync_pageseek(sync,page); | |
316 if(np < 0) { // We had to skip some bytes | |
317 mp_msg(MSGT_DEMUX,MSGL_ERR,"Bad page sync while building syncpoints table (%ld)\n",-np); | |
318 pos += -np; | |
319 continue; | |
320 } | |
321 if(np <= 0) { // We need more data | |
322 char* buf = ogg_sync_buffer(sync,BLOCK_SIZE); | |
323 int len = stream_read(s,buf,BLOCK_SIZE); | |
324 if(len == 0 && s->eof) | |
325 break; | |
326 ogg_sync_wrote(sync,len); | |
327 continue; | |
328 } | |
329 // The page is ready | |
330 //ogg_sync_pageout(sync,page); | |
331 if(ogg_page_serialno(page) != os->stream.serialno) { // It isn't a page from the stream we want | |
332 pos += np; | |
333 continue; | |
334 } | |
335 if(ogg_stream_pagein(oss,page) != 0) { | |
336 mp_msg(MSGT_DEMUX,MSGL_ERR,"Pagein error ????\n"); | |
337 pos += np; | |
338 continue; | |
339 } | |
340 p = 0; | |
341 while(ogg_stream_packetout(oss,&op) == 1) { | |
342 float pts; | |
343 int flags; | |
344 demux_ogg_read_packet(os,&op,vi,&pts,&flags); | |
345 if(flags || (os->vorbis && op.granulepos >= 0)) { | |
346 ogg_d->syncpoints = (ogg_syncpoint_t*)realloc(ogg_d->syncpoints,(ogg_d->num_syncpoint+1)*sizeof(ogg_syncpoint_t)); | |
347 ogg_d->syncpoints[ogg_d->num_syncpoint].granulepos = op.granulepos; | |
348 ogg_d->syncpoints[ogg_d->num_syncpoint].page_pos = (ogg_page_continued(page) && p == 0) ? last_pos : pos; | |
349 ogg_d->num_syncpoint++; | |
350 } | |
351 p++; | |
352 } | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
353 if(p > 1 || (p == 1 && ! ogg_page_continued(page))) |
5732 | 354 last_pos = pos; |
355 pos += np; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
356 mp_msg(MSGT_DEMUX,MSGL_INFO,"Building syncpoint table %d%\r",pos*100/s->end_pos); |
5732 | 357 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
358 mp_msg(MSGT_DEMUX,MSGL_INFO,"\n"); |
5732 | 359 |
360 mp_msg(MSGT_DEMUX,MSGL_V,"Ogg syncpoints table builed: %d syncpoints\n",ogg_d->num_syncpoint); | |
361 | |
362 stream_reset(s); | |
363 stream_seek(s,demuxer->movi_start); | |
364 ogg_sync_reset(sync); | |
365 for(np = 0 ; np < ogg_d->num_sub ; np++) { | |
366 ogg_stream_reset(&ogg_d->subs[np].stream); | |
367 ogg_d->subs[np].lastpos = ogg_d->subs[np].lastsize = ogg_d->subs[np].hdr_packets = 0; | |
368 } | |
369 | |
370 | |
371 // Get the first page | |
372 while(1) { | |
373 np = ogg_sync_pageout(sync,page); | |
374 if(np <= 0) { // We need more data | |
375 char* buf = ogg_sync_buffer(sync,BLOCK_SIZE); | |
376 int len = stream_read(s,buf,BLOCK_SIZE); | |
377 if(len == 0 && s->eof) { | |
378 mp_msg(MSGT_DEMUX,MSGL_ERR,"EOF while trying to get the first page !!!!\n"); | |
379 break; | |
380 } | |
381 | |
382 ogg_sync_wrote(sync,len); | |
383 continue; | |
384 } | |
385 demux_ogg_get_page_stream(ogg_d,&oss); | |
386 ogg_stream_pagein(oss,page); | |
387 break; | |
388 } | |
389 | |
390 } | |
391 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
392 /// Open an ogg physical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
393 int demux_ogg_open(demuxer_t* demuxer) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
394 ogg_demuxer_t* ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
395 stream_t *s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
396 char* buf; |
7010 | 397 int np,s_no, n_audio = 0, n_video = 0, n_text = 0; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
398 ogg_sync_state* sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
399 ogg_page* page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
400 ogg_packet pack; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
401 sh_audio_t* sh_a; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
402 sh_video_t* sh_v; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
403 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
404 s = demuxer->stream; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
405 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
406 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
|
407 sync = &ogg_d->sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
408 page = &ogg_d->page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
409 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
410 ogg_sync_init(sync); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
411 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
412 while(1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
413 /// Try to get a page |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
414 ogg_d->pos += ogg_d->last_size; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
415 np = ogg_sync_pageseek(sync,page); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
416 /// Error |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
417 if(np < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
418 mp_msg(MSGT_DEMUX,MSGL_DBG2,"OGG demuxer : Bad page sync\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
419 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
420 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
421 /// Need some more data |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
422 if(np == 0) { |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
423 int len; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
424 buf = ogg_sync_buffer(sync,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
425 len = stream_read(s,buf,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
426 if(len == 0 && s->eof) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
427 free(ogg_d); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
428 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
429 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
430 ogg_sync_wrote(sync,len); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
431 continue; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
432 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
433 ogg_d->last_size = np; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
434 // We got one page now |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
435 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
436 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
|
437 // 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
|
438 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
|
439 if(id >= 0) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
440 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
|
441 else |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
442 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG : Warning found none bos page from unknow stream %d\n",ogg_page_serialno(page)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
443 break; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
444 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
445 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
446 /// 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
|
447 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
|
448 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
|
449 /// Get the stream serial number |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
450 s_no = ogg_page_serialno(page); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
451 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
|
452 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
|
453 // Take the first page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
454 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
|
455 // Get first packet of the page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
456 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
|
457 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
458 // Reset our vars |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
459 sh_a = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
460 sh_v = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
461 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
462 // Check for Vorbis |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
463 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
|
464 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
|
465 sh_a->format = 0xFFFE; |
5732 | 466 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
|
467 n_audio++; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
468 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
|
469 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
470 /// Check for old header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
471 } 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
|
472 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
473 // Old video header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
474 if(*(int32_t*)(pack.packet+96) == 0x05589f80 && pack.bytes >= 184) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
475 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
|
476 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
|
477 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
478 sh_v->bih->biCompression= |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
479 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
|
480 pack.packet[70],pack.packet[71]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
481 sh_v->frametime = (*(int64_t*)(pack.packet+164))*0.0000001; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
482 sh_v->fps = 1/sh_v->frametime; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
483 sh_v->disp_w = sh_v->bih->biWidth = *(int32_t*)(pack.packet+176); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
484 sh_v->disp_h = sh_v->bih->biHeight = *(int32_t*)(pack.packet+180); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
485 sh_v->bih->biBitCount = *(int16_t*)(pack.packet+182); |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
486 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
|
487 sh_v->bih->biPlanes=1; |
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
488 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
|
489 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
490 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
|
491 n_video++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
492 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is video (old hdr)\n",ogg_d->num_sub); |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
493 if(verbose) print_video_header(sh_v->bih); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
494 // Old audio header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
495 } else if(*(int32_t*)pack.packet+96 == 0x05589F81) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
496 unsigned int extra_size; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
497 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
|
498 extra_size = *(int16_t*)(pack.packet+140); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
499 sh_a->wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)+extra_size); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
500 sh_a->format = sh_a->wf->wFormatTag = *(int16_t*)(pack.packet+124); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
501 sh_a->channels = sh_a->wf->nChannels = *(int16_t*)(pack.packet+126); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
502 sh_a->samplerate = sh_a->wf->nSamplesPerSec = *(int32_t*)(pack.packet+128); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
503 sh_a->wf->nAvgBytesPerSec = *(int32_t*)(pack.packet+132); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
504 sh_a->wf->nBlockAlign = *(int16_t*)(pack.packet+136); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
505 sh_a->wf->wBitsPerSample = *(int16_t*)(pack.packet+138); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
506 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
|
507 sh_a->wf->cbSize = extra_size; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
508 if(extra_size > 0) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
509 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
|
510 |
7396
cfb1bc3925eb
The granule position of pages contining Vorbis audio is in units of
arpi
parents:
7115
diff
changeset
|
511 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
|
512 n_audio++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
513 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is audio (old hdr)\n",ogg_d->num_sub); |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
514 if(verbose) print_wave_header(sh_a->wf); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
515 } else |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
516 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG stream %d contain an old header but the header type is unknow\n",ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
517 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
518 // Check new header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
519 } 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
|
520 pack.bytes >= (int)sizeof(stream_header)+1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
521 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
|
522 /// New video header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
523 if(strncmp(st->streamtype,"video",5) == 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
524 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
|
525 sh_v->bih = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER)); |
5430 | 526 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
527 sh_v->bih->biCompression= | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
528 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
|
529 st->subtype[2],st->subtype[3]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
530 sh_v->frametime = st->time_unit*0.0000001; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
531 sh_v->fps = 1/sh_v->frametime; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
532 sh_v->bih->biBitCount = st->bits_per_sample; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
533 sh_v->disp_w = sh_v->bih->biWidth = st->sh.video.width; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
534 sh_v->disp_h = sh_v->bih->biHeight = st->sh.video.height; |
5430 | 535 if(!sh_v->bih->biBitCount) sh_v->bih->biBitCount=24; // hack, FIXME |
536 sh_v->bih->biPlanes=1; | |
537 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
|
538 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
539 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
|
540 n_video++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
541 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is video (new hdr)\n",ogg_d->num_sub); |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
542 if(verbose) print_video_header(sh_v->bih); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
543 /// New audio header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
544 } 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
|
545 char buffer[5]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
546 unsigned int extra_size = st->size - sizeof(stream_header); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
547 memcpy(buffer,st->subtype,4); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
548 buffer[4] = '\0'; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
549 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
|
550 sh_a->wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)+extra_size); |
6850 | 551 sh_a->format = sh_a->wf->wFormatTag = strtol(buffer, NULL, 16); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
552 sh_a->channels = sh_a->wf->nChannels = st->sh.audio.channels; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
553 sh_a->samplerate = sh_a->wf->nSamplesPerSec = st->samples_per_unit; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
554 sh_a->wf->nAvgBytesPerSec = st->sh.audio.avgbytespersec; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
555 sh_a->wf->nBlockAlign = st->sh.audio.blockalign; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
556 sh_a->wf->wBitsPerSample = st->bits_per_sample; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
557 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
|
558 sh_a->wf->cbSize = extra_size; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
559 if(extra_size) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
560 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
|
561 |
7396
cfb1bc3925eb
The granule position of pages contining Vorbis audio is in units of
arpi
parents:
7115
diff
changeset
|
562 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
|
563 n_audio++; |
5429
e9e2dc1306b1
BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents:
5428
diff
changeset
|
564 mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is audio (new hdr)\n",ogg_d->num_sub); |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
565 if(verbose) print_wave_header(sh_a->wf); |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
566 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
567 /// Check for text (subtitles) header |
7010 | 568 } else if (strncmp(st->streamtype, "text", 4) == 0) { |
569 mp_msg(MSGT_DEMUX, MSGL_V, "OGG stream %d is text\n", ogg_d->num_sub); | |
570 if(demuxer->sub->id==-1) demuxer->sub->id = ogg_d->num_sub; | |
571 n_text++; | |
572 demux_ogg_init_sub(); | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
573 //// Unknow header type |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
574 } else |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
575 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG stream %d has a header marker but is of an unknow type\n",ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
576 /// Unknow (invalid ?) header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
577 } else |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
578 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG stream %d is of an unknow type\n",ogg_d->num_sub); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
579 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
580 if(sh_a || sh_v) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
581 demux_stream_t* ds = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
582 if(sh_a) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
583 // 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
|
584 if(demuxer->audio->id == -1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
585 demuxer->audio->id = ogg_d->num_sub; |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
586 // 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
|
587 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
588 /// Is it the stream we want |
6156 | 589 if(demuxer->audio->id == ogg_d->num_sub) { |
6124
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
590 demuxer->audio->sh = sh_a; |
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
591 sh_a->ds = demuxer->audio; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
592 ds = demuxer->audio; |
6156 | 593 } |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
594 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
595 if(sh_v) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
596 /// Also for video |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
597 if(demuxer->video->id == -1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
598 demuxer->video->id = ogg_d->num_sub; |
5428
a43b00b28081
fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents:
5133
diff
changeset
|
599 // 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
|
600 } |
6156 | 601 if(demuxer->video->id == ogg_d->num_sub) { |
6124
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
602 demuxer->video->sh = sh_v; |
12b1f920c1f4
a/v stream selection - patch by alexander.werth@gmx.de
arpi
parents:
5812
diff
changeset
|
603 sh_v->ds = demuxer->video; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
604 ds = demuxer->video; |
6156 | 605 } |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
606 } |
5732 | 607 /// Add the header packets if the stream isn't seekable |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
608 if(ds && (!s->end_pos || index_mode != 2)) { |
5732 | 609 /// Finish the page, otherwise packets will be lost |
610 do { | |
611 demux_ogg_add_packet(ds,&ogg_d->subs[ogg_d->num_sub],&pack); | |
612 } while(ogg_stream_packetout(&ogg_d->subs[ogg_d->num_sub].stream,&pack) == 1); | |
613 } | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
614 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
615 ogg_d->num_sub++; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
616 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
617 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
618 /// Finish to setup the demuxer |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
619 demuxer->priv = ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
620 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
621 if(!n_video) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
622 demuxer->video->id = -2; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
623 if(!n_audio) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
624 demuxer->audio->id = -2; |
7010 | 625 if(!n_text) |
626 demuxer->sub->id = -2; | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
627 |
5732 | 628 if(!s->end_pos) |
629 demuxer->seekable = 0; | |
630 else { | |
631 demuxer->movi_start = 0; | |
632 demuxer->movi_end = s->end_pos; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
633 demuxer->seekable = 1; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
634 if(index_mode == 2) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
635 demux_ogg_build_syncpoints_table(demuxer); |
5732 | 636 } |
637 | |
7010 | 638 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
|
639 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
640 return 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
641 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
642 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
643 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
644 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
|
645 ogg_demuxer_t* ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
646 stream_t *s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
647 demux_stream_t *ds; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
648 ogg_sync_state* sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
649 ogg_stream_state* os; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
650 ogg_page* page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
651 ogg_packet pack; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
652 int np = 0, id=0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
653 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
654 s = d->stream; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
655 ogg_d = d->priv; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
656 sync = &ogg_d->sync; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
657 page = &ogg_d->page; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
658 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
659 /// Find the stream we are working on |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
660 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
|
661 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
|
662 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
663 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
664 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
665 while(1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
666 np = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
667 ds = NULL; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
668 /// 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
|
669 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
|
670 /// No packet we go the next page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
671 if(np == 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
672 while(1) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
673 int pa,len; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
674 char *buf; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
675 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
|
676 /// 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
|
677 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
|
678 /// Error : we skip some bytes |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
679 if(pa < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
680 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
|
681 ogg_d->pos -= pa; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
682 continue; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
683 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
684 /// We need more data |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
685 buf = ogg_sync_buffer(sync,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
686 len = stream_read(s,buf,BLOCK_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
687 if(len == 0 && s->eof) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
688 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
|
689 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
690 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
691 ogg_sync_wrote(sync,len); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
692 } /// Page loop |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
693 ogg_d->last_size = pa; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
694 /// Find the page's logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
695 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
|
696 mp_msg(MSGT_DEMUX,MSGL_ERR,"OGG demuxer error : we met an unknow stream\n"); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
697 return 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
698 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
699 /// Take the page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
700 if(ogg_stream_pagein(os,page) == 0) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
701 break; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
702 /// Page was invalid => retry |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
703 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
|
704 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
|
705 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
706 } else /// Packet was corrupted |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
707 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
|
708 } /// Packet loop |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
709 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
710 /// Is the actual logical stream in use ? |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
711 if(id == d->audio->id) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
712 ds = d->audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
713 else if(id == d->video->id) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
714 ds = d->video; |
7010 | 715 else if (id == d->sub->id) |
716 ds = d->sub; | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
717 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
718 if(ds) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
719 if(!demux_ogg_add_packet(ds,&ogg_d->subs[id],&pack)) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
720 continue; /// Unuseful packet, get another |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
721 d->filepos = ogg_d->pos; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
722 return 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
723 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
724 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
725 } /// while(1) |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
726 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
727 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
728 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
729 /// 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
|
730 // 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
|
731 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
|
732 demuxer_t *od; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
733 ogg_demuxer_t *ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
734 stream_t* s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
735 uint32_t hdrsizes[3]; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
736 demux_packet_t *dp; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
737 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
|
738 int np; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
739 unsigned char *p = NULL,*buf; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
740 int plen; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
741 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
742 /// Check that the cbSize is enouth big for the following reads |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
743 if(sh_audio->wf->cbSize < 3*sizeof(uint32_t)) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
744 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
|
745 goto fallback; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
746 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
747 /// Get the size of the 3 header packet |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
748 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t)); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
749 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
750 /// Check the size |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
751 if(sh_audio->wf->cbSize < 3*sizeof(uint32_t) + sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1] + hdrsizes[2]) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
752 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
|
753 goto fallback; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
754 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
755 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
756 // Build the ogg demuxer private datas |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
757 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
|
758 ogg_d->num_sub = 1; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
759 ogg_d->subs = (ogg_stream_t*)malloc(sizeof(ogg_stream_t)); |
5812 | 760 ogg_d->subs[0].vorbis = 1; |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
761 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
762 // Init the ogg physical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
763 ogg_sync_init(&ogg_d->sync); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
764 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
765 // 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
|
766 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
|
767 if(np < 0) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
768 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
|
769 free(ogg_d); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
770 goto fallback; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
771 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
772 // Add some data |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
773 plen = ds_get_packet(demuxer->audio,&p); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
774 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
|
775 memcpy(buf,p,plen); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
776 ogg_sync_wrote(&ogg_d->sync,plen); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
777 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
778 // Init the logical stream |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
779 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
|
780 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
|
781 // Write the page |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
782 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
|
783 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
784 // 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
|
785 s = new_ds_stream(demuxer->audio); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
786 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
|
787 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
788 /// 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
|
789 // Initial header |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
790 dp = new_demux_packet(hdrsizes[0]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
791 memcpy(dp->buffer,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdrsizes[0]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
792 ds_add_packet(od->audio,dp); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
793 /// Comments |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
794 dp = new_demux_packet(hdrsizes[1]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
795 memcpy(dp->buffer,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdrsizes[1]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
796 ds_add_packet(od->audio,dp); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
797 /// Code book |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
798 dp = new_demux_packet(hdrsizes[2]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
799 memcpy(dp->buffer,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdrsizes[2]); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
800 ds_add_packet(od->audio,dp); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
801 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
802 // Finish setting up the ogg demuxer |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
803 od->priv = ogg_d; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
804 sh_audio = new_sh_audio(od,0); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
805 od->audio->id = 0; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
806 od->video->id = -2; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
807 od->audio->sh = sh_audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
808 sh_audio->ds = od->audio; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
809 sh_audio->format = 0xFFFE; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
810 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
811 /// Return the joined demuxers |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
812 return new_demuxers_demuxer(demuxer,od,demuxer); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
813 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
814 fallback: |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
815 demuxer->audio->id = -2; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
816 return demuxer; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
817 |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
818 } |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
819 |
5732 | 820 void demux_ogg_seek(demuxer_t *demuxer,float rel_seek_secs,int flags) { |
821 ogg_demuxer_t* ogg_d = demuxer->priv; | |
822 ogg_sync_state* sync = &ogg_d->sync; | |
823 ogg_page* page= &ogg_d->page; | |
824 ogg_stream_state* oss; | |
825 ogg_stream_t* os; | |
826 demux_stream_t* ds; | |
827 sh_audio_t* sh_audio = demuxer->audio->sh; | |
828 ogg_packet op; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
829 float rate; |
5732 | 830 int i,sp; |
831 vorbis_info* vi = NULL; | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
832 int64_t gp = 0; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
833 off_t pos; |
5732 | 834 |
835 if(demuxer->video->id >= 0) { | |
836 ds = demuxer->video; | |
837 rate = ogg_d->subs[ds->id].samplerate; | |
838 } else { | |
839 ds = demuxer->audio; | |
840 vi = &((ov_struct_t*)((sh_audio_t*)ds->sh)->context)->vi; | |
841 rate = (float)vi->rate; | |
842 } | |
843 | |
844 os = &ogg_d->subs[ds->id]; | |
845 oss = &os->stream; | |
846 | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
847 if(ogg_d->syncpoints) { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
848 float time_pos = flags & 1 ? 0 : os->lastpos/ rate; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
849 if(flags & 2) { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
850 if(ogg_d->syncpoints) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
851 time_pos += ogg_d->syncpoints[ogg_d->num_syncpoint].granulepos / rate * rel_seek_secs; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
852 else |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
853 time_pos += (demuxer->movi_end - demuxer->movi_start) * rel_seek_secs; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
854 } else |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
855 time_pos += rel_seek_secs; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
856 |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
857 gp = time_pos * rate; |
5732 | 858 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
859 for(sp = 0; sp < ogg_d->num_syncpoint ; sp++) { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
860 if(ogg_d->syncpoints[sp].granulepos >= gp) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
861 break; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
862 } |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
863 |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
864 if(sp >= ogg_d->num_syncpoint) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
865 return; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
866 pos = ogg_d->syncpoints[sp].page_pos; |
5732 | 867 |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
868 } else { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
869 pos = flags & 1 ? demuxer->movi_start : ogg_d->pos; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
870 if(flags & 2) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
871 pos += (demuxer->movi_end - demuxer->movi_start) * rel_seek_secs; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
872 else |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
873 pos += rel_seek_secs * ogg_d->pos / (os->lastpos / rate); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
874 |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
875 if(pos < demuxer->movi_start) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
876 pos = demuxer->movi_start; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
877 else if(pos > demuxer->movi_end) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
878 return; |
5732 | 879 } |
880 | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
881 stream_seek(demuxer->stream,pos); |
5732 | 882 ogg_sync_reset(sync); |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
883 for(i = 0 ; i < ogg_d->num_sub ; i++) { |
5732 | 884 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
|
885 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
|
886 } |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
887 ogg_d->pos = pos; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
888 ogg_d->last_size = 0; |
5732 | 889 |
890 while(1) { | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
891 int np; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
892 ogg_d->pos += ogg_d->last_size; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
893 ogg_d->last_size = 0; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
894 np = ogg_sync_pageseek(sync,page); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
895 |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
896 if(np < 0) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
897 ogg_d->pos -= np; |
5732 | 898 if(np <= 0) { // We need more data |
899 char* buf = ogg_sync_buffer(sync,BLOCK_SIZE); | |
900 int len = stream_read(demuxer->stream,buf,BLOCK_SIZE); | |
901 if(len == 0 && demuxer->stream->eof) { | |
902 mp_msg(MSGT_DEMUX,MSGL_ERR,"EOF while trying to seek !!!!\n"); | |
903 break; | |
904 } | |
905 ogg_sync_wrote(sync,len); | |
906 continue; | |
907 } | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
908 ogg_d->last_size = np; |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
909 if(ogg_page_serialno(page) != oss->serialno) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
910 continue; |
5732 | 911 |
912 if(ogg_stream_pagein(oss,page) != 0) | |
913 continue; | |
914 | |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
915 while(1) { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
916 np = ogg_stream_packetout(oss,&op); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
917 if(np < 0) |
5732 | 918 continue; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
919 else if(np == 0) |
5732 | 920 break; |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
921 |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
922 if( ((*op.packet & PACKET_IS_SYNCPOINT) || os->vorbis ) && |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
923 (!ogg_d->syncpoints || op.granulepos >= gp) ) { |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
924 demux_ogg_add_packet(ds,os,&op); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
925 if(sh_audio) |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
926 resync_audio_stream(sh_audio); |
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
927 return; |
5732 | 928 } |
5809
4b24942acdbb
Add seeking without index (still not perfect). Use -forceidx for the
albeu
parents:
5732
diff
changeset
|
929 } |
5732 | 930 } |
931 | |
932 mp_msg(MSGT_DEMUX,MSGL_ERR,"Can't find the good packet :(\n"); | |
933 | |
934 } | |
935 | |
5812 | 936 void demux_close_ogg(demuxer_t* demuxer) { |
937 ogg_demuxer_t* ogg_d = demuxer->priv; | |
938 | |
939 if(!ogg_d) | |
940 return; | |
941 | |
942 if(ogg_d->subs) | |
943 free(ogg_d->subs); | |
944 if(ogg_d->syncpoints) | |
945 free(ogg_d->syncpoints); | |
946 free(ogg_d); | |
947 } | |
948 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff
changeset
|
949 #endif |