diff h263.c @ 231:840cd25bf259 libavcodec

- Fixes on RTP and GOB headers for H.263. - RTP callback system implemented for H.263/H.263+. - Bug fix on DC coefficients of H.263. - H.263 decoder now returns PTS on picture number.
author pulento
date Sat, 09 Feb 2002 16:59:56 +0000
parents ac5075a55488
children 5fc0c3af3fe4
line wrap: on
line diff
--- a/h263.c	Sat Feb 09 01:25:06 2002 +0000
+++ b/h263.c	Sat Feb 09 16:59:56 2002 +0000
@@ -62,7 +62,12 @@
     int format;
 
     align_put_bits(&s->pb);
-    put_bits(&s->pb, 22, 0x20);
+
+    /* Update the pointer to last GOB */
+    s->ptr_lastgob = s->pb.buf_ptr;
+    s->gob_number = 0;
+
+    put_bits(&s->pb, 22, 0x20); /* PSC */
     put_bits(&s->pb, 8, ((s->picture_number * 30 * FRAME_RATE_BASE) / 
                          s->frame_rate) & 0xff);
 
@@ -151,22 +156,36 @@
         if (pdif >= s->rtp_payload_size) {
             /* Bad luck, packet must be cut before */
             align_put_bits(&s->pb);
+            flush_put_bits(&s->pb);
+            /* Call the RTP callback to send the last GOB */
+            if (s->rtp_callback) {
+                pdif = s->pb.buf_ptr - s->ptr_lastgob;
+                s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number);
+            }
             s->ptr_lastgob = s->pb.buf_ptr;
             put_bits(&s->pb, 17, 1); /* GBSC */
-            s->gob_number = mb_line;
+            s->gob_number = mb_line / s->gob_index;
             put_bits(&s->pb, 5, s->gob_number); /* GN */
-            put_bits(&s->pb, 2, 1); /* GFID */
+            put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */
             put_bits(&s->pb, 5, s->qscale); /* GQUANT */
+            //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif);
             return pdif;
        } else if (pdif + s->mb_line_avgsize >= s->rtp_payload_size) {
            /* Cut the packet before we can't */
            align_put_bits(&s->pb);
+           flush_put_bits(&s->pb);
+           /* Call the RTP callback to send the last GOB */
+           if (s->rtp_callback) {
+               pdif = s->pb.buf_ptr - s->ptr_lastgob;
+               s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number);
+           }
            s->ptr_lastgob = s->pb.buf_ptr;
            put_bits(&s->pb, 17, 1); /* GBSC */
-           s->gob_number = mb_line;
+           s->gob_number = mb_line / s->gob_index;
            put_bits(&s->pb, 5, s->gob_number); /* GN */
-           put_bits(&s->pb, 2, 1); /* GFID */
+           put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */
            put_bits(&s->pb, 5, s->qscale); /* GQUANT */
+           //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif);
            return pdif;
        }
    }
@@ -413,20 +432,25 @@
     RLTable *rl = &rl_inter;
 
     if (s->mb_intra) {
-	/* DC coef */
-	level = block[0];
+        /* DC coef */
+	    level = block[0];
         /* 255 cannot be represented, so we clamp */
         if (level > 254) {
             level = 254;
             block[0] = 254;
         }
-	if (level == 128)
-	    put_bits(&s->pb, 8, 0xff);
-	else
-	    put_bits(&s->pb, 8, level & 0xff);
-	i = 1;
+        /* 0 cannot be represented also */
+        else if (!level) {
+            level = 1;
+            block[0] = 1;
+        }
+	    if (level == 128)
+	        put_bits(&s->pb, 8, 0xff);
+	    else
+	        put_bits(&s->pb, 8, level & 0xff);
+	    i = 1;
     } else {
-	i = 0;
+	    i = 0;
     }
 
     /* AC coefs */
@@ -1241,8 +1265,8 @@
     /* picture header */
     if (get_bits(&s->gb, 22) != 0x20)
         return -1;
-    skip_bits(&s->gb, 8); /* picture timestamp */
-
+    s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
+    
     if (get_bits1(&s->gb) != 1)
         return -1;	/* marker */
     if (get_bits1(&s->gb) != 0)