[svn-commits] rizzo: branch rizzo/video_v2 r85391 - /team/rizzo/video_v2/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Oct 11 07:03:38 CDT 2007


Author: rizzo
Date: Thu Oct 11 07:03:37 2007
New Revision: 85391

URL: http://svn.digium.com/view/asterisk?view=rev&rev=85391
Log:
add some code to help debugging h261 support.


Modified:
    team/rizzo/video_v2/channels/console_video.c

Modified: team/rizzo/video_v2/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/console_video.c?view=diff&rev=85391&r1=85390&r2=85391
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Thu Oct 11 07:03:37 2007
@@ -415,7 +415,98 @@
 	return f;
 }
 
-
+/* some debugging code to check the bitstream:
+ * declare a bit buffer, initialize it, and fetch data from it.
+ */
+struct bitbuf {
+	const uint8_t *base;
+	int	bitsize;	/* total size in bits */
+	int	ofs;	/* next bit to read */
+};
+
+static struct bitbuf bitbuf_init(const uint8_t *base, int bitsize, int start_ofs)
+{
+	struct bitbuf a;
+	a.base = base;
+	a.bitsize = bitsize;
+	a.ofs = start_ofs;
+	return a;
+}
+
+static uint32_t getbits(struct bitbuf *b, int n)
+{
+	int i, ofs;
+	const uint8_t *d;
+	uint8_t mask;
+	uint32_t retval = 0;
+	if (n + b->ofs > b->bitsize) {
+		ast_log(LOG_WARNING, "bitbuf overflow %d of %d\n", n + b->ofs, b->bitsize);
+		return 0;
+	}
+	if (n> 31) {
+		ast_log(LOG_WARNING, "too many bits %d, max 32\n", n);
+		return 0;
+	}
+	ofs = 7 - b->ofs % 8;	/* start from msb */
+	mask = 1 << ofs;
+	d = b->base + b->ofs / 8;	/* current byte */
+	for (i=0 ; i < n; i++) {
+		retval += retval + (*d & mask ? 1 : 0);	/* shift in new byte */
+		b->ofs++;
+		mask >>= 1;
+		if (mask == 0) {
+			d++;
+			mask = 0x80;
+		}
+	}
+	return retval;
+}
+
+static void check_h261(struct fbuf_t *b)
+{
+	struct bitbuf a = bitbuf_init(b->data, b->used * 8, 0);
+	uint32_t x, y;
+	
+	x = getbits(&a, 20);	/* PSC, 0000 0000 0000 0001 0000 */
+	if (x != 0x10)
+		ast_log(LOG_WARNING, "bad PSC 0x%x\n", x);
+	x = getbits(&a, 5);	/* temporal reference */
+	y = getbits(&a, 6);	/* ptype */
+	ast_log(LOG_WARNING, "TR %d PTY spl %d doc %d freeze %d %sCIF hi %d\n",
+		x,
+		(y & 0x20) ? 1 : 0,
+		(y & 0x10) ? 1 : 0,
+		(y & 0x8) ? 1 : 0,
+		(y & 0x4) ? "" : "Q",
+		(y & 0x2) ? 1:0);
+	while ( (x = getbits(&a, 1)) == 1)
+		ast_log(LOG_WARNING, "PSPARE 0x%x\n", getbits(&a, 8));
+	ast_log(LOG_WARNING, "PSPARE 0 - start GOB\n");
+}
+
+void dump_buf(struct fbuf_t *b);
+void dump_buf(struct fbuf_t *b)
+{
+	int i, x, last2lines;
+	char buf[80];
+
+	last2lines = (b->used - 16) & ~0xf;
+	ast_log(LOG_WARNING, "buf size %d of %d\n", b->used, b->size);
+	for (i = 0; i < b->used; i++) {
+		x = i & 0xf;
+		if ( x == 0) {	/* new line */
+			if (i != 0)
+				ast_log(LOG_WARNING, "%s\n", buf);
+			bzero(buf, sizeof(buf));
+			sprintf(buf, "%04x: ", i);
+		}
+		sprintf(buf + 6 + x*3, "%02x ", b->data[i]);
+		if (i > 31 && i < last2lines)
+			i = last2lines - 1;
+	}
+	if (buf[0])
+		ast_log(LOG_WARNING, "%s\n", buf);
+}
 /*
  * Here starts the glue code for the various supported video codecs.
  * For each of them, we need to provide routines for initialization,
@@ -550,14 +641,22 @@
 	return fbuf_append(b, data, len, 0, 0);	/* ignore trail bits */
 }
 
+
 /*
  * generic encoder, used by the various protocols supported here.
+ * We assume that the buffer is empty at the beginning.
  */
 static int ffmpeg_encode(struct video_out_desc *v)
 {
 	struct fbuf_t *b = &v->enc_out;
+	int i;
 
 	b->used = avcodec_encode_video(v->enc_ctx, b->data, b->size, v->frame);
+	i = avcodec_encode_video(v->enc_ctx, b->data + b->used, b->size - b->used, NULL); /* delayed frames ? */
+	if (i > 0) {
+		ast_log(LOG_WARNING, "have %d more bytes\n", i);
+		b->used += i;
+	}
 	return 0;
 }
 
@@ -576,6 +675,7 @@
 
 	if (!srclen)
 		return 0;
+	check_h261(b);
 	while (srclen) {
 		uint8_t *data;
 		int datalen, ret, dummy = 0;
@@ -789,6 +889,15 @@
 /*---- h261 support -----*/
 static int h261_enc_init(struct video_out_desc *v)
 {
+	v->enc_ctx->bit_rate = v->bitrate;
+	v->enc_ctx->gop_size = v->fps*5;
+	v->enc_ctx->qmin = 3;
+
+	v->enc_ctx->rtp_mode = 0;
+#if 0
+	v->enc_ctx->rtp_payload_size = 0;
+	v->enc_ctx->bit_rate_tolerance = 0;	/* not good */
+#endif
 	return 0;
 }
 
@@ -832,6 +941,9 @@
 	 * the loop one more time.
 	 */
 	for (i = H261_MIN_LEN, start = 0; start < len - 1; start = i, i += 4) {
+#if 0	/* test - disable packetization */
+		i = len;
+#else
 		int found = 0, found_ebit = 0;	/* last GBSC position found */
 		for (; i < len ; i++) {
 			uint8_t x, rpos, lpos;
@@ -874,6 +986,7 @@
 			i = found;
 			ebit = found_ebit;
 		}
+#endif /* test */
 		/* This frame is up to offset i (not inclusive).
 		 * We do not split it yet even if larger than MTU.
 		 */




More information about the svn-commits mailing list