1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit 'b78f81c8033904e2e75add0c9a603df6df514a30'

* commit 'b78f81c8033904e2e75add0c9a603df6df514a30':
  h261: K&R formatting and prettyprinting cosmetics

Conflicts:
	libavcodec/h261_parser.c
	libavcodec/h261data.h
	libavcodec/h261dec.c
	libavcodec/h261enc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-04-05 21:53:57 +02:00
commit 04b0fd7e91
7 changed files with 474 additions and 450 deletions

View File

@ -51,7 +51,7 @@ static void h261_loop_filter(uint8_t *src, int stride)
for (y = 0; y < 8; y++) { for (y = 0; y < 8; y++) {
src[y * stride] = (temp[y * 8] + 2) >> 2; src[y * stride] = (temp[y * 8] + 2) >> 2;
src[7+y*stride] = (temp[7+y*8] + 2)>>2; src[y * stride + 7] = (temp[y * 8 + 7] + 2) >> 2;
for (x = 1; x < 7; x++) { for (x = 1; x < 7; x++) {
xy = y * stride + x; xy = y * stride + x;
yz = y * 8 + x; yz = y * 8 + x;
@ -60,7 +60,8 @@ static void h261_loop_filter(uint8_t *src, int stride)
} }
} }
void ff_h261_loop_filter(MpegEncContext *s){ void ff_h261_loop_filter(MpegEncContext *s)
{
H261Context *h = (H261Context *)s; H261Context *h = (H261Context *)s;
const int linesize = s->linesize; const int linesize = s->linesize;
const int uvlinesize = s->uvlinesize; const int uvlinesize = s->uvlinesize;

View File

@ -27,8 +27,9 @@
#include "parser.h" #include "parser.h"
static int h261_find_frame_end(ParseContext *pc, AVCodecContext *avctx,
static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){ const uint8_t *buf, int buf_size)
{
int vop_found, i, j; int vop_found, i, j;
uint32_t state; uint32_t state;

View File

@ -28,6 +28,7 @@
#include "h261.h" #include "h261.h"
#include "h261data.h" #include "h261data.h"
// H.261 VLC table for macroblock addressing // H.261 VLC table for macroblock addressing
const uint8_t ff_h261_mba_code[35] = { const uint8_t ff_h261_mba_code[35] = {
1, 3, 2, 3, 1, 3, 2, 3,
@ -74,13 +75,13 @@ const int ff_h261_mtype_map[10]= {
MB_TYPE_INTRA4x4, MB_TYPE_INTRA4x4,
MB_TYPE_INTRA4x4 | MB_TYPE_QUANT, MB_TYPE_INTRA4x4 | MB_TYPE_QUANT,
MB_TYPE_CBP, MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_CBP, MB_TYPE_CBP | MB_TYPE_QUANT,
MB_TYPE_16x16, MB_TYPE_16x16,
MB_TYPE_CBP | MB_TYPE_16x16, MB_TYPE_16x16 | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16, MB_TYPE_16x16 | MB_TYPE_CBP | MB_TYPE_QUANT,
MB_TYPE_16x16 | MB_TYPE_H261_FIL, MB_TYPE_16x16 | MB_TYPE_H261_FIL,
MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL, MB_TYPE_16x16 | MB_TYPE_H261_FIL | MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL MB_TYPE_16x16 | MB_TYPE_H261_FIL | MB_TYPE_CBP | MB_TYPE_QUANT
}; };
// H.261 VLC table for motion vectors // H.261 VLC table for motion vectors
@ -90,8 +91,7 @@ const uint8_t ff_h261_mv_tab[17][2] = {
}; };
// H.261 VLC table for coded block pattern // H.261 VLC table for coded block pattern
const uint8_t ff_h261_cbp_tab[63][2] = const uint8_t ff_h261_cbp_tab[63][2] = {
{
{ 11, 5 }, { 9, 5 }, { 13, 6 }, { 13, 4 }, { 23, 7 }, { 19, 7 }, { 31, 8 }, { 12, 4 }, { 11, 5 }, { 9, 5 }, { 13, 6 }, { 13, 4 }, { 23, 7 }, { 19, 7 }, { 31, 8 }, { 12, 4 },
{ 22, 7 }, { 18, 7 }, { 30, 8 }, { 19, 5 }, { 27, 8 }, { 23, 8 }, { 19, 8 }, { 11, 4 }, { 22, 7 }, { 18, 7 }, { 30, 8 }, { 19, 5 }, { 27, 8 }, { 23, 8 }, { 19, 8 }, { 11, 4 },
{ 21, 7 }, { 17, 7 }, { 29, 8 }, { 17, 5 }, { 25, 8 }, { 21, 8 }, { 17, 8 }, { 15, 6 }, { 21, 7 }, { 17, 7 }, { 29, 8 }, { 17, 5 }, { 25, 8 }, { 21, 8 }, { 17, 8 }, { 15, 6 },

View File

@ -28,6 +28,7 @@
#define AVCODEC_H261DATA_H #define AVCODEC_H261DATA_H
#include <stdint.h> #include <stdint.h>
#include "h261.h" #include "h261.h"
extern const uint8_t ff_h261_mba_code[35]; extern const uint8_t ff_h261_mba_code[35];

View File

@ -47,7 +47,8 @@ static VLC h261_cbp_vlc;
static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded); static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded);
static av_cold void h261_decode_init_vlc(H261Context *h){ static av_cold void h261_decode_init_vlc(H261Context *h)
{
static int done = 0; static int done = 0;
if (!done) { if (!done) {
@ -69,22 +70,20 @@ static av_cold void h261_decode_init_vlc(H261Context *h){
} }
} }
static av_cold int h261_decode_init(AVCodecContext *avctx){ static av_cold int h261_decode_init(AVCodecContext *avctx)
{
H261Context *h = avctx->priv_data; H261Context *h = avctx->priv_data;
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
// set defaults // set defaults
ff_MPV_decode_defaults(s); ff_MPV_decode_defaults(s);
s->avctx = avctx; s->avctx = avctx;
s->width = s->avctx->coded_width; s->width = s->avctx->coded_width;
s->height = s->avctx->coded_height; s->height = s->avctx->coded_height;
s->codec_id = s->avctx->codec->id; s->codec_id = s->avctx->codec->id;
s->out_format = FMT_H261; s->out_format = FMT_H261;
s->low_delay = 1; s->low_delay = 1;
avctx->pix_fmt = AV_PIX_FMT_YUV420P; avctx->pix_fmt = AV_PIX_FMT_YUV420P;
s->codec_id = avctx->codec->id; s->codec_id = avctx->codec->id;
h261_decode_init_vlc(h); h261_decode_init_vlc(h);
@ -98,7 +97,8 @@ static av_cold int h261_decode_init(AVCodecContext *avctx){
* Decode the group of blocks header or slice header. * Decode the group of blocks header or slice header.
* @return <0 if an error occurred * @return <0 if an error occurred
*/ */
static int h261_decode_gob_header(H261Context *h){ static int h261_decode_gob_header(H261Context *h)
{
unsigned int val; unsigned int val;
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
@ -118,19 +118,18 @@ static int h261_decode_gob_header(H261Context *h){
s->qscale = get_bits(&s->gb, 5); /* GQUANT */ s->qscale = get_bits(&s->gb, 5); /* GQUANT */
/* Check if gob_number is valid */ /* Check if gob_number is valid */
if (s->mb_height==18){ //cif if (s->mb_height == 18) { // CIF
if ((h->gob_number <= 0) || (h->gob_number > 12)) if ((h->gob_number <= 0) || (h->gob_number > 12))
return -1; return -1;
} } else { // QCIF
else{ //qcif if ((h->gob_number != 1) && (h->gob_number != 3) &&
if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5)) (h->gob_number != 5))
return -1; return -1;
} }
/* GEI */ /* GEI */
while (get_bits1(&s->gb) != 0) { while (get_bits1(&s->gb) != 0)
skip_bits(&s->gb, 8); skip_bits(&s->gb, 8);
}
if (s->qscale == 0) { if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n"); av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
@ -138,9 +137,10 @@ static int h261_decode_gob_header(H261Context *h){
return -1; return -1;
} }
// For the first transmitted macroblock in a GOB, MBA is the absolute address. For /* For the first transmitted macroblock in a GOB, MBA is the absolute
// subsequent macroblocks, MBA is the difference between the absolute addresses of * address. For subsequent macroblocks, MBA is the difference between
// the macroblock and the last transmitted macroblock. * the absolute addresses of the macroblock and the last transmitted
* macroblock. */
h->current_mba = 0; h->current_mba = 0;
h->mba_diff = 0; h->mba_diff = 0;
@ -151,7 +151,8 @@ static int h261_decode_gob_header(H261Context *h){
* Decode the group of blocks / video packet header. * Decode the group of blocks / video packet header.
* @return <0 if no resync found * @return <0 if no resync found
*/ */
static int ff_h261_resync(H261Context *h){ static int ff_h261_resync(H261Context *h)
{
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
int left, ret; int left, ret;
@ -159,8 +160,7 @@ static int ff_h261_resync(H261Context *h){
ret = h261_decode_gob_header(h); ret = h261_decode_gob_header(h);
if (ret >= 0) if (ret >= 0)
return 0; return 0;
} } else {
else{
if (show_bits(&s->gb, 15) == 0) { if (show_bits(&s->gb, 15) == 0) {
ret = h261_decode_gob_header(h); ret = h261_decode_gob_header(h);
if (ret >= 0) if (ret >= 0)
@ -225,7 +225,8 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
return 0; return 0;
} }
static int decode_mv_component(GetBitContext *gb, int v){ static int decode_mv_component(GetBitContext *gb, int v)
{
static const int mvmap[17] = { static const int mvmap[17] = {
0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
}; };
@ -241,20 +242,24 @@ static int decode_mv_component(GetBitContext *gb, int v){
mv_diff = -mv_diff; mv_diff = -mv_diff;
v += mv_diff; v += mv_diff;
if (v <=-16) v+= 32; if (v <= -16)
else if(v >= 16) v-= 32; v += 32;
else if (v >= 16)
v -= 32;
return v; return v;
} }
static int h261_decode_mb(H261Context *h){ static int h261_decode_mb(H261Context *h)
{
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
int i, cbp, xy; int i, cbp, xy;
cbp = 63; cbp = 63;
// Read mba // Read mba
do { do {
h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2); h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
H261_MBA_VLC_BITS, 2);
/* Check for slice end */ /* Check for slice end */
/* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */ /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
@ -262,8 +267,7 @@ static int h261_decode_mb(H261Context *h){
h->gob_start_code_skipped = 1; h->gob_start_code_skipped = 1;
return SLICE_END; return SLICE_END;
} }
} } while (h->mba_diff == MBA_STUFFING); // stuffing
while( h->mba_diff == MBA_STUFFING ); // stuffing
if (h->mba_diff < 0) { if (h->mba_diff < 0) {
if (get_bits_left(&s->gb) <= 7) if (get_bits_left(&s->gb) <= 7)
@ -294,23 +298,23 @@ static int h261_decode_mb(H261Context *h){
h->mtype = ff_h261_mtype_map[h->mtype]; h->mtype = ff_h261_mtype_map[h->mtype];
// Read mquant // Read mquant
if ( IS_QUANT ( h->mtype ) ){ if (IS_QUANT(h->mtype))
ff_set_qscale(s, get_bits(&s->gb, 5)); ff_set_qscale(s, get_bits(&s->gb, 5));
}
s->mb_intra = IS_INTRA4x4(h->mtype); s->mb_intra = IS_INTRA4x4(h->mtype);
// Read mv // Read mv
if (IS_16X16(h->mtype)) { if (IS_16X16(h->mtype)) {
// Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the /* Motion vector data is included for all MC macroblocks. MVD is
// vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the * obtained from the macroblock vector by subtracting the vector
// following three situations: * of the preceding macroblock. For this calculation the vector
// 1) evaluating MVD for macroblocks 1, 12 and 23; * of the preceding macroblock is regarded as zero in the
// 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1; * following three situations:
// 3) MTYPE of the previous macroblock was not MC. * 1) evaluating MVD for macroblocks 1, 12 and 23;
if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) || * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
( h->mba_diff != 1)) * 3) MTYPE of the previous macroblock was not MC. */
{ if ((h->current_mba == 1) || (h->current_mba == 12) ||
(h->current_mba == 23) || (h->mba_diff != 1)) {
h->current_mv_x = 0; h->current_mv_x = 0;
h->current_mv_y = 0; h->current_mv_y = 0;
} }
@ -323,9 +327,8 @@ static int h261_decode_mb(H261Context *h){
} }
// Read cbp // Read cbp
if ( HAS_CBP( h->mtype ) ){ if (HAS_CBP(h->mtype))
cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1; cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
}
if (s->mb_intra) { if (s->mb_intra) {
s->current_picture.mb_type[xy] = MB_TYPE_INTRA; s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
@ -344,9 +347,8 @@ intra:
if (s->mb_intra || HAS_CBP(h->mtype)) { if (s->mb_intra || HAS_CBP(h->mtype)) {
s->dsp.clear_blocks(s->block[0]); s->dsp.clear_blocks(s->block[0]);
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){ if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
return SLICE_ERROR; return SLICE_ERROR;
}
cbp += cbp; cbp += cbp;
} }
} else { } else {
@ -363,29 +365,31 @@ intra:
* Decode a macroblock. * Decode a macroblock.
* @return <0 if an error occurred * @return <0 if an error occurred
*/ */
static int h261_decode_block(H261Context * h, int16_t * block, static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
int n, int coded)
{ {
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
int code, level, i, j, run; int code, level, i, j, run;
RLTable *rl = &ff_h261_rl_tcoeff; RLTable *rl = &ff_h261_rl_tcoeff;
const uint8_t *scan_table; const uint8_t *scan_table;
// For the variable length encoding there are two code tables, one being used for /* For the variable length encoding there are two code tables, one being
// the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second * used for the first transmitted LEVEL in INTER, INTER + MC and
// for all other LEVELs except the first one in INTRA blocks which is fixed length * INTER + MC + FIL blocks, the second for all other LEVELs except the
// coded with 8 bits. * first one in INTRA blocks which is fixed length coded with 8 bits.
// NOTE: the two code tables only differ in one VLC so we handle that manually. * NOTE: The two code tables only differ in one VLC so we handle that
* manually. */
scan_table = s->intra_scantable.permutated; scan_table = s->intra_scantable.permutated;
if (s->mb_intra) { if (s->mb_intra) {
/* DC coef */ /* DC coef */
level = get_bits(&s->gb, 8); level = get_bits(&s->gb, 8);
// 0 (00000000b) and -128 (10000000b) are FORBIDDEN // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
if ((level & 0x7F) == 0) { if ((level & 0x7F) == 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
level, s->mb_x, s->mb_y);
return -1; return -1;
} }
// The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111. /* The code 1000 0000 is not used, the reconstruction level of 1024
* being coded as 1111 1111. */
if (level == 255) if (level == 255)
level = 128; level = 128;
block[0] = level; block[0] = level;
@ -412,12 +416,15 @@ static int h261_decode_block(H261Context * h, int16_t * block,
for (;;) { for (;;) {
code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2); code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2);
if (code < 0) { if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
s->mb_x, s->mb_y);
return -1; return -1;
} }
if (code == rl->n) { if (code == rl->n) {
/* escape */ /* escape */
// The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level. /* The remaining combinations of (run, level) are encoded with a
* 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
* level. */
run = get_bits(&s->gb, 6); run = get_bits(&s->gb, 6);
level = get_sbits(&s->gb, 8); level = get_sbits(&s->gb, 8);
} else if (code == 0) { } else if (code == 0) {
@ -430,7 +437,8 @@ static int h261_decode_block(H261Context * h, int16_t * block,
} }
i += run; i += run;
if (i >= 64) { if (i >= 64) {
av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y); av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
s->mb_x, s->mb_y);
return -1; return -1;
} }
j = scan_table[i]; j = scan_table[i];
@ -445,7 +453,8 @@ static int h261_decode_block(H261Context * h, int16_t * block,
* Decode the H.261 picture header. * Decode the H.261 picture header.
* @return <0 if no startcode found * @return <0 if no startcode found
*/ */
static int h261_decode_picture_header(H261Context *h){ static int h261_decode_picture_header(H261Context *h)
{
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
int format, i; int format, i;
uint32_t startcode = 0; uint32_t startcode = 0;
@ -471,7 +480,6 @@ static int h261_decode_picture_header(H261Context *h){
s->avctx->time_base = (AVRational) { 1001, 30000 }; s->avctx->time_base = (AVRational) { 1001, 30000 };
s->current_picture.f.pts = s->picture_number; s->current_picture.f.pts = s->picture_number;
/* PTYPE starts here */ /* PTYPE starts here */
skip_bits1(&s->gb); /* split screen off */ skip_bits1(&s->gb); /* split screen off */
skip_bits1(&s->gb); /* camera off */ skip_bits1(&s->gb); /* camera off */
@ -498,26 +506,26 @@ static int h261_decode_picture_header(H261Context *h){
skip_bits1(&s->gb); /* Reserved */ skip_bits1(&s->gb); /* Reserved */
/* PEI */ /* PEI */
while (get_bits1(&s->gb) != 0){ while (get_bits1(&s->gb) != 0)
skip_bits(&s->gb, 8); skip_bits(&s->gb, 8);
}
// h261 has no I-FRAMES, but if we pass AV_PICTURE_TYPE_I for the first frame, the codec crashes if it does /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first
// not contain all I-blocks (e.g. when a packet is lost) * frame, the codec crashes if it does not contain all I-blocks
* (e.g. when a packet is lost). */
s->pict_type = AV_PICTURE_TYPE_P; s->pict_type = AV_PICTURE_TYPE_P;
h->gob_number = 0; h->gob_number = 0;
return 0; return 0;
} }
static int h261_decode_gob(H261Context *h){ static int h261_decode_gob(H261Context *h)
{
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
ff_set_qscale(s, s->qscale); ff_set_qscale(s, s->qscale);
/* decode mb's */ /* decode mb's */
while(h->current_mba <= MBA_STUFFING) while (h->current_mba <= MBA_STUFFING) {
{
int ret; int ret;
/* DCT & quantize */ /* DCT & quantize */
ret = h261_decode_mb(h); ret = h261_decode_mb(h);
@ -526,11 +534,14 @@ static int h261_decode_gob(H261Context *h){
h261_decode_mb_skipped(h, h->current_mba, 33); h261_decode_mb_skipped(h, h->current_mba, 33);
return 0; return 0;
} }
av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride); av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
s->mb_x + s->mb_y * s->mb_stride);
return -1; return -1;
} }
h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1); h261_decode_mb_skipped(h,
h->current_mba - h->mba_diff,
h->current_mba - 1);
} }
return -1; return -1;
@ -539,17 +550,19 @@ static int h261_decode_gob(H261Context *h){
/** /**
* returns the number of bytes consumed for building the current frame * returns the number of bytes consumed for building the current frame
*/ */
static int get_consumed_bytes(MpegEncContext *s, int buf_size){ static int get_consumed_bytes(MpegEncContext *s, int buf_size)
{
int pos = get_bits_count(&s->gb) >> 3; int pos = get_bits_count(&s->gb) >> 3;
if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...) if (pos == 0)
if(pos+10>buf_size) pos=buf_size; // oops ;) pos = 1; // avoid infinite loops (i doubt that is needed but ...)
if (pos + 10 > buf_size)
pos = buf_size; // oops ;)
return pos; return pos;
} }
static int h261_decode_frame(AVCodecContext *avctx, static int h261_decode_frame(AVCodecContext *avctx, void *data,
void *data, int *got_frame, int *got_frame, AVPacket *avpkt)
AVPacket *avpkt)
{ {
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
@ -566,15 +579,15 @@ static int h261_decode_frame(AVCodecContext *avctx,
h->gob_start_code_skipped = 0; h->gob_start_code_skipped = 0;
retry: retry:
init_get_bits(&s->gb, buf, buf_size * 8); init_get_bits(&s->gb, buf, buf_size * 8);
if(!s->context_initialized){ if (!s->context_initialized)
if (ff_MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix // we need the IDCT permutaton for reading a custom matrix
if (ff_MPV_common_init(s) < 0)
return -1; return -1;
}
//we need to set current_picture_ptr before reading the header, otherwise we cannot store anyting im there /* We need to set current_picture_ptr before reading the header,
* otherwise we cannot store anything in there. */
if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
int i = ff_find_unused_picture(s, 0); int i = ff_find_unused_picture(s, 0);
if (i < 0) if (i < 0)
@ -606,9 +619,9 @@ retry:
s->current_picture.f.pict_type = s->pict_type; s->current_picture.f.pict_type = s->pict_type;
s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B) if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I) (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
|| avctx->skip_frame >= AVDISCARD_ALL) avctx->skip_frame >= AVDISCARD_ALL)
return get_consumed_bytes(s, buf_size); return get_consumed_bytes(s, buf_size);
if (ff_MPV_frame_start(s, avctx) < 0) if (ff_MPV_frame_start(s, avctx) < 0)

View File

@ -35,7 +35,8 @@
static void h261_encode_block(H261Context *h, int16_t *block, static void h261_encode_block(H261Context *h, int16_t *block,
int n); int n);
int ff_h261_get_picture_format(int width, int height){ int ff_h261_get_picture_format(int width, int height)
{
// QCIF // QCIF
if (width == 176 && height == 144) if (width == 176 && height == 144)
return 0; return 0;
@ -47,7 +48,8 @@ int ff_h261_get_picture_format(int width, int height){
return -1; return -1;
} }
void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){ void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number)
{
H261Context *h = (H261Context *)s; H261Context *h = (H261Context *)s;
int format, temp_ref; int format, temp_ref;
@ -84,12 +86,12 @@ void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
/** /**
* Encode a group of blocks header. * Encode a group of blocks header.
*/ */
static void h261_encode_gob_header(MpegEncContext * s, int mb_line){ static void h261_encode_gob_header(MpegEncContext *s, int mb_line)
{
H261Context *h = (H261Context *)s; H261Context *h = (H261Context *)s;
if (ff_h261_get_picture_format(s->width, s->height) == 0) { if (ff_h261_get_picture_format(s->width, s->height) == 0) {
h->gob_number += 2; // QCIF h->gob_number += 2; // QCIF
} } else {
else{
h->gob_number++; // CIF h->gob_number++; // CIF
} }
put_bits(&s->pb, 16, 1); /* GBSC */ put_bits(&s->pb, 16, 1); /* GBSC */
@ -102,18 +104,22 @@ static void h261_encode_gob_header(MpegEncContext * s, int mb_line){
h->current_mv_y = 0; h->current_mv_y = 0;
} }
void ff_h261_reorder_mb_index(MpegEncContext* s){ void ff_h261_reorder_mb_index(MpegEncContext *s)
{
int index = s->mb_x + s->mb_y * s->mb_width; int index = s->mb_x + s->mb_y * s->mb_width;
if (index % 33 == 0) if (index % 33 == 0)
h261_encode_gob_header(s, 0); h261_encode_gob_header(s, 0);
/* for CIF the GOB's are fragmented in the middle of a scanline /* for CIF the GOB's are fragmented in the middle of a scanline
that's why we need to adjust the x and y index of the macroblocks */ * that's why we need to adjust the x and y index of the macroblocks */
if (ff_h261_get_picture_format(s->width, s->height) == 1) { // CIF if (ff_h261_get_picture_format(s->width, s->height) == 1) { // CIF
s->mb_x = index % 11 ; index /= 11; s->mb_x = index % 11;
s->mb_y = index % 3 ; index /= 3; index /= 11;
s->mb_x+= 11*(index % 2); index /= 2; s->mb_y = index % 3;
index /= 3;
s->mb_x += 11 * (index % 2);
index /= 2;
s->mb_y += 3 * index; s->mb_y += 3 * index;
ff_init_block_index(s); ff_init_block_index(s);
@ -121,14 +127,14 @@ void ff_h261_reorder_mb_index(MpegEncContext* s){
} }
} }
static void h261_encode_motion(H261Context * h, int val){ static void h261_encode_motion(H261Context *h, int val)
{
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
int sign, code; int sign, code;
if (val == 0) { if (val == 0) {
code = 0; code = 0;
put_bits(&s->pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]); put_bits(&s->pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
} } else {
else{
if (val > 15) if (val > 15)
val -= 32; val -= 32;
if (val < -16) if (val < -16)
@ -140,19 +146,17 @@ static void h261_encode_motion(H261Context * h, int val){
} }
} }
static inline int get_cbp(MpegEncContext * s, static inline int get_cbp(MpegEncContext *s, int16_t block[6][64])
int16_t block[6][64])
{ {
int i, cbp; int i, cbp;
cbp = 0; cbp = 0;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++)
if (s->block_last_index[i] >= 0) if (s->block_last_index[i] >= 0)
cbp |= 1 << (5 - i); cbp |= 1 << (5 - i);
}
return cbp; return cbp;
} }
void ff_h261_encode_mb(MpegEncContext * s,
int16_t block[6][64], void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
int motion_x, int motion_y) int motion_x, int motion_y)
{ {
H261Context *h = (H261Context *)s; H261Context *h = (H261Context *)s;
@ -180,7 +184,8 @@ void ff_h261_encode_mb(MpegEncContext * s,
} }
/* MB is not skipped, encode MBA */ /* MB is not skipped, encode MBA */
put_bits(&s->pb, ff_h261_mba_bits[(h->current_mba-h->previous_mba)-1], ff_h261_mba_code[(h->current_mba-h->previous_mba)-1]); put_bits(&s->pb, ff_h261_mba_bits[(h->current_mba - h->previous_mba) - 1],
ff_h261_mba_code[(h->current_mba - h->previous_mba) - 1]);
/* calculate MTYPE */ /* calculate MTYPE */
if (!s->mb_intra) { if (!s->mb_intra) {
@ -222,18 +227,19 @@ void ff_h261_encode_mb(MpegEncContext * s,
av_assert1(cbp > 0); av_assert1(cbp > 0);
put_bits(&s->pb, ff_h261_cbp_tab[cbp - 1][1], ff_h261_cbp_tab[cbp - 1][0]); put_bits(&s->pb, ff_h261_cbp_tab[cbp - 1][1], ff_h261_cbp_tab[cbp - 1][0]);
} }
for(i=0; i<6; i++) { for (i = 0; i < 6; i++)
/* encode each block */ /* encode each block */
h261_encode_block(h, block[i], i); h261_encode_block(h, block[i], i);
}
if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){ if ((h->current_mba == 11) || (h->current_mba == 22) ||
(h->current_mba == 33) || (!IS_16X16(h->mtype))) {
h->current_mv_x = 0; h->current_mv_x = 0;
h->current_mv_y = 0; h->current_mv_y = 0;
} }
} }
void ff_h261_encode_init(MpegEncContext *s){ void ff_h261_encode_init(MpegEncContext *s)
{
static int done = 0; static int done = 0;
if (!done) { if (!done) {
@ -247,13 +253,13 @@ void ff_h261_encode_init(MpegEncContext *s){
s->c_dc_scale_table = ff_mpeg1_dc_scale_table; s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
} }
/** /**
* Encode an 8x8 block. * Encode an 8x8 block.
* @param block the 8x8 block * @param block the 8x8 block
* @param n block index (0-3 are luma, 4-5 are chroma) * @param n block index (0-3 are luma, 4-5 are chroma)
*/ */
static void h261_encode_block(H261Context * h, int16_t * block, int n){ static void h261_encode_block(H261Context *h, int16_t *block, int n)
{
MpegEncContext *const s = &h->s; MpegEncContext *const s = &h->s;
int level, run, i, j, last_index, last_non_zero, sign, slevel, code; int level, run, i, j, last_index, last_non_zero, sign, slevel, code;
RLTable *rl; RLTable *rl;
@ -277,7 +283,8 @@ static void h261_encode_block(H261Context * h, int16_t * block, int n){
else else
put_bits(&s->pb, 8, level); put_bits(&s->pb, 8, level);
i = 1; i = 1;
} else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){ } else if ((block[0] == 1 || block[0] == -1) &&
(s->block_last_index[n] > -1)) {
// special case // special case
put_bits(&s->pb, 2, block[0] > 0 ? 2 : 3); put_bits(&s->pb, 2, block[0] > 0 ? 2 : 3);
i = 1; i = 1;
@ -299,7 +306,8 @@ static void h261_encode_block(H261Context * h, int16_t * block, int n){
sign = 1; sign = 1;
level = -level; level = -level;
} }
code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/, run, level); code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/,
run, level);
if (run == 0 && level < 16) if (run == 0 && level < 16)
code += 1; code += 1;
put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
@ -314,9 +322,8 @@ static void h261_encode_block(H261Context * h, int16_t * block, int n){
last_non_zero = i; last_non_zero = i;
} }
} }
if(last_index > -1){ if (last_index > -1)
put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]); // EOB
}
} }
FF_MPV_GENERIC_CLASS(h261) FF_MPV_GENERIC_CLASS(h261)
@ -329,7 +336,8 @@ AVCodec ff_h261_encoder = {
.init = ff_MPV_encode_init, .init = ff_MPV_encode_init,
.encode2 = ff_MPV_encode_picture, .encode2 = ff_MPV_encode_picture,
.close = ff_MPV_encode_end, .close = ff_MPV_encode_end,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("H.261"), .long_name = NULL_IF_CONFIG_SMALL("H.261"),
.priv_class = &h261_class, .priv_class = &h261_class,
}; };