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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 14 05:05:10 CDT 2007


Author: rizzo
Date: Fri Sep 14 05:05:08 2007
New Revision: 82369

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82369
Log:
more 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=82369&r1=82368&r2=82369
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Fri Sep 14 05:05:08 2007
@@ -63,7 +63,7 @@
  */
 
 #include <ffmpeg/avcodec.h>
-// #include <ffmpeg/swscale.h>	/* requires a recent ffmpeg */
+#include <ffmpeg/swscale.h>	/* requires a recent ffmpeg */
 #include <SDL/SDL.h>
 
 /* Structures for ffmpeg processing */
@@ -94,7 +94,7 @@
 	AVCodecContext	*context;
 	AVCodec		*codec;
 	AVFrame		*frame;
-	int		lasttxframe;
+	int		lasttxframe;	/* XXX - useless: RTP overwrite seqno */
 	int		fps;
 	struct dbuf_t	decbuf;
 	struct timeval	ts;
@@ -334,6 +334,7 @@
 	* Initialize the codec context.
 	*/
 	v->context = avcodec_alloc_context();
+	v->context->bit_rate_tolerance = v->context->bit_rate/5;
 	if (avcodec_open(v->context, v->codec) < 0) {
 		ast_log(LOG_WARNING, "Unable to open the codec context\n");
 		return video_in_uninit(v);
@@ -377,6 +378,14 @@
 	return -1;
 }
 
+/*
+ * Initialize:
+ * - AVCodecContext
+ * - AVCodec
+ * - AVFrame
+ * - decbuf
+ * - mtu
+ */
 static int video_out_init(struct video_out_desc *v, uint32_t format)
 {
 	int codec;
@@ -405,8 +414,8 @@
 	v->context->flags|=CODEC_FLAG_H263P_UMV;
 	v->context->flags|=CODEC_FLAG_AC_PRED;
 	v->context->flags|=CODEC_FLAG_H263P_SLICE_STRUCT;
-	//v->context->bit_rate = 20000;
-	//v->context->gop_size = (int) v->fps*5; // emit I frame every 5 seconds
+	v->context->bit_rate = 20000;
+	v->context->gop_size = (int) v->fps*5; // emit I frame every 5 seconds
  
 	fprintf(stderr, "w: %d...h: %d...fps: %d...", v->w, v->h, v->fps);
 	v->context->time_base = (AVRational){1, v->fps};
@@ -463,6 +472,9 @@
  */
 static void ffmpeg_init(struct video_desc *env, uint32_t format)
 {
+	if (env->initialized)
+		return;
+
 	env->screen = NULL;
 	env->initialized = 0;
 	env->bmp[0] = env->bmp[1] = NULL;
@@ -668,7 +680,7 @@
 		bcopy(env->out.buf.data + 4*l4, bmp->pixels[2], l4);
 		bcopy(env->out.buf.data + 5*l4, bmp->pixels[1], l4);
 	} else {	/* decode */
-#if 1 /* XXX img_convert is deprecated */
+#if 0 /* XXX img_convert is deprecated */
 		img_convert(&pict, PIX_FMT_YUV420P, (AVPicture *)env->in.frame, c->pix_fmt, c->width, c->height);
 #else /* XXX replacement */
 		struct SwsContext *convert_ctx;
@@ -807,6 +819,7 @@
  */
 static uint8_t *get_psc(uint8_t *begin, uint8_t *end, int packet_size)
 {
+#if 0
 	int i;
 	uint8_t *ret=NULL;
 	uint8_t *p;
@@ -817,6 +830,17 @@
 		}
 		p++;/* to skip possible 0 after the PSC that would make a double detection */
 	}
+#else
+	uint8_t *p, *ret = NULL;
+
+	if(begin == end) return NULL;
+	for(p = begin; p < end-2; ++p) {
+		if(p[0] == 0 && p[1] == 0) {
+			ret = p;
+			break;
+		}
+	}
+#endif
 	return ret;
 }
  
@@ -838,20 +862,13 @@
 	do {
 		f = ast_malloc(sizeof(*f));
 		if(fp)
-			fp->frame_list.next = f;
+			AST_LIST_NEXT(fp, frame_list) = f;
 		else
 			ftop = f;
 		fp = f;
 
 		data = ast_malloc(size+header);
 		memcpy(data+header, start, size);
-
-		if(header == 2)
-			data[0] = data[1] = 0; // P == 0
-		else {
-			data[0] |= 0x04; // P == 1
-			header = 2;
-		}
 
 		f->has_timing_info = 1;
 		f->ts = ast_tvdiff_ms(ast_tvnow(), out->ts);
@@ -868,7 +885,14 @@
 		f->seqno = ++(out->lasttxframe);
 		f->datalen = size+header;
 		f->data = data;
-		f->frame_list.next = NULL;
+		AST_LIST_NEXT(f, frame_list) = NULL;
+
+		if(header == 2)
+			data[0] = data[1] = 0; // P == 0
+		else {
+			data[0] |= 0x04; // P == 1
+			header = 2;
+		}
 
 		start += size;
 		len = end-start;
@@ -889,17 +913,19 @@
 	uint8_t *end = out->decbuf.data+len;
 	uint8_t *psc, *pos;
 	struct ast_frame *f, *fp = NULL, *ftop = NULL;
+	int last;
 
 	while(1) {
-		psc = get_psc(lastpsc+2, end, out->mtu);
+		psc = get_psc(lastpsc+2, end, len);
 
 		pos = (psc == NULL) ? end : psc;
-
-		f = create_video_segment(out, lastpsc, pos, 0);
+		last = (psc == NULL) ? 1 : 0;
+
+		f = create_video_segment(out, lastpsc, pos, last);
 		lastpsc = psc;
 
 		if(fp)
-			fp->frame_list.next = f;
+			AST_LIST_NEXT(fp, frame_list) = f;
 		else
 			ftop = f;
 
@@ -920,6 +946,7 @@
 
 	if (!webcam_read(&env->out))
 		return NULL;
+	fprintf(stderr, "webcam read\n");
 
 	// XXX - questa porzione di codice limita la generazione dei
 	// frame al framerate specificato nel file di configurazione
@@ -934,7 +961,9 @@
 	env->out.msts.tv_sec = tvnow.tv_sec;
 	env->out.msts.tv_usec = tvnow.tv_usec;
 	/* get frame and put them in the queue */
+	fprintf(stderr, "webcam_encode\n");
 	webcam_buflen = webcam_encode(env);
+	fprintf(stderr, "split_frame\n");
 	return split_frame(&(env->out), webcam_buflen);
 }
 
@@ -948,9 +977,13 @@
 	 */
 	avcodec_register_all();
 
+	fprintf(stderr, "webcam_open\n");
 	webcam_open(env);
+	fprintf(stderr, "ffmpeg_init\n");
+	//ffmpeg_init(env, CONSOLE_FORMAT_VIDEO);
 	if (env->out.buf.data && owner) {  /* drive webcam */
 		owner->fds[1] = env->out.fd;
+		fprintf(stderr, "video_out_init\n");
 		video_out_init(&env->out, CONSOLE_FORMAT_VIDEO);
 	}
 	ast_log(LOG_VERBOSE, "console_video_start owner %p", owner);




More information about the asterisk-commits mailing list