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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Sep 29 10:41:20 CDT 2007


Author: rizzo
Date: Sat Sep 29 10:41:19 2007
New Revision: 84123

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84123
Log:
A large change but mostly cleaning up.
The real important change here is a fix for a trivial bug in my_scale()
which took ages to be found out - i was overwriting
the source when calling the scaling routine.


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=84123&r1=84122&r2=84123
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Sat Sep 29 10:41:19 2007
@@ -69,10 +69,11 @@
 The code is structured as follows.
 
 When a new console channel is created, we call console_video_start()
-to initialize SDL, the source and the encoder/ decoder
+to initialize SDL, the source, and the encoder/ decoder for
+the formats in use
 (XXX the latter two should be done later, once the codec
 negotiation is complete).
-Also a thread is created to handle the video source and generate frames.
+Also, a thread is created to handle the video source and generate frames.
 
 While communication is on, the local source is generated by the
 video thread, which wakes up periodically, generates frames and enqueues
@@ -84,7 +85,7 @@
 codec parameters), as follows:
 
  loc_src	is the data coming from the camera/X11/etc.
-	The format is typically constrained by the video device driver.
+	The format is typically constrained by the video source.
 
  enc_in		is the input required by the encoder.
 	Typically constrained in size by the encoder type.
@@ -280,9 +281,15 @@
 
 static void free_fbuf(struct fbuf_t *b)
 {
+	struct fbuf_t x = *b;
+
 	if (b->data && b->size)
 		ast_free(b->data);
 	bzero(b, sizeof(*b));
+	/* restore some fields */
+	b->w = x.w;
+	b->h = x.h;
+	b->pix_fmt = x.pix_fmt;
 }
 
 /*!
@@ -596,6 +603,8 @@
 		ast_log(LOG_WARNING, "Unable to allocate enc.in\n");
 		return video_out_uninit(v);
 	}
+	ast_log(LOG_WARNING, "enc_in data at %p size %d\n",
+		enc_in->data, enc_in->size);
 	v->enc_ctx = avcodec_alloc_context();
 	v->enc_ctx->pix_fmt = enc_in->pix_fmt;
 	v->enc_ctx->width = enc_in->w;
@@ -794,35 +803,43 @@
 	return 1;
 }
 
-/*! create an avpict from our fbuf info.
+/*! fill an AVPicture from our fbuf info, as it is required by
+ * the image conversion routines in ffmpeg.
  * XXX This depends on the format.
  */
 static AVPicture *fill_pict(struct fbuf_t *b, AVPicture *p)
 {
+	/* provide defaults for commonly used formats */
 	int l4 = b->w * b->h/4; /* size of U or V frame */
-	int len = b->w;		/* default */
-	int ly = b->w/2;	/* default */
+	int len = b->w;		/* Y linesize, bytes */
+	int luv = b->w/2;	/* U/V linesize, bytes */
+
 	bzero(p, sizeof(*p));
 	switch (b->pix_fmt) {
 	case PIX_FMT_RGB555:
 	case PIX_FMT_RGB565:
 		len *= 2;
+		luv = 0;
 		break;
 	case PIX_FMT_RGBA32:
 		len *= 4;
+		luv = 0;
 		break;
 	}
 	p->data[0] = b->data;
-	p->data[1] = b->data + 4*l4;
-	p->data[2] = b->data + 4*l4;
 	p->linesize[0] = len;
 	/* these are only valid for component images */
-	p->linesize[1] = ly;
-	p->linesize[2] = ly;
+	p->data[1] = luv ? b->data + 4*l4 : b->data;
+	p->data[2] = luv ? b->data + 5*l4 : b->data;
+	p->linesize[1] = luv;
+	p->linesize[2] = luv;
 	return p;
 }
 
-/*! convert/scale between an input and an output format */
+/*! convert/scale between an input and an output format.
+ * Old version of ffmpeg only have img_convert, which does not rescale.
+ * New versions use sws_scale which does both.
+ */
 static void my_scale(struct fbuf_t *in, AVPicture *p_in,
 	struct fbuf_t *out, AVPicture *p_out)
 {
@@ -831,10 +848,10 @@
 	if (p_in == NULL)
 		p_in = fill_pict(in, &my_p_in);
 	if (p_out == NULL)
-		p_out = fill_pict(in, &my_p_out);
-		
-#ifdef OLD_FFMPEG /* XXX img_convert is deprecated */
-	/* env->sdl_ok guarantees that in.frame exists */
+		p_out = fill_pict(out, &my_p_out);
+
+#ifdef OLD_FFMPEG
+	/* XXX img_convert is deprecated, and does not do rescaling */
 	img_convert(p_out, out->pix_fmt,
 		p_in, in->pix_fmt, in->w, in->h);
 #else /* XXX replacement */
@@ -878,6 +895,7 @@
 
 	if (out) {	/* webcam/x11 to sdl */
 		b_in = &env->out.loc_src;
+		b_in = &env->out.enc_in;
 		b_out = &env->out.loc_dpy;
 		p_in = NULL;
 	} else {
@@ -1125,12 +1143,12 @@
 		return NULL;	/* can happen, e.g. we are reading too early */
 
 	/* get frame and put them in the queue */
+	my_scale(&v->loc_src, NULL, &v->enc_in, NULL);
 	show_frame(env, 1);
 	if (b->data == NULL) {
 		ast_log(LOG_WARNING, "fail, no encbuf\n");
 		return NULL;
 	}
-	my_scale(&v->loc_src, NULL, &v->enc_in, NULL);
 
 	buflen = avcodec_encode_video(v->enc_ctx, b->data, b->size, v->frame);
 	return split_frame(v, buflen);
@@ -1189,17 +1207,19 @@
  */
 static void init_env(struct video_desc *env)
 {
-	struct fbuf_t *x;
+	struct fbuf_t *c, *ei, *ld, *rd;
 
 	/* Local video chain */
-	x = &(env->out.loc_src);
-	x->pix_fmt = PIX_FMT_YUV420P;	/* default - camera format */
-	x->w = env->w;
-	x->h = env->h;
-	env->out.enc_in = *x;
-	env->out.loc_dpy = *x;
-	/* Remote video chain */
-	env->in.rem_dpy = *x;
+	c = &(env->out.loc_src);
+	ei = &(env->out.enc_in);
+	ld = &(env->out.loc_dpy);
+	rd = &(env->in.rem_dpy);
+	c->pix_fmt = PIX_FMT_YUV420P;	/* default - camera format */
+	ei->pix_fmt = PIX_FMT_YUV420P;	/* encoder input */
+	ld->pix_fmt = rd->pix_fmt = PIX_FMT_YUV420P; /* sdl format */
+	/* all size default to the same value */
+	c->w = ei->w = ld->w = rd->w = env->w;
+	c->h = ei->h = ld->h = rd->h = env->h;
 }
 
 /*!
@@ -1281,7 +1301,6 @@
 	/*
 	 * now handle the local video source
 	 */
-	ast_pthread_create_background(&env->vthread, NULL, video_thread, env);
 	/* copy video source config from parent */
 	env->out.device = env->videodevice;
 	env->out.w = env->w;
@@ -1307,6 +1326,7 @@
 			ast_channel_set_fd(owner, 1, env->out.fd);
 		video_out_init(&env->out, CONSOLE_FORMAT_VIDEO);
 	}
+	ast_pthread_create_background(&env->vthread, NULL, video_thread, env);
 }
 
 /* see chan_oss.c for these macros */




More information about the svn-commits mailing list