changeset 1358:a6b92de6a9fc libavcodec

postprocessing support fix duplicate frames bug?
author michaelni
date Thu, 10 Jul 2003 19:09:24 +0000
parents 540dd445bf0f
children 4c2febfefd78
files mjpeg.c
diffstat 1 files changed, 40 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mjpeg.c	Thu Jul 10 16:25:30 2003 +0000
+++ b/mjpeg.c	Thu Jul 10 19:09:24 2003 +0000
@@ -808,6 +808,7 @@
 
     int16_t quant_matrixes[4][64];
     VLC vlcs[2][4];
+    int qscale[4];      ///< quantizer scale calculated from quant_matrixes
 
     int org_width, org_height;  /* size given at codec init */
     int first_picture;    /* true if decoding first picture */
@@ -829,6 +830,7 @@
     int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
     uint8_t *current_picture[MAX_COMPONENTS]; /* picture structure */
     int linesize[MAX_COMPONENTS];
+    uint8_t *qscale_table;
     DCTELEM block[64] __align8;
     ScanTable scantable;
     void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
@@ -924,6 +926,11 @@
             j = s->scantable.permutated[i];
 	    s->quant_matrixes[index][j] = get_bits(&s->gb, 8);
         }
+
+        //XXX FIXME finetune, and perhaps add dc too
+        s->qscale[index]= FFMAX(
+            s->quant_matrixes[index][s->scantable.permutated[1]],
+            s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1;
         len -= 65;
     }
     
@@ -1027,6 +1034,9 @@
     if (width != s->width || height != s->height) {
         for(i=0;i<MAX_COMPONENTS;i++)
             av_freep(&s->current_picture[i]);
+            
+        av_freep(&s->qscale_table);
+            
         s->width = width;
         s->height = height;
         /* test interlaced mode */
@@ -1065,6 +1075,8 @@
 	    }
           }
         }
+        s->qscale_table= av_mallocz((s->width+15)/16);
+
         s->first_picture = 0;
     }
 
@@ -1695,7 +1707,7 @@
     MJpegDecodeContext *s = avctx->priv_data;
     uint8_t *buf_end, *buf_ptr;
     int i, start_code;
-    AVPicture *picture = data;
+    AVFrame *picture = data;
 
     *data_size = 0;
 
@@ -1796,6 +1808,8 @@
 			return -1;
                     break;
 		case EOI:
+		    if ((s->buggy_avid && !s->interlaced) || s->restart_interval) 
+                        break;
 eoi_parser:
 		    {
                         if (s->interlaced) {
@@ -1809,7 +1823,7 @@
 			    picture->linesize[i] = (s->interlaced) ?
 				s->linesize[i] >> 1 : s->linesize[i];
                         }
-                        *data_size = sizeof(AVPicture);
+                        *data_size = sizeof(AVFrame);
                         avctx->height = s->height;
                         if (s->interlaced)
                             avctx->height *= 2;
@@ -1830,9 +1844,16 @@
                             avctx->pix_fmt = PIX_FMT_YUV420P;
                             break;
                         }
-                        /* dummy quality */
-                        /* XXX: infer it with matrix */
-//                    	avctx->quality = 3; 
+
+                        if(!s->lossless){
+                            picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); 
+                            picture->qstride= 0;
+                            picture->qscale_table= s->qscale_table;
+                            memset(picture->qscale_table, picture->quality, (s->width+15)/16);
+                            if(avctx->debug & FF_DEBUG_QP)
+                                printf("QP: %d\n", (int)picture->quality);
+                        }
+                        
                         goto the_end;
                     }
 		    break;
@@ -1886,7 +1907,7 @@
     MJpegDecodeContext *s = avctx->priv_data;
     uint8_t *buf_end, *buf_ptr;
     int i;
-    AVPicture *picture = data;
+    AVFrame *picture = data;
     GetBitContext hgb; /* for the header */
     uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
     uint32_t field_size;
@@ -1973,12 +1994,14 @@
     	}
     }
 
+    //XXX FIXME factorize, this looks very similar to the EOI code
+    
     for(i=0;i<3;i++) {
         picture->data[i] = s->current_picture[i];
         picture->linesize[i] = (s->interlaced) ?
     	    s->linesize[i] >> 1 : s->linesize[i];
     }
-    *data_size = sizeof(AVPicture);
+    *data_size = sizeof(AVFrame);
     avctx->height = s->height;
     if (s->interlaced)
         avctx->height *= 2;
@@ -1996,9 +2019,15 @@
             avctx->pix_fmt = PIX_FMT_YUV420P;
             break;
     }
-    /* dummy quality */
-    /* XXX: infer it with matrix */
-//    avctx->quality = 3; 
+    
+    if(!s->lossless){
+        picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); 
+        picture->qstride= 0;
+        picture->qscale_table= s->qscale_table;
+        memset(picture->qscale_table, picture->quality, (s->width+15)/16);
+        if(avctx->debug & FF_DEBUG_QP)
+            printf("QP: %d\n", picture->quality);
+    }
 
     return buf_ptr - buf;
 }
@@ -2010,6 +2039,7 @@
     int i, j;
 
     av_free(s->buffer);
+    av_free(s->qscale_table);
     for(i=0;i<MAX_COMPONENTS;i++)
         av_free(s->current_picture[i]);
     for(i=0;i<2;i++) {