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