Commit 2a0de662 authored by aurel's avatar aurel

VP5 and VP6 video decoder

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@6213 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent ecc727d7
......@@ -56,6 +56,8 @@ version <next>
- MacIntel support
- AVISynth support
- VMware video decoder
- VP5 video decoder
- VP6 video decoder
version 0.4.9-pre1:
......
......@@ -164,6 +164,8 @@ Codecs:
vcr1.c Michael Niedermayer
vmnc.c Kostya Shishkov
vp3* Mike Melanson
vp5 Aurelien Jacobs
vp6 Aurelien Jacobs
vqavideo.c Mike Melanson
wmv2.c Michael Niedermayer
wnv1.c Kostya Shishkov
......
......@@ -778,6 +778,8 @@ following image formats are supported:
@item Sorenson Video 1 @tab X @tab X @tab fourcc: SVQ1
@item Sorenson Video 3 @tab @tab X @tab fourcc: SVQ3
@item On2 VP3 @tab @tab X @tab still experimental
@item On2 VP5 @tab @tab X @tab fourcc: VP50
@item On2 VP6 @tab @tab X @tab fourcc: VP62
@item Theora @tab @tab X @tab still experimental
@item Intel Indeo 3 @tab @tab X
@item FLV @tab X @tab X @tab Sorenson H.263 used in Flash
......
......@@ -123,6 +123,8 @@ OBJS-$(CONFIG_VMDVIDEO_DECODER) += vmdav.o
OBJS-$(CONFIG_VMNC_DECODER) += vmnc.o
OBJS-$(CONFIG_VORBIS_DECODER) += vorbis.o
OBJS-$(CONFIG_VP3_DECODER) += vp3.o
OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o
OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o
OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o
OBJS-$(CONFIG_WMAV1_DECODER) += wmadec.o
OBJS-$(CONFIG_WMAV2_DECODER) += wmadec.o
......
......@@ -371,6 +371,15 @@ void avcodec_register_all(void)
#ifdef CONFIG_THEORA_DECODER
register_avcodec(&theora_decoder);
#endif //CONFIG_THEORA_DECODER
#ifdef CONFIG_VP5_DECODER
register_avcodec(&vp5_decoder);
#endif //CONFIG_VP5_DECODER
#ifdef CONFIG_VP6_DECODER
register_avcodec(&vp6_decoder);
#endif //CONFIG_VP6_DECODER
#ifdef CONFIG_VP6F_DECODER
register_avcodec(&vp6f_decoder);
#endif //CONFIG_VP6F_DECODER
#ifdef CONFIG_ASV1_DECODER
register_avcodec(&asv1_decoder);
#endif //CONFIG_ASV1_DECODER
......
......@@ -17,8 +17,8 @@ extern "C" {
#define AV_STRINGIFY(s) AV_TOSTRING(s)
#define AV_TOSTRING(s) #s
#define LIBAVCODEC_VERSION_INT ((51<<16)+(13<<8)+0)
#define LIBAVCODEC_VERSION 51.13.0
#define LIBAVCODEC_VERSION_INT ((51<<16)+(14<<8)+0)
#define LIBAVCODEC_VERSION 51.14.0
#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
......@@ -121,6 +121,9 @@ enum CodecID {
CODEC_ID_CAVS,
CODEC_ID_JPEG2000,
CODEC_ID_VMNC,
CODEC_ID_VP5,
CODEC_ID_VP6,
CODEC_ID_VP6F,
/* various pcm "codecs" */
CODEC_ID_PCM_S16LE= 0x10000,
......@@ -2192,6 +2195,9 @@ extern AVCodec h264_decoder;
extern AVCodec indeo3_decoder;
extern AVCodec vp3_decoder;
extern AVCodec theora_decoder;
extern AVCodec vp5_decoder;
extern AVCodec vp6_decoder;
extern AVCodec vp6f_decoder;
extern AVCodec amr_nb_decoder;
extern AVCodec amr_nb_encoder;
extern AVCodec amr_wb_encoder;
......
This diff is collapsed.
This diff is collapsed.
/**
* @file vp56.h
* VP5 and VP6 compatible video decoder (common features)
*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef VP56_H
#define VP56_H
#include <stdint.h>
#include "vp56data.h"
#include "dsputil.h"
#include "mpegvideo.h"
typedef struct vp56_context vp56_context_t;
typedef struct vp56_mv vp56_mv_t;
typedef void (*vp56_parse_vector_adjustment_t)(vp56_context_t *s,
vp56_mv_t *vector);
typedef int (*vp56_adjust_t)(int v, int t);
typedef void (*vp56_filter_t)(vp56_context_t *s, uint8_t *dst, uint8_t *src,
int offset1, int offset2, int stride,
vp56_mv_t mv, int mask, int select, int luma);
typedef void (*vp56_parse_coeff_t)(vp56_context_t *s);
typedef void (*vp56_default_models_init_t)(vp56_context_t *s);
typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s);
typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s);
typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf,
int buf_size, int *golden_frame);
typedef struct {
int high;
int bits;
const uint8_t *buffer;
unsigned long code_word;
} vp56_range_coder_t;
typedef struct {
uint8_t not_null_dc;
vp56_frame_t ref_frame;
DCTELEM dc_coeff;
} vp56_ref_dc_t;
struct vp56_mv {
int x;
int y;
};
typedef struct {
uint8_t type;
vp56_mv_t mv;
} vp56_macroblock_t;
struct vp56_context {
AVCodecContext *avctx;
DSPContext dsp;
ScanTable scantable;
AVFrame frames[3];
uint8_t *edge_emu_buffer_alloc;
uint8_t *edge_emu_buffer;
vp56_range_coder_t c;
/* frame info */
int plane_width[3];
int plane_height[3];
int mb_width; /* number of horizontal MB */
int mb_height; /* number of vertical MB */
int block_offset[6];
int quantizer;
uint16_t dequant_dc;
uint16_t dequant_ac;
/* DC predictors management */
vp56_ref_dc_t *above_blocks;
vp56_ref_dc_t left_block[4];
int above_block_idx[6];
DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */
/* blocks / macroblock */
vp56_mb_t mb_type;
vp56_macroblock_t *macroblocks;
DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]);
uint8_t coeff_reorder[64]; /* used in vp6 only */
uint8_t coeff_index_to_pos[64]; /* used in vp6 only */
/* motion vectors */
vp56_mv_t mv[6]; /* vectors for each block in MB */
vp56_mv_t vector_candidate[2];
int vector_candidate_pos;
/* filtering hints */
int deblock_filtering;
int filter_selection;
int filter_mode;
int max_vector_length;
int sample_variance_threshold;
/* AC models */
uint8_t vector_model_sig[2]; /* delta sign */
uint8_t vector_model_dct[2]; /* delta coding types */
uint8_t vector_model_pdi[2][2]; /* predefined delta init */
uint8_t vector_model_pdv[2][7]; /* predefined delta values */
uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */
uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */
uint8_t coeff_model_dccv[2][11]; /* DC coeff value */
uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */
uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */
uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */
uint8_t coeff_ctx[4][64]; /* used in vp5 only */
uint8_t coeff_ctx_last[4]; /* used in vp5 only */
/* upside-down flipping hints */
int flip; /* are we flipping ? */
int frbi; /* first row block index in MB */
int srbi; /* second row block index in MB */
int stride[3]; /* stride for each plan */
const uint8_t *vp56_coord_div;
vp56_parse_vector_adjustment_t parse_vector_adjustment;
vp56_adjust_t adjust;
vp56_filter_t filter;
vp56_parse_coeff_t parse_coeff;
vp56_default_models_init_t default_models_init;
vp56_parse_vector_models_t parse_vector_models;
vp56_parse_coeff_models_t parse_coeff_models;
vp56_parse_header_t parse_header;
};
void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip);
int vp56_free(AVCodecContext *avctx);
void vp56_init_dequant(vp56_context_t *s, int quantizer);
int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
uint8_t *buf, int buf_size);
/**
* vp56 specific range coder implementation
*/
static inline void vp56_init_range_decoder(vp56_range_coder_t *c,
const uint8_t *buf, int buf_size)
{
c->high = 255;
c->bits = 8;
c->buffer = buf;
c->code_word = *c->buffer++ << 8;
c->code_word |= *c->buffer++;
}
static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob)
{
unsigned int low = 1 + (((c->high - 1) * prob) / 256);
unsigned int low_shift = low << 8;
int bit = c->code_word >= low_shift;
if (bit) {
c->high -= low;
c->code_word -= low_shift;
} else {
c->high = low;
}
/* normalize */
while (c->high < 128) {
c->high <<= 1;
c->code_word <<= 1;
if (--c->bits == 0) {
c->bits = 8;
c->code_word |= *c->buffer++;
}
}
return bit;
}
static inline int vp56_rac_get(vp56_range_coder_t *c)
{
/* equiprobable */
int low = (c->high + 1) >> 1;
unsigned int low_shift = low << 8;
int bit = c->code_word >= low_shift;
if (bit) {
c->high = (c->high - low) << 1;
c->code_word -= low_shift;
} else {
c->high = low << 1;
}
/* normalize */
c->code_word <<= 1;
if (--c->bits == 0) {
c->bits = 8;
c->code_word |= *c->buffer++;
}
return bit;
}
static inline int vp56_rac_gets(vp56_range_coder_t *c, int bits)
{
int value = 0;
while (bits--) {
value = (value << 1) | vp56_rac_get(c);
}
return value;
}
static inline int vp56_rac_gets_nn(vp56_range_coder_t *c, int bits)
{
int v = vp56_rac_gets(c, 7) << 1;
return v + !v;
}
static inline int vp56_rac_get_tree(vp56_range_coder_t *c,
const vp56_tree_t *tree,
const uint8_t *probs)
{
while (tree->val > 0) {
if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
tree += tree->val;
else
tree++;
}
return -tree->val;
}
#endif /* VP56_H */
/**
* @file vp56data.c
* VP5 and VP6 compatible video decoder (common data)
*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
#include "vp56data.h"
const uint8_t vp56_b6to3[] = { 0, 0, 0, 0, 1, 2 };
const uint8_t vp56_b6to4[] = { 0, 0, 1, 1, 2, 3 };
const uint8_t vp56_coeff_parse_table[6][11] = {
{ 159, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 145, 165, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 140, 148, 173, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 135, 140, 155, 176, 0, 0, 0, 0, 0, 0, 0 },
{ 130, 134, 141, 157, 180, 0, 0, 0, 0, 0, 0 },
{ 129, 130, 133, 140, 153, 177, 196, 230, 243, 254, 254 },
};
const uint8_t vp56_def_mb_types_stats[3][10][2] = {
{ { 69, 42 }, { 1, 2 }, { 1, 7 }, { 44, 42 }, { 6, 22 },
{ 1, 3 }, { 0, 2 }, { 1, 5 }, { 0, 1 }, { 0, 0 }, },
{ { 229, 8 }, { 1, 1 }, { 0, 8 }, { 0, 0 }, { 0, 0 },
{ 1, 2 }, { 0, 1 }, { 0, 0 }, { 1, 1 }, { 0, 0 }, },
{ { 122, 35 }, { 1, 1 }, { 1, 6 }, { 46, 34 }, { 0, 0 },
{ 1, 2 }, { 0, 1 }, { 0, 1 }, { 1, 1 }, { 0, 0 }, },
};
const vp56_tree_t vp56_pva_tree[] = {
{ 8, 0},
{ 4, 1},
{ 2, 2}, {-0}, {-1},
{ 2, 3}, {-2}, {-3},
{ 4, 4},
{ 2, 5}, {-4}, {-5},
{ 2, 6}, {-6}, {-7},
};
const vp56_tree_t vp56_pc_tree[] = {
{ 4, 6},
{ 2, 7}, {-0}, {-1},
{ 4, 8},
{ 2, 9}, {-2}, {-3},
{ 2,10}, {-4}, {-5},
};
const uint8_t vp56_coeff_bias[] = { 5, 7, 11, 19, 35, 67 };
const uint8_t vp56_coeff_bit_length[] = { 0, 1, 2, 3, 4, 10 };
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -184,6 +184,11 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
switch(flags & 0xF){
case 2: st->codec->codec_id = CODEC_ID_FLV1; break;
case 3: st->codec->codec_id = CODEC_ID_FLASHSV; break;
case 4:
st->codec->codec_id = CODEC_ID_VP6F;
get_byte(&s->pb); /* width and height adjustment */
size--;
break;
default:
av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flags & 0xf);
st->codec->codec_tag= flags & 0xF;
......
......@@ -182,15 +182,15 @@ static const CodecTag nsv_codec_video_tags[] = {
{ CODEC_ID_VP3, MKTAG('V', 'P', '3', ' ') },
{ CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
{ CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
{ CODEC_ID_VP5, MKTAG('V', 'P', '5', ' ') },
{ CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
{ CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
/*
{ CODEC_ID_VP4, MKTAG('V', 'P', '4', ' ') },
{ CODEC_ID_VP4, MKTAG('V', 'P', '4', '0') },
{ CODEC_ID_VP5, MKTAG('V', 'P', '5', ' ') },
{ CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
{ CODEC_ID_VP6, MKTAG('V', 'P', '6', ' ') },
{ CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') },
{ CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') },
{ CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
*/
{ CODEC_ID_XVID, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */
{ CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', '3') },
......
......@@ -114,6 +114,8 @@ const CodecTag codec_bmp_tags[] = {
{ CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
{ CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
{ CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
{ CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
{ CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
{ CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
{ CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
{ CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
......
......@@ -19,6 +19,7 @@
*/
#include "avformat.h"
#include "bitstream.h"
#include "riff.h" /* for CodecTag */
/* should have a generic way to indicate probable size */
#define DUMMY_FILE_SIZE (100 * 1024 * 1024)
......@@ -45,8 +46,6 @@
#define FLAG_SETFILL0 0x02
#define FLAG_SETFILL1 0x04
#define SWF_VIDEO_CODEC_FLV1 0x02
#define AUDIO_FIFO_SIZE 65536
/* character id used */
......@@ -80,6 +79,12 @@ typedef struct {
int audio_type;
} SWFContext;
static const CodecTag swf_codec_tags[] = {
{CODEC_ID_FLV1, 0x02},
{CODEC_ID_VP6F, 0x04},
{0, 0},
};
static const int sSampleRates[3][4] = {
{44100, 48000, 32000, 0},
{22050, 24000, 16000, 0},
......@@ -328,10 +333,12 @@ static int swf_write_header(AVFormatContext *s)
if (enc->codec_type == CODEC_TYPE_AUDIO)
audio_enc = enc;
else {
if ( enc->codec_id == CODEC_ID_FLV1 || enc->codec_id == CODEC_ID_MJPEG ) {
if ( enc->codec_id == CODEC_ID_VP6F ||
enc->codec_id == CODEC_ID_FLV1 ||
enc->codec_id == CODEC_ID_MJPEG ) {
video_enc = enc;
} else {
av_log(enc, AV_LOG_ERROR, "SWF only supports FLV1 and MJPEG\n");
av_log(enc, AV_LOG_ERROR, "SWF only supports VP6, FLV1 and MJPEG\n");
return -1;
}
}
......@@ -361,7 +368,9 @@ static int swf_write_header(AVFormatContext *s)
}
put_tag(pb, "FWS");
if ( video_enc && video_enc->codec_id == CODEC_ID_FLV1 ) {
if ( video_enc && video_enc->codec_id == CODEC_ID_VP6F ) {
put_byte(pb, 8); /* version (version 8 and above support VP6 codec) */
} else if ( video_enc && video_enc->codec_id == CODEC_ID_FLV1 ) {
put_byte(pb, 6); /* version (version 6 and above support FLV1 codec) */
} else {
put_byte(pb, 4); /* version (should use 4 for mpeg audio support) */
......@@ -375,7 +384,8 @@ static int swf_write_header(AVFormatContext *s)
put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
/* define a shape with the jpeg inside */
if ( video_enc && video_enc->codec_id == CODEC_ID_FLV1 ) {
if ( video_enc && (video_enc->codec_id == CODEC_ID_VP6F ||
video_enc->codec_id == CODEC_ID_FLV1 )) {
} else if ( video_enc && video_enc->codec_id == CODEC_ID_MJPEG ) {
put_swf_tag(s, TAG_DEFINESHAPE);
......@@ -512,7 +522,8 @@ retry_swf_audio_packet:
}
}
if ( swf->video_type == CODEC_ID_FLV1 ) {
if ( swf->video_type == CODEC_ID_VP6F ||
swf->video_type == CODEC_ID_FLV1 ) {
if ( swf->video_frame_number == 0 ) {
/* create a new video object */
put_swf_tag(s, TAG_VIDEOSTREAM);
......@@ -521,7 +532,7 @@ retry_swf_audio_packet:
put_le16(pb, enc->width);
put_le16(pb, enc->height);
put_byte(pb, 0);
put_byte(pb, SWF_VIDEO_CODEC_FLV1);
put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type));
put_swf_end_tag(s);
/* place the video object for the first time */
......@@ -784,18 +795,20 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
return AVERROR_IO;
}
if ( tag == TAG_VIDEOSTREAM && !vst) {
int codec_id;
swf->ch_id = get_le16(pb);
get_le16(pb);
get_le16(pb);
get_le16(pb);
get_byte(pb);
/* Check for FLV1 */
if ( get_byte(pb) == SWF_VIDEO_CODEC_FLV1 ) {
codec_id = codec_get_id(swf_codec_tags, get_byte(pb));
if ( codec_id ) {
vst = av_new_stream(s, 0);
av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */
vst->codec->codec_type = CODEC_TYPE_VIDEO;
vst->codec->codec_id = CODEC_ID_FLV1;
vst->codec->codec_id = codec_id;
if ( swf->samples_per_frame ) {
vst->codec->time_base.den = 1000. / swf->ms_per_frame;
vst->codec->time_base.num = 1;
......
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