changeset 2270:21f450be6cb5 libavcodec

lowres width/height cleanup 3rd try
author michael
date Mon, 27 Sep 2004 11:50:56 +0000
parents 535b7dfee202
children 859535b5eb57
files avcodec.h h261.c h263dec.c mdec.c mjpeg.c mpeg12.c parser.c utils.c
diffstat 8 files changed, 54 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/avcodec.h	Mon Sep 27 10:06:10 2004 +0000
+++ b/avcodec.h	Mon Sep 27 11:50:56 2004 +0000
@@ -17,7 +17,7 @@
 
 #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 @@
     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 @@
      * - 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_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 */
--- a/h261.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/h261.c	Mon Sep 27 11:50:56 2004 +0000
@@ -118,8 +118,8 @@
     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 @@
         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;
     }
--- a/h263dec.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/h263dec.c	Mon Sep 27 11:50:56 2004 +0000
@@ -37,10 +37,8 @@
     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 @@
         /* 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 @@
         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;
     }
--- a/mdec.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/mdec.c	Mon Sep 27 11:50:56 2004 +0000
@@ -222,8 +222,8 @@
 
     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;
--- a/mjpeg.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/mjpeg.c	Mon Sep 27 11:50:56 2004 +0000
@@ -859,8 +859,6 @@
     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 @@
 	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 @@
             
         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 @@
     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 @@
 #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;
--- a/mpeg12.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/mpeg12.c	Mon Sep 27 11:50:56 2004 +0000
@@ -1966,8 +1966,8 @@
 
     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 @@
 	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 @@
     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;
 
--- a/parser.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/parser.c	Mon Sep 27 11:50:56 2004 +0000
@@ -299,8 +299,7 @@
             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 @@
 
                         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 @@
     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;
--- a/utils.c	Mon Sep 27 10:06:10 2004 +0000
+++ b/utils.c	Mon Sep 27 11:50:56 2004 +0000
@@ -123,6 +123,13 @@
     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 @@
     } 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);