comparison libmpdemux/demux_ogg.c @ 20493:e8d37db54bf5

realloc subtitle buffers since subcp_recode might have decreased their size.
author reimar
date Sun, 29 Oct 2006 12:44:15 +0000
parents 4419e00b54df
children 30fce0f93ad1
comparison
equal deleted inserted replaced
20492:0b563edd9b3a 20493:e8d37db54bf5
223 ret = (ret << 8) + (tmp[0] & 0xff); 223 ret = (ret << 8) + (tmp[0] & 0xff);
224 224
225 return (ret); 225 return (ret);
226 } 226 }
227 227
228 void demux_ogg_init_sub (void) {
229 int lcv;
230 if(!ogg_sub.text[0]) // not yet allocated
231 for (lcv = 0; lcv < SUB_MAX_TEXT; lcv++) {
232 ogg_sub.text[lcv] = malloc(OGG_SUB_MAX_LINE);
233 }
234 }
235
236 void demux_ogg_add_sub (ogg_stream_t* os,ogg_packet* pack) { 228 void demux_ogg_add_sub (ogg_stream_t* os,ogg_packet* pack) {
237 int lcv; 229 int lcv;
238 int line_pos = 0; 230 int line_pos = 0;
239 int ignoring = 0; 231 int ignoring = 0;
240 char *packet = pack->packet; 232 char *packet = pack->packet;
261 if(pack->granulepos == -1) 253 if(pack->granulepos == -1)
262 pack->granulepos = os->lastpos + os->lastsize; 254 pack->granulepos = os->lastpos + os->lastsize;
263 pts = (float)pack->granulepos/(float)os->samplerate; 255 pts = (float)pack->granulepos/(float)os->samplerate;
264 clear_sub = 1.0 + pts + (float)duration/1000.0; 256 clear_sub = 1.0 + pts + (float)duration/1000.0;
265 } 257 }
258 ogg_sub.text[0] = realloc(ogg_sub.text[0], OGG_SUB_MAX_LINE);
266 while (1) { 259 while (1) {
267 int c = packet[lcv++]; 260 int c = packet[lcv++];
268 if(c=='\n' || c==0 || line_pos >= OGG_SUB_MAX_LINE-1){ 261 if(c=='\n' || c==0 || line_pos >= OGG_SUB_MAX_LINE-1){
269 ogg_sub.text[ogg_sub.lines][line_pos] = 0; // close sub 262 ogg_sub.text[ogg_sub.lines][line_pos] = 0; // close sub
270 if(line_pos) ogg_sub.lines++; 263 if(line_pos) {
264 ogg_sub.lines++;
265 ogg_sub.text[ogg_sub.lines] = realloc(ogg_sub.text[ogg_sub.lines], OGG_SUB_MAX_LINE);
266 }
271 if(!c || ogg_sub.lines>=SUB_MAX_TEXT) break; // EOL or TooMany 267 if(!c || ogg_sub.lines>=SUB_MAX_TEXT) break; // EOL or TooMany
272 line_pos = 0; 268 line_pos = 0;
273 } 269 }
274 switch (c) { 270 switch (c) {
275 case '\r': 271 case '\r':
1153 ogg_d->n_text++; 1149 ogg_d->n_text++;
1154 ogg_d->text_ids = (int *)realloc(ogg_d->text_ids, sizeof(int) * ogg_d->n_text); 1150 ogg_d->text_ids = (int *)realloc(ogg_d->text_ids, sizeof(int) * ogg_d->n_text);
1155 ogg_d->text_ids[ogg_d->n_text - 1] = ogg_d->num_sub; 1151 ogg_d->text_ids[ogg_d->n_text - 1] = ogg_d->num_sub;
1156 ogg_d->text_langs = (char **)realloc(ogg_d->text_langs, sizeof(char *) * ogg_d->n_text); 1152 ogg_d->text_langs = (char **)realloc(ogg_d->text_langs, sizeof(char *) * ogg_d->n_text);
1157 ogg_d->text_langs[ogg_d->n_text - 1] = NULL; 1153 ogg_d->text_langs[ogg_d->n_text - 1] = NULL;
1158 demux_ogg_init_sub();
1159 //// Unknown header type 1154 //// Unknown header type
1160 } else 1155 } else
1161 mp_msg(MSGT_DEMUX,MSGL_ERR,"Ogg stream %d has a header marker but is of an unknown type\n",ogg_d->num_sub); 1156 mp_msg(MSGT_DEMUX,MSGL_ERR,"Ogg stream %d has a header marker but is of an unknown type\n",ogg_d->num_sub);
1162 /// Unknown (invalid ?) header 1157 /// Unknown (invalid ?) header
1163 } else 1158 } else