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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Sep 16 12:31:32 CDT 2007


Author: rizzo
Date: Sun Sep 16 12:31:31 2007
New Revision: 82511

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82511
Log:
change some reference to "webcam" with "video source" as we can
transmit video from different sources.


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=82511&r1=82510&r2=82511
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Sun Sep 16 12:31:31 2007
@@ -94,7 +94,7 @@
 };
 
 struct video_out_desc {
-	/* webcam support.
+	/* video device support.
 	 * videodevice and geometry are read from the config file.
 	 * At the right time we try to open it and allocate a buffer.
 	 * If we are successful, webcam_bufsize > 0 and we can read.
@@ -167,26 +167,12 @@
 	{ 0,			0 },
 };
 
-/*! \brief support to open a webcam using video4linux1 and read()
- *
- */
-#if !defined(HAVE_V4L) || HAVE_V4L != 1
-/* stubs */
-static int webcam_open(struct video_desc *env)
-{
-	return -1;
-}
-static int webcam_read(struct video_out_desc *v)
-{
-	return 0;
-}
-
-#else
-
-/* the real thing */
+#if defined(HAVE_V4L) && HAVE_V4L > 0
 #include <linux/videodev.h>
-
-static int webcam_open(struct video_desc *env)
+#endif
+
+/* open the local video source */
+static int video_open(struct video_desc *env)
 {
 	int i;
 	const char *device = env->videodevice;
@@ -233,7 +219,9 @@
 		im->red_mask, im->green_mask, im->blue_mask);
 	v->pix_fmt = PIX_FMT_RGB565;
 	v->fd = -2;
-    } else {
+    }
+#if defined(HAVE_V4L) && HAVE_V4L != 0
+    else {
 	struct video_window vw = { 0 };	/* camera attributes */
 	struct video_picture vp;
 
@@ -269,6 +257,7 @@
 		goto error;
 	}
     }
+#endif /* HAVE_V4L */
 	v->buf.size = (v->w * v->h * 3)/2;	/* yuv411 */
 	ast_log(LOG_WARNING, "videodev %s opened, size %dx%d %d\n", device, v->w, v->h, v->buf.size);
 	v->buf.data = ast_calloc(1, v->buf.size);
@@ -290,11 +279,11 @@
 	return -1;
 }
 
-/*! \brief complete a buffer from the webcam.
+/*! \brief complete a buffer from the local video source.
  * called by get_video_frame(), in turn called by asterisk
  * as part of the read callback
  */
-static int webcam_read(struct video_out_desc *v)
+static int video_read(struct video_out_desc *v)
 {
 	if (v->buf.data == NULL)	/* not initialized */
 		return 0;
@@ -336,6 +325,8 @@
 
 		return v->buf.size;	/* return the actual size */
 	}
+	if (v->fd < 0)			/* no other source */
+		return 0;
 	for (;;) {
 		int r, l = v->buf.size - v->buf.used;
 		r = read(v->fd, v->buf.data + v->buf.used, l);
@@ -352,7 +343,6 @@
 		}
 	}
 }
-#endif /* HAVE_V4L */
 
 static void show_frame(struct video_desc *env, int out);
 
@@ -827,7 +817,7 @@
 	struct timeval now = ast_tvnow();
 	int i;
 
-	// ast_log(LOG_WARNING, "received video frame %d\n", f->seqno);
+	ast_log(LOG_WARNING, "received video frame %d\n", f->seqno);
 	if(!env->initialized) {
 		ast_log(LOG_WARNING, "here env should be already initialized\n");
 		return -1;	/* error */
@@ -1000,6 +990,8 @@
 		start += size;
 		len = end-start;
 		size = MIN(len, out->mtu);
+		if (len > 0)
+			ast_log(LOG_WARNING, "create_video_segment %d leftover bytes\n", len);
 	} while(len > 0);
 
 	f->subclass |= last_packet; // RTP Marker
@@ -1037,7 +1029,7 @@
 
 		fp = f;
 	}
-
+	// ast_log(LOG_WARNING, "split_frame %d returns %p\n", len, ftop);
 	return ftop;
 }
 
@@ -1047,7 +1039,7 @@
 	struct timeval tvnow;
 	int period, fdiff;
 
-	if (!webcam_read(&env->out))
+	if (!video_read(&env->out))
 		return NULL;
 	//fprintf(stderr, "webcam read\n");
 
@@ -1065,9 +1057,9 @@
 	env->out.msts.tv_usec = tvnow.tv_usec;
 	/* get frame and put them in the queue */
 	show_frame(env, 1);
-	// fprintf(stderr, "webcam_encode\n");
 	webcam_buflen = avcodec_encode_video(env->out.context,
 		env->out.decbuf.data, env->out.decbuf.size, env->out.frame);
+	// fprintf(stderr, "avcodec_encode_video returns %d\n", webcam_buflen);
 	return split_frame(&(env->out), webcam_buflen);
 }
 
@@ -1076,7 +1068,7 @@
  * call (in turn, called by .answer or .dial) when the channel
  * is created. Here we do the following:
  *   - make sure that avcodec is properly initialized;
- *   - try to open the webcam
+ *   - try to open the local video source
  */
 static void console_video_start(struct video_desc *env,
 	struct ast_channel *owner)
@@ -1104,10 +1096,10 @@
 	}
 	/* create windows ? */
 	env->initialized = 1;
-	webcam_open(env);	/* also allocate out.buf.data */
+	video_open(env);	/* also allocate out.buf.data */
 	show_frame(env, 1);
 
-	if (env->out.buf.data && owner) {  /* drive webcam */
+	if (env->out.buf.data && owner) {  /* talk to the local video source */
 		if (env->out.fd >= 0)
 			ast_channel_set_fd(owner, 1, env->out.fd);
 		fprintf(stderr, "video_out_init fd %d\n", env->out.fd);




More information about the asterisk-commits mailing list