FFmpeg
oggdec.c
Go to the documentation of this file.
1 /*
2  * Ogg bitstream support
3  * Luca Barbato <lu_zero@gentoo.org>
4  * Based on tcvp implementation
5  */
6 
7 /*
8  Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use, copy,
14  modify, merge, publish, distribute, sublicense, and/or sell copies
15  of the Software, and to permit persons to whom the Software is
16  furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be
19  included in all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  DEALINGS IN THE SOFTWARE.
29  */
30 
31 #include <stdio.h>
32 #include "libavutil/avassert.h"
33 #include "libavutil/intreadwrite.h"
34 #include "avio_internal.h"
35 #include "oggdec.h"
36 #include "avformat.h"
37 #include "internal.h"
38 #include "vorbiscomment.h"
39 
40 #define MAX_PAGE_SIZE 65307
41 #define DECODER_BUFFER_SIZE MAX_PAGE_SIZE
42 
43 static const struct ogg_codec * const ogg_codecs[] = {
52  &ff_vp8_codec,
59  NULL
60 };
61 
62 static int64_t ogg_calc_pts(AVFormatContext *s, int idx, int64_t *dts);
63 static int ogg_new_stream(AVFormatContext *s, uint32_t serial);
64 static int ogg_restore(AVFormatContext *s);
65 
66 static void free_stream(AVFormatContext *s, int i)
67 {
68  struct ogg *ogg = s->priv_data;
69  struct ogg_stream *stream = &ogg->streams[i];
70 
71  av_freep(&stream->buf);
72  if (stream->codec &&
73  stream->codec->cleanup) {
74  stream->codec->cleanup(s, i);
75  }
76 
77  av_freep(&stream->private);
78  av_freep(&stream->new_metadata);
79 }
80 
81 //FIXME We could avoid some structure duplication
83 {
84  struct ogg *ogg = s->priv_data;
85  struct ogg_state *ost =
86  av_malloc(sizeof(*ost) + (ogg->nstreams - 1) * sizeof(*ogg->streams));
87  int i;
88  int ret = 0;
89 
90  if (!ost)
91  return AVERROR(ENOMEM);
92 
93  ost->pos = avio_tell(s->pb);
94  ost->curidx = ogg->curidx;
95  ost->next = ogg->state;
96  ost->nstreams = ogg->nstreams;
97  memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));
98 
99  for (i = 0; i < ogg->nstreams; i++) {
100  struct ogg_stream *os = ogg->streams + i;
102  if (os->buf)
103  memcpy(os->buf, ost->streams[i].buf, os->bufpos);
104  else
105  ret = AVERROR(ENOMEM);
106  os->new_metadata = NULL;
107  os->new_metadata_size = 0;
108  }
109 
110  ogg->state = ost;
111 
112  if (ret < 0)
113  ogg_restore(s);
114 
115  return ret;
116 }
117 
119 {
120  struct ogg *ogg = s->priv_data;
121  AVIOContext *bc = s->pb;
122  struct ogg_state *ost = ogg->state;
123  int i, err;
124 
125  if (!ost)
126  return 0;
127 
128  ogg->state = ost->next;
129 
130  for (i = 0; i < ogg->nstreams; i++) {
131  struct ogg_stream *stream = &ogg->streams[i];
132  av_freep(&stream->buf);
133  av_freep(&stream->new_metadata);
134 
135  if (i >= ost->nstreams || !ost->streams[i].private) {
136  free_stream(s, i);
137  }
138  }
139 
140  avio_seek(bc, ost->pos, SEEK_SET);
141  ogg->page_pos = -1;
142  ogg->curidx = ost->curidx;
143  ogg->nstreams = ost->nstreams;
144  if ((err = av_reallocp_array(&ogg->streams, ogg->nstreams,
145  sizeof(*ogg->streams))) < 0) {
146  ogg->nstreams = 0;
147  return err;
148  } else
149  memcpy(ogg->streams, ost->streams,
150  ost->nstreams * sizeof(*ogg->streams));
151 
152  av_free(ost);
153 
154  return 0;
155 }
156 
158 {
159  struct ogg *ogg = s->priv_data;
160  int i;
161  int64_t start_pos = avio_tell(s->pb);
162 
163  for (i = 0; i < ogg->nstreams; i++) {
164  struct ogg_stream *os = ogg->streams + i;
165  os->bufpos = 0;
166  os->pstart = 0;
167  os->psize = 0;
168  os->granule = -1;
169  os->lastpts = AV_NOPTS_VALUE;
170  os->lastdts = AV_NOPTS_VALUE;
171  os->sync_pos = -1;
172  os->page_pos = 0;
173  os->nsegs = 0;
174  os->segp = 0;
175  os->incomplete = 0;
176  os->got_data = 0;
177  if (start_pos <= ffformatcontext(s)->data_offset) {
178  os->lastpts = 0;
179  }
180  os->start_trimming = 0;
181  os->end_trimming = 0;
182  av_freep(&os->new_metadata);
183  os->new_metadata_size = 0;
184  }
185 
186  ogg->page_pos = -1;
187  ogg->curidx = -1;
188 
189  return 0;
190 }
191 
192 static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size)
193 {
194  int i;
195 
196  for (i = 0; ogg_codecs[i]; i++)
197  if (size >= ogg_codecs[i]->magicsize &&
198  !memcmp(buf, ogg_codecs[i]->magic, ogg_codecs[i]->magicsize))
199  return ogg_codecs[i];
200 
201  return NULL;
202 }
203 
204 /**
205  * Replace the current stream with a new one. This is a typical webradio
206  * situation where a new audio stream spawn (identified with a new serial) and
207  * must replace the previous one (track switch).
208  */
209 static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic, int page_size,
210  int probing)
211 {
212  struct ogg *ogg = s->priv_data;
213  struct ogg_stream *os;
214  const struct ogg_codec *codec;
215  int i = 0;
216 
217  if (ogg->nstreams != 1) {
218  avpriv_report_missing_feature(s, "Changing stream parameters in multistream ogg");
219  return AVERROR_PATCHWELCOME;
220  }
221 
222  /* Check for codecs */
223  codec = ogg_find_codec(magic, page_size);
224  if (!codec && !probing) {
225  av_log(s, AV_LOG_ERROR, "Cannot identify new stream\n");
226  return AVERROR_INVALIDDATA;
227  }
228 
229  os = &ogg->streams[0];
230  if (os->codec != codec)
231  return AVERROR(EINVAL);
232 
233  os->serial = serial;
234  os->codec = codec;
235  os->serial = serial;
236  os->lastpts = 0;
237  os->lastdts = 0;
238  os->start_trimming = 0;
239  os->end_trimming = 0;
240 
241  /* Chained files have extradata as a new packet */
242  if (codec == &ff_opus_codec)
243  os->header = -1;
244 
245  return i;
246 }
247 
248 static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
249 {
250  struct ogg *ogg = s->priv_data;
251  int idx = ogg->nstreams;
252  AVStream *st;
253  struct ogg_stream *os;
254 
255  if (ogg->state) {
256  av_log(s, AV_LOG_ERROR, "New streams are not supposed to be added "
257  "in between Ogg context save/restore operations.\n");
258  return AVERROR_BUG;
259  }
260 
261  /* Allocate and init a new Ogg Stream */
262  if (!(os = av_realloc_array(ogg->streams, ogg->nstreams + 1,
263  sizeof(*ogg->streams))))
264  return AVERROR(ENOMEM);
265  ogg->streams = os;
266  os = ogg->streams + idx;
267  memset(os, 0, sizeof(*os));
268  os->serial = serial;
271  os->header = -1;
273  if (!os->buf)
274  return AVERROR(ENOMEM);
275 
276  /* Create the associated AVStream */
277  st = avformat_new_stream(s, NULL);
278  if (!st) {
279  av_freep(&os->buf);
280  return AVERROR(ENOMEM);
281  }
282  st->id = idx;
283  avpriv_set_pts_info(st, 64, 1, 1000000);
284 
285  ogg->nstreams++;
286  return idx;
287 }
288 
289 static int data_packets_seen(const struct ogg *ogg)
290 {
291  int i;
292 
293  for (i = 0; i < ogg->nstreams; i++)
294  if (ogg->streams[i].got_data)
295  return 1;
296  return 0;
297 }
298 
299 static int buf_realloc(struct ogg_stream *os, int size)
300 {
301  /* Even if invalid guarantee there's enough memory to read the page */
302  if (os->bufsize - os->bufpos < size) {
303  uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
304  if (!nb)
305  return AVERROR(ENOMEM);
306  os->buf = nb;
307  os->bufsize *= 2;
308  }
309 
310  return 0;
311 }
312 
313 static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
314 {
315  AVIOContext *bc = s->pb;
316  struct ogg *ogg = s->priv_data;
317  struct ogg_stream *os;
318  int ret, i = 0;
319  int flags, nsegs;
320  uint64_t gp;
321  uint32_t serial;
322  uint32_t crc, crc_tmp;
323  int size = 0, idx;
324  int64_t version, page_pos;
325  int64_t start_pos;
326  uint8_t sync[4];
327  uint8_t segments[255];
328  uint8_t *readout_buf;
329  int sp = 0;
330 
331  ret = avio_read(bc, sync, 4);
332  if (ret < 4)
333  return ret < 0 ? ret : AVERROR_EOF;
334 
335  do {
336  int c;
337 
338  if (sync[sp & 3] == 'O' &&
339  sync[(sp + 1) & 3] == 'g' &&
340  sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S')
341  break;
342 
343  if(!i && (bc->seekable & AVIO_SEEKABLE_NORMAL) && ogg->page_pos > 0) {
344  memset(sync, 0, 4);
345  avio_seek(bc, ogg->page_pos+4, SEEK_SET);
346  ogg->page_pos = -1;
347  }
348 
349  c = avio_r8(bc);
350 
351  if (avio_feof(bc))
352  return AVERROR_EOF;
353 
354  sync[sp++ & 3] = c;
355  } while (i++ < MAX_PAGE_SIZE);
356 
357  if (i >= MAX_PAGE_SIZE) {
358  av_log(s, AV_LOG_INFO, "cannot find sync word\n");
359  return AVERROR_INVALIDDATA;
360  }
361 
362  /* 0x4fa9b05f = av_crc(AV_CRC_32_IEEE, 0x0, "OggS", 4) */
363  ffio_init_checksum(bc, ff_crc04C11DB7_update, 0x4fa9b05f);
364 
365  /* To rewind if checksum is bad/check magic on switches - this is the max packet size */
367  start_pos = avio_tell(bc);
368 
369  version = avio_r8(bc);
370  flags = avio_r8(bc);
371  gp = avio_rl64(bc);
372  serial = avio_rl32(bc);
373  avio_skip(bc, 4); /* seq */
374 
375  crc_tmp = ffio_get_checksum(bc);
376  crc = avio_rb32(bc);
377  crc_tmp = ff_crc04C11DB7_update(crc_tmp, (uint8_t[4]){0}, 4);
379 
380  nsegs = avio_r8(bc);
381  page_pos = avio_tell(bc) - 27;
382 
383  ret = avio_read(bc, segments, nsegs);
384  if (ret < nsegs)
385  return ret < 0 ? ret : AVERROR_EOF;
386 
387  for (i = 0; i < nsegs; i++)
388  size += segments[i];
389 
390  idx = ogg_find_stream(ogg, serial);
391  if (idx >= 0) {
392  os = ogg->streams + idx;
393 
394  ret = buf_realloc(os, size);
395  if (ret < 0)
396  return ret;
397 
398  readout_buf = os->buf + os->bufpos;
399  } else {
400  readout_buf = av_malloc(size);
401  }
402 
403  ret = avio_read(bc, readout_buf, size);
404  if (ret < size) {
405  if (idx < 0)
406  av_free(readout_buf);
407  return ret < 0 ? ret : AVERROR_EOF;
408  }
409 
410  if (crc ^ ffio_get_checksum(bc)) {
411  av_log(s, AV_LOG_ERROR, "CRC mismatch!\n");
412  if (idx < 0)
413  av_free(readout_buf);
414  avio_seek(bc, start_pos, SEEK_SET);
415  *sid = -1;
416  return 0;
417  }
418 
419  /* Since we're almost sure its a valid packet, checking the version after
420  * the checksum lets the demuxer be more tolerant */
421  if (version) {
422  av_log(s, AV_LOG_ERROR, "Invalid Ogg vers!\n");
423  if (idx < 0)
424  av_free(readout_buf);
425  avio_seek(bc, start_pos, SEEK_SET);
426  *sid = -1;
427  return 0;
428  }
429 
430  /* CRC is correct so we can be 99% sure there's an actual change here */
431  if (idx < 0) {
432  if (data_packets_seen(ogg))
433  idx = ogg_replace_stream(s, serial, readout_buf, size, probing);
434  else
435  idx = ogg_new_stream(s, serial);
436 
437  if (idx < 0) {
438  av_log(s, AV_LOG_ERROR, "failed to create or replace stream\n");
439  av_free(readout_buf);
440  return idx;
441  }
442 
443  os = ogg->streams + idx;
444 
445  ret = buf_realloc(os, size);
446  if (ret < 0) {
447  av_free(readout_buf);
448  return ret;
449  }
450 
451  memcpy(os->buf + os->bufpos, readout_buf, size);
452  av_free(readout_buf);
453  }
454 
455  ogg->page_pos = page_pos;
456  os->page_pos = page_pos;
457  os->nsegs = nsegs;
458  os->segp = 0;
459  os->got_data = !(flags & OGG_FLAG_BOS);
460  os->bufpos += size;
461  os->granule = gp;
462  os->flags = flags;
463  memcpy(os->segments, segments, nsegs);
464  memset(os->buf + os->bufpos, 0, AV_INPUT_BUFFER_PADDING_SIZE);
465 
466  if (flags & OGG_FLAG_CONT || os->incomplete) {
467  if (!os->psize) {
468  // If this is the very first segment we started
469  // playback in the middle of a continuation packet.
470  // Discard it since we missed the start of it.
471  while (os->segp < os->nsegs) {
472  int seg = os->segments[os->segp++];
473  os->pstart += seg;
474  if (seg < 255)
475  break;
476  }
477  os->sync_pos = os->page_pos;
478  }
479  } else {
480  os->psize = 0;
481  os->sync_pos = os->page_pos;
482  }
483 
484  /* This function is always called with sid != NULL */
485  *sid = idx;
486 
487  return 0;
488 }
489 
490 /**
491  * @brief find the next Ogg packet
492  * @param *sid is set to the stream for the packet or -1 if there is
493  * no matching stream, in that case assume all other return
494  * values to be uninitialized.
495  * @return negative value on error or EOF.
496  */
497 static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize,
498  int64_t *fpos)
499 {
500  FFFormatContext *const si = ffformatcontext(s);
501  struct ogg *ogg = s->priv_data;
502  int idx, i, ret;
503  struct ogg_stream *os;
504  int complete = 0;
505  int segp = 0, psize = 0;
506 
507  av_log(s, AV_LOG_TRACE, "ogg_packet: curidx=%i\n", ogg->curidx);
508  if (sid)
509  *sid = -1;
510 
511  do {
512  idx = ogg->curidx;
513 
514  while (idx < 0) {
515  ret = ogg_read_page(s, &idx, 0);
516  if (ret < 0)
517  return ret;
518  }
519 
520  os = ogg->streams + idx;
521 
522  av_log(s, AV_LOG_TRACE, "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n",
523  idx, os->pstart, os->psize, os->segp, os->nsegs);
524 
525  if (!os->codec) {
526  if (os->header < 0) {
527  os->codec = ogg_find_codec(os->buf, os->bufpos);
528  if (!os->codec) {
529  av_log(s, AV_LOG_WARNING, "Codec not found\n");
530  os->header = 0;
531  return 0;
532  }
533  } else {
534  return 0;
535  }
536  }
537 
538  segp = os->segp;
539  psize = os->psize;
540 
541  while (os->segp < os->nsegs) {
542  int ss = os->segments[os->segp++];
543  os->psize += ss;
544  if (ss < 255) {
545  complete = 1;
546  break;
547  }
548  }
549 
550  if (!complete && os->segp == os->nsegs) {
551  ogg->curidx = -1;
552  // Do not set incomplete for empty packets.
553  // Together with the code in ogg_read_page
554  // that discards all continuation of empty packets
555  // we would get an infinite loop.
556  os->incomplete = !!os->psize;
557  }
558  } while (!complete);
559 
560 
561  if (os->granule == -1)
563  "Page at %"PRId64" is missing granule\n",
564  os->page_pos);
565 
566  ogg->curidx = idx;
567  os->incomplete = 0;
568 
569  if (os->header) {
570  if ((ret = os->codec->header(s, idx)) < 0) {
571  av_log(s, AV_LOG_ERROR, "Header processing failed: %s\n", av_err2str(ret));
572  return ret;
573  }
574  os->header = ret;
575  if (!os->header) {
576  os->segp = segp;
577  os->psize = psize;
578 
579  // We have reached the first non-header packet in this stream.
580  // Unfortunately more header packets may still follow for others,
581  // but if we continue with header parsing we may lose data packets.
582  ogg->headers = 1;
583 
584  // Update the header state for all streams and
585  // compute the data_offset.
586  if (!si->data_offset)
587  si->data_offset = os->sync_pos;
588 
589  for (i = 0; i < ogg->nstreams; i++) {
590  struct ogg_stream *cur_os = ogg->streams + i;
591 
592  // if we have a partial non-header packet, its start is
593  // obviously at or after the data start
594  if (cur_os->incomplete)
595  si->data_offset = FFMIN(si->data_offset, cur_os->sync_pos);
596  }
597  } else {
598  os->nb_header++;
599  os->pstart += os->psize;
600  os->psize = 0;
601  }
602  } else {
603  os->pflags = 0;
604  os->pduration = 0;
605  if (os->codec && os->codec->packet) {
606  if ((ret = os->codec->packet(s, idx)) < 0) {
607  av_log(s, AV_LOG_ERROR, "Packet processing failed: %s\n", av_err2str(ret));
608  return ret;
609  }
610  }
611  if (sid)
612  *sid = idx;
613  if (dstart)
614  *dstart = os->pstart;
615  if (dsize)
616  *dsize = os->psize;
617  if (fpos)
618  *fpos = os->sync_pos;
619  os->pstart += os->psize;
620  os->psize = 0;
621  if(os->pstart == os->bufpos)
622  os->bufpos = os->pstart = 0;
623  os->sync_pos = os->page_pos;
624  }
625 
626  // determine whether there are more complete packets in this page
627  // if not, the page's granule will apply to this packet
628  os->page_end = 1;
629  for (i = os->segp; i < os->nsegs; i++)
630  if (os->segments[i] < 255) {
631  os->page_end = 0;
632  break;
633  }
634 
635  if (os->segp == os->nsegs)
636  ogg->curidx = -1;
637 
638  return 0;
639 }
640 
642 {
643  struct ogg *ogg = s->priv_data;
644  int i, ret;
645  int64_t size, end;
646  int streams_left=0;
647 
648  if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL))
649  return 0;
650 
651 // already set
652  if (s->duration != AV_NOPTS_VALUE)
653  return 0;
654 
655  size = avio_size(s->pb);
656  if (size < 0)
657  return 0;
658  end = size > MAX_PAGE_SIZE ? size - MAX_PAGE_SIZE : 0;
659 
660  ret = ogg_save(s);
661  if (ret < 0)
662  return ret;
663  avio_seek(s->pb, end, SEEK_SET);
664  ogg->page_pos = -1;
665 
666  while (!ogg_read_page(s, &i, 1)) {
667  if (i >= 0 && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
668  ogg->streams[i].codec) {
669  s->streams[i]->duration =
671  if (s->streams[i]->start_time != AV_NOPTS_VALUE) {
672  s->streams[i]->duration -= s->streams[i]->start_time;
673  streams_left-= (ogg->streams[i].got_start==-1);
674  ogg->streams[i].got_start= 1;
675  } else if(!ogg->streams[i].got_start) {
676  ogg->streams[i].got_start= -1;
677  streams_left++;
678  }
679  }
680  }
681 
682  ogg_restore(s);
683 
684  ret = ogg_save(s);
685  if (ret < 0)
686  return ret;
687 
688  avio_seek (s->pb, ffformatcontext(s)->data_offset, SEEK_SET);
689  ogg_reset(s);
690  while (streams_left > 0 && !ogg_packet(s, &i, NULL, NULL, NULL)) {
691  int64_t pts;
692  if (i < 0) continue;
693  pts = ogg_calc_pts(s, i, NULL);
694  if (s->streams[i]->duration == AV_NOPTS_VALUE)
695  continue;
696  if (pts != AV_NOPTS_VALUE && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start) {
697  s->streams[i]->duration -= pts;
698  ogg->streams[i].got_start= 1;
699  streams_left--;
700  }else if(s->streams[i]->start_time != AV_NOPTS_VALUE && !ogg->streams[i].got_start) {
701  ogg->streams[i].got_start= 1;
702  streams_left--;
703  }
704  }
705  ogg_restore (s);
706 
707  return 0;
708 }
709 
711 {
712  struct ogg *ogg = s->priv_data;
713  int i;
714 
715  for (i = 0; i < ogg->nstreams; i++) {
716  free_stream(s, i);
717  }
718 
719  ogg->nstreams = 0;
720 
721  av_freep(&ogg->streams);
722  return 0;
723 }
724 
726 {
727  struct ogg *ogg = s->priv_data;
728  int ret, i;
729 
730  ogg->curidx = -1;
731 
732  //linear headers seek from start
733  do {
734  ret = ogg_packet(s, NULL, NULL, NULL, NULL);
735  if (ret < 0)
736  return ret;
737  } while (!ogg->headers);
738  av_log(s, AV_LOG_TRACE, "found headers\n");
739 
740  for (i = 0; i < ogg->nstreams; i++) {
741  struct ogg_stream *os = ogg->streams + i;
742 
743  if (ogg->streams[i].header < 0) {
744  av_log(s, AV_LOG_ERROR, "Header parsing failed for stream %d\n", i);
745  ogg->streams[i].codec = NULL;
747  } else if (os->codec && os->nb_header < os->codec->nb_header) {
749  "Headers mismatch for stream %d: "
750  "expected %d received %d.\n",
751  i, os->codec->nb_header, os->nb_header);
752  if (s->error_recognition & AV_EF_EXPLODE)
753  return AVERROR_INVALIDDATA;
754  }
756  os->lastpts = s->streams[i]->start_time =
757  ogg_gptopts(s, i, os->start_granule, NULL);
758  }
759 
760  //linear granulepos seek from end
761  ret = ogg_get_length(s);
762  if (ret < 0)
763  return ret;
764 
765  return 0;
766 }
767 
768 static int64_t ogg_calc_pts(AVFormatContext *s, int idx, int64_t *dts)
769 {
770  struct ogg *ogg = s->priv_data;
771  struct ogg_stream *os = ogg->streams + idx;
772  int64_t pts = AV_NOPTS_VALUE;
773 
774  if (dts)
775  *dts = AV_NOPTS_VALUE;
776 
777  if (os->lastpts != AV_NOPTS_VALUE) {
778  pts = os->lastpts;
779  os->lastpts = AV_NOPTS_VALUE;
780  }
781  if (os->lastdts != AV_NOPTS_VALUE) {
782  if (dts)
783  *dts = os->lastdts;
784  os->lastdts = AV_NOPTS_VALUE;
785  }
786  if (os->page_end) {
787  if (os->granule != -1LL) {
788  if (os->codec && os->codec->granule_is_start)
789  pts = ogg_gptopts(s, idx, os->granule, dts);
790  else
791  os->lastpts = ogg_gptopts(s, idx, os->granule, &os->lastdts);
792  os->granule = -1LL;
793  }
794  }
795  return pts;
796 }
797 
798 static void ogg_validate_keyframe(AVFormatContext *s, int idx, int pstart, int psize)
799 {
800  struct ogg *ogg = s->priv_data;
801  struct ogg_stream *os = ogg->streams + idx;
802  int invalid = 0;
803  if (psize) {
804  switch (s->streams[idx]->codecpar->codec_id) {
805  case AV_CODEC_ID_THEORA:
806  invalid = !!(os->pflags & AV_PKT_FLAG_KEY) != !(os->buf[pstart] & 0x40);
807  break;
808  case AV_CODEC_ID_VP8:
809  invalid = !!(os->pflags & AV_PKT_FLAG_KEY) != !(os->buf[pstart] & 1);
810  }
811  if (invalid) {
812  os->pflags ^= AV_PKT_FLAG_KEY;
813  av_log(s, AV_LOG_WARNING, "Broken file, %skeyframe not correctly marked.\n",
814  (os->pflags & AV_PKT_FLAG_KEY) ? "" : "non-");
815  }
816  }
817 }
818 
820 {
821  struct ogg *ogg;
822  struct ogg_stream *os;
823  int idx, ret;
824  int pstart, psize;
825  int64_t fpos, pts, dts;
826 
827  if (s->io_repositioned) {
828  ogg_reset(s);
829  s->io_repositioned = 0;
830  }
831 
832  //Get an ogg packet
833 retry:
834  do {
835  ret = ogg_packet(s, &idx, &pstart, &psize, &fpos);
836  if (ret < 0)
837  return ret;
838  } while (idx < 0 || !s->streams[idx]);
839 
840  ogg = s->priv_data;
841  os = ogg->streams + idx;
842 
843  // pflags might not be set until after this
844  pts = ogg_calc_pts(s, idx, &dts);
846 
847  if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
848  goto retry;
849  os->keyframe_seek = 0;
850 
851  //Alloc a pkt
853  if (ret < 0)
854  return ret;
855  pkt->stream_index = idx;
856  memcpy(pkt->data, os->buf + pstart, psize);
857 
858  pkt->pts = pts;
859  pkt->dts = dts;
860  pkt->flags = os->pflags;
861  pkt->duration = os->pduration;
862  pkt->pos = fpos;
863 
864  if (os->start_trimming || os->end_trimming) {
865  uint8_t *side_data = av_packet_new_side_data(pkt,
867  10);
868  if(!side_data)
869  return AVERROR(ENOMEM);
870  AV_WL32(side_data + 0, os->start_trimming);
871  AV_WL32(side_data + 4, os->end_trimming);
872  os->start_trimming = 0;
873  os->end_trimming = 0;
874  }
875 
876  if (os->new_metadata) {
879  if (ret < 0)
880  return ret;
881 
882  os->new_metadata = NULL;
883  os->new_metadata_size = 0;
884  }
885 
886  return psize;
887 }
888 
889 static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index,
890  int64_t *pos_arg, int64_t pos_limit)
891 {
892  struct ogg *ogg = s->priv_data;
893  AVIOContext *bc = s->pb;
894  int64_t pts = AV_NOPTS_VALUE;
895  int64_t keypos = -1;
896  int i;
897  int pstart, psize;
898  avio_seek(bc, *pos_arg, SEEK_SET);
899  ogg_reset(s);
900 
901  while ( avio_tell(bc) <= pos_limit
902  && !ogg_packet(s, &i, &pstart, &psize, pos_arg)) {
903  if (i == stream_index) {
904  struct ogg_stream *os = ogg->streams + stream_index;
905  // Do not trust the last timestamps of an ogm video
906  if ( (os->flags & OGG_FLAG_EOS)
907  && !(os->flags & OGG_FLAG_BOS)
908  && os->codec == &ff_ogm_video_codec)
909  continue;
910  pts = ogg_calc_pts(s, i, NULL);
912  if (os->pflags & AV_PKT_FLAG_KEY) {
913  keypos = *pos_arg;
914  } else if (os->keyframe_seek) {
915  // if we had a previous keyframe but no pts for it,
916  // return that keyframe with this pts value.
917  if (keypos >= 0)
918  *pos_arg = keypos;
919  else
921  }
922  }
923  if (pts != AV_NOPTS_VALUE)
924  break;
925  }
926  ogg_reset(s);
927  return pts;
928 }
929 
930 static int ogg_read_seek(AVFormatContext *s, int stream_index,
931  int64_t timestamp, int flags)
932 {
933  struct ogg *ogg = s->priv_data;
934  struct ogg_stream *os = ogg->streams + stream_index;
935  int ret;
936 
937  av_assert0(stream_index < ogg->nstreams);
938  // Ensure everything is reset even when seeking via
939  // the generated index.
940  ogg_reset(s);
941 
942  // Try seeking to a keyframe first. If this fails (very possible),
943  // av_seek_frame will fall back to ignoring keyframes
944  if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO
945  && !(flags & AVSEEK_FLAG_ANY))
946  os->keyframe_seek = 1;
947 
948  ret = ff_seek_frame_binary(s, stream_index, timestamp, flags);
949  ogg_reset(s);
950  os = ogg->streams + stream_index;
951  if (ret < 0)
952  os->keyframe_seek = 0;
953  return ret;
954 }
955 
956 static int ogg_probe(const AVProbeData *p)
957 {
958  if (!memcmp("OggS", p->buf, 5) && p->buf[5] <= 0x7)
959  return AVPROBE_SCORE_MAX;
960  return 0;
961 }
962 
964  .name = "ogg",
965  .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
966  .priv_data_size = sizeof(struct ogg),
967  .flags_internal = FF_FMT_INIT_CLEANUP,
968  .read_probe = ogg_probe,
969  .read_header = ogg_read_header,
970  .read_packet = ogg_read_packet,
971  .read_close = ogg_read_close,
972  .read_seek = ogg_read_seek,
973  .read_timestamp = ogg_read_timestamp,
974  .extensions = "ogg",
976 };
ff_old_flac_codec
const struct ogg_codec ff_old_flac_codec
Definition: oggparseflac.c:135
ff_ogm_text_codec
const struct ogg_codec ff_ogm_text_codec
Definition: oggparseogm.c:213
ost
OutputStream * ost
Definition: ffmpeg_filter.c:160
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ogg_stream::segp
int segp
Definition: oggdec.h:79
FF_FMT_INIT_CLEANUP
#define FF_FMT_INIT_CLEANUP
For an AVInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition: internal.h:49
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:768
ogg_stream::lastpts
int64_t lastpts
Definition: oggdec.h:72
ff_ogm_audio_codec
const struct ogg_codec ff_ogm_audio_codec
Definition: oggparseogm.c:204
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
ogg_codec::magicsize
uint8_t magicsize
Definition: oggdec.h:33
ogg_validate_keyframe
static void ogg_validate_keyframe(AVFormatContext *s, int idx, int pstart, int psize)
Definition: oggdec.c:798
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:189
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
ogg_stream::bufpos
unsigned int bufpos
Definition: oggdec.h:64
ff_vp8_codec
const struct ogg_codec ff_vp8_codec
Definition: oggparsevp8.c:139
ogg_stream::got_start
int got_start
Definition: oggdec.h:84
ff_old_dirac_codec
const struct ogg_codec ff_old_dirac_codec
Definition: oggparsedirac.c:125
AVPacket::data
uint8_t * data
Definition: packet.h:373
vorbiscomment.h
ogg_stream::granule
uint64_t granule
Definition: oggdec.h:70
ogg_stream::start_trimming
int start_trimming
set the number of packets to drop from the start
Definition: oggdec.h:87
ogg_read_header
static int ogg_read_header(AVFormatContext *s)
Definition: oggdec.c:725
ogg_new_stream
static int ogg_new_stream(AVFormatContext *s, uint32_t serial)
Definition: oggdec.c:248
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:391
ogg_stream::nb_header
int nb_header
set to the number of parsed headers
Definition: oggdec.h:86
ogg_stream::buf
uint8_t * buf
Definition: oggdec.h:62
ogg_stream::nsegs
int nsegs
Definition: oggdec.h:79
ogg_reset
static int ogg_reset(AVFormatContext *s)
Definition: oggdec.c:157
AVFMT_NOBINSEARCH
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition: avformat.h:481
ogg
Definition: oggdec.h:102
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:352
ff_vorbis_codec
const struct ogg_codec ff_vorbis_codec
Definition: oggparsevorbis.c:504
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:428
ffio_get_checksum
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:612
ff_flac_codec
const struct ogg_codec ff_flac_codec
Definition: oggparseflac.c:128
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
ff_seek_frame_binary
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
Perform a binary search using av_index_search_timestamp() and AVInputFormat.read_timestamp().
Definition: seek.c:282
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:459
ogg_codec::packet
int(* packet)(AVFormatContext *, int)
Definition: oggdec.h:42
DECODER_BUFFER_SIZE
#define DECODER_BUFFER_SIZE
Definition: oggdec.c:41
ogg_gptopts
static uint64_t ogg_gptopts(AVFormatContext *s, int i, uint64_t gp, int64_t *dts)
Definition: oggdec.h:168
ogg_stream::serial
uint32_t serial
Definition: oggdec.h:69
av_packet_add_side_data
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition: avpacket.c:198
AVSEEK_FLAG_ANY
#define AVSEEK_FLAG_ANY
seek to any frame, even non-keyframes
Definition: avformat.h:2277
ogg_stream::lastdts
int64_t lastdts
Definition: oggdec.h:73
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:504
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:476
ogg::headers
int headers
Definition: oggdec.h:105
pts
static int64_t pts
Definition: transcode_aac.c:653
ss
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:261
ogg_packet
static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, int64_t *fpos)
find the next Ogg packet
Definition: oggdec.c:497
free_stream
static void free_stream(AVFormatContext *s, int i)
Definition: oggdec.c:66
avassert.h
ogg_stream::pstart
unsigned int pstart
Definition: oggdec.h:65
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:790
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVInputFormat
Definition: avformat.h:650
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:99
OGG_NOGRANULE_VALUE
#define OGG_NOGRANULE_VALUE
Definition: oggdec.h:115
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:224
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:655
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:449
ogg_stream::got_data
int got_data
1 if the stream got some data (non-initial packets), 0 otherwise
Definition: oggdec.h:85
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
ogg_stream::page_end
int page_end
current packet is the last one completed in the page
Definition: oggdec.h:82
FFFormatContext::data_offset
int64_t data_offset
offset of the first packet
Definition: internal.h:99
ogg::curidx
int curidx
Definition: oggdec.h:106
ogg_stream::new_metadata
uint8_t * new_metadata
Definition: oggdec.h:89
FFFormatContext
Definition: internal.h:73
ogg_stream::page_pos
int64_t page_pos
file offset of the current page
Definition: oggdec.h:75
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
ogg_codec::header
int(* header)(AVFormatContext *, int)
Attempt to process a packet as a header.
Definition: oggdec.h:41
internal.h
NULL
#define NULL
Definition: coverity.c:32
ogg_replace_stream
static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic, int page_size, int probing)
Replace the current stream with a new one.
Definition: oggdec.c:209
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:152
ff_ogm_old_codec
const struct ogg_codec ff_ogm_old_codec
Definition: oggparseogm.c:222
OutputStream::pos
int64_t pos
Definition: dashenc.c:108
ogg_stream::flags
int flags
Definition: oggdec.h:76
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:447
ogg_read_seek
static int ogg_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: oggdec.c:930
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1335
ogg::page_pos
int64_t page_pos
file offset of the current page
Definition: oggdec.h:107
ogg::streams
struct ogg_stream * streams
Definition: oggdec.h:103
ogg_save
static int ogg_save(AVFormatContext *s)
Definition: oggdec.c:82
ogg_get_length
static int ogg_get_length(AVFormatContext *s)
Definition: oggdec.c:641
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:759
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
buf_realloc
static int buf_realloc(struct ogg_stream *os, int size)
Definition: oggdec.c:299
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:262
ogg_read_close
static int ogg_read_close(AVFormatContext *s)
Definition: oggdec.c:710
gp
#define gp
Definition: regdef.h:62
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
sp
#define sp
Definition: regdef.h:63
ogg_stream::private
void * private
Definition: oggdec.h:91
ogg_stream::keyframe_seek
int keyframe_seek
Definition: oggdec.h:83
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
data_packets_seen
static int data_packets_seen(const struct ogg *ogg)
Definition: oggdec.c:289
ffio_init_checksum
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:620
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:372
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:232
ffio_ensure_seekback
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:1055
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:379
ogg::state
struct ogg_state * state
Definition: oggdec.h:108
version
version
Definition: libkvazaar.c:313
AV_PKT_DATA_METADATA_UPDATE
@ AV_PKT_DATA_METADATA_UPDATE
A list of zero terminated key/value strings.
Definition: packet.h:209
ff_crc04C11DB7_update
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:594
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
MAX_PAGE_SIZE
#define MAX_PAGE_SIZE
Definition: oggdec.c:40
ogg_stream::pflags
unsigned int pflags
Definition: oggdec.h:67
ogg::nstreams
int nstreams
Definition: oggdec.h:104
ogg_stream::sync_pos
int64_t sync_pos
file offset of the first page needed to reconstruct the current packet
Definition: oggdec.h:74
ogg_stream::incomplete
int incomplete
whether we're expecting a continuation in the next page
Definition: oggdec.h:81
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
ogg_stream
Definition: oggdec.h:61
avio_internal.h
AV_CODEC_ID_THEORA
@ AV_CODEC_ID_THEORA
Definition: codec_id.h:80
ff_ogm_video_codec
const struct ogg_codec ff_ogm_video_codec
Definition: oggparseogm.c:195
OGG_FLAG_CONT
#define OGG_FLAG_CONT
Definition: oggdec.h:111
ff_skeleton_codec
const struct ogg_codec ff_skeleton_codec
Definition: oggparseskeleton.c:96
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:156
ogg_codecs
static const struct ogg_codec *const ogg_codecs[]
Definition: oggdec.c:43
ff_ogg_demuxer
const AVInputFormat ff_ogg_demuxer
Definition: oggdec.c:963
ogg_stream::header
int header
Definition: oggdec.h:78
ogg_read_timestamp
static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit)
Definition: oggdec.c:889
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:949
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:935
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
avformat.h
ogg_find_codec
static const struct ogg_codec * ogg_find_codec(uint8_t *buf, int size)
Definition: oggdec.c:192
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
ogg_find_stream
static int ogg_find_stream(struct ogg *ogg, int serial)
Definition: oggdec.h:156
ogg_codec::cleanup
void(* cleanup)(AVFormatContext *s, int idx)
Definition: oggdec.h:58
oggdec.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: avpacket.c:232
ogg_restore
static int ogg_restore(AVFormatContext *s)
Definition: oggdec.c:118
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:641
ogg_stream::start_granule
uint64_t start_granule
Definition: oggdec.h:71
ogg_read_packet
static int ogg_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: oggdec.c:819
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:1196
AVPacket::stream_index
int stream_index
Definition: packet.h:375
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
ogg_stream::new_metadata_size
size_t new_metadata_size
Definition: oggdec.h:90
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ogg_codec::nb_header
int nb_header
Number of expected headers.
Definition: oggdec.h:57
ogg_stream::segments
uint8_t segments[255]
Definition: oggdec.h:80
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:477
OGG_FLAG_EOS
#define OGG_FLAG_EOS
Definition: oggdec.h:113
ogg_state
Definition: oggdec.h:94
ogg_calc_pts
static int64_t ogg_calc_pts(AVFormatContext *s, int idx, int64_t *dts)
Definition: oggdec.c:768
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ff_celt_codec
const struct ogg_codec ff_celt_codec
Definition: oggparsecelt.c:92
ogg_probe
static int ogg_probe(const AVProbeData *p)
Definition: oggdec.c:956
AVPacket
This structure stores compressed data.
Definition: packet.h:350
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
ogg_stream::psize
unsigned int psize
Definition: oggdec.h:66
OGG_FLAG_BOS
#define OGG_FLAG_BOS
Definition: oggdec.h:112
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:393
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:767
ogg_codec
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition: oggdec.h:31
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:190
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ogg_read_page
static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
Definition: oggdec.c:313
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ogg_codec::magic
const int8_t * magic
Definition: oggdec.h:32
ogg_stream::end_trimming
int end_trimming
set the number of packets to drop from the end
Definition: oggdec.h:88
ff_dirac_codec
const struct ogg_codec ff_dirac_codec
Definition: oggparsedirac.c:116
ff_speex_codec
const struct ogg_codec ff_speex_codec
Definition: oggparsespeex.c:148
ogg_codec::granule_is_start
int granule_is_start
1 if granule is the start time of the associated packet.
Definition: oggdec.h:53
ogg_stream::pduration
unsigned int pduration
Definition: oggdec.h:68
ff_theora_codec
const struct ogg_codec ff_theora_codec
Definition: oggparsetheora.c:211
ogg_stream::codec
const struct ogg_codec * codec
Definition: oggdec.h:77
ff_opus_codec
const struct ogg_codec ff_opus_codec
Definition: oggparseopus.c:181
ogg_stream::bufsize
unsigned int bufsize
Definition: oggdec.h:63
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:375