[asterisk-commits] rizzo: branch rizzo/video_v2 r85353 - /team/rizzo/video_v2/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 10 13:09:22 CDT 2007


Author: rizzo
Date: Wed Oct 10 13:09:21 2007
New Revision: 85353

URL: http://svn.digium.com/view/asterisk?view=rev&rev=85353
Log:
cleanup

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=85353&r1=85352&r2=85353
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Wed Oct 10 13:09:21 2007
@@ -1,4 +1,3 @@
-/* header for console video */
 /*
  * Experimental support for video sessions. We use SDL for rendering, ffmpeg
  * as the codec library for encoding and decoding, and Video4Linux and X11
@@ -15,6 +14,7 @@
  * thus not compiling in AST_DEVMODE, or don't have swscale, in which case
  * you can try to compile #defining OLD_FFMPEG here.
  *
+ * $File: ... $
  * $Revision$
  */
 
@@ -218,7 +218,7 @@
  * extracted by the RTP packets, RTP reassembly info, and a frame buffer
  * for the decoded frame (buf).
  * and store the result in a suitable frame buffer for later display.
- * NOTE: context == NULL means the rest is invalid (e.g. because no
+ * NOTE: dec_ctx == NULL means the rest is invalid (e.g. because no
  *	codec, no memory, etc.) and we must drop all incoming frames.
  */
 struct video_in_desc {
@@ -249,7 +249,9 @@
 /*! \brief inizialize the decoder */
 typedef int (*decoder_init_f)(struct video_in_desc *v);
 
-/*! \brief extract the bitstream from RTP frames, return 0 if ok, 1 on error */
+/*! \brief extract the bitstream from RTP frames and store in the fbuf.
+ * return 0 if ok, 1 on error
+ */
 typedef int (*decoder_decap_f)(struct fbuf_t *b, uint8_t *data, int len);
 
 /*! \brief actually call the decoder */
@@ -298,7 +300,7 @@
 
 static AVPicture *fill_pict(struct fbuf_t *b, AVPicture *p);
 
-static void free_fbuf(struct fbuf_t *b)
+static void fbuf_free(struct fbuf_t *b)
 {
 	struct fbuf_t x = *b;
 
@@ -312,7 +314,7 @@
 }
 
 /*
- * Append a chunk of data to a buffer taking care of unaligments.
+ * Append a chunk of data to a buffer taking care of bit alignment
  * Return 0 on success, != 0 on failure
  */
 static int fbuf_append(struct fbuf_t *b, uint8_t *src, int len,
@@ -348,7 +350,7 @@
 	i = b->ebit + sbit;	/* bits to ignore around */
 	if (i == 0) {	/* easy case, just append */
 		/* do everything in the common block */
-	} else if (i == 8) { /* almost easy, just handle the overlap */
+	} else if (i == 8) { /* easy too, just handle the overlap byte */
 		mask = (1 << b->ebit) - 1;
 		/* update the last byte in the buffer */
 		dst[-1] &= ~mask;	/* clear bits to ignore */
@@ -447,7 +449,9 @@
 
 
 /*
- * Create RTP/H.263 fragments to avoid IP fragmentation
+ * Create RTP/H.263 fragments to avoid IP fragmentation. We fragment on a
+ * PSC or a GBSC, but if we don't find a suitable place just break somewhere.
+ * Everything is byte-aligned.
  */
 static struct ast_frame *h263p_encap(struct video_out_desc *out,
 	struct ast_frame **tail)
@@ -456,7 +460,6 @@
 	uint8_t *d = out->enc_out.data;
 	int len = out->enc_out.used;
 	int l = len; /* size of the current fragment. If 0, must look for a psc */
-	int frags = 0;
 
 	for (;len > 0; len -= l, d += l) {
 		uint8_t *data;
@@ -499,16 +502,12 @@
 
 		if (!cur)
 			first = f;
-
 		cur = f;
-		frags++;
-		// ast_log(LOG_WARNING, "-- frag %d size %d left %d\n", frags, f->datalen, len - l);
 	}
 
 	if (cur)
 		cur->subclass |= 1; // RTP Marker
 
-	//ast_log(LOG_WARNING, "done, totlen %d frags %d\n", totlen, frags);
 	*tail = cur;	/* end of the list */
 	return first;
 }
@@ -837,7 +836,6 @@
 	uint8_t h261_hdr[4];
 	uint8_t *h = h261_hdr;	/* shorthand */
 	int sbit = 0, ebit = 0;
-	int nframes = 0;
 
 #define H261_MIN_LEN 10
 	if (len < H261_MIN_LEN)	/* unreasonably small */
@@ -894,8 +892,6 @@
 			i = found;
 			ebit = found_ebit;
 		}
-		if (i - start > out->mtu)
-			ast_log(LOG_WARNING, "found %d of %d/%d\n", i - start, start, len);
 		/* This frame is up to offset i (not inclusive).
 		 * We do not split it yet even if larger than MTU.
 		 */
@@ -904,7 +900,6 @@
 
 		if (!f)
 			break;
-		nframes++;
 		/* recompute header with I=0, V=1 */
 		h[0] = ( (sbit & 7) << 5 ) | ( (ebit & 7) << 2 ) | 1;
 		bcopy(h, f->data, 4);	/* copy the h261 header */
@@ -921,7 +916,6 @@
 		cur->subclass |= 1;	// RTP Marker
 
 	*tail = cur;
-	ast_log(LOG_WARNING, "send %d bytes %d frames\n", len, nframes);
 	return first;
 }
 
@@ -1092,7 +1086,7 @@
 	if (v->fd >= 0)
 		close(v->fd);
 	v->fd = -1;
-	free_fbuf(&v->loc_src);
+	fbuf_free(&v->loc_src);
 	return -1;
 }
 
