]> git.sesse.net Git - ffmpeg/commitdiff
lowres width/height cleanup 3rd try
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 27 Sep 2004 11:50:56 +0000 (11:50 +0000)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 27 Sep 2004 11:50:56 +0000 (11:50 +0000)
Originally committed as revision 3522 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/avcodec.h
libavcodec/h261.c
libavcodec/h263dec.c
libavcodec/mdec.c
libavcodec/mjpeg.c
libavcodec/mpeg12.c
libavcodec/parser.c
libavcodec/utils.c

index 17477032ba23fa2b7d2251aaaf5269c942f772af..3abb440376fee97a5499c2e341e02584e705d6a5 100644 (file)
@@ -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 */
index 88bd755392f67ae976da999a0d46f7117dcfbd8f..909af75df2210f32f067cd93b70f0e0893b32fdb 100644 (file)
@@ -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;
     }
index 6ba05645526a2c97a8c7da3bb8000c51bc1810e1..f9680052c2cdc1a0a6e0e02e7b99de3bb34d16ae 100644 (file)
@@ -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;
     }
index ef4e6ec0a9a3f7b2e3208b1f41dcb1a20688767a..cf3a1d347b5085064beb636ccb7283e44315ef21 100644 (file)
@@ -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;
index 19c3b6b09afe9c2b09a00b1b5758368aa1cdca04..8e6d90bc54643b752b0398ecc296c15992bff0e0 100644 (file)
@@ -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;
index 82a1a80fb53761b88390c1c110692589ddd4a934..5a83698efae03cc34174d59593d5f01a1c6472bf 100644 (file)
@@ -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;
 
index 4f82edab55ec0620058ec4e154bfdf1ccd6d6152..97cadc123fba815a35048ae0567b7953f31eebc4 100644 (file)
@@ -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;
index 2790362fe67683488ba79a7003227734475bdaa4..7579e6f31623e49184965f3ed1fcbeb21846aa44 100644 (file)
@@ -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);