annotate libmpdemux/demux_ogg.c @ 6848:4846c53f548d

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