Commit 21adafec authored by Michael Niedermayer's avatar Michael Niedermayer

lowres width/height cleanup 3rd try

Originally committed as revision 3522 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 0b2346d3
......@@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000409
#define FFMPEG_VERSION "0.4.9-pre1"
#define LIBAVCODEC_BUILD 4724
#define LIBAVCODEC_BUILD 4725
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION
......@@ -677,9 +677,11 @@ typedef struct AVCodecContext {
int frame_rate;
/**
* width / height.
* picture width / height.
* - encoding: MUST be set by user.
* - decoding: set by user if known, codec should override / dynamically change if needed
* - decoding: set by lavc.
* Note, for compatibility its possible to set this instead of
* coded_width/height before decoding
*/
int width, height;
......@@ -1663,6 +1665,14 @@ typedef struct AVCodecContext {
* - decoding: set by user
*/
int lowres;
/**
* bistream width / height. may be different from width/height if lowres
* or other things are used
* - encoding: unused
* - decoding: set by user before init if known, codec should override / dynamically change if needed
*/
int coded_width, coded_height;
} AVCodecContext;
......@@ -1972,6 +1982,7 @@ int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
int avpicture_get_size(int pix_fmt, int width, int height);
void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
const char *avcodec_get_pix_fmt_name(int pix_fmt);
void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
enum PixelFormat avcodec_get_pix_fmt(const char* name);
#define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
......
......@@ -118,8 +118,8 @@ static int h261_decode_init(AVCodecContext *avctx){
MPV_decode_defaults(s);
s->avctx = avctx;
s->width = s->avctx->width >> avctx->lowres;
s->height = s->avctx->height >> avctx->lowres;
s->width = s->avctx->coded_width;
s->height = s->avctx->coded_height;
s->codec_id = s->avctx->codec->id;
s->out_format = FMT_H261;
......@@ -715,15 +715,14 @@ retry:
return -1;
}
if (s->width >> avctx->lowres != avctx->width || s->height >> avctx->lowres != avctx->height){
if (s->width != avctx->coded_width || s->height != avctx->coded_height){
ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
s->parse_context.buffer=0;
MPV_common_end(s);
s->parse_context= pc;
}
if (!s->context_initialized) {
avctx->width = s->width >> avctx->lowres;
avctx->height = s->height >> avctx->lowres;
avcodec_set_dimensions(avctx, s->width, s->height);
goto retry;
}
......
......@@ -37,10 +37,8 @@ int ff_h263_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
s->out_format = FMT_H263;
s->width = avctx->width;
s->height = avctx->height;
avctx->width = -((-s->width )>>avctx->lowres);
avctx->height= -((-s->height)>>avctx->lowres);
s->width = avctx->coded_width;
s->height = avctx->coded_height;
s->workaround_bugs= avctx->workaround_bugs;
// set defaults
......@@ -639,8 +637,8 @@ retry:
/* FIXME: By the way H263 decoder is evolving it should have */
/* an H263EncContext */
if ( -((-s->width )>>avctx->lowres) != avctx->width
|| -((-s->height)>>avctx->lowres) != avctx->height) {
if ( s->width != avctx->coded_width
|| s->height != avctx->coded_height) {
/* H.263 could change picture size any time */
ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
s->parse_context.buffer=0;
......@@ -648,8 +646,7 @@ retry:
s->parse_context= pc;
}
if (!s->context_initialized) {
avctx->width = -((-s->width)>>avctx->lowres);
avctx->height = -((-s->height)>>avctx->lowres);
avcodec_set_dimensions(avctx, s->width, s->height);
goto retry;
}
......
......@@ -222,8 +222,8 @@ static void mdec_common_init(AVCodecContext *avctx){
dsputil_init(&a->dsp, avctx);
a->mb_width = (avctx->width + 15) / 16;
a->mb_height = (avctx->height + 15) / 16;
a->mb_width = (avctx->coded_width + 15) / 16;
a->mb_height = (avctx->coded_height + 15) / 16;
avctx->coded_frame= (AVFrame*)&a->picture;
a->avctx= avctx;
......
......@@ -859,8 +859,6 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
MpegEncContext s2;
s->avctx = avctx;
avctx->width = -((-avctx->width ) >> avctx->lowres);
avctx->height= -((-avctx->height) >> avctx->lowres);
/* ugly way to get the idct & scantable FIXME */
memset(&s2, 0, sizeof(MpegEncContext));
......@@ -880,7 +878,7 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
return -1;
s->start_code = -1;
s->first_picture = 1;
s->org_height = avctx->height << avctx->lowres;
s->org_height = avctx->coded_height;
build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12);
build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12);
......@@ -1032,8 +1030,7 @@ static int mjpeg_decode_sof(MJpegDecodeContext *s)
s->width = width;
s->height = height;
s->avctx->width = -((-s->width )>>s->avctx->lowres);
s->avctx->height = -((-s->height)>>s->avctx->lowres);
avcodec_set_dimensions(s->avctx, width, height);
/* test interlaced mode */
if (s->first_picture &&
......@@ -2043,10 +2040,10 @@ static int sp5x_decode_frame(AVCodecContext *avctx,
j += sizeof(sp5x_data_dht);
memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
recoded[j+5] = (avctx->height >> 8) & 0xFF; //FIXME lowres
recoded[j+6] = avctx->height & 0xFF;
recoded[j+7] = (avctx->width >> 8) & 0xFF;
recoded[j+8] = avctx->width & 0xFF;
recoded[j+5] = (avctx->coded_height >> 8) & 0xFF;
recoded[j+6] = avctx->coded_height & 0xFF;
recoded[j+7] = (avctx->coded_width >> 8) & 0xFF;
recoded[j+8] = avctx->coded_width & 0xFF;
j += sizeof(sp5x_data_sof);
memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
......@@ -2070,10 +2067,8 @@ static int sp5x_decode_frame(AVCodecContext *avctx,
#else
/* SOF */
s->bits = 8;
s->width = avctx->width;
s->height = avctx->height;
avctx->width = -((-avctx->width )>>avctx->lowres);
avctx->height = -((-avctx->height)>>avctx->lowres);
s->width = avctx->coded_width;
s->height = avctx->coded_height;
s->nb_components = 3;
s->component_id[0] = 0;
s->h_count[0] = 2;
......
......@@ -1966,8 +1966,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){
if (
(s1->mpeg_enc_ctx_allocated == 0)||
avctx->width != -((-s->width )>>avctx->lowres) ||
avctx->height != -((-s->height)>>avctx->lowres) ||
avctx->coded_width != s->width ||
avctx->coded_height != s->height||
// s1->save_aspect_info != avctx->aspect_ratio_info||
0)
{
......@@ -1979,8 +1979,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){
if( (s->width == 0 )||(s->height == 0))
return -2;
avctx->width = -((-s->width )>>avctx->lowres);
avctx->height = -((-s->height)>>avctx->lowres);
avcodec_set_dimensions(avctx, s->width, s->height);
avctx->bit_rate = s->bit_rate;
s1->save_aspect_info = s->aspect_ratio_info;
......@@ -2776,8 +2775,8 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
if (s1->mpeg_enc_ctx_allocated) {
MPV_common_end(s);
}
s->width = avctx->width;
s->height = avctx->height;
s->width = avctx->coded_width;
s->height = avctx->coded_height;
avctx->has_b_frames= 0; //true?
s->low_delay= 1;
......
......@@ -299,8 +299,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
if (bytes_left >= 4) {
pc->width = (buf[0] << 4) | (buf[1] >> 4);
pc->height = ((buf[1] & 0x0f) << 8) | buf[2];
avctx->width = -((-pc->width )>>avctx->lowres);
avctx->height = -((-pc->height)>>avctx->lowres);
avcodec_set_dimensions(avctx, pc->width, pc->height);
frame_rate_index = buf[3] & 0xf;
pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index];
avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE;
......@@ -322,8 +321,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
pc->width |=(horiz_size_ext << 12);
pc->height |=( vert_size_ext << 12);
avctx->width = -((-pc->width )>>avctx->lowres);
avctx->height = -((-pc->height)>>avctx->lowres);
avcodec_set_dimensions(avctx, pc->width, pc->height);
avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1);
avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1);
avctx->codec_id = CODEC_ID_MPEG2VIDEO;
......@@ -441,8 +439,7 @@ static int av_mpeg4_decode_header(AVCodecParserContext *s1,
init_get_bits(gb, buf, 8 * buf_size);
ret = ff_mpeg4_decode_picture_header(s, gb);
if (s->width) {
avctx->width = -((-s->width )>>avctx->lowres);
avctx->height = -((-s->height)>>avctx->lowres);
avcodec_set_dimensions(avctx, s->width, s->height);
}
pc->first_picture = 0;
return ret;
......
......@@ -123,6 +123,13 @@ void register_avcodec(AVCodec *format)
format->next = NULL;
}
void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
s->coded_width = width;
s->coded_height= height;
s->width = -((-width )>>s->lowres);
s->height= -((-height)>>s->lowres);
}
typedef struct InternalBuffer{
int last_pic_num;
uint8_t *base[4];
......@@ -456,6 +463,12 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
} else {
avctx->priv_data = NULL;
}
if(avctx->coded_width && avctx->coded_height)
avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
else if(avctx->width && avctx->height)
avcodec_set_dimensions(avctx, avctx->width, avctx->height);
ret = avctx->codec->init(avctx);
if (ret < 0) {
av_freep(&avctx->priv_data);
......
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