[Ffmpeg-cvslog] CVS: ffmpeg/libavformat oggparsetheora.c, NONE, 1.1 Makefile, 1.87, 1.88 ogg2.c, 1.4, 1.5 ogg2.h, 1.2, 1.3

Måns Rullgård CVS mru
Wed May 11 18:38:37 CEST 2005


Update of /cvsroot/ffmpeg/ffmpeg/libavformat
In directory mail:/var2/tmp/cvs-serv14454

Modified Files:
	Makefile ogg2.c ogg2.h 
Added Files:
	oggparsetheora.c 
Log Message:
support theora in ogg, plus required ogg core changes


--- NEW FILE: oggparsetheora.c ---
/**
      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
};

Index: Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/Makefile,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- Makefile	8 May 2005 15:04:59 -0000	1.87
+++ Makefile	11 May 2005 16:38:34 -0000	1.88
@@ -17,7 +17,7 @@
       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 \
       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=
 ifeq ($(AMR_NB),yes)
 AMROBJS= amr.o

Index: ogg2.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/ogg2.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ogg2.c	12 Apr 2005 13:33:22 -0000	1.4
+++ ogg2.c	11 May 2005 16:38:34 -0000	1.5
@@ -39,6 +39,7 @@
 
 static ogg_codec_t *ogg_codecs[] = {
     &vorbis_codec,
+    &theora_codec,
     NULL
 };
 
@@ -425,17 +426,18 @@
 static uint64_t
 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];
     AVCodecContext *codec = &st->codec;
     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;
     }else if (codec->codec_type == CODEC_TYPE_VIDEO){
-//FIXME
-        pts = gp * 1000000LL / codec->sample_rate;
-//  pts = gp * st->video.frame_rate.den * 27000000LL /
-//      st->video.frame_rate.num;
+        pts = gp;
     }
 
     return pts;
@@ -534,6 +536,7 @@
 
     for (i = 0; i < ogg->nstreams; i++){
         av_free (ogg->streams[i].buf);
+        av_free (ogg->streams[i].private);
         av_freep (&s->streams[i]->codec.extradata);
     }
     av_free (ogg->streams);

Index: ogg2.h
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/ogg2.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ogg2.h	9 Apr 2005 23:27:48 -0000	1.2
+++ ogg2.h	11 May 2005 16:38:34 -0000	1.3
@@ -33,6 +33,7 @@
     int8_t *name;
     int (*header)(AVFormatContext *, int);
     int (*packet)(AVFormatContext *, int);
+    uint64_t (*gptopts)(AVFormatContext *, int, uint64_t);
 } ogg_codec_t;
 
 typedef struct ogg_stream {
@@ -49,6 +50,7 @@
     int header;
     int nsegs, segp;
     uint8_t segments[255];
+    void *private;
 } ogg_stream_t;
 
 typedef struct ogg_state {
@@ -72,6 +74,7 @@
 #define OGG_FLAG_EOS  4
 
 extern ogg_codec_t vorbis_codec;
+extern ogg_codec_t theora_codec;
 #if 0
 extern ogg_codec_t ogm_video_codec;
 extern ogg_codec_t ogm_audio_codec;





More information about the ffmpeg-cvslog mailing list