2001-07-22 16:18:56 +02:00
|
|
|
/*
|
|
|
|
* H263 decoder
|
2002-05-26 00:45:33 +02:00
|
|
|
* Copyright (c) 2001 Fabrice Bellard.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2002-05-26 00:45:33 +02:00
|
|
|
* 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 of the License, or (at your option) any later version.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2002-05-26 00:45:33 +02:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2001-07-22 16:18:56 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-26 00:45:33 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2002-05-26 00:45:33 +02:00
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-07-22 16:18:56 +02:00
|
|
|
*/
|
|
|
|
#include "avcodec.h"
|
2002-05-19 01:03:29 +02:00
|
|
|
#include "dsputil.h"
|
2001-07-22 16:18:56 +02:00
|
|
|
#include "mpegvideo.h"
|
|
|
|
|
|
|
|
//#define DEBUG
|
2002-05-17 00:01:30 +02:00
|
|
|
//#define PRINT_FRAME_TIME
|
|
|
|
#ifdef PRINT_FRAME_TIME
|
|
|
|
static inline long long rdtsc()
|
|
|
|
{
|
|
|
|
long long l;
|
|
|
|
asm volatile( "rdtsc\n\t"
|
|
|
|
: "=A" (l)
|
|
|
|
);
|
|
|
|
// printf("%d\n", int(l/1000));
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
static int h263_decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
MpegEncContext *s = avctx->priv_data;
|
2001-08-12 02:52:37 +02:00
|
|
|
|
2001-08-15 15:09:47 +02:00
|
|
|
s->avctx = avctx;
|
2001-07-22 16:18:56 +02:00
|
|
|
s->out_format = FMT_H263;
|
|
|
|
|
|
|
|
s->width = avctx->width;
|
|
|
|
s->height = avctx->height;
|
2002-05-22 01:13:57 +02:00
|
|
|
s->workaround_bugs= avctx->workaround_bugs;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/* select sub codec */
|
|
|
|
switch(avctx->codec->id) {
|
|
|
|
case CODEC_ID_H263:
|
2001-11-12 06:19:55 +01:00
|
|
|
s->gob_number = 0;
|
2002-06-02 14:16:28 +02:00
|
|
|
s->first_slice_line = 0;
|
2001-07-22 16:18:56 +02:00
|
|
|
break;
|
2001-08-15 15:09:47 +02:00
|
|
|
case CODEC_ID_MPEG4:
|
2001-07-22 16:18:56 +02:00
|
|
|
s->time_increment_bits = 4; /* default value for broken headers */
|
|
|
|
s->h263_pred = 1;
|
2002-04-22 21:04:28 +02:00
|
|
|
s->has_b_frames = 1; //default, might be overriden in the vol header during header parsing
|
2001-07-22 16:18:56 +02:00
|
|
|
break;
|
2002-04-05 06:09:04 +02:00
|
|
|
case CODEC_ID_MSMPEG4V1:
|
2001-07-22 16:18:56 +02:00
|
|
|
s->h263_msmpeg4 = 1;
|
|
|
|
s->h263_pred = 1;
|
2002-04-05 06:09:04 +02:00
|
|
|
s->msmpeg4_version=1;
|
|
|
|
break;
|
|
|
|
case CODEC_ID_MSMPEG4V2:
|
|
|
|
s->h263_msmpeg4 = 1;
|
|
|
|
s->h263_pred = 1;
|
|
|
|
s->msmpeg4_version=2;
|
|
|
|
break;
|
|
|
|
case CODEC_ID_MSMPEG4V3:
|
|
|
|
s->h263_msmpeg4 = 1;
|
|
|
|
s->h263_pred = 1;
|
|
|
|
s->msmpeg4_version=3;
|
2001-07-22 16:18:56 +02:00
|
|
|
break;
|
2002-04-07 00:29:37 +02:00
|
|
|
case CODEC_ID_WMV1:
|
|
|
|
s->h263_msmpeg4 = 1;
|
|
|
|
s->h263_pred = 1;
|
|
|
|
s->msmpeg4_version=4;
|
|
|
|
break;
|
2002-06-18 02:46:02 +02:00
|
|
|
case CODEC_ID_WMV2:
|
|
|
|
s->h263_msmpeg4 = 1;
|
|
|
|
s->h263_pred = 1;
|
|
|
|
s->msmpeg4_version=5;
|
|
|
|
break;
|
2001-07-22 16:18:56 +02:00
|
|
|
case CODEC_ID_H263I:
|
|
|
|
s->h263_intel = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2002-04-27 14:30:26 +02:00
|
|
|
s->codec_id= avctx->codec->id;
|
2002-07-14 20:37:35 +02:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
/* for h263, we allocate the images after having read the header */
|
2002-03-19 04:51:36 +01:00
|
|
|
if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
|
2001-11-03 01:49:53 +01:00
|
|
|
if (MPV_common_init(s) < 0)
|
|
|
|
return -1;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
if (s->h263_msmpeg4)
|
2002-06-18 02:46:02 +02:00
|
|
|
ff_msmpeg4_decode_init(s);
|
2001-07-22 16:18:56 +02:00
|
|
|
else
|
|
|
|
h263_decode_init_vlc(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int h263_decode_end(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
MpegEncContext *s = avctx->priv_data;
|
|
|
|
|
|
|
|
MPV_common_end(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-12 13:10:33 +02:00
|
|
|
/**
|
|
|
|
* retunrs the number of bytes consumed for building the current frame
|
|
|
|
*/
|
|
|
|
static int get_consumed_bytes(MpegEncContext *s, int buf_size){
|
|
|
|
int pos= (get_bits_count(&s->gb)+7)>>3;
|
|
|
|
|
|
|
|
if(s->divx_version>=500){
|
|
|
|
//we would have to scan through the whole buf to handle the weird reordering ...
|
|
|
|
return buf_size;
|
|
|
|
}else{
|
|
|
|
if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
|
2002-09-12 17:00:09 +02:00
|
|
|
if(pos+10>buf_size) pos=buf_size; // oops ;)
|
2002-09-12 13:10:33 +02:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
static int h263_decode_frame(AVCodecContext *avctx,
|
|
|
|
void *data, int *data_size,
|
|
|
|
UINT8 *buf, int buf_size)
|
|
|
|
{
|
|
|
|
MpegEncContext *s = avctx->priv_data;
|
|
|
|
int ret;
|
|
|
|
AVPicture *pict = data;
|
2002-05-17 00:01:30 +02:00
|
|
|
#ifdef PRINT_FRAME_TIME
|
|
|
|
uint64_t time= rdtsc();
|
|
|
|
#endif
|
2001-07-22 16:18:56 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
|
|
|
|
printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
|
|
|
|
#endif
|
2002-04-27 15:12:57 +02:00
|
|
|
|
|
|
|
s->hurry_up= avctx->hurry_up;
|
2002-06-02 14:16:28 +02:00
|
|
|
s->error_resilience= avctx->error_resilience;
|
|
|
|
s->workaround_bugs= avctx->workaround_bugs;
|
2002-06-09 15:35:56 +02:00
|
|
|
s->flags= avctx->flags;
|
2002-06-02 14:16:28 +02:00
|
|
|
|
2002-09-12 16:43:44 +02:00
|
|
|
*data_size = 0;
|
|
|
|
|
|
|
|
/* no supplementary picture */
|
2001-07-22 16:18:56 +02:00
|
|
|
if (buf_size == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-03 00:08:04 +02:00
|
|
|
if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder
|
2002-04-22 14:45:22 +02:00
|
|
|
init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size);
|
2002-05-02 22:45:43 +02:00
|
|
|
}else
|
2002-04-22 14:45:22 +02:00
|
|
|
init_get_bits(&s->gb, buf, buf_size);
|
2002-06-03 00:08:04 +02:00
|
|
|
s->bitstream_buffer_size=0;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/* let's go :-) */
|
|
|
|
if (s->h263_msmpeg4) {
|
|
|
|
ret = msmpeg4_decode_picture_header(s);
|
|
|
|
} else if (s->h263_pred) {
|
|
|
|
ret = mpeg4_decode_picture_header(s);
|
2002-04-22 21:04:28 +02:00
|
|
|
s->has_b_frames= !s->low_delay;
|
2001-07-22 16:18:56 +02:00
|
|
|
} else if (s->h263_intel) {
|
|
|
|
ret = intel_h263_decode_picture_header(s);
|
|
|
|
} else {
|
|
|
|
ret = h263_decode_picture_header(s);
|
2002-03-19 04:51:36 +01:00
|
|
|
}
|
2002-07-15 16:15:10 +02:00
|
|
|
avctx->has_b_frames= s->has_b_frames;
|
2002-07-27 16:48:44 +02:00
|
|
|
#if 0 // dump bits per frame / qp / complexity
|
|
|
|
{
|
|
|
|
static FILE *f=NULL;
|
|
|
|
if(!f) f=fopen("rate_qp_cplx.txt", "w");
|
2002-08-02 01:23:48 +02:00
|
|
|
fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale);
|
2002-07-27 16:48:44 +02:00
|
|
|
}
|
|
|
|
#endif
|
2002-07-14 20:37:35 +02:00
|
|
|
|
2002-03-19 04:51:36 +01:00
|
|
|
/* After H263 & mpeg4 header decode we have the height, width,*/
|
2001-11-17 16:43:04 +01:00
|
|
|
/* and other parameters. So then we could init the picture */
|
|
|
|
/* FIXME: By the way H263 decoder is evolving it should have */
|
|
|
|
/* an H263EncContext */
|
2002-07-14 20:37:35 +02:00
|
|
|
if (s->width != avctx->width || s->height != avctx->height) {
|
|
|
|
/* H.263 could change picture size any time */
|
|
|
|
MPV_common_end(s);
|
|
|
|
s->context_initialized=0;
|
|
|
|
}
|
2002-03-19 04:51:36 +01:00
|
|
|
if (!s->context_initialized) {
|
|
|
|
avctx->width = s->width;
|
|
|
|
avctx->height = s->height;
|
2002-03-23 00:22:08 +01:00
|
|
|
avctx->aspect_ratio_info= s->aspect_ratio_info;
|
2002-03-19 04:51:36 +01:00
|
|
|
if (MPV_common_init(s) < 0)
|
|
|
|
return -1;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2002-03-19 04:51:36 +01:00
|
|
|
|
2002-09-12 13:10:33 +02:00
|
|
|
if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_size);
|
2002-06-02 14:16:28 +02:00
|
|
|
/* skip if the header was thrashed */
|
2002-06-18 02:46:02 +02:00
|
|
|
if (ret < 0){
|
|
|
|
fprintf(stderr, "header damaged\n");
|
2001-07-22 16:18:56 +02:00
|
|
|
return -1;
|
2002-06-18 02:46:02 +02:00
|
|
|
}
|
2002-04-24 03:24:06 +02:00
|
|
|
/* skip b frames if we dont have reference frames */
|
2002-09-12 13:10:33 +02:00
|
|
|
if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
|
2002-04-27 15:12:57 +02:00
|
|
|
/* skip b frames if we are in a hurry */
|
2002-09-12 13:10:33 +02:00
|
|
|
if(s->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
|
2002-06-02 14:16:28 +02:00
|
|
|
|
|
|
|
if(s->next_p_frame_damaged){
|
|
|
|
if(s->pict_type==B_TYPE)
|
2002-09-12 13:10:33 +02:00
|
|
|
return get_consumed_bytes(s, buf_size);
|
2002-06-02 14:16:28 +02:00
|
|
|
else
|
|
|
|
s->next_p_frame_damaged=0;
|
|
|
|
}
|
|
|
|
|
2002-07-14 20:37:35 +02:00
|
|
|
MPV_frame_start(s, avctx);
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("qscale=%d\n", s->qscale);
|
|
|
|
#endif
|
|
|
|
|
2002-06-02 14:16:28 +02:00
|
|
|
/* init resync/ error resilience specific variables */
|
|
|
|
s->next_resync_qscale= s->qscale;
|
|
|
|
s->next_resync_gb= s->gb;
|
|
|
|
if(s->resync_marker) s->mb_num_left= 0;
|
|
|
|
else s->mb_num_left= s->mb_num;
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
/* decode each macroblock */
|
2002-03-15 15:57:17 +01:00
|
|
|
s->block_wrap[0]=
|
|
|
|
s->block_wrap[1]=
|
|
|
|
s->block_wrap[2]=
|
|
|
|
s->block_wrap[3]= s->mb_width*2 + 2;
|
|
|
|
s->block_wrap[4]=
|
|
|
|
s->block_wrap[5]= s->mb_width + 2;
|
2001-07-22 16:18:56 +02:00
|
|
|
for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
|
2001-11-19 03:13:14 +01:00
|
|
|
/* Check for GOB headers on H.263 */
|
|
|
|
/* FIXME: In the future H.263+ will have intra prediction */
|
|
|
|
/* and we are gonna need another way to detect MPEG4 */
|
|
|
|
if (s->mb_y && !s->h263_pred) {
|
2002-06-02 14:16:28 +02:00
|
|
|
s->first_slice_line = h263_decode_gob_header(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s->msmpeg4_version==1){
|
|
|
|
s->last_dc[0]=
|
|
|
|
s->last_dc[1]=
|
|
|
|
s->last_dc[2]= 128;
|
2001-11-19 03:13:14 +01:00
|
|
|
}
|
2002-03-28 14:41:04 +01:00
|
|
|
|
2002-06-18 02:46:02 +02:00
|
|
|
s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
|
|
|
|
s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
|
|
|
|
|
2002-03-15 15:57:17 +01:00
|
|
|
s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1;
|
|
|
|
s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1);
|
|
|
|
s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1;
|
|
|
|
s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2);
|
|
|
|
s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2);
|
|
|
|
s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2);
|
2001-07-22 16:18:56 +02:00
|
|
|
for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
|
2002-03-15 15:57:17 +01:00
|
|
|
s->block_index[0]+=2;
|
|
|
|
s->block_index[1]+=2;
|
|
|
|
s->block_index[2]+=2;
|
|
|
|
s->block_index[3]+=2;
|
|
|
|
s->block_index[4]++;
|
|
|
|
s->block_index[5]++;
|
2001-07-22 16:18:56 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
|
|
|
|
#endif
|
2002-06-02 14:16:28 +02:00
|
|
|
|
|
|
|
if(s->resync_marker){
|
|
|
|
if(s->mb_num_left<=0){
|
|
|
|
/* except the first block */
|
|
|
|
if(s->mb_x!=0 || s->mb_y!=0){
|
|
|
|
/* did we miss the next resync marker without noticing an error yet */
|
|
|
|
if(((get_bits_count(&s->gb)+8)&(~7)) != s->next_resync_pos && s->decoding_error==0){
|
|
|
|
fprintf(stderr, "slice end missmatch x:%d y:%d %d %d\n",
|
|
|
|
s->mb_x, s->mb_y, get_bits_count(&s->gb), s->next_resync_pos);
|
|
|
|
ff_conceal_past_errors(s, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->qscale= s->next_resync_qscale;
|
2002-06-18 02:46:02 +02:00
|
|
|
s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
|
|
|
|
s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
|
|
|
|
|
2002-06-02 14:16:28 +02:00
|
|
|
s->gb= s->next_resync_gb;
|
|
|
|
s->resync_mb_x= s->mb_x; //we know that the marker is here cuz mb_num_left was the distance to it
|
|
|
|
s->resync_mb_y= s->mb_y;
|
|
|
|
s->first_slice_line=1;
|
|
|
|
|
|
|
|
if(s->codec_id==CODEC_ID_MPEG4){
|
|
|
|
ff_mpeg4_clean_buffers(s);
|
|
|
|
ff_mpeg4_resync(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( s->resync_mb_x==s->mb_x
|
|
|
|
&& s->resync_mb_y==s->mb_y && s->decoding_error!=0){
|
|
|
|
fprintf(stderr, "resynced at %d %d\n", s->mb_x, s->mb_y);
|
|
|
|
s->decoding_error= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-03 01:49:53 +01:00
|
|
|
//fprintf(stderr,"\nFrame: %d\tMB: %d",avctx->frame_number, (s->mb_y * s->mb_width) + s->mb_x);
|
2001-07-22 16:18:56 +02:00
|
|
|
/* DCT & quantize */
|
2002-06-02 14:16:28 +02:00
|
|
|
if(s->decoding_error!=DECODING_DESYNC){
|
|
|
|
int last_error= s->decoding_error;
|
|
|
|
clear_blocks(s->block[0]);
|
2002-03-28 14:41:04 +01:00
|
|
|
|
2002-06-02 14:16:28 +02:00
|
|
|
s->mv_dir = MV_DIR_FORWARD;
|
|
|
|
s->mv_type = MV_TYPE_16X16;
|
|
|
|
if (s->h263_msmpeg4) {
|
|
|
|
if (msmpeg4_decode_mb(s, s->block) < 0) {
|
|
|
|
fprintf(stderr,"Error at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x);
|
|
|
|
s->decoding_error=DECODING_DESYNC;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (h263_decode_mb(s, s->block) < 0) {
|
|
|
|
fprintf(stderr,"Error at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x);
|
|
|
|
s->decoding_error=DECODING_DESYNC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s->decoding_error!=last_error){
|
|
|
|
ff_conceal_past_errors(s, 0);
|
2001-11-17 22:14:54 +01:00
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2002-06-02 14:16:28 +02:00
|
|
|
|
|
|
|
/* conceal errors */
|
|
|
|
if( s->decoding_error==DECODING_DESYNC
|
|
|
|
|| (s->decoding_error==DECODING_ACDC_LOST && s->mb_intra)){
|
|
|
|
s->mv_dir = MV_DIR_FORWARD;
|
|
|
|
s->mv_type = MV_TYPE_16X16;
|
|
|
|
s->mb_skiped=0;
|
|
|
|
s->mb_intra=0;
|
|
|
|
s->mv[0][0][0]=0; //FIXME this is not optimal
|
|
|
|
s->mv[0][0][1]=0;
|
|
|
|
clear_blocks(s->block[0]);
|
|
|
|
}else if(s->decoding_error && !s->mb_intra){
|
|
|
|
clear_blocks(s->block[0]);
|
|
|
|
}
|
|
|
|
//FIXME remove AC for intra
|
|
|
|
|
2001-07-31 01:24:58 +02:00
|
|
|
MPV_decode_mb(s, s->block);
|
2002-06-02 14:16:28 +02:00
|
|
|
|
|
|
|
s->mb_num_left--;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2002-04-24 03:24:06 +02:00
|
|
|
if ( avctx->draw_horiz_band
|
|
|
|
&& (s->num_available_buffers>=1 || (!s->has_b_frames)) ) {
|
2001-08-15 15:09:47 +02:00
|
|
|
UINT8 *src_ptr[3];
|
|
|
|
int y, h, offset;
|
|
|
|
y = s->mb_y * 16;
|
|
|
|
h = s->height - y;
|
|
|
|
if (h > 16)
|
|
|
|
h = 16;
|
|
|
|
offset = y * s->linesize;
|
2002-04-05 06:23:01 +02:00
|
|
|
if(s->pict_type==B_TYPE || (!s->has_b_frames)){
|
|
|
|
src_ptr[0] = s->current_picture[0] + offset;
|
|
|
|
src_ptr[1] = s->current_picture[1] + (offset >> 2);
|
|
|
|
src_ptr[2] = s->current_picture[2] + (offset >> 2);
|
|
|
|
} else {
|
|
|
|
src_ptr[0] = s->last_picture[0] + offset;
|
|
|
|
src_ptr[1] = s->last_picture[1] + (offset >> 2);
|
|
|
|
src_ptr[2] = s->last_picture[2] + (offset >> 2);
|
|
|
|
}
|
2001-08-15 15:09:47 +02:00
|
|
|
avctx->draw_horiz_band(avctx, src_ptr, s->linesize,
|
|
|
|
y, s->width, h);
|
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2002-01-15 23:22:41 +01:00
|
|
|
|
2002-04-07 00:29:37 +02:00
|
|
|
if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
|
2002-01-15 23:22:41 +01:00
|
|
|
if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1;
|
2002-04-22 14:45:22 +02:00
|
|
|
|
|
|
|
/* divx 5.01+ bistream reorder stuff */
|
2002-09-12 13:10:33 +02:00
|
|
|
if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_version>=500){
|
2002-06-02 14:16:28 +02:00
|
|
|
int current_pos= get_bits_count(&s->gb)>>3;
|
|
|
|
|
2002-04-22 14:45:22 +02:00
|
|
|
if( buf_size - current_pos > 5
|
|
|
|
&& buf_size - current_pos < BITSTREAM_BUFFER_SIZE){
|
2002-06-02 14:16:28 +02:00
|
|
|
int i;
|
|
|
|
int startcode_found=0;
|
2002-09-12 13:10:33 +02:00
|
|
|
for(i=current_pos; i<buf_size-3; i++){
|
2002-06-02 14:16:28 +02:00
|
|
|
if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
|
|
|
|
startcode_found=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(startcode_found){
|
|
|
|
memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
|
|
|
|
s->bitstream_buffer_size= buf_size - current_pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s->bitstream_buffer_size==0 && s->error_resilience>0){
|
|
|
|
int left= s->gb.size*8 - get_bits_count(&s->gb);
|
|
|
|
int max_extra=8;
|
|
|
|
|
|
|
|
if(s->codec_id==CODEC_ID_MPEG4) max_extra+=32;
|
|
|
|
|
|
|
|
if(left>max_extra){
|
|
|
|
fprintf(stderr, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
|
|
|
|
if(s->decoding_error==0)
|
|
|
|
ff_conceal_past_errors(s, 1);
|
|
|
|
}
|
|
|
|
if(left<0){
|
|
|
|
fprintf(stderr, "overreading %d bits\n", -left);
|
|
|
|
if(s->decoding_error==0)
|
|
|
|
ff_conceal_past_errors(s, 1);
|
2002-04-22 14:45:22 +02:00
|
|
|
}
|
2002-05-02 22:45:43 +02:00
|
|
|
}
|
2002-04-22 14:45:22 +02:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
MPV_frame_end(s);
|
2002-05-05 03:39:07 +02:00
|
|
|
#if 0 //dirty show MVs, we should export the MV tables and write a filter to show them
|
|
|
|
{
|
|
|
|
int mb_y;
|
|
|
|
s->has_b_frames=1;
|
|
|
|
for(mb_y=0; mb_y<s->mb_height; mb_y++){
|
|
|
|
int mb_x;
|
2002-05-22 01:13:57 +02:00
|
|
|
int y= mb_y*16 + 8;
|
2002-05-05 03:39:07 +02:00
|
|
|
for(mb_x=0; mb_x<s->mb_width; mb_x++){
|
2002-05-22 01:13:57 +02:00
|
|
|
int x= mb_x*16 + 8;
|
2002-05-05 03:39:07 +02:00
|
|
|
uint8_t *ptr= s->last_picture[0];
|
|
|
|
int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
|
|
|
|
int mx= (s->motion_val[xy][0]>>1) + x;
|
|
|
|
int my= (s->motion_val[xy][1]>>1) + y;
|
|
|
|
int i;
|
|
|
|
int max;
|
|
|
|
|
|
|
|
if(mx<0) mx=0;
|
|
|
|
if(my<0) my=0;
|
|
|
|
if(mx>=s->width) mx= s->width -1;
|
|
|
|
if(my>=s->height) my= s->height-1;
|
|
|
|
max= ABS(mx-x);
|
|
|
|
if(ABS(my-y) > max) max= ABS(my-y);
|
|
|
|
/* the ugliest linedrawing routine ... */
|
|
|
|
for(i=0; i<max; i++){
|
|
|
|
int x1= x + (mx-x)*i/max;
|
|
|
|
int y1= y + (my-y)*i/max;
|
|
|
|
ptr[y1*s->linesize + x1]+=100;
|
|
|
|
}
|
2002-05-22 01:13:57 +02:00
|
|
|
ptr[y*s->linesize + x]+=100;
|
2002-05-05 03:39:07 +02:00
|
|
|
s->mbskip_table[mb_x + mb_y*s->mb_width]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2002-03-18 22:06:07 +01:00
|
|
|
if(s->pict_type==B_TYPE || (!s->has_b_frames)){
|
2002-03-12 23:54:25 +01:00
|
|
|
pict->data[0] = s->current_picture[0];
|
|
|
|
pict->data[1] = s->current_picture[1];
|
|
|
|
pict->data[2] = s->current_picture[2];
|
|
|
|
} else {
|
|
|
|
pict->data[0] = s->last_picture[0];
|
|
|
|
pict->data[1] = s->last_picture[1];
|
|
|
|
pict->data[2] = s->last_picture[2];
|
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
pict->linesize[0] = s->linesize;
|
2002-07-15 16:15:10 +02:00
|
|
|
pict->linesize[1] = s->uvlinesize;
|
|
|
|
pict->linesize[2] = s->uvlinesize;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
avctx->quality = s->qscale;
|
2002-02-09 17:59:56 +01:00
|
|
|
|
|
|
|
/* Return the Picture timestamp as the frame number */
|
|
|
|
/* we substract 1 because it is added on utils.c */
|
|
|
|
avctx->frame_number = s->picture_number - 1;
|
|
|
|
|
2002-04-24 03:24:06 +02:00
|
|
|
/* dont output the last pic after seeking
|
|
|
|
note we allready added +1 for the current pix in MPV_frame_end(s) */
|
|
|
|
if(s->num_available_buffers>=2 || (!s->has_b_frames))
|
|
|
|
*data_size = sizeof(AVPicture);
|
2002-05-17 00:01:30 +02:00
|
|
|
#ifdef PRINT_FRAME_TIME
|
|
|
|
printf("%Ld\n", rdtsc()-time);
|
|
|
|
#endif
|
2002-09-12 13:10:33 +02:00
|
|
|
return get_consumed_bytes(s, buf_size);
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2001-08-15 15:09:47 +02:00
|
|
|
AVCodec mpeg4_decoder = {
|
|
|
|
"mpeg4",
|
2001-07-22 16:18:56 +02:00
|
|
|
CODEC_TYPE_VIDEO,
|
2001-08-15 15:09:47 +02:00
|
|
|
CODEC_ID_MPEG4,
|
2001-07-22 16:18:56 +02:00
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
AVCodec h263_decoder = {
|
|
|
|
"h263",
|
|
|
|
CODEC_TYPE_VIDEO,
|
|
|
|
CODEC_ID_H263,
|
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
2002-04-05 06:09:04 +02:00
|
|
|
AVCodec msmpeg4v1_decoder = {
|
|
|
|
"msmpeg4v1",
|
|
|
|
CODEC_TYPE_VIDEO,
|
|
|
|
CODEC_ID_MSMPEG4V1,
|
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2002-04-05 06:09:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
AVCodec msmpeg4v2_decoder = {
|
|
|
|
"msmpeg4v2",
|
|
|
|
CODEC_TYPE_VIDEO,
|
|
|
|
CODEC_ID_MSMPEG4V2,
|
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2002-04-05 06:09:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
AVCodec msmpeg4v3_decoder = {
|
2001-07-22 16:18:56 +02:00
|
|
|
"msmpeg4",
|
|
|
|
CODEC_TYPE_VIDEO,
|
2002-04-05 06:09:04 +02:00
|
|
|
CODEC_ID_MSMPEG4V3,
|
2001-07-22 16:18:56 +02:00
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|
2002-04-07 00:29:37 +02:00
|
|
|
AVCodec wmv1_decoder = {
|
|
|
|
"wmv1",
|
|
|
|
CODEC_TYPE_VIDEO,
|
|
|
|
CODEC_ID_WMV1,
|
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2002-04-07 00:29:37 +02:00
|
|
|
};
|
|
|
|
|
2002-06-18 02:46:02 +02:00
|
|
|
AVCodec wmv2_decoder = {
|
|
|
|
"wmv2",
|
|
|
|
CODEC_TYPE_VIDEO,
|
|
|
|
CODEC_ID_WMV2,
|
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2002-06-18 02:46:02 +02:00
|
|
|
};
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
AVCodec h263i_decoder = {
|
|
|
|
"h263i",
|
|
|
|
CODEC_TYPE_VIDEO,
|
|
|
|
CODEC_ID_H263I,
|
|
|
|
sizeof(MpegEncContext),
|
|
|
|
h263_decode_init,
|
|
|
|
NULL,
|
|
|
|
h263_decode_end,
|
|
|
|
h263_decode_frame,
|
2002-07-14 20:37:35 +02:00
|
|
|
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
|
|
|
|