oggparseogm.c
Go to the documentation of this file.
1 
25 #include <stdlib.h>
26 #include "libavutil/intreadwrite.h"
27 #include "libavcodec/get_bits.h"
28 #include "libavcodec/bytestream.h"
29 #include "avformat.h"
30 #include "internal.h"
31 #include "oggdec.h"
32 #include "riff.h"
33 
34 static int
36 {
37  struct ogg *ogg = s->priv_data;
38  struct ogg_stream *os = ogg->streams + idx;
39  AVStream *st = s->streams[idx];
41  uint64_t time_unit;
42  uint64_t spu;
43 
44  bytestream2_init(&p, os->buf + os->pstart, os->psize);
45  if (!(bytestream2_peek_byte(&p) & 1))
46  return 0;
47 
48  if (bytestream2_peek_byte(&p) == 1) {
49  bytestream2_skip(&p, 1);
50 
51  if (bytestream2_peek_byte(&p) == 'v'){
52  int tag;
54  bytestream2_skip(&p, 8);
55  tag = bytestream2_get_le32(&p);
57  st->codec->codec_tag = tag;
58  } else if (bytestream2_peek_byte(&p) == 't') {
61  bytestream2_skip(&p, 12);
62  } else {
63  uint8_t acid[5] = { 0 };
64  int cid;
66  bytestream2_skip(&p, 8);
67  bytestream2_get_buffer(&p, acid, 4);
68  acid[4] = 0;
69  cid = strtol(acid, NULL, 16);
72  }
73 
74  bytestream2_skip(&p, 4); /* useless size field */
75 
76  time_unit = bytestream2_get_le64(&p);
77  spu = bytestream2_get_le64(&p);
78  if (!time_unit || !spu) {
79  av_log(s, AV_LOG_ERROR, "Invalid timing values.\n");
80  return AVERROR_INVALIDDATA;
81  }
82 
83  bytestream2_skip(&p, 4); /* default_len */
84  bytestream2_skip(&p, 8); /* buffersize + bits_per_sample */
85 
87  st->codec->width = bytestream2_get_le32(&p);
88  st->codec->height = bytestream2_get_le32(&p);
89  st->codec->time_base.den = spu * 10000000;
90  st->codec->time_base.num = time_unit;
92  } else {
93  st->codec->channels = bytestream2_get_le16(&p);
94  bytestream2_skip(&p, 2); /* block_align */
95  st->codec->bit_rate = bytestream2_get_le32(&p) * 8;
96  st->codec->sample_rate = spu * 10000000 / time_unit;
97  avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
98  }
99  } else if (bytestream2_peek_byte(&p) == 3) {
100  bytestream2_skip(&p, 7);
101  if (bytestream2_get_bytes_left(&p) > 1)
103  }
104 
105  return 1;
106 }
107 
108 static int
110 {
111  struct ogg *ogg = s->priv_data;
112  struct ogg_stream *os = ogg->streams + idx;
113  AVStream *st = s->streams[idx];
114  uint8_t *p = os->buf + os->pstart;
115  uint32_t t;
116 
117  if(!(*p & 1))
118  return 0;
119  if(*p != 1)
120  return 1;
121 
122  t = AV_RL32(p + 96);
123 
124  if(t == 0x05589f80){
127  st->codec->time_base.den = 10000000;
128  st->codec->time_base.num = AV_RL64(p + 164);
129  st->codec->width = AV_RL32(p + 176);
130  st->codec->height = AV_RL32(p + 180);
131  } else if(t == 0x05589f81){
134  st->codec->channels = AV_RL16(p + 126);
135  st->codec->sample_rate = AV_RL32(p + 128);
136  st->codec->bit_rate = AV_RL32(p + 132) * 8;
137  }
138 
139  return 1;
140 }
141 
142 static int
144 {
145  struct ogg *ogg = s->priv_data;
146  struct ogg_stream *os = ogg->streams + idx;
147  uint8_t *p = os->buf + os->pstart;
148  int lb;
149 
150  if(*p & 8)
151  os->pflags |= AV_PKT_FLAG_KEY;
152 
153  lb = ((*p & 2) << 1) | ((*p >> 6) & 3);
154  os->pstart += lb + 1;
155  os->psize -= lb + 1;
156 
157  while (lb--)
158  os->pduration += p[lb+1] << (lb*8);
159 
160  return 0;
161 }
162 
164  .magic = "\001video",
165  .magicsize = 6,
166  .header = ogm_header,
167  .packet = ogm_packet,
168  .granule_is_start = 1,
169 };
170 
172  .magic = "\001audio",
173  .magicsize = 6,
174  .header = ogm_header,
175  .packet = ogm_packet,
176  .granule_is_start = 1,
177 };
178 
179 const struct ogg_codec ff_ogm_text_codec = {
180  .magic = "\001text",
181  .magicsize = 5,
182  .header = ogm_header,
183  .packet = ogm_packet,
184  .granule_is_start = 1,
185 };
186 
187 const struct ogg_codec ff_ogm_old_codec = {
188  .magic = "\001Direct Show Samples embedded in Ogg",
189  .magicsize = 35,
190  .header = ogm_dshow_header,
191  .packet = ogm_packet,
192  .granule_is_start = 1,
193 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
const struct ogg_codec ff_ogm_old_codec
Definition: oggparseogm.c:187
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition: oggdec.h:31
unsigned int pflags
Definition: oggdec.h:67
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the pts for a given stream.
Definition: utils.c:3828
int num
numerator
Definition: rational.h:44
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:138
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:954
static int ogm_header(AVFormatContext *s, int idx)
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition: oggparseogm.c:35
static int ogm_dshow_header(AVFormatContext *s, int idx)
Definition: oggparseogm.c:109
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1398
Format I/O context.
Definition: avformat.h:863
#define AV_RL64
Definition: intreadwrite.h:173
unsigned int psize
Definition: oggdec.h:66
const struct ogg_codec ff_ogm_text_codec
Definition: oggparseogm.c:179
enum AVStreamParseType need_parsing
Definition: avformat.h:815
AVStream ** streams
Definition: avformat.h:908
const uint8_t * buffer
Definition: bytestream.h:32
uint32_t tag
Definition: movenc.c:670
bitstream reader API header.
enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:2206
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size)
static float t
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:167
AV_RL32
Definition: bytestream.h:89
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:266
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:157
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:289
AVCodecContext * codec
codec context
Definition: avformat.h:623
int bit_rate
the average bitrate
Definition: avcodec.h:1340
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:31
int width
picture width / height.
Definition: avcodec.h:1408
unsigned int pstart
Definition: oggdec.h:65
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
struct ogg_stream * streams
Definition: oggdec.h:95
AVDictionary * metadata
Definition: avformat.h:718
const struct ogg_codec ff_ogm_video_codec
Definition: oggparseogm.c:163
Stream structure.
Definition: avformat.h:620
NULL
Definition: eval.c:50
enum AVMediaType codec_type
Definition: avcodec.h:1574
unsigned int pduration
Definition: oggdec.h:68
int sample_rate
samples per second
Definition: avcodec.h:1456
static int ogm_packet(AVFormatContext *s, int idx)
Definition: oggparseogm.c:143
raw UTF-8 text
Definition: avcodec.h:404
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1590
const int8_t * magic
Definition: oggdec.h:32
uint8_t * buf
Definition: oggdec.h:62
full parsing and repack
Definition: avformat.h:581
Main libavformat public API header.
AV_WL32 AV_WL24 AV_RL16
Definition: bytestream.h:89
int den
denominator
Definition: rational.h:45
Definition: oggdec.h:94
int channels
number of audio channels
Definition: avcodec.h:1457
void * priv_data
Format private data.
Definition: avformat.h:883
const struct ogg_codec ff_ogm_audio_codec
Definition: oggparseogm.c:171
enum CodecID codec_id
Definition: avcodec.h:1575