Commit 3b066668 authored by michael's avatar michael

lowres width/height cleanup 3rd try


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