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  avpriv_set_pts_info(st, 64, time_unit, spu * 10000000);
90  } else {
91  st->codec->channels = bytestream2_get_le16(&p);
92  bytestream2_skip(&p, 2); /* block_align */
93  st->codec->bit_rate = bytestream2_get_le32(&p) * 8;
94  st->codec->sample_rate = spu * 10000000 / time_unit;
95  avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
96  }
97  } else if (bytestream2_peek_byte(&p) == 3) {
98  bytestream2_skip(&p, 7);
99  if (bytestream2_get_bytes_left(&p) > 1)
101  }
102 
103  return 1;
104 }
105 
106 static int
108 {
109  struct ogg *ogg = s->priv_data;
110  struct ogg_stream *os = ogg->streams + idx;
111  AVStream *st = s->streams[idx];
112  uint8_t *p = os->buf + os->pstart;
113  uint32_t t;
114 
115  if(!(*p & 1))
116  return 0;
117  if(*p != 1)
118  return 1;
119 
120  t = AV_RL32(p + 96);
121 
122  if(t == 0x05589f80){
125  avpriv_set_pts_info(st, 64, AV_RL64(p + 164), 10000000);
126  st->codec->width = AV_RL32(p + 176);
127  st->codec->height = AV_RL32(p + 180);
128  } else if(t == 0x05589f81){
131  st->codec->channels = AV_RL16(p + 126);
132  st->codec->sample_rate = AV_RL32(p + 128);
133  st->codec->bit_rate = AV_RL32(p + 132) * 8;
134  }
135 
136  return 1;
137 }
138 
139 static int
141 {
142  struct ogg *ogg = s->priv_data;
143  struct ogg_stream *os = ogg->streams + idx;
144  uint8_t *p = os->buf + os->pstart;
145  int lb;
146 
147  if(*p & 8)
148  os->pflags |= AV_PKT_FLAG_KEY;
149 
150  lb = ((*p & 2) << 1) | ((*p >> 6) & 3);
151  os->pstart += lb + 1;
152  os->psize -= lb + 1;
153 
154  while (lb--)
155  os->pduration += p[lb+1] << (lb*8);
156 
157  return 0;
158 }
159 
161  .magic = "\001video",
162  .magicsize = 6,
163  .header = ogm_header,
164  .packet = ogm_packet,
165  .granule_is_start = 1,
166  .nb_header = 2,
167 };
168 
170  .magic = "\001audio",
171  .magicsize = 6,
172  .header = ogm_header,
173  .packet = ogm_packet,
174  .granule_is_start = 1,
175  .nb_header = 2,
176 };
177 
178 const struct ogg_codec ff_ogm_text_codec = {
179  .magic = "\001text",
180  .magicsize = 5,
181  .header = ogm_header,
182  .packet = ogm_packet,
183  .granule_is_start = 1,
184  .nb_header = 2,
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  .nb_header = 1,
194 };
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
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:2126
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.
Definition: utils.c:3283
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
#define AV_RL16
Definition: intreadwrite.h:42
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:107
Format I/O context.
Definition: avformat.h:828
#define AV_RL64
Definition: intreadwrite.h:173
unsigned int psize
Definition: oggdec.h:66
uint8_t
const struct ogg_codec ff_ogm_text_codec
Definition: oggparseogm.c:178
enum AVStreamParseType need_parsing
Definition: avformat.h:775
AVStream ** streams
Definition: avformat.h:876
const uint8_t * buffer
Definition: bytestream.h:33
uint32_t tag
Definition: movenc.c:802
bitstream reader API header.
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:159
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:258
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:297
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
int bit_rate
the average bitrate
Definition: avcodec.h:1404
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:31
int width
picture width / height.
Definition: avcodec.h:1508
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:97
#define AV_RL32
Definition: intreadwrite.h:146
AVDictionary * metadata
Definition: avformat.h:699
const struct ogg_codec ff_ogm_video_codec
Definition: oggparseogm.c:160
Stream structure.
Definition: avformat.h:622
NULL
Definition: eval.c:52
enum AVMediaType codec_type
Definition: avcodec.h:1347
unsigned int pduration
Definition: oggdec.h:68
enum AVCodecID codec_id
Definition: avcodec.h:1350
int sample_rate
samples per second
Definition: avcodec.h:2104
static int ogm_packet(AVFormatContext *s, int idx)
Definition: oggparseogm.c:140
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1365
const int8_t * magic
Definition: oggdec.h:32
uint8_t * buf
Definition: oggdec.h:62
full parsing and repack
Definition: avformat.h:576
Main libavformat public API header.
raw UTF-8 text
Definition: avcodec.h:416
Definition: oggdec.h:96
int channels
number of audio channels
Definition: avcodec.h:2105
void * priv_data
Format private data.
Definition: avformat.h:848
const struct ogg_codec ff_ogm_audio_codec
Definition: oggparseogm.c:169