oggparseskeleton.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 David Conrad
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavcodec/bytestream.h"
22 #include "avformat.h"
23 #include "internal.h"
24 #include "oggdec.h"
25 
26 static int skeleton_header(AVFormatContext *s, int idx)
27 {
28  struct ogg *ogg = s->priv_data;
29  struct ogg_stream *os = ogg->streams + idx;
30  AVStream *st = s->streams[idx];
31  uint8_t *buf = os->buf + os->pstart;
32  int version_major, version_minor;
33  int64_t start_num, start_den;
34  uint64_t start_granule;
35  int target_idx, start_time;
36 
37  strcpy(st->codec->codec_name, "skeleton");
39 
40  if (os->psize < 8)
41  return -1;
42 
43  if (!strncmp(buf, "fishead", 8)) {
44  if (os->psize < 64)
45  return -1;
46 
47  version_major = AV_RL16(buf+8);
48  version_minor = AV_RL16(buf+10);
49 
50  if (version_major != 3 && version_major != 4) {
51  av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
52  version_major, version_minor);
53  return -1;
54  }
55 
56  // This is the overall start time. We use it for the start time of
57  // of the skeleton stream since if left unset lavf assumes 0,
58  // which we don't want since skeleton is timeless
59  // FIXME: the real meaning of this field is "start playback at
60  // this time which can be in the middle of a packet
61  start_num = AV_RL64(buf+12);
62  start_den = AV_RL64(buf+20);
63 
64  if (start_den > 0 && start_num > 0) {
65  int base_den;
66  av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
67  avpriv_set_pts_info(st, 64, 1, base_den);
68  os->lastpts =
69  st->start_time = start_time;
70  }
71  } else if (!strncmp(buf, "fisbone", 8)) {
72  if (os->psize < 52)
73  return -1;
74 
75  target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
76  start_granule = AV_RL64(buf+36);
79  "Multiple fisbone for the same stream");
80  return 1;
81  }
82  if (target_idx >= 0 && start_granule != OGG_NOGRANULE_VALUE) {
84  }
85  }
86 
87  return 1;
88 }
89 
90 const struct ogg_codec ff_skeleton_codec = {
91  .magic = "fishead",
92  .magicsize = 8,
93  .header = skeleton_header,
94  .nb_header = 0,
95 };
const char * s
Definition: avisynth_c.h:668
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition: oggdec.h:31
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
#define OGG_NOGRANULE_VALUE
Definition: oggdec.h:111
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
static int skeleton_header(AVFormatContext *s, int idx)
#define AV_RL16
int64_t lastpts
Definition: oggdec.h:72
Format I/O context.
Definition: avformat.h:944
#define AV_RL64
unsigned int psize
Definition: oggdec.h:66
static int64_t start_time
Definition: ffplay.c:293
uint8_t
Opaque data information usually continuous.
Definition: avutil.h:145
const struct ogg_codec ff_skeleton_codec
AVStream ** streams
Definition: avformat.h:992
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
unsigned int pstart
Definition: oggdec.h:65
uint64_t start_granule
Definition: oggdec.h:71
struct ogg_stream * streams
Definition: oggdec.h:99
#define AV_RL32
Stream structure.
Definition: avformat.h:643
static int ogg_find_stream(struct ogg *ogg, int serial)
Definition: oggdec.h:131
enum AVMediaType codec_type
void * buf
Definition: avisynth_c.h:594
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const int8_t * magic
Definition: oggdec.h:32
uint8_t * buf
Definition: oggdec.h:62
Main libavformat public API header.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:689
Definition: oggdec.h:98
void * priv_data
Format private data.
Definition: avformat.h:964