@@ -1245,9 +1239,9 @@
 	}
 	v->codec = NULL;	/* only a reference */
 	v->discard = 1;		/* start in discard mode */
-	free_fbuf(&v->dec_in);
-	free_fbuf(&v->dec_out);
-	free_fbuf(&v->rem_dpy);
+	fbuf_free(&v->dec_in);
+	fbuf_free(&v->dec_out);
+	fbuf_free(&v->rem_dpy);
 	return -1;	/* error, in case someone cares */
 }
 
@@ -1311,10 +1305,10 @@
 	}
 	v->codec = NULL;	/* only a reference */
 	
-	free_fbuf(&v->loc_src);
-	free_fbuf(&v->enc_in);
-	free_fbuf(&v->enc_out);
-	free_fbuf(&v->loc_dpy);
+	fbuf_free(&v->loc_src);
+	fbuf_free(&v->enc_in);
+	fbuf_free(&v->enc_out);
+	fbuf_free(&v->loc_dpy);
 	if (v->image) {	/* X11 grabber */
 		XCloseDisplay(v->dpy);
 		v->dpy = NULL;
@@ -1788,6 +1782,10 @@
 
 	c->pix_fmt = PIX_FMT_YUV420P;	/* default - camera format */
 	ei->pix_fmt = PIX_FMT_YUV420P;	/* encoder input */
+	if (ei->w == 0 || ei->h == 0) {
+		ei->w = 352;
+		ei->h = 288;
+	}
 	ld->pix_fmt = rd->pix_fmt = PIX_FMT_YUV420P; /* sdl format */
 	/* inherit defaults */
 	copy_geometry(ei, c);	/* camera inherits from encoder input */
@@ -1913,9 +1911,34 @@
 #define M_STR(tag, dst)         M_F(tag, ast_copy_string(dst, __val, sizeof(dst)))
 #endif
 
+/*
+ * Parse a geometry string, accepting also common names for the formats
+ */
 static int video_geom(struct fbuf_t *b, const char *s)
 {
-	return sscanf(s, "%dx%d", &b->w, &b->h);
+	static struct {
+		const char *s; int w; int h;
+	} *fp, formats[] = {
+		{"cif",		352, 288 },
+		{"qcif",	176, 144 },
+		{"sqcif",	128, 96 },
+		{"vga",		640, 480 },
+		{"qvga",	320, 240 },
+		{NULL,		0, 0 },
+	};
+	for (fp = formats; fp->s; fp++) {
+		if (!strcasecmp(s, fp->s)) {
+			b->w = fp->w;
+			b->h = fp->h;
+			return 0;
+		}
+	}
+	if (sscanf(s, "%dx%d", &b->w, &b->h) != 2) {
+		ast_log(LOG_WARNING, "Invalid video_size %s, using 352x288\n", s);
+		b->w = 352;
+		b->h = 288;
+	}
+	return 0;
 }
 
 /* extend ast_cli with video commands. Called by console_video_config */
@@ -1928,6 +1951,8 @@
 		ast_cli(fd, "videodevice is [%s]\n", env->out.videodevice);
         } else if (!strcasecmp(var, "videoformat")) {
 		ast_cli(fd, "videoformat is [%s]\n", env->codec_name);
+        } else if (!strcasecmp(var, "sendvideo")) {
+		ast_cli(fd, "sendvideo is [%s]\n", env->out.sendvideo ? "on" : "off");
         } else if (!strcasecmp(var, "video_size")) {
 		ast_cli(fd, "sizes: video %dx%d camera %dx%d local %dx%d remote %dx%d in %dx%d\n",
 			env->out.enc_in.w, env->out.enc_in.h,




More information about the asterisk-commits mailing list