[Ffmpeg-cvslog] CVS: ffmpeg/libavcodec oggtheora.c, NONE, 1.1 allcodecs.c, 1.102, 1.103 vp3.c, 1.38, 1.39

Måns Rullgård CVS mru
Wed May 11 18:42:19 CEST 2005


Update of /cvsroot/ffmpeg/ffmpeg/libavcodec
In directory mail:/var2/tmp/cvs-serv6682

Modified Files:
	allcodecs.c vp3.c 
Added Files:
	oggtheora.c 
Log Message:
theora decoding using libtheora


--- NEW FILE: oggtheora.c ---
/**
    Copyright (C) 2005  M??ns Rullg??rd

    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 <theora/theora.h>
#include "avcodec.h"

typedef struct TheoraContext {
    theora_info info;
    theora_state state;
    theora_comment comment;
    ogg_packet op;
} TheoraContext;

static int
Theora_decode_frame(AVCodecContext *ctx, void *outdata, int *outdata_size,
                    uint8_t *buf, int buf_size)
{
    TheoraContext *thc = ctx->priv_data;
    AVFrame *frame = outdata;
    yuv_buffer yuv;

    thc->op.packet = buf;
    thc->op.bytes = buf_size;

    if(theora_decode_packetin(&thc->state, &thc->op))
	return -1;

    theora_decode_YUVout(&thc->state, &yuv);

    frame->data[0] = yuv.y;
    frame->data[1] = yuv.u;
    frame->data[2] = yuv.v;
    frame->linesize[0] = yuv.y_stride;
    frame->linesize[1] = yuv.uv_stride;
    frame->linesize[2] = yuv.uv_stride;

    *outdata_size = sizeof(*frame);
    return buf_size;
}

static int
Theora_decode_end(AVCodecContext *ctx)
{
    TheoraContext *thc = ctx->priv_data;
    theora_info_clear(&thc->info);
    theora_comment_clear(&thc->comment);
    return 0;
}

static int
Theora_decode_init(AVCodecContext *ctx)
{
    TheoraContext *thc = ctx->priv_data;
    int size, hs, i;
    ogg_packet op;
    uint8_t *cdp;

    if(ctx->extradata_size < 6)
	return -1;

    theora_info_init(&thc->info);

    memset(&op, 0, sizeof(op));
    cdp = ctx->extradata;
    size = ctx->extradata_size;

    for(i = 0; i < 3; i++){
	hs = *cdp++ << 8;
	hs += *cdp++;
	size -= 2;

	if(hs > size){
	    av_log(ctx, AV_LOG_ERROR, "extradata too small: %i > %i\n",
                   hs, size);
	    return -1;
	}

	op.packet = cdp;
	op.bytes = hs;
	op.b_o_s = !i;
	if(theora_decode_header(&thc->info, &thc->comment, &op))
	    return -1;
	op.packetno++;

	cdp += hs;
	size -= hs;
    }

    theora_decode_init(&thc->state, &thc->info);

    ctx->width = thc->info.width;
    ctx->height = thc->info.height;
    ctx->time_base.num = thc->info.fps_denominator;
    ctx->time_base.den = thc->info.fps_numerator;
    ctx->pix_fmt = PIX_FMT_YUV420P; /* FIXME: others are possible */

    return 0;
}

AVCodec oggtheora_decoder = {
    "theora",
    CODEC_TYPE_VIDEO,
    CODEC_ID_THEORA,
    sizeof(TheoraContext),
    Theora_decode_init,
    NULL,
    Theora_decode_end,
    Theora_decode_frame,
    0,
    NULL
};

Index: allcodecs.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/allcodecs.c,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- allcodecs.c	2 May 2005 22:14:42 -0000	1.102
+++ allcodecs.c	11 May 2005 16:42:15 -0000	1.103
@@ -61,7 +61,7 @@
 #endif
 #ifdef CONFIG_LIBTHEORA
 #ifdef CONFIG_OGGTHEORA_ENCODER
-    register_avcodec(&oggtheora_encoder);
+//    register_avcodec(&oggtheora_encoder);
 #endif //CONFIG_OGGTHEORA_ENCODER
 #ifdef CONFIG_OGGTHEORA_DECODER
     register_avcodec(&oggtheora_decoder);
@@ -358,7 +358,7 @@
 #ifdef CONFIG_VP3_DECODER
     register_avcodec(&vp3_decoder);
 #endif //CONFIG_VP3_DECODER
-#ifdef CONFIG_THEORA_DECODER
+#if (defined CONFIG_THEORA_DECODER && !defined CONFIG_LIBTHEORA)
     register_avcodec(&theora_decoder);
 #endif //CONFIG_THEORA_DECODER
 #ifdef CONFIG_ASV1_DECODER

Index: vp3.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/vp3.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- vp3.c	3 Mar 2005 02:24:20 -0000	1.38
+++ vp3.c	11 May 2005 16:42:15 -0000	1.39
@@ -2973,6 +2973,7 @@
     NULL
 };
 
+#ifndef CONFIG_LIBTHEORA
 AVCodec theora_decoder = {
     "theora",
     CODEC_TYPE_VIDEO,
@@ -2985,3 +2986,4 @@
     0,
     NULL
 };
+#endif





More information about the ffmpeg-cvslog mailing list