Commit df4c11e4 authored by mru's avatar mru

support theora in ogg, plus required ogg core changes


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@4217 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 6df665f9
...@@ -17,7 +17,7 @@ OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o img2.o raw.o rm.o \ ...@@ -17,7 +17,7 @@ OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o img2.o raw.o rm.o \
yuv4mpeg.o 4xm.o flvenc.o flvdec.o movenc.o psxstr.o idroq.o ipmovie.o \ yuv4mpeg.o 4xm.o flvenc.o flvdec.o movenc.o psxstr.o idroq.o ipmovie.o \
nut.o wc3movie.o mp3.o westwood.o segafilm.o idcin.o flic.o \ nut.o wc3movie.o mp3.o westwood.o segafilm.o idcin.o flic.o \
sierravmd.o matroska.o sol.o electronicarts.o nsvdec.o asf.o asf-enc.o \ sierravmd.o matroska.o sol.o electronicarts.o nsvdec.o asf.o asf-enc.o \
ogg2.o oggparsevorbis.o ogg2.o oggparsevorbis.o oggparsetheora.o
AMROBJS= AMROBJS=
ifeq ($(AMR_NB),yes) ifeq ($(AMR_NB),yes)
AMROBJS= amr.o AMROBJS= amr.o
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
static ogg_codec_t *ogg_codecs[] = { static ogg_codec_t *ogg_codecs[] = {
&vorbis_codec, &vorbis_codec,
&theora_codec,
NULL NULL
}; };
...@@ -425,17 +426,18 @@ ogg_get_headers (AVFormatContext * s) ...@@ -425,17 +426,18 @@ ogg_get_headers (AVFormatContext * s)
static uint64_t static uint64_t
ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) ogg_gptopts (AVFormatContext * s, int i, uint64_t gp)
{ {
ogg_t *ogg = s->priv_data;
ogg_stream_t *os = ogg->streams + i;
AVStream *st = s->streams[i]; AVStream *st = s->streams[i];
AVCodecContext *codec = &st->codec; AVCodecContext *codec = &st->codec;
uint64_t pts = AV_NOPTS_VALUE; uint64_t pts = AV_NOPTS_VALUE;
if (codec->codec_type == CODEC_TYPE_AUDIO){ if(os->codec->gptopts){
pts = os->codec->gptopts(s, i, gp);
} else if (codec->codec_type == CODEC_TYPE_AUDIO){
pts = gp * 1000000LL / codec->sample_rate; pts = gp * 1000000LL / codec->sample_rate;
}else if (codec->codec_type == CODEC_TYPE_VIDEO){ }else if (codec->codec_type == CODEC_TYPE_VIDEO){
//FIXME pts = gp;
pts = gp * 1000000LL / codec->sample_rate;
// pts = gp * st->video.frame_rate.den * 27000000LL /
// st->video.frame_rate.num;
} }
return pts; return pts;
...@@ -534,6 +536,7 @@ ogg_read_close (AVFormatContext * s) ...@@ -534,6 +536,7 @@ ogg_read_close (AVFormatContext * s)
for (i = 0; i < ogg->nstreams; i++){ for (i = 0; i < ogg->nstreams; i++){
av_free (ogg->streams[i].buf); av_free (ogg->streams[i].buf);
av_free (ogg->streams[i].private);
av_freep (&s->streams[i]->codec.extradata); av_freep (&s->streams[i]->codec.extradata);
} }
av_free (ogg->streams); av_free (ogg->streams);
......
...@@ -33,6 +33,7 @@ typedef struct ogg_codec { ...@@ -33,6 +33,7 @@ typedef struct ogg_codec {
int8_t *name; int8_t *name;
int (*header)(AVFormatContext *, int); int (*header)(AVFormatContext *, int);
int (*packet)(AVFormatContext *, int); int (*packet)(AVFormatContext *, int);
uint64_t (*gptopts)(AVFormatContext *, int, uint64_t);
} ogg_codec_t; } ogg_codec_t;
typedef struct ogg_stream { typedef struct ogg_stream {
...@@ -49,6 +50,7 @@ typedef struct ogg_stream { ...@@ -49,6 +50,7 @@ typedef struct ogg_stream {
int header; int header;
int nsegs, segp; int nsegs, segp;
uint8_t segments[255]; uint8_t segments[255];
void *private;
} ogg_stream_t; } ogg_stream_t;
typedef struct ogg_state { typedef struct ogg_state {
...@@ -72,6 +74,7 @@ typedef struct ogg { ...@@ -72,6 +74,7 @@ typedef struct ogg {
#define OGG_FLAG_EOS 4 #define OGG_FLAG_EOS 4
extern ogg_codec_t vorbis_codec; extern ogg_codec_t vorbis_codec;
extern ogg_codec_t theora_codec;
#if 0 #if 0
extern ogg_codec_t ogm_video_codec; extern ogg_codec_t ogm_video_codec;
extern ogg_codec_t ogm_audio_codec; extern ogg_codec_t ogm_audio_codec;
......
/**
Copyright (C) 2005 Matthieu CASTET
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
**/
#include <stdlib.h>
#include "avformat.h"
#include "bitstream.h"
#include "bswap.h"
#include "ogg2.h"
typedef struct theora_params {
int gpshift;
int gpmask;
} theora_params_t;
static int
theora_header (AVFormatContext * s, int idx)
{
ogg_t *ogg = s->priv_data;
ogg_stream_t *os = ogg->streams + idx;
AVStream *st = s->streams[idx];
theora_params_t *thp = os->private;
int cds = st->codec.extradata_size + os->psize + 2;
uint8_t *cdp;
if (os->seq > 2)
return 0;
if(!thp){
thp = av_mallocz(sizeof(*thp));
os->private = thp;
}
if (os->buf[os->pstart] == 0x80) {
GetBitContext gb;
init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
skip_bits(&gb, 7*8); /* 0x80"theora" */
skip_bits(&gb, 3*8);
st->codec.width = get_bits(&gb, 16) << 4;
st->codec.height = get_bits(&gb, 16) << 4;
skip_bits(&gb, 64);
st->codec.time_base.den = get_bits(&gb, 32);
st->codec.time_base.num = get_bits(&gb, 32);
st->codec.sample_aspect_ratio.num = get_bits(&gb, 24);
st->codec.sample_aspect_ratio.den = get_bits(&gb, 24);
skip_bits(&gb, 38);
thp->gpshift = get_bits(&gb, 5);
thp->gpmask = (1 << thp->gpshift) - 1;
st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = CODEC_ID_THEORA;
} else if (os->buf[os->pstart] == 0x83) {
vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
}
st->codec.extradata = av_realloc (st->codec.extradata, cds);
cdp = st->codec.extradata + st->codec.extradata_size;
*cdp++ = os->psize >> 8;
*cdp++ = os->psize & 0xff;
memcpy (cdp, os->buf + os->pstart, os->psize);
st->codec.extradata_size = cds;
return os->seq < 3;
}
static uint64_t
theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp)
{
AVStream *st = ctx->streams[idx];
ogg_t *ogg = ctx->priv_data;
ogg_stream_t *os = ogg->streams + idx;
theora_params_t *thp = os->private;
uint64_t iframe = gp >> thp->gpshift;
uint64_t pframe = gp & thp->gpmask;
return (iframe + pframe) * AV_TIME_BASE * st->codec.time_base.num /
st->codec.time_base.den;
}
ogg_codec_t theora_codec = {
.magic = "\200theora",
.magicsize = 7,
.header = theora_header,
.gptopts = theora_gptopts
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment