FFmpeg
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 "libavutil/intreadwrite.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 
38 
39  if ((os->flags & OGG_FLAG_EOS) && os->psize == 0)
40  return 1;
41 
42  if (os->psize < 8)
43  return -1;
44 
45  if (!strncmp(buf, "fishead", 8)) {
46  if (os->psize < 64)
47  return -1;
48 
49  version_major = AV_RL16(buf+8);
50  version_minor = AV_RL16(buf+10);
51 
52  if (version_major != 3 && version_major != 4) {
53  av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
54  version_major, version_minor);
55  return -1;
56  }
57 
58  // This is the overall start time. We use it for the start time of
59  // of the skeleton stream since if left unset lavf assumes 0,
60  // which we don't want since skeleton is timeless
61  // FIXME: the real meaning of this field is "start playback at
62  // this time which can be in the middle of a packet
63  start_num = AV_RL64(buf+12);
64  start_den = AV_RL64(buf+20);
65 
66  if (start_den > 0 && start_num > 0) {
67  int base_den;
68  av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
69  avpriv_set_pts_info(st, 64, 1, base_den);
70  os->lastpts =
71  st->start_time = start_time;
72  }
73  } else if (!strncmp(buf, "fisbone", 8)) {
74  if (os->psize < 52)
75  return -1;
76 
77  target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
79  if (target_idx < 0) {
80  av_log(s, AV_LOG_WARNING, "Serial number in fisbone doesn't match any stream\n");
81  return 1;
82  }
83  os = ogg->streams + target_idx;
85  av_log(s, AV_LOG_WARNING, "Multiple fisbone for the same stream\n");
86  return 1;
87  }
90  }
91  }
92 
93  return 1;
94 }
95 
96 const struct ogg_codec ff_skeleton_codec = {
97  .magic = "fishead",
98  .magicsize = 8,
99  .header = skeleton_header,
100  .nb_header = 0,
101 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ogg_stream::lastpts
int64_t lastpts
Definition: oggdec.h:71
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AV_RL64
uint64_t_TMPL AV_RL64
Definition: bytestream.h:91
int64_t
long long int64_t
Definition: coverity.c:34
ogg_stream::buf
uint8_t * buf
Definition: oggdec.h:61
ff_skeleton_codec
const struct ogg_codec ff_skeleton_codec
Definition: oggparseskeleton.c:96
ogg
Definition: oggdec.h:101
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
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
ogg_stream::pstart
unsigned int pstart
Definition: oggdec.h:64
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
OGG_NOGRANULE_VALUE
#define OGG_NOGRANULE_VALUE
Definition: oggdec.h:114
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
ogg_stream::flags
int flags
Definition: oggdec.h:75
ogg::streams
struct ogg_stream * streams
Definition: oggdec.h:102
start_time
static int64_t start_time
Definition: ffplay.c:329
ogg_stream
Definition: oggdec.h:60
AVStream
Stream structure.
Definition: avformat.h:743
avformat.h
ogg_find_stream
static int ogg_find_stream(struct ogg *ogg, int serial)
Definition: oggdec.h:155
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
oggdec.h
ogg_stream::start_granule
uint64_t start_granule
Definition: oggdec.h:70
OGG_FLAG_EOS
#define OGG_FLAG_EOS
Definition: oggdec.h:112
ogg_stream::psize
unsigned int psize
Definition: oggdec.h:65
ogg_codec
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition: oggdec.h:30
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ogg_codec::magic
const int8_t * magic
Definition: oggdec.h:31
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:792
skeleton_header
static int skeleton_header(AVFormatContext *s, int idx)
Definition: oggparseskeleton.c:26