annotate libmpdemux/demux_ogg.c @ 5650:71f221e98fa4

fix dvdnav detection
author pontscho
date Tue, 16 Apr 2002 17:29:04 +0000
parents 779ebb242aec
children 6586448b5243
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
4
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
5 #include <stdlib.h>
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
6 #include <stdio.h>
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
7
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
8 #include "../mp_msg.h"
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
9 #include "../help_mp.h"
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
10 #include "stream.h"
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
11 #include "demuxer.h"
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
12 #include "stheader.h"
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
13
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
14 #ifndef HAVE_OGGVORBIS
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
15 /// Some dummy function to use when no Ogg and Vorbis lib are avaible
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
16 int demux_ogg_open(demuxer_t* demuxer) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
17 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
18 }
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 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
21 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
22 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
23
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
24 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
25 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_NoOggVorbis);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
26 // disable audio
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
27 demuxer->audio->id = -2;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
28 return demuxer;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
29 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
30 #else
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
31
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
32 #include <ogg/ogg.h>
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
33 #include <vorbis/codec.h>
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
34
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
35 #define BLOCK_SIZE 1024
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 /// 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
38 /// 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
39 typedef struct ov_struct_st {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
40 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
41 settings */
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
42 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
43 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
44 } ov_struct_t;
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 //// OggDS headers
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
47 // Header for the new header format
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
48 typedef struct stream_header_video
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
49 {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
50 ogg_int32_t width;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
51 ogg_int32_t height;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
52 } stream_header_video;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
53
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
54 typedef struct stream_header_audio
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
55 {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
56 ogg_int16_t channels;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
57 ogg_int16_t blockalign;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
58 ogg_int32_t avgbytespersec;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
59 } stream_header_audio;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
60
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
61 typedef struct stream_header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
62 {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
63 char streamtype[8];
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
64 char subtype[4];
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
65
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
66 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
67
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
68 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
69 ogg_int64_t samples_per_unit;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
70 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
71
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
72 ogg_int32_t buffersize;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
73 ogg_int16_t bits_per_sample;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
74
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
75 union
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
76 {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
77 // Video specific
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
78 stream_header_video video;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
79 // Audio specific
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
80 stream_header_audio audio;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
81 } sh;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
82 } stream_header;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
83
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
84 /// Our private datas
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
85
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
86 /// A logical stream
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
87 typedef struct ogg_stream {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
88 /// Timestamping stuff
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
89 float samplerate; /// granulpos 2 time
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
90 int64_t lastpos;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
91 int32_t lastsize;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
92
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
93 // Logical stream state
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
94 ogg_stream_state stream;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
95 } ogg_stream_t;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
96
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
97 typedef struct ogg_demuxer {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
98 /// Physical stream state
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
99 ogg_sync_state sync;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
100 /// Current page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
101 ogg_page page;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
102 /// Logical streams
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
103 ogg_stream_t *subs;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
104 int num_sub;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
105 } ogg_demuxer_t;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
106
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
107 /// Some defines from OggDS
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
108 #define PACKET_TYPE_HEADER 0x01
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
109 #define PACKET_TYPE_BITS 0x07
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
110 #define PACKET_LEN_BITS01 0xc0
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
111 #define PACKET_LEN_BITS2 0x02
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
112 #define PACKET_IS_SYNCPOINT 0x08
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
113
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
114
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
115 // 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
116 // 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
117 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
118 int id,s_no;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
119 ogg_page* page = &ogg_d->page;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
120
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
121 s_no = ogg_page_serialno(page);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
122
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
123 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
124 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
125 break;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
126 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
127
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
128 if(id == ogg_d->num_sub)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
129 return -1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
130
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
131 if(os)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
132 *os = &ogg_d->subs[id].stream;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
133
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
134 return id;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
135
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
136 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
137
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
138 /// 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
139 // 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
140 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
141 demuxer_t* d = ds->demuxer;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
142 demux_packet_t* dp;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
143 unsigned char* data;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
144 float pts = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
145 int flags = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
146
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
147 // 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
148 if((*pack->packet & PACKET_TYPE_HEADER) &&
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
149 (ds == d->video || (ds == d->audio && ((sh_audio_t*)ds->sh)->format != 0xFFFE )))
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
150 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
151
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
152 // For vorbis packet the packet is the data, for other codec we must jump the header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
153 if(ds == d->audio && ((sh_audio_t*)ds->sh)->format == 0xFFFE) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
154 data = pack->packet;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
155 if(*pack->packet & PACKET_TYPE_HEADER)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
156 pts = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
157 else {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
158 vorbis_info* vi = &((ov_struct_t*)((sh_audio_t*)ds->sh)->context)->vi;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
159 // When we dump the audio, there is no vi, but we dont care of timestamp in this case
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
160 if(vi) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
161 int32_t blocksize = vorbis_packet_blocksize(vi,pack) / vi->channels;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
162 // Calculate the timestamp if the packet don't have any
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
163 if(pack->granulepos == -1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
164 pack->granulepos = os->lastpos;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
165 if(os->lastsize > 0)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
166 pack->granulepos += os->lastsize;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
167 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
168 pts = pack->granulepos / (float)vi->rate;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
169 os->lastsize = blocksize;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
170 os->lastpos = pack->granulepos;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
171 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
172 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
173 } else {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
174 // Find data start
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
175 int16_t hdrlen = (*pack->packet & PACKET_LEN_BITS01)>>6;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
176 hdrlen |= (*pack->packet & PACKET_LEN_BITS2) <<1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
177 data = pack->packet + 1 + hdrlen;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
178 // Calculate the timestamp
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
179 if(pack->granulepos == -1)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
180 pack->granulepos = os->lastpos + os->lastsize;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
181 // If we alredy have a timestamp it can be a syncpoint
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
182 else if(*pack->packet & PACKET_IS_SYNCPOINT)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
183 flags = 1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
184 pts = pack->granulepos/os->samplerate;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
185 // Save the packet length and timestamp
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
186 os->lastsize = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
187 while(hdrlen) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
188 os->lastsize <<= 8;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
189 os->lastsize |= pack->packet[hdrlen];
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
190 hdrlen--;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
191 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
192 os->lastpos = pack->granulepos;
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
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
195 /// Send the packet
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
196 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
197 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
198 dp->pts = pts;
a43b00b28081 fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents: 5133
diff changeset
199 dp->flags = flags;
5133
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
200 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
201 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
202 dp, ds, pts, dp->len, flags);
5133
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
203 return 1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
204 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
205
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
206 /// Open an ogg physical stream
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
207 int demux_ogg_open(demuxer_t* demuxer) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
208 ogg_demuxer_t* ogg_d;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
209 stream_t *s;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
210 char* buf;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
211 int np,s_no, n_audio = 0, n_video = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
212 ogg_sync_state* sync;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
213 ogg_page* page;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
214 ogg_packet pack;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
215 sh_audio_t* sh_a;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
216 sh_video_t* sh_v;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
217
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
218 s = demuxer->stream;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
219
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
220 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
221 sync = &ogg_d->sync;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
222 page = &ogg_d->page;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
223
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
224 ogg_sync_init(&ogg_d->sync);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
225
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
226 while(1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
227 /// Try to get a page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
228 np = ogg_sync_pageout(sync,page);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
229 /// Error
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
230 if(np < 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
231 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
232 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
233 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
234 /// Need some more data
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
235 if(np <= 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
236 int len;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
237 buf = ogg_sync_buffer(sync,BLOCK_SIZE);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
238 len = stream_read(s,buf,BLOCK_SIZE);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
239 if(len == 0 && s->eof) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
240 free(ogg_d);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
241 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
242 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
243 ogg_sync_wrote(sync,len);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
244 continue;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
245 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
246
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
247 // We got one page now
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
248
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
249 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
250 // 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
251 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
252 if(id >= 0)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
253 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
254 else
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
255 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
256 break;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
257 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
258
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
259 /// 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
260 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
261 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
262 /// Get the stream serial number
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
263 s_no = ogg_page_serialno(page);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
264 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
265 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
266 // Take the first page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
267 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
268 // Get first packet of the page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
269 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
270
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
271 // Reset our vars
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
272 sh_a = NULL;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
273 sh_v = NULL;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
274
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
275 // Check for Vorbis
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
276 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
277 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
278 sh_a->format = 0xFFFE;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
279 n_audio++;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
280 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
281
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
282 /// Check for old header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
283 } 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
284
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
285 // Old video header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
286 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
287 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
288 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
289 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER);
e9e2dc1306b1 BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents: 5428
diff changeset
290 sh_v->bih->biCompression=
5133
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
291 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
292 pack.packet[70],pack.packet[71]);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
293 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
294 sh_v->fps = 1/sh_v->frametime;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
295 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
296 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
297 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
298 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
299 sh_v->bih->biPlanes=1;
e9e2dc1306b1 BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents: 5428
diff changeset
300 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
301
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
302 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
303 n_video++;
5429
e9e2dc1306b1 BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents: 5428
diff changeset
304 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
305 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
306 // Old audio header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
307 } 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
308 unsigned int extra_size;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
309 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
310 extra_size = *(int16_t*)(pack.packet+140);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 sh_a->wf->cbSize = extra_size;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
320 if(extra_size > 0)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
321 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
322
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
323 ogg_d->subs[ogg_d->num_sub].samplerate = sh_a->samplerate * sh_a->channels;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
324 n_audio++;
5429
e9e2dc1306b1 BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents: 5428
diff changeset
325 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
326 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
327 } else
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
328 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
329
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
330 // Check new header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
331 } 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
332 pack.bytes >= (int)sizeof(stream_header)+1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
333 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
334 /// New video header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
335 if(strncmp(st->streamtype,"video",5) == 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
336 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
337 sh_v->bih = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER));
5430
779ebb242aec argh, some samples sue new header chunks - fixed
arpi
parents: 5429
diff changeset
338 sh_v->bih->biSize=sizeof(BITMAPINFOHEADER);
779ebb242aec argh, some samples sue new header chunks - fixed
arpi
parents: 5429
diff changeset
339 sh_v->bih->biCompression=
5133
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
340 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
341 st->subtype[2],st->subtype[3]);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
342 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
343 sh_v->fps = 1/sh_v->frametime;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
344 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
345 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
346 sh_v->disp_h = sh_v->bih->biHeight = st->sh.video.height;
5430
779ebb242aec argh, some samples sue new header chunks - fixed
arpi
parents: 5429
diff changeset
347 if(!sh_v->bih->biBitCount) sh_v->bih->biBitCount=24; // hack, FIXME
779ebb242aec argh, some samples sue new header chunks - fixed
arpi
parents: 5429
diff changeset
348 sh_v->bih->biPlanes=1;
779ebb242aec argh, some samples sue new header chunks - fixed
arpi
parents: 5429
diff changeset
349 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
350
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
351 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
352 n_video++;
5429
e9e2dc1306b1 BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents: 5428
diff changeset
353 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
354 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
355 /// New audio header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
356 } 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
357 char buffer[5];
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
358 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
359 memcpy(buffer,st->subtype,4);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
360 buffer[4] = '\0';
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
361 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
362 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
363 sh_a->format = sh_a->wf->wFormatTag = atoi(buffer);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
364 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
365 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
366 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
367 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
368 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
369 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
370 sh_a->wf->cbSize = extra_size;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
371 if(extra_size)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
372 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
373
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
374 ogg_d->subs[ogg_d->num_sub].samplerate = sh_a->samplerate * sh_a->channels;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
375 n_audio++;
5429
e9e2dc1306b1 BITMAPINFOHEADER fixed to be accepted by win32 decoders (divx,divxds)
arpi
parents: 5428
diff changeset
376 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
377 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
378
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
379 /// Check for text (subtitles) header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
380 } else if(strncmp(st->streamtype,"text",4) == 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
381 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG text stream are not supported\n");
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
382 //// Unknow header type
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
383 } else
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
384 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
385 /// Unknow (invalid ?) header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
386 } else
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
387 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
388
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
389 if(sh_a || sh_v) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
390 demux_stream_t* ds = NULL;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
391 if(sh_a) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
392 // 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
393 if(demuxer->audio->id == -1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
394 demuxer->audio->id = ogg_d->num_sub;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
395 demuxer->audio->sh = sh_a;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
396 sh_a->ds = demuxer->audio;
5428
a43b00b28081 fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents: 5133
diff changeset
397 // 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
398 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
399 /// Is it the stream we want
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
400 if(demuxer->audio->id == ogg_d->num_sub)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
401 ds = demuxer->audio;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
402 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
403 if(sh_v) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
404 /// Also for video
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
405 if(demuxer->video->id == -1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
406 demuxer->video->id = ogg_d->num_sub;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
407 demuxer->video->sh = sh_v;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
408 sh_v->ds = demuxer->video;
5428
a43b00b28081 fixed 10l bug: using ds instead of dp, and adding some debug prints
arpi
parents: 5133
diff changeset
409 // 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
410 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
411 if(demuxer->video->id == ogg_d->num_sub)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
412 ds = demuxer->video;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
413 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
414 /// Add the packet contained in this page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
415 if(ds) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
416 /// Finish the page, otherwise packets will be lost
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
417 do {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
418 demux_ogg_add_packet(ds,&ogg_d->subs[ogg_d->num_sub],&pack);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
419 } while(ogg_stream_packetout(&ogg_d->subs[ogg_d->num_sub].stream,&pack) == 1);
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 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
422 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
423 ogg_d->num_sub++;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
424 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
425
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
426 /// Finish to setup the demuxer
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
427 demuxer->priv = ogg_d;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
428 /// We can't seek :(
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
429 demuxer->seekable = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
430
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
431 if(!n_video)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
432 demuxer->video->id = -2;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
433 if(!n_audio)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
434 demuxer->audio->id = -2;
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 mp_msg(MSGT_DEMUX,MSGL_V,"OGG demuxer : found %d audio stream and %d video stream\n",n_audio,n_video);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
437
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
438 return 1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
439 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
440
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
441
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
442 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
443 ogg_demuxer_t* ogg_d;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
444 stream_t *s;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
445 demux_stream_t *ds;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
446 ogg_sync_state* sync;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
447 ogg_stream_state* os;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
448 ogg_page* page;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
449 ogg_packet pack;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
450 int np = 0, id=0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
451
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
452 s = d->stream;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
453 ogg_d = d->priv;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
454 sync = &ogg_d->sync;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
455 page = &ogg_d->page;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
456
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
457 /// Find the stream we are working on
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
458 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
459 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
460 return 0;
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
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
463 while(1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
464 np = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
465 ds = NULL;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
466 /// 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
467 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
468 /// No packet we go the next page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
469 if(np == 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
470 while(1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
471 int pa,len;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
472 char *buf;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
473 /// Get the next page from the physical stream
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
474 while( (pa = ogg_sync_pageout(sync,page)) != 1) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
475 /// Error : we skip some bytes
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
476 if(pa < 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
477 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG : Page out not synced, we skip some bytes\n");
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
478 continue;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
479 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
480 /// We need more data
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
481 buf = ogg_sync_buffer(sync,BLOCK_SIZE);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
482 len = stream_read(s,buf,BLOCK_SIZE);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
483 if(len == 0 && s->eof) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
484 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
485 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
486 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
487 ogg_sync_wrote(sync,len);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
488 } /// Page loop
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 /// Find the page's logical stream
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
491 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
492 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
493 return 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
494 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
495 /// Take the page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
496 if(ogg_stream_pagein(os,page) == 0)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
497 break;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
498 /// Page was invalid => retry
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
499 mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG demuxer : got invalid page !!!!!\n");
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
500 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
501 } else /// Packet was corrupted
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
502 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
503 } /// Packet loop
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
504
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
505 /// Is the actual logical stream in use ?
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
506 if(id == d->audio->id)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
507 ds = d->audio;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
508 else if(id == d->video->id)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
509 ds = d->video;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
510
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
511 if(ds) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
512 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
513 continue; /// Unuseful packet, get another
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
514 return 1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
515 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
516
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
517 } /// while(1)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
518
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
519 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
520
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
521 /// 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
522 // 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
523 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
524 demuxer_t *od;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
525 ogg_demuxer_t *ogg_d;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
526 stream_t* s;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
527 uint32_t hdrsizes[3];
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
528 demux_packet_t *dp;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
529 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
530 int np;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
531 unsigned char *p = NULL,*buf;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
532 int plen;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
533
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
534 /// 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
535 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
536 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
537 goto fallback;
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 /// 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
540 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
541
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
542 /// Check the size
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
543 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
544 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
545 goto fallback;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
546 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
547
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
548 // Build the ogg demuxer private datas
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
549 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
550 ogg_d->num_sub = 1;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
551 ogg_d->subs = (ogg_stream_t*)malloc(sizeof(ogg_stream_t));
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
552
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
553 // Init the ogg physical stream
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
554 ogg_sync_init(&ogg_d->sync);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
555
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
556 // 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
557 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
558 if(np < 0) {
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
559 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
560 free(ogg_d);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
561 goto fallback;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
562 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
563 // Add some data
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
564 plen = ds_get_packet(demuxer->audio,&p);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
565 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
566 memcpy(buf,p,plen);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
567 ogg_sync_wrote(&ogg_d->sync,plen);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
568 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
569 // Init the logical stream
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
570 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
571 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
572 // Write the page
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
573 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
574
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
575 // 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
576 s = new_ds_stream(demuxer->audio);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
577 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
578
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
579 /// 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
580 // Initial header
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
581 dp = new_demux_packet(hdrsizes[0]);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
582 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
583 ds_add_packet(od->audio,dp);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
584 /// Comments
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
585 dp = new_demux_packet(hdrsizes[1]);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
586 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
587 ds_add_packet(od->audio,dp);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
588 /// Code book
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
589 dp = new_demux_packet(hdrsizes[2]);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
590 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
591 ds_add_packet(od->audio,dp);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
592
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
593 // Finish setting up the ogg demuxer
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
594 od->priv = ogg_d;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
595 sh_audio = new_sh_audio(od,0);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
596 od->audio->id = 0;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
597 od->video->id = -2;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
598 od->audio->sh = sh_audio;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
599 sh_audio->ds = od->audio;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
600 sh_audio->format = 0xFFFE;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
601
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
602 /// Return the joined demuxers
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
603 return new_demuxers_demuxer(demuxer,od,demuxer);
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
604
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
605 fallback:
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
606 demuxer->audio->id = -2;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
607 return demuxer;
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
608
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
609 }
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
610
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
611 /// TODO : Seeking 8-)
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
612
9841a86d66f9 Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
diff changeset
613 #endif