2 Copyright (C) 2005 Måns Rullgård
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation
6 files (the "Software"), to deal in the Software without
7 restriction, including without limitation the rights to use, copy,
8 modify, merge, publish, distribute, sublicense, and/or sell copies
9 of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
26 #include <theora/theora.h>
29 typedef struct TheoraContext
{
32 theora_comment comment
;
37 Theora_decode_frame(AVCodecContext
*ctx
, void *outdata
, int *outdata_size
,
38 uint8_t *buf
, int buf_size
)
40 TheoraContext
*thc
= ctx
->priv_data
;
41 AVFrame
*frame
= outdata
;
45 thc
->op
.bytes
= buf_size
;
47 if(theora_decode_packetin(&thc
->state
, &thc
->op
))
50 theora_decode_YUVout(&thc
->state
, &yuv
);
52 frame
->data
[0] = yuv
.y
;
53 frame
->data
[1] = yuv
.u
;
54 frame
->data
[2] = yuv
.v
;
55 frame
->linesize
[0] = yuv
.y_stride
;
56 frame
->linesize
[1] = yuv
.uv_stride
;
57 frame
->linesize
[2] = yuv
.uv_stride
;
59 *outdata_size
= sizeof(*frame
);
64 Theora_decode_end(AVCodecContext
*ctx
)
66 TheoraContext
*thc
= ctx
->priv_data
;
67 theora_info_clear(&thc
->info
);
68 theora_comment_clear(&thc
->comment
);
73 Theora_decode_init(AVCodecContext
*ctx
)
75 TheoraContext
*thc
= ctx
->priv_data
;
80 if(ctx
->extradata_size
< 6)
83 theora_info_init(&thc
->info
);
85 memset(&op
, 0, sizeof(op
));
87 size
= ctx
->extradata_size
;
89 for(i
= 0; i
< 3; i
++){
95 av_log(ctx
, AV_LOG_ERROR
, "extradata too small: %i > %i\n",
103 if(theora_decode_header(&thc
->info
, &thc
->comment
, &op
))
111 theora_decode_init(&thc
->state
, &thc
->info
);
113 ctx
->width
= thc
->info
.width
;
114 ctx
->height
= thc
->info
.height
;
115 ctx
->time_base
.num
= thc
->info
.fps_denominator
;
116 ctx
->time_base
.den
= thc
->info
.fps_numerator
;
117 ctx
->pix_fmt
= PIX_FMT_YUV420P
; /* FIXME: others are possible */
122 AVCodec oggtheora_decoder
= {
126 sizeof(TheoraContext
),